[go: up one dir, main page]

0% found this document useful (0 votes)
325 views11 pages

Dashrath Nandan Java (Unit1) Notes - Alasso

1. Java is an object-oriented programming language developed by Sun Microsystems in 1995. It is a robust, secure, platform-independent language. 2. Key features of Java include automatic memory management, no pointers, support for object-oriented concepts like classes, inheritance and polymorphism. It is also platform independent. 3. Core Java concepts include objects, classes, variables, data types, packages, access modifiers, inheritance and polymorphism. Classes can contain fields, methods and constructors. Inheritance allows subclasses to inherit features from parent classes.

Uploaded by

Deb
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
325 views11 pages

Dashrath Nandan Java (Unit1) Notes - Alasso

1. Java is an object-oriented programming language developed by Sun Microsystems in 1995. It is a robust, secure, platform-independent language. 2. Key features of Java include automatic memory management, no pointers, support for object-oriented concepts like classes, inheritance and polymorphism. It is also platform independent. 3. Core Java concepts include objects, classes, variables, data types, packages, access modifiers, inheritance and polymorphism. Classes can contain fields, methods and constructors. Inheritance allows subclasses to inherit features from parent classes.

Uploaded by

Deb
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
You are on page 1/ 11

alsssmate

UNIT:1 Þashath Date


Page
Nandan

t cauai caua ds a highleusl ebject - uientid pegMamg


Language t us deuelabed by Sun Micnoytem
in 1995James GGsling is Knbunas faheu faua
Plattom: Any handwone o softuare enwnenmment in whik
a pupiam ns Jaua has JRE and API

DSinplei Jaua dyntan it dipe , clean and eay.


i) Robust i ses toong mneamoy managment
in) Secuned : No No expit
escplicit polntes
i9) Object-beiented : Ghject, class,rkentance, olymasphism s
Abstaction s Encaptaten
v))Platosm dndebendent ) fortabe Q) gh berfomance

Jaua
i. Ct+ iu platom dependent.Jaua i blatoem Jndkhemdend
Roesnt upbont Multple Jnheae
3- Superd multple nheniale Jaua
4 pert Potntos has sestecicted pelnte
5.dt doent hane beitinst has tut in thtead bubfet:
dupport for theads"
6 spportotnucoe aaua coesntt sebert touckres
ano unon and nion

Obiecl : An objet s an instance staclas.


tclas:A clas is dtined as buupuint sf object
Vaigbll: l is a centainen thieh helds the value
nstance and Statte vaiable
Loal Vaiabla ,
clssate
Dae
Page.

Xcaua Identhensi Names laed fon clasel, Vaniables amd


mehodu aHe calld identyes
ALL idnkitis shauld begin uth leter, Cusaeney chaitaDh
bA keguord canmst be ud as ldentifins
Jderttis ae case kensitiue
E: age Salasy, Value

*aua KeyuosId : n aua, a keyua9d uahued


uHd hat hae aa buedefinid meaning.
pedtinud eaniy.
&q: abstad, if, else, do, int, Shott, long fo ot for, k

Tokens : Ateken is he asmallest elment s a


bgram hat is a speayied meaning to
Cempiler t include Keyuands Vanioble, Constant, ete
oug Data Type : Data tybe specify he cerent Sigs
and ualues thattan te stoed inVaabe:

PNon-Primitive dota tyye


*Brimitive D: T Non- Pmitie DT
Dhese aHe bredefined +CHeated by þtugamex
i)tcannot sed to can te lsedtocall mettod
Call methed to botfom derme cporatien
i> he die depends en data hy haue all the amme biye

leng, shet, deusle


classmate
Date
Page

x hekages:t package iu apack (grep) of clawes, intonfaas


and other packges:
(0 Builk in backage: he atseody
defineo patagesAte
java io, jasla lang.x
ike

CD Usen-dafinec package : he fackag CHeatd b se


. Sub pakges : Apackage inoide anbthex ackage is nsusn
a subakage.
oAduantages Bf aing backoges: Reuuabilly s Beter htimigatin
Name lenlict
& Acces ModitioHs: enacces mediins esticts the
acess &ta class, CenstHUcte, daa member and
method in anehe class
yPES:
1 Derault AM: he sspe is linitd to he prckage orly
2)Piblie Am: ese can te accesed rom anyhine.
3) Petected Am: hese can be accessed uithin the package
amd
Qnd autsicle pkg: thisugh child clas
4) Paivnte AM: hee bann be acesed uitin he claw
Erammble: Private AM Protected Am
Clas Dng A Clas Arumal
Private sting name ; Piolecked wed aspegRo"Animals
Pubie cles min5
PSVM (Shing (]args)2 Clas Dog exlends Aime
Dn d new Dn)
dname = "Dashat';2
Psu (Sbnng IJ avs)5
Dog d
hi il genenate Enor
hu
blc ue ae Pivate Vauable
G Data clas from main Dutput: Animal
alassMate
Date
Page

