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

Java Notes

Uploaded by

ajtrish19062005
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 Notes

Uploaded by

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

VNIT -3.

io Stucms

*. ConsDle based T/o is casier ko sinple pgran nly.


Consele bajed T), i nct suitable
suitable for applicat in
AWT.
eriented pgams which
dees pmevide thu stung , fexible T/o which is
alattd to ile and netve>k .

’uam : * Java pgrame peyom /o thiegh stuans.


+. A sti an en abstactin that ettiet produes
tonsnus
îngormnation.
sinkcd to a
*, A Sthua physicl duvice by tte
java sfe gyotem.
Tpes q sÈxams:
Stuan

BYTE CHARÐ CTER

Stream

roiter.
le ip Trput outputx9 Readarsqoi
d data ip. Stuam Stream.
ofp = data p.
’ Byte Stream: Byte stream ane med uading
data
witing bínavy
level all lo ia sill by te- onenkd.
’ toput Sheam: ¢.t is Jox stuaming bye input .
Metteod C)
Buuiptn
int available C) -’ Reteoens thu nunn bet byfes of awailable
in file fox xuading
ypid close () closses u input turtur uad
atknpt nill ge nevate
nerPaenption an

yoid aNk (înt nu Byles)’ Plaee a matk at the cwvunt


maK
peint thu înpt stream that i l l JUmain
valid tnil e ead.
Byjte
Belan supposed ) Rlns
iset ()

iot Ruad t) suppnted by te


’ Re tevns inkeger upsentaton 4 he next
avatlable byk o îrput - is tuned when thu
end en countered,
fnt xad (te ef bulfe Cg) Attemps to uad up to butfe,
ength byter ?nto bufer and stuine thu aitual
rumber q byfe wee
vhen thu end the file is en counkned,
int uad (&yhs bulen , int joet E, Snt numBytes)’ Atfempts to
uad
up to sta Hng at
utwsning thu numbor
4 bytes suce euglly uad
uturud wun tu end the ftle is
oid enorfeed,
Uset ()Resets tu
nput poinh b he set mak.

lang skip (leng humbyk)’ gnore humbytes byts


sutuning the number y by les ackualiy înut,
iqnoxe .
HLE NP¯T STREAM
Tmport ava . Yo.*;
elas file
publie static void main (Shing args CJ)
char s ;
txy
Tnput stream fo new file Thput
Ihput stuam
("0/ava pgms /input . txt ")
Ss. available ();
s= (ehar 1fs. uad )
Systm. cut. printtn s) ;
fs. close ();

p:
cate h (To Exception e)

dgsem . ot. printtn (" fle not found ");

import java .io . *; in put tat.


D a t a

dass File ip input


hai, Fs. welom.
public statie void nmain Sing ang CI)

chat s
by
=new ile Tnput Shram (" input
drlad g s. available (0
for lint is 1) i<=l yit+)

hoi Ez welome
Systm ,out. pvintin (4)}
?
Cath (Exepton e)
Syclem. out panttn (e))
impot jara.
jaa. io.4
impot java . uil. ^;
elas rteout 1 le te
shing
publie stat e oid maln (Shing ang 3) wello
ingtt q tha shing
Sting st
byt CJ new byh ChoJ (w file is cwated
h naWe
Scan nev
ching")yunwelom pinkd
Syadem.out pantBn ("entev a
b:st. get Byes C; s3stroan
Shing tb. lagth ):
Qup ut Shream in = hw flebutpud Seam ("t fat");

Im. close );

hpot java. io :
inpet joa, til. *;
clas {ite
publie state void man (3ing args CI)
Shing st =how
byte [JCI b hewbte Co][o]
S tanngr S Seapnar (aystm in);
Syskm, out.pìntin ("enkr a shring");
for (int i=1; 1<te t+)

St CiJ=S.next );

fr int i:t}icst. tength itt)


Wappet clau in Java:
mchdisn to conNt
R. Onappx clau in Jara providu tu
primitire datatyad .
phmiti re into dbject and oyject into ouound a data tyo
clau wMaps (encloses)
appetancu.
giva it an objeet
type is igud
* Whuva, tou data
tued.
elases include mthoos to unwap f obijeut and
back e data type
grre mportanu % wYapper elau)
’to Lses with w pper cau
into obje cb, that ts,to gire cbject
coAvert simple data type wed.
hoe comtucto ou
databype ;
wn c pansing pcvati on)
oweat shings nt data typu lkno
d. o xXX() is yed.
type poAe
hou ethods G
java, lang packoge kron ds
eight clau es
wopper clasin awa.
Wiapper edaa
Primiie Data tpe
nhiek

allroter

byte Byte
Short
snovt
p a u

(datatp)
Cat mstInteqeY
int

