- What is the difference between an Abstract class and Interface ?
- What is user defined exception ?
- What do you know about the garbage collector ?
- What is the difference between C++ & Java ?
- Explain RMI Architecture?
- How do you communicate in between Applets & Servlets ?
- What is the use of Servlets ?
- What is JDBC? How do you connect to the Database ?
- In an HTML form I have a Button which makes us to open another page in 15 seconds. How will do you that ?
- What is the difference between Process and Threads ?
- What is the difference between RMI & Corba ?
- What are the services in RMI ?
- How will you initialize an Applet ?
- What is the order of method invocation in an Applet ?
- When is update method called ?
- How will you pass values from HTML page to the Servlet ?
- Have you ever used HashTable and Dictionary ?
- How will you communicate between two Applets ?
- What are statements in JAVA ?
- What is JAR file ?
- What is JNI ?
- What is the base class for all swing components ?
- What is JFC ?
- What is Difference between AWT and Swing ?
- 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 ?
- How does thread synchronization occurs inside a monitor ?
- How will you call an Applet using a Java Script function ?
- Is there any tag in HTML to upload and download files ?
- Why do you Canvas ?
- How can you push data from an Applet to Servlet ?
- What are 4 drivers available in JDBC ?
- How you can know about drivers and database information ?
- If you are truncated using JDBC, How can you know ..that how much data is truncated ?
- And What situation , each of the 4 drivers used ?
- How will you perform transaction using JDBC ?
- 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 ?
- Suppose server object is not loaded into the memory, and the client request for it , what will happen?
- What is serialization ?
- Can you load the server object dynamically? If so, what are the major 3 steps involved in it ?
- What is difference RMI registry and OSAgent ?
- 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 ?
- What are the benefits of Swing over AWT ?
- Where the CardLayout is used ?
- What is the Layout for ToolBar ?
- What is the difference between Grid and GridbagLayout ?
- How will you add panel to a Frame ?
- What is the corresponding Layout for Card in Swing ?
- What is light weight component ?
- Can you run the product development on all operating systems ?
- What is the webserver used for running the Servlets ?
- What is Servlet API used for connecting database ?
- What is bean ? Where it can be used ?
- What is difference in between Java Class and Bean ?
- Can we send object using Sockets ?
- What is the RMI and Socket ?
- How to communicate 2 threads each other ?
- What are the files generated after using IDL to Java Compilet ?
>
Looking for answers? Try this book:


6 Comments on Large collection of Java interview questions
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.
Instead of begging for the answers look them up your self…you will learn a lot more…….
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;
!DOCTYPE HTML PUBLIC “-//W3C//DTD HTML 4.0 Transitional//EN”>
xmlns="http://www.w3.org/2002/xhtml">< ?xml version="1.0"?>
rel=stylesheet>
Java Language Questions
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.
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:
The Java Virtual Machine is a software that can be ported onto various
hardware-based platforms.
The Java API is a large collection of ready-made software components that
provide many useful capabilities, such as graphical user interface (GUI)
widgets.
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.
The native code is code that after you compile it, the compiled code runs
on a specific hardware platform.
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.
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.
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.
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.
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().
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.
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.
The window, Frame and Dialog classes use a border layout as their default
layout.
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.
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.
No. They are completely different. Some syntax may be similar.
src="Java Job Interview Questions_files/foot.html" frameBorder=0
width="100%">
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.
Only few questions has been answered. Thanks for that. Can I please get the complete list of answers for all the questions mentioned above.