Anda di halaman 1dari 21

7/17/2010 Master list of Java interview questions - …

Search Tech Interv iews

Tech Interviews Search


Prepare for job interviews with the questions and answers asked by high-tech employers

.NET C++ Da t a ba se Gen er a l Ha r dw a r e Ja v a Net w or kin g Pu zzles SA P A BA P Test in g Un ix /Lin u x

Jav a > > Mast er list of Java int erv iew quest ions - 115 quest ions

Java Jobs for Freshers. Java Training Bangalore Java Training Bangalore
MNC's Hiring Freshers Now. Submit Training by 10 year exp real time Best Training on Java,JSP,Servlets
Your Resume Free. consultant in Basic & all Advanced Struts,Hibernate,Spring,JSF,EJB
Monsterindia.com www.javafasttrack.com www.jlcindia.com

Master list of Java interview questions - 115


questions
By adm in | Ju ly 1 8 , 2 0 0 5

1 1 5 questions total, not for the w eak. Cov ers ev ery thing from basics to JDBC connectiv ity ,
AWT and JSP.

1 . What is t he difference bet ween procedural and object -orient ed programs?- a)


In procedural program , program m ing logic follows certain procedures and the
instructions are executed one after another. In OOP program , unit of program is object,
which is nothing but com bination of data and code. b) In procedural program , data is
exposed to the whole program whereas in OOPs program , it is accessible with in the
object and which in turn assures the security of the code. americanexpress.com/india Ads by Google
2 . What are Encapsulat ion, Inherit ance and Polymorphism?- Encapsulation is the
m echanism that binds together code and data it m anipulates and keeps both safe from Job Interview Question Articles
outside interference and m isuse. Inheritance is the process by which one object C# Interv iew Questions and Answers
acquires the properties of another object. Poly m orphism is the feature that allow s one QTP Interv iew Questions and Answ ers
interface to be used for general class actions. C+ + Interv iew Questions and Answers
3 . What is t he difference bet ween Assignment and Init ializat ion?- Assignm ent PHP Interv iew Questions and Answ ers
can be done as m any tim es as desired whereas initialization can be done only once. XML Interv iew Questions and Answers
Jav aScript Interv iew Questions and Answers
4 . What is OOPs?- Object oriented program m ing organizes a program around its data, i. Asp.Net Interv iew Questions and Answ ers
e. , objects and a set of well defined interfaces to that data. An object-oriented program J2EE Interv iew Questions and Answers
can be characterized as data controlling access to code. ABAP Interv iew Questions and Answers
5. What are Class, Const ruct or and Primit iv e dat a t y pes?- Class is a tem plate for Perl Interv iew Questions and Answers
m ultiple objects with sim ilar features and it is a blue print for objects. It defines a ty pe Jav a Interv iew Questions and Answ ers
of object according to the data the object can hold and the operations the object can
perform . Constructor is a special kind of m ethod that determ ines how an object is
initialized when created. Prim itiv e data ty pes are 8 ty pes and they are: by te, short, Resources
int, long, float, double, boolean, char. Technology Question and Answer Website
6 . What is an Object and how do y ou allocat e memory t o it ?- Object is an instance How to dance around the salary -expectation
of a class and it is a software unit that com bines a structured set of data with a set of question
operations for inspecting and m anipulating that data. When an object is created using 1 0 m istakes m anagers m ake during job interv iews
new operator, m em ory is allocated to it. ID Maker
7 . What is t he difference bet ween const ruct or and met hod?- Constructor will be Stupid interv iew questions
autom atically inv oked when an object is created whereas m ethod has to be called How to Answer These Tricky Interv iew Questions
explicitly . Sev en tips for w riting an online profile for LinkedIn,
8. What are methods and how are t hey defined?- Methods are functions that operate My Space or Facebook
on instances of classes in which they are defined. Objects can com m unicate with each Video surv eillance
other using m ethods and can call m ethods in other classes. Method definition has four Ink cartridges
parts. They are nam e of the m ethod, ty pe of object or prim itiv e ty pe the m ethod Laptop com puters
returns, a list of param eters and the body of the m ethod. A m ethod’s signature is a Affordable life insurance
com bination of the first three parts m entioned abov e. Ink cartridges
9 . What is t he use of bin and lib in JDK?- Bin contains all tools such as jav ac,
appletv iewer, awt tool, etc., w hereas lib contains API and all packages.
1 0. What is casting?- Casting is used to conv ert the v alue of one ty pe to another. T utorials
1 1 . How many ways can an argument be passed to a subrout ine and explain AJAX Tutorials
t hem?- An argum ent can be passed in tw o way s. They are passing by v alue and Dealing w ith y our job
passing by reference. Passing by v alue: This m ethod copies the v alue of an argum ent Getting a job
into the form al param eter of the subroutine. Passing by reference: In this m ethod, a Jav aScript tutorials

techinterviews.com/master-list-of-java-i… 1/21
7/17/2010 Master list of Java interview questions - …
reference to an argum ent (not the v alue of the argum ent) is passed to the param eter. Job interv iew tips from Yahoo! HotJobs
1 2 . What is t he difference bet ween an argument and a paramet er?- While defining My SQL tutorials
m ethod, v ariables passed in the m ethod are called param eters. While using those Retiring from y our job
m ethods, v alues passed to those v ariables are called argum ents. Ruby on Rails tutorials
1 3 . What are different t y pes of access modifiers?- public: Any thing declared as Salary guide for IT jobs
public can be accessed from any where. priv ate: Any thing declared as priv ate can’t be Self-em ploy m ent
seen outside of its class. protected: Any thing declared as protected can be accessed by TechInterv iew s guides in PDF
classes in the sam e package and subclasses in the other packages. default m odifier : Can Understanding pointers
be accessed only to classes in the sam e package. XML Tutorials
1 4 . What is final, finalize() and finally ?- final : final key w ord can be used for class, XUL tutorials
m ethod and v ariables. A final class cannot be subclassed and it prev ents other
program m ers from subclassing a secure class to inv oke insecure m ethods. A final
m ethod can’t be ov erridden. A final v ariable can’t change from its initialized v alue. RSS Feeds
finalize() : finalize() m ethod is used just before an object is destroy ed and can be called All posts
just prior to garbage collection. finally : finally , a key word used in exception handling, All com m ents
creates a block of code that will be executed after a try /catch block has com pleted and
before the code following the try /catch block. The finally block will execute whether or
not an exception is thrown. For exam ple, if a m ethod opens a file upon exit, then y ou
will not w ant the code that closes the file to be by passed by the exception-handling
m echanism . This finally key word is designed to address this contingency .
1 5. What is UNICODE?- Unicode is used for internal representation of characters and
strings and it uses 1 6 bits to represent each other.
1 6 . What is Garbage Collect ion and how t o call it explicit ly ?- When an object is no
longer referred to by any v ariable, jav a autom atically reclaim s m em ory used by that
object. This is known as garbage collection. Sy stem . gc() m ethod m ay be used to call it
explicitly .
1 7 . What is finalize() met hod?- finalize () m ethod is used just before an object is
destroy ed and can be called just prior to garbage collection.
1 8. What are Transient and Volat ile Modifiers?- Transient: The transient m odifier
applies to v ariables only and it is not stored as part of its object’s Persistent state.
Transient v ariables are not serialized. Volatile: Volatile m odifier applies to v ariables
only and it tells the com piler that the v ariable m odified by v olatile can be changed
unexpectedly by other parts of the program .
1 9 . What is method ov erloading and met hod ov erriding?- Method ov erloading:
When a m ethod in a class hav ing the sam e m ethod nam e w ith different argum ents is
said to be m ethod ov erloading. Method ov erriding : When a m ethod in a class hav ing
the sam e m ethod nam e with sam e argum ents is said to be m ethod ov erriding.
20. What is difference bet ween ov erloading and overriding?- a) In ov erloading,
there is a relationship betw een m ethods av ailable in the sam e class whereas in
ov erriding, there is relationship between a superclass m ethod and subclass m ethod. b)
Ov erloading does not block inheritance from the superclass w hereas ov erriding blocks
inheritance from the superclass. c) In ov erloading, separate m ethods share the sam e
nam e w hereas in ov erriding, subclass m ethod replaces the superclass. d) Ov erloading
m ust hav e different m ethod signatures whereas ov erriding m ust hav e sam e signature.
2 1 . What is meant by Inherit ance and what are it s advant ages?- Inheritance is the
process of inheriting all the features from a class. The adv antages of inheritance are
reusability of code and accessibility of v ariables and m ethods of the super class by
subclasses.
22 . What is t he difference bet ween t his() and super()?- this() can be used to inv oke a
constructor of the sam e class whereas super() can be used to inv oke a super class
constructor.
23 . What is t he difference bet ween superclass and subclass?- A super class is a class
that is inherited w hereas sub class is a class that does the inheriting.
24 . What modifiers may be used wit h t op-lev el class?- public, abstract and final can
be used for top-lev el class.
2 5. What are inner class and anony mous class?- Inner class : classes defined in other
classes, including those defined in m ethods are called inner classes. An inner class can
hav e any accessibility including priv ate. Anony m ous class : Anony m ous class is a class
defined inside a m ethod without a nam e and is instantiated and declared in the sam e
place and cannot hav e explicit constructors.
26 . What is a package?- A package is a collection of classes and interfaces that prov ides a
high-lev el lay er of access protection and nam e space m anagem ent.
27 . What is a reflection package?- jav a. lang. reflect package has the ability to analy ze
itself in runtim e.
28. What is int erface and it s use?- Interface is sim ilar to a class which m ay contain
m ethod’s signature only but not bodies and it is a form al set of m ethod and constant
declarations that m ust be defined by the class that im plem ents it. Interfaces are useful
for: a)Declaring m ethods that one or m ore classes are expected to im plem ent
b)Capturing sim ilarities between unrelated classes without forcing a class relationship.
c)Determ ining an object’s program m ing interface w ithout rev ealing the actual body of

