Some of the Interview Questions with answer on Java Technology
can be found on this Page as follows:

Java Interview Question
What if one has to design a event monitoring system that can monitor
any specific but generally categorised events happening for example
database is not working or down, or any specific dependency is not
available, etc., how one can go about designing such a system or any 
ready to use software available for this purpose?

Please send you answer to this question to authors mail id at
Java Interview Question
What are Optimistic and Pessimistic locking strategies?

Please send you answer to this question to authors mail id at
Be rest assured, your email id will not be shown here.The content that will be published here are
Your First Name, Date of post and matter.



Name: Guddu
Date: 02-July-2008
Comment:
I think, Optimistic locking is like not expecting a change/update in backend data, while
working on data from a query, and so there should be provision for checking and handling
any data merging conflicts, while pessimistic locking would be like not allowing any 
other user to be able to work on the same data concurrently.
Please correct me if i am wrong.
Java Interview Question What happens when a database connection pool , creates many JDBC database connections and keep those active, how are the concurrencies of same user sessions handled at database level/side? Please send you answer to this question to authors mail id at
Be rest assured, your email id will not be shown here.The content that will be published here are
Your First Name, Date of post and matter.

Name: Guddu
Date: 05-July-2008
Comment:
I think, database has ways to manage user session, and each connection channel is having
a different User session/processes assigned, this way may be database can manage user
query execution plans. This is purely my guess and I am not sure on this.
Java Question What are the different types of JDBC drivers available, and what are the basic difference of one driver from other drivers? Can you elaborate on this? Please send you answer to this question to authors mail id at
Be rest assured, your email id will not be shown here.The content that will be published here are
Your First Name, Date of post and matter.

>
Name: Guddu
Date: 05-July-2008
Comment:
In JDBC, there are four different types of drivers, classified as Type-I, II, III and IV.

I have used mainly Type IV driver, and I think it is more of a pure Java driver, that means
one need not have to have the database client related native libraries installed on the client
PC. Only Database URL/connection string , user name and password should be enough to connect
yo database, be it locally or remotely located.
Java Interview Question What are the factors that can impact scalability of an enterprise Application on J2EE Technology? Please send you answer to this question to authors mail id at
Be rest assured, your email id will not be shown here.The content that will be published here are
Your First Name, Date of post and matter.


Java Interview Question
What are the memory leak possibilities in Java based application
and how to resolve those

Please send you answer to this question to authors mail id at
Be rest assured, your email id will not be shown here.The content that will be published here are
Your First Name, Date of post and matter.



Java Interview Question
If given a requirement for pagination / page by page iterator in a project
for showing mass data/ bulk data , could be in 100 1000 records. 
What will be your thought about implementing this using Java, JSP and JSP 
Tag Library Technologies?

Java Interview Answer
There are two ways of approaching this particular requirement. One is to
design, develope and test and apply this Page by Page Iterator logic.
The other approach would be to look or find for some of the existing pagination
framework, either open source or commercial, that will fit into the functional 
and technical requirements of project. Features I would look for are it should 
have good/professional GUI, customizable enough to Plug-in or plug-out whenever
required. That is it should be pluggable and should allow me to de-couple
this framework from the existing presentation layer and this framework should be
having some ways or provisions of passing data (data to be shown in tabular form)
dynamically.

Java Interview Question
Can you such one such framework now?

One of such pagination framework/ page by page iterator I can think of is a Tag
Library based Paging Framework from 
http://freesourceutilityhelp.googlepages.com/pagebypageiterator-framework.html
It has a default look, but can easily be overridden by changing the Java code at 
Tag level. This Framework has a way to provide data by writing a POJO class and 
configuring it with the Tag.
I think it uses Template Method Design Pattern for this. Nice work I must say.

Java Interview Question
Can you explain/provide a business case for Abstract Factory Design Pattern?

Java Interview Answer
To my understanding, it is an abstraction of Factories of Java Objects. Let me
put forth a real world case. Suppose one has to put down/laid down a process/flow 
of activities for achieving a common collective goal. For using this process in 
multiple functional areas for different types of data, may be applying billing 
process, in purchase department, or in stores or in quality assurance, then the 
process can be a Factory and Providing an abstraction to applying this process 
into different departments is like abstract Factory pattern.

