Download Introduction to Java and Applet

Survey
yes no Was this document useful for you?
   Thank you for your participation!

* Your assessment is very important for improving the work of artificial intelligence, which forms the content of this project

Document related concepts
no text concepts found
Transcript
Introduction to
Java and Applet
Lecture 3 from Chapters 1
and 2 of the complete
reference
1
Java’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.
2
Java and the Internet
• Java is a portable, platformindependent 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.
3
Java 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.
4
Security
• Without Java, Once you are downloading
an executable program, there is a risk of
viral infection.
• If it is written in Java using Javacompatible browser, it is pretty safe.
• Java also provides a “firewall” between a
networked application and our PC to safeguard information such as credit card
number, bank account balance.
5
Java’s Merit-
Interpreter 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.
6
Java Overview –
some 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.
7
Download Java Compiler (1)
8
Download Java Compiler (2)
9
Download Java SDK (3)
10
Installing StandardSDK
Java 2
11
Installation -
check whether you
have installed java and javac
12
Set the path to include the directory
Test it by typing javac in other directory
13
JDK components
• appletviewer.exe
• java.exe
• javac.exe
• javadoc.exe
• javap.exe
• jdb.exe
applet viewer
intepreter
compiler
document generator
decompiler
debugger
14
A simple Program – javac & java
15
Explanation to the first program
16
Explanation 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
17
Second Program
18
Second Program Explanation
• 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
19
Applet (1)
20
Applet (2) – the result
21
Explanation 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
22
Javadoc - Document Generator
23
Javadoc – some example
24
Javadoc.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.
25
Javap – decompiler
26
Javap - 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.
27
Jdb – Debugger
28
Jdb - 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
29
Jdb – help
30
Summary
• Java is related to C+.
• Java is a direct descendent of C.
• Java’s object-oriented features were
influenced by C++
• It is ideal for client [windows]-server
[Linux] platform.
31