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

Content Team

The IndicThreads Content Team posts news about the latest and greatest in software development as well as content from IndicThreads' conferences and events. Track us social media @IndicThreads. Stay tuned!

95 thoughts on “Java Interview Questions

  • July 25, 2006 at 6:34 pm
    Permalink

    jsp life cycle? 8)

    -JSP interpretation to servlet, :upset
    -servlet conversion to byte-code, :p
    -load to web server, :roll
    -execute :grin
    -garbage collection 😡

  • July 21, 2006 at 10:36 am
    Permalink

    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.

  • July 20, 2006 at 9:49 am
    Permalink

    can u tell me a software testing interview questions in cognizant

  • July 19, 2006 at 7:20 am
    Permalink

    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

  • July 3, 2006 at 1:29 am
    Permalink

    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.

  • June 27, 2006 at 1:48 pm
    Permalink

    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

  • June 19, 2006 at 10:44 pm
    Permalink

    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

  • May 31, 2006 at 8:36 am
    Permalink

    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.

  • May 31, 2006 at 6:35 am
    Permalink

    Questions are good but should be added with more brief answers. Also, Some more questionss should be added.

  • May 29, 2006 at 1:59 pm
    Permalink

    The site is good for freshers, but i think more questions should be added with answers. 🙂

  • May 24, 2006 at 5:22 am
    Permalink

    [B]java is a lenthe why?[/B]
    struts is a open fram work why? :grin 8)

  • May 22, 2006 at 11:33 am
    Permalink

    [B]EntityBeans are easy in understanding but difficult in putting them into practice !!! Why ???[/B]

  • April 25, 2006 at 6:48 am
    Permalink

    Explaine the session facade design of Entity beans. What are its significance?

    [B]Session facade design[/B]

  • April 23, 2006 at 6:11 am
    Permalink

    1) what are anonymous classes
    2 explain reflect package and its uses

  • April 19, 2006 at 1:05 am
    Permalink

    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

  • March 1, 2006 at 8:08 am
    Permalink

    how to get the conect by clause functionality of oracle when migrating to sql server

  • February 1, 2006 at 10:27 pm
    Permalink

    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.

Leave a Reply