Java Interview Question
In which category/types does Template Method Design Pattern fit in, out of 
Structural Pattern,
creational pattern, behavioral pattern?

Template Design Pattern goes in behavioral pattern category. As it provides 
behavior/implementation of a method at runtime only.

Java Interview Question
Can you be able to co-relate different categories of design patterns like 
creational pattern, structural pattern, behavioral pattern with Object Oriented 
programming principles like abstraction, encapsulation, inheritence, polymorphism 
etc?

To my understanding, creational pattern can be referred to as Encapsulation and 
Abstraction. Structural pattern can be referring to inheritence and behavioral 
pattern can be referring to polymorphism OO Principles.

Please note: If you have any difference of opinion, please send me your opinion at
share.understanding at gmail.com

Java Interview Question
Which core J2EE Design pattern can be treated in somewhat similar to Servlet Filters
from Java Servlet 2.3?

Intercepting Filter core J2EE Design Pattern.

Java Servlet Interview Question
While using Servle Filters, Can I be able to manipulate HTTP response
before actually sending /flushing buffer back to browser?

Yes, in Servlet Filters in doFilter method, FilterChain.doFilter method
can be used to get the response back in Servlet Filter once servlet processing
is completed.

Java Servlet Interview Question
Is this behavior observed in case of Servlet forwards or send redirects the
Request and Response to another Servlet or JSP?

Yes, whether HTTP Request or HTTP Response are forwarded or send redirected
, execution flow comes back to the Filter after the chain.doFilter method line
and then executes the forwarded Servlet/JSP.


J2EE Design Pattern Interview Question
Is there any difference between Transfer Object and Value Objects?

To my understanding, Value Objects and Transfer Objects can be both POJO
but Value Object can be directly used by client code, but Transfer Object
may require a Transfer Assembler for getting real advantage of this pattern.
I may say that Transfer Object is a corse grained Value Object, like for example
an complex UI has many fields to be shown and all these fields are comming from 
different database tables and fields, so there could be a single Transfer object
with all the required fields to be shown on screen, and this Transfer Object
can be populated by a Transfer assembler by querying multiple tables , instead
if value object is used, then there could be many calls from client tier to 
service tier for these values to be accumulated at client side.

Java Interview Question
Given a choice of technology for developing a client server application
but should be operating on multi platform and protocol, what will be
your choice of Technology in this scenario?

Please send you answer to this question to authors mail id at
Be rest assured, your email id will not be shown here.The content that will be published here are
Your First Name, Date of post and matter.

Java Servlet Interview Question
If multiple Servlets accessing HttpSession concurrently, will these be any 
threading or concurrency issues?

Yes, as multiple Servlets will be concurrently accessing same HttpSession, 
so there could be threading issues.

Java Servlet Interview Question

What is the difference between include and forward methods of ServletContext 
RequestDispatcher?

include method writes/appends the response buffer while forward method has to
have a clean response buffer, so any Servlet calling forward method should have
a cleared response buffer before target Servlet's Service method is called.

Java Servlet Interview Question
Supose Servlet A forwarding request to Servlet B, and Servlet B is either throws a
runtime exception or any checked exception of type ServletException or IOException,
then How is this exceptions handled or where is it getting propaged?

It should be propaged to the caller Servlet A.

Java Servlet Interview Question
Can RequestDispatcher be used for forwarding request and response to another Servlet 
in a different web application hosted in the same application server?

Yes, it is possible to forward HTTP request and response to a Servlet/JSP in a 
different ServletContext or web application hosted in the same web server.

Java Servlet Interview Question
Can a Java Object be stored in HTTP Session be visible to both web applications
in case of the above scenario?

No, Java Object stored in one Http Session cann't be visible in other Http Session.

Java Servlet Interview Question
Suppose in a web application, there is a requirement for checking user credentials
or login status , before even accessing a HTML or XML file, how you do this?

Using Servlet Filters, I should be able to impose validation of user login status
for dynamic and static resources in web application.


