Download as txt, pdf, or txt
Download as txt, pdf, or txt
You are on page 1of 25

==================================================================================

==
|
| url for the page is : http://www.geocities.com/binoymg/java_questions.htm
|
|
==================================================================================
=

100 java interview questions and answers

here is my collection of 100 java interview questions and answers. hope this would
be a great help for new and experienced programmers to refresh their technical
knowledge. i would like to express my sincere thanks to kamal, who helped me to
make it successful. expecting your valuable suggestions and comments.

binoy m. george

1.what's the difference between interface and abstract class? which one you would
prefer? in what situation would you use an abstract class?

interfaces are often used to describe the peripheral abilities of a class, not its
central identity. an abstract class defines the core identity of its descendants.
"heterogeneous vs. homogeneous." if implementers/subclasses are homogeneous, tend
towards an abstract base class. if they are heterogeneous, use an interface.
abstract classes are excellent candidates inside of application frameworks.
abstract classes let you define some behaviors; they force your subclasses to
provide others.

2. why would you apply design patterns (benefits)?

a pattern is a recurring solution to a standard problem. when related patterns are


woven together they form a ``language'' that provides a process for the orderly
resolution of software development problems. pattern languages are not formal
languages, but rather a collection of interrelated patterns, though they do
provide a vocabulary for talking about a particular problem. both patterns and
pattern languages help developers communicate architectural knowledge, help people
learn a new design paradigm or architectural style, and help new developers ignore
traps and pitfalls that have traditionally been learned only by costly experience.

http://www.mindspring.com/~mgrand/pattern_synopses.htm#creational%20patterns

3. name 3 design patterns in the java 2 api. write a singleton. in what situation
would you use a singleton?

singleton pattern, business delegate, value object


singleton pattern ensure a class only has one instance, and provide a global point
of access to it. it�s important for some classes to have exactly one instance.
although there can be many printers in a system, there should be only one printer
spooler. there should be only one file system (or file system manager) and one
window manager.
public class singleton {
private static final singleton instance =
new singleton();

// private constructor supresses


// default public constructor
private singleton( ) {
}

public static singleton getinstance( ) {


return instance;
}
}
if you want to make it serializable, then change the declaration to:

public class singleton implements serializable

and add this method:

private object readresolve()


throws objectstreamexception {
return instance;
}
the readresolve method serves to prevent the release of multiple instances upon
deserialization.

another implementation in the appcontroller factory class


/**
* @return the unique instance of this class.
*/
static public appcontrollerfactory instance() {
if(null == _factory) {
_factory = new appcontrollerfactory();
}
return _factory;
}

business delegate: in a normal scenario, presentation-tier components (e.g. a jsp)


interact directly with business services. as a result, the presentation-tier
components are vulnerable to changes in the implementation of the business
services: when the implementation of the business services change, the code in the
presentation tier must change. the goal of business delegate object design pattern
is to minimize the coupling between presentation-tier clients and the business
service api, thus hiding the underlying implementation details of the service. in
this way we enhance the manageability of the application. using this design
pattern, the client request is first handled by a servlet that dispatches to a jsp
page for formatting and display. the jsp is responsible for delegating the
processing of business functionality to a "business delegate" via a javabean.

the value object is used to encapsulate the business data. a single method call is
used to send and retrieve the value object. when the client requests the
enterprise bean for the business data, the enterprise bean can construct the value
object, populate it with its attribute values, and pass it by value to the client.
4. what is the prototype design pattern?

prototype design pattern is a creational design pattern. this pattern helps the
object oriented design more flexible elegant and reusable.

5. explain the concept of entity beans and session beans. what are the benefits of
using an application server? is it possible that in certain situations you would
not use an appserver? why?

the enterprise javabeans architecture is a component architecture for the


development and deployment of component-based distributed business applications.
applications written using the enterprise javabeans architecture are scalable,
transactional, and multi-user secure. these applications may be written once, and
then deployed on any server platform that supports the enterprise javabeans
specification.