techinterviews.com/master-list-of-java-i… 2/21
7/17/2010 Master list of Java interview questions - …
the class.
29 . What is an abst ract class?- An abstract class is a class designed with
im plem entation gaps for subclasses to fill in and is deliberately incom plete.
3 0. What is t he difference bet ween Integer and int ?- a) Integer is a class defined in
the jav a. lang package, whereas int is a prim itiv e data ty pe defined in the Jav a
language itself. Jav a does not autom atically conv ert from one to the other. b) Integer
can be used as an argum ent for a m ethod that requires an object, whereas int can be
used for calculations.
3 1 . What is a cloneable int erface and how many met hods does it cont ain?- It is not
hav ing any m ethod because it is a TAGGED or MARKER interface.
3 2 . What is t he difference bet ween abst ract class and int erface?- a) All the
m ethods declared inside an interface are abstract w hereas abstract class m ust hav e at
least one abstract m ethod and others m ay be concrete or abstract. b) In abstract class,
key w ord abstract m ust be used for the m ethods whereas interface we need not use that
key word for the m ethods. c) Abstract class m ust hav e subclasses whereas interface
can’t hav e subclasses.
3 3 . Can you have an inner class inside a met hod and what v ariables can you
access?- Yes, we can hav e an inner class inside a m ethod and final v ariables can be
accessed.
3 4 . What is t he difference bet ween St ring and String Buffer?- a) String objects are
constants and im m utable whereas StringBuffer objects are not. b) String class supports
constant strings whereas StringBuffer class supports growable and m odifiable strings.
3 5. What is t he difference bet ween Array and v ector?- Array is a set of related data
ty pe and static whereas v ector is a growable array of objects and dy nam ic.
3 6 . What is t he difference bet ween except ion and error?- The exception class defines
m ild error conditions that y our program encounters. Exceptions can occur when
try ing to open the file, which does not exist, the network connection is disrupted,
operands being m anipulated are out of prescribed ranges, the class file y ou are
interested in loading is m issing. The error class defines serious error conditions that
y ou should not attem pt to recov er from . In m ost cases it is adv isable to let the program
term inate when such an error is encountered.
3 7 . What is t he difference bet ween process and t hread?- Process is a program in
execution whereas thread is a separate path of execution in a program .
3 8. What is mult it hreading and what are t he met hods for int er-t hread
communicat ion and what is t he class in which t hese met hods are defined?-
Multithreading is the m echanism in which m ore than one thread run independent of
each other w ithin the process. wait (), notify () and notify All() m ethods can be used for
inter-thread com m unication and these m ethods are in Object class. wait() : When a
thread executes a call to w ait() m ethod, it surrenders the object lock and enters into a
waiting state. notify () or notify All() : To rem ov e a thread from the w aiting state, som e
other thread m ust m ake a call to notify () or notify All() m ethod on the sam e object.
3 9 . What is t he class and int erface in jav a t o creat e t hread and which is t he most
advant ageous met hod?- Thread class and Runnable interface can be used to create
threads and using Runnable interface is the m ost adv antageous m ethod to create
threads because we need not extend thread class here.
40. What are t he st at es associat ed in the t hread?- Thread contains ready , running,
waiting and dead states.
4 1 . What is sy nchronizat ion?- Sy nchronization is the m echanism that ensures that
only one thread is accessed the resources at a tim e.
42 . When y ou will sy nchronize a piece of y our code?- When y ou expect y our code will
be accessed by different threads and these threads m ay change a particular data
causing data corruption.
43 . What is deadlock?- When two threads are waiting each other and can’t precede the
program is said to be deadlock.
44 . What is daemon t hread and which method is used t o creat e t he daemon
t hread?- Daem on thread is a low priority thread which runs interm ittently in the
back ground doing the garbage collection operation for the jav a runtim e sy stem .
setDaem on m ethod is used to create a daem on thread.
4 5. Are t here any global v ariables in Java, which can be accessed by ot her part of
your program?- No, it is not the m ain m ethod in w hich y ou define v ariables. Global
v ariables is not possible because concept of encapsulation is elim inated here.
46 . What is an applet ?- Applet is a dy nam ic and interactiv e program that runs inside a
web page display ed by a jav a capable brow ser.
47 . What is t he difference bet ween applicat ions and applets?- a)Application m ust
be run on local m achine w hereas applet needs no explicit installation on local m achine.
b)Application m ust be run explicitly w ithin a jav a-com patible v irtual m achine
whereas applet loads and runs itself autom atically in a jav a-enabled browser.
d)Application starts execution with its m ain m ethod whereas applet starts execution
with its init m ethod. e)Application can run with or without graphical user interface
whereas applet m ust run within a graphical user interface.