*Aclass in jua Containa i -


fldsMetbods ConstrucorsBlbcks "Nested las 2Trilenlace.

* Slatic clas: A statie clas cannot be instantiatdie


we canmtceate ohject1 fa stato clas.
uecam cam enly eces it membeH singcas nameiku
Stadic Nested clas
Nested clase Class Test Ater
Exam_le: Static int dat= 30;
clauintOutexClass?
= 10, Statie las Lnr5
ed ms)s
S-outt" data is"+ data);?
33Jnt y si
Public atatic usid main StonJarz
pSVM (Shing a9s)
Outerclàss o =new OuterclascO; new Testo uter j

loutbut i
data ls 30

nhuni lance in Jaua i


Snhesilanu in Jaua is a mechanism n wtiib ne
sbjist acguies al he buepontis and behauiewn sf
payent Objeck
class A A |C-B |A
Supendas + coss A)

Sub-ClaS + lclags B
caxB fcand
fclags C tienaxchical Hybrid
Single () Multiluot Gin)
slssnste
Date
Page.

Jhe extends Keyuoid indlicates hat you aHe making a


Lclass hat drius from an bristing at
&xamblea: Clas Animal$
Common Code Common ode
clas Animal
Coole
Camn
|cas Cat extnds
SOut ('eating")2 Clas Baby Do ektnds Doj? Aimal
cLas Dog extends Animal Veld weept
Veid bask0$ Sod ("eping'34 Sbut ('meuseing)
Clas Main
S6tlban king' Pslstingt3ang) Clars manS
Uass maën i psyM (S) PSVMEEHS
Baby Deg bd= neuo Babyby )& Cat C=new cot
Dg d=no Dog 03 bd' weeeb) C" meoo)
do bat KO bde baIkOy
ba' eat);
Dutþut i bayking
Otput: weeping
bar king |3outut:eating
Meueing
eaing eating
ingle rhinitance Multtleuel tnhenitance Hienachical

. Multile bahvitanee net suseted in jaua.


ex: The Cclas inheaits Aand Bclass.Aand B haue the
same meeod and if e cal il from child class Ghject,
there il te ambuguity to call metlhed f Aor Bclass

*Abstaction:
details ank sheuing 9ny functienalty to the lser
Jhene a tue uyy toachieue abstacten:
OAbstact clan otQ100%)
Ontentace ( Jooy)
alsssnate
Date
Page.

Abstact nterface
Dhe ahstact keybend ia uede the duegae keyuakdis scd
) Doesnt supbort Snhitanesubbet tnhevttane
to) Can hue abstat as weu ate can cly haue abstract mekhDd
nen bstct netod.
Can haue stotic method, lannst hae dete metod and
amd cnstuctos. Constuctos
ex: abshact clas Anima &x: Inteface AS Vofd a0?
abstact Ved eatO 2
Clos Dog extend Animauf abshact cas B.inblemets A
Sop c" Gatng) ;2clay maim
psvM (Shing [7 args)$ PSVM Shiny Jag:)S
Abr Animal . obf- new Dog0;
O6j. et (); ba3 2
33
*lymrbhim
Polymenphis mians Mamy fatm anditcwns wten
ul haue many clas hat üne Heleatd by inhnitane
Ubcastin : he ufernce uaniasle sp fanent(lass
do the sbict child slaM, it is knsun aL
akcasting
Method Ovexloadag Methad Ovesxiding
JCompile-tine selyriinphismKun time polymapnilon
)3A is pntomed cetin clast sccus n tuo class.
in aametens ae diterint nthis Name as uele a
anamelr must be same:
Cas hauing mutjle mthade df dubclas has he dame
hawng same name but method As aeelarod
Parent les.
nte
diterent in Parameter:
alkssMAte
Date
Page

Method 0veHloading Mehod OveHAiding