Java Interview Question
How to approach a performance bottleneck while dealing with a 
specific problem, and troubleshoot this while using JDBC Technology?

Please send you answer to this question to authors mail id at


Be rest assured, your email id will not be shown here.The content that will be published here are
Your First Name, Date of post and matter.

Java Interview Question
Have you noticed java.io.OutputStream related changes in class 
definition in Java 5.0, over Java 1.4?

In Java 1.4 OutputStream is an abstract class extending Object
but in Java 5.0, OutputStream is an abstract class extending Object
and implementing Closeable and Flushable interfaces.
Some of these interfaces like Appendable, Readable, Iterable
etc are added.

Java Interview Question
Can you be able to override default look of a Button from AWT?

Yes, it is possible, just by creating a customized Button that 
extends java.awt.Button and overriding paint(Graphics ) method 
from Component.

Java Interview Question
Is there any recomentation in terms of performance in case of
using PreparedStatement and calling stored procedure?

Please send you answer to this question to authors mail id at


Be rest assured, your email id will not be shown here.The content that will be published here are
Your First Name, Date of post and matter.

Java Interview Question
Which one will be faster, normal data outputstream or buffered
output stream?

Java Interview answer
I think buffered output stream will be faster, as it is like
sending a chunk of data at a time to disk in form of file io
operation.

Java Interview Question
Is there any ways of getting a chunk of Data from database
at a time without really iterating through resultset while
using database?

Java Interview answer
Yes if database supports this feature. But how?
is again database specific feature.


J2EE Interview Question
What is the best way to handle runtime exceptions in EJB?

Please send you answer to this question to authors mail id at


Be rest assured, your email id will not be shown here.The content that will be published here are
Your First Name, Date of post and matter.

J2EE Interview Question
What will happen if a JTA transaction initiated inside
a Stateless Session Bean and a EJB Timer service is called
from the transaction context? Will the transaction be 
propagated to the EJB Timer service as well or NOT?

Please send you answer to this question to authors mail id at


Be rest assured, your email id will not be shown here.The content that will be published here are
Your First Name, Date of post and matter.

J2EE Interview Question
What is difference between a web server and a J2EE Web container?

J2EE Interview answer
To my understanding, web server is independent of J2EE Technology
and should be responding to HTTP GET/Post operation, it can be apache
, IIS or any web server but J2EE web container is to host Servlet
and JSP server side java code to be invoked by web server in the
process of looking up specific directory and resource from the URL.

Please send you answer to this question to authors mail id at
Be rest assured, your email id will not be shown here.The content that will be published here are
Your First Name, Date of post and matter.



This is purely my own understanding, if you have some other 
answer/opinion to thie question, please write to me and I shall
publish this here, with your name only (email id will not be shown).
You can reach me at share.understanding at gmail.com


J2EE Interview Question
Will be a Singleton object be visible across web applications, provided
all the web applications are having this singeton class in it?

J2EE Interview answer
It all depends on Class Loader, as Singleton is instantiated as static
inside a classloader, then it should not be visible across web applications
if this singleton class is placed inside web-inf/classes folder or as a Jar
file in web-inf/lib folder. But this singleton object will be visible
across all web applications, if this singleton class is deployed such that
this class gets instantiated in the main/system classloader of the web server,
like for Apache Tomcat web server , if singleton class is placed in common\lib
folder as a JAR file, the it should be visible across all the web applications
as a single copy.

Java Interview Question
Can I be able to override a final method?

Java Interview answer
No, final keyword is used to restrict any change in
implementation or state of any Java type.
By implementing final method, we can restrict this method
from being overridden.

Java Interview question
Which one should I use for forwarding request a servlet hosted in
another instance of web container node in cluster, sendRedirect or
requestdispatcher?

Java Interview answer
sendredirect can be used to initiate another request, but same request
cann't be forwarded to another web container instance in cluster nodes.

Please send you answer to this question to authors mail id at
Be rest assured, your email id will not be shown here.The content that will be published here are
Your First Name, Date of post and matter.

J2EE Interview Question
What is SessionSynchronization in J2EE Technology?

