You are on page 1of 21

SAVA BY DURGA SIR

Language Fundameatals
lo Reserved ords G) Vai-arg methets
Dada Types main oethod
Literals (omnCind- lineargumens
Artays Jaua cdling standard
DENTEER
A namein Java programis called Tolentitier wwhich
Can be usedl foidenthkication purpose. Tt can be
method name Variahle name class name br lobel
ame
closs Tast)
public stathc wod nain)lítring Li ar)
int (M= I0

fatad idenhkier=
Rules tor Dehining Java Tdentihrs
Only allouwed chaacters are (-z Az) (o-3)
1f 0e are using Qiny otherr choracter.well get
tOmpile hme ertor fr- totalahumber
tota# (X)
Tdenhhiers rcant starts uita
Dtvs123tutal lX)
b-ava idenhhier are coae sensihve Dfoune iavs
anguage.is reatedu au ae senihve pngram ming
Cx- clas Test 2inInt number lo
we can Int Numbe 20,
differentiate wrt int NUMBER 3D
Case
There is nu length limit for jaxa idenhers but
itis not recomimended to take too length yiderhfhen
ale cant uereserye d ord a dani hers
int if20(X)
All prede hined avo claH hamesik intertace
identihiers
Qullic ztathie void oain (ringlar)
int sting
Systemioupnatla (tring)

Cyetemud println |Runnable]i


Oudot994 Valid ý

Eventhough it is alid but it is not qond


prathce because it redue
oil and creotel LanciDn
RESERVED WoRDS
Some kiorde are relerved to represtnt
come meanings Qnd functionality such thupc
oh hords ae called reerved worde.

ASoUated oth Reserved iords3) Associated


with vae
tuneicnali hies pritnathioy
CKtykiord (so) Reserved Literals 8)
te
|Used keyuord (9) Unutd keyuord (2) false
null
goto Const
Keyi ord for Dat Typês Keyord 4ar Flo Lontral
byte
short clse
int Suitch lGntinue
lang
tloät
Case
dehanlt
return
double while
boalean do
char for
break

keysind
public
to Modilisrs Keyaerdl tor Excapis
private
potected catch
Hondling
staic hinally
final
abstratt thowS
Ssnchmnizad (Lsert 4v)
nahive

tronsi ent.
valahle Chts Rala ted Keyword
class
I11 interfacR
extends
Object Related Keard implement
instan co of packagt
Impor
Super
Retutn Tupe Keyiwordthused Keynrd
L qoto
Ctonet
2

got uL age n goto created several pmblem


Vinold 1ngucige and hente Sun peopik banned
this keyburd in Tava
const Use
goto const unused
areunused keywords and
we are
hmeerDr
Reseryed iterals
Ly tnue Voueator boolean
false datz typ
hull 3- dehaut value hor
Cabject roheiene
enum(4:5Y) to define a gmup af naméd tonit
ehum Month
JAN£ER,-NoV,DEC

enum BRer

In C reurn tupe is ophon al, dejoua tupe is inte


Note InJava return type is mandqtory. o melhod bon'
return anything oe have to dedlane mehod uoith void
Conclusion
A SS reerved wiordt in Jaya tontons oaly
louier cNe alphahet symba
-n JoNA, We
we haye. only_ heui key wordand heneS
ho delete keyiord becawe detuction o
lekl objects is a reapoaúbility o acbag&
Collec toL.
The tollouaing are neu) keyordsin Java
stict p (lL2v)
asser||:4v)
strictfo butnot stnic +f
Instanteof butnt instantef
Syndhronizd butnot Synchronize
Rxtends but not extend
Lmplemend butnot Lmplemeat
import burt nat ifmport
Const butnot LOnstont

DATA TYPES
In Java cvery anable and evey fxpresion hau

Eoch and eueny alata type i cleary cdefined.


Evesy asignmént should he checked by tompiler for
tupe Yarpabili hy
Becaue o abave
above readon t can oocludeTavo
Jacaa is stmngy Typsd Pngminming
Lansidered asa Dbect Onented Pragrag=
Java is not tansidered
Lan quage Dune bemuse Ceveral ooP feateL.
languag atisfed by Java (likeoperatar
Lascha
0verloading. mulhple inhenitent&tte )
MoreoVRr We ne depending on prioitive
int s10 dat tyges which caL

frimitive Data Lpes(&)


Numeric Data Tupe ) (2) Non Numahc

char
5'ayte
short floating Pint boolean
int Dat Type (e)
lons
ieat double

Except baaleanahar remaining data


tpes are conicered a
becauke e canan fepresent
fepresen hoth porithve and
neaative data type
8YTE
size J byde (3bits)
NAX VALWE = t|2 MSB
NIN VALUE =- 128
-128 to |2 . 2 2 2 2 2? 2' 2
Rangi 64492+16t&y2
1 ’-e
|24
The HSR acts a sign bits
n positie hum ber
mecns