techinterviews.com/master-list-of-java-i… 3/21
7/17/2010 Master list of Java interview questions - …
48. How does applet recognize t he height and widt h?- Using getParam eters()
m ethod.
49 . When do y ou use codebase in applet ?- When the applet class file is not in the sam e
directory , codebase is used.
50. What is t he lifecycle of an applet ?- init() m ethod - Can be called when an applet is
first loaded start() m ethod - Can be called each tim e an applet is started. paint()
m ethod - Can be called when the applet is m inim ized or m axim ized. stop() m ethod -
Can be used when the brow ser m ov es off the applet’s page. destroy () m ethod - Can be
called when the browser is finished with the applet.
51 . How do y ou set securit y in applets?- using setSecurity Manager() m ethod
52 . What is an ev ent and what are t he models available for ev ent handling?- An
ev ent is an ev ent object that describes a state of change in a source. In other words,
ev ent occurs when an action is generated, like pressing button, clicking m ouse,
selecting a list, etc. There are two ty pes of m odels for handling ev ents and they are: a)
ev ent-inheritance m odel and b) ev ent-delegation m odel
53 . What are t he advant ages of t he model over t he ev ent-inheritance model?-
The ev ent-delegation m odel has two adv antages ov er the ev ent-inheritance m odel.
They are: a)It enables ev ent handling by objects other than the ones that generate the
ev ents. This allows a clean separation between a com ponent’s design and its use. b)It
perform s m uch better in applications where m any ev ents are generated. This
perform ance im prov em ent is due to the fact that the ev ent-delegation m odel does not
hav e to be repeatedly process unhandled ev ents as is the case of the ev ent-inheritance.
54 . What is source and list ener?- source : A source is an object that generates an ev ent.
This occurs when the internal state of that object changes in som e w ay . listener : A
listener is an object that is notified when an ev ent occurs. It has two m ajor
requirem ents. First, it m ust hav e been registered with one or m ore sources to receiv e
notifications about specific ty pes of ev ents. Second, it m ust im plem ent m ethods to
receiv e and process these notifications.
55. What is adapt er class?- An adapter class prov ides an em pty im plem entation of all
m ethods in an ev ent listener interface. Adapter classes are useful when y ou w ant to
receiv e and process only som e of the ev ents that are handled by a particular ev ent
listener interface. You can define a new class to act listener by extending one of the
adapter classes and im plem enting only those ev ents in which y ou are interested. For
exam ple, the MouseMotionAdapter class has two m ethods, m ouseDragged()and
m ouseMov ed(). The signatures of these em pty are exactly as defined in the
MouseMotionListener interface. If y ou are interested in only m ouse drag ev ents, then
y ou could sim ply extend MouseMotionAdapter and im plem ent m ouseDragged() .
56 . What is meant by controls and what are different t y pes of cont rols in AWT?-
Controls are com ponents that allow a user to interact w ith y our application and the
AWT supports the follow ing ty pes of controls: Labels, Push Buttons, Check Boxes, Choice
Lists, Lists, Scrollbars, Text Com ponents. These controls are subclasses of Com ponent.
57 . What is t he difference bet ween choice and list ?- A Choice is display ed in a
com pact form that requires y ou to pull it down to see the list of av ailable choices and
only one item m ay be selected from a choice. A List m ay be display ed in such a way
that sev eral list item s are v isible and it supports the selection of one or m ore list item s.
58. What is t he difference bet ween scrollbar and scrollpane?- A Scrollbar is a
Com ponent, but not a Container whereas Scrollpane is a Conatiner and handles its own
ev ents and perform its own scrolling.
59 . What is a layout manager and what are different t ypes of layout managers
av ailable in jav a AWT?- A lay out m anager is an object that is used to organize
com ponents in a container. The different lay outs are av ailable are FlowLay out,
BorderLay out, CardLay out, GridLay out and GridBagLay out.
60. How are t he element s of different layouts organized?- FlowLay out: The elem ents
of a FlowLay out are organized in a top to bottom , left to right fashion. BorderLay out:
The elem ents of a BorderLay out are organized at the borders (North, South, East and
West) and the center of a container. CardLay out: The elem ents of a CardLay out are
stacked, on top of the other, like a deck of cards. GridLay out: The elem ents of a
GridLay out are of equal size and are laid out using the square of a grid. GridBagLay out:
The elem ents of a GridBagLay out are organized according to a grid. Howev er, the
elem ents are of different size and m ay occupy m ore than one row or colum n of the grid.
In addition, the rows and colum ns m ay hav e different sizes.
6 1 . Which cont ainers use a Border lay out as t heir default lay out ?- Window, Fram e
and Dialog classes use a BorderLay out as their lay out.
62 . Which cont ainers use a Flow layout as t heir default layout ?- Panel and Applet
classes use the FlowLay out as their default lay out.
63 . What are wrapper classes?- Wrapper classes are classes that allow prim itiv e ty pes
to be accessed as objects.
64 . What are Vect or, Hasht able, LinkedList and Enumeration?- Vector : The
Vector class prov ides the capability to im plem ent a growable array of objects.
Hashtable : The Hashtable class im plem ents a Hashtable data structure. A Hashtable

