Location via proxy:   [ UP ]  
[Report a bug]   [Manage cookies]                
0% found this document useful (0 votes)
108 views

Core Java

Uploaded by

[L]Jinesh pande
Copyright
© © All Rights Reserved
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
108 views

Core Java

Uploaded by

[L]Jinesh pande
Copyright
© © All Rights Reserved
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
You are on page 1/ 59

List of java class Topics

1:-History of java.

2:-Difference between java and C++.

3:-Dynamic and static binding.

4:-Escape sequence.

5:-Variable.

6:-Data type and it’s range and size full form of unicode.

7:-Operators in java.

8:-Type casting.

9:-Keyword in java.

10:-Wrapper class in java.

11:-Control statement. If, if else , nested if , else if , else if ladle , switch case.

12:-Loops.

13:-Labbled break and Labbled continue statement.

14:-Array 1d , 2d , 3d and so on…….(multiple array).

15:-Commend line argument.

16:-Instance and local variable.

17:-this and super keyword.

18:-String class methods.

19:-Constructor.

20:-Inheritance.

21:-Exception handling.

22:-Static keyword.

23:-Polymorphism.

24:-Varargs methods in java.

25:-final keyword.

26 :-blank final variable.

28:-MVC architecture.

29:-Package.

30:-Abstract class and method.


31:-Interface.

32:-IO in java.

33:-GUI (AWT).

34:-Event handling (EDM).

35:-Swing.

36:-Applet.

*************************************End*********************************

1:- history of java:-


● December 1990 me America ki ek company sun micro system ke head ne ek
project ko start kiya jiska name green project tha jiska aim electronic device
{ networking } tha.
● Eske liye unhone January 1991 ko world se developers ko hire kiya esme 3
developers main the jams ,mike, and patric .
● Mike ka work business development tha. Patric ka work graphics development
tha or jams ka work sutable language ko selcet karne ka tha.
● Jams ne C++ language ko select kiya tha but unka project networking pr based
tha. But C++ platform dependent thi Esliye ese reject ker diya gaya.
● Network means jaha more than one different different operating system vale
computer ko apas me connect karna hota hai.
● 1995 ko unhone ek apne alag language bana ker ready ki but jab vo es
language ko register karvane gaye OAK name se to es name se pahle se hi
America me koi dusra product register tha .
● OAK kuch country ka national tree hai . like Germany , Greece

● Tab unhone es language ka name java selcet ki kyo ki java ek island hai jaha se
world ki best coffee produce ki jate hai.
● Finally 23 January 1996 ko java ka jdk version 1.0 launch hoaa.

-----------------------------------------------------------------------------------------------------------------

2:- difference between C++ and Java


C++ Java

● Platform dependent. platform independent.

● Semi object oriented programming. Pure OOPs as compered to C++.


● Does not support all features of OOPs. support all features of OOPs.

● Support multiple inheritance. does not support.

● It has operator overloading. does not have.

● It is difficult. easy compare to C++.

● It has Pointer concept. It does not have pointer concept.

● Robust because platform independent.

● Dynamic memory de allocation by user by JVM (G.C.).


To delete keyword.

difference between JDK and JVM and JRE


JDK:- JDK ka full form (java development kit) hota hai.jo ki JVM and JRE ko contains
karta hai.JRE ka Full form (Java Runtime Environment ) hai. And JVM ka full form
(java virtual machine ) hai. JDK java language ke sath work karne ke liye pure tools
provide karta hai. Ye development tools like java compiler debugger etc.
JRE:- JRE ka Full form (Java Runtime Environment ) hai.ye java program ko execute
karne ke liye environment provide karvata hai and program ko run karne ke liye jo
necessary files ki jarurat hoti hai unhe provide karvata hai. Ye JVM ko internally
contains karta hai jo java program ko run karvata hai.
JVM:- JVM ka full form (java virtual machine ) ye interpreter ke form me ek software
hai jo ki C language hme likha hai.Esse hum hamre java program ke byte code ko run
karvate hai. Eske sath libraryes bhi rahti hai.JVM ka kam byte code file ko load
karna ,verify karna and execute karna eske liye 3 component hote hai class
loader,JVM memory Area execution engine
-----------------------------------------------------------------------------------------------------------------

3:-Dynamic and static binding.


According to C language

● Stack is static memory and heap is dynamic memory. C me pointer ke through


dynamic memory allocate ker sakte hai.
● C++ me new keyword ki help se dynamic memory allocate kerte hai or delete
keyword se delete karte hai.
● Java me JVM khud karta hai GC ki help se.

● Static memory pura program terminate hone pr free hoti hai.

● Dynamic memory ko hum apni requirement ke hisab se free ker sakte hai.

● Static memory ko reuse ker sakte hai. Dynamic memory ko nhi ker sakte.

Program save:-File_name.java
Program compile:-javac File_name.java
Program run:-java class_name
Bina main() method ke program compile hoga run nhi.
-----------------------------------------------------------------------------------------------------------------

4:-Escape sequence.
● Only { \ }back slash ka hi mtlab hota hai { / } forward ka koi mtlab nhi
hota
● \n is use to change the current line.

● \t is use to tab space.

● \r is use for move curser at first position.

● \” is used to print single “

● \’ is used to print single ‘

● \\ is used to print single \

● \b is used for back space

● \f is used for form feed

● Forword / slash means nothing C me \ ke bad kuch bhi likhne pr vo \ ko


ignore ker deta hai. but java me error deta hai.

How to set Environment Variables in Java

● 1) Goto Control Panel\System and Security\System

● 2) Click on the Left side last option

● "Advance System Settings".

● 3)Now click on the "Environment Variable" button in Advance tab.

● 4)Input the value of the environment variable in the Edit/New System


Variable window, and click OK.

-----------------------------------------------------------------------------------------------------------------

5:-Variable.
● In C undefined symbol error ati hai bina variable declare kiye. Java me can not
find symbol error ati hai.
● Variable declaration data_type variable_name = value ;
Ex:- int x=20;
● Java me variable ko use karne se pahle uske corresponding value assign karna
compulsory hai. varna error ayege.
● Kise bhi variable ko data_type dene pr memory create hoti hai.

● Variable name unique hona cahiye.

● Variable ka name keyword se start nhi ker sakte hai.

● Variable ka name digits se start nhi ker sakte but beach me use kar skate hai.

● Variable ka name spaceial symbol se start nhi ker sakte hai, Only $ and _ ka
use kar sakte hai. java 8 version se.
● int data_type 4 type ke hote hai int, short ,byte ,long

● float data_type 2 type ke hote hai float and double

-----------------------------------------------------------------------------------------------------------------

6:-Data type and it’s range and size full form of unicode.

Data Type range Defau

boolean false 1 bit

char 0 to 65535 2 byte

byte -128 to 127 1 byte

short -32768 to 32787 2 byte

int -2147483648 to 4 byte


2147483647

long -9223372036854775808 to 8 byte


9223372036854775807

float 0.0f 4 byte

double 0.0d 8 byte


● Jitne range hai utne tak hi number store ker sakte hai.

● Full form of Unicode:- universal code.

● Java me range se bahar jane pr by default int hi manta hai. int ke case tak.

● Arithmetic operator me by default int leta hai.

● Formula:- Max(type of x , type of y , int)

-----------------------------------------------------------------------------------------------------------------

7:-Operators in java.

● Java me by default point vali value ko double manta hai yadi hum cahate
hai ki float me le to number ke last me f lagana hoga.

● Octal ki range 0 se 7 hoti hai.

● Printf full form:- formeted method.

● %f ke case me point ke bad 6 digitd tak value ate hai.

● Kise bhi number ke agge 0b lag jane se vaha binory ban jata hai.

● java me _ ka use kar sakte hai kyo ki compiler usse ignore ker deta hai.

● yadi humne long ka use kiya or last me L nhi lagaya to vha error dega
integer number too large. Kyo ki vo int hi manega right side ki value ko.

● Java me float ke case me point ke bad by default 7 digits and double me


16 digets leta hai.

Video lectures of C reletad to data type and operators.

● Without getch() screen hold nhi hogi but output aa jayega jo ki hum
alt+f5 se dekh sakte hai C me.
● C ki sari files #include file me store hai.

● Ager koi function library me nhi milta hai to error dega .function should
have prototype.
● Full form of stdio.h is stream input output.
● Hum file ka name bhi change ker sakte hai apne hisab se. go in turboC3
>include<all files will be there.
● We can use “ ” at the palce of < > while declare hadder file.

● Keyboard ki sabhi key ko character kahte hai. getch() ka full form get
character hai .yah one character leta hai keyboard se.
● For color change of font in turbo C =go to opetions>environment
>color>edit window>string.
● Comments ko readability ko badhane ke liye use kiya jata hai. jo ki
compiler ke dovara ignore ker de jati hai. ye 2 type ki hoti hai C me
single line and multipal line.
Arithmetic operator:-
Q what is arithmetic operator?
Ans:- arithmetic operators work on 2 operands .+,-,*, /,%
% ke case me jo number ko divide karte hai uska hi shin ata hai. but / me
jo hum padhte aa rahe hai vesa hi chalta hai.

Number System:-
Binory:-0, 1
Octal:-0 to 7
Decimal:-0 to 9
Hexa decimal:-0 to 9 ,a,b,c,d,e,f

● Decimal ko binary me change karne ke liye 2 se divide karege.

● Decimal ko octal me change karne ke liye 8 se divide karege.

● Decimal ko hexadecimal me change karne ke liye 16 se divide karege

● Binary ko Decimal me change karne ke liye 2 se multiply karege.

● octal ko Decimal me change karne ke liye 8 se multiply karege.

● hexadecimal ko Decimal me change karne ke liye 16 se multiply karege

● octal ko hexadecimal me karne ke liye pahle octal to decimal nikalna


hoga and fer uss decimal ka hexadecimal nikalege.
● % ke bad kuch number likne pr vo agge se utne space skip karta hai like
%5d

Relational operator:- <,>,<=,>=,!=,==


Assignment operator:- +=,-=,*=,/=,%=,=

● Eske sath by default compiler implicit type casting ker deta hai.

Inc/Dec operator:- ++,--


This are 2 type

● Pre(++x):- increment then assign.

● Post(x++):- assign then increment.

● Full form of scanf = screen formeted.

● We can use like ++x+++x but we can not use like x+++++x yadi asa karte
hai to error ayega Lvalue required.

Bitwise operator:- &,|,^,<<,>>,~

● & operator me ek bhi condition false to output= false

● | operator me ek bhi condition true to output=ture

● ^ Esme same same false and different different ture hota hai.

● XOR(^)operaot ko nikalne ka shortcut tarika & operator ko OR operator


ki jo value hai usme se substract ker do.
● Bitwise left shef << operator me hume binory nikal ker number ke
peache jitney se shift karna hai utne 0 lagane padte hai fer decimal
nikalte hai.
● Eska shortcut tarika hai ki jo number hai usko jitney se left shift karna
hai utne bar uss number ko double ker do.
● Bitwise right shef >> operator me hume binory nikal ker number ke
peache se jitney se shift karna hai utne 0 hatana padte hai fer decimal
nikalte hai.
● Eska shortcut tarika hai ki jo number hai usko jitney se right shift karna
hai utne bar uss number ko half ker do.
● Bitwise compliment ~ me jo number hai usme 1 add ker do or sign ko
ulta ker do .

