1 introduction to java and applet lecture 3 from chapters 1 and 2 of the complete reference

31
1 Introduction to Introduction to Java and Applet Java and Applet Lecture 3 Lecture 3 from Chapters 1 from Chapters 1 and 2 of the complete and 2 of the complete reference reference

Post on 19-Dec-2015

226 views

Category:

Documents


3 download

TRANSCRIPT

Page 1: 1 Introduction to Java and Applet Lecture 3 from Chapters 1 and 2 of the complete reference

1

Introduction to Introduction to Java and AppletJava and AppletLecture 3Lecture 3 from Chapters 1 from Chapters 1

and 2 of the complete and 2 of the complete referencereference

Page 2: 1 Introduction to Java and Applet Lecture 3 from Chapters 1 and 2 of the complete reference

2

Java’s LineageJava’s Lineage• Java is related to C+.• Java is a direct descendent of C.• Java’s object-oriented features were

influenced by C++• Java was developed by James Gosling

etc. at Sun Mircosystems in 1991.• It was called “oak” and was renamed

as Java.

Page 3: 1 Introduction to Java and Applet Lecture 3 from Chapters 1 and 2 of the complete reference

3

Java and the InternetJava and the Internet• Java is a portable, platform-

independent language that could be used to produce code that would run on different platform.

• Java expands the universe of objects that can move freely in Cyberspace.

• It is ideal for client [windows]-server [linux] platform.

Page 4: 1 Introduction to Java and Applet Lecture 3 from Chapters 1 and 2 of the complete reference

4

Java AppletsJava Applets• Java supports two types of programs:

applications and applets• An application: It is a program that

runs on our PC under windows XP.• An applet: It is a tiny Java program,

dynamically downloaded across the network, like music, video clip.

Page 5: 1 Introduction to Java and Applet Lecture 3 from Chapters 1 and 2 of the complete reference

5

SecuritySecurity• Without Java, Once you are downloading

an executable program, there is a risk of viral infection.

• If it is written in Java using Java-compatible browser, it is pretty safe.

• Java also provides a “firewall” between a networked application and our PC to safe-guard information such as credit card number, bank account balance.

Page 6: 1 Introduction to Java and Applet Lecture 3 from Chapters 1 and 2 of the complete reference

6

Java’s Merit- Java’s Merit- Interpreter and BytecodeInterpreter and Bytecode

• Java that resolves security and portability problems is because the output of a Java Compiler is not executable code (not .exe or .com).

• It is bytecode. • Bytecode is an optimised codes to be

executed by the Java Run Time system.• Java run-time system is an interpreter.

Page 7: 1 Introduction to Java and Applet Lecture 3 from Chapters 1 and 2 of the complete reference

7

Java Overview – Java Overview – some key elementssome key elements

• Simple: simple and easy to learn • Object-oriented: Clean, usable approach to

objects• Robust: reliable under different operating

environments across the networks (The Internet)

• Mutlithreaded: supports a few light weight processes

• Interpreted: Although it is an interpreted language, the performance is good.

Page 8: 1 Introduction to Java and Applet Lecture 3 from Chapters 1 and 2 of the complete reference

8

Download Java Compiler (1)Download Java Compiler (1)

Page 9: 1 Introduction to Java and Applet Lecture 3 from Chapters 1 and 2 of the complete reference

9

Download Java Compiler (2)Download Java Compiler (2)

Page 10: 1 Introduction to Java and Applet Lecture 3 from Chapters 1 and 2 of the complete reference

10

Download Java SDK (3)Download Java SDK (3)

Page 11: 1 Introduction to Java and Applet Lecture 3 from Chapters 1 and 2 of the complete reference

11

Installing Standard- Installing Standard- Java 2 SDKJava 2 SDK

Page 12: 1 Introduction to Java and Applet Lecture 3 from Chapters 1 and 2 of the complete reference

12

Installation - Installation - check whether you check whether you have installed java and javac have installed java and javac

Page 13: 1 Introduction to Java and Applet Lecture 3 from Chapters 1 and 2 of the complete reference

13

Set the path to include the directory Set the path to include the directory

Test it by typing javac in other directory

Page 14: 1 Introduction to Java and Applet Lecture 3 from Chapters 1 and 2 of the complete reference