J2EE Interview answer (open for discussion)
In case of Stateful SessionBean, if used to be notified within a transaction
boundary, in order to synchronize its state with associated transactions, then
stateful session bean class should implement SessionSynchronization interface.

J2EE Interview Question
What will happen if multiple threads are spanned from servlet running within
a transaction? Will all threads be running under the same transaction?

J2EE Interview Answer
No, as all these threads cann't run or be associated with the originating 
transaction.

Java Interview Question
From designing perspective what is importance of abstract class?
Java Interview answer
Abstract class can be used for extending functionality or giving
designer room for defining method those can be implemented at
developement time. Suppose you are defining a framework and 
wanted to provide a hook for implementor of this framework to
provide real functionality, then using abstract class and defining
some abstract method provides developer with a hook to attach 
poject related functionality at developement time.
Like for example Template design pattern, one can extend an 
abstract class and implement certain abstract methods, and framework
can be able to pick up the real implementation at runtime.

Java interview question
Using AWT can you be able to customize standard visual components
like Button?
Java Interview answer
Yes, using decorator design pattern, thus by extending component
like Button and overriding actual look of this component, I should
be able to change look of these standard AWT components.

Java Interview Questions with answer (to my understanding)

Java Interview Question 1 
If you are using JDK1.5 version of Java Platform and you are
told to write a multi-thread application, What will be your
approach to this objective/task?

Java Interview answer
In JDK1.5 version of Java Platform, there is a new package 
java.util.concurrent is introduced / included, that has many 
thread related api to use. Such as ThreadPoolExecutor, with 
pooling of threads, exception handling, and thread management
complexities are already implemented/provided and ready to use.
So I should be able to use this package and its classes
to make multi-thread application with one level above normal 
Plain Old Ways of doing multithreading application like 
extending thread class or implementing Runnable interface.

Java Interview Question 2 
Can I use a composite key (like combination of multiple keys, 
like a String, a Date, a Integer, a Byte), while storing 
objects in a Hashtable? Suppose I have to store a Student Object
in a Hashtable provided key for this object are values like
studentName-classroll-dateofBirth combination?

Java Interview Answer
Yes, one way of doing this is by defining a class with studentName,
classRoll, dateOfBirth as fields and overriding equals and hashCode 
methods of Object class, appropriately to equate using all these 
three field values and hashCode a hash value of these fields.

Java Interview Question 3 
Can you define psedo-Javacode for calculating factorial of 10?

Java Interview Answer
A recursive loop of values with decrement by 1 and filling an array
and then passing this array to a method for multiplying all the array
elements one by one and returning the final result.

Java Interview Question 4 
If you have to move a point (x and y co-ordinates) in a projectile 
trajectory and depending on the initial force applied.
How do you calculate all the points or trajectory path in a two 
dimensional graph, using Java Technology as programming language?

Java Interview Answer
I don't have any answer to this question as of now.
This question is left to visitor/readers of this page,
you can send your answers/ideas/approaches to my email id at 
guddumails at indiatimes.com


Java Interview Question 5
Which API / class from Java Platform, can be used to implement FIFO
 (First In First Out) of elements?

Java Interview Answer
Queue class can be used as ready made FIFO implementation from Java
Platform.

Java Interview Question 6
Which API / class from Java Platform, can be used to implement LIFO
(Last In First Out) of elements?

Java Interview Answer
Stack class can be used as ready made LIFO implementation from Java 
Platform.

Java Interview Question 7
In Java Platform based multi-thread appliocation, Is it thread safe 
to use shared mutable objects?

Java Interview Answer
No, as mutable objects are not thread-safe by implementation. So it 
is always advisable to use immutable objects incase of sharing same 
instance across threads, as values of immutable instances can never 
be changed.

Java Interview Question 8
What is the difference between synchronized method and synchronized 
static method in a class?

Java Interview Answer
In case of synchronized method, if a thread invokes this method, it
acquires a object level monitor/lock for the object (whose synchonized 
method is called/invoked?). But in case of synchronized static method, 
if a thread invokes this static synchonized method, then a class level 
monitor/lock is getting acquired for the object(whose synchronized 
method is called/ invoked).


Java Interview Question 9
Will there be chances of locking in case of two threads instantiating 
an object and invoking 