Program control statement:- if, if else, nested if, nested if else, else if
ladder, goto, switch case ,ternary operator[conditional operator].
● C programming me hum if() ki ( ) me constant value de sakte hai but java
me nhi de sakte.

Video lectuers of java releed to data type and operators.

● Yadi hum java me printf method ka use karte hai to hume formet
spacifire ka use karna padhta hai yadi nhi karte hai to error deta hai.
● % ke case me jis number ko divide karte hai uska hi sign ata hai.but
divide me jesa padhte aa rhe hai vesa ata hai.
● Formula =Max(first type, second type,int)

● Hum nuber ke beach me _ character ka use kar sakte ha like10_20=1020.

● Bina kise name se bhi hum java me file ko save ker sakte hai like .java
pr class ka name likhan jaruri hai program me.
● Apan character me direct int value de sakte hai pr assign nhi ker sakte
hai.
● jab bhi arithmetic operation perform hota hai to output int me hi ata hai.

● jo user karta hai usse explicit type casting kahte hai or jo compiler karta
hai usse implicit type casting kahte hai.
● Assignment operator me implicit type casting hoti hai.

● java me number ko left se justifty karne ke liye hum %d ke pahle serf 0


ka use kar sakte hai baki kese ka nhi varna exception dega.
● Kabhi bhi number ko increase nhi ker sakte hume variable ke through
karna hoga.
● int character me nhi ja sakta hai but char ko int me store karva sakte hai
assign ker ke but direct int value character me de sakte hai.
● Assignment operator ke case me pahle pura right side solve hoga.

● String and boolean data type ke sath kabhi bhi type casting nhi ker
sakte hai. baki sabhi data type ke sath ker sakte hai
● source ke sare value destination ke pass hona cahiye tabhi implicit type
casting ho sakti hai.
● String and Boolean data type serf == and != operator ke sath work karta
hai.
● Humesa comparesion same same data type ke beach hota hai.
● Jab hum binory nikalte hai or yadi sign bit 0 hoti hai to mtlab positive or
yadi 1 hoti hai to means negative. Yadi sign bit negative hogi To fer 2s
complement nikalna hoga.
● Right shift field with zero operator me jitney se shift karna hota hai utne
0 peache se hata ker start me add ker dete hai fer binory nikalte hai.
● Javap java.package_name.class_name yaha ek ase command hai jo
CMD pr class se releted sabhi details bata deti hai.
● Double class me –ve infinity and +ve infinity hai constant me esliye jab
floate value se divide karte hai to exception nhi ate hai.
● But Integer class me asa nhi hai esliye arithmetic exception aati hai 0 se
divide karne pr.
● Jab 0.0 ko 0 se divide karte hai to NAN ata hai output.

● Hum value ko 3 ways se assign ker sakte hai. Simple


assignment(x=10) , chained assignment(x=y=z=10), compound
assignment( x+=10).
● Assignment operator me by default implicit type casting hoti hai and ye
boolean and string ko chhod ker sab data type ke sath work karta hai.
boolean and string serf += and = operator ke sath hi work karte hai
esme.
● == and != ko equality operator bolte hai.ye sabhi data type ke sath work
karte hai.
● Relational operator boolean and string data type ko chod ker sabke sath
work karte hai.
● Shift operator ke sath boolean data type work nhi kar sakta hai.

● Bitwise operator ko hum assignment operator ki tarha likh sakte hai like
x&=y -> x=x&y;
● Bitwise operator sabhi data type ke sath work karta hai jabki logical
operator serf boolean ke sath hi work karta hai.
● Jab more than one condition ko combine ker ke use karte hai to logical
operator ka use karte hai.
● ! operator ulta ker deta hai .

● Inc/dec operator boolean and String ke sath work nhi karta hai.
● Jab bhi hum kise number ke agge \u laga dete hai to vaha Unicode
character ban jata hai.yadi kuch number diya to vaha by default hexa
decimal ban jata hai.
● String ke bad ka sara content string hi manta hai fer cahe vaha koi sa
bhi data type ho.
● Boolean arithmetic operator le sath use nhi ho sakta hai.

● Java me relational operator ka return type Boolean hi hota hai but C me


int hota hai.
● println()method me sabhi data type ko store kar sakte hai.

● yadi value ko increment karte hai to Lvalue required error ate hai C me.

● Jab bhi continue order me solve karte hai to pahle hamesa post hi
manta hai.
● Jab value assign hoti hai to main memory me ja ker store hoti hai. varna
pahle expression temporary memory me ja ker store hota hai.
● Inc/dec by default implicit type casting provide karvata hai

● Java me class hamesa capital letter se start hoti hai or keyword hamesa
small letter se start hote hai.
● .class file ka size 8 bit hota hai.

● ASCII Value of characters


0 - 9 Numbers 48- 57
A - Z Capital letters 65 - 90
a - z small letters 97 – 122

● Full form of ASCII and Unicode

ASCII :- American Standard Code for Information Interchange.

UNICODE :-Universal code (Unique, Universal, and Uniform character


enCoding)

-----------------------------------------------------------------------------------------------------------------

8:-Type casting And Wrapper class.


Q whar is type casting?
Ans:-changing a value frome one data type to another data type is called type
casting.
Type casting is happen when you assign a value of one primitive data type to
another type.

● Ek data type ko dusre data type me convert karne ki process ko type


casting kahte hai.
● Ek object ko dusre object me convert karne ki process ko type casting
kahte hai.
● Data type ko object me and object ko data type me kabhi convert nhi kar
sakte hai.
● Yadi hum data type ko object me ya object ko data type me change
karna cahate hai to hume wrapper class ka use karna hoga.

In Java, there are two types of Type casting:

1)implicit casting (automatically):- Converting a smaller type to a larger type.it


is done by compiler.

* ye tabhi hote hai jab sourse ki sare value destination ke pass ho. Yadi nhi
hogi to implicit type casting nhi hogi.

*yadi hum karna cahate hai to fer hume explicit type casting karna hoga.

* jab bhi hum explicit type casting karte hai to data ke loss hone ki possibility
rahte hai.

* type casting karne pr vaha apne range ke circle me move karne lagta hai.

byte -> short -> char -> int -> long -> float -> double

2)explicit Casting (manually):- Converting a larger data type to a smaller data


type.it is done by user.

double -> float -> long -> int -> char -> short -> byte

Weapper class:-

Q what is wrapper class?

Ans:-wrapper class primitive data type ko object me convert karne ka kam


karti hai.
● Yadi hum string ko int me convert karna cahate hai to hume parseInt()
method ka use karna padega ye serf string type ke numeric data ko hi
convert karte hai. yadi kise or type ke data ko dete hai to exception
dega.

-----------------------------------------------------------------------------------------------------------------

9:-Keyword in java.
Q what is keywords?
Ans:- keywords are special type of words. That have a predefined meaning in
the language.
There are total 53 Reserved keywords in Java. They are:

50 -> Reserved Keywords

48 keywords

(can be used by programmer )

2 keywords