techinterviews.com/master-list-of-java-i… 4/21
7/17/2010 Master list of Java interview questions - …
indexes and stores objects in a dictionary using hash codes as the object’s key s. Hash
codes are integer v alues that identify objects. LinkedList: Rem ov ing or inserting
elem ents in the m iddle of an array can be done using LinkedList. A LinkedList stores
each object in a separate link w hereas an array stores object references in consecutiv e
locations. Enum eration: An object that im plem ents the Enum eration interface
generates a series of elem ents, one at a tim e. It has tw o m ethods, nam ely
hasMoreElem ents() and nextElem ent(). HasMoreElem nts() tests if this enum eration
has m ore elem ents and nextElem ent m ethod returns successiv e elem ents of the series.
6 5. What is t he difference bet ween set and list ?- Set stores elem ents in an unordered
way but does not contain duplicate elem ents, whereas list stores elem ents in an ordered
way but m ay contain duplicate elem ents.
66 . What is a st ream and what are t he t ypes of St reams and classes of t he
St reams?- A Stream is an abstraction that either produces or consum es inform ation.
There are tw o ty pes of Stream s and they are: By te Stream s: Prov ide a conv enient
m eans for handling input and output of by tes. Character Stream s: Prov ide a
conv enient m eans for handling input & output of characters. By te Stream s classes: Are
defined by using tw o abstract classes, nam ely InputStream and OutputStream .
Character Stream s classes: Are defined by using two abstract classes, nam ely Reader
and Writer.
67 . What is t he difference bet ween Reader/Writ er and Input St ream/Out put
St ream?- The Reader/Writer class is character-oriented and the
InputStream /OutputStream class is by te-oriented.
68. What is an I/O filter?- An I/O filter is an object that reads from one stream and
writes to another, usually altering the data in som e way as it is passed from one stream
to another.
69 . What is serializat ion and deserializat ion?- Serialization is the process of writing
the state of an object to a by te stream . Deserialization is the process of restoring these
objects.
7 0. What is JDBC?- JDBC is a set of Jav a API for executing SQL statem ents. This API
consists of a set of classes and interfaces to enable program s to write pure Jav a
Database applications.
7 1 . What are drivers available?- a) JDBC-ODBC Bridge driv er b) Nativ e API Partly -
Jav a driv er c) JDBC-Net Pure Jav a driv er d) Nativ e-Protocol Pure Jav a driv er
7 2 . What is t he difference bet ween JDBC and ODBC?- a) OBDC is for Microsoft and
JDBC is for Jav a applications. b) ODBC can’t be directly used with Jav a because it uses
a C interface. c) ODBC m akes use of pointers which hav e been rem ov ed totally from
Jav a. d) ODBC m ixes sim ple and adv anced features together and has com plex options
for sim ple queries. But JDBC is designed to keep things sim ple while allowing adv anced
capabilities w hen required. e) ODBC requires m anual installation of the ODBC driv er
m anager and driv er on all client m achines. JDBC driv ers are written in Jav a and
JDBC code is autom atically installable, secure, and portable on all platform s. f) JDBC
API is a natural Jav a interface and is built on ODBC. JDBC retains som e of the basic
features of ODBC.
7 3 . What are t he t ypes of JDBC Driv er Models and explain t hem?- There are two
ty pes of JDBC Driv er Models and they are: a) Tw o tier m odel and b) Three tier m odel
Tw o tier m odel: In this m odel, Jav a applications interact directly with the database. A
JDBC driv er is required to com m unicate w ith the particular database m anagem ent
sy stem that is being accessed. SQL statem ents are sent to the database and the results
are giv en to user. This m odel is referred to as client/serv er configuration where user is
the client and the m achine that has the database is called as the serv er. Three tier
m odel: A m iddle tier is introduced in this m odel. The functions of this m odel are: a)
Collection of SQL statem ents from the client and handing it ov er to the database, b)
Receiv ing results from database to the client and c) Maintaining control ov er accessing
and updating of the abov e.
7 4 . What are t he st eps involv ed for making a connect ion wit h a dat abase or how
do you connect t o a database?a) Loading the driv er : To load the driv er, Class.
forNam e() m ethod is used. Class. forNam e(”sun. jdbc. odbc. JdbcOdbcDriv er”); When
the driv er is loaded, it registers itself w ith the jav a. sql. Driv erManager class as an
av ailable database driv er. b) Making a connection with database: To open a connection
to a giv en database, Driv erManager. getConnection() m ethod is used. Connection con =
Driv erManager. getConnection (”jdbc:odbc:som edb”, “u ser”, “password”); c) Executing
SQL statem ents : To execute a SQL query , jav a. sql. statem ents class is used.
createStatem ent() m ethod of Connection to obtain a new Statem ent object. Statem ent
stm t = con. createStatem ent(); A query that returns data can be executed using the
executeQuery () m ethod of Statem ent. This m ethod executes the statem ent and returns
a jav a. sql. ResultSet that encapsulates the retriev ed data: ResultSet rs = stm t.
executeQuery (”SELECT * FROM som e table”); d) Process the results : ResultSet returns
one row at a tim e. Next() m ethod of ResultSet object can be called to m ov e to the next
row. The getString() and getObject() m ethods are used for retriev ing colum n v alues:
while(rs. next()) { String ev ent = rs. getString(”ev ent”); Object count = (Integer) rs.

techinterviews.com/master-list-of-java-i… 5/21
7/17/2010 Master list of Java interview questions - …
getObject(”count”);
7 5. What t ype of driver did you use in project ?- JDBC-ODBC Bridge driv er (is a driv er
that uses nativ e(C language) libraries and m akes calls to an existing ODBC driv er to
access a database engine).
7 6 . What are t he t ypes of st at ement s in JDBC?- Statem ent: to be used
createStatem ent() m ethod for executing single SQL statem ent PreparedStatem ent — To
be used preparedStatem ent() m ethod for executing sam e SQL statem ent ov er and ov er.
CallableStatem ent — To be used prepareCall() m ethod for m ultiple SQL statem ents
ov er and ov er.
7 7 . What is st ored procedure?- Stored procedure is a group of SQL statem ents that
form s a logical unit and perform s a particular task. Stored Procedures are used to
encapsulate a set of operations or queries to execu te on database. Stored procedures can
be com piled and executed with different param eters and results and m ay hav e any
com bination of input/output param eters.
7 8. How t o creat e and call stored procedures?- To create stored procedures: Create
procedure procedurenam e (specify in, out and in out param eters) BEGIN Any m ultiple
SQL statem ent; END; To call stored procedures: CallableStatem ent csm t = con.
prepareCall(”{call procedure nam e(?,?)}”); csm t. registerOutParam eter(colum n no. ,
data ty pe); csm t. setInt(colum n no. , colum n nam e) csm t. execute();
7 9 . What is servlet ?- Serv lets are m odules that extend request/response-oriented
serv ers, such as jav a-enabled web serv ers. For exam ple, a serv let m ight be responsible
for taking data in an HTML order-entry form and apply ing the business logic used to
update a com pany ’s order database.
80. What are t he classes and int erfaces for serv let s?- There are two packages in
serv lets and they are jav ax. serv let and
81 . What is t he difference bet ween an applet and a servlet ?- a) Serv lets are to
serv ers what applets are to browsers. b) Applets m u st hav e graphical user interfaces
whereas serv lets hav e no graphical user interfaces.
82 . What is t he difference bet ween doPost and doGet met hods?- a) doGet() m ethod
is used to get inform ation, w hile doPost() m ethod is used for posting inform ation. b)
doGet() requests can’t send large am ount of inform ation and is lim ited to 2 40-2 55
characters. Howev er, doPost()requests passes all of its data, of unlim ited length. c) A
doGet() request is appended to the request URL in a query string and this allow s the
exchange is v isible to the client, whereas a doPost() request passes directly ov er the
socket connection as part of its HTTP request body and the exchange are inv isible to the
client.
83 . What is t he life cy cle of a servlet ?- Each Serv let has the sam e life cy cle: a) A serv er
loads and initializes the serv let by init () m ethod. b) The serv let handles zero or m ore
client’s requests through serv ice() m ethod. c) The serv er rem ov es the serv let through
destroy () m ethod.
84 . Who is loading t he init () met hod of serv let ?- Web serv er
85. What are t he different serv ers av ailable for dev eloping and deploy ing
Servlet s?- a) Jav a Web Serv er b) JRun g) Apache Serv er h) Netscape Inform ation
Serv er i) Web Logic
86 . How many ways can we t rack client and what are t hey ?- The serv let API
prov ides two way s to track client state and they are: a) Using Session tracking and b)
Using Cookies.
87 . What is session t racking and how do y ou t rack a user session in servlet s?-
Session tracking is a m echanism that serv lets use to m aintain state about a series
requests from the sam e user across som e period of tim e. The m ethods used for session
tracking are: a) User Authentication - occurs when a web serv er restricts access to
som e of its resources to only those clients that log in using a recognized usernam e and
passw ord. b) Hidden form fields - fields are added to an HTML form that are not
display ed in the client’s brow ser. When the form containing the fields is subm itted, the
fields are sent back to the serv er. c) URL rewriting - ev ery URL that the user clicks on is
dy nam ically m odified or rew ritten to include extra inform ation. The extra
inform ation can be in the form of extra path inform ation, added param eters or som e
custom , serv er-specific URL change. d) Cookies - a bit of inform ation that is sent by a
web serv er to a browser and w hich can later be read back from that browser. e)
HttpSession- places a lim it on the num ber of sessions that can exist in m em ory . This
lim it is set in the session. m axresidents property .
88. What is Serv er-Side Includes (SSI)?- Serv er-Side Includes allows em bedding
serv lets within HTML pages using a special serv let tag. In m any serv lets that support
serv lets, a page can be processed by the serv er to include output from serv lets at
certain points inside the HTML page. This is accom plished using a special internal
SSINCLUDE, which processes the serv let tags. SSINCLUDE serv let will be inv oked
whenev er a file w ith an. shtm l extension is requested. So HTML files that include
serv er-side includes m ust be stored with an . shtm l extension.
89 . What are cookies and how will y ou use t hem?- Cookies are a m echanism that a
serv let uses to hav e a client hold a sm all am ount of state-inform ation associated with

techinterviews.com/master-list-of-java-i… 6/21
7/17/2010 Master list of Java interview questions - …
the user. a) Create a cookie w ith the Cookie constructor: public Cookie(String nam e,
String v alue) b) A serv let can send a cookie to the client by passing a Cookie object to
the addCookie() m ethod of HttpServ letResponse: public v oid HttpServ letResponse.
addCookie(Cookie cookie) c) A serv let retriev es cookies by calling the getCookies()
m ethod of HttpServ letRequest: public Cookie[ ] HttpServ letRequest. getCookie().
90. Is it possible t o communicat e from an applet t o serv let and how many way s
and how?- Yes, there are three way s to com m unicate from an applet to serv let and
they are: a) HTTP Com m unication(Text-based and object-based) b) Socket
Com m unication c) RMI Com m unication
9 1 . What is connect ion pooling?- With serv lets, opening a database connection is a
m ajor bottleneck because we are creating and tearing dow n a new connection for ev ery
page request and the tim e taken to create connection will be m ore. Creating a
connection pool is an ideal approach for a com plicated serv let. With a connection pool,
we can duplicate only the resources we need to duplicate rather than the entire serv let.
A connection pool can also intelligently m anage the size of the pool and m ake sure each
connection rem ains v alid. A num ber of connection pool packages are currently
av ailable. Som e like DbConnectionBroker are freely av ailable from Jav a Exchange
Works by creating an object that dispenses connections and connection Ids on request.
The ConnectionPool class m aintains a Hastable, using Connection objects as key s and
Boolean v alues as stored v alues. The Boolean v alue indicates whether a connection is in
use or not. A program calls getConnection() m ethod of the ConnectionPool for getting
Connection object it can use; it calls returnConnection() to giv e the connection back to
the pool.
92 . Why should we go for int erserv let communicat ion?- Serv lets running together
in the sam e serv er com m unicate with each other in sev eral way s. The three m ajor
reasons to use interserv let com m unication are: a) Direct serv let m anipulation - allows
to gain access to the other currently loaded serv lets and perform certain tasks (through
the Serv letContext object) b) Serv let reuse - allow s the serv let to reuse the public
m ethods of another serv let. c) Serv let collaboration - requires to com m unicate w ith
each other by sharing specific inform ation (through m ethod inv ocation)
93 . Is it possible t o call servlet wit h paramet ers in the URL?- Yes. You can call a
serv let with param eters in the sy ntax as (?Param 1 = xxx || m 2 = y y y ).
94 . What is Serv let chaining?- Serv let chaining is a technique in which two or m ore
serv lets can cooperate in serv icing a single request. In serv let chaining, one serv let’s
output is piped to the next serv let’s input. This process continues until the last serv let is
reached. Its output is then sent back to the client.
9 5. How do serv let s handle multiple simult aneous request s?- The serv er has
m ultiple threads that are av ailable to handle requests. When a request com es in, it is
assigned to a thread, which calls a serv ice m ethod (for exam ple: doGet(), doPost() and
serv ice()) of the serv let. For this reason, a single serv let object can hav e its serv ice
m ethods called by m any threads at once.
96 . What is t he difference bet ween TCP/IP and UDP?- TCP/IP is a tw o-way
com m unication between the client and the serv er and it is a reliable and there is a
confirm ation regarding reaching the m essage to the destination. It is like a phone call.
UDP is a one-way com m unication only between the client and the serv er and it is not a
reliable and there is no confirm ation regarding reaching the m essage to the
destination. It is like a postal m ail.
97 . What is Inet address?- Ev ery com puter connected to a network has an IP address. An
IP address is a num ber that uniquely identifies each com puter on the Net. An IP
address is a 3 2 -bit num ber.
98. What is Domain Naming Serv ice(DNS)?- It is v ery difficult to rem em ber a set of
num bers(IP address) to connect to the Internet. The Dom ain Nam ing Serv ice(DNS) is
used to ov ercom e this problem . It m aps one particular IP address to a string of
characters. For exam ple, w ww. m ascom . com im plies com is the dom ain nam e
reserv ed for US com m ercial sites, m oscom is the nam e of the com pany and w ww is the
nam e of the specific com puter, which is m ascom ’s serv er.
99 . What is URL?- URL stands for Uniform Resource Locator and it points to resource files
on the Internet. URL has four com ponents: http://ww w. address. com :80/index.htm l,
where http - protocol nam e, address - IP address or host nam e, 80 - port num ber and
index.htm l - file path.
1 00. What is RMI and st eps involv ed in developing an RMI object?- Rem ote Method
Inv ocation (RMI) allows jav a object that executes on one m achine and to inv oke the
m ethod of a Jav a object to execute on another m achine. The steps inv olv ed in
dev eloping an RMI object are: a) Define the interfaces b) Im plem enting these interfaces
c) Com pile the interfaces and their im plem entations with the jav a com piler d) Com pile
the serv er im plem entation w ith RMI com piler e) Run the RMI registry f) Run the
application
1 01 . What is RMI archit ect ure?- RMI architecture consists of four lay ers and each lay er
perform s specific functions: a) Application lay er - contains the actual object definition.
b) Proxy lay er - consists of stub and skeleton. c) Rem ote Reference lay er - gets the