a session bean is a type of enterprise bean; a type of ejb server-side


component. session bean components implement the javax.ejb.sessionbean interface
and can be stateless or stateful. stateless session beans are components that
perform transient services; stateful session beans are components that are
dedicated to one client and act as a server-side extension of that client.

session beans can act as agents modeling workflow or provide access to special
transient business services. as an agent, a stateful session bean might represent
a customer's session at an online shopping site. as a transitive service, a
stateless session bean might provide access to validate and process credit card
orders. session beans do not normally represent persistent business concepts like
employee or order. this is the domain of a different component type called an
entity bean.

an entity bean is a type of enterprise bean; a type of ejb server-side


component. entity bean components implement the javax.ejb.entitybean interface and
can be container-managed (cmp) or bean-managed (bmp). entity beans are designed to
represent data in the database; they wrapper data with business object semantics
and read and update data automatically. entity beans can be safely shared by many
clients, so that several applications can access the same bean identity at the
concurrently

web server & application server: why?

yes, it is possible to use the web server alone in certain circumstances such as,
if you are hosting a website serving

static html pages.

the web server, in general, sends web pages to browsers as its primary function.
most web servers also process input from users, format data, provide security, and
perform other tasks. the majority of a web server�s work is to execute html or
scripting such as perl, javascript, or vbscript

an application server prepares material for the web server -- for example,
gathering data from databases, applying business rules, processing security
clearances, or storing the state of a user�s session. in some respects the term
application server is misleading since the functionality isn�t limited to
applications. its role is more as an aggregator and manager for data and processes
used by anything running on a web server.

one of the most frequent causes of poor web server performance is data management
or data-related transactions. web servers and html in particular were not designed
for large-scale data handling. application servers shine at managing data. xml
translation, communication with database servers, validating data, and applying
business rules are all functions for which application servers were originally
designed. a key element may be the business rules.

6. explain final, finalize, and finally. when the finalize is invoked? how does gc
work? etc.

keyword final is equivalent to const in c/c++. if you declare a variable as final


in java the value will be unaltered. that variable will not be created per
instance basis.

finally is tied with exception handling try catch. finally block will be executed,
even if the exception is caught or not. usually used for closing open connections
files etc.

the garbage collector invokes an object's finalize() method when it detects that
the object has become unreachable.

7. in a system that you are designing and developing, a lot of small changes are
expected to be committed at the end of a method call (persisted to the db). if you
don't want to query the database frequently. what would you do?

8. what is a two-phase commit?

two phase commit technology has been used to automatically control and monitor
commit and/or rollback activities for transactions in a distributed database
system. two phase commit technology is used when data updates need to occur
simultaneously at multiple databases within a distributed system. two phase
commits are done to maintain data integrity and accuracy within the distributed
databases through synchronized locking of all pieces of a transaction. two phase
commit is a proven solution when data integrity in a distributed system is a
requirement. two phase commit technology is used for hotel and airline
reservations, stock market transactions, banking applications, and credit card
systems
9.give an algorithm that calculates the distance between two text strings (only
operations you can have are: delete, add, and change, one by one). given the
definition of a sequence (5 4 7 6 is, but 1 2 4 5 is not), write an algorithm to
check if an arbitrary array is a sequence or not.

10.describe a situation where concurrent access would lead to inconsistency in


your application. how would you solve this problem?

make the respective class synchronized.

11.what is the difference between rmi and iiop?

the remote method invocation classes in jdk 1.1 provide a simple, yet extremely
powerful, distributed object model for java. although rmi is language-specific,
because of java's platform-neutrality, rmi can be utilised widely, and with the
use of jdbc can provide basic object-relational mapping capabilities or with jni,
can provide access to platform-specific capabilities.