Java Interview Answer
No, I don't think so, as two threads instantiates two different 
instantiation of a class, so, there will be two diferent objects whose 
lock are acquired by two different threads.

But in case there are two single instance of an object / singleton object 
and having two synchronized methods, and both methods are using / calling 
other object, to get some value, then there could be chances of lock issues.
As one instance is locked and again this object wants to lock another 
instance for some value, but this object is already locked by the other 
thread, so both threads wait for the lock indefinitely.

Some of the tools found on the net as follows:

1. http://r2build.sourceforge.net/
R2Build, make your build easier....

**********************************************************************

    Java Exception Handling strategies:
Exception Handling is always been an area that has many implication in overall functioning of any Java based application or system. As we, Java Developers already know that there is a specific Exception hierarchy or framework is already in place in JDK, in order to proceed with proper handling of exceptions in Java based application. Just to re-state this basic exception hierarchy, I am going to write something about it. There is a Super class Throwable, that has error and exception as sub class. Errors, I think need not be handled by program code, and it should be triggering a system shut down. But in case of exceptions, there can be two possibilities, one is runtime and one in coding time. Sometimes these are called as unchecked and checked exceptions. Checked exception can be handled in the same method/class where it occured or can be thrown back to the main program to place exception handling generic code at one place in the Java application. But Unchecked exception or runtime exceptions should be automatically comming to the main program without need for throws clause or to be thrown, if the method raising this exception is not explicitly catching this runtime exception, which should be avoided, as in my opinion it could be like hiding the exception without the main program even knowing that a runtime exception has occured. ********************************************************************** Exception Handling strategies can be as simple as putting try..catch..finally or try..finally or try..catch..catch..finally..catch..finally or sometimes could be nested as well. But with little bit of logical thinking and better exception handling strategy, it is possible to tame exceptions, be it checked or unchecked and output is better code with properly handled exceptions. I would like to discuss some of these exception handling strategies (I think) with some sorts of program code. ********************************************************************** J2ME >> Overview of J2ME operational environment Here is a diagram depicting the Operational environment of any mobile application. Components for the same are a Mobile/PDA, a WAP Gateway, a web server, a JAD file and a Jar file. JAD ( Java Descriptor file) has all the information about the location and class for any MIDLET. Once user types in the URL of the MIDLET (like http://www.xyz.com/x/test.jad ) request goes to the WAP server, then to the WEB server over HTTP. This URL is added to the Java Application Manager (JAM)stored in the Mobile device. JAD file is downloaded onto the JAM and the send a request to WAP/WEB server for the JAR file ( Java Archive file ). After downloading the required JAR file, Mobile device stores it in the local Database as depicted in the diagram. On invocation of the Install and run, the MIDLET ( stored in the JAR file), installs itself and start running inside the KVM of the Mobile device. A sample JAD file is listed below: MIDlet-1: eShop, eShop.png, EShop MIDlet-Jar-Size: JAR file size in bytes (such as 1002) MIDlet-Jar-URL: http://www.xyz.com/x/eShop.jar MIDlet-Name: eShop MIDlet-Vendor: MIDlet-Version: version (such as 1.0) Here MIDlet-1 says there is only one MIDLET in the eShop.jar file located at MIDlet-Jar-URL. Size of the eShop.jar file is value against MIDlet-Jar-Size Sometimes client is accessing a WEB server directly from mobile device. Then one HTML file is needed at the server end for mobile devices to access and install the required MIDlet. The HTML file can be as small as : ********************************************************************** Are you looking for some basic and conceptual understanding/information about Scalability (A Non Functional Requirement), I recommend you following links, as I have read through these links and found these interesting and informative to start with. (As these are external links and we are no related to these links, we are not liable for anything related to these links) http://www.infoq.com/news/2007/10/whatisscalability http://www.infoq.com/articles/scalability-principles ********************************************************************** Some of the Java Quiz can be interesting to work out at leisure time at http://www.duke.edu/~trc7/cps/lessons/quiz1.html ********************************************************************** JavaScript based Open Source Framework with Cross browser compatibility and much more at http://mootools.net