A Look at Java
Categorize Java Which paradigm? Which paradigm? Scripting? Scripting? Declarative or procedural? Declarative or procedural? Which generation? Which generation? Low, high, or very high level? Low, high, or very high level? Compiled or interpreted? Compiled or interpreted?
How Programming Works: Pre-Java 1. Programmer types a program into a text editor. This code is called the source code.This code is called the source code. It is saved as a file on your computer, much like any other file you create.It is saved as a file on your computer, much like any other file you create. Since the code is human- readable, it is usually kept private.Since the code is human- readable, it is usually kept private. #include main() { cout << "Hello World!"; return 0; }
How Programming Works: Pre-Java 1. Source Code 2. A program called a compiler reads the code and makes machine code instructions specific to the type of machine you are running on. This code is NOT human- readable. This code is NOT human- readable. This is what comes on software CDs, so that the code remains proprietary. This is what comes on software CDs, so that the code remains proprietary. #include main() { cout << "Hello World!"; return 0; } _main _TEXT SEGMENT _argc$ = 8 _argv$ = 12 _main PROC NEAR ; COMDAT push OFFSET e call _printf 0000a 83 c4 04 add esp, d 33 c0 xor eax, eax Compiler
How Programming Works: Pre-Java 1. Source Code 2. Compiled to Machine Code 3. Run on the computer - Now the program can be run, but only on the machine it was compiled for. #include main() { cout << "Hello World!"; return 0; } _main _TEXT SEGMENT _argc$ = 8 _argv$ = 12 _main PROC NEAR ; COMDAT push OFFSET e call _printf 0000a 83 c4 04 add esp, d 33 c0 xor eax, eax Compiler Hello World! Executed by a machine with Intel 32-bit processor
Java Programming Language James Gosling, Sun Microsystems, 1991 James Gosling, Sun Microsystems, 1991 Idea: Want a computer application to control the appliances in a home Idea: Want a computer application to control the appliances in a home But - different chips on each But - different chips on each Need: Programming language that works on any machine Need: Programming language that works on any machine 3 years later, Internet hits, and we realize portability is a great idea… 3 years later, Internet hits, and we realize portability is a great idea…
How Java Programming Works 1. Programmer types a program into a text editor. This code is called the source code.This code is called the source code. It is saved as a file on your computer, much like any other file you create.It is saved as a file on your computer, much like any other file you create. Since the code is human- readable, it is usually kept private.Since the code is human- readable, it is usually kept private. public class Hello{ public static void main( String[] args){ System.out.println( “Hello World!”); }
How Java Programming Works 1. Source Code 2. The Java compiler reads the code and makes an intermediate code called bytecode. Again, this code is NOT human-readable. Again, this code is NOT human-readable. Again, this is what comes on software CDs, so that the code remains proprietary. Again, this is what comes on software CDs, so that the code remains proprietary. public class Hello{ public static void main( String[] args){ System.out.println( “Hello World!”); } 0: iconst_2 1: istore_1 2: iload_1 3: sipush : if_icmpge 44 9: iconst_2 10: istore_2 11: iload_2 12: iload_1 13: if_icmpge 31 Java Compiler: Same for all machines
How Java Programming Works 1. Source Code 2. Compiled to Bytecode 3. Interpreted by JVM (Java Virtual Machine) This program reads bytecode and translates it directly to whatever machine code is needed. public class Hello{ public static void main( String[] args){ System.out.println( “Hello World!”); } _main _TEXT SEGMENT _argc$ = 8 _argv$ = 12 _main PROC NEAR ; COMDAT push OFFSET e call _printf 0000a 83 c4 04 add esp, d 33 c0 xor eax, eax Interpreted by JVM Java Compiler: Same for all machines 0: iconst_2 1: istore_1 2: iload_1 3: sipush : if_icmpge 44 9: iconst_2 10: istore_2 11: iload_2 12: iload_1 13: if_icmpge 31
How Java Programming Works 1. Source Code 2. Compiled to Bytecode 3. Interpreted by JVM to Machine Code 4. Executed by machine public class Hello{ public static void main( String[] args){ System.out.println( “Hello World!”); } _main _TEXT SEGMENT _argc$ = 8 _argv$ = 12 _main PROC NEAR ; COMDAT push OFFSET e call _printf 0000a 83 c4 04 add esp, d 33 c0 xor eax, eax Interpreted by JVM Java Compiler: Same for all machines 0: iconst_2 1: istore_1 2: iload_1 3: sipush : if_icmpge 44 9: iconst_2 10: istore_2 11: iload_2 12: iload_1 13: if_icmpge 31 Hello World!
Java Overview public class Hello{ public static void main(String[] args){ System.out.println(“Hello World!”); } _main _TEXT SEGMENT _argc$ = 8 _argv$ = 12 _main PROC 0: iconst_2 1: istore_1 2: iload_1 3: sipush 1000 Hello World! e a 83 NEAR ; COMDAT push e call 0000a 83 c4 04 add esp, 0000d 33 c0 xor eax, Source Code: MUST be named Hello.java Bytecode: will be saved as Hello.class Mac Whatever UnixWindows
So, what about Eclipse? What is eclipse? What is eclipse? How does it work? How does it work? What languages will it work for? What languages will it work for?