the iiop (internet inter-orb protocol) protocol connects corba products from
different vendors, ensuring interoperability among them. rmi-iiop is, in a sense,
a marriage of rmi and corba.

12.draw a class diagram (uml) for a system.

13.which do you prefer, inheritance or delegation? why?

please refer
http://www.objectmentor.com/resources/listarticles?key=date&date=2002

14.what is the difference between the jdk 1.02 event model and the event-
delegation model introduced with jdk 1.1?

the jdk 1.02 event model uses an event inheritance or bubbling approach. in this
model, components are required to handle their own events. if they do not handle a
particular event, the event is inherited by (or bubbled up to) the component's
container. the container then either handles the event or it is bubbled up to its
container and so on, until the highest-level container has been tried. in the
event-delegation model, specific objects are designated as event handlers for gui
components. these objects implement event-listener interfaces. the event-
delegation model is more efficient than the event-inheritance model because it
eliminates the processing required to support the bubbling of unhandled events.

15. give an example of using jdbc access the database.

try
{
class.forname("register the driver");
connection con = drivermanager.getconnection("url of db", "username","password");
statement state = con.createstatement();
state.executeupdate("create table testing(firstname varchar(20), lastname
varchar(20))");
state.executequery("insert into testing values('phu','huynh')");
con.commit();
}
catch(exception e)
{
system.out.println(e);
}finally {

state.close();
con.close();
}

16. difference of requestdispatcher and sendredirect ?

getrequestdispatcher is a method of servletcontext

1. forward is handled completely on the server


2.preserve all the request data, request state on the server
3.the url of the original servlet is maintained
4.does not require a round trip to the client, and thus more efficient

sendredirect is a method of httpservletresponse

1.requires the client to reconnect to the new resource, the request is first sent
to the client which requests for the resource
mentioned in the argument of sendredirect method.
2.does not automatically preserve all the request data result in a different
final url (convert relative url to absolute url)

17.can you tell me what iterators and enumerators are?

in any collection class, you must have a way to put things in and a way to get
things out. enumerations and iterators are used to get the object out from a
collection class.

one benefit of using iterators over enumerations is iterators check for concurrent
modifications when you access each element. enumerators faster than iterators.

18.you know what a queue is .... implement a queue class with java. what is the
cost of enqueue and dequeue? can you improve this? what if the queue is full? what
kind of mechanism would you use to increase its size?

please refer : queue.doc

19. difference between string & stringbuffer?

string object is immutable that is string is constant. stringbuffer is mutable.


stringbufffer will give better performance than string object.

20 what is synchronization and why is it important?

with respect to multithreading, synchronization is the capability to


control the

access of multiple threads to shared resources. without


synchronization, it is

possible for one thread to modify a shared object while another thread
is in the

process of using or updating that object's value. this often leads to


significant errors.

21 what's the diffence between green threads and native threads?

green threads are the default threads provided by the jdktm. native threads are
the threads that are provided by the native os:

native threads can provide several advantages over the default green threads
implementation, depending on your computing situation.

benefits of using the native threads:

if you run javatm code in a multi-processor environment, the solaris kernel can
schedule native threads on the parallel processors for increased performance. by
contrast, green threads exist only at the user-level and are not mapped to
multiple kernel threads by the operating system. performance enhancement from
parallelism cannot be realized using green threads.

the native threads implementation can call into c libraries that use solaris
native threads.

such libraries cannot be used with green threads.

when using the native threads, the vm can avoid some inefficient remapping of i/o
system calls that are necessary when green threads are used.

22 how do you run os commands from java

using runtime.getruntime.execute() command)

23 does a varibale displayed in xsl can it be changed

ans: no

24 diff between sax and dom

xml parsers, dom is more powerful reads the complete and parse, sax parse segment
by segment sequentially

25 can the singleton pattern will work in multiple jvm's


not sure, my answer is: no

27 thread isolation levels

28 how do you delete duplicate rows in oracle db

