0% found this document useful (0 votes)
7 views

Java Assignment

assignment java

Uploaded by

Narender K
Copyright
© © All Rights Reserved
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
7 views

Java Assignment

assignment java

Uploaded by

Narender K
Copyright
© © All Rights Reserved
Available Formats
Download as PDF, TXT or read online on Scribd
You are on page 1/ 35

cojed Ovientr SYGmmIv SIng a vet

re
anyt) he
Wha es Java its tri Onee amd rIn

Matyse
8 Jvm Java ne) acU as a
un-Time e ne
Viyhua M
ha Tho orHyaly
Sun Jav pghGalions. Jum i one

Code Jum iS
in Jv
Ctls e mar e ffod pre(e
Envivonme
URE(Java Runhime
De & tu
Onte un Ayo hare)
Called hWORA (W
e
ppiolons ame
Java Oe

Ja va Cods C
C o m d e v elop
meaMS A Y O Y ) meN
other SaUa
an any
iE lo run
y hem Md CM eppee
lhis is a

othotdamy
adjustmenb.
naole Sytam

lecause of V
poSble

avs is ORA.
t ke cc
prorsmig langue*s
tdtjonal ve y t e
I e Se tbe
e onp ( e
PYogYams tnder yY
whon 1t pashc-loY
Code undlevsfood y a
tht S4me (oda
to yy te
so fyy
hadiore havdida7e, l d d
with differe
anotiey
machne

caufe an eve, o
Cede oil
undestonds
dife b C m d e v S h u e d

e Cohe
Code
have t o Y e compee
yoy
en hod )aye
ava,R, The Procve m Cem vexteto code Are
no

|Undex toed 4taacdoare, xathef is (Onverte l

te code (.clas3 6le) tuicd inFexpvetod uM


,

one tomiled gener les loy Code i l e ,


JVm ave Virta
un yheve any machne) L i d ho
aed
o n e Once
Macne) ame hence i g nahe o
u ny here.

Javn fro8a

VaC

(Compi ler)

Byle o de

cle3File

MacOC
indo inur
Waeinave
n y hes O ontyhck orS
n
s
melvd t a
Aa A Contnc n Dan s i m i laY Coa
clam is Yeated
nvoke e hey an objek of tte
name
ho e came
ave me tieds CantnlCho
Onike
ha i clogs Cnd drs hae any Yetum

clos Test
TesC)
Coshructy losely

be divide into 3 ypes


n Dava, u cfors Cort

Jav ffods
Conutyycor: Simila tG me

Aq
No-
mo no
hawe CUn paramet
C6mAtrucfo May
av
ans
a9met). L a (outuch does not accopt
ConRfr Ctor
no-arSumen
iS knsWn a s
DAYa Mete i

cas Main
i
choY wrtt
no pora meker
Main () l Cosd
pnvate

Costucho is celle4)
System. o : prin

vo4 Main i ast)


Puce vert stedie constnchr wiHhoutany
heuw Main) calling lte
Maiy o6)- faramater

ysten-oupistdnC"yalue tf i:+obj.i )
et pa
Conttrucho 1 (led
Valuue is
Java Pvme Aexized Conefruc frr
amoY Ye mr hr v
A Javh (onstuc Com c o accept one

Sweh t t rchore ae Knaw as pe T9 mete ri7 (onclru rh if

elass Main
S n lang a
velue
Wcostrchy accejling ciugle
Main CShiny lang)2
langnoqs lang
Langg
Syetes- out.p rintln(langangeo nyammirg
t

puuslic Ctol vmd man CSting ags 1)

Call cstsuchy by paus1 a gle velue


Main o j 1 n e Main C Jaus)
Main D.j2=ne Main C Plhy ttoh ")'
Minb3
ne Man c)

r o Vamannin Xanga
o po
Pyan frogva mmi9 Xaug
CProgrenenting lang
uoge

3 Javw Defaul Consfucfor


Jaue Cprle
ctor,
we de nt Creale any COnah
autonaically Cveli no dv9
a c t cfor dui
Castycuy is colled
execulio prosYay s
delaulk Comt ruetoo
e
evolen o
c4he vajf May3fis avgs C))
ptalslie
Called
Aefaul ult co uL Y S
Mi obj ne Man)
Ualue
System.o prind ly (" Dejault
obj
ytey. ow prid tn ( a
System. t . ptntI (b= "
o b)

Dtalt velu
er pu

Lfalse

loerute tis
and Spey Kep
a ifforences
ho de access neHods
ue t
gpeY kay
acce
Pros pare closs
utle t
wlle t iiis
s sseel

Of Cren
clod.
e
o V-
metods
keOrd
keqwovd 11 Java
resestef
vesesvef
e
usd Ce
a

tis
eguwosd C fs
ber. D
os a idti
e 1 OS u e l / telke
Lwe Coun in&tomce
Closr a
evenk Contex
yete vano
ca bt usel 1q
a e mYS
class
clals
nien ela) o 4 vreut
ofCGYYe
aa s A
an4dg me
e
ee paep Cahsfsy Ctor (oll
Con
Con
Os UYgumel
lse ose it
na n
sta Ce
nc e
COm closS
vefuYn
cqye
lo uSed to
Can
clos RR
SHalie nb
UDld GEGC

tna, a o0
Sytem- out. rint In ();

ttt, be 600
yhem. piatn C)

te vdMoin S f n 6 9 I )
puklic

