Dashrath Nandan JAVA (Unit2) Notes
Dashrath Nandan JAVA (Unit2) Notes
allectin
Collectier Ln jaua is afameuok that praides en
Lanckitectne to stere and manipulatu he ge f
*Hienaxchyi
Jhe jata util bactage cotains aucassesand inteface
tor he lollectiern frameuask
Iterable : In erface
- - e : Impements
exends.
-Necton
JArray Deguel Tree S e t c
Stack
*Methocs af (ollechion 4ntenlace:
Public boelean add(Ee) :insert an elemment in this Cellecten
Peblic boelean Yemove (Ch;. Ele): elete an elenent fron the (8llehen
Hbublic t Siel) : retuon the total nmbe of element
Checks cellecton iu enpty:
iubic boolean eguals (obEle) : 4/ mathes teo celleclien
clAsSMAGe
Date
Page
* Terate indeface:
eator intojace ueidea he Jailty g ttraling the
element ina tasuand dinction only Jhree chods o
) Publie boolean hos Next ): Tehoen tue if ileatr has more element
D) bublie Bbjctnext (): ksenthe element and move Cuvsor pinka bles
i) bublic usid Yemove ): Yemove Lost element etened by ileiat,.
inkeol List
i) Diagram in Hienovchy
DJhe auxaylst implements linkedllist insement the
the lit° intntae cellection intofacee
dubly lnked list t
to store tke slments.stene Hhe element:
iv) dt can act as a litonly t can act as a ist and Quu
be t implemet lit enly.| both
Qnd accsino oloto.J Ldata
Vi) Manisulatien usle Manibulatien u fast
Vi) Conshuctoys t oArnaylst(0> uyalinked bste) : Congbucemphy lit
Avayist(olleeion C): "linked listolection c):
Ayoylist(nt Capaiby):
Sromye import jauas utl.* imbart jaua- util o*
class
phath clas Dshrath
pubie sttie woidmanSting Ioay) þublie statie uoid mainShing
Araylist<stingy list=huw Araylist LinkedistKsbing) al= new inked ust O
ist add("Dash ah): al add (" DQshrath");
ba st add'Nandan); alo add ("ANandan");:
ioratr ib= list. ieretor (); erator<shin2 ib= al itrabrl
thile (it. kashint0) While (i has Net0)5
Sap( ib nert); 332 SoP(iho
0utfti Dashyam
natO);
Cutbut: Dashyath
332
Nomdan Namdam
cassMste
Date
Paqe
t a n Hastset clas
Jaua Hashet clas cued to cCeate a collecten hot
Lsesahash tasle for storage " Hohset stoes the
elements by sing
sing
Java Hashsét clas
aa mechanism calleol hashing
linked Hshset
Kexends
ellecie Collectipn
ext
im þlements St
Abstact sot rblament
Abskact Set
Texens -ext Sorted St
Hosh Set
inked Hash set Nauigalle set
Tmblemeny
Fxame: Set
Class tshSet wile lfe hasNext)
bubie sIate loid man (Gny la»g) Sep(ienet O); 334
HoshSct (sbingy slt= newhshSet);
Set add( "one'" Stadd |" To");
Sct add " Ihne' ;Set.cd("fous'); hree
IeatoyKsting>= Set: ieratoy t);
elAssmate
Date
Page
Adiaailage Ruadantage
imultanLsus Qccess to multe
aplicatien
Hew t cueott hread
By estending Thyead clau by ialmentng unnabl
las ulti exends hyead
Publie uoid yunc) clas Mult2 inplemnt Kunnable
Sop(thread is eming)5q ublic oid n)
PS Vm(Shirng Jangs) SoP("threac is unntng');?
Multi f new mult (0j
D) Process syncknigotion
Helps Keeb threads from interfeing win
Mutial Erclisie one anofier sile Shaving data.
By Snchron'zed method
block
By Stat'e synchbnigation
Cooperatienlner thread ommuniialien in jaua)
i Synchaoned Method
4is uidto leck an byect thlt =ti?
for any shared HesDUNLe. Puslie ueied yn (05
bxamble: cas Table toprint Ta,e( 100)3 33.
ynchonized void þint (int n)s
Aalie clas Test Synchrenigatien
SoP (h*); PS ym (Sbing(] arg)f
Tabe ebi=new Table);
CaHA (aaptine)f sop le);i;
clay ma Thsead! exlende Thyead
t00
clay My hxead?exends Thyeag S
200
?Table tj joo
Date
Poge
) ymchronigud black
3can b wsed to bentom you makL any sale melnsod
dyndiangalin
clas Tabls
ueid þnt Table (int n)
atealCrcspicn e)fsople) 33
Rest Code Bome as
dynchaonigd method's lode
io
Consumey in,
tis an Dbstaction that Cihen broolues or
DByte Sheamy : Roauide lonunient means fo hanalng knh
and autut st byty hut
TijutSheom (read data brom oute) fandlig inhe
Ano
Outtut Styeam(Stir data to odegination)
i) Charackex Stseamy:. .ou handling nput nd butut st
ChavacteHL- Readr andl Winn oe
Charactor sheam:
Fle onsole
oking oe Io Stream: Asocke
Al Consoil Socket
oo1
TnbutSteam Output Sheam
Souxe Java ioro Destinaion
Reacl
Abb Wsite
I/O Stream
Byte Avray FlteH bibed cbfect T/oShream
sheam Io Streám Io, Stream Ho Steam
Data Buztered Push Back Input Stream
oStheam Pint Shream
Ex:
Import java- io.; imþort java- jo.*;
Clas Example Class Example
Psvm(Shhng (34r9s)tys PSVm(Sting C) rgs) toy
Student sI= new Student(16,"Dr); 0bi. InbStream in haw UlsT
FOS fout= new FOS(" t); Shudents= (Student) in-1eod Ohjec Ü;
Object-OS out= nw O0S (fou); Sop( S- id+' "+Sname) ; G
Orput: Soualijcd
* he keyuod: tramsient
hanaint keyuord is uAed in Objcct Senaliatin h
tranint oyuerd fuuids t uith the abilathy to
contsl th srializatien þucs and giue w fleibilil
*ening:
eract
he sbject clening s a way to
reot
clas uld'to clone an Clone () method ef Ghyect
’Jhe jua -lang. Clonable
buby the clats wthee inerkace must be implmes
&hyect clone ue uant to cHeat
alassnste
Date
Page
* Annatations
Anmetations ane used toadd meta- data to the aa Elements
ie instance variable , Constuctors, mehods lases, ete
Annotatien stat uith @
lytes a Annotatien
1 Morkex nmetation i eOvenide annotation aswnw hat
he subclau method ia DreHKioing the parent clas methad
Hhas no method
*ustom Annotations
sUH-oened annetation! can be sed to nnenate
usgyam lements
O[aen spcfen] intrtace (Annotatien Name>
Data ype (Method Name >(1 elefaut Valua] ;
Examþle : Thes:
Clas Animalf Predehined annottions :
Public uBd YUn()F PDeprecateed oveice
Sop ["Running"D3?
Clas Dog extends Animelf @
Subprehaenigy SaseVanang
Pebllesveude
A
td runl 1a-Meta- annotationy:
soP' Dog)532 Retentin Dowmentd
Psvm/shsng [largs)
dl" yun033 3 13 (ustom ainttatiers
Outut : Do9
beon important sín the deueligme
anguape Jirit has
ates-diwn deuelepment
sting is the þuecsef checking undinalt an
llnit testing iu dne at the dlevetohen'slwel
Feases:
DJUmitu an oben sourceframeuork
Prouide annotatior to identiy test method
np Prouide test nennes for Humningtut
to wmiti edes faatea
Unit Test Case i Jt i a bart f code, hich ensws
hat aneher bat code(method) orkA as exhected
*AnnotakiorA fox Junit teting
Test dhecitis that mehod is testmehod.
Before clas methed invoked cnly once, before
Beore mehod inwoked before tet gBasting al tet
Aer , 9 Afer Clas case
%AMent las
Jhe orge jnit oAset clas
bueidle metods to ayet
LMetols :
Void asertTruel bookean
Concliton)
Check that concliHon
Mad att Nul |9hid y) : hck
that ohject ii ne
alkssste
Dashrath
Nandam
Date
Page
* JDBC OBDC
.hn Database Connecity: Open Daabase Connectiuity '
i) Uscd yor eny Jaa langioges Used for any lang. ,<,c,
ctt, Ja, ek.
i) We can le it on any blatorm Ondy hhindasBatform.
1) DBC i Qhjcct Oriented
) SunMlcresystom in 13?7 Inteduced by 1Miesosat inîn 1992
1
*TDBC Arhitectue
Java AbplicaHon
TDec diver Mamager
DBMS
JDBC Driye.
JDEC Diver is a oóottuwase compenent that enos jaua
abblication to intovat with the dotabase hoe are 4 typa
TypeJ: JDBC- QBBC Brdqe Tybe 2: JDBC-Natine API
4tconunts JDBC methed callsNatue-API þay-Java Driver
into the ODBC functisn calls. Convert JDBC Calls on theclient
ApI foY OYaclei or Othen DBMS.
JDBC-0D BC 0DBC Vendor I. DE Jdbe APT
Jaa bide Dhver Datab
Naive
Java -APE Vendor
disey DB
Dver ib
t MVC hamellouk
Zhe model- iew -Contoller MVC
battrn that ssenates an aplication nto the
man lgical Comperent- thé model, the uieo,
he conbélloro
alassnate
Date
Page
sti ued yor all the UIlogic sf asle' is mo del pesed to iew
D) Controllen :
Contstlen act as aintintace blw Jhe uiwendiy outbt
Model and lliew to busces al the Butput
busines legie and incoming Yeguest
XExamble :
import java).*3
clan 'db
Psvn (ShingClargs)$
ry$ Lood the ves
das for Name ('orade jWbc dnver):
Connecion (on =Drives anagyr 9et(onmictien Jdbc torace :thin:D
local hot: Is20: xe");
Cseale connecon bhject
Stalement Shmt = Con 'reate Statement U;
Resutset rs = execute Quexg("3elec+ *from student' ;
Sop("value fom shudent table ane : ");