Dala
ARRAYS
ntmducion
S
komopeaN
indexed uoleation
dat Plement
o ed
Vaniabe po that readabilt
IRnpved but mcin disadVantaye of anhays
decreing the ize based Dn regire na t
heae t he ahay Concept
hod c tompulagLy
Cnow ths size in advance whidh
ATta Declana tin.
1D Aay Declanation:
1nt[] Jt i tecomoended hecause
ngme is cleny sepanated mm hae
A+ he time ot declanatin le cant speci
ottnise well get (omple hmeeDI
2p Atay Declanotn.n'
Dote
Puga
intGO
which the toll wmy ane valid ?
int Ma.ba-2 b 2
ane tnyia to apply for nekt|remainina, vancble
XX
3-D Aray Declandhen
Jnt lai)
Data,
Poga
Atay reohibn
in Java is an obiect only
hence we can create ahQys
hew operoto,
Qnd not ovoulable to the
pngtammen ede
Jnt[ a new intC3]ts];e
Output
Array fype
dowble CJ ’CD
short C
LB
booleanC)
Delu
CONCLUSIO N
aay crea hoa
compile Hme ere
hew iad CJ X
ti's legad o have an anhay with size Oin
Outaut oLif n value is paked thnough
amnond line angument
31fut a tnying to specihy Gunay size caith
Ome niçative int alue Haen Luell qet Runtim
euEenia Saying Ncaatie ArtaySize Excerstian.
int i x= new iAt(-3] RE- NegcteAray Size
Ecephon.
To sprcay Array i2e allowed data types
Qne hyte shotthanint if Lwe ane tryng
to specitu any odhen upe then elll get
Compile hinae eroE
int C]ngy intC101:
Lbyte ’short
tintc1 Xnew Intlb]i
S30 cha
Data
Poga 26
NoteTk
int dat type
Hemoy UOr Snce the tofel
21649483649X y bytes
8S899345Y hy tea
83R860 960938 Kbytes
R19.99q94618Sy Mbyte
9999999963 Caby tex
integen t numben tom lange
k Even in the irsE cae e may get untims
encenhon if sutiiet heap memon not
availoble
k 2 Artay Crea tion
I iava oD anhay not inaplemented by using
mahiy sth¡le Sun penple folaused anay o
amays appach fot mulh-dinehsional
anay ereation, The main Qdvantge ok this
aomach is
js me morg uhlization S Ée ia Dmved
impeved
Int1nLw int2][1:
Puge 2
n0]fo] hew int
hjch o the olouaing Qrray declamaton one valid?
hew antIJX
hew int 3]C
new
Attray Thi thializahon
Dnce wecreates ananHQy eeny element by defeult
inhalizod with dekadt vaies.
letofe
to henewen we ane to priatany rekeinee
Janiablentehal4 ten Stng mehod willbe allid
Data,
hich is implemeated hy defaut to et retuh.
claxharm hakende- in heua,dlecimal fa
Sopln (w) Inasge
sopln (n[olel)
lntcIneeu Inte]C1i
Nul Pinten uceptiba
NoTE
bucephien
Once we crea tey an anay every nay element
ay detat iniialized uitk dekault valuesif we
Ro SatHshed uit detaltvaluesthea we
Can ovenride hese values mth Oun customi2ed alue.
o]10
20
2 3
ML31 40
M-] 60, RE- Array hdex Dt 8ond Excep ton
X[2-s]= 90; CE- PLP found: ceuble regued:int
29
ToE1f we a tång o acexartay element with
Dut o tange ind ey (eithen peshve vaue jnegative
L value) then uwe'l iniraeenception
Seing aTray TadexOt otBoundExce phiena
Arey Declanation lreotion nitializotiorn Jn
gle Linc
We can declan creat nd hitiale an ana
inale lin (Ahortut reprclentetion ).
iat(3]
char J c h ' a , ' e u
Sale can exttnd this ghortat tosaulti-dimenlional
aysalo
intC1L1r1
Sepln Lx21]Ce]): RE-AL0DBE
SoplalyJ[3(01:gE-Aloo &E
Ropla(x[2la]) KE AID OBEoho
Data
Poga30
e oant to e His chartut campulsoxy
ineif uoe ant ting to divide into
mulHple ine
tatINI0,20,30
ME$10420.3041
(E- ilegal Haad o Expresio
len gth w
aal vaziable applicable
lenath vaiable represortsthe size o the aray
Soplh .length) cE- Connct find 3yrm bul
Symbolmethod length l
lo catien dax int
lengthjilongth l) isoa inal me hcd applicable
biects.
retums ho ot chahotters present
String Se "durgo
to cation: clas jaa
Deha
Paga 3/
NOTS leath anable agmlicable hoxnnays hut naf
applicabt Shri caject hue' not tox axays
SA"AA"'ABA'
Sopl Salangt)i S
3ymbo)
nt symbo): mn ethod len
location:cles String J
XSopln (so]lengtt y ce- Cannot tid synkol
2ymbei vriabk lenyth
loca ton: cloys Java (ogstn
aultidimiGnal arhay lengta anakle
eptlents ohly bae siz e burt not total &ize
int[J M hew intl6]s]
Thena is o directuny to cpeibyalength o mulhi
dimensiena annay but inditectHy wtt caH find
Somehme ie con declant an anhay uthout none
such yp of namele annayi ae caled anenympl.
Data
Page.
Tht main uie ofanonymguy aIcy 1s
aet (emptle time ennor
henuthment we Can gie
or anonymous arsay hen
nt newind ( o20,304
eMam ale. u to call Sum
methoda oenLqire Cun annay but aten
Lomple tin4 Str method all wwe ae
hence tY disk
beat cheice
a Tut
V m
3
Sopln "Te Sumi"+
2
AayEleaes Ataigsiaunt
HCale
antay element w2
can be inmpliaiy pmmoted to delaned type
byte b 20
ohag
Shot
sat ype anhayi the alloued
Data
Paga
byte sh.ort.cha 1t
QNhayeleme e can pmylde eitheh
declanad type object or it child class
objeet.
Numbe nE ntw Nlubeno72
Numt
n new int bytehort
n7 Ctring ["duna') dote ot
tound i inualasgs
elements
jk ementetion alas ebleat ane allosed
Runnable. CI T hew Kunnable Cio]
Runnae<t)
Jead
Aray Type Alotwed Elemerd Bypes
pimitive aniays ahy tupe hich can heinplily
pomoted to declounad type
bkjed tspeanhays eitatn declanst dupe ar id
Abstract clastypes dild clas Dhject
Intehate hupe HS ipaplementaton cloos
athay Obiects ane allowed
Artay Vaniable Asignment
not
lement level pm motioni ane no applicable
fu- chon element can be pomotcd to int type
(ches in) whena chon anay
Cahat be pmnmated to nt anay chanclto
chanl] ch aa
teqirecl int.
Data
qutormaica lle
folluig cpentions ponharm'
chan int
X chan ntI
Sin+double
trint
X Maat C] ntl
$ting Solieot
Strin
Buth the cale
case o OLect tyPe anngyc
child clak type anay Can be pomoted to
Darent clas hype ainay
Cae2
wwheneren we
to anothen anay interna ement won't
be copied ut rekncnce rani alale woill be
he-assined
2
Detn
axigning One ahay to
anothen anhay teaddemeot the dirae0Cry
must be matohed r Lathe plate oh l-D
int we should praide1D anhay only
Int I a2 new int(311
hound int J(J
reqired: int [
aund ini
lat
Wheneve we CBiqning one onnay to annthen
QDay both alinon sion and mut be mgtched
but sized ane not required to mateh
Sapln Lazgsci 1)
Data
Pogo
Jova let A R
RE-ÀIOORE
ava Test A R
RE-AT00RE
clas eat
arh
|
Sppl (s):
Java C
Java Test
calnarbage
le tor eligible abjects many hoo otal (2
ereotedl?( phieati man
how Tatal
nt new
Dela
Data,
ypet o Noiables
Division
Saed on tupc oh value repreented by aq
Varable_are diaded into
LS Pnmihive vaiableA - Can be ued to
epresent prinmitive valves
rehr nbtek
Sutudent(he Student )i
S
DiViSDn
Based O postiea declana hon and
behaioh all aniables ane diided into
Iastante vonicbles
LS Stathc vaa bles
Local ValableA
Tastance vanahle
- I tho valu oha varia bleIS varied hom
olject to ohjecf such iupe of voniable oe
alled Lnstance vauable
-for evey Ohect a tepanate copy og
Inc tance voa ble wil be created
Dote
wHERE TD DECLAR Ge
Iri tznte vanebik houwde declane within
the clai directHy, butouttide c any mthed
or blok orcontuctor
Inctance Vasable uoilL be areated at the ime
obiect destnuchion hence te sicpe o instahe
vaniable
Instancevaislble toiH heStoredi the
heap memony
HAcC ESS
Statie anea but we Can
obiect re<e rerteBut
NaialblelirectHy tmm Instane CIrea
clas eat
pvmainlstriagl arg2
be stetic
Lontet
public void m
3
Data
Paga. 42
dehautValue anc) we ane not requîred h
peoa initiaizahion ekplicity
alox eat
double
Jeat neo TeXt(
rtance vaable aulso knoun a ohËect leve
Naables atribu tes
Stahic NariableA
T thevalueo cvon vaniob
iab le s not vaned
from object to objet then it is not
retorcnatnded to declang vaisble as inttane
Mania blewe haMe to dealane suah type o
vanja ble at aa level wing Stahic modiien.
object a sepañate opy will be creoted bt
Date
Pag
in the Cose eh statie vaniable QSngle tepy
will be ereatedat clor level and haeo by
S 'Stahic vanable should be decland withinte
WHERE clau dice ctty bu + outside o any metho d
Statie vaniable ill be coeated at the tine o
ScOPE elas nading and deatroyedl at the time o
Sope oo Static Vanakle
clax Unloadin g hente Scope
Scope o clat le
Java jeNtSteps hellowed ater this Gne
Crecte t Stat ma Thead
Sta vandble
Locate Teatclad ile
Otood Testcis
uecute mainllaethod
Stah Varabe Unlood Test cla
dextnuc hon
Jenraingte moin Thhiad
S den VH
STORE L Static va iable wuill be stred in mne thod anca
L decan acceK Stahc Vaable erthen by
ACESS phject retenceoY by closd name but
etommended to tule cl name.
Within the SQme lass it is not require to wt
Cl name and we con accs
directy
expliiHytnihaizahon perhoa to
INITHALZATON
n1 veid pubtic
(uSaplh
Stote ).arg String roin(
Test clas
ctatic
an bothinstance
and
om
directy sooiables Sttie acreSs Can
Teatn Sopl
tn); Sopln
int10 static
classTest
Data
claest
Stahic double d
Sapln d|O.0
Steticaniables also knoLOn au elas leve
xaiah lea orGeld
clas et
int u: 20, q99
p hain (Sticg[Iag) ti 20
tey 994
Rapladtzn"