14

JDK componentsJDK components• appletviewer.exe applet viewer• java.exe intepreter• javac.exe compiler• javadoc.exe document generator

• javap.exe decompiler• jdb.exe debugger

Page 15: 1 Introduction to Java and Applet Lecture 3 from Chapters 1 and 2 of the complete reference

15

A simple ProA simple Program – javac & javagram – javac & java

Page 16: 1 Introduction to Java and Applet Lecture 3 from Chapters 1 and 2 of the complete reference

16

Explanation to the first programExplanation to the first program

Page 17: 1 Introduction to Java and Applet Lecture 3 from Chapters 1 and 2 of the complete reference

17

Explanation to the first programExplanation to the first program• Class: First is the name of class. It will

generate a First.class after compilation (javac)

• Public: is an access specifier that allows the programmer to control

• Main(): must be declared as public so that it can be accessed.

• String args[]: argv[0] is the first argument• System.out.println: Display the contents

followed by a line feed

Page 18: 1 Introduction to Java and Applet Lecture 3 from Chapters 1 and 2 of the complete reference

18

Second ProgramSecond Program

Page 19: 1 Introduction to Java and Applet Lecture 3 from Chapters 1 and 2 of the complete reference

19

Second Program - Second Program - ExplanationExplanation

• int num; declares an integer valuable called num

• Num = 10; assign a value of 10• System.out.println("The value of num

is " + num); The “+” causes the value of num to be displayed

• .println() ; displays the string passed • .print(); display the string without

line feed

Page 20: 1 Introduction to Java and Applet Lecture 3 from Chapters 1 and 2 of the complete reference

20

Applet (1)Applet (1)

Page 21: 1 Introduction to Java and Applet Lecture 3 from Chapters 1 and 2 of the complete reference

21

Applet (2) – the resultApplet (2) – the result

Page 22: 1 Introduction to Java and Applet Lecture 3 from Chapters 1 and 2 of the complete reference

22

Explanation to AppletExplanation to Applet• Prepare a java

program called third

• In the HTML, specify the class of the program (third)

• Use appletviewer or IE explorer to see the result

Page 23: 1 Introduction to Java and Applet Lecture 3 from Chapters 1 and 2 of the complete reference

23

Javadoc - Javadoc - Document GeneratorDocument Generator

Page 24: 1 Introduction to Java and Applet Lecture 3 from Chapters 1 and 2 of the complete reference

24

Javadoc – some exampleJavadoc – some example

Page 25: 1 Introduction to Java and Applet Lecture 3 from Chapters 1 and 2 of the complete reference

25

Javadoc.exeJavadoc.exe

• Javadoc is a tool shipped with JDK that generates HTML documentation from the comments in the class source files.

• With the aid of Javadoc we can simplify documentation of our code and make it a regular habit.

Page 26: 1 Introduction to Java and Applet Lecture 3 from Chapters 1 and 2 of the complete reference

26

Javap – decompilerJavap – decompiler

Page 27: 1 Introduction to Java and Applet Lecture 3 from Chapters 1 and 2 of the complete reference

27

Javap - explanationJavap - explanation• The javap

command disassembles a class file.

• Its output depends on the options used. If no options are used, javap prints out the package.

Page 28: 1 Introduction to Java and Applet Lecture 3 from Chapters 1 and 2 of the complete reference

28

Jdb – DebuggerJdb – Debugger

Page 29: 1 Introduction to Java and Applet Lecture 3 from Chapters 1 and 2 of the complete reference

29

Jdb - explanationJdb - explanation• The Java Debugger, jdb, is a simple

command-line debugger for Java classes.

• It provides inspection and debugging of a local or remote Java Virtual Machine.

• Jdb class format

Page 30: 1 Introduction to Java and Applet Lecture 3 from Chapters 1 and 2 of the complete reference

30

Jdb – helpJdb – help

Page 31: 1 Introduction to Java and Applet Lecture 3 from Chapters 1 and 2 of the complete reference

31

SummarySummary• Java is related to C+.• Java is a direct descendent of C.• Java’s object-oriented features were in

fluenced by C++• It is ideal for client [windows]-server [Lin

ux] platform.