Large collection of Java interview questions

  1. What is the difference between an Abstract class and Interface ?
  2. What is user defined exception ?
  3. What do you know about the garbage collector ?

  4. What is the difference between C++ & Java ?
  5. Explain RMI Architecture?
  6. How do you communicate in between Applets & Servlets ?
  7. What is the use of Servlets ?
  8. What is JDBC? How do you connect to the Database ?
  9. In an HTML form I have a Button which makes us to open another page in 15 seconds. How will do you that ?
  10. What is the difference between Process and Threads ?
  11. What is the difference between RMI & Corba ?
  12. What are the services in RMI ?
  13. How will you initialize an Applet ?
  14. What is the order of method invocation in an Applet ?
  15. When is update method called ?
  16. How will you pass values from HTML page to the Servlet ?
  17. Have you ever used HashTable and Dictionary ?
  18. How will you communicate between two Applets ?
  19. What are statements in JAVA ?
  20. What is JAR file ?
  21. What is JNI ?
  22. What is the base class for all swing components ?
  23. What is JFC ?
  24. What is Difference between AWT and Swing ?
  25. Considering notepad/IE or any other thing as process, What will happen if you start notepad or IE 3 times? Where 3 processes are started or 3 threads are started ?
  26. How does thread synchronization occurs inside a monitor ?
  27. How will you call an Applet using a Java Script function ?
  28. Is there any tag in HTML to upload and download files ?
  29. Why do you Canvas ?
  30. How can you push data from an Applet to Servlet ?
  31. What are 4 drivers available in JDBC ?
  32. How you can know about drivers and database information ?
  33. If you are truncated using JDBC, How can you know ..that how much data is truncated ?
  34. And What situation , each of the 4 drivers used ?
  35. How will you perform transaction using JDBC ?
  36. In RMI, server object first loaded into the memory and then the stub reference is sent to the client ? or whether a stub reference is directly sent to the client ?
  37. Suppose server object is not loaded into the memory, and the client request for it , what will happen?
  38. What is serialization ?
  39. Can you load the server object dynamically? If so, what are the major 3 steps involved in it ?
  40. What is difference RMI registry and OSAgent ?
  41. To a server method, the client wants to send a value 20, with this value exceeds to 20,. a message should be sent to the client ? What will you do for achieving for this ?
  42. What are the benefits of Swing over AWT ?
  43. Where the CardLayout is used ?
  44. What is the Layout for ToolBar ?
  45. What is the difference between Grid and GridbagLayout ?
  46. How will you add panel to a Frame ?
  47. What is the corresponding Layout for Card in Swing ?
  48. What is light weight component ?
  49. Can you run the product development on all operating systems ?
  50. What is the webserver used for running the Servlets ?
  51. What is Servlet API used for connecting database ?
  52. What is bean ? Where it can be used ?
  53. What is difference in between Java Class and Bean ?
  54. Can we send object using Sockets ?
  55. What is the RMI and Socket ?
  56. How to communicate 2 threads each other ?
  57. What are the files generated after using IDL to Java Compilet ?


Looking for answers? Try this book:



This entry was posted in Java. Bookmark the permalink. Post a comment or leave a trackback: Trackback URL.

