You are on page 1of 7

Name:

Shr
uti
kaVet
al

Rol
lno.
:16

Jav
aPr
ogr
ammi
ng(
JPR)
(22412)
Pr
act
icalNo.
1and2:Set upaJavaprogr
ammi ngdev
elopment
env
ironmentandtestusi
ngsmallpr
ogram.

Q.
1Pr
act
ical
Rel
atedQuest
ions:
-

1.Wr
it
einst
all
ati
ondi
rect
orypat
hofy
ourdi
rect
ory
?

Ans.
:Inst
all
ati
onDi
rect
orypat
h:-

a.Got
oMy
Comput
erpr
oper
ti
es.

b.Cl
ickont
headv
ancedt
ab.

c.Cl
ickonenv
ironmentv
ari
abl
es.

d.Wr
it
ethepat
hint
hev
ari
abl
ename.

e.Copyt
hepat
hofbi
nfol
der
.

f
.Past
epat
hofbi
nfol
deri
nthev
ari
abl
eval
ue

g.Cl
ickonokbut
ton.

2.Wr
it
eval
ueofpat
henv
ironmentv
ari
abl
e?

Ans.
:C:
\Pr
ogr
amFi
les\
Jav
a\j
dk-
16\
bin

3.Li
stf
older
scr
eat
edaf
teri
nst
all
ati
on.

Ans.
:bi
n

conf

i
ncl
ude
j
mods

l
egal

l
ib

copy
right

r
elease

4.Mai
nmet
hodi
sdecl
aredasst
ati
c.Just
if
y.

Ans.:Javamai n()methodisalwaysstatic,sothatcompilercancallit
withoutthecreationofanobjectorbeforet hecreati
onofanobj ectofthe
class.I
nanyj avaprogram,themai n(
)met hodist hestar
tingpointfr
om
wher ecompilerstart
sprogram executi
on.So, t
hecompi lerneedstocall
themai n()method.

5.Pr
ogr
am i
snamedwi
thcl
asscont
aini
ngmai
nmet
hod.

Ans.:Al
ljavaprogramsmusthav eanentrypoi
nt,
whichisal
way sthe
main()method.Whenev erthepr
ogram i
scall
ed,i
tautomati
cal
lyexecut
es
themain()methodf i
rst
.Themainclasscanhaveanyname, al
though
typi
call
yitwil
ljustbecall
ed“Main”
.

_
___
___
___
___
___
___
___
___
___
___
___
___
___
_

Q.
1Exer
cise:
-

1)Wr
it
etheopt
ionspr
ovi
dedbyf
oll
owi
ngJDKt
ool
sal
ongwi
tht
hei
ruse

1.j
ava

2.j
avac

3.j
avadoc

Ans.
:

1.j
ava–Thej
avacommandst
art
saJav
aappl
icat
ion.I
tdoest
hisby
star
t i
ngaJavarunti
meenv
ironment
,loadi
ngaspeci
fi
edcl
ass,
and
call
ingthatcl
ass’
smainmethod.

Opt
ionspr
ovi
dedi
njav
a:-

i
.cl
ass–t
henameoft
hecl
asst
obecal
led.

i
i.fil
e.j
ar–t
henameoft
heJARf
il
etobecal
led.Usedonl
ywi
tht
he
command.

i
ii
.ar
gument
s–t
hear
gument
spassedt
othemai
nfunct
ion.

2.javac–Thej avact
oolr
eadst hecl
assinter
facedef
ini
ti
ons,writt
enin
theJav aprogrammingl
anguage,andcompi l
esthem i
ntobytecode
classfil
es.Itcanal
soprocessannotat
ionsinJavasourcef
il
esand
classes.

Opt
ionspr
ovi
dedi
njav
ac:
-

i
. f
il
ename

i
i. akey[
=val
ue]–keyshoul
dbeoneormor
eident
if
ier
stobe
separ
atedby“.
”.