long ong
Hoat
Jtoat
Jouble
double
chot
Char aer
boolean Boolean

’ Autoboxing + wntoxing: tt tonve prìmine iot obiet ohjet int

pimihire oathmahcaly
paveu by which primiire type is automat caly
encapulaedeaivaln ype appen.
Unbouag: t is a procs by whith vaue o ojeut is

automakieally extacd from type waper.
lass est

publie static oid maùn (Shng argsl 3)


Tteqo iolb 10o
int i iob ;
Sqctm. out. prntln (i4""4 iob))
Characer cob a';
char ch= tobj
t4ch)yhet
Syskm,out pintln (cob

Charaskr Stheam

SHem closMU provide sufident tuni omadity fo

handle ay Tlo spevatBion , ty Caunnot wok döety wth


Unicode charate
Law a is to gupport t ' wnte onta
tte Moin purpoSs
to incude
un phlosophy , it was ne ceuouy
autes
Suppot to chav
Tara's Modal
Reod s n abshat dass fh at dufines
io this dos will row
chavowt r input. Al a te uttcds
Styeauming
on envOY conditt ons
TOFXphon
absaet cdas thct dains streLmina
ttu Method in tis clasI utum a void
chavacer output. emvoy,
value and tow an ToEruphon
impot jaa .io. ; Ruader
olas File Reade Demo

public ctaic yoid main CShing avgt C3)


thows EKugion
int ch
File Roa duY y : new File Recdey " fileveadarinput . tt J'
while (lch yead)! - )
ite Kaadr Demo.|os
Systam 0t
out -pintin (chav )ch ); Roadorems
Jr. close );

Ruadr wia Parn!


import java- io.*
class fle Reay Deno

public stoie void Main ( s ting axg L bne


thnwa ereaphion
Int ch,
Shng Shr;
Filekeady fy =new FileEeady l leNadriput. tat)
while Ctch z fr. read e)) = )

System.outpintln ( sy );
Filwitey 4 naw Flewiy(ile ouput. tt");h
for ( int izoiiz shr. tength(9
+J
{-wntt Csr,char At t )
CLONEABLE

k. Make a Cofey f a clos

Tnfau te couabte
d. uing tnbult
Kuywo rd - implemunts
Test Clone C))

impot java. til, * )


clas ci implemunts elonab le
int a ,b}

3
claAy do

staic void main (Shing Ygs C3)


publie
Io e : hew

C2 C. Test Clo ne l);


&yhmout- pintin ( ce.a t" + c2- b)
UN IT

au Amall Tava applicahn that can be

DnHrat seve, ampovkd Ver Intvnet, ond can be


outo matcally intaud and xun pant 4 web douu trnt
Ary pet in Towa (s a dass thot

avo. applet. Applet class. G) jeua .


betneen an applet Cund Towa appli caton
class fhat extends e
* Ar oppet in fava is a
jay a-applet. Applet class
*, A mainl) utnod is not invoked cn an applet , and an

let class viii not dibine main (J.


duig nud oto be embeddd mthin an HTML
import java.yplet. *
impert yawa. awt.a )
height
<applet ode : "opr"

publie elass app exlnds Applet


publle id intt U
printn ("applet Inlialed");yp
Systum, ou.
publie vld stat ()
stortd")
System.out.pinin (" opplet
3 m
publie void paint (Gnaphics g ) h m e t
g.set colour (olour ud)!
q. draw Sing weleome t2 studens" D5,25 2;
9. draw Reet ( fo, 30,50,50/
q.41 Ret (to, 30, 5D,5)}

pubtic veid stop ()

syetem out pantin applet shopped ");


3
Run the plet
J applet merer aPP
Java c opp. jawa welomne £3 Stu din.
opplet viewer app.jowa
pplet initialed
applet stavted.
opplet sbpped.
’ Pasing pavdmaBer to the applet

< applot tode fit ctass vith Do height :5d6 y


<paam name name
he pavamuler"
Vau :"value para mutey"

Impost wa. awt. *)

2 applet tode hello. class width = 5oo hight


hame subjeet 1 vaue TAVA"S
< paxam
:ADS"
< param name = subet 2, vale
PNam name = Subiet 3 vaue = "DBMS">
<lapplat >

public class hello exctends Applet


Sing SI, S2, s32
pubiic void paint CGnaphies g)
9- draw Shing (wel come to
Satyatabama D year esE );
S qet Paamekr "sbject t"
S get Poxamekex ("sutject 2") ;
S3 qet Pauarmeter ("subj ect 3")
9- set Cotous (otous }green)
3. draxShing (s, so, teo) aplot -Dx
.9: set coloun (eolbun. onange)
eome to sathyabama
9. draw Shang (sa ,so, o)) Dyoay SE
q- set cotouy ( tolouT. d) ApS
DEMS.

You might also like