deleting duplicate rows when there is a primary key:

delete

from customers

where id in

(select id

from

(select id, lastname, firstname,

rank() over (partition by lastname,

firstname order by id) as seqnumber

from

(select id, lastname, firstname

from customers

where (lastname, firstname) in

(select lastname, firstname

from customers

group by lastname, firstname

having count(*) > 1)))

where seqnumber > 1);

deleting duplicate rows when there no primary key:

this technique works for tables that have no primary key�which, by itself,
is a sign of bad database design, but that's another topic for discussion.

for such tables, you can use the rowid pseudocolumn instead of the primary key to

get the same result:

delete

from customers

where rowid in

(select mykey

from

(select mykey, lastname, firstname,

rank() over (partition by lastname, firstname order by mykey) as


seqnumber

from

(select rowid as mykey, lastname, firstname

from customers

where (lastname, firstname) in

(select lastname, firstname

from customers

group by lastname, firstname

having count(*) > 1)))

where seqnumber > 1);

29 what is saaj?

soap with attachment api for java

30 how do you make servlet thread safe?

by extending the servelt from singlethread


31 what are models in assets

a) small mid specialty taxable, growth specialty taxable

b) foreign equity specialty taxable,

c) conservative tax deferred, conservative taxable

d) income and growth tax deferred, income and growth taxable

e) moderate growth tax deferred, moderate growth taxable

f) growth tax deferred, growth taxable, aggressive growth tax deferred

32 what is the life cycle of a servelt?

instantiate->init--> service --> destroy

33 how do you make a class singleton.

by making the class final and writing constructor private

34. jsp page life cycle:

there are 7 phases in the jsp life cycle:

1 : page translation : the page is parsed and the java file containing the servlet
is created.

2 : page compilation : the java file is compiled.

3 : load class : the compiled class is loaded.

4 : create instance : an instance of the servlet is created.

5 : call_jspinit( ) : this method is called before any other method to allow


initialization.

6 : call_jspservice() : this method is called for each request

7 : call_jspdestroy() : this method is called when the servlet container decides


to take the servlet out of service
35 what is serialization and externalization

serialization: converting byte to stream

externalization : stream to byte

36. diff between arraylist and vector

arraylist is not synchronized but vector is. arraylist is faster than


vector. vector has many legacy methods.

37. hashmap, hashtable and treemap.

hashmap is unsynchronized and permits nulls. this class makes no guarantees as to


the order of the map; in particular, it does not guarantee that the order will
remain constant over time. hashmap is not synchronized so it is good in
performance. hashtable is synchronised.

the point of a treemap is that you get the results in sorted order. treemap is the
only map with the submap( ) method, which allows you to return a portion of the
tree. the treemap is generally slower than the hashmap

38. diff between int and integer

int: primitive data type.

integer: object, wrapper class of int.

39.diff between static and final?

a static method is a method that's invoked through a class, rather than a


specific object of that class

a final method is just a method that cannot be overridden static methods can be
overriden, but they cannot be

overriden to be non-static, whereas final methods cannot be overriden.

40. how to prevent a variable from serialization?


to prevent serialization declare the variable as "transient".

41. what are userdefined exceptions?

user defined exception are the programmer created software detected exceptions.
programs may name their own exceptions by assigning a string to a variable or
creating a new exception class is called user defined exception

42. explain about garbage collector?

the name "garbage collection" implies that objects that are no longer needed by
the program are "garbage" and can be thrown away. a more accurate and up-to-date
metaphor might be "memory recycling." when an object is no longer referenced by
the program, the heap space it occupies must be recycled so that the space is
available for subsequent new objects. the garbage collector must somehow determine
which objects are no longer referenced by the program and make available the heap
space occupied by such unreferenced objects. in the process of freeing
unreferenced objects, the garbage collector must run any finalizers of objects
being freed.

advantages: first, it can make programmers more productive

a second advantage of garbage collection is that it helps ensure program


