Core Java
Core Java
1:-History of java.
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.
11:-Control statement. If, if else , nested if , else if , else if ladle , switch case.
12:-Loops.
19:-Constructor.
20:-Inheritance.
21:-Exception handling.
22:-Static keyword.
23:-Polymorphism.
25:-final keyword.
28:-MVC architecture.
29:-Package.
32:-IO in java.
33:-GUI (AWT).
35:-Swing.
36:-Applet.
*************************************End*********************************
● 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.
-----------------------------------------------------------------------------------------------------------------
● 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.
-----------------------------------------------------------------------------------------------------------------
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 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
-----------------------------------------------------------------------------------------------------------------
6:-Data type and it’s range and size full form of unicode.
● Java me range se bahar jane pr by default int hi manta hai. int ke case tak.
-----------------------------------------------------------------------------------------------------------------
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.
● 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.
● 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
● Eske sath by default compiler implicit type casting ker deta hai.
● We can use like ++x+++x but we can not use like x+++++x yadi asa karte
hai to error ayega Lvalue required.
● ^ Esme same same false and different different ture hota hai.
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.
● 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)
● 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.
● 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.
● 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.
● 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.
-----------------------------------------------------------------------------------------------------------------
* 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
double -> float -> long -> int -> char -> short -> byte
Weapper class:-
-----------------------------------------------------------------------------------------------------------------
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:
48 keywords
2 keywords
3 -> Literals
● 8 data type
● Other 10 keyword.
-----------------------------------------------------------------------------------------------------------------
11:-Control statement.
Q what is control statements?
● 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:-
● 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.
● 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
-----------------------------------------------------------------------------------------------------------------
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
● 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.
-----------------------------------------------------------------------------------------------------------------
● 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.
-----------------------------------------------------------------------------------------------------------------
● 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.
● Yadi data ko metrix ke form me print karvana hai to 2d array ka use karte
hai.
● 2 array declaration :-
● 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.
-----------------------------------------------------------------------------------------------------------------
● 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.
-----------------------------------------------------------------------------------------------------------------
● 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.
● String s2=”Manish”;
● Jaha bhi constructor ki bat ate hai it is use for initialize the object.
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.
Multilevel inheritance.
Hierarchical inheritance.
multipal inheritance java me nhi hai eske palce pr interface diya 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.
● 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.
● 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.
● 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.
● 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.
● 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.
● 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.
Stack trace.
● Stack trace ka means kis kis method se exception ho ker aai 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.
● 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.
static block
● 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.
● 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:-
● 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.*;
● 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.
● 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.
Inheritance.
Same method name
Same parameter list.
● 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.
-----------------------------------------------------------------------------------------------------------------
● 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.
● 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:-
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.
● 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.
-----------------------------------------------------------------------------------------------------------------
● 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.
-----------------------------------------------------------------------------------------------------------------
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.
Private Yes No No No
● 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.
● 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.
● 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.
set classpath=drive_name:\floder_name;.;%classpath%
now compile and run program.
● 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.
-----------------------------------------------------------------------------------------------------------------
● 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.
-----------------------------------------------------------------------------------------------------------------
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.
● 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
● 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.
● 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
● read() method 1 character lene ke bad enter press pr \r and \n leti 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:-
-----------------------------------------------------------------------------------------------------------------
33:-GUI (AWT).
● 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.
● Subclasses:- Object->Componant->Container->Window->Frame->Swing.
● Jab hume Frame banana hai to Frame class ko extends karna padta 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.
● 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()
● 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);
● 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.
● 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.
● 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.
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.
● 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)
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.
● 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.
● Sabse pahle hume html page bana ker ready karna hai.
-----------------------------------------------------------------------------------------------------------------
● 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.
● Hum hamre program ko version me change ker ke bhi run karva sakte
hai.command se.
Ex :- javac –source version_name class_name.java