A Look at Java. Categorize Java Which paradigm? Which paradigm? Scripting? Scripting? Declarative or...

12
A Look at Java A Look at Java

Transcript of A Look at Java. Categorize Java Which paradigm? Which paradigm? Scripting? Scripting? Declarative or...

Page 1: A Look at Java. Categorize Java Which paradigm? Which paradigm? Scripting? Scripting? Declarative or procedural? Declarative or procedural? Which generation?

A Look at JavaA Look at Java

Page 2: A Look at Java. Categorize Java Which paradigm? Which paradigm? Scripting? Scripting? Declarative or procedural? Declarative or procedural? Which generation?

Categorize JavaCategorize 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?

Page 3: A Look at Java. Categorize Java Which paradigm? Which paradigm? Scripting? Scripting? Declarative or procedural? Declarative or procedural? Which generation?

How Programming Works: Pre-How Programming Works: Pre-JavaJava1.1. Programmer types a Programmer types a

program into a program into a text text editoreditor. .

• This code is called the This code is called the source codesource code. .

• It is saved as a file on It is saved as a file on your computer, much like your computer, much like any other file you create. any other file you create.

• Since the code is human-Since the code is human-readable, it is usually kept readable, it is usually kept private.private.

#include <iostream.h>

main(){ cout << "Hello World!"; return 0;}

Page 4: A Look at Java. Categorize Java Which paradigm? Which paradigm? Scripting? Scripting? Declarative or procedural? Declarative or procedural? Which generation?

How Programming Works: Pre-How Programming Works: Pre-JavaJava1.1. Source CodeSource Code

2.2. A program called a A program called a compilercompiler reads the reads the code and makes code and makes machine codemachine code instructions specific to instructions specific to the type of machine you the type of machine you are running on.are running on.

• This code is NOT human-This code is NOT human-readable.readable.

• This is what comes on This is what comes on software CDs, so that the software CDs, so that the code remains proprietary.code remains proprietary.

#include <iostream.h>

main(){ cout << "Hello World!"; return 0;}

_main _TEXT SEGMENT_argc$ = 8 _argv$ = 12 _main PROCNEAR ; 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

Compiler

Page 5: A Look at Java. Categorize Java Which paradigm? Which paradigm? Scripting? Scripting? Declarative or procedural? Declarative or procedural? Which generation?

How Programming Works: Pre-How Programming Works: Pre-JavaJava1.1. Source CodeSource Code

2.2. Compiled to Machine Compiled to Machine CodeCode

3.3. Run on the computerRun on the computer- Now the program can be run, - Now the program can be run,

but only on the machine it but only on the machine it was compiled for.was compiled for.

#include <iostream.h>

main(){ cout << "Hello World!"; return 0;}

_main _TEXT SEGMENT_argc$ = 8 _argv$ = 12 _main PROCNEAR ; 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

Compiler

Hello World!

Executed by a machine with Intel 32-bit processor

Page 6: A Look at Java. Categorize Java Which paradigm? Which paradigm? Scripting? Scripting? Declarative or procedural? Declarative or procedural? Which generation?

Java Programming Java Programming LanguageLanguage• James Gosling, Sun Microsystems, James Gosling, Sun Microsystems,

19911991• Idea: Want a computer application to Idea: Want a computer application to

control the appliances in a homecontrol the appliances in a home• But - different chips on eachBut - different chips on each• Need: Programming language that Need: Programming language that

works on any machineworks on any machine• 3 years later, Internet hits, and we 3 years later, Internet hits, and we

realize portability is a realize portability is a great ideagreat idea……

Page 7: A Look at Java. Categorize Java Which paradigm? Which paradigm? Scripting? Scripting? Declarative or procedural? Declarative or procedural? Which generation?

How Java Programming WorksHow Java Programming Works1.1. Programmer types a Programmer types a

program into a program into a text text editoreditor. .

• This code is called the This code is called the source codesource code. .

• It is saved as a file on It is saved as a file on your computer, much like your computer, much like any other file you create. any other file you create.

• Since the code is human-Since the code is human-readable, it is usually kept readable, it is usually kept private.private.

public class Hello{ public static void main(

String[] args){ System.out.println(

“Hello World!”); }}

Page 8: A Look at Java. Categorize Java Which paradigm? Which paradigm? Scripting? Scripting? Declarative or procedural? Declarative or procedural? Which generation?

How Java Programming WorksHow Java Programming Works1.1. Source CodeSource Code

2.2. The Java The Java compilercompiler reads the code and reads the code and makes an intermediate makes an intermediate code called code called bytecodebytecode..

• Again, this code is NOT Again, this code is NOT human-readable.human-readable.

• Again, this is what comes Again, this is what comes on software CDs, so that on software CDs, so that the code remains the code remains proprietary.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 1000 6: 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

Page 9: A Look at Java. Categorize Java Which paradigm? Which paradigm? Scripting? Scripting? Declarative or procedural? Declarative or procedural? Which generation?

How Java Programming WorksHow Java Programming Works1.1. Source CodeSource Code

2.2. Compiled to BytecodeCompiled to Bytecode

3.3. Interpreted by JVM (Java Interpreted by JVM (Java Virtual Machine) This Virtual Machine) This program reads bytecode program reads bytecode and translates it directly and translates it directly to whatever machine to whatever machine code is needed.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 PROCNEAR ; 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

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

Page 10: A Look at Java. Categorize Java Which paradigm? Which paradigm? Scripting? Scripting? Declarative or procedural? Declarative or procedural? Which generation?

How Java Programming WorksHow Java Programming Works1.1. Source CodeSource Code

2.2. Compiled to BytecodeCompiled to Bytecode

3.3. Interpreted by JVM to Interpreted by JVM to Machine CodeMachine Code

4.4. Executed by machineExecuted by machine

public class Hello{ public static void main(

String[] args){ System.out.println(

“Hello World!”); }}

_main _TEXT SEGMENT_argc$ = 8 _argv$ = 12 _main PROCNEAR ; 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

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

Hello World!

Page 11: A Look at Java. Categorize Java Which paradigm? Which paradigm? Scripting? Scripting? Declarative or procedural? Declarative or procedural? Which generation?

Java OverviewJava Overviewpublic 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!

FLAT:??_C@_0M@KPLPPDAC@Hello?5World?$AA@00005 e8 00 00 00 000000a 83

NEAR ; COMDAT 0000 68 00 00 00 00 push00005 e8 00 00 00 00 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

MacWhatever

UnixWindows

Page 12: A Look at Java. Categorize Java Which paradigm? Which paradigm? Scripting? Scripting? Declarative or procedural? Declarative or procedural? Which generation?

So, what about Eclipse?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?