Professional Documents
Culture Documents
Javacw
Javacw
Javacw
simtroneudy.
Achitece Nauknal TAVA PA®ndes coole Songi wdily and
Pectobilky. t helps te eopily pgode the opuatung
tepeted ane High Payr mute JAVA enabes onestzbn
irvvoneliate
A pltum pogans by Cmpiling trte
esudetuon calld SAVA byte cede. This co de can be exetuted
Auray in AVA a
Aup ike -yped yootiable
stued a common nam n JAVA allovays we
Cempes hw atay
Whun n away s deckavasl-iy a
aUay
YOvtnanme =
newr type si«]
a =
neus irt |5J
inta
Combined> i t al]= hew int 5];
memoypace t -
Hene the nw epeHatose
alecates
e
a
in JAVA
ritializing aay
inibiclize away dning deelaxat
Dn JAVA twe con
bnt a S1,2,3.4,5?s
in JAVA USng e indes
tWe can alse intialixe axray n
l0 j
Ex alo] =
a[g 20,
a TaJ a0
Sorple Puoaam
impe java. lo. *
ckass somplu i
puki static veid roin (Stri angs
bo a neuw üt |5;
tnt o {,2,3,4, 5
4piv i= 0; i4
a. lenath , i+a)
Systam. oud.. pairtin (a[1),
Mutti-TDimonsinol Assa4
n
aay t c a . A consists f Jows and
coums. Also called modbix Ooay
Fx int
a[]I]- nw it []E];
a[ofoJ =10
Sample Progam
impet java.is, *
hass ezarnple t
dette
pubkevoid mawn String aqs II)
)
Systen. eut.purt (a [JIJ+
ckass olauname
ype instante vaviablel
ist) S {
type mehedname!(paroneter
methednamen
3
The doda oY vaviables deine widhin a clasz ane Lallesd
Menbes t e da%
Exarple:
ind heighd;
vt, depth
Void yownel)
Sample Pangran:
ckoss be
arc &enth
irnt bradth
ivb meigt
3
elass deme9
public static veid maun
(Strèng ags I3)
bex b neur box) ;
Juble yel
b. Rength = 10
b. bxeacdth =5
b. hetght = 15,
consbuutoi iniiclires
an object îmediatuliy upon
A th dan nome
nume as
some
Creaun. hag the conutuuctoe u
he
nesides. Once delind
in which it Caatid. Conatruct
is
whn the okject
wtamatiially calld veld. shis b bdtoue
evan
noun kpe net
o n t have oa is the dae
dan n u t u
he impliit
netucun type
inibialixe the
inibialire he
Coneduuctn n
be used to
type itsul vracUbn. SE Cen alo be
nstounte vauiakes duing object
e poguamming which has te
e d te wribe tre logie
the eotuon f ter objedt
e cxeuted autemsicaly en
#)Pavomettrized comstrute
dlout
A covtructor ohih hos ne poutauneters iu ealled
yolluss
constuuster. Tt s wsd te plovide dilent
vamtuid
to distenct ohjects.
Examae
class sadnt
t id
string mume
bund
studert int i, sing n) P cotru Tor
id =i ,
name = n3
void display t)
+ name);
"+ id Name:
Systurn.ouk.pxötin " Td : +
sudrt 81 -
nw studnt (101, "olivet ")
sudert 2 = nuw student (102, " Tina")
81.display);
B2.displag)
d: 10 Noame: oive
Nme: Tina
Id 102
Cnatuuctex Oveloading c o n s t r u d o L
oe
ian
moHe
y th
s a technique f having dyfuetieted
ane
pvanmetu list.
Ty and
tiin
wth lfueyt list
in the puameuu
by e
no
compder
than
cn JAVA
Metta Ovuloasung have
ore
ulole3 a
class to
thot allous payamster
featine dilerut
a name
buut w h
wth the scne
mechansm
n e metlod 2
sveleading
teugh
mhod
AVA 6ppo vt
peTmeten
ehnging the no
Metkiod-
G) By
class adlition ?
irt b)
idt add ( i t
a,
stostic
pekion Cotb)s
b it )
etotie it add (int a,int
ueturn (atbtc) ;
3
clous test
stolie void mair (tring axg [J)
public
add (to,20));
Systom. 8ut. prirth ( addition.
add C5,10, 15));
Systen. cut. puirtln ( aeldition.
Nethod-2
class addition
ptotie irnt add ( int a, int b)
rtn (a+b);
3
dass test
pulie sbotic vecd main (Sreng ags I7)
Systen. eut prirnttn (odolition, add (a0.5o)) ,
System ed. pxatr (addition. add (s.1o))
supo kass.
The etehds keywod is wd to h eibante
plosm in
JAVA
tax
ckoss baseelass
metbhels
in java e n e vavaLle
which u
ed t
upex kycooxol a
Excumple
cdaus auendass
int n=/o0 ,
m.pi nt ) ;
c a n be wsed to invoke
immediat peret
pocrert Jo
methoel
clas peoson i
ved ahewC)
Bup.sheu ()
F
doss Geme
public static voicd man (Strirg args ID
suderm = new sudent O;
m. )
Osput
This boe elas
Thits ts olived las
ECan be used te aele immediote tastet dars consouuer.
EX
cass pesen t
peUsDn construudox
extenols peruseni
ekass student
studut ( )
Bupe () ckas
censtauctex");
('Studert
puirtin
Systern.eut.
3
sbatic vecd main (Sting ags IJ
public
sandent D,
student m = new
Detthed vevriding
delaned in he paret
Aubelas has the
bame m etbhed os
t d or u n time pelymephism .
Ruls to be fsllewed
n==t)
etin
esult = lact (n-1)*ns
ewn eslt s
ciass reuien
pislic stokie veid main (Stirg ags TI)
Whan
fat is colled
fact () Rectmethed], The fot s CA
wm an
cotqumet eone.h e aundion etuwuns ene othetwse
t nds
puoduct fat (n->n, Ttis precen p
diX n
eguals te nethed
ont. n I and the cells to the
being tusuning
when
yeu comyauke t fecteuuol 'of 3 Aicst call
fett () wl pas a
Rcond coll te be made
made
within
las hi keyweno
a Akene vai aske hat nfeus to c u n t okject.
tie
The mest commen use
this keywotd t o eliminate
Corus icn between alas atbibute and paramtby wih h e
Sme name. ettu ses trkeuwend is as ollus:
Example
Wbed
er elesing cume das istan ce vasui able
das sudert S
int Holn6 ; Sbting rame
String nome
sadut ( int ndllne, Sting name)
u.uone =neWne,
this. name = name
veld diuplay ) f
Syston. out. privtkn (Aolno t +name
cas deme
pubsle statio maivn (Stuing avq I J)
veid
Sttdent 8 = new studet (10, "Guita");
stradent 82 studot ( 101, "4bi ") ,
ne
olP 10o Guta
1. display ()
to Abi
82. diplay O
lass mthod
sed te nveke cunent
has Af
veid m )
Hello n );
Syston.u. prirttm
veid nl)
System-eut. prirtv ("Helle n ");
ths.m( )
e N
Ased te invoke cwmenb kons conudten
clas A
A (int ) {
3
dasg derme
puic sotic veid main (Sbiwg avgs [j)
A
A a nuw A (i0);
upt
Helle A