Java
Java
Character Set
C
Encoding [Link] Unicode-16 ASC-II 1/8
Bita 1616 Brits 7 bibs/8bits
Minimum Valut in
unicode> \u0000
Maximum valu in unicodle >
\uffff/\uFFFF
Tokens
(48+2
goto const aar non uorking reervd
kepo0rd
entibier Alphabt, Nymber, Underscore T Curmeysmbsls
($.4,7 ete)
Ex oid hegillo t
static void heoacllo t)
Number Tet
Real
int a- 2,365
Sytm- out-printInlal; p7 Error
Split ndto deckraion and
asignreut
4-02-22
Opeyadors in Java
-
Aivthmatic oprator-
Almost Same as Cand C+t
Java flood emider () aH &
E float Q-11,b
Systm 0utpriv-ln/ a 6];
Op 1-0
Ex
Ex inta=10-5X narrouing
X
( daturype float str double
nt a 5 1f x vabu d dabtye ict ¥ inkialie
TYT Error AAIE1)
Float a 5 lidening
short &byte-
ExShort a-2;
short b-3
short C0
Catb,
systm- 0ut pintln[c); , c -(sbort| atb;
O/p-> Error Java short atr byeke s TET opea-ion
Ex bute a-5
bufe ba3;
byke C 0
C-at+b
Sstmout prindlh (c)j
O/p- error
Datarpe Size
baol (bavkan) undefined (1bit)
byte 1 B
3 char ?8
4 Shord 8
48
float 46
7 Jong 88
8 double 8B
,,
7 , > , == , !=
C Compilr zAT Output hr relational Operator 8PTK
OAT1 Jorm OAT Java H Tue r false
, as ur Java ù 37IT T
databype bool (bmlean)
-
Logical Operator
0/1 bIHT W&
Binavy Umary
&4 Logiral AND
3Logcl Ne
, loqical 0R
- u fJava EURT Tue false ù6uW KAT
AND J sfalke op falk
OR HTrut T 0/p True
Unary Binar
1(omplomeut AND
OR
3 A -OR
4
L4 Shift
5 7 Right Shift
nput Outpat Unsigned
Right shift
Binary New value
Ex
System-out-privdn (5<<a); 0p 20
System-out- pintn/ 50>2a); Op12
Systmout println( 50-0>720); op Enror float X
System out printlh{ 1 >7 3);
yp-1 (ntsl aR
3,4,5cte qns abw
Ex Sustmout pmrint ln507772) Op 12
unsigned
Hourtie wmber kr=ft st arr Right shift mt mse
always ro entr INT, TtATT p aHT Same AIT
H50>7 2 8TA 50 2, gngwer R I
R- Negative Nun ber O/p Same Tt Ar}UTT
System out priutIn (-I >>2); p
Sustem out privtin (1>Y>) ; o/p 1073 7HI0R3
Signed (3 bit *
Assignmact Operator
-Binary opPrafor GT R-valu -value store ar
singe valu) (variable)
EX a-5
5,6,7 O/p 5
6-0
-43
-(5,6, 7), Op 1
5 6 a=(541,6), (141); olp->8
a/-5+
a /l5+3);
1o/(S+2);
1
Miscellaneouk Operator
Size of () Java H x
A ?B:C
ATrue alse
Candri--
Ex-
Systm-our printin| 5<lo ? +3 : *3);
0lp 5
Vaviable in Jav
Same a CC
Use F Flexibility Reusabilit
Variable is a 8pace in menory (RAM) which
stores 8ome
value har can be changed
during program exe cution
Control Stafm tnt in Java
Continue
for-each L 7ctun
Ex il (
Sustem. out printin ("Hello"
elst
[Link] printn (" Hi ");
O/p Error FIT Java 4-che, o11 w-t
tue /false uork AT&
Swirtth (a)
Cae 1 5-0p ("A"), benk;
C0e(1+1): S.0.p. ("8");
Cage('A): S0p("c");
default S-0-p-("X"); brak; OlpB
C
Ex for( int i-I; i-5;it|
Cowtinue i
Olp->1
3
Sqstm out- printnl7); 4
Ex int a-3;
while (a<-5)
i f (a==4) Ofp-> nnif lop
X 3
Coninui
else
Systm out printin (a);
Ex int a=3;
, whilt (a «=b)
O/p4
break;
else
S-0-p-(++0);*
Ex int a-3
do
,x lt (==4
brpak;
else
System-out pricdtin ++a); ;
while (a<=o);True
O/p 4
Array in Java
syntax
int ati= new intt [ size];
- - - -
Smitiakrzcahon
int at] =
new int Li
f,3,33,44, 55};
Snitialize
T time size meution 48t
RG
Tava H) array, inser t snt values
{u23,35, 14 s
4PHeIT GHITHT AR Eror r hanele
Compiler
int a[]= new int
Taj {U,3,35; X Erov
Ex int a L] -
new iut [ ,33, 35, 44, 55 ;
C/
Ctallow èar F3HA pointrr
ar 1-2 p/ace TT A5 memory
Occupy a ?
for-each ( terator)
Syntax
for (Tterator : Name of Anay)
Ex
Ex t atj =
new int [i {1,23,33, 44, 55 3;
for (ind i:a)
System out printBn[i);
33
33
44
55
C Java
C Compiler, location -
String $1="UTKARSH";
String 52= " UARSH";
S.0-p- [Link]) +" "+S-hash@cet ); ap> 604532179 80517147
new ktpoord
Sring
String s1 nw String ("UTKARSH'|;
Shring
String $2 Mew String( "UTKARSH");
il (s1-53
Systmout-priuth("Yes");
ebe
Systm out printIn ("No ";
Op7 No
if(S1= S)
S-0p-( Yes");
Op- No Addrewes tonpared
else
S.0p(" No");
(s1 equals(52)
S-0-p("Yes;
else olpYes Value Compared
S0-p-"No ");
Strmg
Strimg $2 e u String("UTKARSH";
Systrm-ouk-printnl st. compare To (s2));
p-0
Ex- String $3 =new String("ATKARSH");
String S4 neuw String" 6TKARSH";
Systm- out-print/n (52- CompartTo (54));
olp |
Constructor
EX
public class CAB1
- - Congtructor
CAG1 efult
Constructor 7
aHT objert ATAEt
Olp 3 Hello
Normal Mehod
void CAB1I
Op7 Hello
Hi
inta
CAB 1 (int yl
void Hello )
t a-30;
Systm- out println (this-a); i [Link]-(a);
Olp 30
public Stafic void main (Strimg apti
CAB1 Anaw CAB1 (1o) ;
[Link]();
O/p->10
onhreritance in daya.
Ex package pack ; - - - -
clas&es mettiod
import staic impor
import Apple *j inpor:staBic Computtr Haduar.
Aple package RT closscs import keybuard;
Computer-package
import Apple Banana Hardware-clas8
Apple packiage st3T7 Banana dlas keyboard- stutic metiod
Types of inheri ton ce in Java
Single dnheritance
C
3
HET C clas a st
anbiuily&rofs
a, class C * mheritzaT?
C
ar class A 7Eclass 8 3
Jara tror t t
-
Super Keyword
Super Keyaoord WT parent clas member Ar child claas r
Apple U) Constructor
Q-100;
nt a
Aple ()
-100
veid pdisplay l
void displayl
Sgstm-0ut pridn (a): }
public class Pack extnds Apple
t a
Pack ()
=50
void display
spsem-ou printn(al:3
public static vaid main (String Ii
args)
Pack P-nu Pack11; P-display 0
L-
P polisplay; O/p9 50
0/p- l0o
50 [Link]
Pdisplay (0;
3
Ex7 class Apple
Op 80
50
inol
Java Const sit7 goto -H , 3HTT Final
fina variable -
final int- 4s
a-55
Systm-aud-printIn/a);
Qublic static void
main(String ti args
Pack P-new fackl);
3
3 Op- Error Remove Finad modifier from
yariabk t
final method OVeTeidmg - aft
Ex
class Apple
void Hello (1 final void Hello/
Syotom 0u-println/'Superclas;
void Hllo 1
yoid Hello 1
void Helloty
fS:op( "Super Clos");Í
Super Child
M
MiR
M2
super R1 Child R2
Ex- ublic static void main (Sring ti args)
fack Pnew Pack); v Apple P- nto lackll;
[Link] () P-Hellol),
O/p> Child clay p Child class
o 1 - 0 3 - 2 3
Abstract class
Pltclass aHD abstaet methiod HT
Abstract method-
HT melhod ftaet body -Te8 T
=0
pare virtuad fanction &1 IHT?
Abstract cla88
Pardial Abstraction l00 Abstraction
Some function abstract
All ave abstract fr tong
5ome noYma
Java 8 dntrface
static method H dehult method
add Barapr
Multipe inheritmce X Mutiplk imheritance \
SHIRTimplrmentotear taran1
Data str mefhod teatsft -by delaul i data, Anal à
stethod, pblic gar
Start aith abstract kypuwd
tort oith nterkace keyuord.
Normal clus8 Abstract class drerface
class Aple abstract clov Apple ntertace Apple
Ex indrrface Apple
int a-5
abstract void Helln;
3
public class Pack implemnts Apple
pablic voidHello t) ---
void Hello ( Error
djaut
-- Int q-93; 6mr mthod public
Sysem out printhn[ a) ;} iutorfaceL_E
daka
chaneX by delauls Ainal m
ublic gtatic void main( String ]
args
ack P-neb Pack (;
P. Hello t);
3 p-5
Esception Handling
try,throw. catch, trous, Finally- 5
Kaywords
Sinally Method &HT exception sm A7-T 3
T condrtions PT7
Ex
void Helo (1
it a-10 jintb- s
nt b-o; a
trySystm out-privetin ( .
Exception FTt
catch HATI
catth Exception e] t S.0-p-(e);} Arihmehe tseption
finallg Systm-aut privdIn l" Amally Excepon "); 3
public staric void main Lfnaly
(String ]
args
Pack D-nuw Pack1; e- java-Aritmmahic
kxcepti on:/by d
P-Hello 1
ap 5 ---try TI
Finaly Exception --- finally ATI
throws
pablic static Yoid main(string lian public void kuboard ) t#rowe Avithmatic
Excgption
Harduee H-nu Harduare; Eint q=10
nt b-0
-
AET ackape computer; T throws Rautar package pack; aT neti
W ETo clauy Hardoart, import stm&seir Arthmatie Exeytin
Error 3H2tI
Types of Eception
aTRT(Compilation3
Comprier, program T
-
class maun
class main Class Printsbream
PSvm ) static Prindstream out ;! vojd
prindIn t
System-out-privedlnl1; 1
Systm class
Out, Systm cla 7 static odject Gtr prikts
clos
team
printn, HE printstreqm class T method 1