6 Comments on Large collection of Java interview questions

  1. Don Bora
    Posted 2/10/2004 at 9:47 pm | Permalink

    For those wanting the answers to the questions, just google the stuff, it takes more time than memorizing the questions but at least you have a better shot at actually /knowing/ what you’re talking about. Also, um… some of the grammar in some of the questions.. really… can’t that be cleaned up?

    Aside from that. Great list. I’ve actually been asked JVM level questions only to find out that that the interviewer was sub-par at programming. I am going to start issuing my own test before I let someone test my knowledge.

  2. Research_and_Learn
    Posted 3/24/2004 at 2:19 pm | Permalink

    Instead of begging for the answers look them up your self…you will learn a lot more…….

  3. Kathy
    Posted 4/3/2004 at 11:24 pm | Permalink

    Vectors and Threads
    The thread methods are synchronized so you will not corrupt a vector by manipulating it with more than one thread.
    However, care must still be taken.
    Consider the following application:
    import java.util.*;
    import java.io.*;

    class vector3 {

    public static void ShowVector(Vector v) {
    String str;

    for (int i=0; i < v.size();i++) {
    try {
    Thread.sleep(100);
    }
    catch (InterruptedException e) {}
    str = (String)v.elementAt(i);
    System.out.println(i+" :"+str);
    }
    }

    public static void main(String args[]) {

    Vector v;
    BusyThread T;

    v = new Vector();
    T = new BusyThread(v,1000);
    T.start();
    for (int i=0; i < 10; i++) {
    System.out.println("Vector had size "+v.size());
    ShowVector(v);
    System.out.println("Vector has size "+v.size());
    try {
    Thread.sleep(1000);
    }
    catch (InterruptedException e) {}
    }
    }
    }
    BusyThread just adds to and removes elements from a vector at random:
    import java.util.*;

    class BusyThread extends Thread {
    Vector v;
    int count;

    public BusyThread(Vector v, int count) {
    this.v = v;
    this.count = count;
    }

    public void run() {
    double ran;
    for (int i=0; i < count; i++) {
    ran = Math.random();
    if (ran > 0.5)
    v.addElement(”abcdef”+i);
    else if (v.size() > 0)
    v.removeElementAt(0);
    try {
    sleep(10);
    }
    catch (InterruptedException e) {}
    }
    }
    }
    The timing is set up to make it likely that the vector will change between when the index is checked against the size of the vector and when the element is gotten from the vector.

    Enumerations
    Another way to step through elements of a vector is with an Enumeration.
    An Enumeration is an interface with two methods:
    · public abstract boolean hasMoreElements()
    · public abstract Object nextElement()
    You can create an enumeration from a vector with the elements method:
    public final synchronized Enumeration elements()
    Here is how you might use it in the above example:
    class vector4 {

    public static void ShowVector(Vector v) {
    String str;
    Enumeration enum;

    enum = v.elements();
    while (enum.hasMoreElements()) {
    try {
    Thread.sleep(100);
    }
    catch (InterruptedException e) {}
    str = (String)enum.nextElement();
    System.out.println(str);
    }
    }

    We can run this and see if it has the same problem.
    The vector documentation says:
    Any changes to this vector may be visible in this enumeration, depending on where the changes were made and how far the enumeration has proceeded.
    One way to fix the problem is by catching the exception that is thrown by nextElement
    class vector4c {

    public static void ShowVector(Vector v) {
    String str;
    Enumeration enum;

  4. Kathy
    Posted 4/3/2004 at 11:28 pm | Permalink

    !DOCTYPE HTML PUBLIC “-//W3C//DTD HTML 4.0 Transitional//EN”>

    < ?xml version="1.0"?> xmlns="http://www.w3.org/2002/xhtml">Java Job Interview Questions





    rel=stylesheet>

    Java Language Questions


    1. What is a platform?

      A platform is the hardware or software environment in which a program runs.
      Most platforms can be described as a combination of the operating system and
      hardware, like Windows 2000/XP, Linux, Solaris, and MacOS.


    2. What is the main difference between Java platform and other platforms?

      The Java platform differs from most other platforms in that it’s a
      software-only platform that runs on top of other hardware-based platforms.

      The Java platform has two components:

      1. The Java Virtual Machine (Java VM)
      2. The Java Application Programming Interface (Java API)

    3. What is the Java Virtual Machine?

      The Java Virtual Machine is a software that can be ported onto various
      hardware-based platforms.


    4. What is the Java API?

      The Java API is a large collection of ready-made software components that
      provide many useful capabilities, such as graphical user interface (GUI)
      widgets.


    5. What is the package?

      The package is a Java namespace or part of Java libraries. The Java API is
      grouped into libraries of related classes and interfaces; these libraries are
      known as packages.


    6. What is native code?

      The native code is code that after you compile it, the compiled code runs
      on a specific hardware platform.


    7. Is Java code slower than native code?

      Not really. As a platform-independent environment, the Java platform can be
      a bit slower than native code. However, smart compilers, well-tuned
      interpreters, and just-in-time bytecode compilers can bring performance close
      to that of native code without threatening portability.


    8. What is the serialization?

      The serialization is a kind of mechanism that makes a class or a bean
      persistence by having its properties or fields and state information saved and
      restored to and from storage.


    9. How to make a class or a bean serializable?

      By implementing either the java.io.Serializable interface, or the
      java.io.Externalizable interface. As long as one class in a class’s
      inheritance hierarchy implements Serializable or Externalizable, that class is
      serializable.


    10. How many methods in the Serializable interface?

      There is no method in the Serializable interface. The Serializable
      interface acts as a marker, telling the object serialization tools that your
      class is serializable.


    11. How many methods in the Externalizable interface?

      There are two methods in the Externalizable interface. You have to
      implement these two methods in order to make your class externalizable. These
      two methods are readExternal() and writeExternal().


    12. What is the difference between Serializalble and Externalizable interface?

      When you use Serializable interface, your class is serialized automatically
      by default. But you can override writeObject() and readObject() two methods to
      control more complex object serailization process. When you use Externalizable
      interface, you have a complete control over your class’s serialization
      process.


    13. What is a transient variable?

      A transient variable is a variable that may not be serialized. If you don’t
      want some field not to be serialized, you can mark that field transient or
      static.


    14. Which containers use a border layout as their default layout?

      The window, Frame and Dialog classes use a border layout as their default
      layout.


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


    16. 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 causes dirty data and leads to significant errors.


    17. Is Java a super set of JavaScript?

      No. They are completely different. Some syntax may be similar.


  5. Posted 4/21/2004 at 5:57 am | Permalink

    Hi friends Sachin again,
    Answers to some more questions:

    What is user defined exception?
    Ans: There are many exception defined by java which are used to track the run time exceptions and act accordingly. User can also define his exceptions that can be thrown in the same way java exceptions.

    What do you know about the garbage collector?
    Ans: Garbage collector is used to recollect memory from the us=nused objects. They are the objects that are no longer needed because of function or class scope is going to finish.

    Explain RMI Architecture?
    Ans: Sometimes it is necessary to invoke a method of an object that is being executed on a remote machine as part of distributed computing. This shares computation between 2 machines. Fortunately java has provided this mechanism. This mechanism is called RMI.

    What is the use of Servlets?
    Ans: Servlets are used as a middleware and contains the whole business logic and keep client and server free with their presentation and data processing parts respectively. They are mainly used in web projects where many clients are requesting the service from the server. The communication always takes place through servlets.

    What is JDBC? How do you connect to the Database?
    Ans: Java Database Connectivity is a technique of connect java front end to back end database and allowing the retrieval and manipulation of data in the database using java. The process of using JDBC to connect to the database is as follows:
    1. Register the driver: Class.forName(”driverName”)// for example, sun.jdbc.odbc.JdbcOdbcDriver
    2. Making the connection using DriverManager Class’s getConnection method: Connection con = DriverManager.getConnection(”url,”myLogin”, “myPassword”); // For example url may be jdbc:odbc:dsn_name.
    3. Creating the JDBC Statement: Statement stmt = con.createStatement();
    4. Retreiving the data in the ResultSet: ResultSet rs = stmt.executeQuery(query); // where query can be any valid sql query.

    What is the difference between Process and Threads?
    Ans: Process is a program in execution. The execution of processes must be sequential. On the other hand thread is a light-weighted process which is executed in parallel with other threads. The theard shares some of the resources with other threads but ceratin things are unique to as particular thread like process id and program counter.

    What is the difference between RMI & Corba?
    Ans: The main difference between the two is in RMI a method is invoked executing on a remote machine while in Corba the whole obejct is returned back to the calling machine. Moreover for RMI object whose method is being called must be alive where as for Corba object may not need to be alived.

    How will you initialize an Applet?
    Ans: Using init() method.

    What is the order of method invocation in an Applet?
    Ans: The following is order:
    1. init()
    2. start()
    3. paint()
    4. stop()
    5. destroy()

    When is update method called?
    Ans: update method is called every time whenever we call a repaint() method.

    How will you pass values from HTML page to the Servlet?
    Ans: HTML page calls Servlet using action attribute of form tag. In the servlet paramaters names and their values can be retreived using
    request.getParameterNames() and request.getParameterValues(paramName) functions.

  6. Venkatesh
    Posted 6/27/2004 at 3:54 am | Permalink

    Only few questions has been answered. Thanks for that. Can I please get the complete list of answers for all the questions mentioned above.

Post a Comment

Your email is never published nor shared. Required fields are marked *

*
*