Java Interview Questions
The tech job market is very
active these days, particularly in the developing world. Techies seem to be jumping jobs left, right and center.
Naturally the most discussed topics in developer circles are jobs and job interview questions.
During discussions with a few developer friends, we came up with this idea of creating a databank of frequently asked
interview questions (FAQs).
The
easy way to create this interview questions databank, is to ask as many
people as possible to share the questions they were asked or the
questions that they asked.
If you wish to share Java Interview Question/s, please
add a comment to this particular item.
Please copy paste the following format and add your comment.
We will later compile all data into any easy to use format, mostly an
Excel sheet.
Name (optional):
Company (optional):
Location –
Job Position-
Experience-
Skills –
Questions & Answers:
(Update: Aug 06) – Comments over the past year suggest that in Java questions 1) Interfaces 2) Abstract classes are easily the most popular topics. While for web applications questions related to request, session and application scopes are popular.
For questions on:
Software Quality and Testing Interview Questions
Python Interview Questions
Related:
Java and J2EE Today: An interview with Satish Talim
Interviews with Java experts
jsp life cycle? 8)
-JSP interpretation to servlet, :upset
-servlet conversion to byte-code, :p
-load to web server, :roll
-execute :grin
-garbage collection 😡
What is the difference between POST and GET?
Get – form data is to be encoded (by a browser) into a URL. Usage recommendations – If the processing of a form is idempotent (i.e. it has no lasting observable effect on the state of the world), then the form method should be GET. Many database searches have no visible side-effects and make ideal applications of query forms.
Post – form data is to appear within a message body. Usage – If the service associated with the processing of a form has side effects (for example, modification of a database or subscription to a service), the method should be POST.
What problems might you encounter if you have a class level variable in a servlet?
All requests use the same instance of a servlet and values can get over-written. Unless the servlet implements single Thread model
What is an interface?
Within the Java programming language, an interface is a type, just as a class is a type. Like a class, an interface defines methods. Unlike a class, an interface never implements methods; instead, classes that implement the interface implement the methods defined by the interface. A class can implement multiple interfaces.
What does the ‘protected’ keyword do?
It allows access to class, package and subclass.
When writing code to access the database, where is the best place to write your query? In the JSP, the servlet or somewhere else?
Best to write it in xml/config files. So that if the DB changes, the code does not have to be recomplied
Why do we have wait()/notify()/notifyAll() methods in Objects class?
Wait causes current thread to wait until either another thread invokes the notify() method or the notifyAll() method for this object, or a specified amount of time has elapsed. So the thread which owns the monitor will wait for object to be available.
The thread goes in wait state for this object and then to relinquish any and all synchronization claims on this object. Thread T becomes disabled for thread scheduling purposes and lies dormant until one of four things happens:
• Some other thread invokes the notify method for this object and thread T happens to be arbitrarily chosen as the thread to be awakened.
• Some other thread invokes the notifyAll method for this object.
• Some other thread interrupts thread T.
• The specified amount of real time has elapsed, more or less. If timeout is zero, however, then real time is not taken into consideration and the thread simply waits until notified.
What is a weak reference?
Suppose that the garbage collector determines at a certain point in time that an object is weakly reachable. At that time it will atomically clear all weak references to that object and all weak references to any other weakly-reachable objects from which that object is reachable through a chain of strong and soft references. At the same time it will declare all of the formerly weakly-reachable objects to be finalizable. At the same time or at some later time it will enqueue those newly-cleared weak references that are registered with reference queues.
If Static method is synchronized which object is considered for lock?
Class gets the lock not the object.
Explain monitors in java?
Java provides a monitor when a class has synchronized methods. Whenever control enters a synchronized method, the thread that called the method acquires the monitor for the object whose method has been called. Other threads cannot call a synchronized method on the same object until the monitor is released.
can u tell me a software testing interview questions in cognizant
Please give me Java questions which are asked in industries e.g. how we use .zip format or what is the need of JSP when servlets are there. and also networking questions
good qs..imp ones 🙂
Q: What is the difference between an Interface and an Abstract class?
A: An abstract class can have instance methods that implement a default behavior. An Interface can only declare constants and instance methods, but cannot implement default behavior and all methods are implicitly abstract. An interface has all public members and no implementation. An abstract class is a class which may have the usual flavors of class members (private, protected, etc.), but has some abstract methods.
do get()- send limited data
do post()-send unlimited data
interface – contains only abstract methods and finnal constants
protect keyword for datamemebers – they are available only for the classes and subclasses in the same package
request scope – data in request bean avaliable for all the pages of current client request
application scope- data in apllication bean available to all session and all pages in the application.
page – data is available only to current page
transient keyword for variables- is used when we think a varible sholdn’t be serialized
Theses are a few ques in my first interview
1) wht is MVC
2) wht is thread syncronization. explain the use of nitify all
3)Java autimatically handles garbage collection, but how will we call the garbage collector at runtime.
4) what is the diff between ServletContext and SessionContext
J2EE transactiom follow the Distributed Transaction Processing specs , where we have 3 basic components. Application programs(AP), Resouce Manager(RM) and Transaction Manager(TM)
so a TM interacts with the RM using a XA interface where as TM interacts with AP using
a TX interface.
Questions are good but should be added with more brief answers. Also, Some more questionss should be added.
The site is good for freshers, but i think more questions should be added with answers. 🙂
its nice but wat abt answers?
[B]java is a lenthe why?[/B]
struts is a open fram work why? :grin 8)
[B]EntityBeans are easy in understanding but difficult in putting them into practice !!! Why ???[/B]
[B]can we make two main in one program[/B] 😡
Explaine the session facade design of Entity beans. What are its significance?
[B]Session facade design[/B]
1) what are anonymous classes
2 explain reflect package and its uses
if the Parent class and child class should have same class name and signature,called Run Time Polymorphism.
Using dynamic Dispatcher method we can achive Run time Polymorphism
What is run time polymorphism?
Difference between JTA and JTS
I found a blog which describes what these interfaces mean
http://javahub.blogspot.com/
how to get the conect by clause functionality of oracle when migrating to sql server
heard so
What does abstract mean?
[B]null[/B]
J2EE transactiom follow the Distributed Transaction Processing specs , where we have 3 basic components. Application programs(AP), Resouce Manager(RM) and Transaction Manager(TM)
so a TM interacts with the RM using a XA interface where as TM interacts with AP using
a TX interface.
RM can be like a JDBC driver.