AP Computer Science Anthony Keen
Computer 101 What happens when you turn a computer on? –BIOS tries to start a system loader –A system loader tries to start an operating system.
Java 101 What happens when you run a program? You tell the operating system to run a program called java.exe with a command line argument, your program. Java starts up and then calls your main method.
Where does a program start? public static void main(String[] args) –public = anyone can call this method –static = you dont need an instance to call this method –void = this method doesnt return anything –main = the name of the method –String[] = this function takes an array of Strings as its parameter –args = the name of our array
Primitives int –Holds an Integer float, double –Holds a decimal value char –Holds a single character boolean –Holds true or false
Sequential Programming The statements within a function (like main) are executed in order.
Conditional Statements if(boolean) { // stuff } –if the boolean is true, then we execute the code inside the curly braces
Conditional Statements if(boolean) { // stuff } else { // different stuff } –if the boolean is false, then we execute the code inside the elses curly braces
Conditional Statements switch(int) { case 0: // stuff break; case 1: // other stuff break; default: // default stuff }
Looping Structures while (boolean) { // Stuff } While the boolean value is true, we will keep doing whatever is inside the whiles curly braces.
Looping Structures Typical Use: int count = 0; while (count < 10) { // Stuff count++; // count = count + 1; }
Looping Structures for (initialize; condition; increment) { // Stuff }
Looping Structures Typical use for (int i = 0; i < 10; i++) { // Stuff }
Input / Output Input –JOptionPane.showInputDialog ( … ) Output –System.out.print ( … ) –System.out.println ( … ) Escape Codes –\n = New Line –\t = Tab
In Review Primitives Sequential Programming Conditional Statements Looping Structures Input / Output
Operators =, is assigned to +, add numbers or concatenate Strings -, subtract numbers *, multiply numbers /, divide numbers %, divide numbers and give the remainder
Logic Operators &&, AND ||, OR ==, equal to !=, not equal to &, bitwise AND |, bitwise OR <, less than >, greater than
What else have we covered?