techinterviews.com/master-list-of-java-i… 7/21
7/17/2010 Master list of Java interview questions - …
stream of by tes from the transport lay er and sends it to the proxy lay er. d)
Transportation lay er - responsible for handling the actual m achine-to-m achine
com m unication.
1 02 . what is Unicast Remot eObject ?- All rem ote objects m ust extend
UnicastRem oteObject, w hich prov ides functionality that is needed to m ake objects
av ailable from rem ote m achines.
1 03 . Explain t he met hods, rebind() and lookup() in Naming class?- rebind() of the
Nam ing class(found in jav a. rm i) is used to update the RMI registry on the serv er
m achine. Nam ing. rebind(”AddSev er”, AddServ erIm pl); lookup() of the Nam ing class
accepts one argum ent, the rm i URL and returns a reference to an object of ty pe
AddServ erIm pl.
1 04 . What is a Jav a Bean?- A Jav a Bean is a software com ponent that has been designed
to be reusable in a v ariety of different env ironm ents.
1 05. What is a Jar file?- Jar file allows to efficiently deploy ing a set of classes and their
associated resources. The elem ents in a jar file are com pressed, which m akes
dow nloading a Jar file m uch faster than separately downloading sev eral uncom pressed
files. The package jav a. util. zip contains classes that read and write jar files.
1 06 . What is BDK?- BDK, Bean Dev elopm ent Kit is a tool that enables to create, configure
and connect a set of set of Beans and it can be used to test Beans w ithout writing a code.
1 07 . What is JSP?- JSP is a dy nam ic scripting capability for web pages that allow s Jav a as
well as a few special tags to be em bedded into a web file (HTML/XML, etc). The suffix
traditionally ends with .jsp to indicate to the web serv er that the file is a JSP files. JSP
is a serv er side technology - y ou can’t do any client side v alidation with it. The
adv antages are: a) The JSP assists in m aking the HTML m ore functional. Serv lets on
the other hand allow outputting of HTML but it is a tedious process. b) It is easy to m ake
a change and then let the JSP capability of the web serv er y ou are using deal with
com piling it into a serv let and running it.
1 08. What are JSP script ing element s?- JSP scripting elem ents lets to insert Jav a code
into the serv let that w ill be generated from the current JSP page. There are three
form s: a) Expressions of the form < %= expression %> that are ev aluated and inserted
into the output, b) Scriptlets of the form that are inserted into the serv let’s serv ice
m ethod, and c) Declarations of the form < %! Code %> that are inserted into the body of
the serv let class, outside of any existing m ethods.
1 09 . What are JSP Direct iv es?- A JSP directiv e affects the ov erall structure of the serv let
class. It usually has the following form :< %@ directiv e attribute= ”v alue” %> Howev er,
y ou can also com bine m ultiple attribute settings for a single directiv e, as follows:< %@
directiv e attribute1 = ”v alue1 ″ attribute 2= ”v alue2″ . . . attributeN = ”v alueN” %>
There are tw o m ain ty pes of directiv e: page, which lets to do things like im port classes,
custom ize the serv let superclass, and the like; and include, which lets to insert a file
into the serv let class at the tim e the JSP file is translated into a serv let
1 1 0. What are Predefined variables or implicit object s?- To sim plify code in JSP
expressions and scriptlets, w e can use eight autom atically defined v ariables, som etim es
called im plicit objects. They are request, response, out, session, application, config,
pageContext, and page.
1 1 1 . What are JSP ACTIONS?- JSP actions use constructs in XML sy ntax to control the
behav ior of the serv let engine. You can dy nam ically insert a file, reuse Jav aBeans
com ponents, forw ard the user to another page, or generate HTML for the Jav a plugin.
Av ailable actions include: jsp:include - Include a file at the tim e the page is requested.
jsp:useBean - Find or instantiate a Jav aBean. jsp:setProperty - Set the property of a
Jav aBean. jsp:getProperty - Insert the property of a Jav aBean into the output.
jsp:forw ard - Forward the requester to a newpage. Jsp: plugin - Generate browser-
specific code that m akes an OBJECT or EMBED
1 1 2 . How do y ou pass dat a (including Jav aBeans) t o a JSP from a servlet ?- (1 )
Request Lifetim e: Using this technique to pass beans, a request dispatcher (using either
“include” or forward”) can be called. This bean will disappear after processing this
request has been com pleted. Serv let: request. setAttribute(”theBean”, m y Bean);
RequestDispatcher rd = getServ letContext(). getRequ estDispatcher(”thepage. jsp”); rd.
forward(request, response); JSP PAGE:< jsp: useBean id= ”theBean” scope= ”request”
class= ”. . . . . ” /> (2) Session Lifetim e: Using this technique to pass beans that are
relev ant to a particular session (such as in indiv idual user login) ov er a num ber of
requests. This bean w ill disappear w hen the session is inv alidated or it tim es out, or
when y ou rem ov e it. Serv let: HttpSession session = request. getSession(true); session.
putValue(”theBean”, m y Bean); /* You can do a request dispatcher here, or just let the
bean be v isible on the next request */ JSP Page:< jsp:useBean id= ”theBean”
scope= ”session” class= ”. . . ” /> 3 ) Application Lifetim e: Using this technique to pass
beans that are relev ant to all serv lets and JSP pages in a particular app, for all users.
For exam ple, I use this to m ake a JDBC connection pool object av ailable to the v arious
serv lets and JSP pages in m y apps. This bean will disappear when the serv let engine is
shut down, or when y ou rem ov e it. Serv let: GetServ letContext().
setAttribute(”theBean”, m y Bean); JSP PAGE:< jsp:useBean id= ”theBean”

