IB Computer Science II Paul Bui Introduction to Java IB Computer Science II Paul Bui
What does a computer look like? Central Processing Unit (CPU) Memory
What is a computer program? 101011110101010100110010000011101011010111101010101001100100000111010101111010101010011001000001110101011110101010100110010000011101010111101010101001100100000111010101111010101010011001000001110101011110101010100110010000011101010111101010101001100100010010000011101010111101010
Assembly Language Also known as machine code/language or low-level language Example: ADD R1, R2, R3 SUB R1, R1, 1 MULT R3, R1, R2 Why can’t I run my PC programs on a Mac?!?!? Different from machine to machine
I Hate Tedious Stuff Old school programs Invention of the high-level language ADD R1, R2, R3 SUB R1, R1, 1 D = B*(B+C-1) MULT R4, R1, R2 Waaaay easier to understand
Compilers Translates or converts a high-level language (e.g., Java, C++) to a low-level language Does other stuff too! Checks syntax Optimizations and more! One would say, “Yeah, so I compiled my code to an executable or binary”
Before Java… Applications or Programs Operating System (Windows XP, Mac OSX, etc.) Hardware (CPU + Memory + etc.)
How Java Works Java Application or Java Program Java Runtime Environment or Java Virtual Machine Operating System (Windows XP, Mac OSX, etc.) Hardware (CPU + Memory + etc.)
What does this mean? Java bytecode (Java’s low-level language) Java sourcecode (high-level) Java bytecode (low-level) assembly Two different operating systems with the JRE or JVM can run the same Java program
Ok, so I want to program now! //My first Java program! class HelloWorld{ public static void main(String[] args) { System.out.println("Hello World!"); }
How to Compile and Execute Open a text editor (gedit, tea, vi, etc.) Code Code Code Save file as CLASSNAME.java Example: HelloWorld.java Open a terminal javac HelloWorld.java java HelloWorld