lect2 intro javatechnology
TRANSCRIPT
-
8/10/2019 Lect2 Intro Javatechnology
1/41
JAVSpring 2013
Lecture 1Introduction to Java Technology
-
8/10/2019 Lect2 Intro Javatechnology
2/41
Duc L. M. JAV Spring 2013 2
Lecture outline
Basic terminologies Java programming language Java platform Java virtual machine
-
8/10/2019 Lect2 Intro Javatechnology
3/41
Duc L. M. JAV Spring 2013 3
MyProgram.java
Host platforms
Basic terminologies1
Java virtual machine
APIJava platforms
Java language
-
8/10/2019 Lect2 Intro Javatechnology
4/41
Duc L. M. JAV Spring 2013 4
Java programming language
Brief history Language features The HelloWorldApp.java program
2
-
8/10/2019 Lect2 Intro Javatechnology
5/41
-
8/10/2019 Lect2 Intro Javatechnology
6/41
Duc L. M. JAV Spring 2013 6
Brief history (2)
"imilar in synta# to $%$&&: but omits comple#! confusing! unsafe features
"upported by web browsers via e#tensions: Java programs are 'embedded( in HT)L pages
*esign and architecture decisions drew from+iffel! "mallTal ! ,b-ective $! and $edar%)esa
-
8/10/2019 Lect2 Intro Javatechnology
7/41Duc L. M. JAV Spring 2013 7
Language features
"imple! ob-ect oriented! familiar .obust and secure Architecture neutral and portable High performance Interpreted! threaded! and dynamic
-
8/10/2019 Lect2 Intro Javatechnology
8/41Duc L. M. JAV Spring 2013 8
he HelloWorldApp.java program
public class HelloWorldApp { public static void main(String[] args {
System.out.println(!Hello World"! #
$$
-
8/10/2019 Lect2 Intro Javatechnology
9/41Duc L. M. JAV Spring 2013 9
!eveloping a Java program
An overview of the software development process
javac MyProgram.javajavac MyProgram.java java MyProgramjava MyProgram
-
8/10/2019 Lect2 Intro Javatechnology
10/41Duc L. M. JAV Spring 2013 10
Java Application programminginterface (A"#)
A collection of ready/made components thatprovide useful capabilities
0rouped into libraries nown as packages
-
8/10/2019 Lect2 Intro Javatechnology
11/41Duc L. M. JAV Spring 2013 11
Java platform (1)
A software/based platform in which Javaprograms run
.uns on top of other hardware/based platforms!e1g1 2indows! Linu#! etc1
3
-
8/10/2019 Lect2 Intro Javatechnology
12/41Duc L. M. JAV Spring 2013 12
Java platform (2)
*esigned for classes of host platforms and%orapplications
+#amples of host platform classes:
small devices: restricted configuration P$s: standard hardware configuration servers: high performance configuration
+#amples of application classes: stand alone small scale large scale
-
8/10/2019 Lect2 Intro Javatechnology
13/41Duc L. M. JAV Spring 2013 13
Java platform (3)
*iffer in the J3) implementations and%or APIfeatures:
host re4uirements 5 different J3) implementations
application re4uirements 5 different API features Three main platforms:
Java S$ Java ++ Java )+
-
8/10/2019 Lect2 Intro Javatechnology
14/41Duc L. M. JAV Spring 2013 14
Java S$
Java "tandard +dition Provides core functionality:
basic types and ob-ects programming abstractions for networ ing! security!
database access! 06I development and 7)Lparsing
$ommon development tools and deploymenttechnologies
-
8/10/2019 Lect2 Intro Javatechnology
15/41
Duc L. M. JAV Spring 2013 15
Java S$ platform
threa%
-
8/10/2019 Lect2 Intro Javatechnology
16/41
Duc L. M. JAV Spring 2013 16
Java S$ focus in this mo%ule
threa%
-
8/10/2019 Lect2 Intro Javatechnology
17/41
Duc L. M. JAV Spring 2013 17
!es&top application
HelloWorldApplication
!$'
-
8/10/2019 Lect2 Intro Javatechnology
18/41
Duc L. M. JAV Spring 2013 18
Applet
HelloWorldApplet
!$'
-
8/10/2019 Lect2 Intro Javatechnology
19/41
-
8/10/2019 Lect2 Intro Javatechnology
20/41
Duc L. M. JAV Spring 2013 20
Java '$
Java )obile +dition *esigned for small devices
e1g1 mobile phones Provides API and a small/footprint J3) API 8 subset of Java "+ API & libraries for small
device applications Java )+ applications often interact with Java
++ platform services
-
8/10/2019 Lect2 Intro Javatechnology
21/41
Duc L. M. JAV Spring 2013 21
'o ile application
HelloWorldMidlet
!$'
-
8/10/2019 Lect2 Intro Javatechnology
22/41
Duc L. M. JAV Spring 2013 22
Java virtual machine
,verview and features Program e#ecution cycle ,ther selected topics:
"tac memory Heap memory
*
-
8/10/2019 Lect2 Intro Javatechnology
23/41
Duc L. M. JAV Spring 2013 23
vervie+ (1)
The J3) is the base for the Java platform )a es Java programs platform independent:
'write once! run anywhere( *ifferent versions e#ist for different hardware/
based platforms
-
8/10/2019 Lect2 Intro Javatechnology
24/41
Duc L. M. JAV Spring 2013 24
vervie+ (2)
-
8/10/2019 Lect2 Intro Javatechnology
25/41
Duc L. M. JAV Spring 2013 25
,eatures
An abstract computing machine with: instruction set memory management
+mulates the host machines to ensure platform/independent byte codes
*oes not re4uire Java programming language
supports any language that follows the class fileformat
-
8/10/2019 Lect2 Intro Javatechnology
26/41
-
8/10/2019 Lect2 Intro Javatechnology
27/41
Duc L. M. JAV Spring 2013 27
Virtual machine start up
The method main is invo ed with argumentString[] :
header: public static void main String[] ;
argument is a nullable String array Invocation is typically from the command line:
java HelloWorldApp say %ello &orld"
-
8/10/2019 Lect2 Intro Javatechnology
28/41
Duc L. M. JAV Spring 2013 28
HelloWorldApp +ith arguments
public class HelloWorldApp { public static void main(String[] args {
'or (int i )# i * args.lengt%# i++ {
System.out.println(args[i]); $
$
$
-
8/10/2019 Lect2 Intro Javatechnology
29/41
Duc L. M. JAV Spring 2013 29
Loa%ing
$lass HelloWorldApp is loaded by,lass-oader
The loaded class is an ob-ect of class ,lass cached for subse4uent use
Loading may fail due to: incorrect class file format
incorrect version of the class file format not found
-
8/10/2019 Lect2 Intro Javatechnology
30/41
Duc L. M. JAV Spring 2013 30
Lin&ing
$ombines the loaded class into the runtimestate of the J3)
Three steps:
verification : chec the class structure preparation : creating and initialising class fields to
default values resolution : resolve references to other classes
-
8/10/2019 Lect2 Intro Javatechnology
31/41
Duc L. M. JAV Spring 2013 31
#nitialisation
+#ecute initialisers: class static; initialisers initialisers for static fields
Also causes any super class es; to be loaded!lin ed and initialised: if not already
-
8/10/2019 Lect2 Intro Javatechnology
32/41
Duc L. M. JAV Spring 2013 32
.reation of ne+ class instances
,b-ects are created if re4uired ,b-ect creation involves:
allocating enough memory space for all variables
declared in the class and super class; initialising the variables e#ecuting a constructor method
-
8/10/2019 Lect2 Intro Javatechnology
33/41
Duc L. M. JAV Spring 2013 33
HelloWorldApp +ith o /ects
public class HelloWorldApp { public static void main(String[] args {
String msg = "Hello orld!";
// or String msg = ne String( Hello orld!#); System.out.println(msg #
$
$
-
8/10/2019 Lect2 Intro Javatechnology
34/41
Duc L. M. JAV Spring 2013 34
,inalisation of class instances
.emove ob-ects that are no longer in use Java garbage collector automatically remove
ob-ects these
9inali
-
8/10/2019 Lect2 Intro Javatechnology
35/41
Duc L. M. JAV Spring 2013 35
nloa%ing
6nload unused classes to reduce memory use A class is unloaded when its associated
,lass-oader is removed
"ystem classes may never be unloaded
-
8/10/2019 Lect2 Intro Javatechnology
36/41
Duc L. M. JAV Spring 2013 36
Virtual machine e-it
2hen one of two things happens: all non/daemon processes threads; finish e#ecution invo es System.e2it or 3un4ime.e2it
-
8/10/2019 Lect2 Intro Javatechnology
37/41
Duc L. M. JAV Spring 2013 37
Stac&s
+ach program thread has a stac to: hold local variables and partial results used in method invocation and return
"tac /overflow error is thrown if a stac runs outof memory "tac si
-
8/10/2019 Lect2 Intro Javatechnology
38/41
Duc L. M. JAV Spring 2013 38
Specifying threa% stac& si e
To specify a =) stac si
-
8/10/2019 Lect2 Intro Javatechnology
39/41
Duc L. M. JAV Spring 2013 39
eap
A run/time memory shared among all J3)threads: created on J3) start up
6sed for storing ob-ects Heap space is reclaimed by a garbage collector ,ut/of/memory error is thrown if heap runs out
of space Heap si
-
8/10/2019 Lect2 Intro Javatechnology
40/41
Duc L. M. JAV Spring 2013 40
eap
To specify initial and ma# heap si
-
8/10/2019 Lect2 Intro Javatechnology
41/41
Summary
Java technology includes Java language!platform! virtual machine and API Java language is ob-ect oriented! robust! and
architecture neutral *ifferent types of Java platforms designed for
different classes of hosts and applications Java "+! ++! )+
Java virtual machine is a software abstraction ofthe host! ma ing Java programs platformindependent