techinterviews.com/master-list-of-java-i… 8/21
7/17/2010 Master list of Java interview questions - …
scope= ”application” class= ”. . . ” />
1 1 3 . How can I set a cookie in JSP?- response. setHeader(”Set-Cookie”, “cookie string”); To
giv e the response-object to a bean, write a m ethod setResponse (HttpServ letResponse
response) - to the bean, and in jsp-file:< % bean. setResponse (response); %>
1 1 4 . How can I delet e a cookie wit h JSP?- Say that I hav e a cookie called “foo, ” that I set
a while ago & I want it to go away . I sim ply : < % Cookie killCookie = new Cookie(”foo”,
null); KillCookie. setPath(”/”); killCookie. setMaxAge(0); response.
addCookie(killCookie); %>
1 1 5. How are Servlet s and JSP Pages relat ed?- JSP pages are focused around HTML (or
XML) with Jav a codes and JSP tags inside them . When a web serv er that has JSP
support is asked for a JSP page, it checks to see if it has already com piled the page into a
serv let. Thus, JSP pages becom e serv lets and are transform ed into pure Jav a and then
com piled, loaded into the serv er and executed.

T h is en t r y w a s post ed in Jav a. Book m a r k t h e perm alink . Po s t a co m m ent or lea v e a t r a ck ba ck :


Trackback URL.

« Som e VB interv iew questions General UNIX interv iew questions »

americanexpress.com/india Ads by Google

4 4 C OMME NT S ON MA S T E R LIST OF JA V A INT E R V IE W QUE S T IONS


- 115 QUE ST IONS

Dhananjay
Posted 8/1/2005 at 4:15 am | Pe rmalink

Any application dev eloped in JAVA and using nativ e code will be plateform
independent ?

dhinesh
Posted 8/8/2005 at 7:08 am | Pe rmalink

Actually in jav a no operator ov erloading.but we are using increm ent(+ + ) and


decrem ent(–) operator.this also operator ov erloading. why that contradiction?

dhinesh
Posted 8/8/2005 at 7:11 am | Pe rmalink

Actually in jav a no operator ov erloading.but we are using increm ent(+ + ) and


decrem ent(†“-) operator.this also operator ov erloading. why that
contradiction?

techinterviews.com/master-list-of-java-i… 9/21
7/17/2010 Master list of Java interview questions - …

KOtresh
Posted 8/13/2005 at 12:19 am | Pe rmalink

There is no operator ov erloading in JAVA, but operator + is used as arithm etic


addition and concatination operator. why ? pls clarify this

srinivasulu
Posted 8/26/2005 at 12:31 am | Pe rmalink

difference Serv letContext and PageContext

Kotresh
Posted 8/31/2005 at 5:15 am | Pe rmalink

Default Lay out for Jfram e(swings)?

Ajay
Posted 9/19/2005 at 12:34 am | Pe rmalink

difference between Directiv e and action

Siya
Posted 10/27/2005 at 3:56 pm | Pe rmalink

I don’t know where this site has been all m y life!!!It has clear answers to alm ost
ev ery question rev olv ing around Jav a.Keep it up!

Prabhakar Peri
Posted 11/18/2005 at 1:16 am | Pe rmalink

Hi all, this is the reply to questions 2,3 , and 4 .

“Operator ov erloading is not av ailable in Jav a” does not m ean that there is no
operator ov erloading in Jav a. It m ean that the program m er cannot im plem ent
operator ov erloading. It is in built av ailable in the language.

Actually y ou cannot find any program m ing language w ithout operator


ov erloading. Strictly no program m ing language is excem pted. Hav e a look at
the following exam ple.

3+2
2 .5 + 3 .0

These two expressions can be processed by any language. The sam e + sy m bol is
used to add two integral num bers as well as to add two real num bers. Is it not
ov erloading? The + operator is ov erloaded to operate on integrals and real
num bers. This applies to all languages.

Hence, operator ov erloading is there in Jav a, but in built. It cannot be extended


by the program m er as y ou can do in C+ + .

techinterviews.com/master-list-of-java-i… 10/21
7/17/2010 Master list of Java interview questions - …

Ed Parrish
Posted 11/18/2005 at 6:19 pm | Pe rmalink

Question 3 2 has an incorrect answer. Jav a does not require an abstract m ethod
to m ake an abstract class. Jav a only requires the key word abstract. Also, y our
point c) would be better stated that abstract classes m ust hav e subclasses
whereas interfaces m ust be im plem ented.

Yelena Cherdak
Posted 12/1/2005 at 11:26 am | Pe rmalink

Question 82 is not correct. You wrote:


What is the difference between doPost and doGet m ethods?

> > > doPost and doGet m ethods are serv let m ethods that respond to GET and
POST HTTP requests. And y our explanation is correct if y ou talk about
differences between GET and POST HTTP requests. Serv let m ethods are called
on Serv er side and work with requests objects on the serv er retriev ing data
from requests and
perform whatev er business logic is required.

- a) doGet() m ethod is used to get inform ation, while doPost() m ethod is used for
posting inform ation. b) doGet() requests can†™t send large am ount of
inform ation and is lim ited to 24 0-255 characters. Howev er, doPost()requests
passes all of its data, of unlim ited length. c) A doGet() request is appended to the
request URL in a query string and this allows the exchange is v isible to the
client, whereas a doPost() request passes directly ov er the socket connection as
part of its HTTP request body and the exchange are inv isible to the client.

KingKoder
Posted 4/23/2006 at 2:20 pm | Pe rmalink

Geez, this list of questions answered m ore of m y qu estions than the 4 jav a books
I own.

siva rama krishna


Posted 5/23/2006 at 1:36 am | Pe rmalink

Still som e basics need to cov ered like SWING VS AWT etc…

Durgaprasad
Posted 6/8/2006 at 3:45 pm | Pe rmalink

serv let context contains the serv let’s v iew of web application within which
serv let is running and it can be used to log ev ents etc where as page context
prov ides access to all the nam espaces associated w ith a JSP page and access to
sev eral page attributes

Azhar
Posted 7/6/2006 at 12:25 pm | Pe rmalink

Great questions.You dont hav e to open up book if y ou are preparing for an


interv iew.

techinterviews.com/master-list-of-java-i… 11/21
7/17/2010 Master list of Java interview questions - …

Samrat
Posted 10/16/2006 at 6:45 am | Pe rmalink

There is an wrong in Q 3 2..


Q3 2 )What is the difference betw een abstract class and interface?-
Answer: All the m ethods declared inside an interface are abstract whereas
abstract class m ust hav e at least one abstract m ethod and others m ay be
concrete or abstract.

As far m y knowledge,
abstract class m ust hav e at least one abstract m ethod is wrong.But the v ice-
v ersa is true.If there is an abstract m ethod in a class,y ou m ust hav e to declare
that class as abstract class.
Abstract class m ay or m ay not contain abstract class.

sowmya
Posted 10/27/2006 at 7:14 am | Pe rmalink

Can any body explain m e about HashTable,hashCode() in jav a.If possible with
som e sim ple code exam ple.Plz let m e know .
Thanks

jlk
Posted 12/6/2006 at 2:24 am | Pe rmalink

TCP/IP can not be com pared to UDP. Both TCP and UDP sit at lay er 3 ov er IP.

Prapti
Posted 1/11/2007 at 1:56 am | Pe rmalink

To answ er Dinesh’s question:


It is true that in Jav a, we don’t hav e Operator Ov erloading. That m eans a user
can not perform operator ov erloading operations him self, like we do in C+ + .
But internally Jav a has it’s operator ov erloading behav iors or m ethods defines,
which can be utilized by the user.To be m ore clear, user can not create their
own operator ov erloading program s.

Sam e way , in Jav a, there is no pointer concept as w e hav e in C. But we do hav e


object references. So, here the approach is different, w hich is explained.

amrita
Posted 2/21/2007 at 2:12 pm | Pe rmalink

the answer regarding interface and abstract class is still not clear. w hich is
correct?

KOT RESH
Posted 2/23/2007 at 12:30 am | Pe rmalink

Can v instantiate Math class?

techinterviews.com/master-list-of-java-i… 12/21
7/17/2010 Master list of Java interview questions - …

chinmay
Posted 3/7/2007 at 6:52 am | Pe rmalink

exam ple of interface:

public interface aa
{
public v oid do( );//abstract m ethods,but no need
public v oid show( );//to use abstract key word
}

public class bb im plem ents aa


