name: inverse layout: true class: taylor msoe --- class: center, middle .title[ # Java Basics ] ??? * **P** speaker view * **C** clone slideshow * **?** help --- # Creating and Running a Java Program * Write Java program in a text file with `.java` extension -- * Compile the program -- * Run the program with a Java Virtual Machine (JVM) --- # Typical Steps in Software Development * Requirements analysis -- * Design -- * Implementation -- * Testing -- * Documentation -- * Maintenance --- # Program Overview * All Java code is organized into `.java` files containing a **class** -- * Class name and file name just match -- * Each program has one `main()` method that specifies instructions ``` Java public class ClassName { public static void main(String[] args) { // ... } } ``` -- * A **method** is a sequence of instructions to be performed + To start, our programs will have one class and one method (the `main()` method) --- # Representing Data * Programs consist of instructions that act upon data within the program -- * Data is represented as a sequence of bits (e.g., 00010011011101001) -- * Each piece of data has a type associated with it -- * Java uses the type to determine how to interpret the bits -- * Data in our programs can be specified as a literal value + `3` — is an integer literal + `3.8` — is a double-precision floating point literal + `'a'` — is a single character literal + `"and"` — is a string literal --- # Variables * A variable is a name associated with a piece of data in our program -- * Names must follow identifier rules (simplified) + Begin with a letter + Can contain letters, digits, and underscores + Are case sensitive + Must be unique and cannot be Java keywords -- * Each variable must have a type associated with it -- * We declare a variable by indicating its type followed by the desired name ``` Java int i; ``` -- * Java has several built-in types (called **primitives**) --- # Primitives * `int` — integer (32 bits representing values between -2 billion and 2 billion) -- * `double` — double-precision floating point number (64 bits representing a number with a decimal point) -- * `char` — character value (16 bits) -- * `boolean` — true or false -- * `byte`, `short`, and `long` — integers (8 bits, 16 bits, and 64 bits, respectively) -- * `float` — floating point number (32 bits representing a number with a decimal point) --- # Reference Types * Java also supports non-built-in types, e.g., `String`, `Scanner` -- * Here the variable holds a memory address where the actual data is stored -- * Reference types refer objects which hold data -- * The objects may have methods (behaviors) that can called to act on the data