he RR.GEGO

ed pu

/n vaYIOS Cntex as ivey belreo


Supe
Spex Com le el
Cas
porerl
Seto e im meiale
i cm
inStamCe Vemaste
mmeliate
parun las
Parent cclas
Com e used s vfer
1
metwd Pve clos
(los3
m meliale pYe
use t r e f e r
D E (am be
ConstruCtp,

emple
clas Paent

Stokic in 6 20
e less Bale extemls Poves
VOol C)

(cupeY.a)
Jystem o t pridIn
stem oud.
.b)
pritl, (stY.b)

vad main (Sfn-y 7


s talie

neo
13ake (). YYC)

and OuipStrtam
Strea m

tke hie ra chy f Input


Cpive
claxses

nput yeam c LF S t h e
sptY

abshaef Closs
clas3 1 ay byle
p u ream ay inpul r a m
cla3ses epre celauj
claas all
Usethmethods of DptSfream

Descisoy
Method dota - o ta
te next yle of
y vend ) eads ke at
pud ab ctac stean. i v e tums -
0 Extpton
p
ttvoS CAd l e
esfimale o thu numSey o
iu availalle ) ASetyn ane
pssli
o Exceftion ctre inpo
void close ) thens
IS t e to close e
Ppb
Stream
o Cxception
-
1nput team

elnpurSheam Bte Ava FieInput RpedTnp Ceye Inpu


Inp.tth ea hyeam Hveam (tsec mn

Drka StreamB«fevedlnp PchBackInpud


Streem Ctyenm

Outp Stem chAS


abshact coss. DF is the sopeeca
oukpue&tseam clas5 is an
A ou
dall classes vepresenjng an outpat heum of byE.
o to Some sink
a e Sendc them
SE Qcceplk tpubyles

ureau ethods oulrsfveam

Me Hs Descripio
rooc t wita kyE toe
puelic Vd wse (u) ufe a

CUYYe bupuk theam.


1o Exepton

b2 puble uoid wie (kye C7) uccd t oil


s an aay
uros 1o Exterton oyle Co Cqwe oudput ream

3) pubke void flusG) throws lushes tt Cuoved otpu


10Erceploh eam.
Culpul sheam he vanchM

he Oukpuk
ByeAs Tay Rleaptveam, rbp.b Shesarh ccp-berem
heam QtpubShtany

DkaalpThemBulfevkiHpd iCheam
Styesm

DEference e e y metod Ocsioadivg amd Oueioi

Metod Ovexlomdiu Metuod Ovesid


Me btod Ouerloadiug ic a Metlk ovemdi iasun- hime
pleine penuphism Pelymopi cM

alps t incresce to vendalbilkty L e d to ran o eri


impemedadion ofthe me tal t i
of to PrgYem
is altady pVovidel loy iH peed
cl9s o uper cos

E OCcu1s with c8 Tt Is ptrsmed tn tao csses

wrth nhe vtome Thticnship


Metied overloadtmayo Mefhed Ove1i luay nee
uiye1nheamce nhe fom.
O

Melhod Ovev loacdiug Mend Oveyrtd'

Me nd Ove YN(
m e TUad Ovex londiuy,mettas M eha me SGTme
MMS hae
mug heve me nanMe amc
yatu
afeve Slawt, eS

Tn me tod Ove sidiug , h


e tuod ovevlodaing, tho
mug b e Came
ehwn tpe cay o Can nee etuan e
Co-aYa

hae o chomg to pan mefey

Pnamic
Stake biling jis beiug we methels
Use oY Ovelling
Y Over loaele4 ne thod3

Eves bteN pevormane ooY PekuYmahce


t aCon ehiud his is

na tidiug of oveYsiAko
Aone a
me hd 1S e
Duntie
amd finol methods
vol ond fnel meheds ivale
Cawt be dveyYdden
overloaded
shoul e same
tsqumen
s h o u t le Argmen st
ePere stile Jeing inmetha ovesiing
elhed ovexloading
xaple o Nethed Overleadi
inpost java to.
clas Me thalOverlo ndingEx 2
Stalc in add Cita, int b
reuhn at
ctotic ad iut a, t it

Yetu a t

Pubic v i MaiySting a v S )

yste ow. pyln (" add () Jith 2 pavaeteTC


Syetey.cu n t lu( adl
u,c),
fertD
Syctem o . prisy "aAA C) with 3 param
System.out. priutn (add Cu, 6,7));