i
ii
. add-
modul
esmodul
es

i
v. cl
asspat
h–speci f
ywheretofi
nduserclassfi
les,
andannot
ati
on
pr
ocessorsandsourcef
il
es.Thi
sclasspathoverr
idest
heuser
cl
asspathinthecl
asspathenvi
ronmentvari
able.

3.j
avadoc–j avadocisatoolwhichcomeswit
hJDKandi ti
susedfor
generat
ingJavacodedocument at
ioni
nHTMLf or
matfrom Java
sourcecode,whichrequi
resdocument
ati
oninapredef
inedfor
mat.

2)Li
stdi
ff
erentv
ersi
onsofJDK.

Ans.:JDKAl
phaandBeta(
1995)thejav
aal phaandbet
awast
hef
ir
st
rel
easebutt
heyhavehi
ghl
yunstabl
eAPl sandABls.
 JDK1.
0(Januar
y23,
1996)

 JDK1.
1(Febr
uar
y19,
1997)

 J2SE1.
2(December8,
1998)

 J2SE1.
3(May8,
2000)

 J2SE1.
4(Febr
uar
y6,
2002)

 J2SE5.
0(Sept
ember30,
2004)

 Jav
aSE6(
December11,
2006)

3)Testt
heset
upusi
ngsi
mil
arpr
ogr
ams

cl
assDemo1

publ
i
cst
ati
cvoi
dmai
n(st
ri
ngar
gs[
])

Sy
stem.
out
.pr
int
ln(
"Hel
l
oWor
ld"
);

Out
put:
Q.3Cr
eat
eaprogr
am t
oper
for
m ar
it
hmet
icoper
ati
onsusi
ngcommand
l
inear
gument
s.

Pr
ogr
am Code:

cl
assOper
ati
on

publ
i
cst
ati
cvoi
dmai
n(St
ri
ng[
]ar
gs)

i
nta=I
nteger
.par
seI
nt(
args[
0])
;

i
ntb=I
nteger
.par
seI
nt(
args[
1])
;

Sy
stem.
out
.pr
int
ln(
"Addi
ti
oni
s"+(
a+b)
);

Sy
stem.
out
.pr
int
ln(
"Subt
ract
ioni
s"+(
a-b)
);

Sy
stem.
out
.pr
int
ln(
"Mul
ti
pli
cat
ioni
s"+(
a*b)
);

Sy
stem.
out
.pr
int
ln(
"Di
vi
sioni
s"+(
a/b)
);

Out
put
:
Q.
4Cr
eat
eapr
ogr
am t
oper
for
m ar
it
hmet
icoper
ati
onsusi
ngscannercl
ass.

Pr
ogr
am Code:

i
mpor
tjav
a.ut
il
.Scanner
;

cl
assOper
ati
on

publ
i
cst
ati
cvoi
dmai
n(St
ri
ngar
gs[
])

i
ntf
ir
st,
second,
add,
subt
ract
,mul
ti
ply
;

f
loatdev
ide;

Scannerscanner=newScanner
(Sy
stem.
in)
;

Sy
stem.
out
.pr
int
("
Ent
erTwoNumber
s:"
);

f
ir
st=scanner
.next
Int
();

second=scanner
.next
Int
();

add=f
ir
st+second;

subt
ract=f
ir
st-second;
mul
ti
ply=f
ir
st*second;

dev
ide=(
fl
oat
)fi
rst/second;

Sy
stem.
out
.pr
int
ln(
"Sum ="+add)
;

Sy
stem.
out
.pr
int
ln(
"Di
ff
erence="+subt
ract
);

Sy
stem.
out
.pr
int
ln(
"Mul
ti
pli
cat
ion="+mul
ti
ply
);

Sy
stem.
out
.pr
int
ln(
"Di
vi
sion="+dev
ide)
;

Out
put
:

_
___
___
___
___
___
___
___
___
___
___
___
___

You might also like