Sunteți pe pagina 1din 25

Interview Questions in Core Java

1.what is a transient variable?


A transient variable is a variable that may not be serialized.
2.which containers use a border Layout as their default layout?
The window, Frame and Dialog classes use a border layout as their default layout.
3.Why do threads block on I!?
Threads block on i/o (that is enters the waiting state so that other threads may e!ecute while the i/o
"#eration is #erformed.
". #ow are !bserver and !bservable used?
"b$ects that subclass the "bservable class maintain a list of observers. %hen an "bservable ob$ect is
u#dated it invokes the u#date( method of each of its observers to notify the observers that it has changed
state. The "bserver interface is im#lemented by ob$ects that observe "bservable ob$ects.
$. What is synchroni%ation and why is it i&'ortant?
%ith res#ect to multithreading, synchronization is the ca#ability to control the access of multi#le threads to
shared resources. %ithout synchronization, it is #ossible for one thread to modify a shared ob$ect while
another thread is in the #rocess of using or u#dating that ob$ect&s value. This often leads to significant
errors.
(. Can a lock be ac)uired on a class?
'es, a lock can be ac(uired on a class. This lock is ac(uired on the class&s )lass ob$ect.
*. What+s new with the sto',-. sus'end,- and resu&e,- &ethods in J/0 1.2?
The sto#(, sus#end( and resume( methods have been de#recated in *D+ ,.-.
1. Is null a keyword?
The null value is not a keyword.
2. What is the 'referred si%e of a co&'onent?
The #referred size of a com#onent is the minimum com#onent size that will allow the com#onent to dis#lay
normally.
13. What &ethod is used to s'ecify a container+s layout?
The set.ayout( method is used to s#ecify a container&s layout.
11. Which containers use a 4lowLayout as their default layout?
The /anel and A##let classes use the Flow.ayout as their default layout.
12. What state does a thread enter when it ter&inates its 'rocessin5?
%hen a thread terminates its #rocessing, it enters the dead state.
13. What is the Collections 67I?
The )ollections A/0 is a set of classes and interfaces that su##ort o#erations on collections of ob$ects.
1". Which characters &ay be used as the second character of an identifier. but not as the first
character of an identifier?
The digits 1 through 2 may not be used as the first character of an identifier but they may be used after the
first character of an identifier.
1$. What is the List interface?
The .ist interface #rovides su##ort for ordered collections of ob$ects.
1(. #ow does Java handle inte5er overflows and underflows?
0t uses those low order bytes of the result that can fit into the size of the ty#e allowed by the o#eration.
1*. What is the 8ector class?
The 3ector class #rovides the ca#ability to im#lement a growable array of ob$ects
11. What &odifiers &ay be used with an inner class that is a &e&ber of an outer class?
A (non4local inner class may be declared as #ublic, #rotected, #rivate, static, final, or abstract.
12. What is an Iterator interface?
The 0terator interface is used to ste# through the elements of a )ollection.
23. What is the difference between the 99 and 999 o'erators?
The 55 o#erator carries the sign bit when shifting right. The 555 zero4fills bits that have been shifted out.
21. Which &ethod of the Co&'onent class is used to set the 'osition and si%e of a co&'onent?
set6ounds(
22. #ow &any bits are used to re'resent :nicode. 6;CII. :<4=1(. and :<4=1 characters?
7nicode re(uires ,8 bits and A9)00 re(uire : bits. Although the A9)00 character set uses only : bits, it is
usually re#resented as ; bits. 7TF4; re#resents characters using ;, ,8, and ,; bit #atterns. 7TF4,8 uses ,84
bit and larger bit #atterns.
23What is the difference between yieldin5 and slee'in5?
%hen a task invokes its yield( method, it returns to the ready state. %hen a task invokes its slee#(
method, it returns to the waiting state.
2". Which >ava.util classes and interfaces su''ort event handlin5?
The <vent"b$ect class and the <vent.istener interface su##ort event #rocessing.
2$. Is si%eof a keyword?
The sizeof o#erator is not a keyword.
2(. What are wra''ed classes?
%ra##ed classes are classes that allow #rimitive ty#es to be accessed as ob$ects.
2*. /oes 5arba5e collection 5uarantee that a 'ro5ra& will not run out of &e&ory?
=arbage collection does not guarantee that a #rogram will not run out of memory. 0t is #ossible for
#rograms to use u# memory resources faster than they are garbage collected. 0t is also #ossible for
#rograms to create ob$ects that are not sub$ect to garbage collection
21. What restrictions are 'laced on the location of a 'acka5e state&ent within a source code file?
A #ackage statement must a##ear as the first line in a source code file (e!cluding blank lines and
comments.
22. Can an ob>ect+s finali%e,- &ethod be invoked while it is reachable?
An ob$ect&s finalize( method cannot be invoked by the garbage collector while the ob$ect is still reachable.
>owever, an ob$ect&s finalize( method may be invoked by other ob$ects.
33. What is the i&&ediate su'erclass of the 6''let class?
/anel
31. What is the difference between 'ree&'tive schedulin5 and ti&e slicin5?
7nder #reem#tive scheduling, the highest #riority task e!ecutes until it enters the waiting or dead states or
a higher #riority task comes into e!istence. 7nder time slicing, a task e!ecutes for a #redefined slice of
time and then reenters the #ool of ready tasks. The scheduler then determines which task should e!ecute
ne!t, based on #riority and other factors.
32. ?a&e three Co&'onent subclasses that su''ort 'aintin5.
The )anvas, Frame, /anel, and A##let classes su##ort #ainting.
33. What value does readLine,- return when it has reached the end of a file?
The read.ine( method returns null when it has reached the end of a file.
3". What is the i&&ediate su'erclass of the /ialo5 class?
%indow
3$. What is cli''in5?
)li##ing is the #rocess of confining #aint o#erations to a limited area or sha#e.
3(. What is a native &ethod?
A native method is a method that is im#lemented in a language other than *ava.
3*. Can a for state&ent loo' indefinitely?
'es, a for statement can loo# indefinitely. For e!am#le, consider the following?
for(@@ @
31. What are order of 'recedence and associativity. and how are they used?
"rder of #recedence determines the order in which o#erators are evaluated in e!#ressions. Associatity
determines whether an e!#ression is evaluated left4to4right or right4to4left
32. When a thread blocks on I!. what state does it enter?
A thread enters the waiting state when it blocks on 0/".
"3. <o what value is a variable of the ;trin5 ty'e auto&atically initiali%ed?
The default value of an 9tring ty#e is null.
"1. What is the catch or declare rule for &ethod declarations?
0f a checked e!ce#tion may be thrown within the body of a method, the method must either catch the
e!ce#tion or declare it in its throws clause.
"2. What is the difference between a @enuIte& and a CheckboA@enuIte&?
The )heckbo!Aenu0tem class e!tends the Aenu0tem class to su##ort a menu item that may be checked or
unchecked.
"3. What is a task+s 'riority and how is it used in schedulin5?
A task&s #riority is an integer value that identifies the relative order in which it should be e!ecuted with
res#ect to other tasks. The scheduler attem#ts to schedule higher #riority tasks before lower #riority tasks.
"". What class is the to' of the 6W< event hierarchy?
The $ava.awt.A%T<vent class is the highest4level class in the A%T event4class hierarchy.
"$. When a thread is created and started. what is its initial state?
A thread is in the ready state after it has been created and started.
"(. Can an anony&ous class be declared as i&'le&entin5 an interface and eAtendin5 a class?
An anonymous class may im#lement an interface or e!tend a su#erclass, but may not be declared to do
both.
"*. What is the ran5e of the short ty'e?
The range of the short ty#e is 4(-B,C to -B,C 4 ,.
"1. What is the ran5e of the char ty'e?
The range of the char ty#e is 1 to -B,8 4 ,.
"2. In which 'acka5e are &ost of the 6W< events that su''ort the event=dele5ation &odel defined?
Aost of the A%T4related events of the event4delegation model are defined in the $ava.awt.event #ackage.
The A%T<vent class is defined in the $ava.awt #ackage.
$3. What is the i&&ediate su'erclass of @enu?
Aenu0tem
$1. What is the 'ur'ose of finali%ation?
The #ur#ose of finalization is to give an unreachable ob$ect the o##ortunity to #erform any cleanu#
#rocessing before the ob$ect is garbage collected.
$2. Which class is the i&&ediate su'erclass of the @enuCo&'onent class.
"b$ect
$3. What invokes a thread+s run,- &ethod?
After a thread is started, via its start( method or that of the Thread class, the *3A invokes the thread&s
run( method when the thread is initially e!ecuted.
$". What is the difference between the Boolean C o'erator and the CC o'erator?
0f an e!#ression involving the 6oolean D o#erator is evaluated, both o#erands are evaluated. Then the D
o#erator is a##lied to the o#erand. %hen an e!#ression involving the DD o#erator is evaluated, the first
o#erand is evaluated. 0f the first o#erand returns a value of true then the second o#erand is evaluated. The
DD o#erator is then a##lied to the first and second o#erands. 0f the first o#erand evaluates to false, the
evaluation of the second o#erand is ski##ed.
$$. ?a&e three subclasses of the Co&'onent class.
6o!.Filler, 6utton, )anvas, )heckbo!, )hoice, )ontainer, .abel, .ist, 9crollbar, or Te!t)om#onent
$(. What is the Dre5orianCalendar class?
The =regorian)alendar #rovides su##ort for traditional %estern calendars.
$*. Which Container &ethod is used to cause a container to be laid out and redis'layed?
validate(
$1. What is the 'ur'ose of the Eunti&e class?
The #ur#ose of the Euntime class is to #rovide access to the *ava runtime system.
$2. #ow &any ti&es &ay an ob>ect+s finali%e,- &ethod be invoked by the 5arba5e collector?
An ob$ect&s finalize( method may only be invoked once by the garbage collector.
(3. What is the 'ur'ose of the finally clause of a try=catch=finally state&ent?
The finally clause is used to #rovide the ca#ability to e!ecute code no matter whether or not an e!ce#tion is
thrown or caught.
(1. What is the ar5u&ent ty'e of a 'ro5ra&+s &ain,- &ethod?
A #rogram&s main( method takes an argument of the 9tringFG ty#e.
(2. Which Java o'erator is ri5ht associative?
The H o#erator is right associative.
(3. What is the Locale class?
The .ocale class is used to tailor #rogram out#ut to the conventions of a #articular geogra#hic, #olitical, or
cultural region.
(". Can a double value be cast to a byte?
'es, a double value can be cast to a byte.
($. What is the difference between a break state&ent and a continue state&ent?
A break statement results in the termination of the statement to which it a##lies (switch, for, do, or while.
A continue statement is used to end the current loo# iteration and return control to the loo# statement.
((. What &ust a class do to i&'le&ent an interface?
0t must #rovide all of the methods in the interface and identify the interface in its im#lements clause.
(*. What &ethod is invoked to cause an ob>ect to be5in eAecutin5 as a se'arate thread?
The start( method of the Thread class is invoked to cause an ob$ect to begin e!ecuting as a se#arate thread.
(1. ?a&e two subclasses of the <eAtCo&'onent class.
Te!tField and Te!tArea
(2. What is the advanta5e of the event=dele5ation &odel over the earlier event=inheritance &odel?
The event4delegation model has two advantages over the event4inheritance model. First, it enables event
handling to be handled by ob$ects other than the ones that generate the events (or their containers. This
allows a clean se#aration between a com#onent&s design and its use. The other advantage of the event4
delegation model is that it #erforms much better in a##lications where many events are generated. This
#erformance im#rovement is due to the fact that the event4delegation model does not have to re#eatedly
#rocess unhandled events, as is the case of the event4inheritance model.
*3. Which containers &ay have a @enuBar?
Frame
*1. #ow are co&&as used in the initiali%ation and iteration 'arts of a for state&ent?
)ommas are used to se#arate multi#le statements within the initialization and iteration #arts of a for
statement.
*2. What is the 'ur'ose of the wait,-. notify,-. and notify6ll,- &ethods?
The wait(,notify(, and notifyAll( methods are used to #rovide an efficient way for threads to wait for a
shared resource. %hen a thread e!ecutes an ob$ect&s wait( method, it enters the waiting state. 0t only enters
the ready state after another thread invokes the ob$ect&s notify( or notifyAll( methods.
*3. What is an abstract &ethod?
An abstract method is a method whose im#lementation is deferred to a subclass.
*". #ow are Java source code files na&ed?
A *ava source code file takes the name of a #ublic class or interface that is defined within the file. A source
code file may contain at most one #ublic class or interface. 0f a #ublic class or interface is defined within a
source code file, then the source code file must take the name of the #ublic class or interface. 0f no #ublic
class or interface is defined within a source code file, then the file must take on a name that is different than
its classes and interfaces. 9ource code files use the .$ava e!tension.
*$. What is the relationshi' between the Canvas class and the Dra'hics class?
A )anvas ob$ect #rovides access to a =ra#hics ob$ect via its #aint( method.
*(. What are the hi5h=level thread states?
The high4level thread states are ready, running, waiting, and dead.
**. What value does read,- return when it has reached the end of a file?
The read( method returns 4, when it has reached the end of a file.
*1. Can a Byte ob>ect be cast to a double value?
Io, an ob$ect cannot be cast to a #rimitive value.
*2. What is the difference between a static and a non=static inner class?
A non4static inner class may have ob$ect instances that are associated with instances of the class&s outer
class. A static inner class does not have any ob$ect instances.
13. What is the difference between the ;trin5 and ;trin5Buffer classes?
9tring ob$ects are constants. 9tring6uffer ob$ects are not.
11. If a variable is declared as 'rivate. where &ay the variable be accessed?
A #rivate variable may only be accessed within the class in which it is declared.
12. What is an ob>ect+s lock and which ob>ect+s have locks?
An ob$ect&s lock is a mechanism that is used by multi#le threads to obtain synchronized access to the ob$ect.
A thread may e!ecute a synchronized method of an ob$ect only after it has ac(uired the ob$ect&s lock. All
ob$ects and classes have locks. A class&s lock is ac(uired on the class&s )lass ob$ect.
13. What is the /ictionary class?
The Dictionary class #rovides the ca#ability to store key4value #airs.
1". #ow are the ele&ents of a BorderLayout or5ani%ed?
The elements of a 6order.ayout are organized at the borders (Iorth, 9outh, <ast, and %est and the center
of a container.
1$. What is the F o'erator?
0t is referred to as the modulo or remainder o#erator. 0t returns the remainder of dividing the first o#erand
by the second o#erand.
1(. When can an ob>ect reference be cast to an interface reference?
An ob$ect reference be cast to an interface reference when the ob$ect im#lements the referenced interface.
1*. What is the difference between a Window and a 4ra&e?
The Frame class e!tends %indow to define a main a##lication window that can have a menu bar.
11. Which class is eAtended by all other classes?
The "b$ect class is e!tended by all other classes.
12. Can an ob>ect be 5arba5e collected while it is still reachable?
A reachable ob$ect cannot be garbage collected. "nly unreachable ob$ects may be garbage collected..
23. Is the ternary o'erator written A G y ? % or A ? y G % ?
0t is written ! J y ? z.
21. What is the difference between the 4ont and 4ont@etrics classes?
The FontAetrics class is used to define im#lementation4s#ecific #ro#erties, such as ascent and descent, of a
Font ob$ect.
22. #ow is roundin5 'erfor&ed under inte5er division?
The fractional #art of the result is truncated. This is known as rounding toward zero.
23. What ha''ens when a thread cannot ac)uire a lock on an ob>ect?
0f a thread attem#ts to e!ecute a synchronized method or synchronized statement and is unable to ac(uire
an ob$ect&s lock, it enters the waiting state until the lock becomes available.
2". What is the difference between the EeaderWriter class hierarchy and the In'ut;trea&
!ut'ut;trea& class hierarchy?
The Eeader/%riter class hierarchy is character4oriented, and the 0n#ut9tream/"ut#ut9tream class hierarchy
is byte4oriented.
2$. What classes of eAce'tions &ay be cau5ht by a catch clause?
A catch clause can catch any e!ce#tion that may be assigned to the Throwable ty#e. This includes the <rror
and <!ce#tion ty#es.
2(. If a class is declared without any access &odifiers. where &ay the class be accessed?
A class that is declared without any access modifiers is said to have #ackage access. This means that the
class can only be accessed by other classes and interfaces that are defined within the same #ackage.
2*. What is the ;i&'le<i&eHone class?
The 9im#leTimeKone class #rovides su##ort for a =regorian calendar.
21. What is the @a' interface?
The Aa# interface re#laces the *D+ ,., Dictionary class and is used associate keys with values.
22. /oes a class inherit the constructors of its su'erclass?
A class does not inherit constructors from any of its su#erclasses.
133. 4or which state&ents does it &ake sense to use a label?
The only statements for which it makes sense to use a label are those statements that can enclose a break or
continue statement.
131. What is the 'ur'ose of the ;yste& class?
The #ur#ose of the 9ystem class is to #rovide access to system resources.
132. Which <eAtCo&'onent &ethod is used to set a <eAtCo&'onent to the read=only state?
set<ditable(
133. #ow are the ele&ents of a CardLayout or5ani%ed?
The elements of a )ard.ayout are stacked, one on to# of the other, like a deck of cards.
13". Is CCI a valid Java o'erator?
Io, it is not.
13$. ?a&e the ei5ht 'ri&itive Java ty'es.
The eight #rimitive ty#es are byte, char, short, int, long, float, double, and boolean.
13(. Which class should you use to obtain desi5n infor&ation about an ob>ect?
The )lass class is used to obtain information about an ob$ect&s design.
13*. What is the relationshi' between cli''in5 and re'aintin5?
%hen a window is re#ainted by the A%T #ainting thread, it sets the cli##ing regions to the area of the
window that re(uires re#ainting.
131. Is JabcJ a 'ri&itive value?
The 9tring literal LabcL is not a #rimitive value. 0t is a 9tring ob$ect.
132. What is the relationshi' between an event=listener interface and an event=ada'ter class?
An event4listener interface defines the methods that must be im#lemented by an event handler for a
#articular kind of event. An event ada#ter #rovides a default im#lementation of an event4listener interface.
113. What restrictions are 'laced on the values of each case of a switch state&ent?
During com#ilation, the values of each case of a switch statement must evaluate to a value that can be
#romoted to an int value.
111. What &odifiers &ay be used with an interface declaration?
An interface may be declared as #ublic or abstract.
112. Is a class a subclass of itself?
A class is a subclass of itself.
113. What is the hi5hest=level event class of the event=dele5ation &odel?
The $ava.util.<vent"b$ect class is the highest4level class in the event4delegation class hierarchy.
11". What event results fro& the clickin5 of a button?
The Action<vent event is generated as the result of the clicking of a button.
11$. #ow can a D:I co&'onent handle its own events?
A com#onent can handle its own events by im#lementing the re(uired event4listener interface and adding
itself as its own event listener.
11(. What is the difference between a while state&ent and a do state&ent?
A while statement checks at the beginning of a loo# to see whether the ne!t loo# iteration should occur. A
do statement checks at the end of a loo# to see whether the ne!t iteration of a loo# should occur. The do
statement will always e!ecute the body of a loo# at least once.
11*. #ow are the ele&ents of a DridBa5Layout or5ani%ed?
The elements of a =rid6ag.ayout are organized according to a grid. >owever, the elements are of different
sizes and may occu#y more than one row or column of the grid. 0n addition, the rows and columns may
have different sizes.
111. What advanta5e do Java+s layout &ana5ers 'rovide over traditional windowin5 syste&s?
*ava uses layout managers to lay out com#onents in a consistent manner across all windowing #latforms.
9ince *ava&s layout managers aren&t tied to absolute sizing and #ositioning, they are able to accomodate
#latform4s#ecific differences among windowing systems.
112. What is the Collection interface?
The )ollection interface #rovides su##ort for the im#lementation of a mathematical bag 4 an unordered
collection of ob$ects that may contain du#licates.
123. What &odifiers can be used with a local inner class?
A local inner class may be final or abstract.
121. What is the difference between static and non=static variables?
A static variable is associated with the class as a whole rather than with s#ecific instances of a class. Ion4
static variables take on uni(ue values with each ob$ect instance.
122. What is the difference between the 'aint,- and re'aint,- &ethods?
The #aint( method su##orts #ainting via a =ra#hics ob$ect. The re#aint( method is used to cause #aint( to
be invoked by the A%T #ainting thread.
123. What is the 'ur'ose of the 4ile class?
The File class is used to create ob$ects that #rovide access to the files and directories of a local file system.
12". Can an eAce'tion be rethrown?
'es, an e!ce#tion can be rethrown.
12$. Which @ath &ethod is used to calculate the absolute value of a nu&ber?
The abs( method is used to calculate absolute values.
12(. #ow does &ultithreadin5 take 'lace on a co&'uter with a sin5le C7:?
The o#erating system&s task scheduler allocates e!ecution time to multi#le tasks. 6y (uickly switching
between e!ecuting tasks, it creates the im#ression that tasks e!ecute se(uentially.
12*. When does the co&'iler su''ly a default constructor for a class?
The com#iler su##lies a default constructor for a class if no other constructors are #rovided.
121. When is the finally clause of a try=catch=finally state&ent eAecuted?
The finally clause of the try4catch4finally statement is always e!ecuted unless the thread of e!ecution
terminates or an e!ce#tion occurs within the e!ecution of the finally clause.
122. Which class is the i&&ediate su'erclass of the Container class?
)om#onent
133. If a &ethod is declared as 'rotected. where &ay the &ethod be accessed?
A #rotected method may only be accessed by classes or interfaces of the same #ackage or by subclasses of
the class in which it is declared.
131. #ow can the CheckboA class be used to create a radio button?
6y associating )heckbo! ob$ects with a )heckbo!=rou#.
132. Which non=:nicode letter characters &ay be used as the first character of an identifier?
The non47nicode letter characters M and N may a##ear as the first character of an identifier
133. What restrictions are 'laced on &ethod overloadin5?
Two methods may not have the same name and argument list but different return ty#es.
13". What ha''ens when you invoke a thread+s interru't &ethod while it is slee'in5 or waitin5?
%hen a task&s interru#t( method is e!ecuted, the task enters the ready state. The ne!t time the task enters
the running state, an 0nterru#ted<!ce#tion is thrown.
13$. What is castin5?
There are two ty#es of casting, casting between #rimitive numeric ty#es and casting between ob$ect
references. )asting between numeric ty#es is used to convert larger values, such as double values, to
smaller values, such as byte values. )asting between ob$ect references is used to refer to an ob$ect by a
com#atible class, interface, or array ty#e reference.
13(. What is the return ty'e of a 'ro5ra&+s &ain,- &ethod?
A #rogram&s main( method has a void return ty#e.
13*. ?a&e four Container classes.
%indow, Frame, Dialog, FileDialog, /anel, A##let, or 9croll/ane
131. What is the difference between a Choice and a List?
A )hoice is dis#layed in a com#act form that re(uires you to #ull it down to see the list of available
choices. "nly one item may be selected from a )hoice. A .ist may be dis#layed in such a way that several
.ist items are visible. A .ist su##orts the selection of one or more .ist items.
132. What class of eAce'tions are 5enerated by the Java run=ti&e syste&?
The *ava runtime system generates Euntime<!ce#tion and <rror e!ce#tions.
1"3. What class allows you to read ob>ects directly fro& a strea&?
The "b$ect0n#ut9tream class su##orts the reading of ob$ects from in#ut streams.
1"1. What is the difference between a field variable and a local variable?
A field variable is a variable that is declared as a member of a class. A local variable is a variable that is
declared local to a method.
1"2. :nder what conditions is an ob>ect+s finali%e,- &ethod invoked by the 5arba5e collector?
The garbage collector invokes an ob$ect&s finalize( method when it detects that the ob$ect has become
unreachable.
1"3. #ow are this,- and su'er,- used with constructors?
this( is used to invoke a constructor of the same class. su#er( is used to invoke a su#erclass constructor.
1"". What is the relationshi' between a &ethod+s throws clause and the eAce'tions that can be
thrown durin5 the &ethod+s eAecution?
A method&s throws clause must declare any checked e!ce#tions that are not caught within the body of the
method.
1"$. What is the difference between the J/0 1.32 event &odel and the event=dele5ation &odel
introduced with J/0 1.1?
The *D+ ,.1- event model uses an event inheritance or bubbling a##roach. 0n this model, com#onents are
re(uired to handle their own events. 0f they do not handle a #articular event, the event is inherited by (or
bubbled u# to the com#onent&s container. The container then either handles the event or it is bubbled u# to
its container and so on, until the highest4level container has been tried.
0n the event4delegation model, s#ecific ob$ects are designated as event handlers for =70 com#onents. These
ob$ects im#lement event4listener interfaces. The event4delegation model is more efficient than the event4
inheritance model because it eliminates the #rocessing re(uired to su##ort the bubbling of unhandled
events.
1"(. #ow is it 'ossible for two ;trin5 ob>ects with identical values not to be e)ual under the II
o'erator?
The HH o#erator com#ares two ob$ects to determine if they are the same ob$ect in memory. 0t is #ossible for
two 9tring ob$ects to have the same value, but located indifferent areas of memory.
1"*. Why are the &ethods of the @ath class static?
9o they can be invoked as if they are a mathematical code library.
1"1. What CheckboA &ethod allows you to tell if a CheckboA is checked?
get9tate(
1"2. What state is a thread in when it is eAecutin5?
An e!ecuting thread is in the running state.
1$3. What are the le5al o'erands of the instanceof o'erator?
The left o#erand is an ob$ect reference or null value and the right o#erand is a class, interface, or array ty#e.
1$1. #ow are the ele&ents of a DridLayout or5ani%ed?
The elements of a =rid6ad layout are of e(ual size and are laid out using the s(uares of a grid.
1$2. What an I! filter?
An 0/" filter is an ob$ect that reads from one stream and writes to another, usually altering the data in some
way as it is #assed from one stream to another.
1$3. If an ob>ect is 5arba5e collected. can it beco&e reachable a5ain?
"nce an ob$ect is garbage collected, it ceases to e!ist. 0t can no longer become reachable again.
1$". What is the ;et interface?
The 9et interface #rovides methods for accessing the elements of a finite mathematical set. 9ets do not
allow du#licate elements.
1$$. What classes of eAce'tions &ay be thrown by a throw state&ent?
A throw statement may throw any e!#ression that may be assigned to the Throwable ty#e.
1$(. What are K and 7I?
< is the base of the natural logarithm and /0 is mathematical value #i.
1$*. 6re true and false keywords?
The values true and false are not keywords.
1$1. What is a void return ty'e?
A void return ty#e indicates that a method does not return a value.
1$2. What is the 'ur'ose of the enableKvents,- &ethod?
The enable<vents( method is used to enable an event for a #articular ob$ect. Iormally, an event is enabled
when a listener is added to an ob$ect for a #articular event. The enable<vents( method is used by ob$ects
that handle events by overriding their event4dis#atch methods.
1(3. What is the difference between the 4ile and Eando&6ccess4ile classes?
The File class enca#sulates the files and directories of the local file system. The EandomAccessFile class
#rovides the methods needed to directly access data contained in any #art of a file.
1(1. What ha''ens when you add a double value to a ;trin5?
The result is a 9tring ob$ect.
1(2. What is your 'latfor&+s default character encodin5?
0f you are running *ava on <nglish %indows #latforms, it is #robably )#,-C-. 0f you are running *ava on
<nglish 9olaris #latforms, it is most likely ;;C2N,..
1(3. Which 'acka5e is always i&'orted by default?
The $ava.lang #ackage is always im#orted by default.
1(". What interface &ust an ob>ect i&'le&ent before it can be written to a strea& as an ob>ect?
An ob$ect must im#lement the 9erializable or <!ternalizable interface before it can be written to a stream as
an ob$ect.
1($. #ow are this and su'er used?
this is used to refer to the current ob$ect instance. su#er is used to refer to the variables and methods of the
su#erclass of the current ob$ect instance.
1((. What is the 'ur'ose of 5arba5e collection?
The #ur#ose of garbage collection is to identify and discard ob$ects that are no longer needed by a #rogram
so that their resources may be reclaimed and reused.
1(*. What is a co&'ilation unit?
A com#ilation unit is a *ava source code file.
1(1. What interface is eAtended by 6W< event listeners?
All A%T event listeners e!tend the $ava.util.<vent.istener interface.
1(2. What restrictions are 'laced on &ethod overridin5?
"verridden methods must have the same name, argument list, and return ty#e. The overriding method may
not limit the access of the method it overrides. The overriding method may not throw any e!ce#tions that
may not be thrown by the overridden method.
1*3. #ow can a dead thread be restarted?
A dead thread cannot be restarted.
1*1. What ha''ens if an eAce'tion is not cau5ht?
An uncaught e!ce#tion results in the uncaught<!ce#tion( method of the thread&s Thread=rou# being
invoked, which eventually results in the termination of the #rogram in which it is thrown.
1*2. What is a layout &ana5er?
A layout manager is an ob$ect that is used to organize com#onents in a container.
1*3. Which arith&etic o'erations can result in the throwin5 of an 6rith&eticKAce'tion?
0nteger / and O can result in the throwing of an Arithmetic<!ce#tion.
1*". What are three ways in which a thread can enter the waitin5 state?
A thread can enter the waiting state by invoking its slee#( method, by blocking on 0/", by unsuccessfully
attem#ting to ac(uire an ob$ect&s lock, or by invoking an ob$ect&s wait( method. 0t can also enter the
waiting state by invoking its (de#recated sus#end( method.
1*$. Can an abstract class be final?
An abstract class may not be declared as final.
1*(. What is the EesourceBundle class?
The Eesource6undle class is used to store locale4s#ecific resources that can be loaded by a #rogram to
tailor the #rogram&s a##earance to the #articular locale in which it is being run.
1**. What ha''ens if a try=catch=finally state&ent does not have a catch clause to handle an
eAce'tion that is thrown within the body of the try state&ent?
The e!ce#tion #ro#agates u# to the ne!t higher level try4catch statement (if any or results in the #rogram&s
termination.
1*1. What is nu&eric 'ro&otion?
Iumeric #romotion is the conversion of a smaller numeric ty#e to a larger numeric ty#e, so that integer and
floating4#oint o#erations may take #lace. 0n numerical #romotion, byte, char, and short values are
converted to int values. The int values are also converted to long values, if necessary. The long and float
values are converted to double values, as re(uired.
1*2. What is the difference between a ;crollbar and a ;croll7ane?
A 9crollbar is a )om#onent, but not a )ontainer. A 9croll/ane is a )ontainer. A 9croll/ane handles its
own events and #erforms its own scrolling.
113. What is the difference between a 'ublic and a non='ublic class?
A #ublic class may be accessed outside of its #ackage. A non4#ublic class may not be accessed outside of
its #ackage.
111. <o what value is a variable of the boolean ty'e auto&atically initiali%ed?
The default value of the boolean ty#e is false.
112. Can try state&ents be nested?
Try statements may be tested.
113. What is the difference between the 'refiA and 'ostfiA for&s of the LL o'erator?
The #refi! form #erforms the increment o#eration and returns the value of the increment o#eration. The
#ostfi! form returns the current value all of the e!#ression and then #erforms the increment o#eration on
that value.
11". What is the 'ur'ose of a state&ent block?
A statement block is used to organize a se(uence of statements as a single statement grou#.
11$. What is a Java 'acka5e and how is it used?
A *ava #ackage is a naming conte!t for classes and interfaces. A #ackage is used to create a se#arate name
s#ace for grou#s of classes and interfaces. /ackages are also used to organize related classes and interfaces
into a single A/0 unit and to control accessibility to these classes and interfaces.
11(. What &odifiers &ay be used with a to'=level class?
A to#4level class may be #ublic, abstract, or final.
11*. What are the !b>ect and Class classes used for?
The "b$ect class is the highest4level class in the *ava class hierarchy. The )lass class is used to re#resent
the classes and interfaces that are loaded by a *ava #rogram.
111. #ow does a try state&ent deter&ine which catch clause should be used to handle an eAce'tion?
%hen an e!ce#tion is thrown within the body of a try statement, the catch clauses of the try statement are
e!amined in the order in which they a##ear. The first catch clause that is ca#able of handling the e!ce#tion
is e!ecuted. The remaining catch clauses are ignored.
112. Can an unreachable ob>ect beco&e reachable a5ain?
An unreachable ob$ect may become reachable again. This can ha##en when the ob$ect&s finalize( method is
invoked and the ob$ect #erforms an o#eration which causes it to become accessible to reachable ob$ects.
123. When is an ob>ect sub>ect to 5arba5e collection?
An ob$ect is sub$ect to garbage collection when it becomes unreachable to the #rogram in which it is used.
121. What &ethod &ust be i&'le&ented by all threads?
All tasks must im#lement the run( method, whether they are a subclass of Thread or im#lement the
Eunnable interface.
122. What &ethods are used to 5et and set the teAt label dis'layed by a Button ob>ect?
get.abel( and set.abel(
123. Which Co&'onent subclass is used for drawin5 and 'aintin5?
)anvas
12". What are synchroni%ed &ethods and synchroni%ed state&ents?
9ynchronized methods are methods that are used to control access to an ob$ect. A thread only e!ecutes a
synchronized method after it has ac(uired the lock for the method&s ob$ect or class. 9ynchronized
statements are similar to synchronized methods. A synchronized statement can only be e!ecuted after a
thread has ac(uired the lock for the ob$ect or class referenced in the synchronized statement.
12$. What are the two basic ways in which classes that can be run as threads &ay be defined?
A thread class may be declared as a subclass of Thread, or it may im#lement the Eunnable interface.
12(. What are the 'roble&s faced by Java 'ro5ra&&ers who don+t use layout &ana5ers?
%ithout layout managers, *ava #rogrammers are faced with determining how their =70 will be dis#layed
across multi#le windowing systems and finding a common sizing and #ositioning that will work within the
constraints im#osed by each windowing system.
12*. What is the difference between an if state&ent and a switch state&ent?
The if statement is used to select among two alternatives. 0t uses a boolean e!#ression to decide which
alternative should be e!ecuted. The switch statement is used to select among multi#le alternatives. 0t uses
an int e!#ression to determine which alternative should be e!ecuted.
121. What is the List interface?
The .ist interface #rovides su##ort for ordered collections of ob$ects.
@ost fre)uent )uestions
3- QG Java and CLL
A? 9ome of the similarities and differences are in the table?
Features *ava )/)PP
/ointer Io 'es
"#erator "verload Io 'es
Ty#edef, Define,
/re#rocessors Io 'es
9tructures, 7nions Io 'es
<nums Io 'es
Functions Io (only methods within classes 'es
=oto statement Io 'es
Automatic )oercionsIo(ty#es should be converted e!#licitly 'es
=lobal 3ariables Io. 3ariable is #art of a class 'es
Tem#lates Io 'es
/rivate, /rotected, /ublic
0nheritance Io 'es
Default #arameters Io 'es
=arbage )ollection 'es Io
Aulti4thread su##ort 'es Io
Aulti#le 0nheritance
'es. 9u##orts only interface inheritance and not im#lementation inheritanceQ
'es
<!ce#tion >andling
'es. try/catch must be defined if the function declares that it may throw an e!ce#tion.
'es. 'ou may not include the try/catch even if the function
throws an e!ce#tion.
Function "verload 'es 'es
0nternationalization 'es 'es
0nclude of other "b$ects Rim#ort Rinclude
)omments L//L,L/S S/,/SS S/ L//L,L/S S/L
1- QG What is the 'ur'ose of the toolkit in the 6bstract Window <oolkit ,6W<-? #ow does 6W<
work ?
A? The A%T toolkit is an interface between the abstract window layer and a s#ecific windowing
im#lementation.
2- QG What is layout &ana5er ? #ow does it work ?
A? A layout manager is an ob$ect that #ositions and resizes the com#onents in a )ontainer according to
some algorithm@ for e!am#le, the Flow.ayout layout manager lays out com#onents from left to right until it
runs out of room and then continues laying out com#onents below that row.
3- QG 6dvanta5es and disadvanta5es of layout &ana5er ?
"- QG Co&'are ;WI?D co&'onents to standard 6W<.
A? 9wing is an e!tension of, and not a re#lacement for the A%T. There is some overla# between A%T and
9wing (for e!am#le a 9wing *6utton com#onent might be viewed as an im#roved functional re#lacement
for an A%T 6utton com#onent. "ne of the advantages of 9wing com#onents is that because the
com#onents are not rendered on the screen by the o#erating system, the look and feel of a com#onent does
not change as the a##lication or a##let is e!ecuted on different #latforms running under different o#erating
systems. Furthermore, it is #ossible to cause 9wing com#onents to mimic the look and feel of a s#ecific
#latform no matter what #latform the #rogram is running on. This is known as #luggable look and feel.
9wing com#onents su##ort the *D+ ,.,
Delegation <vent Aodel. From an event handling view#oint, 9wing com#onents o#erate the same as
A%T com#onents (e!ce#t that 9wing #rovides a number of new event ty#es. Aany 9wing com#onents
don&t have an A%T counter#art. A number of new and e!citing com#onents are included in the 9wing
library that don&t e!ist in the A%T (toolti#s, #rogress bars, trees, etc.
$- QG What is Java Beans ?
A? According to *ava9oft, LA *ava 6ean is a reusable software com#onent that can be mani#ulated visually
in a builder tool.L
(- QG What you know about Corba i&'le&entation in Java ?
A? *ava ,.- #romises full )"E6A 0D. su##ort.
*- QG What do you know about networkin5 su''ort in Java ?
A? *ava su##orts Llow4levelL and Lhigh4levelL classes. L.ow4levelL classes #rovide su##ort for socket
#rogramming? 9ocket, Datagram9ocket, and 9erver9ocket classes. L>igh4levelL classes #rovide L%eb
#rogrammingL? 7E., 7E.<ncoder, and 7E.)onnection classes. Ietworking #rogramming classes ease
the #rogramming of network a##lications, but do not substitute your knowledge of networking. *ava
networking like anything else in *ava is #latform4inde#endent.
1- QG What is it ob>ect seriali%ation ?
A? 9erialization is a way to convert ob$ects (including com#le! data structures such as lists and
trees into a stream of bytes.
2- QG #ow to &ake a''lication thread=safe ?
A? 'ou should use the word synchronized to mark the critical section of code. 'ou may also use other
methods of thread synchronization (see wait(, notify(, notifyAll( etc.
13- QG What is it reflection ,intros'ection- ? Why is reflection 'ossible in the Java lan5ua5e?
A? Eeflection (intros#ection is (uerying a class about its #ro#erties, and o#erating on methods and
fields by the name for a given ob$ect instance. Eeflection is #ossible in the *ava language because of late
binding.
11- QG Why are Java 6Echive ,J6E- files i&'ortant?
A? *AE files bundle .class files and o#timize a##let downloads.
4ollowin5 answer &ay not be correct
12- /escribe what ha''ens when an ob>ect is created in Java
9everal things ha##en in a #articular order to ensure the ob$ect is constructed #ro#erly?
,. Aemory is allocated from hea# to hold all instance variables and im#lementation4s#ecific data of the
ob$ect and its su#erclasses. 0m#lemenation4s#ecific data includes #ointers to class and method data.
-. The instance variables of the ob$ects are initialized to their default values.
T. The constructor for the most derived class is invoked. The first thing a constructor does is call the
consctructor for its su#erclasses. This #rocess continues until the constrcutor for $ava.lang."b$ect is called,
as $ava.lang."b$ect is the base class for all ob$ects in $ava.
U. 6efore the body of the constructor is e!ecuted, all instance variable initializers and initialization blocks
are e!ecuted. Then the body of the constructor is e!ecuted. Thus, the constructor for the base class
com#letes first and constructor for the most derived class com#letes last.
13- In Java. Mou can create a ;trin5 ob>ect as below G ;trin5 str I JabcJN C ;trin5 str I new
;trin5,JabcJ-N
%hy cant a button ob$ect be created as ? 6utton bt H LabcL %hy is it com#ulsory to create a button ob$ect
as? 6utton bt H new 6utton(LabcL@ %hy this is not com#ulsory in 9tring&s case.
The main reason you cannot create a button by
6utton bt,H LabcL@
is because LabcL is a literal string (something slightly different than a 9tring ob$ect, by4the4way and bt, is
a 6utton ob$ect. That sim#le. The only ob$ect in *ava that can be assigned a literal 9tring is $ava.lang.9tring.
0m#ortant to not that you are I"T calling a $ava.lang.9tring constuctor when you ty#e 9tring s H LabcL@
For e!am#le
9tring ! H LabcL@
9tring y H LabcL@
refer to the same ob$ect. %hile
9tring !, H new 9tring(LabcL@
9tring !- H new 9tring(LabcL@
refer to two different ob$ects.
1"- What are the &ain differences between Java and CLL?
<verything is an ob$ect in *ava( 9ingle root hierarchy as everything gets derived from $ava.lang."b$ect
*ava does not have all the com#licated as#ects of )PP ( For e!? /ointers, tem#lates, unions, o#erator
overloading, structures etc..
The *ava language #romoters initially said LIo #ointersQL, but when many #rogrammers (uestioned how
you can work without #ointers, the #romoters began saying LEestricted #ointers.L 'ou can make u# your
mind whether itVs really a #ointer or not. 0n any event, thereVs no #ointer arithmetic.
There are no destructors in *ava. (automatic garbage collection
*ava does not su##ort conditional com#ile (Rifdef/Rifndef ty#e.
Thread su##ort is built into $ava but not in )PP.
*ava does not su##ort default arguments. ThereVs no sco#e resolution o#erator ?? in *ava. *ava uses the
dot for everything, but can get away with it since you can define elements only within a class. <ven the
method definitions must always occur within a class, so there is no need for sco#e
resolution there either.
ThereVs no Lgoto L statement in *ava.
*ava doesnVt #rovide multi#le inheritance (A0, at least not in the same sense that )PP does.
<!ce#tion handling in *ava is different because there are no destructors.
*ava has method overloading, but no o#erator overloading. The 9tring class does use the P and PH
o#erators to concatenate strings and 9tring e!#ressions use automatic ty#e conversion, but thatVs a s#ecial
built4in case.
*ava is inter#reted for the most #art and hence #latform inde#endent.
1$- What are interfaces?
0nterfaces #rovide more so#histicated ways to organize and control the ob$ects in your system.
The interface keyword takes the abstract conce#t one ste# further. 'ou could think of it as a W#ureX abstract
class. 0t allows the creator to establish the form for a class? method names, argument lists, and return
ty#es, but no method bodies. An interface can also contain fields, but The interface keyword takes the
abstract conce#t one ste# further. 'ou could think of it as a W#ureX abstract class. 0t allows the creator to
establish the form for a class? method names, argument lists, and return ty#es, but no method bodies.
An interface can also contain fields, but
An interface says? WThis is what all classes that im#lement this #articular interface will look like.X Thus,
any code that uses a #articular interface knows what methods might be called for that interface, and thatVs
all. 9o the interface is used to establish a W#rotocolX between classes. (9ome ob$ect4oriented #rogramming
languages have a keyword called #rotocolto do the same thing.
1$- #ow can you achieve @ulti'le Inheritance in Java?
*ava&s interface mechanism can be used to im#lement multi#le inheritance, with one im#ortant difference
from cPP way of doing A0? the inherited interfaces must be abstract. This obviates the need to choose
between different im#lementations, as with interfaces there are no im#lementations.
1(- What is the difference between ;trin5Buffer and ;trin5 class?
A string buffer im#lements a mutable se(uence of characters. A string buffer is like a 9tring, but can be
modified. At any #oint in time it contains some #articular se(uence of characters, but the length and content
of the se(uence can be changed through certain method calls.
The 9tring class re#resents character strings. All string literals in *ava #rograms, such as LabcL are constant
and im#lemented as instances of this class@ their values cannot be changed after they are created.
1*- /escribe. in 5eneral. how >ava+s 5arba5e collector works?
The *ava runtime environment deletes ob$ects when it determines that they are no longer being used. This
#rocess is known as garbage collection.
The *ava runtime environment su##orts a garbage collector that #eriodically frees the memory used by
ob$ects that are no longer needed. The *ava garbage collector is a mark4swee# garbage collector that scans
*ava&s dynamic memory areas for ob$ects, marking those that are referenced. After all #ossible #aths to
ob$ects are investigated, those ob$ects that are not marked (i.e. are not referenced are known to be garbage
and are collected.
11- What+s the difference between II and e)uals &ethod?
The e(uals method can be considered to #erform a dee# com#arison of the value of an ob$ect, whereas the
HH o#erator #erforms a shallow com#arison.
The e(uals( method com#ares the characters inside a string ob$ect. HH o#erator com#ares two ob$ect
references to check whether they refer to the same instances or not.
12- What are abstract classes. abstract &ethods?
9im#ly s#eaking a class or a method (ualified with LabstractL keyword is an abstract class or abstract
method.
'ou create an abstract class when you want to mani#ulate a set of classes through a common interface. All
derived4class methods that match the signature of the base4class declaration will be called using the
dynamic binding mechanism.
An abstract method is an incom#lete method. 0t has only a declaration and no method body. >ere is the
synta! for an abstract method declaration? abstract void f(@
23- #ow can you force all derived classes to i&'le&ent a &ethod 'resent in the base class?
)reating and im#lementing an interface would be the best way for this situation. *ust create an interface
with em#ty methods which forces a #rogrammer to im#lement all the methods #resent under it.
Another way of achieving this task is to declare a class as abstract with all its methods abstract.
21- What is the difference between an 6''let and an 6''lication?
,. A##lets can be embedded in >TA. #ages and downloaded over the 0nternet whereas A##lications have
no s#ecial su##ort in >TA. for embedding or downloading.
-. A##lets can only be e!ecuted inside a $ava com#atible container, such as a browser or a##letviewer
whereas A##lications are e!ecuted at command line by $ava.e!e or $view.e!e.
T. A##lets e!ecute under strict security limitations that disallow certain o#erations(sandbo! model security
whereas A##lications have no inherent security restrictions.
U. A##lets don&t have the main( method as in a##lications. 0nstead they o#erate on an entirely different
mechanism where they are initialized by init(,started by start(,sto##ed by sto#( or destroyed by destroy(.
22- Java says Jwrite once. run anywhereJ. What are so&e ways this isn+t )uite true?
Any time you use system calls s#ecific to one o#erating system and do not create alternative calls for
another o#erating system, your #rogram will not function correctly.
9olaris systems and 0ntel systems order the bits of an integer differently. ('ou may have heard of little
endian vs. big endian
0f your code uses bit shifting, or other binary o#erators, they will not work on systems that have o##oside
endianism.
23- /escribe >ava+s security &odel.
*ava&s security model is one of the most interesting and uni(ue as#ects of the language. For the most #art
it&s broken into two #ieces? the user ad$ustable security manager that checks various A/0 o#erations like file
access, and the byte code verifier that asserts the validity of com#iled byte code.
#ublic abstract class 9ecurityAanager $ava.lang.9ecurityAanager is an abstract class which different
a##lications subclass to im#lement a #articular security #olicy. 0t allows an a##lication to determine
whether or not a #articular o#eration will generate a security e!ce#tion.
2"- What is the difference between a 8ector and an 6rray. /iscuss the advanta5es and disadvanta5es
of both?
The vector container class generalizes the conce#t of an ordinary ) array. .ike an array, a vector is an
inde!ed data structure, with inde! values that range from 1 to one less than the number of elements
contained in the structure. Also like an array, values are most commonly assigned to and e!tracted from the
vector using the subscri#t o#erator. >owever, the vector differs from an array in the following im#ortant
res#ects?
The size of the vector can change dynamically. Iew elements can be inserted on to the end of a vector, or
into the middle. 0t is im#ortant to note, however, that while these abilities are #rovided, insertion into the
middle of a vector is not as efficient as insertion into the middle of a list.
A vector has more Lself4knowledgeL than an ordinary array. 0n #articular, a vector can be (ueried about its
size, about the number of elements it can #otentially hold (which may be different from its current size,
and so on.
A vector can only hold references to ob$ects and not #rimitive ty#es.
3ector 0m#lementaions are usually slower then array because of all the functionality that comes with them.
As im#lemented in *ava, vector is a thread4safe class and hence all methods are synchronous methods,
which makes them considerably slow.
2$- #ow &any different ty'es of J/BC drivers are 'resent? /iscuss the&.
Ty#e ,? *D6)4"D6) 6ridge #lus "D6) Driver?
The first ty#e of *D6) driver is the *D6)4"D6) 6ridge. 0t is a driver that #rovides *D6) access to
databases through "D6) drivers. The "D6) driver must be configured on the client for the bridge to
work. This driver ty#e is commonly used for #rototy#ing or when there is no *D6) driver available for a
#articular D6A9.
Ty#e -? Iative4A/0 #artly4*ava Driver?
The Iative to A/0 driver converts *D6) commands to D6A94s#ecific native calls. This is much like the
restriction of Ty#e , drivers. The client must have some binary code loaded on its machine. These drivers
do have an advantage over Ty#e , drivers because they interface directly with the database.
Ty#e T? *D6)4Iet /ure *ava Driver?
The *D6)4Iet drivers are a three4tier solution. This ty#e of driver translates *D6) calls into a database4
inde#endent network #rotocol that is sent to a middleware server. This server then translates this D6A94
inde#endent #rotocol into a D6A94s#ecific #rotocol, which is sent to a #articular database. The results are
then routed back through the middleware server and sent back to the client. This ty#e of solution makes it
#ossible to im#lement a #ure *ava client. 0t also makes it #ossible to swa# databases without affecting the
client.
Ty#e U? Iative4/rotocol /ur *ava Driver
These are #ure *ava drivers that communicate directly with the vendor&s database. They do this by
converting *D6) commands directly into the database engine&s native #rotocol. This driver has no
additional translation or middleware layer, which im#roves #erformance tremendously.
2(- What does the keyword Jsynchroni%eJ &ean in >ava. When do you use it? What are the
disadvanta5es of synchroni%ation?
9ynchronize is used when u want to make ur methods thread safe. The disadvantage of synchronise is it
will end u# in slowing down the #rogram. Also if not handled #ro#erly it will end u# in dead lock.
,. "nly use (and minimize it&s usesynchronization when writing multithreaded code as there is a s#eed (u#
to five to si! time slower, de#ending on the e!ecution time of the synchronized/non4synchronized method
cost associated with its use.
-. 0n case of syncronized method modifier, the byte code generated is the e!act same as non4syncronized
method. The only difference is that a flag called A))N9'I)E"I0K<D #ro#erty flag in method&s
methodNinfo structure is set if the syncronized method modifier is #resent.
T. Also, syncronized keyword can make the code larger in size if used in the body of the method as
bytecode for monitorenter/monitore!it is generated in addition to any e!ce#tion handling.
2*- What are native &ethods? #ow do you use the&?
Iative methods are methods that are defined as #ublic static methods within a $ava class, but whose
im#lementation is #rovided in another #rogramming language such as ).
21- What is E@I?
EA0 stands for Eemote Aethod 0nvocation. Traditional a##roaches to e!ecuting code on other machines
across a network have been confusing as well as tedious and error4#rone to im#lement. The nicest way to
think about this #roblem is that some ob$ect ha##ens to live on another machine, and that you can send a
message to the remote ob$ect and get a result as if the ob$ect lived on your local machine. This
sim#lification is e!actly what *ava Eemote Aethod 0nvocation (EA0 allows you to do.
22- What is J/BC? /escribe the ste's needed to eAecute a ;QL )uery usin5 J/BC.
The *D6) is a #ure *ava A/0 used to e!ecute 9Y. statements. 0t #rovides a set of classes and interfaces
that can be used by develo#ers to write database a##lications.
The ste#s needed to e!ecute a 9Y. (uery using *D6)?
,. "#en a connection to the database.
-. <!ecute a 9Y. statement.
T. /rocess th results.
U. )lose the connection to the database.
33- 6ccess s'ecifiersG J'ublicJ. J'rotectedJ. J'rivateJ. nothin5?
/ublic Z any other class from any #ackage can instantiate and e!ecute the classes and methods
/rotected Z only subclasses and classes inside of the #ackage can access the classes and methods
/rivate Z the original class is the only class allowed to e!ecuted the methods.
31- What does the JfinalJ keyword &ean in front of a variable? 6 &ethod? 6 class?
F0IA. for a variable ? value is constant
F0IA. for a method ? cannot be overridden
F0IA. for a class ? cannot be derived
32- /oes Java have J5otoJ?
no
33- Why JbytecodeJ? Can you reverse=en5ineer the code fro& bytecode?
3"- What synchroni%ation constructs does Java 'rovide? #ow do they work?
3$- 6re constructors inherited? Can a subclass call the 'arent+s class constructor? When?
'ou cannot inherit a constructor. That is, you cannot create a instance of a subclass using a constructor of
one of it&s su#erclasses. "ne of the main reasons is because you #robably don&t want to overide the
su#erclasses constructor, which would be #ossible if they were inherited. 6y giving the develo#er the
ability to override a su#erclasses constructor you would erode the enca#sulation abilities of the language.
3(- /oes Java have destructors?
Io garbage collector does the $ob working in the background
3*- What does the JabstractJ keyword &ean in front of a &ethod? 6 class?
Abstract keyword declares either a method or a class. 0f a method has a abstract keyword in front of it,it is
called abstract method.Abstract method hs no body.0t has only arguments and return ty#e.Abstract methods
act as #laceholder methods that are im#lemented in the subclasses.
Abstract classes can&t be instantiated.0f a class is declared as abstract,no ob$ects of that class can be
created.0f a class contains any abstract method it must be declared as abstract
31- ?a&e four &ethods every Java class will have.
#ublic 9tring to9tring(@
#ublic "b$ect clone(@
#ublic boolean e(uals(@
#ublic int hash)ode(@
32- Diven a teAt file. in'ut.tAt. 'rovide the state&ent re)uired to o'en
this file with the a##ro#riate 0/" stream to be able to read and #rocess this file.
"3- /iscuss the differences between creatin5 a new class. eAtendin5 a class and i&'le&entin5 an
interfaceN and when each would be a##ro#riate.
S)reating a new class is sim#ly creating a class with no e!tensions and no
im#lementations. The signature is as follows
#ublic class Ay)lass(
[
\
S<!tending a class is when you want to use the functionality of another class or classes.
The e!tended class inherits all of the functionality of the #revious class. An e!am#le of
this when you create your own a##let class and e!tend from $ava.a##let.A##let. This
gives you all of the functionality of the $ava.a##let.A##let class.
The signature would look like this
#ublic class Ay)lass e!tends Ay6ase)lass
[
\
S0m#lementing an interface sim#ly forces you to use the methods of the interface
im#lemented. This gives you two advantages. This forces you to follow a standard
(forces you to use certain methods and in doing so gives you a channel for
#olymor#hism. This isnVt the only way you can do #olymor#hism but this is one of the
ways.
#ublic class Fish im#lements Animal
[
\
"3- What+s the difference between the II o'erator and the e)uals,- &ethod? What test does
!b>ect.e)uals,- use, and whyJ
The HH o#erator would be used, in an ob$ect sense, to see if the two ob$ects were
actually the same ob$ect. This o#erator looks at the actually memory address to see if it
actually the same ob$ect. The e(uals( method is used to com#are the values of the
ob$ect res#ectively. This is used in a higher level to see if the ob$ect values are e(ual.
"f course the the e(uals( method would be overloaded in a meaningful way for
whatever ob$ect that you were working with.
"1- why do you create interfaces. and when @:;< you use one.
'ou would create interfaces when you have two or more functionalities talking to each other. Doing it this
way hel# you in creating a #rotocol between the #arties involved.
"2- What is the difference between instanceof and isInstance?
instanceof is used to check to see if an ob$ect can be cast into a s#ecified ty#e without throwing a cast class
e!ce#tion.
is0nstance(
Determines if the s#ecified "b$ect is assignment4com#atible with the ob$ect re#resented
by this )lass. This method is the dynamic e(uivalent of the *ava language instanceof
o#erator. The method returns true if the s#ecified "b$ect argument is non4null and can
be cast to the reference ty#e re#resented by this )lass ob$ect without raising a
)lass)ast<!ce#tion. 0t returns false otherwise.
"3- #ow &any &ethods do u i&'le&ent if i&'le&ent the ;eriali%able Interface?
The 9erializable interface is $ust a LmarkerL interface, with no methods of its own to im#lement.
Are there any other &marker& interfacesJ
$ava.rmi.Eemote
$ava.util.<vent.istener
""- OWhat are the advanta5es of develo'in5 an n=tiered syste&?
"$- OWhy is it often difficult to se'arate the business layer fro& the data access layer?
"(- . /iff between 6rrayList and 8ector
"*- 8ariable shadowin5 with eAa&'le
,. %hat is the diffrence between an Abstract class and 0nterface J
-. %hat is user defined e!ce#tion J
T. %hat do you know about the garbate collector J
U. %hat is the difference between )PP D *ava J
C. <!#lain EA0 ArchitectureJ
8. >ow do you communicate in between A##lets D 9ervlets J
:. %hat is the use of 9ervlets J
;. %hat is *D6)J >ow do you connect to the Database J
2. 0n an >TA. form 0 have a 6utton which makes us to o#en another #age in ,C seconds. >ow will do you
that J
,1. %hat is the difference between /rocess and Threads J
,,. %hat is the difference between EA0 D )orba J
,-. %hat are the services in EA0 J
,T. >ow will you initialize an A##let J
,U. %hat is the order of method invocation in an A##let J
,C. %hen is u#date method called J
,8. >ow will you #ass values from >TA. #age to the 9ervlet J
,:. >ave you ever used >ashTable and Dictionary J
,;. >ow will you communicate between two A##lets J
,2. %hat are statements in *A3A J
-1. %hat is *AE file J
-,. %hat is *I0 J
--. %hat is the base class for all swing com#onents J
-T. %hat is *F) J
-U. %hat is Difference between A%T and 9wing J
-C. )onsidering note#ad/0< or any other thing as #rocess, %hat 5 will ha##en if you start note#ad or 0< T
timesJ %here T #rocesses are started or T threads are started J
-8. >ow does thread synchronization occurs inside a monitor J
-:. >ow will you call an A##let using a *ava 9cri#t function J
-;. 0s there any tag in >TA. to u#load and download files J
-2. %hy do you )anvas J
T1. >ow can you #ush data from an A##let to 9ervlet J
T,. %hat are U drivers available in *D6) J
T-. >ow you can know about drivers and database information J
TT. 0f you are truncated using *D6), >ow can you know ..that how much 5 5 5 data is truncated J
TU. And %hat situation , each of the U drivers used J
TC. >ow will you #erform transaction using *D6) J
T8. 0n EA0, server ob$ect first loaded into the memory and then the stub reference is sent to the client J or
whether a stub reference is directly sent to the client J
T:. 9u##ose server ob$ect is not loaded into the memory, and theclient re(uest for it , what will ha##enJ
T;. %hat is serialization J
T2. )an you load the server ob$ect dynamicallyJ 0f so, what are the ma$or T ste#s involved in it J
U1. %hat is difference EA0 registry and "9Agent J
U,. To a server method, the client wants to send a value -1, with this value e!ceeds to -1,. a message
should be sent to the client J %hat will you do for achieving for this J
U-. %hat are the benefits of 9wing over A%T J
UT. %here the )ard.ayout is used J
UU. %hat is the .ayout for Tool6ar J
UC. %hat is the difference between =rid and =ridbag.ayout J
U8. >ow will you add #anel to a Frame J
U:. %hat is the corres#onding .ayout for )ard in 9wing J
U;. %hat is light weight com#onent J
U2. )an you run the #roduct develo#ment on all o#erating systems J
C1. %hat is the webserver used for running the 9ervlets J
C,. %hat is 9ervlet A/0 used for conneting database J
C-. %hat is bean J %here it can be used J
CT. %hat is difference in between *ava )lass and 6ean J
CU. )an we send ob$ect using 9ockets J
CC. %hat is the EA0 and 9ocket J
C8. >ow to communicate - threads each other J
C:. %hat are the files generated after using 0D. to *ava )om#ilet J
C;. %hat is the #rotocol used by server and client J
C2. )an 0 modify an ob$ect in )"E6A J
81. %hat is the functionality stubs and skeletons J
8,. %hat is the ma##ing mechanism used by *ava to identify 0D. language J
8-. Diff between A##lication and A##let J
8T. %hat is serializable 0nterface J
8U. %hat is the difference between )=0 and 9ervlet J
8C. %hat is the use of 0nterface J
88. %hy *ava is not fully ob$ective oriented J
8:. %hy does not su##ort multi#le 0nheritance J
8;. %hat it the root class for all *ava classes J
82. %hat is #olymor#hism J
:1. 9u##ose 0f we have variable & 0 & in run method, 0f 0 can create one or more thread each thread will
occu#y a se#arate co#y or same variable will be shared J
:,. 0n servlets, we are having a web #age that is invoking servlets username and #assword J which is cheks
in the database J 9u##ose the second #age also 0f we want to verify the same information whether it will
connect to the database or it will be used #revious informationJ
:-. %hat are virtual functions J
:T. %rite down how will you create a binary Tree J
:U. %hat are the traverses in 6inary Tree J
:C. %rite a #rogram for recursive Traverse J
:8. %hat are session variable in 9ervlets J
::. %hat is client server com#uting J
:;. %hat is )onstructor and 3irtual functionJ )an we call 3irtual funciton in a constructor J
:2. %hy we use ""/9 conce#tsJ %hat is its advantage J
;1. %hat is the middleware J %hat is the functionality of %ebserver J
;,. %hy *ava is not ,11 O #ure ""/9 J ( <com9erver
;-. %hen we will use an 0nterface and Abstract class J
;T. %hat is an EA0J
;U. >ow will you #ass #arameters in EA0 J %hy u serializeJ
;C. %hat is the e!act difference in between 7nicast and Aulticast ob$ect J %here we will use J
;8. %hat is the main functionality of the Eemote Eeference .ayer J
;:. >ow do you download stubs from a Eemote #lace J
;;. %hat is the difference in between )PP and *ava J can u e!#lain in detail J
;2. 0 want to store more than ,1 ob$ects in a remote server J %hich methodology will follow J
21. %hat is the main functionality of the /re#ared 9tatement J
2,. %hat is meant by static (uery and dynamic (uery J
2-. %hat are the Iormalization Eules J Define the Iormalization J
2T. %hat is meant by 9erveletJ %hat are the #arameters of the service method J
2U. %hat is meant by 9ession J Tell me something about >TT/9ession )lass J
2C. >ow do you invoke a 9erveltJ %hat is the difference in between do/ost and do=et methods J
28. %hat is the difference in between the >TT/9ervlet and =eneric 9ervlet J <!#alin their methods J Tell
me their #arameter names also J
2:. >ave you used threads in 9ervelet J
2;. %rite a #rogram on EA0 and *D6) using 9tored/rocedure J
22. >ow do you sing an A##let J
,11. 0n a )ontainer there are C com#onents. 0 want to dis#lay the all the com#onents names, how will you
do that one J
,1,. %hy there are some null interface in $ava J %hat does it mean J =ive me some null interfaces in
*A3A J
,1-. Tell me the latest versions in *A3A related areas J
,1T. %hat is meant by class loader J >ow many ty#es are thereJ %hen will we use them J
,1U. >ow do you load an 0mage in a 9ervlet J
,1C. %hat is meant by flickering J
,18. %hat is meant by distributed A##lication J %hy we are using that in our a##lications J
,1:. %hat is the functionality of the stub J
,1;. >ave you used any version control J
,12. %hat is the latest version of *D6) J %hat are the new features are added in that J
,,1. <!#lain - tier and T 4tier Architecture J
,,,. %hat is the role of the webserver J
,,-. >ow have you done validation of the fileds in your #ro$ect J
,,T. %hat is the main difficulties that you are faced in your #ro$ect J
,,U. %hat is meant by cookies J <!#lain J
Aake sure you have a co#y of your resume in front of you. "+ to have a cheat sheet or two 4 $ust don&t let
anyone hear #a#ers shuffling.
+now your ""ADD definitions, such as #olymor#hism, inheritance, etc.
+now the difference between an interface and an abstract class.
+now that *ava does not su##ort multi#le inheritance the way )PP does.
+now that you im#lement an interface (can im#lement more than one.
+now that you e!tend an abstract class (can only e!tend more than one.
+now about the access modifiers? #ublic/friendly(default/#rotected/#rivate. 6e able to e!#lain in one or
two sentences for each case. This is where you can get tangled u# in a #hone conversation and confuse the
heck out of the interviewer and yourself.
+now A%T <vent Aodel 4 tough to do over the #hone 4 but you may get hit on a (uestion.
+now the two ways to start a thread 4 Le!tending ThreadL or Lim#lementing EunnableL.
+now that the method is LrunL but to run a thread you use LstartL.
1. #ow can I i&'rove the 'erfor&ance of a >ava a''lication. what are the >ava o'ti&i%ation
techni)ues.
That (uestion is about as meaningful as Lhow do you code stuffJL There&s no one right answer, and the
interviewer #robably $ust wanted to see if you knew SanythingS about o#timization. The answer is to go to
the /erformance thread and read the #ostings. 0f you search there for LbooksL, you should find some good
references which will get you started. 'ou should also search for LtoolsL.
(uote?
-. %hat should you do to ensure that your a##let works e!actly the same way on both 0< and netsca#e.
9hort answers include? make sure they use the same *3A, don&t use com#le! =70s, and most im#ortantly
test to be certainQ /ersonally, 0&d (uestion the benefit of the a##let and ask if could be done with *9/s.

S-ar putea să vă placă și