1. echt)
le Noqeoana Rao
Naganjuna 13
n-OhH 3
pinlP oe) piPTwo'» porae (Tee Joe
o/p Onekoo Pnee
nh
Pae
1o, 20
. n A 2
eyee (
O/p- 1O 20 5
2. JOVD
va elTons
ndavd edPhr -(aee (6jec)
oejova
Coye jova,
advanee java
evpvises edtion jaee co)jee)
vo edttm (3ame (odjme)
Ppcoions
Biandalorne opplfcatfons Runs o a Sinele
chne not ghoyable to olhey machibe rmuoPRee,
oecioplayey.nolepodl
ishfbufed applicairs-vun 1e broote
(o
ustneo00
Shayable to d%erv 'oachibe t
e-notSile opplicotiocg -o91SymblanCoutdaled vevafon)
onchdid,os oirelou)s
Ktevenceg betoeen Canejava
Java
ohfect overled languae
VOceduroe erled
no Secut Secured tang
->Tn javo thene b no olihlevs
poiney menna cddhess dala
plolfhvo deper:dlent
CP no polhle ue Cannet Meh cata)
Mge (oppltatd) ) delharo holepernclert
langunge
3. c SuppOvs ava doeent Suppovt to
9oto
Staterme
3totennents
fava Suppovs clynamic
ve does not Suppost
dectaraton
dynamic declayation
proceduac otened c p ooram Stoucteure 15 dlRded
o 1Br3hat
oto Some pocedung tRais why is poocedune
functon aenicd lanauager
-Tn Doceduse e data fsceyouing froo Te
module TO arpthe module thee s no ontio on e dote
-In Cc
by delaut functfan9 ave qlobal Scope,
global Scope
whereven we Loar uwe Cor Call then
In c thee s no Secuity fo the data, hat 3 wh
e Cort develop businexs applfcathons
txe10, Y=20
void add proceclune
void Sub )
proceduve
4. wic ma ()
add
t-
Subl)
Spg oops Conceptcoe Con provialc restictons
usina Oops
PostRe data o
ctassSomple
povatc ttx= 1o, Y=20,2 ltdata mcmbersS
of soo povate /publfe yotd addl procedune
mersbex RmcsnS
=*Y
ofp
pub lic void 3ub () rocedure
z'x-Yoha
by C plafovo ependent
enecutable -fe
Source G9le
a Cie
Compile
CoCotc9 natie Cacle os
ative undensandable fov poarnteulon os)
5. jovo urhia
Source ic Closs-fMC
ojovo byte
1010
Code
1OoO
ova Coroplen Ceates byte Code that Conno be
undevstcad by any Os
- vn iepetes Corveys to naie Code poticulay cg
qoto sucd to transfes the Cortrol ro one to
onother plac with n a unction
jova Suppot oll Contol taternents ecepi cto
Sclection atcmens
Swtch
9else etse P (todde P); nesed Sortch
gurnping 3iaternerhst ja does rotSppera
ndeanott
ovra Corhue, oto) ctur 9etp 9cdemert- dua o
mulfthresdrg oncept
loopi Staterrent
h m rfel
ohPie do-while fo
5 Whct cdunarrie Declanation
declove vanables uoherreNeT ue want
we Con
Cproqam vofd oon)
pitf wekome";
r 1O /esvoo
Calfog any unchon we Cont declone asobies
6. javd -ornes qosl?qSun roicio Bytcr (1995)
1verssoeleagcd 199G Cjd61.0)
yovo developroert
ava 9un roco Sysiern didrc oe ony obbevatiön tox
8-ust
f-ancter
v-stua
-fnalyse
ScJPSun Ceyted javo proororn, (Ccore java)
ocjp Oracle Certited avap1oofasme
avo Sloaen
wORA- wte once un ayohesC
Sova 3logan cprcsents platfosm 1Deependerd
ConverotorS oava procrammir
hruy pd hslom
1Oorming
)lov Class narnes-
elass ame hould 3tat uit uppeicose lete
9P4 9s having mulple words ach OTd 1
PPret leHer 3hould be Capital
rovn
class Student
cla99mployee Tnfo
class-raIndeOut OPBoundsEcephaon
DMeifod narnes
method narne Should iant th
louwen Cose
7. Iellers + 9 hauing muHple wod Cach ovcd of
Re-hs lete Should be opiHal Cieept wovd
Nod qel c)
vdtd qe DataC)
void qet SudertTofo
voia ecualsTqnoveCaseC)
RH)
Svatiobles
vaables must be în louey Case eters
publfe she
pivate Shqpuod br
piokcted o Sal
Hoat ovg defaut /package
Conetants utel
Constarns must be uppercaee,f f +shovnd
muthple words ust be Sepevaed by undevecoeC-)
NORTH
SoUTH
PAGE UP u re
PAGe-DoWN
wbat ae be outpu SAatemeris ava
C->pitp C) unction nclude 2stcfo:bz
t Cout object nclude 2fosteornb
Sysiern.outpito ()- t Pse Stakrnent nest e
8. 9ystero Out piot C) Sarnc 1me
Syster Out pioAPC) - Sarne line
Syprem- class larg pachage
Outobject pfot Streo class
ropovavatarg frnpovt ava-lang:yse
all Re classes F ang
packae
java- ma pochagc
aung 3ub pochage
-How to wte mai ( mettod Java
public Siate void mon(ShRoq ags[ 1)
Statc publie void main (Shing TTemve)
Stin-clss tn jova
java Saßtuoov jd re
ava untime enviTonment
java developme ri
jly- javac -jrc e =jvm +api
ppT Applfcation programminq InETface Collection
pachage
ava Javax
ang
Qwt
opplet
mac
9. ohat pat
port T9 a aperaing Sustem environment Seaiche
Pov/eveles
Con Set e pal D tuo LOays
tde
TerpovOny Path
pearmanent path
TeroperoTY patb- TP we Set te poatt in Coromand
prormpt,her + s Called Heroporoasy pct TPuoe
C
close Be Cmd prompt partR ust11 be emoved
Comiler oddre
epath poqrom Flesjava jaa.o bin
peimaneot parth
Cornputey >propevhes> ctuanee
Systern ScHnqsenvironmert vatiables clfck new i
use vaiobles
wamabe Dorne potk
vnioble vatue :Complfley adde
r
clich o
prorar iropoytjovo.Iang
closs Sormple
pubfc 1atic void main (Sq oqst)
S5tem.out pitn(welcorne to jao old
10. how to Cornpile
gavac Penooe
jovac ga java
houto un
Jova classnorme >
Java Sarople
note - TP class cleclared publie int
narnc as elassname java"
we Should Save theFle
ote.2-oe Conna wTte tuoo public classes
pTogram
pTOqram? Proport ova loq*
class Sareple
puble, Siate void moin (Si orast)
sterm-out piintl anC Sho") .
Systero out.pigln (o.no:13/aho o Ph:92As3
Dfereee blushrotbase and abrct oviented
ctaes ot Suppas nhetenee
DRPerenee
11. *Doloupes
DDumbe Oolartypes
9 Character Oadatype
decimal Oolatype
logcal Dalctype
Dumbe Qatatypes hoeoa es r
Byte abyte -128 to 12 (-to )
a byte -32H68 to 326 to a-
3hort
bytes - to +2 -1)
poot w toryo
ocal aniables
The
The vaniables ohich we are dectàed neide
tey ae Called ocal vaniables
meithod
sIn java tRere o feasabilfty os boge valu
CTbeve sno qarbage values ava)
-Before ony vaable t mugt be
to use
Rol eed i Conesponelingalues
mso
Gienerat output c
20
O+20-B0
0 20= -10
D22O
I value s O
D2 value s 20
13. Bis ond anqes
ts unsgned 6iSaned
3bits -uto+3
oto 15 8 t0+
5 BRB O to 3 f tG TO t15
OTO63lo n32t0+3)
ts otoin hGu to +63
Oto 255
G bi by to 65535 32168 to 1336
Hou to cpcses -Ne numbers n Binasy?
-Oo s Cormplimentto heqiven+venumbes hopo
-O1-1 OO 1
S Compmerd 1oo 'sCompfmen t'to
O -3
5- O1O)
s Cormpl?ment101O
1OL 5) huomf
Lhot happens data eceeds Eeorge?
-uhereve daia ciceeds thc arge akes
Cnulay manne v
Teue we uorsbto 8tore8 value 8 b
tove 1e
14. +Pen t becomes
2E
unsigned oee byte rane
O- G5535-0
G5535+0
O-2G5585-1
G5535+2
e-D- 65535-(n-
G5535+n-D-1
e enal Typecastng)
unsapedti G5620 lG5535+85
pirsf).u )
op- D-)
35-18u
128
-128- 122-0=29 +1-129-
1292-128 t1 -129
-129 2 123-1t26
129+D=-OS4D-
-12-n= 129- (D-1)»
clas Sample G
publPe 8tatc vd main (Stng on9st)
11byte b=128; //eno
byte ob-(byte)12
Syste out prirtio (); /-125
b (byt) 300
15. System out. printn (b): /4
N-Pioat xu.|lewai
Ifloat x eu5P 11 vallel
Ploat x Ploot)u5, llvald
3ustem-out pioiIn ( //u5
TpeCaeta
Conveth9 the valuc rom one typeto anothe
pe
impfåte /idenq type Coeti
)eapite / nowowing type castie
Dplicitr /widerin onvertinq the value from lowe
data type to bighe, claia type. To his type
Casttng memooy toss occuTS
3c1-ciec
hort o
ubes byte ar /
2byes
byte b20
shot 9-b /l valfd
b, 1lvalid
proorn!
class wideninqnoample
16. publfc tatc uotd mon (Sh ogt)
oyte b=20
Shavt S-b
tem out pi (b+ l 20 20
Po-b
SoP Cb+ t7 21020
20
plicte /narouoaCornveytie the value fsom
0
haber datatype to loue datetypPe Tn hs
occurs8
typecasttng odataloss
bye Sher o ong
ot 320
byte b=i
Class NdTowing eiamplr
pSvm Sng eslI
n 320
Il byte ba ero
byte b=(byt)?
Sop (+ aD ll 320 GY
coubie u5
SOP (x ); tlu.5
17. 9 De&roal Darlatype
u bures (u5P
Ploa
double bytes (u
Floa 3.5 Ihenan
chonacie Ootatypes
cha bytes O to G5535
char es
asi Co to 255)
Dunicode (o td G6535) Jaua Supports unicode
cha
O o
AD ente
32 Space
to C
uetd53
GS to o
ato 3
97 to 122
n Rie
ocal Datchje
booleon byte tue falsc sd py
d
wile () /lcno t cvalfc
we (o)I eno in jova 'vaPd nc
CoIe (true)l volfd.in c enas
Ce Pala)) vald
18. eyuwOTde
woTd T6e mearnmg
heyuworel e a Teserved
these wOTcls, alyeaaly detmed i vm/jova ompilen
um/ava Compiler
vey heyuoarc has Spectal meanng in ava. Tk
Cant be changed Tn javg
vey
eanng in ava. 7h
mconin these uwoTds Can be changed In jav
we bave53 eyord3 a
heyuoards oclated to dao type
bute Shart ind, long. char,Ploat double uoid
Deyudords oelated to Control Staterncnts
etse, SustCh Case default, brcab, Conhnue
vetun ohile, doa
heyuoords related ro eccess Specie modAers
public 3tate
vateno reabshact
oal
oteched
tronsientinh
Synchroraed,
publie :- we Can accees any he
poivateonly wit i he class
protected'wi6 o te pachage and Sub claases
Othe pacha
2defoult7 (o)pachage aditer;-TP here s o
modPe then s alled dePault
19. on acces in oitA iD The pachage
The pacoge
we Con
eyuords related to class
Clags,inteface, etends, implemernS, Insiace
heyorcS elated to eiceptiom handlling
tyCatch, thvow 6us, tnaly
Oops object oiented proramming uctureConcepts
ctass
) object
data encapaulation
ral ch
u)dota abshachon
) polymophYem
cnbeitance
Class s a heyworcd usng class heyuooid e
Can Crocote claiatype (ctass is a use defne
cdatatype
) Class a CollecHon dartarnembevS (vaniables
class9
and ermbevfurctiorn (metkod)
a dala
membene, ave sed to Store Re dat
)Data
membe unchians oe uscd to pe-tsvm he
operats on data
iv class s a 10qica epresentation t dosent
any 9pace To Thc memovy
accupy
20. Claes Sornple
Tt xto, Y22O,K3
voicd add () Rd clog3
fornot dove (spamou)
void Sub () oects
objec object the physcal epresentatfon rior
he claes
bluc pii ocloes
Yn9tance class
TO Ccalc object we nee
eeference vaniable
ne opeiatos
Refevence vavioble-T+ Stues e addheas (bascode)
e objec
2Clossname > <vaioablenarmne>;
Sanple S
De beyuoord uging neud Heyuoovd e Can memony
for 16e clas6 hew hcyucrc oetun3 TRe addres
object
Syiax ne Claagnanme ()
23. tn ane Siep
Sample Sanew Sample O
Two Stepe
Somple S3
S oe Sarnple O
Cass Sample
t l0, Y-20,Z
Class Maindasss
public 9tatic uo main (Shina onsst)offowj7
Sarmple 3 new SampleO.
7 ic
otem-
SOP (e)
Sample 92 neuD Sornpie: gi
m
SOP piiin (99);
3
loinio
OTE
we Con ccate any o.o object to he clo8
wbat Singeton elage?
only One object Can be Ceated
1Calende Sevet
24. upe vaniables
1
oocal voviables
2 tate vanables
3Instance Varable
tadhic Naviableahe vaviobles tobich rie we ae
dectared ,uoith te Class w1 3iatic madifer
1S hnown a9 Siotic vaiables
closs Sarnple
ot
SAatie t xy,z:
TO o access Static vamables,no ned to ceate
object t clage name we Can acce&
classname
.2vaiablename>
Sarnple .x
Sample.V
3totc vaiables Occup only one memay
location fov eotre class e, tese ae also
Called class vartableS
ce vantableeThe vaiables which we ae
declared wit be class othout Stortc mocthew
oitout Stortc modife
Rnetance vaTTable
s hnouon
To acces ostance Vaiables we nced to
Create abject wt Obect we an acce
25. 2 Object>.2 vaiablenarne>
Sample 9-ne Sample ()
S.x
class Sarmple
Saticind ab.c Static vatiable
ip Xy,7; osance vaviable
ofd fun 10
Ro P-10. 1 local vaiobles
Sote etanc
vorRable clossname.vorioble oject vaniable
aormplc fov nstonce vaiabies
class -91pha
?ntN,Z
clo9s Mofo Cos9
pevm (Sti onqt)
pra o rcuo fAlpra CO;
a1.10
26. a1Y20
a2z= a2x +Oo
SoP Cx :" ta1.x) /ho
9.0P Cy: +an.v112o
30P 2 01.ž) ; |l3o
9oP
3-pha a2-neo-9lpha O
a2.Y 2
a2 a2.x 02.y
sop (x"+ a2.x lo
SoP y:"+a.,1lo
SoP a2. lo
3
pes methods
Stac 99)insance metfods
methods
Sialc metfodeTe meRods chich we arve declanes
cOn i e clas8 uRt Siac mod@fen s Knewn as
Sicrfc oethcd
ctass Sarople
Stoe Noid Puna)
27. usin clo8 Darte
-we Can acces Statfc nethod9 uSin clag
2Clas9nome 2metßod hame
Somple Pun aC);
Snstonce metPade
he which twe declare h
mehods ane
te clags stout Stoemod?fers hnoun a
rstancc method
Cla Sampl
void fun1()
->oe Con accos ineancc meihod u3i09 object
2 cbject>. 2method namc>
Sample S1 ncuw Sample C)
91.un C)
Y Sia+fc inGkarce
Sx
vanfobeSompie-x 9.y
metheds Somple ur9fun2)
28. Comple proqsar) fov Siatë retods
Clos9-tpha
Slac vid dplay)
3.0.P I arm SHatic mciPcd fror-9tpha)
class Morcla
psvm (SRrg opi
fpha.dspay ()
W mainclaas show().
ShowC)
Static votd 9ho )
9.oP I am tatc method o main")
3
eiampe far nstance method
Class 9Ipha
vofel abplay C)
3.OP C a in3tance method tem alpha"
3
29. cla Dela
vdia 9houo ()
Sop Cam instance metsad som beia")
class Main
pubc se vRd moin ( Shing c)
fpha al= neto AIpha(
ecto a2 - new Beia c)D
Maio a3
=
neo Man
a-dsplay
e Show ()
void Ran ()
meies
sop or oonce fro mafn)3
Siatc Siate Oulc
- e can cal dfcctl Sarme class Satc mehods
irrto 9Hatic methods Sarne clo
30. gample funa)
not mardato
claxs Saroplc
34atfe fid Puna)
3tatic void inz()
Pur1C)
on-9atic to on-iotic Rute
clax Samplc
void Runa()
vofd tun 20
Pun
Siatc to an-9iafe aule
class Samplc
Slofc void tuna C)
ofd fun 2 ()
Pun
s0)
31. DeD-9latfe to Statf ulc
class Sample
we,Connot GlL drect-
vofc un2)
slatc votd fun 20)
NFun2(); onao
Samplc s newSampe ()
9.Puna)
1
class 1mete
(s end-Pov
Ytx10 Y=20 ;
vRd odd
Syatemout pintn (z="+D
od ub C)
Z= X- Y
Systern out pim (z-"+2),
clas Main
32. -PTneha, al peu, AsihmcHc
al addC)
at 9ub ()
olp' - 30
Trs heyuoorc
Thi9 denotes cla CuTsen obect THis Ts. used to
dferenae bot local and nsance Vanabies he
ctoss
Getto and eHex metfhods
Seter metfods 2He meth ods Qe used to Sct thc
Nalueg vaiablea
qeter rmethoda gcter mettod ane used to e te
values the vasiabls
1This heyucord
void getoato(int1,inty)
ctass Šample
ptvate it xYZ:
voicl qgedata ()
2-Hig-1+*s.3
go am ct data u
pev
y-20
33. Sastom out pintlo I a getDaa it pora").
veid pAOxta O Clotue1
s.op (: "a
SOP y:"aY):
sor (z"-D;
3
cla Main cb
psum Shig asqs
Sarmple S-neo Saople)
SpintData)
soP C
Sget Oata ();
Sprint Oaat);
90P C -e -
aboin
9 ge ada (1o0,20d
ideinyt ulo
9 print Data y
3 birec
am 3ct data tuT pa
am seh deta tut ps9
Y-200
Y20 Z300s
30
34. polynophiso
roa
poly means
-> nopbism means om
oe function in manyfaon
-> usina Some name To difPereri metRods o ditesent
oplementatio polymapbism,
polmespsm
Statfc dunamic
CCompce fme) (runtime)
eamefod ovevbadim e meRod oemiding
class Studerst
pivate nt 9no
pivate Shing sname
pivate toat au
vod qe Student ()
SnO1
Snane abc
SoP C am qel Student witfout parametey J
voRd qetSrudent (nisgno, Shing Snamc Ploatav)
s8no -Snoj
SSHame =Sname
35. SoP C arn get Student th Pavameleys)
vod mirtStuden)
soP Sro+3nd)
sor Shame:" - Srorm)
sor og:" +av
Clos Mafn Class
Psvm (Sng aqsl1)
Student s-neuo StuderhO
S.pint StudentO
tbure
sorC
SFPStudent ( )
S.pin Studert)
S-oPC
SqetStudert(12,"abcd'n.3u59)osut tne
SpintStuden ()
olp-
SAO,2
so O
9name tabcd,
Sname enull
a12.B4S
avgO.o
am geHStuolert o pasc
Sramc abc
avsi2 12
37. clas Cicle
float 1,aca
Ploat Rnd-AreaO
avea= 3.1u *
yetuon aco
3
-Ploat Pdfreaploot)
anca 3.1up+s is.
Clo Moin closs
psvm (Shing av 13)
Ccle Cncw CRrcleO
SOP (freo;C. Piod-PrcaO)
SoP (rea;"ac fndhyeo(96P);
Can you oveslaad moio() method?
In c c°s a piocedurc oriented onquc.geovevlcod
s Cops Conceptnot only mofo() functfom,
Can overload any funthon în c
38. To C c Suppovts tnciaon oveoading we an
ovesload all funcfors but e ont oveload
main funcon
Toava- we Con ovcload allPunchon n jaua. o one
y Coanestfc ovevlcadfnq. rmain() unction s
ovevloaded vrn eseutes e 9TS
ponaroeer main
roettcd coly
Clos Sompie
psvo (Shirq aqst3)
SOP ("tMetlo) ot be Ecuteo
pBvm ot avgs[3)
Sor tiell o")
Houo to Tcad opuls n ava
Can Tcad the inpus i tto asys
ue
using Command 1frc crgumems
)using Scanner Ctass
Commarnd he aqumens
-passine arqumentS to a Peuncton tough Command
fhe e (81ough Command rampt)
But basically we l pot e Ongumets to te
39. Panchons when de Col u we oon Call
an
functiens rom Re Command ompt- wr wi Catl
ancHons from anothe funchanS
But mndi e ony ane funcion which wil be
Called by e vm nepetey at e Command promp
oyPoRe main functfan we an pos agument
Rom Ae Command prompt So basieally arrqumers
poxed
pEdto mai tunchm fs Called Commond e asm-
uTaPper clases
(Ls pre pf ve
oDEClas, Hose Classer
vey daa ye bas
ae Called -tlsl)o
OYappes Classe3
datatype closs
Ppr tor muet
Bye
Shovt Shovt
Totege
Pioa Floot
double Oouble
cho Chavac4e«
boDr
->wrapper clases Qe uJel Convert pimive
datatyr efercnce daetupe
clas Sample
Funot
psvm (Shng st
soP ( no .oCmd l aTgucmenis+0m9e
Rne
ot xTo*getpansdin (a1q-1
40. Yoy=Tnteqes panscint(mqs);
9oP x :a Sng. value (o
(fnt to Sh
soP y:"ay);
Iptegeparreelnt (")
(shg to n)
HouD to un Java Sompie 1o 20
olp no Cmd ne agumens 2
y 20
Close Sample
PSVmShing arqst
80P wetcome ags i)
SoP wetcorne+ags Lul
Sor addon"+(anesio] argsta), l/1oso
SOp no o Cmd 1ne aqumerts: +a1gs.lenth)
pp ovo Sample 1 20 tingai
welcome20
oddtiom 020
nooCmd line arqumens 2
41. Convevting Shing b Ploat
Ploat povscFloo (orgCI
ead 9 Ptoat numbers add hem usinq Cmd he a
claxs Sampe
pavm (Sing crmect))
floal x Float pascFlootCrmieclo)
ftoat Y Float pareeloal (Cmvec[);
s0P (x:,
s0r v:"+
Bop ndd?hon"(x+ V)
3OP("nocne ire aves:cmecAenath)s
3
Sconner class
> s avoiloble in Gava ufl pachage
impovt java ufl.
mpot javo uil SconnerS
l
>t s usd o reod nputs fro useY
OEjECT CRETIO Scanney sc=nco Sanne (System i)
Fmeihods neHTiC):+reods the înt value fom use
nentFloat ). it rcads the floct values om
42. net( eads e Shias(TAout paces
pettLineC): *+ veads be Sngs (uSR Spacesb)
oettDouble ()+ reads te doubie values.
)impot java.ul."
ropott fova uttl-Scanres
class Studer
pavo (Stng arqs[I
Ova.uA. Scanne sc new java.t4l Scanne Syhenin)
SoP (rtey Sno:"
sro =
sc.netJn
ScnetLine ); /) Cads the enter ChenaceY
Sop te snarme "):
Shing name =
Se.nestO
hing snarme Sc. nettLne);
SoP ier avg"
Ptoat avg=sc.netFloot
9OP (Sno ; "a sno)
SOP snarne:" Sname)
sopaq ava
43. Contho atemersts
SetectiGn 8tortemertS
1PP else P else (adder#), nested
B)ampin9 Statements
-breah Corhnue,netunn,oto
Apeopin
3AatemenS
while do-while,ff
Suntar p
P (Conditiom
Statemers
else 9P CCondiHion)
Statemernt - e e 1
else
Shatemenis 2
f elsc f fonefone ) 90
P (Condion)
Stateroers
else f tondlon2)
Statcnents 2
44. else
9tctHernent 8
3
2012l2
onetuctos
Conshuctov O
1 a Spedal oermbey funcHoD novroall1
uss Ho Halge eobecS of c das and
ablesn hee Object
used
- Spefal
Spectal because ts name i Same as tBe
Sam as t8e
ohenevey
class and w be Called opli&ty h
narne
an object fs Ceatedfbs he class
Sample
Constuctor Connotbe epliCHY.
->Consthuctos Can have Zeso
any Dumbes o
pOyameters
->Consthuetors Cannot have aetunn typt
Spetofon ro evc vod als
>snee ConShuctors also lthetunchom3, all he
are
acces Specer Can be opplicod
Conshuctos anc 3 types
defaulH Constucto a ovgumernts Gnshuatan
Sarnple
45. panametniaed Grshucta
Sample (o
Copy Constucto
Sample (Sample o)
Con e Create obfect rthout Conshucoi
D0o without Conshuctav we Cannot Creat obje
toheneva e ar not igConshructoy(rot
(reitalRs
vaviables) Then Cormpley tabes the 2sponsi6iiy to
iitalisation o te vaable (tCeates tbe dlefault
Constucta)
a clos3 Sample
Sample (O
SOP ( ao no para Conetructo)
Sample (nt
Sor (a am onc paya onstucto
Sample (ntxinty)
SoP I am two paTa Consthuctu x +Y)
3
1725
class ManClas
46. Pevm (Shiq ons
Samplc 9=ncw SampieO;
Saroplc Sa oew Sample 6y
Samplc S2 new Somple (100,2co)
P- am o par Constuctos
a OnC para Consucto 10
am tuoo Para onstuctos ICO200
ass Sample tmployee
n
Tt eno
Stinq ename
double Sal
-roployee O fnot vc valuea 4e
te deault values are qven
enoO
ename =null
Sal 0.0
tmployee C)
eno-
lo
ename"abe
Sal - 60000 Oo;
SOP am no as nst
47. mployee (int eno, Shing cnarnc,doube Sal)
-ts en0-eno
Tsename ename
isSal Sal;
0P I am anq Const;
nployee mployee o)
eno o.eno
ename =Oename
Sal O Sal
Ser a om Copy Const")
void pin Employee (
8or eno:+eno)
5yley
SOP ename: "a ename)
SoP Sal asal)
lass Main Class
psvm (Sthinq ovast
tmployee et ne tmployeeO
e1pint Employee ()
48. SoP
Eroployee e- new Ernployee (102, xyz"aoooo.Oo)
epintEroployec O
Sop
Enplouee e3a new Employee (ea) s
ep EmployeeO:
SoP
Employee eu= new Employee (ea)
eupist Employee) 6
3
dp om no avos Const
eno i1o
ename: abc
Sal GOCOO.O
am ags onst
eno o2
ename Yz
9al 0000 Oo
2am CopH Const
enolO
ename ahc
SalGOCOO O
I am Copy Cons
enot02
49. onshuctn Chainin9
s) ts usel to call Same class (onshuctus
Rule is () Should be in st tme ue Cant Loite
as a Second Slatemer
class Sarmple
Sample tD
SoP ( am defoultCorst
Sample (t
SOP I am one pa Conet:"ax)
Sample (int xnt D
o.3000
sis(10
11
SOP (a am tuo para onst:"ax, +Y)
3
CD.Oo
clas Main class
psvm (Shinq aes1)
Sample 9-new Semple (too,2oo)
50. p- om debul Cost
am one pana Cone10
I ap too pana Congt 1o0,20
oOTeusina s. we Can Call Punchcns also
His Pun4C);
s Pu02 )
atic actoy pethods
produces e Same class object
Trmpovt java. util.*
class Calende arnple
psvm Sirq arqeJ
lcalende cDes Calendei leno
Calende C Calernde .getlnstance ;liStaHc facheo
ettod
SOP (
clas-Alpha
privak rt Yz
pTiate-Aipha C)
Y-20
51. 90PT am pivale onshuctun
9lohc-Dpha et-Apha Object C) 7 SMarhte jactmy
Npha a new -Plpha (
3etunn a
ucid piotData (
SoP (xa
sor y:
soP z:+2)
class MainClass
psvm (Sg amt
= neD Alpha); ena :+ a
pivate onshuct
ft Ppho
ppha a= -Pipho .e-ipha Onject
a pi Daaa (),
3
who Shoe doss?
Ao oe dect Can be Crtoe
e Colendc), SeTvIe4 cla
52. DOTCDovmally we Coan Caeate umbes obj
an
TAe
The class, bu ue Cary Ceateb Singleton
Slatc blocs
the jova picqam uittho maiD
Con e eiccute
metfod ?
matn
we Can wte Te moqram thout mat
we Compile , but we adt exccute tIn cand
Con
t main fancHon must be equeel o enecute poepam
anjavaue Can execute jaua pvogam uithout maîm
man
meihcd using Staticbloch executfon oseibie thout
mainbeloo vesiens ds1-c)
->To execution ua Pogamava ompme Ceae.
class e jvm enecuhes the class eohilt erecuk
-Rst t Secnches Static bloc s eisie mt
s efsed t eecutes tRe Stotie blockthen ît
Seaches t mon method
-p Satfc bloch s not eaisted, drecty+ acuts
he moin method
class Sample
Statfc
Sep ( am oac black):
soP T Can aecurt ut moin
Suttm.aît (): Ss pmom eau
53. clas ampe
Statfc
SoP T am 9tate bloch)
psvm (Shfnq aiest)
Sop (I am main mettcol")
olp Tam Hatie blcck
a am main mcttod
OteP mooe bars ane latic bloch s efstes
eiecute TP Slatic blccks fRomtop to boHom
DOTE 2- Siahc blocs ane used to iSAalfse Statie
vaiobles te class
class Sample
Static
s0P T am Stotblac)
3
sOP am non-Slatfe bloch;
Semple C
Sor I am Constucta )
7
Psvm (Shing nqp)
54. Somple S=neuSampe
soP T arm aio mettcd)
Oop- Slathe bloch
Oo-91atc bloch ATe class tevel bloc,obich doret
bove an pototypec
The need oa non- SHatfc blochs to eecute an
Lwheneve an object s Cveated rrespechve dF
he onshucto
->Don- 9tattc blochs ave executed Outomatically uOheneve-
otRectis CTeated (befose onshuctos)
Class Sample
Statc Tot S
otD3
9tatc -
S-1O
n20
psvm (Shrg onqe
soP (s Somple s
I/9ystem out piotn (o+" Sormple)enaY
Sbmple S=new Sampie(
55. Soe (n:" s.
Toboiance
- -DPpng class pTopezteg (dlata memberg
Cne
and membe functors to anathe class
-Sip9 Hendes Keyuoord we Cor tnhent he
Iohei-ance ave 5ypes
sigte leve nhesîtance
9nu level nhetance
3 multple inbeitance
)thid Tnheitance
5) Reranchfelbeftarce
Singe teve) Inhettance
Base clas
aren class
uper class
generalfsed class
Deived clos
child class
Sub closs
Sepedliscd clay
56. mui 1evel inbeHorCe
B
-D++C C
DLufiple Tnheitarce (java does not Suppa thi)
C
D+BtC
Hybrid iphetarnce'
B
thierarchiel Tnheritance'
D
Collecign Sle leelnheftances
57. Sineeel Tbbeanr poqra
class Sample lleimde ava-lanq object
inx1o, Y=20, Z
oid addt
Z-xy
soP (-rdton is:'+z):
3
class SubSample eitnds Sarnple
vofd Sub)
Kx-Y
SoP Subtracion îs:+
3
class MainClas
psvm (Shing args)
liSaople s pew Sample) AEu ta anly
mpe re Conten
9 adld ();
SubSample ss- ncw SubSample )
SS addC)
ss Sub t)
58. we Ccate object fo base
NOTe wbeneva
Class
bosc Clase Conent he loaded but 2 we crate
obiectfo deve class bott class Contents wil e
toaded (base+ desive)
ohjec
obfec
Sample
Sample
SubSampe
-java lorq Object s a Supe clas9 all th
classesThese. class me}Rods ane auainble fov all tRe
objects
upe heyworol (
-> 18 used Call bose class (onstuctoss
vevy Conshucto has Supe ) Hayword by defhult
e st ioe
qdefault
- A Calls te base class Conshructor
ine
Rulett Should be îne &st line
pIeora
class Object
Ohject
ctass Sample lextende jaua 1ang. okjcat
Sample )
59. Aelaull onshucta
Supen ). h als R bre class eaull Grsbu
SoP Ca am Con Sample"
clas SubSample exendsSample
Sub Sarmple )
7SupesO
Sop C am Con9 oSubSample'),
clas MdRnClass
fo psv (Shing anqst)
Saople S- Dei Sample
iurom
SubSample ss ncw SubSampleO tleo
blui
class Sample
Sarnple )
SoP (I am defaut Sample Gre");
Sarmple Cint)
SoP CI am one pme Sarnple Const")
60. ctes Subsample exterds ampe
3ubaople C)
SoP C am defout 9ubSarnple onst)
Sub Somple (fo )
Supe(1);
SoP ( am oe pana Subsample Gnst"),
ctas Maîn
psvm (SHRog avgst3)
SubSarmple
s=newSample().
SubSample s31 rew Subsample(to;
pa be pioed
Multilevet Tnbetance
Statte
Gnand pact non-statc
consthuctui a
toe
-Stafe
paaer
- non-Staic
Conshucta
Cld
slac
an-slcc
Conshuctov
61. Ela Ghardfoer
Stahe
soP am Stothc block GivandPavent")
SoP (I an non- Sote block o Gnandaoerst )
3
GrvondPavent
SoP ( arm Conshuctos oGond rent
3
class Porent exends Guandloreni
Siatc
SoPa o Stat blcc oneo)
SoP am non-Siac block paent')
Pave
soP(I om Corcshuctos Parent)
Class CHld extends e
Siac
62. SoP am 9atic bloch Cbild
SoP am non-Sloahc block ochild)
3
chill
soP C a Conshuctos cld
clas M1aioCla
svm (Sa ags
IIGrandPavert P-neus GnandRcotOs
t1 Parcot p- pew Pascoi(Os
Child c Dew cHldd
-
pT am Sa block oGrandParens
Iam S4ac bloc dpavent
am 34atc bloch dcild
94aic bloch Gnondren?
am
arn onstucto GaandParen
om ron Siahc bloch aven?
I am Conshucto Pavent
1am nOD: Statc bloch ld
am Conshuca o cd
63. dRfferenee betweenb local,1sSupes vaziableg
cla Sample
otXal0o, y -200, Z=B00
class SuhSample Catends Sample
b turen
int x O, y:20
NoRd furn1C)
Sct x2
sOP x:a), 12
pre
SoP s. x:" #9.) Iho
soP (supex"Supey X) i/acd hst
SOP (y" ) }l20 7 nerot
soP s y:"+isy) l2o bl
sOP (supey y:Supe. y); l/200
sop ( z;" this.z) :h 300
SoP 'supe z"+Supe ) 11
00
clas Mainclas
ron
psvm (Shig asI)
SubSomple 9S De SubSarmple ()
9s. funi O
64. Metkod oveidog (ckunamic Polurpoyphigr
class Sorople
Pot x-1o, y =20,2 7
void funi()
soPDddî+ons
3
class SubSample ettends Sample
void funa0
-Y
SoP ( subhactior s:"dD
clas Mainclass gm be
svm (Sh arqst
Sarnpie S-pew Sampe0;ubv
SubSample ss- oao SubSample0:
ss funa()
65. ulea oemde e oeod
Dotbpe Tule
twc Should ot chamete piototyee
id nt(ot
cces Spe ule
an it ual bope acces peae
pvate lou
Ldeaut
protece
public
class Sample
pickcia a un3
doss SubSample ettmds Sampk
potces vuna6 lafd
pubic void uni)1 valid
1l aRvate vod fun (O lleno
1/ void Puna ) 1iera
ception ule'
class Sampie
void Pan 1 () rows Jresupedicepion
66. ClassubSampe exends Sample
i void fun O6nous ception ien
ord fao3)frowST upiei ecepte /lead
-we Soeuld net change Tbe excepon he
oveniddc oetioc
-Dssieda deid class cbje base Closs
eoc vasiable
methed ovenidoa
-uthme eveniding
-> dupamic CYcTidin
-dynarnic rethcd dispotc
*Class oimal
voic ea O
9oP CDmal s'catiog)
void Secp)
Sop -nîmal is steepirg
clox Cot extends oimal
67. vod eat)
soPCatseat
void Srept)
soP(Cat Sleepin)
class Dog eterds -9oima
void aO
soP oos Catin)
voRd 9leepO
onf
prhiv
sOPCOo seeping
Pbvo
Atom
bosre7
clos Mainclas8
Psvm (9ming ags)
hotbr
rimal aenew -9nima) ()
a.ec C)
a. Sleep0
rioa a ne Bg e )
aat O
a Sleep OS
Dew Cot C)
68. aCat
a.Secp
ote apiograrn to chet ffe ver is
leap yea not
S importava. uil .Sconne
publfc class Main
psvm (Shfnq dvgsti)
Scanne sc new Sconne ystem.in
Sc netIi()
P ((veay uoo- =o) 11(veano1co !-o yeon7u=O
sOP CAeap yean)
els
3oP Coon- kap ycon")
cligs
mpovt fava u1Scannei
pubfe Class Main
psvm (Shig avqst)
Scanne 8C De Scantmey Sustem.in)
Po (rt o -+t)
70. To (ot f-o ien; i+) ye-
p
Fox (rot s-0 9s+
:SoP (
to (rt -o sjen-i, i+)
Sor ")
90Priniln ();
Sopin ")- o)p-
3
Sopin O:
Pos i =o.YD
SoP
71. bstoct closscs
Based
asedupon method dleftna+an metPods
clossiHed ipto tooYpes
Concvcte me1hods abetract metfiod
metodJs
ncooplele
Cornplcte metthod3
- mesfods wrth body mettods orout body
void Run1 () abstract voTd fun;
tet incornplele
->-Dclogshat s modified STBBe eyuood
abghac class Sompe
abetract
-> abetract class Cannot be retantiated (.e ,e onro
Cocae object oThe abstoct Clossampe saneoSampel
ena
Can Cveate eference vorablcos ap
-0-se-1
- But we
abehact class Sample B/valfc
-)-An abetact classs a class at an ortai
Oe obstract metßods
oettod a metfod orthou bod
abstiact
(.e no implementakon)
-> -9D abetract class Can Cortain ConcTetc oethods alo
(novmal mekod e methade wth body)
Relevcnce vaiable an be Crectes o 'abetroc
clasçeg
an abstract clo
etends
->An Omal class that
ovenide
Ovenide all the abstrac methodg iDte cla
basto
72. CRe, proviefig implermentatiaoo
e
roeihadR
absract cls tho ertends an abetact
cls oeedTo OVeTmde abstact ethods n
the cls
abstrac class vehicte
abetract voidl SHat O
abetrac vordrnove)
class ov etends vehiele
void 8lantC)
SOP CCan Slated)
voicl move ()
SOP Co s mong o
la8S bihe ertends vehicle
void Stent C)
30P hhe 9tooted)
void movc )
sop BiKe s moving)
73. claas Mainclass
PSum(Shing anqs
vebicle V neo vchicle ), 1en
vehicleV/lvalfd
VE new arO
v.Start O
V moveO;
Ve new Sthe )
V. Sav (O
V.move ();
abshact class Shape
double di,da ,arta j
void getdim (double didouble d
his di-d
1hisdo- da:
abstract oid nd -frca C)
Rectanaie e1tends 9hape L 95
class
votd d -rea)
arca = di d2
sOP Recangte oea; aread S
74. 3
ta mangle ettends Shape
vord-hd Areo O
aea =
0.5 dida
SoP Tangle avea aeo)
cas,Main Clas
psvm(Singangst
t1 Sbape s- new Shape; erO
Shape S: /lvalid
rue-new Rectangie
gel Oio (u5,u69dcn
S.hd ra()
-OcTaalc)
S.getOm (3u,3:5) o
he
Srd-rea);
3
3
Rectanal
ale-frca
= 20.T
75. Irterface
method
Tntaface a Collecterp all abstraCt
inteface Sampl
void fana);
oid fun 20:
Inteface mettods a deloult obstrac
obsthact ond pubie
vord un2C); public abshac ed funaC).
usi mplernents heywad, u Con impemcnt 1r
9erface
class tfart mplements an Spiface hog
ovemide all the methods hot iteface
- we Can rot CTCate obfect fuvYoiejacel but we Can
Cae reference vanable
Sarnple ne darnple O; ERROR
Sample S Il valfd h
usig iptface we Con perfam mutiple nhetan
ndirctiy
class all Concretr methods
abstact class-Oomal+ atshoc methods
methods
oterfoce abshoc metRods
Sample
subSamplc
76. ceface Somplc
vd funi1t) lpuble abstact vod-na ).
v
fan2 (Shing rarn), 11 pubic abshac von ShR
claas SubSample mplemens Sarnpit
rubiic vool fan1)
sOP I am Pun2 fron Sarple inieface):
pubtc void fuoaing
soP C amn2 from Sarople ie-face:
od funs)
Sor
a am-fun3 frorn SubSomple closs")
clos 11ain ClasS
psvm (Shicq avat1D
I Sample s-new Sample O; emai
Sample 3, Ilvalft
3 neo Sub Sampl1eO;
S fun1 O3
SFun
2Cromec")
Ils fun3 ); eno
77. Sub Sarople es pew Sub Sample
O
l sstna(); //valRd
)t
Se
Pan2U
Rn2
(Shr
s3-funaTmec); /hald
S
9s.an3(; Ivalid
SsbSormpe
tun1O
FumtShn
Pans
SS
OoTe
otefoce ine-facee
class
class B
iotefaceB
ctas B
class
class G ettends
ilerface B ettnde
iopemens
FrHenface
void funa ();
3
iefoce catends
Plepac o)mvet
void un2O;
oteface e eterds
void un3();
3
clas Sample tmplemers (c
nu
78. pubtic d -fuoac
Sor CI am Ran 2 om nieAace );
pubfe vofd fuo2) aro o
SoP (I amun9 koro inerface 8
publie uoid un30
soP CT artun3fromoicface C
berit
ctass Main Class
pavm (Shing nqst1)
fuan a C)
a= neu Sample
tl a furna) ou
tl a. fun 2(); ena
t/a tun3(), eTsO
b new sämple
tun1 )
Fun a)
I bPan2()
Ilban30; /lenoT
Ce new Sample () 7
Puna)
c:Pana()
C Run20
cfun2O: funBC)
Ctun3, O
79. ava de doesnt Sppavt uhple bes
Gn esface meitods ae piai
on u face wcRcds are Sot
class- collecho nly ancet meibade
Eac dass - collecf d cneee and absacs me
Eaca -
citecn abetioc meiods
ethod
Cane gisc
pe metd mpie ecdi
bod
vid rome (9 some)
een (Fioot ve
cos avolorqc nplerses
o u
n pabfe vod ane (9ti ome
SoP1 om mehed. n]ou +pose
80. publc vcid versicn (ftoot vev
SDP (I am fava verion ve)
clas Main Class
pubc Staeodan (i
lonugr 2-neuo Longun O ena
Lanqunne 7 fvalfd
T-Dew JavaLonquo
Z-rome (Tava )
class er
vid loca t)
Sop Ca am progeio per
itcface Urcle
m
void ha D
Cto Chd eienda Fannermplerners Unei
81. puble void batis O
sop (I om properh drom Upcle
cloas MainClass
pSvm (Shnq onqe)onbo
r ancle u= new CldO
biloi 3ocpno.
child c=Dew Child pJouol he
Cablood)
C habits (O;
OOTe In one picam e Can mplernent
inany numbe ClaClass3
tcface Sample
pool bini
ctaas clase Claec Clas D
Ctas A Omplements Sample
clas B3
implemen Sample f3
clas C implements Sarnple {
82. nal Keuocrd
->4nalvanfablea an+ bc Todiktd
nal mettods Cant b ovemidden
hal classes Cant be cxiended obeRtel
class Sample
psvm(Stira ongi)
finalnt x-10;
x4Io; |l erO
soP ();
woTE- inteace
pubfenta= 10
public Stotfe ot a-o;
pubfc Stetfenalintoa-lo;
deautnteY face vaiables ac publie, Staht 9
-final
manhey taq nterface
Contain
markee inteyface means +deaen doesn Contan
vommable methodd
an
intevface iy hmashev oeace
83. Tfss only -for maning pupose
ample
fava
Crauys
Tn java aTays eercnee pes (e)whereve
aC
an Omray ory ty one Cray objec
uill be Ceated ctape n heap aea wt6
we CTeate
2 detaut membeTS
1Set values be actual value
senats - he no value n he arsay
9hof
JO CTeae
Pray Teference vaiable rCcatio
Te vaI]
Co
tyPe Lvan (
Type CJ vo
ohnin iuslbe
e ota;
Co)
ipof
9ot a
84. ne typ [siaeJ:
e oew int
io one Sep
Syoiaa typeC var = eo tyre sz:
qRnI a=neuo in[5];
sRo
Sgle dimenal aay r
nt oj-new in5J
mult dimensiana amars
Jgd Orays etetuar
nt alJLI -neu nuJ[J
clase Dray Exa
pavm (SHig 9sl
otD-ateger PorsTtCa9sla)
90Pa:) emnel
s0P (lengtt :a ler)
fon o, izn; ta
aLtJ Totges parser (ovqs 0)
3
SoP -9nay elemens are)
86. 30P (nte ae f the omay)
ot a C3- ew intl
sor ne aay tements)
fon (oRo, Rea:lent6 î)
a[] sc-nexlInt )
SOP (-9ray -lernecs a):
Por ( 0e atenajh i
sor (a i-" o
3
p'--Xnter ae he errva
3
Eotevq orng elernens
30 28
C
art
rvay dlemen
oTo]-19
ali-30
a]2
Jo each loop
classfrroy er3
pev (Shing ongt)
87. /nt o t3 nw i3 io,20,30,uo,0t; eas
it oL3 to, 20, 30o,
uo,so1
-R coch loop
9oP (
pibtSpecial elcmens Rohe awoy?
->IP Be net elemen s opeottthon CurTre eermt
en int t
olp'
S1p5
3 C
u2
ropet jovautl-Scanney
closs Main
Psvm (9hing anqs])
Scanney sc-eusSanneSysiem in)
ntn-Sc netI
aRJ Sc.nexilniO:
88. sop(oft)
elersen Ps
pinthe Cuert element f ne
mebg o1 o35,
/p, 122 2 125
12
12 122 123 124 125 127
12
Fos
(oPo fenat.)
Tot a]7. 10
o11 7- s1) 5 for9,
9or
(aCt]")
3
Revey se Te qven-au
/e-G
35 6 9 12 21 G 5 3
clas -Pnay ExG
po (Shira t)
Sconne S= neu Sanoev (Sstenn
89. nt n Sc netIoD
n oy lun;i.)
at]- seneTi)
nt crnp - o[]
o]- on:
an- ternp
O 20 30
at a1 alal-1
emp a[oJ: tcrmp a[I
a[Jso[:
trop-of
a3-a
ap3]- temp
afo]- ab3:
a-terP a-temP
Iosct oTay eement a SpedA pesrtion
aTa
/p 5 oP1o 20 30
10 20
9o-elrmen
90. Fompovt java uRl Sronne
class nayex?
psum (shing ongsi1)
Soanne Scene
canner (Sptem .o)
nSc- netn ):
fe(trt Tso, fen :9.)
a[t]sc.nexlo()
3
int C 9c. nerrt
i pos- Sc-netTN)
nsevt egc
tex(rot Fn; >pes,9-
amDJ. anB-
am Cpos-ete
t
fox (ot o; ?en in
Sor (aTr3- :
50
91. pit duplfcae clements e aay
T/e-6 p-12
212t
impot java- u. Scanner
s
class DupfccteDemo
pavm (Shing ags[)
Frh5.c
Scannen Sc- new Scorse (Serm.i
Rn- Sc.netIr (O
Pn(-oen i)
3entRrefye
al]-Sc. netIi();
Wloic
te (oC=-
C-1
G; Jenzj*
9
c4t
alj]--1
te(c)
92. sor (ar] )
pio the diofnc elemenis the amay
õlp'
3
I2 3 2
soleropatava.ul: Scann
class oisinciDemo
PSum (Shiog a [)
Sconney sC= new Scanne (Sptm n;
t a Teus o[nJ
fo -o,ien i
a = sc. net Ini O;
(oT3!= -1)
c
93. c
clas
3
pot Na.u-Sconne
class-raErs
psum(e
Scanner sc= peo
Sarna (SysitmRd
SOPrta Tows:")
rtTOuos sc-nettit0
soPCencols:"
t
int Cols sc-natIrt(O
to1C3-neo i rouo
colsl
Sysicm out piiln (a: 'aa:
syeitm. out. priin Clenat a.lergth)
Sor (ntey mahii elerments")
for t=0 i2ow3;+
S
int j0j jzcolsjt
94. aPJU-Se.nexttnt)
skem.Out pintln Cmatit elements:
-PaCirt-oerous
(rt j-o jzcols j+
System Ourt pirinatI]
Sskem Out.pYotin [D
usgo each loop
Suystem ou palln Cmatii elemer usšing fos bch)
fortJ: a)
fo (rt xd?r)
SoP(x1+
3
System out pinilnO;
+ Sum mati elemens
ityt Sum=O
o int9-o,?2rowsi
oCto; ecols+)
Sum Sum aJUGJ
95. Sustem. Cout piptln (Sum
Suro TO elemers r
For (ntoerows,
C
pt Sum 0
-Pox
(oo j4colsj
Sum- Sum+ aRILG
System Out pintlo (Sum
Suro o dagonal elemernts?
Q02
Q0 ai
o (o Reroosf)
22
Q2
Sum= Sum+af]G
For o ienousir
FoGoecols;j t)
F==1005-1)
Surn Surm+oIL]
96. agaedfrays
3
DiGferent and fPervent Colums
nOwS 2 3 S
ornas
->Collectio of ngle dimensfonal omays
al] neo 3
aJ: new i T]
a[]- neus n
mpo GavauR: ScanneT
class Jagged-fhoyexample
pSvm(9ing angst3 U
Scannen Sc new Scanne (Systeor
Sustcm Out pin te nowos:)
int Tows: SCnerIot()
n at1 noniFouwsll]:
a rew int
al]- neu ]
a nau int E:
alne ot]; /
SOP nter t Yow elements
new in Sc netant:
97. Sustm.outpin es mah elemernts:"):
Fos
(to, ica.length
a1G1-Sc-nettInt ()
Systern out priotln Mati elements a)
Por intf-o; %a-ienqth
ho
aRIGJ- Sc DerIot () o
Shings
-7Guroup o choyactevS ae Calte Shibgs
e Con perfom Stng operatons usRrg casse
Classe
LShing 2-ShingeuPter Shina Bfide
Te
Sing osiects a Tmmutable obiects (Cont
Objects (Con be
ch
Geatirg hings usinghingorshructoss
Constructurs
Shing C)
Shig S- new Shing(
98. Shig (Chan chansl)
chan st7 l'o', 'b, 'c, 'd,'e';
Shin t= oew Shig()
ysko -at. pintin (Sh) tlabcde
Sthina Cca chas[7 Sarnde n oumchars
Shing Sh neu Shina (c.o3)
System. out pintln (sth) llabc
byt bIJ= 65, 66,69.68, 6 40} /BcoeF
uShing (bye asei acnarsC)
e Shng Str:eo 9ting ( b
SOP (Sh)l ABCDe F r
5Shin bye asdt 4 charsl3}ini 9Haninde1nt num chars
sth
Shinq 9h= Da Shing
class ShinaEx1
p3vm (Sing avqst)
Shing 31= "Cmec elcorne
System Out pritln 'Lench; S11ength O); ll2)
Shing 92- St. im O; o
Sysie out printinhengt;" 92 lenath(); M13
yskout pitln Uppeicase:+92.to Uppeiase(
Sustmout pitin (Uppercasc92.toAsoueraaeO
99. Clas ShiaEy2
psum (Shig cst3)
Shing Sh = welcome to osec and to hu
S0plnCot inder
o:stide to
er et)
9-0pln ("lastinde o: sh.losinder efr
S-opn(rs+nde to:4shinde (to)
3-0.pln (last înde too:4Sh )asiindet oF(
3-0p sub Bhinqsh.Subshing ())
der
+
9-0pln (sub Shing;9h Subshing(1,)
S-0pl (s emptyst.s fropty )
9.0pln ("chon at:"A sh. char At (4
chan s[j neo chao str lenat(
Str qet chavs (O.sh:lenath(),s,o)
o Grt-o; izs.lerath
Tread Sleep (100o)
3.0piot(ot])
Shing ormpariso
-versus equals methods
-+ wed to Cornpare addrass (cfevence
equals method s usedto ompame, Contnt
cla StinaEr 3
psvm(Shina a)
101. Sustm out pintln nep:"a9a); l/s2: (mnec dducal
System ot pintln("cha -t 492. Chan i(.
s2.delekchar At (5);
ion
Sysem.out pritln (s2sa)l Cmec tdutin
s2 inse 6,L'); i 7
n
Systemout pintin 's2492); I7Gmec-Tducat
2.7eplace (o,5, Java"); s lhy
Sustem
cutprintln C"s2:"+82): lljava Kducaten
Syslem out piptlnReverse:"as2.evcrse);
Cepttans
n eceptian 1S an event, ohich occurs during
The execuho a prorap,that disups be
nomal tow e procrarm's nstuchos(eccu
TTOV occuTS at Comle tmcSuntadca
mistote ane eTOvs. webave anyerraTs
he psoqsam we Cont eiecute theprogra
System. out pîntin (welcome")-buo m
uero
ceptiam Tt OccuTS a un tme uwe
Can un e
Car un he
programD
linig tuom
en: 5 b 0
sn uc o
nia uc rera
Calb (exception)
bas
102. Compile nc emmoys utime enonS
SumaAICal misabe 2. memoY ervors, 9lach
Ovevfloo, Segnenatio
faut
cephavs
Comile time eiceptians Tunhine exceptom9
(cheched eecptiens
--At Cormpile timc runhimc eceptions Cannat he
(unchecked eiecphs)
n
r s
necognisel
neicepthon Occurcd io the proam eicautioy
when
l -kminaefom hat place
aoenupted ExcephioD AroanderOutofPound Eceptom
File MotFound Excephfo Pumbe1 Fovmat Ex ceptioo
IOE Excepheo ThmefcEvceptan
Cephiontiondlin9
- Converfng sem aeneratd enio mesecanto
uAcT understandabie ena mcssage
-TO andle fe abave exceptians we have ecephionaM
handles
ceiONol hondles
Catch
3) tro
throus
5-naH
103. e blec
Some Set ines ane Kept undes e
to Conch
bloch Scan o bloc and t to1
Ss occuYd thy bo
hot cepom 34 any ettephien3 octuYed
notihs to JRC m
3 JRCjm) appocka to hat ecepho hroos
cnceptien Aoo try block to out Side the y bilen
ecephon
u-the end e ty bloch Gtch vcady to e
Cotch e cceptioan n ho Catch bioch hon
Covweapordig ecephin clo oYhcephon doi
5'
no mfomatiom toode nto eceptioo clas
hcephion class okect e
cepon cla s the Supe class -for a ecphin
chaes
pley the enechutibn oCatch bloch, nomal ertutr
hception clas ohject
Ercepfiom class s the Supey chs v all eceptPeo
T
clooe
oPteY he enecution of otch bibc novmol
eccue
Coich (cepfiao class obe)
104. itired
rmo indevdt Bound Eiceprr
OumberFomat Ccephon
PRthmee Esceptiom
+Class Somple
povo (9hq angsf1)D
System-out pintn Cpiognom eccutioro 9ionted)
n 3nteger po selo (ovgst)
9slemoul- mintin (o val s:4d
Ssm-out priinllo Cproopeoro tecutioo Coroptele
Gavo Somple 1o
output
piooam execution haved
nval s 10
proomam exeutiarn Coropleted
-PrmayTedeOut ofeounds Eicephior
class Sormple
pavm (Shing ovqet1)
SstemOurt pictn prqnam cieuhion 9ianted;
nt n Tnteger panseIrt (orvsTal)
Syeie out pintin o val :"an)
105. Colch (nayIndet Outat Bound Eicepham e)
ISystem out phnthm ();
n System oul pmilo (e-qet mesaq
Dumbev Fomatercepion
claesSample
1nec ineuom
povr hirg rga
semout pirtn ieuton 9artea")
nTrteqer poseInt(args[o1)
Syshern oul piln (n vat îs :D
Cahch (umbevFotmatEcephon e) nbolyom
He prindstachTracc O;
Systen. Qut piin (e) pro
YSm Out pitin'U nead to pos vane
System out pintnžheuon omletd
106. PithmetCTEicepian
clas Sample
psvm(Stinq agst)
Syetem-out ptn 'pmoqoro eaeaution statd"
ot a-ege pavecint (ovgs[1);
int oJnteqn pavsea(argst
Syetem. out pritin (c val is :
Cotch (Pitbmetic Eiceptian e)
Sysiem:out piptiD (e)
Sysierm. out piiin Cdivigion by a is not possibe);|
Sustem out piotin proqram eiecuhon Completed)
wt muHiple Catches
class Sarople p
pevm (Shig avqst3)
System out pirt poqvam evecuho Stavte);
inta Ieger.panscint (argplo)
ttbTntegev pansIt (aqp[U):
C ab
107. semout prtin Cc val is:)
Cafch
femaqInder@utofBoundaêxceptoni
i System out pirn (e):
Oystto Out piotin U eed to pos inputs)
Catch (1umber Fomat Eicepfon e
Sstm outt pîrttn(e) thphfe
Systern aut iotn oneed to pass int values").
S
Cctch(thmeticenception
-3 isrnfiyt
lSystemout pintn(e) fi u te
Systemout otln Divisior by o is not possibie)
tu
Susien-out pritin proqrarn 'eiecuton Corvplecd
i
NaTE
cepion class s e Super class o alcepioo
classe using icephion Clags ue an handlee all
hind
S eiceptoms
Catchhceptiane)
108. 11-ethmce ¥icepHon Taised
catch (etceptione
Systen rOut
lul2
Automctic Gonbog Collechon
wbenever we Ce not dlelettng e cbecsme
2a OccurS
umcPRered objects CP TRerc i ocfevence) one elbbe
gaboge Collectio
initates Re proces qabage Collecton Hen
Utomefe gaba Collectu Coltects (detete Re uneeee
jecs
Class Sarople
9
ureeet
Sample 81- neuw Sample ()
Sample 82 neuo SampleC)
elble to
Sample% 93- B 9onbag Collechom
Sample S2
Sample clas oame
-x:t othibutes
+etx(Ro): ud
mettool
+9ety yt) :vo
109. ons Snpe
pote9sKY
Yenn3
pae A 3 y Cov) #oe ectod
+y-Y
ph rhrtY() as rethod
oenny
ctox Mhclaa
Sanple 9 pod SompirO:
3-9e x()
Spem-u pitn vel a:9-n)
Sptem-out pRbtn Cy valte asqet v)
110. -fonekm ch calls see
prPn Metcoe
min
calfing-Runefon main
called-Rmese moin
the Colled urnefn and afg-Rrelbo Sore
fen 49s talleo eure urefio
yeneyoe rumibeYs or 3 t vecuson
leops
ww.pet jaNout- ranne
closs Sornple
9tofle
povm (9Nion ovp)
(o
Scance cneu Sconney (Syekern)
Spem- out prinh es n value)
noxrerT (
apoy(
tarc vdid oploy os
piem-out pintnl)
111. f (treyfaetergh a)
ecg-
ehes hs'a
poeretd pirain(
yssom ul pia (ea)
o ut pleind
pseuderede
Ses Ost,bei
o (nach e hom o )
fe
4 (a
Cons
2
Cnd f
a o+ 2
end-o lp-bsa
mild bra 24153
112. fot Pl
opa P
Po
P"p P 0
Pa
st, bsi
ele
1 ((os pa (e)
end V
pp , ,
swpp
93 pp
PP pp
fp
pirs pp4a
3rmey n (ra oih)
e(b-a>)
n ba-unr (a+2,b-2
se
eunna
113. Cnd
Tctunn a-b
end function -Amn()
Set bauo, a- 20 C 20
(c(ua)
b 0
else
aO+2
CO+ 2
op-90
End
b a
etsc
a at 22
C a2
Cnd
n a br c
Se a:), b1 olp'
for(each rom 1 3) 2
aa-c
b-b+c+g
2 2
b:bmod 5
End fo
in ab
3ntrgen funn (rta lot
-(b&a)
a-1o, b=10
9Chun 3 funn (0,2)+fann(b-s0)
114. End f
etun a-b ehn 3-la. )nas)
End
Aunction kann/1
a 2 b-2
Tntrgerfunn (ndaind )
3oegeC
feseoch Chom -2tb2)
a ate
Ero Pn
t (oe5)
ehu n a4 b
Cro
7etus o a
nd 1
etun at
na-tarcfeo funn )
9twing-ot,9econd
ole'-welcome
Dck
&et =" wetcorme
Second
et
Fist-stuse
pint Secord
+Set o- be1, C> 3
bred (1+ 6 modi((mod2)
pina aahrC.
115. Totger m
Set m-o
rteges aDuJ- {u,3,2,1
p-O
R(eachAom tb3)
m-maR
End
End fo
pint m
Integex a,b.c
Set a8, b=j)
Poeach cArom uto c)
aat 1
olp'-10
(6> )
a= at 1
else
Jump out d e loop
end fo
pTit a tb
Toteger a,b, c
Set a- 3, b=6. C-9
.ano
ab a o)p-13B
h ab
a a a
C b 'a
116. Sct b-2, Cl
Totcge 9,5,Cd,
for cach a from 3t
get a-, b=0 ceG d9
b-b+1
Poreachi fom otos)
c-C+b
9(aORb 0R c ANOd)
End foa
prfrt at
pint a+ btc
end P
(a equals2 ole'2
pint at
end
(aeguals d 13
fump out toop
set m, JF2
End
Tntepen al{6.¢. C, 3,3s
t End fo
pi Tounney at-a[]-a[
9e-2 Jouney
Sct P=3
alj-1
eisc
ow
r (each S Prorm oto 2
P p+9
aeaa]-3
to each from 2 to 2)
End
mam]+o]
P=pt
an
End fu
fo (each 9 ron oto2
pin
P-P+ olP5
Erdor
End fuv
Set aG, b=u3
oTint
DAqt
P a b
frr
elp-24
wHAle (P not quals
pntP
117. Darta Structu
Dala 3ucture ae uscd o oon3e
oTqoge
eiert manne neert, deleie, updote
Dora huctunes are 913pe
Lneav dato 9tructurrc
i) non- 1nca dáa Stuctures
inea Oola Stuctur
TP we ogange 1e data in
ltneo pasien
amays ned1t, Stacns, queues br
Oo-ineay Data Stuctuses-
TP we qanae fe datain hieyanchfal mo
1Frees Grraphs
nked lsis
Jnean Collechon ncdes (elements) ae Coll
Call
JSneas
1inked t
Sinked 1sts ae 3 ypes
Sinale nked 1sts
)Doubie nked 1ets
rcula inked lsts
ofsaduantaqes aTays
TOT
Stat n 8e(we can'tncvease tRe S
te arrsay atuntime
118. C a Co1lection homogencous eleroers
dato
a[o]10 a[o)10
alJ= "abc
Sequerhia mernony (Continuoug
memo
9aro
Cquires8
nt aC3 = new in ioo]
insevhio/delet apeTatong ad Cost
cPtective metgsing proceses)
Suftabie fo vehiving opplatding
frays one
fossible
feoens
Tn asas andOm accexsing s rossble
Sop (aloa); Ilasec
ne SoP ([1ooco0oal);1l 1See
Sngle ned l ol
nhed 1fst oe way Tet is a
Colled nooles
Stoqle
nca Collechion daa emeis Colled nooles
dvfded
data elemets
ncon
nto tuoo Pelda
3heP&st elc
Contains the ntomation
tcv each node 9 dvded into tuoelda
and he SecondPeld
Centains
node
Contains
he eltment
net
te addve opHe
and he
The st Pield s Called dala eld and Re
eConol Pld Called sclod
nnRed
Sccond fug
b
) data field
2
The poinle to e lst node Contains a
119. Spectal vatue C&lled nulln
c) 1fred also Contains a pofter vaniable
ohich pofntsto. tbe -Prst Dar
Catled 41EAD
Re n foifrharp poe
bead
Liieby potsis61poite
1000
data cddress doto adde data cddves
10 2000 20 3000 null
20 00 3000pY
TO implement data Shuctures we equre
2cquie
SeP ePevental closs l 1o) o
whats Selfeferential class?)20e
placing nCerence vaiable a3 Q, membe to
fe baiipoi
.Same clos
tob
clasg Studert
ctstls
Fom
Shin 9name
9Hudentent
3
StuderA S1 neto Sudet()
impot jova.ut, SCanner ois
clas Studeni 3-it b cieb
Stino Sname
120. Studen OeTt
Main Cas
Class
Student nead oulL ta ncwnode, temp
NOid CTcatenode ()
ncwnode = new Student()
Scanne sC new Scannen (Sustamn)
Syste) Out point entr Sno:").
newnode Sno=Sc.nettI)
Systen out pirt eotc SnamC
Dewnode 3name Sc nen ()
Dewnode
. net = Oull
9P(head =null')
headrewode
toî= Dewnodeg on
else
tofnent neonode
a= Dewnace
vod dbplay ()
Fox(emp -head Aeropnull 2
tep-temp.ne
Ste-out. poiotnemp.Sno*
temp 9oame
121. public Siatfe voc rooin (Sthg l)
new MainClass()
hosom
main Cta
do
Scanne Se- new Sann (Systemin
mCocatenadC)
Systern out. pinin (" do u want to Conthnue '
P (o-0) oessey
break hrsn aboosusrr
gie (tue) bu
mdeplay1()
bto en
Kod nurnber c node. in e give n ed
vod dRepioyst(
for tep =heod emp)r rutl emp kmp1
Spen.on pín ro rode Cour
122. alter nate node 1
The qiven linhcd
alfer nae
print
4he
1fs
t Count:O;
intemp-heao temp= null temp temp ert)
Court+t
F (Court %2 jeo)
SoPtcmp'sno 4 termp. Snarme)
ndout given node s pocsent ov not in e
qiven 1st ?
Nofd Seovch int Keu
n fl0
Postmp =hrad ternpnull, fnP: tnp.net
Herp Sno-K)
9op
(ound")
elee
Bopot dourd );