Survey
* Your assessment is very important for improving the workof artificial intelligence, which forms the content of this project
* Your assessment is very important for improving the workof artificial intelligence, which forms the content of this project
A Look at Java Categorize Java • Which paradigm? • Scripting? • Declarative or procedural? • Which generation? • Low, high, or very high level? • Compiled or interpreted? How Programming Works: Pre-Java 1. Programmer types a program into a text editor. • • • This code is called the source code. It is saved as a file on your computer, much like any other file you create. Since the code is humanreadable, it is usually kept private. #include <iostream.h> 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 humanreadable. This is what comes on software CDs, so that the code remains proprietary. #include <iostream.h> main() { cout << "Hello World!"; return 0; } Compiler _main _TEXT SEGMENT _argc$ = 8 _argv$ = 12 _main PROC NEAR ; COMDAT 00000 68 00 00 00 00 push OFFSET FLAT:??_C@_0M@KPLPPDAC@Hello?5World?$AA@ 00005 e8 00 00 00 00 call _printf 0000a 83 c4 04 add esp, 4 0000d 33 c0 xor eax, eax 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. Hello World! Executed by a machine with Intel 32-bit processor #include <iostream.h> main() { cout << "Hello World!"; return 0; } Compiler _main _TEXT SEGMENT _argc$ = 8 _argv$ = 12 _main PROC NEAR ; COMDAT 00000 68 00 00 00 00 push OFFSET FLAT:??_C@_0M@KPLPPDAC@Hello?5World?$AA@ 00005 e8 00 00 00 00 call _printf 0000a 83 c4 04 add esp, 4 0000d 33 c0 xor eax, eax Java Programming Language • James Gosling, Sun Microsystems, 1991 • Idea: Want a computer application to control the appliances in a home • But - different chips on each • Need: Programming language that works on any machine • 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. It is saved as a file on your computer, much like any other file you create. Since the code is humanreadable, 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 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!”); } } Java Compiler: Same for all machines 0: iconst_2 1: istore_1 2: iload_1 3: sipush 1000 6: 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 (Java Virtual Machine) This program reads bytecode and translates it directly to whatever machine code is needed. _main _TEXT SEGMENT _argc$ = 8 _argv$ = 12 _main PROC NEAR ; COMDAT 00000 68 00 00 00 00 push OFFSET FLAT:??_C@_0M@KPLPPDAC@Hello?5World?$AA@ 00005 e8 00 00 00 00 call _printf 0000a 83 c4 04 add esp, 4 0000d 33 c0 xor eax, eax Interpreted by JVM public class Hello{ public static void main( String[] args){ System.out.println( “Hello World!”); } } Java Compiler: Same for all machines 0: iconst_2 1: istore_1 2: iload_1 3: sipush 1000 6: 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 4. Machine Code Executed by machine Java Compiler: Same for all machines Hello World! _main _TEXT SEGMENT _argc$ = 8 _argv$ = 12 _main PROC NEAR ; COMDAT 00000 68 00 00 00 00 push OFFSET FLAT:??_C@_0M@KPLPPDAC@Hello?5World?$AA@ 00005 e8 00 00 00 00 call _printf 0000a 83 c4 04 add esp, 4 0000d 33 c0 xor eax, eax public class Hello{ public static void main( String[] args){ System.out.println( “Hello World!”); } } Interpreted by JVM 0: iconst_2 1: istore_1 2: iload_1 3: sipush 1000 6: if_icmpge 44 9: iconst_2 10: istore_2 11: iload_2 12: iload_1 13: if_icmpge 31 Java Overview Source Code: MUST be named Hello.java public class Hello{ public static void main(String[] args){ System.out.println(“Hello World!”); } } Bytecode: will be saved as Hello.class 0: iconst_2 1: istore_1 2: iload_1 3: sipush 1000 _main _TEXT SEGMENT _argc$ = 8 _argv$ = 12 _main PROC NEAR ; COMDAT 0000 68 00 00 00 00 push 00005 e8 00 00 00 00 call 0000a 83 c4 04 add esp, 0000d 33 c0 xor eax, Mac Windows FLAT:??_C@_0M@ KPLPPDAC@Hello?5 World?$AA@ 00005 e8 00 00 00 00 0000a 83 Hello World! Unix Whatever So, what about Eclipse? • What is eclipse? • How does it work? • What languages will it work for?