{
public v oid do( )
{
//declaration part
}
public v oid show( )
{
//declaration part
}
}

exam ple of abstract class:

public abstract class aa


{
public v oid do()// non static m ethod
{
//declaration part
}
abstract v oid show ();
}
public class bb extends aa
{
v oid show( )
{
//declaration part
}
}

martinus
Posted 4/5/2007 at 3:31 pm | Pe rmalink

I think m ost of these questions are only useful when y ou need a brainless coder.
When y ou want som ebody w ho really knows what he is doing, I w ould ask
som ething along these questions:

* Show m e a sam ple of y our work


* Do y ou use test driv en dev elopm ent? Why / Why not?
* What other program m ing languages do y ou know?
* What do y ou like, what do y ou hate about Jav a?
* What im portant design patterns do y ou use?
* Do y ou work with JUnit, Checksty le, PMD, Findbugs, etc?

Looser
Posted 4/16/2007 at 3:28 am | Pe rmalink

Hey m artinus,
You are talking v ery high lev el. Dont u know that u need to know all these
things before coding. Design patterns and unit testing com es later. If the code
sty le and standards are bad, w hat is the use of doing such w ork which will not

techinterviews.com/master-list-of-java-i… 13/21
7/17/2010 Master list of Java interview questions - …
be scalable.
Please do answer y our own questions in this forum , except for the first one so
that ev ery body else can know what y ou(and probably people like y ou) would
expect.

Madan
Posted 5/21/2007 at 12:50 am | Pe rmalink

Connection con= Driv erManager.getConnection(url).


please explain this one in Interfaces.

sumit
Posted 5/26/2007 at 10:47 am | Pe rmalink

Diff between abstract class and interface


abstract class m ay contain non abstract m ethods where as m ethods in interface
are abstract.
when class is declared abstract,it m ust hav e atleast 1 abstract m ethod

velavan
Posted 7/12/2007 at 2:29 am | Pe rmalink

what ty pe data can be stored in cookies?


can store by te data in cookies?
how can store int data in cookies?
can send int data through doget() ?

Marcus
Posted 7/26/2007 at 7:28 pm | Pe rmalink

Martinus is correct although for the sake of the people reading he probably
should hav e went into m ore detail about the point he was m aking.

I’m a Jav a Architect and hav e been for m any y ears for com panies such as IBM,
BellSouth etc…. and what I found is that the people who are asking these I/O
and basic language lev el questions can’t answer the questions them selv es. Who
care if y ou know all the im plicit v ariables and etc… The question is can y ou use
them and ev en better y et, how fast on y ou on finding the inform ation y ou need.
I could probably write a book on Jav a or C+ + but how m any people can retain
all the inform ation related to a language like Jav a. I’v e nev er seen a seasoned
dev eloper in an interv iew throw out questions like explain the difference
between abstract and interface! Nobody cares if y ou can m em orize it! The
question is do y ou truely understand the concept of OO program m ing and can
y ou use it.

I’v e seen dev elopers under m e com e to an interv iew session with 50 questions
that they them selv es downloaded from the internet and hav e the nerv e to try
and rattle a potential em ploy ee. Once they ask the question I usually ask them
to elaborate on the correct answer. That stopped it ev ery tim e. Nev er condem
som eone for som ething y ou are lacking in y ourself.

Deepak Kalra
Posted 8/20/2007 at 8:14 am | Pe rmalink

Difference between Interface & Abstract Class

techinterviews.com/master-list-of-java-i… 14/21
7/17/2010 Master list of Java interview questions - …
First Definition of both.

Interface–> This is an pure abstract class. Means that a class which has all the
functions as abstract.

Abstract Class–> This is a class w hich has zero or m ore function declared as
abstract. By abstract it m eans that the abstract key w ord should be there w hich
the function signature & also no im plem entation should be giv en for the
function. i.e. public v oid function(); No opening ‘}’ & No closing ‘}’.

now why we need these 2 different things when they look alm ost sam e?

These two things looks alm ost like but they are not totally sam e. The situations
they are used is totally different. take the exam ple of ev ents in AWT. All the
listeners are interfaces. Interfaces are v ery well suited for the env ironm ent
where y ou hav e to im plem ent call back m echanism .

You can also look at this way that when y ou hav e im plem entation for few of the
functions of y ou class & rem aining functionality depends on the env ironm ent
or depends on the client who is using use abstract class. Also y ou can use
abstract class when y ou hav e im plem entation for all y ou functions but the use
of it depends on the client by adding som e feature to it.

You can use interface when y ou hav e no im plem entation with y ou.

Now i know y ou all will raise a question that then w hy not to use abstract class
as interface?
Well i hav e an answer for that too but y ou try it. Hint: Multiple Inheritance.

Bikram Singh
Posted 9/14/2007 at 10:50 pm | Pe rmalink

Well, To decide whether to use Interfaces or Abstract classes :


Go for abstract classes if for som e of the m ethods y ou want to prov ide the
im plem entation and som e y ou want to be im plem ented by the subclasses.

Interfaces are good when y ou w ant to declare constants throughout the


application and to im plem ent best coding practices (That 1 0 different
dev elopers working on different m odules of sam e application, will use sam e
m ethods nam e and constants nam e).

Abov e all, use Interfaces w hen u want to use any other superclass in ur class.

Joe Blow
Posted 1/3/2008 at 9:04 am | Pe rmalink

Well,

As an interv iew er, I don’t ask any of these questions, since it’s just a
m em orization process and any body can read and rem em ber answers to these
questions before an interv iew . So during m y interv iews candidates w rite code
and discuss what they did. Based on that I grade them , like on a written/v erbal
exam . This shows m e that a person can think. Based on that I m ake m y
decision. So if a person can’t solv e (note: doesn’t hav e to be com pletely correct)
not com plicating problem and can’t discuss ab what, how and why he or she did
som ething, that person is out the door. I usually look for people who can think
and explain w hat they did and just m em orize the answers.

….

peter lawrey

techinterviews.com/master-list-of-java-i… 15/21
7/17/2010 Master list of Java interview questions - …
Posted 3/14/2008 at 4:43 am | Pe rmalink

> What is the difference between Assignm ent and Initialization?

Proper initialization is only done once. Howev er, y ou can access a v ariable
before it has been properly initialised. If y ou do this y ou see the default
initialisation v alue for the v ariable or constant.

e.g.
static {
       Sy stem .out.println("TEXT= "+ getText());
   }

   public static String getTextProperty () {


       return Sy stem .getProperty ("text","Hello World" );
   }

   public static final String TEXT = getTextProperty ();

   public static String getText() {


       return TEXT;
   }

   static {


       Sy stem .out.println("TEXT= "+ getText());
   }

   public static v oid m ain(String… args) {

   }

This prints

TEXT= null
TEXT= Hello World

> What is casting?- Casting is used to conv ert the v alue of one ty pe to another

Casting prim ativ es conv erts the ty pe (changes it)


Casting objects just checks the object is an instanceof the Class, but doesn’t
conv ert or alter it.

> How m any way s can an argum ent be passed to a subroutine and explain
them ?

An argum ent can be passed to a m ethod by setting a field and then calling the
m ethod. This is com m on in Factory objects w here v alues in the factory are set
first and then a creation m ethod is called. (rather hav e a m ethod for ev ery
possible com bination of argum ents y ou could prov ide)

As argum ent can be passed by context. The sim plest exam ple is
Sy stem .getProperties(), howev er m ost IOC containers hav e their own m ore
flexible way of doing this.

> What are different ty pes of access m odifiers?

The default (no m odifier) for an interface is the sam e as public.

> What is Garbage Collection and how to call it explicitly ?- When an object is no
longer referred to by any v ariable,…

Actually w hen the v ariable is unreachable it is collected.


e.g. say A refers to B and B refers to A, but nother else does. This will be
cleaned up ev en though these obejcts hav e references to them .

> What is finalize() m ethod?

The finalize() m ethod can be called at any tim e. Howev er it should be
called before being cleaned up,, but this is not gu arenteed.

techinterviews.com/master-list-of-java-i… 16/21
7/17/2010 Master list of Java interview questions - …
> What is the difference between String and String Buffer?

StringBuilder is prefered to StringBuffer from Jav a 5 as it is not sy nchronized.