integrity. garbage collection is an important part of java's security strategy.
java programmers are unable to accidentally (or purposely) crash the jvm by
incorrectly freeing memory.

43. what is the difference between the >> and >>> operators?

the >> operator carries the sign bit when shifting right.

the >>> zero-fills bits that have been shifted out.

44. how are observer and observable used?


objects that subclass the observable class maintain a list of observers. when an
observable object is updated it invokes the update() method of each of its
observers to notify the observers that it has changed state. the observer
interface

is implemented by objects that observe observable objects.

45. what is synchronization and why is it important?

with respect to multithreading, synchronization is the capability to


control the

access of multiple threads to shared resources. without


synchronization, it is

possible for one thread to modify a shared object while another thread
is in the

process of using or updating that object's value. this often leads to


significant errors.

46. what is the difference between yielding and sleeping?

when a task invokes its yield() method, it returns to the ready state.

when a task invokes its sleep() method, it returns to the waiting


state.

47. does garbage collection guarantee that a program will not run out of memory?

garbage collection does not guarantee that a program will not run out
of memory.

it is possible for programs to use up memory resources faster than


they

are garbage collected. it is also possible for programs to create


objects that are

not subject to garbage collection

48 what is the difference between preemptive scheduling and time slicing?


under preemptive scheduling, the highest priority task executes until
it enters the

waiting or dead states or a higher priority task comes into existence.

under time slicing, a task executes for a predefined slice of time and
then reenters

the pool of ready tasks. the scheduler then determines which task
should execute next,

based on priority and other factors.

49 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.

50. what is the purpose of finalization?

the purpose of finalization is to give an unreachable object the


opportunity to

perform any cleanup processing before the object is garbage collected.

51. what invokes a thread's run() method?

after a thread is started, via its start() method or that of the


thread class,

the jvm invokes the thread's run() method when the thread is initially
executed.

52. what is the purpose of the runtime class?

the purpose of the runtime class is to provide access to the java runtime system
and to use the operating system commands.

53. what is the relationship between the canvas class and the graphics class?
a canvas object provides access to a graphics object via its paint()
method.

54. what is the difference between a static and a non-static inner class?

a non-static inner class may have object instances that are associated with
instances

of the class's outer class. a static inner class does not have any object
instances.

55. what is the dictionary class?

the dictionary class provides the capability to store key-value pairs.

56 name the eight primitive java types.

the eight primitive types are byte, char, short, int, long, float, double, and
boolean.

57 what is the relationship between an event-listener interface and an event-


adapter class?

an event-listener interface defines the methods that must be implemented by an


event handler for a particular kind of event. an event adapter provides a default
implementation of an event-listener interface

58. what modifiers can be used with a local inner class?

a local inner class may be final or abstract.

59. diff between overloading and overriding?


overloading : same name, different signature

overriding : same name, same signature

employee class difines

public void giveraise( double percentage)

boss class can override giveraise