Pabiie cdas Sanble & Publie clas Vechiclef
Pwstie siakc Void add (inka,in b)S Void vUn 0{ sop( "vechicle ");?
Sop(Q tb)3 das Bi extonds Vechicle
Publie usd add (nt a, înt b, in )s veo Yun 0 Sop
Sa P(a+bt )33 ("Bike")32
PSVM(Shing C1args)s
PSVm (Shing[Jags) BiKe bE neo Bi keOj
Sample obf =no vecttcte ne tecuttU;
Ob qdo(,2)3
bon()
Output: 3 Output Vechice
Bike

Encapsuation in aua iw apueces urapting


Lcede anddata tegher ito a dng nit
Acuantoges:
Make the Chs Yead-Gnly o hwite-Gnly
peuide Contrele Qen he data
-hlay to achieue data hiding
Pnlatsulatid casis easyto test
Accesers (beter)iMehd to tebue the hiddem dat.
Mudators (Setter ):Method to change hidden data
Doshxah
Public cles student $
þrivate Shing nami
kuublie Shóra getame)f
Yefurn namej
Seter methed
S geitex mehod
elkssmate

Dashath Nandam Data


Page

*Excaption Hamdling:
Jhe tnepten handling in jaua ia bne af he puwyl
mechaism to hande hl untime eines do hat
Hhe momal leur s4 the abblicatien can be maintaint
hua exception handing iu mamapod ua fe Keyusadai

*Exception: An eccebtion is an abnomal condition'


he banent claw if te laception lan i jpua lang: Excion
Nbes ot, Excaption
UA DAined Exception SuiLt- inExcept Gm
Checked Excebions Unchecked Excestions
c s Not FOurd Ercepien Aohmekc Ercep.
IO Excaptie
bFile Net fend ExcapHton Anay Tnolex ut
|sBund Erc
0Checked Exception: Checked exception ane called
Lombile-me encestien because hese lxceptiend ae
checked at cempile tinme by cemjiler
D acheckecl Eacastiin: heclas hatinhenia he
Auntime seLaptien

EXceptiem astacK OveMtes erNer


alAssAte
Date
Page.

ExcepBen
D Clased aa an Uncheked casid aw checked and
tybe Wnchecked
D beleng to jua dangsemprt bilorng to uAlang: bxcagtitn
tdt is BecoueHase
iv)tCan't be DccwY at tcam occy at un lne
ompile tne
TO Eor, Out of Memory EoY, ete. t Nu Pointen Exception, ete

Ty block : he tuy tlock tontains set of statemint


here an encestin can scoun " dt mut

Catch blok: A calh block u whene excepton ae


handled hen an exceptien sccw en

Frallys he finaly tlsck isu lad to sacaute the


necesayLode of the puegram
ThHew: hew Keyuwd is ed to theBa
trteptien erplitly
TAeeus: dt i sed jon hanollingChecked excestien
Thew theu
D) Used to thxow excepton +Used to decdane an exeptien.
eeplity posibe dusing exeution
) declaned nsidea tsti ued utth muthod
method body
|sÙnaBove (mehod dechyatien]
) cmmet tBU multiple t e can
euption declae multible
eaeptien uing thuews
alAssmAte
Date,
Page

* Final: inal u a keyuod


Finalyi frnally is ableck. 4till excute whethuExcap: 0cuY a hBX
ratos clan p
fnalize: firaliye i a mehod -dt ia wsed to puforcalctd:
ust befoe object gantage
public clas bxcestlenExaaiple
Public clas Enor bram$
PsVM(Shing CJarg) int =100;
Yecunsine Method (0 int y=O
bl|esleidmathad( int i)s
thile (i!=o)f
jaua-lang: Aithmelic excaptron;
yewnsive method()>3 Output:

E publie clas brestion Handling


Psym(Shingll ang:) aay fousued by cath block ,y

int atJ= newinf lsJ;


a[sJ =30/0;2
cetch (sthmetic Baception e){
Soeutl"Asthmee Ercaplion Oceuwz"?e
Cateh (Exception e)i Geewns")s?
S-sut("Parent ec7ien

etl"inally block is aluua ereeuted"3


So ");bensE
Srout (" vest of code
3
3
classmte
Date
Page

E Pblie clas t Thyow$ imþort jaua bExcapiens


Blatic Weid Yalidae| int age)
thaow neoAsthmetie Ecplen'NValia"
ot thrao neaoTo Excapkion("eya)?
else
Uaid n() thous Io Excahien $
S eut ("Welaome to Vote');?
PSVM Shöng L] arngs)
Validate (e3); t
Seew ("yest af code"); cateh (Excptone)t
Ssut(" ercplien handled"s?
PSvm(Shing Grgs t1)5
Test throws hË heoTest ThYows l);
User- defened
Output i Exceptien handted
Clas My Excepien eslnd1 scqplen
puslie myexeepien (Stfng S)5
Supen (9)3f)
Rublie clasy main
PsVM (Shin C)ag)
ow neLo yExcapion ( onenendon"; ?
cateA (My ExcapYon e)s
Sop(" cagn)s
Seple get mesage o)i
utbut : Caugkt
dne nandam

You might also like