A feature of Jav a 7 called escape analy sis should m ean the JVM can workout
that sy nchronization is not required in m any cases, but there is som e doubt
that it prov ides the perform ance im prov em ent claim ed.

> What are the states associated in the thread?

As of Jav a 5, The states of a Thread are defined in Thread.State. These are


NEW, RUNNABLE, BLOCKED, WAITING, TIMED_WAITING, TERMINATED.

> What is daem on thread and which m ethod is used to create the daem on
thread?- Daem on thread is a low priority thread

There are a num ber of dem on threads and a Thread has the priority it is giv en,
regardless of whether it is a dem on or not.

> Any application dev eloped in JAVA and using nativ e code will be plateform
independent ?
No. som e operations are platform dependant. E.g. Ru ntim e.exec() depends on
what com m ands y ou hav e installed.

> we are using increm ent(+ + ) and decrem ent(†“) operator.this also
operator ov erloading

It isn’t ov erloaded, it is part of the language.

> abstract class m ust hav e at least one abstract m ethod.


> … when class is declared abstract,it m ust hav e atleast 1 abstract m ethod

This works (but isn’t v ery useful)

public abstract class NoAbstractMethods {


}

> Can y ou instantiate Math class?


I assum e y ou m ean an object which is an instanceof Math. The Math class is
loaded and initialised as soon as y ou use one of its m ethods.

You shouldn’t need to create a Math object, the constructor for Math is priv ate
and all its m ethods are static. (You could using reflections but don’t)

peter lawrey
Posted 3/14/2008 at 4:59 am | Pe rmalink

BTW: The constructor for Class is priv ate and reflections prev ents y ou from
creating it, ev en though reflections will allows the construction of other objects
with priv ate constructors.
The only w ay to create a Class is using a ClassLoader.

Sangeetha
Posted 3/28/2008 at 1:53 am | Pe rmalink

Hi All.
Pls clarify m y doubt.

In ov erloading we are hav ing one m ethod as

 int methodA (int a, int b)

Are we allowed to hav e another m ethod by only changing the return ty pe and
not the param eters passed.

techinterviews.com/master-list-of-java-i… 17/21
7/17/2010 Master list of Java interview questions - …
double methodA(int c, int d)

peter lawrey
Posted 4/3/2008 at 1:07 am | Pe rmalink

> Are we allow ed to hav e another m ethod by only changing the return ty pe.

Let m e ask y ou; w hat would y ou want it to do?


Which m ethod should the following call if it was ov erloaded as y ou suggest?

Sy stem .out.println(m ethodA(1 ,2));

You could try it and see w hat happens.

devanshi
Posted 4/14/2008 at 4:16 am | Pe rmalink

hey Sangeetha.for y our q:Are we allowed to hav e another m ethod by only


changing the return ty pe and not the param eters passed

answer: no its not allowed as m ethod ov erloading can be only in 3 cases-:


1 )diff no of param eters
2 )diff ty pe of param eters
3 )diff positioning of param eters

it doesnt allow based on return ty pe as in ur q

Chaitanya
Posted 4/24/2008 at 3:28 am | Pe rmalink

About Q3 3
I hav e som e m ore differences
1 )Interface can be instantiated, whereas abstract class cannot
2 )Interface has only constant v ariables and abstract class can hav e all v ariable
that a norm al class has
3 ) When we im plem ent interfaces w e hav e to im plem ent all its m ethods but
while im plem enting abstract class we can choose to ignore som e m ethods

please do let m e know w hether these are right. Thanx n Regards

Sangeetha
Posted 4/25/2008 at 12:17 am | Pe rmalink

hi dev anshi,

As u m entiooned, diff positioning of param eters is allowed in m ethod


ov erloading, w hereas w hen i tried this code.

am ethod (String a, int b, int c)

and another m ethod as

am ethod (String a, int c, int b)

it throw s m e as a duplicate am ethod in ty pe


ov erloading. Pls clarify m y understanding on different positioning of
param eters.

techinterviews.com/master-list-of-java-i… 18/21
7/17/2010 Master list of Java interview questions - …

peter lawrey
Posted 4/25/2008 at 4:24 pm | Pe rmalink

> Chaitany a
1 ) You cannot instantiate an instance or an abstract class.
2 ) An interface can only hav e public static final v ariables, public abstract
m ethods and public nested classes/interfaces
3 ) When im plem enting a concrete class y ou hav e to im plem ent all abstract
m ethods. For an interface all m ethods in the interface are abstract (but not
m ethods in Object by default), whereas in abstract classes not all m ethods need
to be abstract, possibly none of them .

peter lawrey
Posted 4/25/2008 at 4:26 pm | Pe rmalink

> Sangeetha
Only the ty pes of the param eters are im portant for ov erloading. The nam es of
the param eters are not im portant.
Changing the nam es around m akes no difference if their ty pes are the sam e.

peter lawrey
Posted 4/25/2008 at 4:26 pm | Pe rmalink

> 1 ) You cannot instantiate an instance or an abstract class.

should read

1 ) You cannot instantiate an interface or an abstract class.

Galaxius
Posted 6/1/2008 at 11:16 am | Pe rmalink

I agree with Martinus and MArcus abov e. I interv iew candidates v ery
frequently and hav e noticed that the quality of the dev eloper who can answ er,
say all these 1 1 5 questions v s a quality of a dev eloper who can answer half of
these but is m ore successful in answering problem solv ing and logical questions
is enorm ous!!!

I would norm ally approach an interv iew candidate with a relativ ely easier
problem solv ing question like, say , if y ou hav e 2 v ariables and u want to swap
them without introducing a third v ariable, object or any other storage
m echanism ..how would u do it.

if he cannot answer a relativ ely sim ply problem solv ing q, i can see a profile of
his quality em erging.

som e of m y fav orite tacks are ” giv e m e a query that will conform to the
following rules - say , return a row if 3 colum ns m atch(ie user has specified
three v alues all of which exist in a row in the db), return the next sub lev el row
if 2 colum ns m atch and the third colum n is not specified and so on!!

finally , in jav a - if i hav e to query the person’s knowledge .. i stick to


threads/innerclasses and classloading. I’v e noticed 9 9 % of jav a codes ignore this
1 % of language essentials (probably because its harder? ) .. this trinite of
questioning still giv es m e a clear black and white picture whether the
candidate is selected or shown the door!!!

Usually , the substandard dev eloper interv iew is ov er in 1 5 m inutes flat!!!!

techinterviews.com/master-list-of-java-i… 19/21
7/17/2010 Master list of Java interview questions - …

KOtresh
Posted 6/3/2008 at 2:47 am | Pe rmalink

Refer to Q.No. 3 5.

Hi Sangeetha. This is the basic question in function ov erloading.

In function Ov erloading two function should hav e different signatures.


SIgnatures m eans prototy pe.
But here return ty pe is not considered.

e.g., int fun(int,int); int fun(int,char)


is function ov erloading

int fun(int,int); float fun(int,int)


is not function ov erloading

Ranjitha
Posted 6/23/2008 at 6:48 am | Pe rmalink

Refer to Q.No. 3 9

Hi Sangeetha,
When u say different positioning of param eters, we m ean that
int fun(int i,char c); int fun(char c,int i), these functions can co exist in the
sam e class. if u observ e the param eter ty pes are sam e but are positioned
differently in the argum ent list.

ONE T R A C KBA C K

Are You a Master Java Developer?? | Personal Insights on


By
Web 2.0, Blogging, and Business on 4 /3 0 /2 0 0 7 a t 9 :0 4 pm

[...] latest “Stum ble” resulted in being sent to this Master list of Jav a interv iew
questions - 1 1 5 questions. Obv iously , I’m not a m aster jav a dev — the 1 0 or so
questions I looked at m eant little [...]

POS T A C OMME NT

Your em ail is never published nor shared. Required fields are m arked *

N am e * Em ai l *

Websi te

Com m ent

techinterviews.com/master-list-of-java-i… 20/21
7/17/2010 Master list of Java interview questions - …

Post Com m ent

Pow er ed by WordPres s . Bu ilt on t h e Them atic Them e Fram ew o rk .

techinterviews.com/master-list-of-java-i… 21/21

Anda mungkin juga menyukai