(can't be used by programmer i.e goto and const)

3 -> Literals

(Three literals used by Java are True,False and Null)

● OOPs has 17 keyword.

● Program control statement have 10 keywords.

● Exception handling have 5s keyword.

● 8 data type

● Other 10 keyword.
-----------------------------------------------------------------------------------------------------------------

11:-Control statement.
Q what is control statements?

Ans:-java me program sequencing order me execute hota hai mtlab line by


line.

By using control statement we can control the flow of program.

If, if else, nested if , else if , else if ladle , switch case .

● if() ke pearanthises me constant value nhi de sakte hai java me. But C
me de sakte hai.only boolean de sakte hai.
● else ko kabhi bhi single use nhi ker sakte hai.

● if() and else ke beach kabhi bhi koi statement nhi ho sakta hai.

● Yadi ek bar else if me condition true ho jate hai to vo agge check nhi
karega.
● else if() ladder me jaruri nhi ki last me else ho.

● Yadi if() me { }nhi lagaya to by default vaha first semicolon tak manta
hai.

switch case:-

● default ka use pure program me kahi bhi ker sakte hai.


● 1 program me 1 se jiyda switch case use ker sakte hai.

● Ager ek ke ander ek switch case ho sakte hai but usme break use nhi
hona cahiye.
● case ki condtion switch se match na hone pr hi default work karta hai
varna nhi karta.
● default ke bina bhi program run ho jata hai , default ke agge bhi colon (:)
lagana jaruri hai.
● Ek program me 1 se jiyada default ka use nhi ker sakte hai.

● Ek program me 2 same case nhi ho sakte hai.yadi kiya to error ayege


duplicate case
● break ka use na karne pr program continue chalega end tak.

● break ko loop and switch case ke sath hi use ker sate hai only.

● Jis type ke data type ka variable humne switch case me pass kiya hai
hum usse type ke case bana sakte hai.other nhi.
● switch case me char, int, byte, short, String, ke alava koi or data type
use nhi ker sakte hai.
● yadi variable char me hai or case me int hai to ASCII value se work
karega.
● break ko 1 se jiyada bar use kiya ek sath to error dega java me. But C me
work karta hai.
● Switch ke () me value pass karna jaruri hai khali nhi chood sakte hai

● program run command in different version:-


javac –source version_name class_name.java
● version 1.7 se java ne switch case me String ko use karne ki permission
di hai usse pahle nhi thi .version 1.7 me serf warning deta hai.
● case me variable ke name ko direct use nhi kar sakte hai yadi karna
chate hai to us variable ko final keyword se final declare karna hoga.
● Switch ke sath continue ka use nhi ker sakte hai java me. But C me ker
sakte hai

-----------------------------------------------------------------------------------------------------------------
12:-Loops.
Q what is Loop?
Ans:-Loop is used to execute the block of code several times according to
the condition given in the loop. It means it executes the same code multiple
times so it saves time or code and also helps to traverse the elements of an
array.
There are 4 types of loop

● while loop

● do while loop

● for loop

● for each loop

int i; => ( declare )


i=10; => (initialization)
i++; => ( incriment )
Step1:- initialization.
Step 2:- check condition.
Step 3:-if condition is false then loop end.
Step 4:- if condition is true execute body and increment /decrement
Step 5:- again condition check if it is true it will execute until condition will not be false.
for each loop ka mainly use array ke data ko print karvana hota hai.
for each means automatically executable loop.
for each/enhance loop ka advantage yaha hai ki hum cahe kitne bhi size ka array bana ker
ready ker sakte hai.
For each loop ka concept java 1.5 version se aya hai.usse pahle nhi tha.

● Unreachable statement variable ke case me nhi ayega serf true or false


ke case me ayega.
● Variable ki value run time pr decide hoti hai compiler ko pta nhi hota hai.

● Constant ke case me compile time pr chacking hoti hai and variable me


run time pr.
● final variable ki value kabhi change nhi ho sakte hai.

● loop ke () me loop ka variable declare karne pr hum uss variable ko loop


ki body ke ander tak hi use ker sakte hai bahar nhi.
● For loop me serf 2 hi semicolon hona cahiye na hi usse jiyda na hi kam.

● Loop me jab condition nhi hoti hai to by default vo true manta hai.

● Local variable ki kabhi bhi default value nhi hoti hai humesa instance
variable ki hoti hai 0 java me.
● Loop me first semicolon ke bad serf condition hi hona cahiye koi
statement nhi. kyo ki vo void leta hai.
● Java me loop me 2nd semicolon ke bad hum i+2 ase nhi de sakte error
dega kyo ki assign karna jaruri hai, C me chal jayega .
● Yadi loop me condition me direct false diya hai to error ayege ki jab
false hi dena tha to loop kyo lagaya
● Yadi true dege to loop ke bahar koi statement nhi de sakte hai kyo ki
infinite time jayega to vaha tak pahochega hi nhi .kyo ki java me kuch
bhi chij faltu use nhi ker sakte.jiska koi use na ho.
● Condition me true false ke case me unreachable statement error ati hai
java loop ki body ke bahar print karate hai to. But variable ke case me
nhi ati hai infinite times chalta hai program.
● Ager loop ke body nhi banai hai to loop ke just neache ap variable
declare nhi ker sakte ho .body banana ke bad ker sakte hai.body ke
ander.
● ! operator ka use serf Boolean data type ke sath hi ker sakte hai.

● Yadi kise number ko check karna hai ki vo 3 se divide hota hai ki nhi to
jis number ka janna hai uski digits ka sum ker lo or ager sum ane vala
number 3 ke table me ata hai mtlab vo 3 se divide ho jayega.
-----------------------------------------------------------------------------------------------------------------

13:-Labbled break and Labbled continue statement.


Q what is labbled break and labbled continue?
Ans:- labbled break direct labble se break karne ka kam karta hai cahe kahi se
bhi ho.
OR
It is used to bypass the reminder code for some condition for a particular loop
from certain point but continue is execute the loop continuesly.

● Continue flow ko neache ane se rokta hai.

● Normal continue and break ka loop and switch me hi use kar sakte hai
,switch ke sath continue ka use nhi ker sakte java me .but labbled ka use
kisi ke bhi sath ker sakte hai.
● Labbled break and continue are ulternative of goto. Because we don’t
have permission to use goto in java.
● Normal break by default current line ko break karta hai. but labbled pure
labble se hi break karta hai.
● Logical operator me yadi ek condition satisfied hoti hai to fer vo next ko
check nhi karta hai but bitwise me dono condition ko check karta hai.
● Logical operator Boolean ke case me work karta hai and bitwise int ke
case me.
● Object ki working runtime pr hoti hai variable ki working compile time pr
hoti hai.
● Integer me _ ko use karne ki permission java version 1.7 se de hai use
pahle nhi thi.
-----------------------------------------------------------------------------------------------------------------

14:-Array 1d, 2d , 3d and so on…….(multiple array).


Q what is array?
Ans:-array Is collection of homogeneous type of data [same type ka data].

● class ka bhi array bana sakte hai. Ex:- String s[ ]={ };

● array declaration :- data_type variable_name [ ]= new datatype[size];

int x [ ] =new int [5];


● int x[ ]={10,30,30};

● Array ka index –ve nhi ho sakta hai.like S.o.pln(x[-1]); .Exception ati hai.

● Yadi index se jiyda value access karne ki kosis karte hai to array
indexOutOfBound exception ate hai java me. But C me garbage value
deta hai.
● Array ke pure data ko print karvane ko array ko travers karna kahte hai.

● Jab bhi koi exception ayege to uske pahle ka data print hoga but uske
baad ka print nhi hoga.
● Data types default values in instance :- byte,short,int,long=0;
Float, double=0.0;
Boolean=false;
Char =space;
String =null;
● Array type ka variable normal variable me convert nhi hota hai.

● Bahot sari value ke Collection ko 1d array kahte hai.

● 1d array ke collection ko 2d array kahte hai and so …….on.

● Yadi data ko metrix ke form me print karvana hai to 2d array ka use karte
hai.
● 2 array declaration :-

data_type variable_name [ ] [ ] = new data_type[number of 1d array] [value of


1d array]
Ex:-int x[ ] [ ]=int [2][3];

● Jab bhi array ke elements fix na ho usse irregular array kahte hai.
Ex:- int x[ ] [ ]=new int[3] [ ]; exception ate hai yaha. nullpointer.
● Length ka means number of totle element jo 1 se start hota hai but
indexing 0 se start hoti hai.
● Metla ek esi language hai jisme indexing 1 se start hoti hai.

● Parent class ki property child class pahle access karne ke liye super
keyword ka use karte hai inheritance ke case me. Kyo ki by default child
ka hi data print hota hai.
● Array ko khali ya fer es tarha se declare nhi ker sakte Like:_
Int x[ ] [ ]=new int [ ] [3];
● Hum kis kis tarha se array declare ker sakte or kis tarha se nhi:-
int x[ ] [ ]=new int [4] [ ]; //Work
int x[ ] [ ]=new int [ ] [3]; //error
int x[ ] [ ]=new int [ ] [ ]; //error
int [ ]x [ ]=new int [4] [3]; //it will work
int [ ] [ ]x=new int [4] [3]; //it will work
int [ ][ ] x=new int [4] [3]; //it will work
int [ ] x[ ]=new int [4] [3]; //it will work
● Syntax of Anonymous array:- int [ ] x=new int[ ]{2,3,4,2,5};

● Anonymous array asa array hota hai jiska koi name nhi hota hai. ese
function ke throw get karte hai.
● List of 2d array is called 3d array.
1d array=collection of indexing value.
2d array=collection of 1d array
3d array=collection of 2d array
● 3d array declaration :- Int x [ ] [ ] [ ]=new int [3d] [2d] [1d];

Q:- 1:-Find maximum and minimum value from array:- hum 2 tarha se ker
sakte hai. 1st firstly short array 2nd get length and compare.
2:-find second learges value to array.
-----------------------------------------------------------------------------------------------------------------

● Ctrl+shift+up down:- for drage line of code.

● Ctrl+shift+Q:-for multipal line comment.

● Ctrl+Q:- for single line comment.

15:-Commend line argument.


Q what is commend line argument?
Ans:-esme jab hum run time pr run command ke bad jo likhte hai vo main
method ke array ar[ ] me ja ker store ho jata hai.

● Interview question:- commend line argument se 2 number ko addition.

● Interview question:- user commend line argument se jitney bhi number


dale uska addition.
-----------------------------------------------------------------------------------------------------------------

Class:- class is a collection of data member and member function .


Ex:- Animal , Fruit.

● Same type ke data ko ek hi category me rakhne ke purpose se hum


class ka use karte hai.
Object:-object is real time entities .
OR
When any refrance gets memory that’s called object.
Ex:-chair, laptop ,LED etc.
Abstraction:- hiding internal details and showing only essential
information[functionality] is called Abstration.
Ex:- car , ATM.
Inheritance:- when child class able to access the property of parent class is
called inheritance.
Ex:- Dog access property of Animal class.
Polymorphism:- Polymorphism word came from greek language .if one task is
perform in different way it is known as polymorphism.
OR
Same function name with different functionality is called polymorphism.
Ex:- speaking .
Encapsulation:- Wrapping up the data member and member function in single
unit is called encapsulation.
Ex:- capsule

16:-Instance and local variable.


Q what is instance varable and local variable?
Ans:- A variable which is declare outside the method and inside the class is
called instance variable.
A variable which is declare inside the method is called local variable.

● Object ka other name instance hai. Bina object ke class ka data bahar
access nhi ho sakta hai.
● Instance variable, method and block ho sakta hai.

● Jitney parameters use kiye hai method me uthe hi calling me pass karna
hai na hi kam na hi jada.
● Yadi value ko return karvaya hai to jaha se hum call karte hai vhi pr
value return hoti hai.
● Kise bhi variable ko use karne se pahle usme value ko assign kerna
jaruri hai.
● Local variable ko initialize karna hota hai instance variable ko nhi kyo ki
eski default value 0 hoti hai.
● Yadi mithia room me hai mtlba (method me) to hall me matlab (class me
)nhi jayega yadi room me nhi hai to hall me jayega or yadi hall or room
dono me nhi hai to dusre ke room me nhi jayega mtlab gussa aa jayega
to error aa jayegi.
● Mithai eyes ke samne hona cahiye mtlab agge ki taraf peache kabhi nhi
dekhega.
● Har ek object ke corresponding instance variable ki separate memory
create hoti hai.
-----------------------------------------------------------------------------------------------------------------

17:-this and super keyword.


Jis tarha se C++ me this pointer work karta hai vese hi java me this keyword
work karta hai.

● this hamesa current class ke instance variable ko point karta hai and
current object ke refrence ko hold karta hai.
● super keyword parent class ke property ko child class se pahle access
karvane me help karta hai. inheritance ke case me.

Here is given the 6 usage of java this keyword.

1. this can be used to refer current class instance variable.


2. this can be used to invoke current class method (implicitly)
3. this() can be used to invoke current class constructor.
4. this can be passed as an argument in the method call.
5. this can be passed as argument in the constructor call.
6. this can be used to return the current class instance from the method.

Usage of Java super Keyword

● super can be used to refer immediate parent class instance variable.

● super can be used to invoke immediate parent class method.

● super() can be used to invoke immediate parent class constructor.


-----------------------------------------------------------------------------------------------------------------

18:-String class methods.


Return_type method_name
int length();
char charAt(int)
String toUpperCase()
String toLowerCase()
boolean equals(String)
boolean equalsIgnoreCase(String)
String concat(String)
int indexOf(String)
int lastIndexOf(String)
String substring(int)
String substring(int,int)
boolean startsWith(String)
boolean endsWith(String)
String trim()
int compareTo (String)
int compareToIgnoreCase(String)
String replace(char,char)
String[ ] split(String)

● String class ka object kitne tarha se bana sakte hai:-

● String s1=new String(“Manish”);

● String s2=”Manish”;

● String s3=new String();


s3=“Manish”;
● char x[ ]={‘M’,’a’,’n’,’i’,’s’,’h’};
String s4=new String(x);
-----------------------------------------------------------------------------------------------------------------
19:-Constructor.
Q what is constructor?
Ans:-constructor is block of code ,it is use to initialize the object.

● Jaha bhi constructor ki bat ate hai it is use for initialize the object.

● Constructor ka return type nhi ho sakta.

● Class ka jese hi object banega Constructor call ho jayega.

● Constructor name same class name jesa hona cahiye.

● Constructor overload ho sakta hai override nhi.

● Ek hi class me bahot sare Constructor ko different - different parameter


ke sath bana ker ready karna Constructor overloading kahlata hai.

● Yadi kise Constructor ka return type de diya to vo apne ap ko method


manne lagta hai java me.

● Inheritance me constructor ke case me parent class ka constructor call


hota hai jabki method ke case me sub class ki method call hoti hai.
Constructor are two types:-
1:- Default , 2:- parameterized

● Yadi koi constructor na banao to compiler default constructor add ker


deta hai
● Kai log bolte hai Constructor 3 type ke hote 3rd non parameterized hota
hai . But asa nhi hai jo bina parameter vala user declare karta hai use
non parameterized kahte hai or jo compiler karta hai use default kahte
hai. lekin hai dono same hi.
● 1 object se constructor ek hi bar call hota hai.jabki method n number of
time call ho sakte hai.
-----------------------------------------------------------------------------------------------------------------

20:-Inheritance.
Q what is inheritance?
Ans:- when sub class access the all properties of existing class .
● Child class ke object se parent ki sare properties access ker sakte hai.

● Inheritance are 3 types in java: single inheritance.

Multilevel inheritance.
Hierarchical inheritance.
multipal inheritance java me nhi hai eske palce pr interface diya hai.

● Multipal inheritance me ambiguti ate hai esliye.

● Methods and variable by default default hote hai.

● Object hamesa sub class ka hi banega.

● Inheritance perform karne ke liye java me extends keyword ka us karte


hai. C++ me: ka use karte hai.
● It provides reuseablity.

● We can not access private class data through inheritance

● Method overloading serf inheritance ke through hi possible hai.

● Jab 1 child class 1 parent class ki property ko access karti hai to vaha
single inheritance kahlata hai.
● Chain inheritance ko multilevel inheritance kahte hai .

● Jab more than one child class 1 parent class ki property ko access karti
hai to use hierarchical inheritance kahte hai.
Q why java does not support multipal inheritance?
Ans:-jab bhi chaild class more than 1 parent class ko extends ker ke us
class ko access karti hai jiske pass same method hai to java compiler
confuse ho jata hai and there might be memory duplication that’s why java
does not support multipal inheritance.
-----------------------------------------------------------------------------------------------------------------

21:-Exception handling.

● Exception hamesa run time pr hi ati hai cahe koi kitna


bhi confuse kare.
Q what is Exception?
Ans:-An exception is unexpected or unwanted event which occurs at
execution of program.

Q what is Exception handling?


Ans:- program execution ke doraan aane vale distruction ko ignore karne
ke liye use kiye jane vale code ko exception handling kahte hai.

● Ek try block pr exception to kitni bhi aa sakte hai but frist exception ke
baad try block terminate ho jata hai.
● Exception Throwable class ki sub class hai. and Object class sabhi
class ki parent class hai java me.
● Exception 2 type ki hoti hai 1:- Checked 2:- Unchecked exception.

● Asi exception jo compiler ke dovara check ki jate hai usse checked


exception kahte hai.
● Asi exception jo compiler nhi JVM check karta hai usse unchecked
Exception kahte hai.
● Checked Exception sub classes:-IO , Sql , UnknowHost ,FileNOtFound,
ClassNotFound Exception.
● Unchecked Exception sub classes :- NumberFormate, Arithmetic ,
NullPointer , ClassCast , ArrayIndexOutOfBounds ,
StringIndexOutOfBounds Exception.
● All exceptions ki super class Exception hai.

● Exception handling have 5 keywords:- try, catch, finally, throw, throws .

● Jis code me exception ke ane ke chances hote hai usse try block ke
ander likhte hai.
● Jese if ko else ke bina use nhi ker sakte vese hai vese hi try ko
catch,final ya resource declaration ke bina use nhi ker sakte hai.
● Jis type ki exception try me junrate hoti hai uss hi type ka catch block
execute hota hai.
● catch() ke pahle try hi hona cahiye.

● try and catch() ke beach me koi bhi block of code nhi aa sakta hai.

● catch block tabhi execute hoga jab try me exception ayegi.

● 1 try block ke sath kitne bhi catch block use kar sakte hai.
● try block me exception junrate hone ke bad uske neache ka code
execute nhi hoga.
● File ka name humesa run time pr check hota hai.

● throw keyword kabhi bhi exception handle nhi karta hai. ye kam serf
try ,catch and finally karte hai.
● finally block always executable block hota hai.

● Cahe exception aye ya na aye finally block to chalega hi.

● Ex:- yadi hume koi account register karna hai koi bhi software me to
hume sabse pahle data base ya server se connect karna hoga.to hume
sabse pahle connection ko open karna hoga or last me close karna
hoga. Yadi last me connection ko kisi karan se close karna bhul gaye to
application crase ho jayege to esse bachane ke liye finally block ka use
karte hai.
● Hum finally block ko kahi bhi use kar sakte hai try ya catch block ke bad.

● Exception recoverable hoti hai jabki error nhi hoti hai.

● Yadi exception ko handle nhi kiya hai to pahle finally block chalega uske
bad exception ayege.
● Yadi hum cahate hai ki humari condition ke according exception ana
cahiye to hume throw keyword ka use karna padega.
● Hum throw keyword ki help se checked and unchecked dono type ki
exception junrate ker sakte hai.
● Jo hum exception ke constructor me pass karte hai koi bhi string to vo
exception ke colon{ : }ke bad output me aa ker print hota hai.
● Yadi humare program me unchecked exception aa rahi hai to compile ko
koi problem nhi hogi kyo ki JVM check karega to run time pr ayege. But
yadi checked exception ate hai to ya to try catch and finally block se
handle ker lo ya fer throws keyword se method se bahar ker ke calling
method ke pass pahocha do.

● Yadi hum Checked Exception to throws karvate hai to hume io package


ko import karna jaruri hai.

● Yadi hum throw keyword se exception ko throw karvate hai to uske


neach koi bhi statement nhi ho sakta hai. unrechable error deta hai. But
ager koi Exception aati hai to uske neache likh sakte hai.
● Overriden method kabhi bhi exception ko throws nhi ker sakti hai. Yadi
hum super class ki method se karvayege to koi problem nhi hai but
subclass ki method se throws karvane pr error deta hai.
Q Exception kab kab aa ker junrate hoti hai?
Ans:-exception serf run time pr hi junrate hoti hai. to fer FileNotFound
Exception ky hai? ye to ek worning hai. ki run time pr exception aa sakti hai to
ese handle ker lo. Ex:- bajar vala ya railvestation vala.

● Throws keyword humesa serf Checked exception ko hi drope down


karta hai calling method ke pass Unchecked ko nhi.
● Java program me bydefault ek thread hota hai jise main thrade kahte
hai.Hum khud ka bhi thrade bana ker ready ker sakte hai.
● Har ek thread ke liye JVM runtime stack creates karta hai.

● JVM har method ko stack me store karta hai and execution complete
hone ke baad one by one har method ko bahar nikal deta hai or ase
karte karte main method ko bhi execute kerne ke bad jab stack empty
bachti hai to JVM uss stack ko destroy ker deta hai. Ese Runtime Stack
macnism karhte hai.
● Method me exception ati hai to vah JVM ko handover ker deta hai. Fer
JVM check karta hai ky exception ko handle karne ka code method ke
ander hai ya nhi hai yadi nhi hoga to vo program ko abnormally
terminate ker dega.
● Jab exception handle nhi hoti hai to JVM last me us exception ko default
exception handler ko handover ker deta hai.
Q default exception handler exception ko kis form me printf karvate hai?
Ans:-vaha stack ke form me print karvata hai.

● Syntax of exception:- Name of exception:description

Stack trace.

● Stack trace ka means kis kis method se exception ho ker aai hai.

Exception propagation:- jab bhi throws keyword se exception ko calling


method ke pass dropedown karte hai ase karte karte jab vaha main() method
tak pahoch jata hai or fer method se bahar kerne ke just pahle default
exception handler ko handover ker deta hai. ye jo exception deligat hoti ja rahe
hai ya propagate hoti ja rahe hai ese hi exception propagation kahte hai.

● Diffrence between throws and try catch block?


1:- throws keyword exception ko calling method ke pass deligate karta
hai. Jabki try catch block exception ko handle karte hai.
2:- throws keyword serf checked exception ko calling method ke pass
/dropedown karta hai. Jabki try catch block dono checked and
unchecked ko handle karta hai.
3:- throws keyword ko method ke bahar use karte hai.Jabki try catch ko
method ke ander use karte hai.
● Diffrence between throw and throws keyword?
1:- throw keyword manually exception ko junrate karne ke liye use karte
hai. Jabki throws keyword ka use checked exceptionko method se bahar
karne kam karta hai.
2:- throw keyword method ke ander use hota hai. Jabki throws keyword
method ke bahar use hota hai.
3:- throw keyword ke sath hamesa exception ka object use karte
hai.Jabki throws keyword ke sath exception ka name use karte hai.
4:- throw keyword se 1 bar me 1 hi exception ko junrate karva sakte hai.
Jabki yadi hamare program me more than one exception ane ke chance
hai to hum comaa { , } se seprate ker ke sabhi ko bahar ker sakte hai.
Q kya hum 1 catch block se more than one exception ko handle ker
sakte hai?
Ans:-ji ha blikul ker sakte hai | symbol ka use karke ,but esme parent
child reletion nhi hona cahiye.
● Yadi hum cahate hai ki hume bar bar exception ka name na likhna pade
to hum catch block me exceptions ki parent class Exception ko block
pass ker sakte hai.
● Ek hi type ki exception ko 1 se jiyada bar catch nhi karva sakte hai.

● Hum catch block me pahle Exception name and baad me Exception


class use kar sakte hai. eska ulta nhi.
Q ki jo ye exception handling topic pad rahe hai esme exception ko print
karvane ke kitne tarike hai.
Ans:- hum exception ko 3 tarike se print karva sakte hai.
1:-toString():-Exception name + Description.
2:-getMessage():- Discription.
3:-printStackTrace():- Exceptoin_Name + Discription +stack trace.
Q ki jab default exception handler exception ko print karvata hai to kis form
me karvata hai?
Ans:- printStackTrace ke form me . Esliye vo exception ko stack ke form me
print karvata hai.
Q what is fully checked exception?
Ans:-ase exception jiski sari sub class checked exception ho usse fully
checked exception kahte hai. Ex:- IO Exception.
Q what is partially checked exception?
Ans:- ase exception jiske pass checked and uncheacked exception dono ho
usse partially checked exception kahte hai.
-----------------------------------------------------------------------------------------------------------------

22:-Static keyword.
● static method static data ko hi access ker sakti hai without Object .

● Non static method static and non static dono type ke data ko access kar
sakti hai.
● Yadi hum method ke data ko bina object ke access karna chate hai to
hame method ko static banana padega.
● static can be inner class, globle variable,method,static block,static
import,static object.
● Yadi static method hai to override nhi ho sakte hai.

● Yadi method ko static bana diya to vo direct class name se access ho


sakte hai ( . )operator ki help se.
● Har ek object ke courresponding instance variable ki seprate memory
creat hoti hai. jabki static variable ki commen memory creat hoti hai.
● Variabel mainly 2 type ke hote hai 1:- non static [instance variable] 2:-
local .
● JVM me memory ke alag alag part bane hote hai data store karne ke
liye.
Q Diffrence between instance and static variable?
Ans:- 1:- Har ek object ke courresponding instance variable ki seprate
memory creat hoti hai. jabki static variable ki commen memory creat hoti hai.
2:- instance variable heap memory me ja ker store hota hai. jabki static
variable memory area name ke memory me ja ker store hota hai.
3:-instance variable object se hi access hota hai. jabki static variable direct
class name and object se call ho sakta hai.
4:-instace variable ko object variable bhi kahte hai. static variable ko class
variable bhi kahte hai.
Q asi konsi condition jaha ap static ka use karege?
Ans:-unic memory ko junrate karne ke liye. Ex:- railve ticket, collage
admission.

● static keyword ka use memory manegment ke liye karte hai.

● static variable me ek jagha update karte hai to sabhi jagha update ho


jata hai.but instance variable me nhi hota.
● static method serf static data ko hi access karti hai but object se hum
kisi bi type ke data ko access ker sakte hai.
● S.o.pln() hum method ke ander hi likh sakte hai.

● Jese hi object create hota hai instance block call ho jata hai.

● static block class ke load hote hi call ho jata hai. yadi humne class ko
kise bhi tarha se kahi bhi access kiya to vo load ho jati hai.
Q ky hum hamare program me more than one instance block bana ker ready
ker sakte hai?
Ans:- ji ha bilkul ker sakte hai but yaha 1 object se 1 hi bar call ho sakta hai.
Q instance block and constructor me ky difference hai?
Ans:-1:- instance block object se metch ho ker call hota hai .jabki constructor
parameter se match ho ker call hota hai.
2:-Instace block me koi perameter nhi de sakte , But constructor me de sakte
hai.

● sabse pahle static block chalta hai then instance block then constructor
then method.
● Jab jab object banega constructor ke pahle instance block call hoga fer
constructor call hoga.
Q JVM main() method ko direct call karta hai ya object bana ker?
Ans:- JVM main method ko direct class name se access karta hai kyo kyo ki
main() method static hai.

● JVM main() method ko kuch ase call karta hai :- class_name.main()

static block

● Sabse pahle program me class load hoti hai.

● static block class load hote hi call hota hai.


● Static block method ke ander work nhi karta hai but instance block work
karta hai.
Q ky hum hamre program me more than one static block create ker sakte hai?
Ans:- ha hum hamri class me kitne bhi static block bana ker ready ker sakte
hai koi problem nhi hai.
Q ky static block class me upper neache kahi bhi use kar sakte hai ya fer
neache hi ker sakte hai?
Ans:-ha hum static block ko class me kahi bhi use kar sakte hai.
JVM sabse pahle all static block ko hi call karta hai tabhi main() method ke
pass jata hai.

● JVM jis method ki jarurat hoti hai usse hi call karta hai sabhi ko nhi.

● Object bante hi class load ho jate hai cahe object kahi bhi bane.

Q ky bina main() method ke program run hoga?


Ans:- java 1.6 tab bina main() method ke program run ho jata tha pr uske bad
se nhi hota hai.

● Static variable local variable nhi ho sakta kyo ki static variable ki sabhi
ke liye commen memory creat hoti hai.esliye vaha globle hi hona cahiye.
Q Explane public static void main(String ar[])
Ans:-

● Command line argunment ke perpus se main method me String arr[]


pass karte hai.
● JVM jab bhi program ko run karta hai to vaha pahle program me main()
method ko dhundhta hai.esliye main() likte hai.
● main() method kabhi bhi value ko return nhi karti esliye eska return type
void likhte hai.
● JVM main() method ko direct class name se access karta hai esliye esko
static declare karte hai.
● JVM main() method ko kahi se bhi access ker sake esliye ese public
declare karte hai.
● Class serf 1 hi bar load hoti hai.

Q ky hum object ko static bana sakte hai?


Ans:- ha hum object ko static bana sakte hai.main method ke upper declare
ker ke kahi se bhi access ker sakte hai object ko.
Q ky println() method System class ke pass hai?
Ans:- nhi ye to PrintStream class ke pass hai jo ki IO package se belong karti
hai.

● println( )method PrintStream class ki instance method hai.

● eska mtlab ye hai ki PrintStream class ke object se println() method call


ho jayege.
Q Explain System.out.println()?
Ans:- println() method PrintStream class ke pass rakhi hai.

● PrintStream class java.io package me rakhi hai.

● out System class ka final static variable hai.

● out System class ka static variable hone ke sath sath PrintStream class
ka object bhi hai.
● out PrintStream class ka object hai esliye hum out se printStream class
ko ace ss ker sakte hai.

Static block:-
Q version number 1.5 ka koi new feature batao?
Ans:- static import and for each loop.
● Eska benefit ye hai ki hume bar bar same chij ko likhna na pade to use
static import ker do.
● Syntax:- import static java.package_name.class name.*;

● parseInt() method bhi Integer class ki static method hai.

● local variable ka scope method block tak hi hota hai uske bad vo
destroy ho jata hai. But static variable ka scope program terminate hone
tak hota hai.
Q Ase konse condition hai jaha ambiguse error aa sakte hai?
Ans:- 1st static import jab Integer ,Short, class ko ek sath import ker ke
access kare tab. 2nd multipal inheritance me.
Q main() method ko JVM call karta hai ky koi ase condition hai jaha hum
manually main() method ko call ker sakte hai?
Ans:- ji ha sir hum main() method ko manually call ker sakte hai. class
name se.

● this and super keyword ko kabhi bhi static method ke ander use nhi ker
sakte.

23:-Polymorphism.
Virtual or Pure virtual Function.
 C++ me by default Compile time binding hoti hai. Mtlab refrance jiska uski
method call hogi . But java me by default run time binding hoti hai mtlab ki
jiska object uski method call hogi.
 C++ me sabse pahle vo check kartra hai ki jiska refrece hai uske pass vo
method hai ya nhi . yadi hoti hai to check ki vo method normal hai ya
virtual or pure virtual yadi nhi hai to compile time pr hi binding ker dega.
Nhi to fer run time pr binding karega yadi run time binding hoti hai to jiska
object uski method call hogi.
 Yadi compile time binding ho jati hai to run tim kabhi nhi hogi.
 Yadi C++ me jiska refrance hota hai uske pass normal method hoi to jiska
refrance uski method call ho jatyegi . But java me yadi esa hota hai to jiska
object uski method call hogi.
 Yadi java me hum cahate hai ki compile time pr binding ho to hume
method ko static banana hoga.
 Compile time binding reference ke currusponding hoti hai . But run time
binding Object ke currusponding hoti hai.
 Virtual function vitual keyword se declear karte hai but pure virtual
function ko virtual keyword ke sath sath 0 se intilize karna compalsari hai.
 En dono ke currusponding C++ me runtime binding hoti hai.
 Virtual function ko override karna jaruri nhi hai ker bhi sakte hai nhi bhi
apki choice. But pure virtual method ko override kerna compalsari hai.

Q what is polymorphism?
Ans:- one thing more form means ek chij ke kai tariake or uska mtlab saff
taraha se najer ata ho.
OR
Same function name name with different functionality is called polymorphism.

● This are two types:-


1:- compile time / static binding / early binding.
2:- run time / dynamic binding / late binding.
● According to compile time polymorphism:- method overloading, method
hinding.
● According to run time polymorphism:- method overloading.

● static method ko overlode to ker sakte hai but override nhi ker sakte hai.

● Private method ko overlode to ker sakte hai but override nhi ker sakte.

● Final method ko overlode to ker sakte hai but override nhi ker sakte.

Q ky main() method ko overlode or override ker sakte hai ?


Ans:- main() method ko overload to ker sakte hai but override nhi ker sakte
hai.

● Method overloading:- same class.

Same method name.


Different parameter list.

● Method Overriding:- Different class .

Inheritance.
Same method name
Same parameter list.

● Method overriding ka advantage ye hai ki same method rahte hai to


hume method ke name yad nhi rakhna padta hai.
1:-Code ko reuse ker sakte hai.
2:-Time save hota hai.
3:-Execution fast hota hai.
● Humesa es order ko follow karta hai.
byte -> short -> int -> long -> float -> double.
● Super class ka constructor hamesa default hona cahiye.

● Yadi humare program me koi bhi constructor nhi hai to JVM by default
default constructor ko add ker dega.
● Sub class se serf or serf by default super class ka constructor hi call
hoga.
Q difference between method overriding and method hinding?
Ans:- 1:-method overriding me super class and sub class me instance method
hona cahiye. Jabki method hinding me static hona chahiye
2:- method overriding runtime polymorphism ka type hai. method hinding
compile time polymorphism ka type hai.
3:- method overriding working object ke corruesponding hoti hai . method
hinding referance ke corruesponing hoti hai.
-----------------------------------------------------------------------------------------------------------------

24:-Varargs methods in java.


Method overloading me kuch drawbages hai jese hume 5 numbers ka addition
karna hai to 5 argument vali method banana padege.ase hi bahot sare methods
banana hai to alaga argument dena hoga. But jabki yahi kam 1 method se ho
sakta hai jise varargs kahte hai. Esme kitne bhi number of parameters pass ker
sakte hai.

● Varargs ko 3(…) dots se hi add karte hai usse na jiyda na kam.

● Example ke liye jese printf() method hoti hai C me to jitne bar %d likho
uthne bar number print hote hai to usme bhi varargs ka hi concept hota
hai.
● Hum varargs ki jarurat kyo padi?
1:- Ky hoga yadi hume na pta ho ki hume kitne number of parameters
pass karne hai.
2:- Ky hoga yadi ap unlimited agument pass karna cahate ho .
To eske solution ke liye varargs ka concept java me hai. jisse ap n
number of parameters pass ker sakte ho.
● Varargs syntax:- return_type method_name (data_type …variable_name)

● Jitney bhi parameters hote hai vo sabhi variable_name ke pass jate hai.

● Variable name internally array[ ] ke form me ban jata hai.

● Yadi hum pure parameters ko access karvana cahate hai to for each
loop lagana hoga.
● Varagrs ka ye roule hai ki yadi apko varargs ke sath parameter ka use
karna hai to pahle parameter likhege uske bad hi varargs likh sakte hai
like:- sum(int x,int…a)
Q ky hum more than one varargs parameter ka use kar sakte hai method
me.
Ans:- nhi ker sakte hai.only one varargs ka hi use ker sakte hai.
Q ky hum ek hi class me varargs parameter and array parameter pass ker
sakte hai?
Ans:- no nhi ker sakte hai.
Q ky varargs parameter ko overload ker sakte hai?
Ans:- ha hum ker sakte hai.

● Jis tarha ka parameter pass karege uss tarha ki method chalege varargs
vali.
● Varargs me calling time pr perameter pass karna jaruri hai.

Q ky hum normal parameter vali and varargs parameter vali method ko same
program me use kar sakte hai?
Ans:- ha bilkul bana sakte hai.

Q yadi varargs parameter ke jagha array pass ker diya like void sum(int [] a)
To ky chalega?
Ans:- bilkul bhi nhi de sakte hai kyo ki niche argument to method me normal
vala dete hai. yadi array type ka banaya to neache bhi calling time pr array
pass karna hoga.
Q yadi hum neache se array type ka argument pass ker rahe hai lekin method
me varargs ka use karte hai to ky yaha chalega?
Ans:- ji ha bilkul chalega.

● Yadi method me varargs pass kiya hai to vo sabhi type ka data recive
ker lega. Normal bhi or array type ka bhi. Like void show(int…a)
● But yadi method me array pass kiya hai to serf vaha array type ka hi
argument lega. Like void show(int [ ] a)
Q yadi hum varargs me 2d type ka array ko pass karna cahate hai to hum 2d
array ko kese pass karege?
Ans:- yadi 2d array hai to recive karne vala 1d type ka varargs hona cahiye.
Hum kis kis tarha se varargs ko pass ker saktge hai:-

● void sum(int …a)// it will work

● void sum(int… a)// it will work

● void sum(int…a)// it will work

● void sum(int … a)// it will work

● void sum(int . ..a)// error

● void sum(int a…)// error

● jaha jaha pr error hai vaha pr illegal error ayege.


● Hum public static void main(String ar[]) array ke braket ki jagha (…)bhi
pass ker sakte hai.
● Private method ko kabhi bhi override nhi ker sakte hai kyo ki method
overriding ka sabse basic roule ye hai ki inherit karna jaruri hai .but
private method ko kabhi override nhi kar sakte hai.
● Super class ka data access karne ke liye super keyword ka and
instance data ko access karne ke liye this keyword ka use karte hai.
-----------------------------------------------------------------------------------------------------------------

25:-final keyword.
● Ek tarha se final constant ki jagha use hota hai java me.

● Yadi final variable hai to uski value change nhi ho sakti hai.

● Yadi kise class ko final declare kiya to vo kabhi inherit nhi ho sakti hai.

Q yadi hum kise class ki property ko inherit hone se bachana cahate hai to
ky kare?
Ans:-usse final declare ker do.

● final method ko overload to ker sakte hai but override nhi ker sakte hai.

Q yadi interview me bola ki final keyword ko explain karo to?


Ans:- final keyword ko hum variable ke sath bhi method ke sath bhi and class
ke sath bhi use ker sakte hai.

● yadi final variable hai to uski value pure program me change nhi ho sakti
hai.kyo ki vo constant baan jata hai.
● yadi final method hai to vo override nhi ho sakti hai.

● yadi final class hai to usse extends nhi ker sakti hai.

● jo class final hai usse inherit nhi ker sakte but final class dusre class ko
inherit ker sakti hai.
● private data kabhi bhi class ke bahar access nhi ho sakta hai.

● inheritance reusability ko badhata hai sath hi uski super class me data


ko add ker sakte hai. Esliye hi arrow upper ki taraf hota hai .
● yadi hume kise bhi method ki definition pasand nhi aa rahi hai to change
karne ke liye inherit karna hoga.
● Static and instance variable ki default value 0 hoti hai.

● Default value compiler assign karta hai.

-----------------------------------------------------------------------------------------------------------------

26 :-blank final variable.


● Blank final variable ke case me default value blank hoti hai.taki hum
runtime pr value assign ker sake.
● Yadi blank final variable ki default value 0 rakh dete to vo useless hoti
kyo ki final variable ki value change nhi ker sakte hai.
● Blank final variable me value constructor and instance block se hi pass
ker sakte hai kyo ki ye runtime pr hi call hota hai.
● Yadi balnk final variable me constructor se value pass nhi ki to error
ayege
● Java me object runtime pr create hota hai.

● Object ke carrouseponding refrance variable esliye create karte hai taki


hum operaton perform karva sake.
● Jab super class ka refrance variable sub class ke object ko store karta
hai and dono class me same name static method and same parameter
hote hai to usse method hinding kahte hai.ese upcasting kahte hai
● Yadi child class ka refrance dete hai or parent ki memory dete hai to
error ate hai ese down casting hai but yadi hum ese jabber jasti object
type ki type casting ker ke karvate hai to run time pr class cast
exception ate hai.
● Java me up casting possible hai but down casting possible nhi hai.

● Hum hamre program ko version me change ker ke bhi run karva sakte
hai.command se.
Ex :- javac –source version_name class_name.java
Q Ky hum blank final variable me instance block ki value assign karva sakte
hai?
Ans:- ji ha karva sakte hai kyo ki instance block bhi constructor ki tarha
work karta hai , object ke creat hote hi call hota hai.
Q yadi humne instance block ki help se blank final variable ko value assign ker
de to ky constructor se bhi same program me ker sakte hai ky?
Ans:-nhi ker sakte hai.
Q hum static blank final variable me value kese assign ker sakte hai ky hum
constructor se assign ker sakte hai ky?
Ans:-nhi constructor se nhi ker sakte hume static block se hi karvana hoga.
-----------------------------------------------------------------------------------------------------------------

28:-MVC architecture.
MVC= Modle view controller.
Q what is MVC architiecture?
Ans:- yah kuch bhi nhi serf code ko organize tarike se likhne ka tarika hai ka
hai.yah ek program pattern hai jiske jariye ap code karte hai.
Q Why is it required?
Ans:-Jab koi project pr work chalta hai to us pr sab alag alag log kam karte hai
jese backhand, frontend, design. To yadi kise 1 bande ka work complete nhi
hoaa to baki ko rukhna padega.
To esse bachne ke liye hum ek tarike ka use
karte hai jise hum MVC architiecture kahte hai. esse hum code ko 3 part me
devide karte hai.
Modle:- yaha jo Database se releted jo functionality hai like fetch data , update
data etc. usse releted correction hum Modle me karege.
View:- View me hum design part karege. Jisse user intract karega to vo sab
View me ata hai.From CSS, HTML.
Controller:- yaha model or view ke beach me bridge ka kam karta hai.
Controller me hi hum business logic likhte hai.
Jese loop laga ker data ko
fatch ker ke dekhana hai to vo ek controller ka logic hai.
Ex:- hum calculater ka program banate hai. to kise ne input diya View se 2+3 to
eska answer ka logic jo likhte hai to vo ata hai controller me.
Real life Example:- restaurants ka Example dena hai.
Jo veter hai vo Controller hai. jo safe and user ke beach bridge ka kam
karta hai, safe jo hai Model hai, and user jo hai View hai.

● Controller chijo ko control karta hai.

● View jisse user intract karta hai usse kahte hai.


● Modle requested data ko manipulate karta hai.

-----------------------------------------------------------------------------------------------------------------

29:-Package.
Q what is package?
Ans:- A package arrage number of classes and interfaces and sub-package
of same type into single group is called package.

Understanding Java Access Modifiers


Let's understand the access modifiers in Java by a simple table.

Access within within outside package outside package


Modifier class package by subclass only

Private Yes No No No

Default Yes Yes No No

Protected Yes Yes Yes No

Public Yes Yes Yes Yes

● Yadi koi access modifier nhi hai to JVM usse default manta hai.
● Yadi hum chate hai ki data har jagha access ho to hume public declear
karna hoga.
● Jab bhi hum different folder me data access karna cahate hai to jis data
ko access karna hai vo public hona cahiye same package ke ander.
Q how to crate package?
Ans:- yadi hume java me package banana hai to package keyword se declear
karna hoga.

● Package and folder ka name same hota hai.

● jiske liye package ready kerna hai uske top pr package and folder_name
likhna hoga.
● Uske bad hume javac -d F:\packDemo\Demo.java likhna hoga CMD pr.

● javac -d disk_name:\Package_name\Class_name.java.

● jis class me package banana hai to us folder ka name same rahega jo


package ka name hoga.or class bhi usse folder me save hogi.
● Fer yadi uss package ko use karna chate hai dusre class me to package
ko import karna hoga us class me.to us package ki property use kar
payege hum.
● Hume jaha class ke data ko access karna hai vaha vaha pr package ko
import ker do.
● * ka mtlab serf class and interface ko access karne ki permission hoti
hai na ki file ko. Ex:- import java.manish1.*;
Qky ek drive(disk) ki class ka data dusre drive(disk) ki class me access ker
sakte hai?
Ans:- ha bilkul ker sakte hai bina package use kare.

● Yadi hum ek drive ka data dusre drive me access karna cahate hai to
hume class path set karna hoga
● Jiska data hume access karna hai uska path pahle ayega.

● Path set on CMD:-

set classpath=drive_name:\floder_name;.;%classpath%
now compile and run program.

● Package and folder ka name same hona cahiye.


● Hum serf .class file se program ko run ker sakte hai. kyo ki program ko
run karne ke liye serf .class file ki jarurat hoti hai.
● .java serf compiler ko cahiye hoti hai.

● Yadi hum cahate hai kise program me compile karne pr vaha automatic
folder ke ander .class file junrate ho jana cahiye.to usme CMD pr
command likhna hoga Ex:- packDemo name ke folder me Demo.java
rakha hai to:-
Command:- javac –d . A . java
-d ka mtlab subdirectry.
To ab yaha kuch asa banega:- F:\packDemo>javac –d . A .java. –d ke
baad and A ke pahle 1 – 1 space ayega.
● Yadi hum javac –d . A .java se compile karte hai to java1 and io folder
packDemo name ke folder me hi ban jayega.
But yadi hum dusre Drive
me bana cahate hai Ex:- ram name ke folder me to.
Tab hume javac –d D:\ram A.java likhna pdega.
● Hum path ko 2 tarha se set ker sakte hai.
1:- Temparary path:- CMD se.
2:- permanent path:- Envirement variable se.
-----------------------------------------------------------------------------------------------------------------

30:-Abstract class and method.


C++:- Pure virtual is called abstraction .

● Jis class me ek bhi pure virtual function ho usse abstract class kahte
hai.
● Bina body vale function ko pure virtual function kahte hai.
Ex:- void sum();
● Pure virtual function ko virtual keyword se declare karte hai.
Ex:- virtual void sum();
● Pure virtual function ko 0 se inisialize karna compalsary hai.
Ex:- vritual void sum()=0;
● Hum kabhi bhi abstract class ka object nhi bana sakte hai.

● sub class me super class ke sabhi pure virtual function ko declare karna
jaruri hota hai. yadi asa nhi kiya to sub class by default abstract class
ban jate hai.
● Abstract class ke data ko access karne ke liye class ko inherit karna
comperlary hota hai colon(:) se C++ me.
Java abstract class:-

● Jab hume koi bhi chij mendatory hai ki vo karvana hi hai but uske alava
apke pass koi or choice bhi hai ki ap caho to kuch or add ker sakte ho to
abstract class ka use karte hai. varna interface ka.
● Java me abstract class ko abstract keyword se declare karte hai.

● Hum kabhi bhi abstract class ka object creat nhi ker sakte hai.

● Abstract class ke data ko access karne ke liye abstract class ko inherit


karna compalsary hota hai.
● Abstract class ke data ko sub class ke object se access karte hai.

Java abstract method:-

● Bina body vali method ko abstract method kahte hai.

● Abstract method ko abstract keyword se declare kar sakte hai.

● Jis class me ek bhi abstract method ho to usse abstract declare karna


compulsory hai.
● Sub class me super class ki sabhi all abstract method ki body ko define
karna comaplsary hai. yadi asa nhi karte hai. to sub class ko abstract
declare karna hoga.
● Abstract class me abstract and non abstract dono type ki method ho
sakte hai.
Q ky hum main() method vali class ko hum abstract bana sakte hai ya nhi
bana sakte hai ?
Ans:- ha hum bana sakte hai.esliye ker sakte hai kyo ki main() method
static hoti hai and main() method ko JVM class name se access karta hai. to
object creat hi nhi hota hai.
Q ky abstract class ke ander static method ho sakti hai?
Ans:- ha ho sakti hai.
Q ky hum final method inherit hoti hai?
Ans:- ha ho sakte hai. But final class nhi ho sakte hai.
Q ky final method ko override ker sakte hai?
Ans:- nhi final method ko nhi ker sakte hai. non final method ko ker sakte
hai.

-----------------------------------------------------------------------------------------------------------------

31:-Interface.
Q what is interface?
Ans:- The interface in Java is a mechanism to achieve pure abstraction . There
can be only abstract methods in the Java interface.
Yaha pr java version 1.7 ke hisab se discuss hoga.

● Jab hume koi bhi chij medatory hai ki vo karvana hi hai uske alava koi
opetion nhi hai to hum pure abstraction means interface ka use karte
hai.
● Interface ko interface keyword se declare karte hai.

● Abstract class me abstract and non-abstract me method bana ker ready


ker sakti hai.but interface me serf abstract method hi ho sakti hai.
● Interface ke ander variable bhi use kar sakte hai. kyo ki interface me
variable by default public static final hota hai.
● Interface ka object creat nhi ker sakte hai.

● Interface ke data ko access karne ke liye interface ko implements karna


compalsary hai.
● Sub class me interface ki sabhi abstract method ki body define karna
compalsary hai.yadi asa nhi karte hai to subclass ko abstract bana na
padega.
● Interface ki abstract method ko sub class me public area me hi declare
karna hota hai.
● Interface ki jitney bhi method hoti hai uske sath java compiler by default
2 keyword add ker deta hai 1:- public 2:-abstract.
● Kis kis tarha se interface me method ko declare ker sakte hai.
1:- public abstract void show();
2:-public void show();
3:-abstract void show();
4:- void show();
● Kyo ki interface ke ander ki sare method by default public abstract hoti
hai. to yadi humne declare nhi kiya hai public abstract to compiler add
ker deta hai.
● Class interface ko implements ker sakti hai but interface class ko nhi.

● Interface interface ko extends karta hai. implements nhi karta hai.

Q ky hum java me multipal inheritance use ker sakte hai?


Ans:- class ke base pr multipal inheritance possible nhi hai but interface ke
through possible hai.
Q ky hum one interface se multipal interface ko extends keyword se extend kar
sakte hai?
Ans:- ha ji bilkul ker sakte hai.
Q ky interface ke ander constant , static hote hai?
Ans:- ha sir hote hai.

Q ky interface ke ander instance variable bana sakte hai?


Ans:- nhi bana sakte hai. kyo ki by default public static final maan leta hai.
Q ky interface ki method ko private bana sakte hai?
Ans:- nhi bana sakte hai.
Q ky interface ke variable ki value ko update ker sakte hai?
Ans:- ji bilkul nhi ker sakte hai.

Weaker access privilege error.

● Method override me bhi yadi super class ki method ko public declare


kiya hai to vah override nhi hogi error dega.
● Private -> default -> protected -> public . eska ulta kabhi work nhi
karega.yahi method overriding ka roule hai weaker access privilege me.
-----------------------------------------------------------------------------------------------------------------
32:-IO in java.
System.out full form:- Standard Output Device Screen
System.in full form:- Standard Input Device keybord.
IO=> I=Input , O=Output.

● Eska use karne ke liye sabse pahle io package ko import karna padta hai
Ex:- import java.io.*;
● System.in se ISR and BR classes hai

● ISR:- Input Stream Reader.

● ISR ke pass data ko variable me store karne ke functionality nhi hai


esliye hum eek or class ka use karna padhta hai.jiska name BR hai
● BR:- Buffred Reader.

● BR class ke passs ek method hai jiska name read() method hai jisse 1
character ko read kerti hai.
● read() method ka return type int hai.

● jis tarha se C me kise predefine chij ko use karne ke liye Hadder file ko
include karna padta hai vese hi java me package ko import karte hai.
● ISR ke object ke constructor me System.in pass karna padhta hai.

● ISR ka object bana ker uska refrance BR ke object ke constructor me


pass karna padta hai.
● Input output opreraton ki sare classes io package se belong karte hai.

● Stream 3 type ki hoti hai 1:-System.in 2:- System.out 3:- System.err

● read() method serf int ko hi hold kar sakti hai kyoki iska return type int
hota hai.yadi hum dusre data type ko store karvana cahate hai to
type_ casting karna hoga.
● Yadi read() method me more then one character ko pass kiya to vo bas
first character ko hi hold karega.
● Java me by default java.lang package import hota hai.esliye jab hum
String , System classes ka use karte hai to hume package import nhi
karna padhta hai. kyo ki ye classes lang package se belong karti hai.
● Pure String ko read karne ke liye readLine() method ka use karna hota
hai.ye bhi io package se belong karte hai but esme exception ate hai to
usse throw karvana padta hai .
● StringTokenizer class ki help se value ko seprate ker sakte hai.

● Yadi humare pass 2 hi tokan hai or hum usse jiyada number ko space se
seprate karte hai to vah serf starting ke hi number lega. But hum 2 se
kam element dete hai runtime pr NoSuchElement Exception ate hai.
● Stringtokenizer class java.util package se blong karti hai

● Yadi hum { , } se ya kise bhi character se splite karna cahate hai to


StringTokenizer ke object ke constructor me usko pass karna hoga
double code { “ ” } me.
● Yadi ek number and dusra string dala to NumberFormate exception ate
hai
● hum jitney nextToken method ka use karte hai to countToken method
utne token ko count nhi karte hai.
● countToken method banati hai ki kitne number of token bache hai.

● haseMoreTokens ka return type true ya false hota hai.yadi tokens


bachege to true return karega yadi nhi bachege to false return karega.
● Enter key ke press karne pr keyboard pr \r junrate hota hai.

● read() method 1 character lene ke bad enter press pr \r and \n leti hai.

● Scanner class me Automatic data space se splet ho jayega.

● Scanner class ka return type int hota hai.

● nextInt() method ka return type int hota hai.ase hi sabhi data type ke liye
hoga like nextByte … etc.
● yadi nextInt me 1 int and 1 String diya to inputMissMatch exception
ayge.

IO interview Questions:-

● palindrom program using IO.

● Prime number program using IO.

● Perfect number program using IO.

● Power of number program using IO.

● Sum of N number program using IO.

-----------------------------------------------------------------------------------------------------------------
33:-GUI (AWT).

GUI full form:- graphical User Interface.

● User ko graphic ke through interface provide karvana hi GUI kahlata


hai.
● AWT full form:- Abstract Window Toolkit.

● Java me AWT ne hume bahot sare interface and classes provide ki hai
jiski help se hum graphics ki coding ker sakte hai.
● esme me Button ko component kahte hai and border ko frame kahte hai.

● 1 file me hum kitni bhi class bana sakte hai.

● Subclasses:- Object->Componant->Container->Window->Frame->Swing.

● Jab hume Frame banana hai to Frame class ko extends karna padta hai.

● Frame class java.awt.Frame package me rakhi hai.

● Frame ki width and hight bydefault pixle me chalet hai.

● Program java me usse class se run hota hai jis class me main() method
hogi.
● Frame by default invisible hoti hai.ese visible karne ke liye setVisible()
method ko true karna hota hai.
● Frame ka size by default 0 hota hai eska size increase karna hai to
setSize(width,hight) method ka use karna hoga.
● Frame by default upperLeft corner me hoti hai yadi hum uske location
change karna cahate hai to setLocation(lower,upper)method ka use
karna hoga.
● Frame ne hum ek method provide ki hai jiska name hai paint().

● Jis type se main() method String Type ka parameter pass karna jaruri hai
vese hi paint() method me Graphics class ko pass karna jaruri hai.
Ex:- public void paint(Graphics g)
● Jese jab hum constructor bana ker object banate hai to constructor
automatic call ho jata hai. Vese hi Frame load hote hi paint() method call
ho jati hai.
● Graphics class java.awt.Graphics package se ati hai.

● Graphics class ne hume ek method provide ki hai jiska name


drawString(String_name,x axis , y axis) hai. yaha Graphics class ke
object se call hogi , esse hum Frame ke ander koi bhi msg print karva
sakte hai.
● Color bhi ek class hai jo ki color ko set karne ke liye use karte hai.and ye
awt package se ati hai.
● Background Color set karne ke liye setBackground(Color.color_name)
method ka use karege.
● Java me method ka first word hamesa small hota hai and next word
capital hota hai.
● Frame banne ke bad close nhi hoti hai yadi hum close karna chate hai to
CMD pr Ctrl+c press karna hoga.
● Ye sabhi method paint method me ayege:-

● dreawLine(x1,y1,x2,y2) method ke pass 4 argument hote hai.yaha line


draw karane ke kam ati hai.
● drawRect(x,y,width,hight) yaha rectangle banana ke kam ate hai.

● drawRoundRect(x,y,w,h,xr,yr) yaha round courve vala rectangle banana


ke kam ati hai.
● drawOval(x,y,w,h) yaha circle banana ke kam ati hai.esse elips bhi bana
sakte hai hight kam ker ke.
● Yadi arc katna hai to drawArc(x,y,w,h,starting_angle,Moving_angle)

● Starting angle se hume totle jitna angle ko move karvana hai utna
moving angle me likhna hoga.
● drawPolygon(x[ ],y[ ],n) esse hum kise bhi tarha ka shape bana sakte
hai.
● yadi sabhi method ke agge fill laga diya to jo shapes hoge vo filled hoge
usme hum color bhi bhar sakte hai.
● by default font ka color black hota hai. and Frame ka color white hota
hai.
● sabhi color 3 color se mil ker bane hote hai RGB:-Red, Green, blue.

● Hum jo color dalege usse neache valo ka sabka color vhi set ho jayega.
● Yadi hume color ko apne hisab se set karna hai to Color class ka object
banana hoga.Ex:-Color c=new Color(c1,c2,c3);
● Font ka size increase karne ke liye font class ka object banana hota hai.
Ex:- Font f=new Font(“name of font”,font_type,size);
f.setFont()

● Math class Funtions:-


1:- Math.max(n1,n2);
2:- Math.min(n1,n2);
3:- Math.pow(n1,n2);
4:- Math.sqrt(n1);
5:- Math.cbrt(n1);
6:- Math.sin(n1);
7:- Math.cos(n1);
8:- Math.tan(n1);
● Math.random():- yaha method har bar 0 se 1 ke beach me number
junrate karati hai.
● Color ki range 0 se 255 hoti hai esse jiyada nhi ho sakti hai.

● random() method ka return type long hota hai.

● Math class java.lang package se belong karte hai.

AWT Componant:- Lable,Button,List,Choice,Checkbox,TextComponant(1:-


TextField 2:- TextArea)

● Kise bhi chij ko different – different tarike se represent karna hi layout


kahlata hai.
● Frame ke ander by default boarderLayout maneger hota hai.

● FlowLayout jitna bada msg hota hai Button ko utna bada la ker print
karvata hai. yadi FlowLayout ko add karna hai to eska object banana
hoga.Ex:- FlowLayout f=new FlowLayout();
setLayout(f1);

● Button ko use karne ke liye Button class ka object banana padega.


Ex:-Button b=new Button(“click”);
add(b);
● Yadi add() method ka use nhi kiya to frame me add nhi hoga.

● TextField ka mtlab input field .


● Jis order me hum component ko program me rakhte hai vo usse order
Frame me show hote hai.
● Bydefault flowLayout content ko 1 hi line me show karta hai yadi frame
end ho jati hai to hi vo next line me jata hai.
● Yadi hum apne hisab se componants ko set karna chate hai to
setLayout(null) karna hoga.
● Yadi hume frame ki border pr kuch likhna hai top pr to
setTitle(“Anything”); ka use karna hoga.
● Lable ka use TextField ke pahle kuch msg show karane ke liye karte hai.
Ex:- Lable la=new Lable(“Enter name”);
add(la);
-----------------------------------------------------------------------------------------------------------------

34:-Event handling (EDM).


EDM:- Event Deligation Modle
● Yadi hum button ke Click pr koi event perform karana chate hai to hume
Listener ko add karna hoga.
● Listener ke pass bahot sare methods hoti hai.

● Jab hum Button pr click karte hai or yadi listener laga hai to listener ki
method call hoti hai or us method ke ander ka code execute hota hai.
● Listener ko use karne ke liye hume 3 steps karne hoti hai.
1:- Listener ko sabse pahle implements karna hota hai.
2:-Componant me Listener ko add karna hota hai add(this) method se.
3:-Listener ki sare methods ko override karna hota hai
actionPreformed() method me.
● Jis jis component me click pr koi operaton perform karvana hai to usme
Listener ko add karna hoga.
● Jese alag alag type ki value ke liye alag data type hote hai vese hi alag
component ke liye alag alag Listener hota hai.
● Ex: Button class me ActionListener name ke Listener ka use karte
hai .or eske pass actionPerformed(ActionEvent e) name ki method hoti
hai
● ActionListener interface java.awt.event.* name ke package me rakha hai.
● Yadi ActionListener ki method ko override nhi kiya to error ayege.

● TextField se data get karne ke liye method hai getText().

● TextField se data set karne ke liye method hai setText().

● Hum jese bhi click karte hai uska refrance ActionEvent ke refrance
variable ke pass jata hai.if condition me e.getSource( ) method ko
compare karne ke liye likhte hai.
● List ka use data ko 1 list ke form me Frame pr show karane ke liye karte
hai.
● Choice ka use bhi bahot sare deta ko store karne liye karte hai but yaha
dropedown hota hai.
● Checkbox ka use kise chij ko select ker ke right ka mark ke liye karte
hai.by default ye deselect hota hai.
● Checkbox me hum dono ko select ker sakte hai but yadi hum cahate hai
ki kies 1 ko hi select hona cahiye to hume RadioButton ka use karna
hoga.
● AWT ke pass RadioButton name ke koi class nhi hai. but AWT me
CheckboxGroup class ki help se hum RadioButton bana sakte hai.
● RedioButton se hum kise ek ko hi select ker sakte hai.

● Yadi hum cahate hai ki alag category ki RadioButton banaye to hume


utne CheckboxGroup globle declare karna hoga.
● getState() method jab Checkbox true hota hai to true return karti hai.

● TextField me line change nhi hoti hai but TextArea me ho jati hai.

● List ka main use more than one Item ko select karne ki permission dena
hai.
● Yadi list se 1 item ko select karna hai to method hai getSelectedItem().
But yadi more than one one Item ko select karna hai to getSelectedItem()
method ka use karte hai.
● Yadi frame ko close karna hai to Ctrl+c se to ho hi jayege but yadi hum
cahate hai ki cross ke button se direct cut ho jaye to hume program me
kuch code likhna hoga.
Ex:-f.addWindowListener(new WindowAdapter(){
public void windowClosing(WindowEvent e){
System.exit(0);
} })
Q :- India flage.
Tiktack game.
Snackgame.
Snack and ladder game.
calculater

-----------------------------------------------------------------------------------------------------------------

35:-Swing
● AWT swing ka advanced version hai.

● Diffrence between AWT and Swing:-


1:-AWT platform dependent hai .But Swing platform independent hai.
2:-AWT ke liye Frame class ko extends karna padhta hai .But swing me
JFrame ko extends karna hota hai
3:- AWT java.awt package se ata hai. But swing javax.swing package se
ata hai.
4:-Awt ke pass koi method nhi hai Frame ko close karne ke liye esliye
Listener ka use karte hai. But Swing ke pass hai Ex:-
setDefaultCloseOperation(EXIT_ON_CLOSE)
5:-AWT ke pass swing se kam componant hai. But Swing ke pass jada
hai.
6:-AWT ke pass havy weight componant hai. But swing ke pass less
weight hai.
7:-AWT slow work karta hai. But Swing fast work karta hai.
8:-AWT me jiyda memory lagti hai. But swing me less memory lagti hai.
9:- AWT MVC architecture ko follow nhi karta hai. But Swing karta hai.
10:- AWT ka look and feel jiyada accha nhi hota hai swing ke compeard
me. But swing ka hota hai AWT ke compare me.

Q ager java platform indepandant hai to fer AWT paltform dependant kyo hai?

Ans:- kyo ki AWT me bana software ka look different different hota hai alag
alag operating System pr esliye AWT platform dependant hai , But Swing ka
hum different bhi dekha sakte hai and same bhi dekha saktehai.

● Sub classes:-Object->Componant->Container->Window->Frame>JFrame

● Swing me bina kise class ya method ke Frame hat to jate hai but by
default vaha open hi rahte hai.
● Swing me bydefault border layout chalta hai.
● Swing ke pass flowLayout method nhi hai.

● Swing me passwordField bana sakte hai.


Ex:- JPasswordField tp= new JpasswordField(*);
add(tp);
● Swing me sabhi chije jiyada same hi hai bas unke agge J lagana hota hai
like JButton, JFrame , JTextField ,JLable … etc
● Yadi hum cahate hai ki humari Frame Maximize na ho to
setResizable(false) ker do.
● Yadi hum cahate hai ki kuch bhi press kare to passwordField me ? aa
jaye.
To hume EchoChar() ka use karna hoga.hum jo eske ()me pass
karege vo aa jayega.
● AWT ke pass RadioButton nhi hai. But Swing ke pass RadioButton hai.

● AWT me jise Choice kahte hai usse Swing me ComboBox kahte hai.

● Yadi hum cahate hai ki 1 bar me list me 3 hi element show baki scrool
me cahli jaye to setVisibleRowCount(3); dena hoga.
● Yadi hum cahate hai ki buton ke click pr CMD pr koi msg aa ker print ho
jaye to hume ActionListener me S.o.pln(“ ”); karvan hoga.
● Yadi hume 2 TextField ke data ko add karva ker 3rd me print karvana hai
to parseInt method se convert kar ker variable me add ker lo and usko
3rd TextField ke object se setText(variable_name); karva do.
● Yadi hume value ko right , left , up ,down se printing cahate hai to hume
1 method ka use karna hoga.
Ex:-setHorizontalAlignment(JTextField.anychoice(right , left , up ,down))
● Yadi hum 1 digit peache se delet karna cahate hai to ek method hai
subString :-
Ex:- setText(s1.substring(0,s1.length( )-1));
● Yadi hume squre nikalna hai to Math.sqrt() method ka use karna hoga.

● Yadi hum cahate hai ki jo jo numbre ko enter kare to unka sum ana
cahiye to hume 2 class ka use karna hoga .eske liye pahle javax.script;
package ko import karna hoga.
1:-ScriptEngineManager sm= new ScriptEngineManager();
2:-ScriptEngine se=sm.getEngineByName(“js”); eske pass ek method
hoti hai eval(). Ex:-tx1.setText(“ ”+se.eval(s1));ese try block me likege.
2nd vali ke use pr exception ate hai to usse throws karana padega.
● getSelect() method ka return type object hota hai.

● yadi hum cahate hai ki List me jitney bhi item dale hai aa ker disply ho
jaye to ek method hai getSeletedValues( ); eska return type array type ka
object hota hai.
● Humne total :-
flowLayout,greadLayout,boarderLayout,cardLayout.flowLayout(null)

PalceHolder:- placeHolder mtlab jo background me light color me dekhta


hai login form me or kuch type karne pr vo hat jata hai.

● KeyListener ke pass totle 3 method hoti hai .


1:- keyRelesed(keyEvent e)
2:-keyPressed(keyEvent e)
3:-keyTyped(keyEvent e) en method ka use 1 bar place holder ko hatne
ke bad vapas dekhane ke liye kiya jata hai.
● Trim() method first and last space ko remove ker deta hai.

● 1 Componant se dusre componant ke beach 5 pixcle ka horizontal gape


and 5 pixle vertical gape hota hai.
● FlowLayout componant ko center se print karvane ka kam karta hai.

● Panel , JPanel , Applet , JApplet class me by default FlowLayout hota


hai.
● BorderLayout ki help se componant ko kise bhi direction me set kar
sakte hai.
● Ek Frame me dusre Frame ja ker add nhi ho sakte yadi karte hai to
Exception ate hai. illigalArgument
● Swing me hum paint() method ka use nhi ker sakte hai.kyo ki ye
internally esme use ki gai hai. But yadi hum karna cahate hai to hume 1
method de gai hai paintComponant(Graphics g). But ese hum JPanal
class ke ander hi use kar sakte hai.
● Yadi hum image ko Frame me show karvana cahate hai to. Sabse pahle
Image File me save honi cahiye.fer hum Image class ka object bana ker
use kar sakte hai.
-----------------------------------------------------------------------------------------------------------------

36:-Applet.
Websites 2 types ki hoti hai:-
1:- static 2:- dynamic.
Static:- ase websites jisse user intract na ker sakte mtlab koi change na ker
sakte un websites ko static websites kahte hai. Ex:- javatpoint, w3Schools...
Dynamic:- ase websites jisse user intract ker sake unko dynamic websites
kahte hai. Ex:- Facebook , gmail , registration form.
Html ,Css yaha static websites language hai.
Q what is applet?
Ans:- Java dynamic website language hai and html and CSS ko java ke sath
use ker ke dynamic bana sakte hai and java me html and CSS ko java ke
sath murge karne ke liye tool diya hai use Applet kahte hai.

● Ese feature ke karan java ko hot java bhi kahte hai.

● Jese frame banana ke liye inherit karte hai Frame class ko vese hi applet
banana ke liye Applet class ko inherit karna hota hai.
● Yaha import java.applet .Applet; package se belong karte hai.

● Applet ke pass kabhi bhi main() method nhi ho sakte hai.esliye applet ke
program ko run karvane ka kam browser me install plugin karvata ya fer
applet viewer karta hai.
● Sabse pahle applet ki .java file bana ker ready karna hai.

● Jese normal file ko compile karte hai vese hi compile ker ke .class bana
lo.
● Applet case sensitive nhi hota hai. upper lower dono case chalet hai.

● Applet ko testing ke perpuse se use karte hai.

● Sabse pahle hume html page bana ker ready karna hai.

● Hum applet ko single page me likh sakte hai pr applet ke code ko


comment me likhna padega . */ */
● Applet mai jab kuch same as AWT jes hi hota hai.

Applet ki life cycle ne hume 4 methods provide ki hai.


1:- public void inti( );
2:- public void start( );
3:- public void stop( );
4:- public void dstroy( );
● Jab jab start method chalege paint method call hogi.

● Maximize karne pr start method call hogi.

● Destroy method ke pahle stop method call hoti hai.

-----------------------------------------------------------------------------------------------------------------

Changes accoding to versions

● Finally 23 January 1996 ko java ka jdk version 1.0 launch hoaa.

● Variable ka name spaceial symbol se start nhi ker sakte hai, Only $ and _ ka
use kar sakte hai. java 8 version se.
● program run command in different version:-
javac –source version_name class_name.java
● version 1.7 se java ne switch case me String ko use karne ki permission
di hai usse pahle nhi thi .version 1.7 me serf warning deta hai.
● For each loop ka concept java 1.5 version se aya hai.usse pahle nhi tha.

● Integer me _ ko use karne ki permission java version 1.7 se de hai use


pahle nhi thi.
● Q version number 1.5 ka koi new feature batao?

● Ans:- static import and for each loop.

● Hum hamre program ko version me change ker ke bhi run karva sakte
hai.command se.
Ex :- javac –source version_name class_name.java

You might also like