public void giveraise(double percentage){

------

boss can overload giveraise

public void giveraise(string newtitle){

----

overloaded method called depends on arguments.

restrictions of method overriding:

overridden methods must have the same name, argument list, and return type. the
overriding method may not limit the access of the method it overrides. the
overriding method may not throw any exceptions that may not be thrown by the
overridden method.

60. 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
61 what is stack and heap ? if you declare a primitive type such as declaring a
variable where does it store? where does jvm referes all the live objects?

the java stack is used to store parameters for and results of bytecode
instructions, to pass parameters to and return values from methods, and to keep
the state of each method invocation. the state of a method invocation is called
its stack frame. the vars, frame, and optop registers point to different parts of
the current stack frame. the heap is where the objects of a java program live. any
time you allocate memory with the new operator, that memory comes from the heap.
the java language doesn't allow you to free allocated memory directly. instead,
the runtime environment keeps track of the references to each object on the heap,
and automatically frees the memory occupied by objects that are no longer
referenced -- a process called garbage collection.

62 explain the dostarttag() and doendtag() methods ?

the dostarttag() and doendtag() methods belong to the tag interface of the
javax.servlet.jsp.tagext package. the tag interface provides methods that connect
a tag handler (a tag handler is an object invoked by a web container/server to
evaluate a custom tag during the execution of the jsp page that references the
tag.) with a jsp implementation class , including the life cycle methods and
methods that are invoked at the start and end tag. the method dostarttag()
processes the start tag associated with a jsp while the doendtag() method
processes the end tag associated with a jsp.

63 what is your platform's default character encoding?

if you are running java on english windows platforms, it is probably


cp1252.

if you are running java on english solaris platforms, it is most


likely 8859_1.

64 explain how do you implement tags in jsp ?

the "taglib" directive is included in a jsp page which uses tags defined a tag
library. here is the syntax for that:

<%@ taglib uri="uri" prefix="prefix" %>

the uri refers to a uri (uniform resource identifier, a term referring to any
specification that identifies an object on the internet) that uniquely identifies
the tld, tag library descriptor. a tag library descriptor is an xml document that
describes a tag library. the prefix attribute defines the prefix that
distinguishes tags defined by a given tag library from those provided by other tag
libraries.

65 how can a dead thread be restarted?

a dead thread cannot be restarted.

66 for a cmp bean what should the ejbcreate returns?

remote interface

67 what is the order of method invocation in an applet ?

68 how will you pass values from html page to the servlet ?
session or cookies

69 how does thread synchronization occurs inside a monitor?

70 can you load the server object dynamically? if so, what are the major 3 steps
involved in it ?

71 what is difference in between java class and bean ?

a java bean is a java class object that encapsulates data in the form of

instance variables. these variables are reffered to as properties of the bean.

the class then provides a set of methods for accessing and mutating its
properties.

72. you add web components to a j2ee application in a package called war (web
application archive). a war has a specific hierarchical directory structure. which
directory stores the deployment descriptor for a web application located in the
myapp directory?

an application located in the myapp directory will have its deployment


descriptor in the myapp/web-inf directory.
73 suppose if we have variable ' i ' in run method, if i can create one or more
thread

each thread will occupy a separate copy or same variable will be shared ?

74 what are session variable in servlets?

75 what are the normalization rules ? define the normalization ?

first normal form


for a table to be in first normal form (1nf) each row must be identified, all
columns in the table must contain atomic values, and each field must be unique.

second normal form


for a table to be in second normal form (2nf), it must be already in 1nf and it
contains no partial key functional dependencies. in other words, a table is said
to be in 2nf if it is a 1nf table where all of its columns that are not part of
the key are dependent upon the whole key - not just part of it.

third normal form

a table is considered to be in third normal form (3nf) if it is already in second


normal form and all columns that are not part of the primary key are dependent
entirely on the primary key. in other words, every column in the table must be
dependent upon "the key, the whole key and nothing but the key."

76 what is meant by class loader? how many types are there? when will we use them?

the class classloader is an abstract class. a class loader is an object that is


responsible for loading classes. given the name of a class, it should attempt to
locate or generate data that constitutes a definition for the class. a typical
strategy is to transform the name into a file name and then read a "class file" of
that name from a file system.

applications implement subclasses of classloader in order to extend the manner in


which the java virtual machine dynamically loads classes. the classloader class
uses a delegation model to search for classes and resources

77 how do you load an image in a servlet ?

78 what is meant by cookies ? explain ?


cookies are a general mechanism which server side connections can use to both
store and retrieve information on the client side of the connection. a cookie is
a unique identifier that a web server places on your computer: a serial number for
you personally that can be used to retrieve your records from their databases.
it's usually a string of random-looking letters long enough to be unique. they are
kept in a file called cookies or cookies.txt or magiccookie in your browser
directory/folder. they are also known as ``persistent cookies'' because they may
last for years, even if you change isp or upgrade your browser.

79 wrapper class. is string a wrapper class


example : integer is a wrapper class of int. string is not a wrapper
class.

80 checked & unchecked exception


� use checked exceptions for conditions that client code may reasonably be
expected to handle. this compile-time checking for the presence of exception
handlers is designed to reduce the number of exceptions which are not properly
handled."

� if you are throwing an exception for an abnormal condition that you feel
client programmers should consciously decide how to handle, throw a checked
exception.

� unchecked exceptions indicate software bugs.

� precisely because unchecked exceptions usually represent software bugs,


they often can't be handled somewhere with more context.

81 explain lazy activation


lazy activation defers activating an object until a client's first use (i.e., the
first method invocation). delay activation until the first client request for the
object. uses faulting remote references the faulting remote reference contains a
persistent activation handle (reference) for the remote object and a transient
remote reference to the remote object. the transient remote reference can be null.
on the first reference to the remote object, if the transient remote reference is
null, the persistent activation handle is used to contact (directly or indirectly)
the activator for the remote object. if need be the activator activates the object
and returns the proper remote reference to the remote object.

82 how do you delete a httpsession.

the invalidate() method of the httpsession interface expires the current session.
it causes the representation of the session to be invalidated and removed from its
context.

83 what is the different of an applet and a java application

in simple terms, an applet runs under the control of a browser, whereas an


application runs stand-alone, with the support of a virtual machine. as such, an
applet is subjected to more stringent security restrictions in terms of file and
network access, whereas an application can have free reign over these resources.

applets are great for creating dynamic and interactive web applications, but the
true power of java lies in writing full blown applications. with the limitation of
disk and network access, it would be difficult to write commercial applications
(though through the user of server based file systems, not impossible). however, a
java application has full network and local file system access, and its potential
is limited only by the creativity of its developers.

84. how do we pass a reference parameter to a function in java?

even though java doesn't accept reference parameter, but we can


pass in the object for the parameter of the function.
for example in c++, we can do this:

void changevalue(int& a)
{
a++;
}
void main()
{
int b=2;
changevalue(b);
}

however in java, we cannot do the same thing. so we can pass the


the int value into integer object, and we pass this object into the
the function. and this function will change the object.

85. explain the difference between the equals() method, and the == operator

- what happens if .equals() is not defined? (bit wise comparison)


- we had a bit of an argument about stringss being given the same address by the
compile

86. how do you put an object on the stack in java?

stack is inherited from vector. so it has all of the characteristics and behaviors
of a vector plus some extra stack behaviors.

stack stk = new stack();


for(int i = 0; i < months.length; i++)
stk.push(months[i] + " ");
system.out.println("stk = " + stk);
// treating a stack as a vector:
stk.addelement("the last line");

87 what can't you do in an ejb?

you can't use java.io


88. do you know about text formatter?

89. how would you create a hashmap from an array?

90. how would you create a list from an array?

91. how do you stop a thread?

92. what can you tell me about the reflection package?

the java core reflection api provides a small, type-safe, and secure api that
supports introspection about the classes and objects in the current java virtual
machine*. if permitted by security policy, the api can be used to:

construct new class instances and new arrays

access and modify fields of objects and classes

invoke methods on objects and classes

access and modify elements of arrays

pls refer to :
http://java.sun.com/j2se/1.3/docs/guide/reflection/spec/java-reflection.doc.html

93. are private member variables saved if class is serializable?

94. a question about the clonable interface, deep/shallow copies, clone() method

96. what are thread priorities?

thread priorities (min_priority ( 1 ), norm_priority ( 5 ) , mx_priority ( 10 ) )

97 what is difference in between java class and bean ?


what differentiates beans from typical java classes is introspection. tools that
recognize predefined patterns in method signatures and class definitions can "look
inside" a bean to determine its properties and behavior. a bean's state can be
manipulated at the time it is being assembled as a part within a larger
application. the application assembly is referred to as design time in contrast to
run time. in order for this scheme to work, method signatures within beans must
follow a certain pattern in order for introspection tools to recognize how beans
can be manipulated, both at design time, and run time.

in effect, beans publish their attributes and behaviors through special method
signature patterns that are recognized by beans-aware application construction
tools. however, you need not have one of these construction tools in order to
build or test your beans. the pattern signatures are designed to be easily
recognized by human readers as well as builder tools. one of the first things
you'll learn when building beans is how to recognize and construct methods that
adhere to these patterns.

98.why might you define a method as native?

native methods are methods implemented in another programming language such as


c/c++.

to get to access hardware that java does not know about


to write optimized code for performance in a language such as c/c++

99. which design patterns reduces the coupling between presentation-tier clients
and business services in a web application?

business delegate

in a normal scenario, presentation-tier components (e.g. a jsp) interact directly


with business services. as a result, the presentation-tier components are
vulnerable to changes in the implementation of the business services: when the
implementation of the business services change, the code in the presentation tier
must change. the goal of business delegate object design pattern is to minimize
the coupling between presentation-tier clients and the business service api, thus
hiding the underlying implementation details of the service. in this way we
enhance the manageability of the application. using this design pattern, the
client request is first handled by a servlet that dispatches to a jsp page for
formatting and display. the jsp is responsible for delegating the processing of
business functionality to a "business delegate" via a javabean.

100. explain the significance of using the following design patterns mvc, dao(data
access object, value object)

mvc design pattern provide multiple view using the same model.

dao (data access object), which enables easier migration to different persistence
storage implementation.

the value object is used to encapsulate the business data. a single method call is
used to send and retrieve the value object. when the client requests the
enterprise bean for the business data, the enterprise bean can construct the value
object, populate it with its attribute values, and pass it by value to the client.
101 why do you make setautocommit(false) for a transaction?

setautocommit

public abstract void setautocommit(boolean autocommit) throws sqlexception


if a connection is in auto-commit mode, then all its sql statements will be
executed and committed as individual transactions. otherwise, its sql statements
are grouped into transactions that are terminated by either commit() or
rollback(). by default, new connections are in auto-commit mode. the commit occurs
when the statement completes or the next execute occurs, whichever comes first. in
the case of statements returning a resultset, the statement completes when the
last row of the resultset has been retrieved or the resultset has been closed. in
advanced cases, a single statement may return multiple results as well as output
parameter values. here the commit occurs when all results and output param values
have been retrieved.

http://stein.cshl.org/jade/distrib/docs/java.sql.connection.html#setautocommit(boo
lean)

102 explain the soap request paradigm

103. explain the following jar files and its purpose?

crimson.jar - crimson is a java xml parser which supporrts xml 1.0 via the
following apis:

espressapi - espresschart provides an easy-to-use application programming


interface (api) that enables users to create and customize

2d and 3d charts within their own applications (and applets). it is written in


100% pure java, but can use native libraries for a performance boost

when exporting. http://www.quadbase.com/espresschart/help/manual/chp_8.html

imap - imap is the internet message access protocol, or as it was once known, the
interactive mail access protocol. it represents a communications mechanism for
mail clients to interact with mail servers, and manipulate mailboxes thereon.

perhaps the most popular mail access protocol currently is the post office
protocol (pop), which also addresses remote mail access needs. imap offers a
superset of pop features, which allow much more complex interactions and provides
for much more efficient access than the pop model.

itext � used to convert a rtf file to a pdf file http://www.lowagie.com/itext/

the end
hope this would be a great help for new and experienced java programmers who are
attending interviews. i could not include the answers for some of the questions
please bear with me. i will update the answers in the future releases� binoy m.
george

please email your valuable comments and suggestions to: binoymg@hotmail.com

You might also like