cansaotive nuaber
1mecns
fhitivak ho vaill be represented dlidlyin membny
Labert a negctiveno uill
ail) be represtnded in
Twns omplemen t otm
bute h=)28X
oapileEmo: pastikle
pastikle lnss o precision fond
int required i byte
bte b2 l0-s
Conpite éron pacsikle Joss at precisinn koundi
double eauired byte

Coagile erron : intompahible dupeA haund: baslean


feguiredihyde
duran"
Campile en intompahble hupea tound ijavaulan Shi
reaired byte
Byte is e beit choiceif we ant to
handle data
n terms
terms o streams eithen m
she tiles or fom he nehuork
neta fil supportd
o and nehabrk supported on'is byte].
SHORT
2is rarely uàed dat tupe in Javamnsey

-3236R to 3169

Short s= 329bR X
faund tequitd therd

CEplp yaund idouble required i shart

CE incompaitle hpe tound : boalean


Ataired chory
Short dodta hype ic bestes suitable hor ]k:bit
proceskor ike RO8S blit thele pnleskon ane
Lampletely Duddated and hente' carrerpondent sar
dat tune is alio ouddated cladr tupe

+s most tomroonly ed cat tupe in ava.


Size:4byte l22 hit)
-93) to g3-1
2]44483448 to 2144 483644 :

int 2]47y83644

CE- integ no too loge


Int x 2144423642
plp taundi lang tauired i ind
ompatible tupes hound: bealean
heamim ol: int
IONG
Sametimea Int maynot enough to hald big valuetttn
we should
anfarlang hpe
eu-. the ameunt
amgunt nnt Aistante traveled hy li in
A0o0 caus to bald this value int ma hot eneugh
tor lang data tupe
x-2- tae no
no.nt characker peleatin a big hle nay
exteed int ango hence the return tpe o lenst
aethod is lona hut hot int
long =lenghl)
Range:-263 t

NoTE- AlL the a bnve dada tupel (hyte shortint Jo)


mkant hor Teprea inhias inteseral values if e
want to
e shoLJd
represent oag paint valuzt Hea
uld ao for ahing 'paint dada hupes
Eloating point data thypes
flogt Deuble

decimal platesoaccunar
IEloat ollouc single llea) - Dauble tollaai
predtion doukleraarelprecicion
Size 4 bytes32 bits)
Range - -3.4eS8 to
Range 3.4e38 Range e302

BonlEAN
Size NA -No+ Apolita ble lVichucl HacbineDepeodec)
Range - NA ;But aloued Valuek are tuel halc ]
boolean b= tnie V
CE - Inoopatible typed tound int requirtdchaelao
boolean b=Ine
(E- Cannn+ fiad Symba l
Symbal : Vaniable Tnue
locathon: cos TeAt

bpoleanb"Te"a
tE- intampahible types und ijaxazlang
S0:P |"Hello" S.0:P"Helo "l:.
else 3
S s.0-p " H;:

incompahblt type koundi int


Tequredi bonlee
CHAK
siz032 byie AsC1I code baed
ahd th no dithentt alloed AscL
chonactens ane's26 To pepreaet these
256
2Sb chanactenÀ 8 bit ane enoughaoe
A size o chanin old language 's byte het
Java is UNLCODE based ahd Ho oh dikkenAt
UNiCoDE Chanaters ane >256 4 46S36
repesend thee many chonactere8 bit roay not

hentz tho size t cha in Tava is 2 by ded.


0to
SUHHARY,
DaaypeSize Ranse INrop pertlays Dela
hyte 1byte-2'2'1 Byte
short Short
int 4byte -231 ’2-1 Inteqen
lo ng Rbyte -2b3_1 Long
4hyte -3.4e38 -’ a46g8Float
LaDuble Rbyte-7e308 >:?e308 Double
boolean NA NALAllowed- truelhalhl Beolean false
char |2 byte 0>6SS3 lCharacten
[repreent
Space
Chanacter
NOTE nul) is a dehaut aue for ohËe ct
TeBenante Canpply to primitive dafe
pl it we tn to uie, combile me frDs
fy - char ch null
CE In nmoatible tue
oundi< nul hype
Teauted : chan
11ERAL
A tonatant value which can be
vaiae is calleda litera

data type hame o Onstant


keyword vaucble vatu
int w 010 Np-preliith O]
1
Heua decmal for iterali lbaso- Jh) [oto 2,aoi
or On)
Iniegeral literals
for Jintesfrnl dota pes l hyteshact int longlt
Can cpea literalvalut in the olleuain, boB
abeve.

for exta dhgits la t o f ecan ute bath loseg


Loake uppa caàe chanacer thisis one ah
Veny heu) aneas wohene Java is Dot cat senitiye
TThe iterals value can be descri bed in gnly these
pealkle uays integeral literals

int Dx KeerX
clax Test
public slatic vaid cmain
int w=10
int

