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

Post on 19-Dec-2015

224 views 3 download

Tags:

Transcript of 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

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.

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.

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.

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.

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.

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.

8

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

9

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

10

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

11

Installing Standard- Installing Standard- Java 2 SDKJava 2 SDK

12

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

13

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

Test it by typing javac in other directory

14

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

• javap.exe decompiler• jdb.exe debugger

15

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

16

Explanation to the first programExplanation to the first program

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

18

Second ProgramSecond Program

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

20

Applet (1)Applet (1)

21

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

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

23

Javadoc - Javadoc - Document GeneratorDocument Generator

24

Javadoc – some exampleJavadoc – some example

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.

26

Javap – decompilerJavap – decompiler

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.

28

Jdb – DebuggerJdb – Debugger

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

30

Jdb – helpJdb – help

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.