add ) with P T a mete Ts

adod )
t 3 para Metess

xample Metthod Overl i g

mper jaaio. *
class ni ma
"
O mehod obse clasg ")
systey. ou.poinbIg C eak

Aninn!
Clos Doa exte4 ds
Vond eat )

privt-ln ("ead-t) method o deived clas)


8ystery ouo-

Cysten.Ous. prind CDbs is ehy


Me fho A)vexYirn y

cl-lic Uojd Moty S frig aT5))

LogdI Mew De
ADimal a l h e A nimal )
. east O

a eatc)
Animal n i a l - veus Dog

Ani ma. eat C

derived e l a
Ou-pud
e r t c2 me hod of
Do iseatin
bse class
Ca-C) me ho
ea
derives clars
eat) mefiuod o
Deg eabin

SECTEON-B

9Hno ExcefLon ondg fc one) Gie example

u Exeeptios adllins9 tn Javg ic


one o te powerl
Ans
mechanicm t handle teYunCavne erors So thalte
maishextne4.
simelflow of Ku apphcatioh can

Supose teve oNe LO skmek in JeNoPYoSYe and

Om tceion occuIS a Sklemev Stvesh ol


ie slJimenbs
h Code uet e exetted.
han e
HoNee ve
D s e exete
6 wil
stule m-ply
maurla
t veg otJe
Pe6wM cepR
on ha md ing ,

se xe cteA

elou
Jave ceplion closes ic et uen
Ikeievacly o

ThYotda L

GxceFlion

T0Excepti on stackOvesflo4 Ero

vistae)achine
SQLExeepkon ErroY
Class Not
FouadExee ption OtolMeMor
ErveY
Runtme &vception

Aritheti Exception

a fowde r Exeeption

Aambeofmltyterkon

Tndexouto}Bound
Extejlion
KtY OYd Descipton
hey KeyWord t e ?peaty a ock he
JShonle pate ay exleuon coda. L meo
we
(aME UC tyy lock alone. hrylock mus
loe
follawe i t e r ctoh or
fins l9
Careh heCakh block is usd ts havdle ta erception
musE epreceded bm ty lock uidhmeang
we Camt use Cory ock aloue DFamae
bullswe by binally block ater.

Finaly binally lock is seA t tretule a hecesgor


erthey ay
Code t e pmogvam. DE u exeuted
X Ceptuoh is hand led or h
hehYous"
ho p/ord used t rod anexuefuan
to dedare
hsos thethrows eqword is used
tha e c m occuY
jexceptions DE spe ifes
OM excelion In e meltod. DE doe sSN
hro AM excepioh .D alwaup use w i melod
S1ghetue
fy a a
puldkc class JasexeephonExoample

puic static void molntnug avgtCI)


i dea= too/o

SCaRch(AnthmeicExepio e)
shem.Ous. primnLe);
ysten. ot priutln Cvest ot t
Code )
d n n g ffev.
clnonm
Whot w thu doveME belueey

lrivgBuffer
he Striug cla e Haiug Buffer closs IS
Iimmu lable
Mutlle

amd
)Sting ik slow amd (ohSu mes ring 13u ffer i

MOYE Me MeYy when we Conceake


lonsumes leR3 Meme 14 nen

hale tvo many tings be cause we Concakenale lnint


evey me ft Creles new
nsame
the Sring uffaY dlass doesn
3) Sins ClaRs overvide3
cla oveide the eqvalsc) nme te
esual) me od f obje
So you (n comp4Te the ton ken o Objed clas
eguals t)
otuv trinas bey
Metbed
Jlowex Stning uger class ic kaste
SAring Cla is
ing
while pevkornny (oncate nadion l e perhoYn(on Cake
nalioh
openalion epevaon

sina c lass uses (onl tam tringlbuffer u(e ¢ teap


pool. MemoTU

pubhc clo Concaptest


puki ctke Stnig concalbi{ring 0
Stit"java
C i i c o ie 16008> i4 +)

ttTpoid"
e tuyn t

Pu bh talkc Sinq (ontatwi HStingafer)


Sti w ("Java"),
Styingbuff sL= he

S6. oppend ( Tpoiw")

Yehurh sb.toltnng )

vod mayStY1ug arg3C))


Pubhc

onG stasHlima System. CurrenlimeMilisO

ConcotiHh Striva O,
Syshem.oub printn Time tkey by Concaling

SAn t (Syrtem.(urveTime tMIlis (SeotTime)+S")


Ctent ime-System.CuYYenFlinmeMitlis()
ConCarWhring Bulfer)
Spstemoupridln (ime brakn y Conca wi
triautfu:+(Suswm. cugyedTme Mills)-tea | ime s

Oudpd
Time bken by (ontaing wit tring 98ms
Time taken byCancading wth rgBuffe: Oms
Time

You might also like