name: inverse layout: true class: taylor msoe --- class: center, middle .title[ # Java Basics Review ## Writing Java Programs, Datatypes, and identifiers ] ??? Toggle speaker view by pressing P Pressing C clones the slideshow view, which is the view to put on the projector if you're using speaker view. Press ? to toggle keyboard commands help. --- # Writing Java Programs * Java programs are written in a text file with the filename extention `.java` -- * The Java compiler translates the Java source code into bytecode -- * The bytecode is stored in a binary file with the filename extention `.class` -- * Java bytecode is run by a Java Virtual Machine (JVM) -- * The JVM translates the bytecode into instructions for the specific hardware on which it is running -- * Once a Java program is compiled into bytecode, it can be run on any hardware that has a JVM written for it --- # Basic Steps in Software Development * Requirements analysis -- * Design -- * Implementation -- * Testing -- * Documentation -- * Maintenance --- # Primitive datatypes * Primitive datatypes are types that are built into the Java language -- * Each primitive requires a fixed number of bytes to represent the value -- + `int` — Integer value, e.g., `1` -- + `long` — Integer value with a bigger range, e.g., `4000000000L` -- + `double` — double precision floating point value, e.g., `3.75` -- + `float` — floating point value, e.g., `3.75F` -- + `char` — a single character, e.g., `'A'` -- + `boolean` — `true` or `false` --- # Classes and Objects * Objects are instances of a user-defined class -- * An object contains data and has behavior defined -- * The class describes what data is part of the object and the code to run when a behavior is requested --- # Identifiers * An identifier is a label used in your program to refer to a variable -- * Identifiers can refer to primitive types or objects -- * Primitives require a predictable number of bytes (e.g., `int` is 4 bytes) and value is stored "in the variable" -- * Objects may require different amounts of memory (e.g., a `String` containing `A` requires less memory than `Absorbability`) -- * Identifiers that refer to an object store the location in memory where the object is stored -- + The actual object is stored elsewhere --- # Memory Diagram for Primitives * Declaring a primitive: `int i;` --
-- * Assignment: `i = 3;` --
--- # Memory Diagram for Objects * Declaring a primitive: `String x;` --
-- * Assignment: `x = "My class is fun.";` --