8/6/2019 Microsoft Power Point - ILP J2EE Stream CoreJava 01 Introduction V0.2
1/20
23October2007
Introd
uctionto
Java
Vers
ion
1.0
8/6/2019 Microsoft Power Point - ILP J2EE Stream CoreJava 01 Introduction V0.2
2/20
2
23Octobe
r2007
CourseO
bjec
tive
The
Objectiveo
fJavacou
rse
is:
Tounders
tan
dbas
icp
rogramm
ingco
ncep
tsus
ingJava
syn
tax.
Toapprec
iateOOPco
ncep
tsan
dencouragepro
blem
so
lving
us
ing
OOPtec
hn
iques
.
Tounders
tan
dvarious
Java
APIand
how
touse
them
effectiv
elyinpro
jec
ts.
Tounders
tan
dthenee
dforexcep
tion
han
dlingand
how
to
use
inJavaenv
ironme
nt.
8/6/2019 Microsoft Power Point - ILP J2EE Stream CoreJava 01 Introduction V0.2
3/20
3
23Octobe
r2007
Wha
tisJ
ava
?
Java
isboth:
AProgramm
ing
language
APlatform
8/6/2019 Microsoft Power Point - ILP J2EE Stream CoreJava 01 Introduction V0.2
4/20
4
23Octobe
r2007
TheJav
aProgrammingLa
nguage
Java
isan
Objec
tOriente
dProgramm
ing
language
.
Java
ssyn
tax
iss
imilarto
C/C++syntax
.
Java
isbothcomp
iledand
interpre
ted
.
The
interm
ediateform
isc
alledJava
byte
co
de
,w
hichis
platform
indepen
den
t.
By
teco
des
are
interpre
tedby
JVMduringrun
time
.
8/6/2019 Microsoft Power Point - ILP J2EE Stream CoreJava 01 Introduction V0.2
5/20
5
23Octobe
r2007
JavaPl
atform
The
JavaP
latform
has
twocomponen
ts:
The
Java
Virtua
lMach
ine
(JVM)
The
Java
App
lica
tion
Programm
ingIn
terface
(JavaA
PI)
8/6/2019 Microsoft Power Point - ILP J2EE Stream CoreJava 01 Introduction V0.2
6/20
6
23Octobe
r2007
The
Java
Platform
The
JavaV
Misbase
forJ
avap
latforman
disporte
don
to
various
hardware-b
ase
da
ndOSbasedp
latforms
.
The
JavaA
PIisa
largeco
llec
tiono
fread
y-m
ade
,freque
ntly
use
dc
lass
libraries
,s
tore
dinpac
kages.
8/6/2019 Microsoft Power Point - ILP J2EE Stream CoreJava 01 Introduction V0.2
7/20
7
23Octobe
r2007
The
Java
Env
ironmen
tJava
Program
Jav
aVirtua
lmac
hine
Native
OS/Platform
Java
API
JAVA
PLATFO
RM
8/6/2019 Microsoft Power Point - ILP J2EE Stream CoreJava 01 Introduction V0.2
8/20
8
23Octobe
r2007
ASimpleJavaProgram
/**Thisisour
firs
tJava
Pro
gram
*/
class
FirstC
lass
{ pu
blics
taticvo
idma
in(Str
ingargs
[])
{
System
.ou
t.prin
tln(
He
lloWorl
d.);
}}
8/6/2019 Microsoft Power Point - ILP J2EE Stream CoreJava 01 Introduction V0.2
9/20
9
23Octobe
r2007
CompilingandR
unningin
Eclipse
8/6/2019 Microsoft Power Point - ILP J2EE Stream CoreJava 01 Introduction V0.2
10/20
10
23Octobe
r2007
JavaDataTypes
Twomajor
da
tatypes
Prim
itiv
e
Because
javaprogra
mhas
torunon
differen
tarch
itec
ture
an
dO
S,
thes
izeof
the
da
tas
hould
rema
insame.
Otherw
ise
,on
differe
ntmac
hinesth
eou
tpu
tw
illbe
differen
t
Re
ference
Allob
jec
tsareo
ftyp
ere
ference
datatype
.Java
do
esn
t
allow
direc
tly
toacce
ssmemory
.Bu
to
bjec
tsarere
fere
d
bypo
interson
ly.
8/6/2019 Microsoft Power Point - ILP J2EE Stream CoreJava 01 Introduction V0.2
11/20
11
23Octobe
r2007
Primitiv
eDataTy
pes
In
tegers
by
te
(8bit)
s
hort
(16bit)
int
(32bit)
long
(64bit)
8/6/2019 Microsoft Power Point - ILP J2EE Stream CoreJava 01 Introduction V0.2
12/20
12
23Octobe
r2007
Prim
itive
Da
taTypes
Rea
lNumb
ers
floa
t
(32bit)
dou
ble
(64bit)
Other
Type
s
c
har
(16bit)
boo
lean
(true
/false
)
8/6/2019 Microsoft Power Point - ILP J2EE Stream CoreJava 01 Introduction V0.2
13/20
13
23Octobe
r2007
Re
ferenc
eDa
taType
s
Examp
les:
Arrays
Strings
Objects
Interfac
es
Thename
referencemeansapo
inter
inthememory
.All
objec
tsare
referre
dby
the
irmemory
loca
tionon
ly.
Butuser
canno
tdire
ctlyaccessme
mory
loca
tion.
Memorym
anagemen
tista
kencare
byJ
VMitse
lf.
8/6/2019 Microsoft Power Point - ILP J2EE Stream CoreJava 01 Introduction V0.2
14/20
14
23Octobe
r2007
Varia
bleNames
Varia
blenames
inJavaare
lega
lJavaiden
tifiercompris
edo
fa
serieso
fU
nico
dec
haracters
.
Varia
blenamesmus
tnot
be
Java
keywordora
boo
lean
litera
l
Samevaria
blenames
hou
ldno
tappeartw
icew
ithinascope
.
8/6/2019 Microsoft Power Point - ILP J2EE Stream CoreJava 01 Introduction V0.2
15/20
15
23Octobe
r2007
JavaOpe
rators
Ari
thme
tic
Opera
tors
+,
-,*,/,%
Unary
Arith
me
tic
Opera
tors
++
,--
Re
lational
an
dCon
ditiona
lOpera
tors
>,
>=
,
,>
,&
,|,^,
~
Ternary
Opera
tor:
()?():()
8/6/2019 Microsoft Power Point - ILP J2EE Stream CoreJava 01 Introduction V0.2
16/20
16
23Octobe
r2007
Con
trolF
low
Dec
isionm
aking
if
-else,
sw
itc
h-c
ase
Loop
for,wh
ile,
do-w
hile
Excep
tion
try-c
atc
h-f
ina
lly,
throw
Misce
llane
ous
Break,
con
tinue
,label:,re
turn
8/6/2019 Microsoft Power Point - ILP J2EE Stream CoreJava 01 Introduction V0.2
17/20
17
23Octobe
r2007
Arraysin
Java
Javaarraysareo
bjec
ts.
Arrayconta
ins
like-t
ypedva
lues
.
Arraycancon
tainbo
thpr
imitivean
dre
ference
da
tatype
s.
Whenuse
dw
ithre
ference
da
tatypes
,reference
(memory
loca
tion
)is
on
lys
tore
dinarraysan
dnot
therea
lo
bjects
.
Javasupportsmu
ltidimens
iona
larrays.
Theyareno
thin
gbu
t
arrayo
far
rays
.
8/6/2019 Microsoft Power Point - ILP J2EE Stream CoreJava 01 Introduction V0.2
18/20
18
23Octobe
r2007
Arraysin
Java
Array
Dec
lara
tion
intmyIn
tegers
[];
int[]my
Integers;
Arraymem
orya
lloca
tion:
intmyIn
tegers
[]=new
int[10];
Array
Initia
liza
tion:
intmyIn
tegers
[]=
{1,2,3,4,5
};
8/6/2019 Microsoft Power Point - ILP J2EE Stream CoreJava 01 Introduction V0.2
19/20
19
23Octobe
r2007
Stringsin
Java
Asequenc
eo
fc
harac
ters
isencapsu
latedasa
Stringo
bjec
t.
Javauses
+opera
tor
for
Stringconcatena
tion
.
Someuse
fulString
functionsare:
s
.lengt
h();
s
1.e
qua
ls(s2);
s
1.s
ubString
(in
ts
tartIn
dex
,intup
To);
8/6/2019 Microsoft Power Point - ILP J2EE Stream CoreJava 01 Introduction V0.2
20/20
20
23Octobe
r2007
Summa
ry
Inthisse
ssionyoule
arnedabout:
JavaProgrammingLanguage
JavaPlatform
JavaEnvironment
FirstJ
avaProgram
DataTypes
Opera
tors
ControlFlow
JavaArraysandS
trings