Syatem.cud.phidtn [xtyt'z)
ecinal<br
(1oJn

MEOXID

integeral
hype but e can shecity cxplicitily as ang

precisioo found o
bngElo; reqired
There is no way diect to speimy byte ond shert
tifural explicihl, but indirecy weWe can tpecik
whsneNen aAsicghing thtegel liera
byte aiable and ' a l u z within th
Cnge o ble hen tonpiler treat it auto matady
ay byte likral imalay hart likral aleo.
TVH will aluoays provide values in deeimal o
shor t s: 32361V
Shorts Z24b X
fountiat
Teguirt d shord
e loathing paint terails.
eveny
Douklé
Dowble type and hince Lbee
tantacisn diectly
to the Hast vaniahle but we can specif lcatin
f123.T6CÆ - PLP
faunddeuble
Hoat f 23-uCfv
double

We can spaihy eplicthily Hoatiy peinf literal


daubie Ape by su lith darD.
ateounse His conwenhon ik nat reauirecl

Fouad idaukle

We Can spenhy kloacthing point liternl onl, in


derimal a and e con't specih in octal
and headecimaltorms
double d=in3.4SKV
deuble d = o123 u T V Ttis
S eecmt
terst but hot
doube dOXl2345% octal iteral
CE- malhomed loating print iteral.
We can akigh integenal litead directy to
icothing peint vanialle ound thatinteaenal
Siteral can be speciied eithin in dedimal
or octal br hexadecimal fom

douked=oxEote
Wdoukle d= 016
Poind itdhal O
Vdowhle do12
doubte 10

le can't aaiga ioating paint liteala to


intearal thpea
fecsired: jnt

We Can specity htanting point literal een in


double d :203 ) 1:2¬3
Sophld):
12 00. 0 2X 10

200.0
found idlouke teguedfasr
teat
BonL EAN LIIERAL
The caly alloued value tor boalean date
Anue or kalse
Vbocleanb thue
X boalean b 0 CE ncorm catible tupeA
kound : int
riqired bonleaa
X bocle an b Tnue:CE = cannat ind symbe
Symbel : vaniabie Tae
location:clas.eat
X boole cun b=tnue intarapatikle hypes
oundiava.laa Shiy
raitd Loolean!
#2 Reter boalean datahpeor mar
CHAR LTERAL
le can pehy char literal aA Singde chanatten
withi sîngle quoteA (')
Vahan c a':
chan ch a - CE- Chhot hnd Symb
Symbal : vaniale a

X chon ch "a Ce incompahble type,


Rquired chon 0
X char ch ' a b - CEE-Vnclose d chon tenal
CE2- Unclosed chan litenal
not a statemeat

We con speaiky chan literal a


which repreleat unicode alue otHe chonale
Land that integeaal Con be speiied eltbn in
decimalox cctal or hexade cimal homs but
allauwed_ang is O- 65351
char ch 94; chon ch =0xFace)
Soph(thJ:
chan ch 0129 v
ehan kh bit3v chan che6rs36i
CE- PLP tondiint
Teqire di cho

2- e Can represent chan iteral as in Unicode


reprelentation nhich is nodhing but 'luxxxr
Luhee XXX T u-disit here
hexa de
de cim no

Coph (eh

Exeny eLcape is o valid chan iteral

harotten
Escape chenactensin Jave
fccape chanacten Descriphie
he ne
hoizontal tab
Canzinge. rehuh
back space
form feed
sin_le qote
doubte qucte
bock slash

sopn " This is Synbal"]X


Sopn "This ic "symbol"x
Sopn " This is yaho)":
topn " Tais is ybal"x
Se.ph This is 1 cyabn|": V
Which O the following ahe valio ?
X
chan ch0XBeerX
chas ch \uface X
chanoh
chan ch m X
chon h liface'X

4 String literad
Ay ceaueatt af chanactenk uotkin doublesate
Sting
1.3 venion ehhahtlment wrt iteras
Rinany Literals
nr inteanal data thåge
huge unt L6veaions wt Can
cpeih iferal valw in the
decimal
- hexadecimal toms
Dat

but
denal value even in binany oma also
Alleueed digits cne
ont (o1)
Herl valae should be preh oith fDE)or
(OB).

usageaunden
liHerals
tore fymbol in gumen
undencore Symbol Llu htimenic tenah
clbubled
doubled 2 3 4 h 189
deuble d 1234Ih4
The main advont e n tais copmath
hea abilihy oh fhe code willL be impmved

woilL he nemoved atomaically hen ce citen


oraila io the above lines will beeDnCkecome
deuble d 23Hsb 489

We can uee more than undeh Soreymbol-ao


Dete,

We can tuse

tuing anahnt elte we


Lampileioe efor
aloubled=23-4r6J

double de2-Ha-R9

byte shorti
2 byte

Int lona Hoat double


Hbte Rbyte
char
Lniesanal Eloahing-point
Peint
Value e we can
vaiaale beccse both ane
dtusat hthnany tepreitatahion nkernal.

You might also like