Java Interview Questions

 
1.
What is the difference between an Interface and an Abstract class?
2.
What is the purpose of garbage collection in Java, and when is it used?
3.
Describe synchronization in respect to multithreading.
4.
Explain different way of using thread?
5.
What are pass by reference and passby value?
6.
What is HashMap and Map?
7.
Difference between HashMap and HashTable?
8.
Difference between Vector and ArrayList?
9.
Difference between Swing and Awt?
10.
What is the difference between a constructor and a method?
11.
What is an Iterator?
12.
State the significance of public, private, protected, default modifiers both singly and in combination and state the effect of package relationships on declared items qualified by these modifiers.
13.
What is an abstract class?
14.
What is static in java?
15.
What is final?
16.
What if the main method is declared as private?
17.
What if the static modifier is removed from the signature of the main method?
18.
What if I write static public void instead of public static void?
19.
What if I do not provide the String array as the argument to the method?
20.
What is the first argument of the String array in main method?
21.
If I do not provide any arguments on the command line, then the String array of Main method will be empty or null?
22.
How can one prove that the array is not null but empty using one line of code?
23.
What environment variables do I need to set on my machine in order to be able to run Java programs?
24.
Can an application have multiple classes having main method?
25.
Can I have multiple main methods in the same class?
26.
Do I need to import java.lang package any time? Why ?
27.
Can I import same package/class twice? Will the JVM load the package twice at runtime?
28.
What are Checked and UnChecked Exception?
29.
What is Overriding?
30.
What are different types of inner classes?
31.
Are the imports checked for validity at compile time? e.g. will the code containing an import such as java.lang.ABCD compile?
32.
Does importing a package imports the subpackages as well? e.g. Does importing com.MyTest.* also import com.MyTest.UnitTests.*?
33.
What is the difference between declaring a variable and defining a variable?
34.
What is the default value of an object reference declared as an instance variable?
35.
Can a top level class be private or protected?
36.
What type of parameter passing does Java support?
37.
Primitive data types are passed by reference or pass by value?
38.
Objects are passed by value or by reference?
39.
How do I serialize an object to a file?
40.
Which methods of Serializable interface should I implement?
41.
How can I customize the seralization process? i.e. how can one have a control over the serialization process?
42.
What is the common usage of serialization?
43.
What is Externalizable interface?
44.
When you serialize an object, what happens to the object references included in the object?
45.
What one should take care of while serializing the object?
46.
What happens to the static fields of a class during serialization?
47.
Does Java provide any construct to find out the size of an object?
48.
Give a simplest way to find out the time a method takes for execution without using any profiling tool?
49.
What are wrapper classes?
50.
Why do we need wrapper classes?
51.
What are checked exceptions?
52.
What are runtime exceptions?
53.
What is the difference between error and an exception?
54.
How to create custom exceptions?
55.
If I want an object of my class to be thrown as an exception object, what should I do?
56.
If my class already extends from some other class what should I do if I want an instance of my class to be thrown as an exception object?
57.
How does an exception permeate through the code?
58.
What are the different ways to handle exceptions?
59.
What is the basic difference between the 2 approaches to exception handling.
1> try catch block and
2> specifying the candidate exceptions in the throws clause?
When should you use which approach?
60.
Is it necessary that each try block must be followed by a catch block?
61.
If I write return at the end of the try block, will the finally block still execute?
62.
If I write System.exit (0); at the end of the try block, will the finally block still execute?
63.
How are Observer and Observable used?
64.
What is synchronization and why is it important?
65.
How does Java handle integer overflows and underflows?
66.
Does garbage collection guarantee that a program will not run out of memory?
67.
What is the difference between preemptive scheduling and time slicing?
68.
When a thread is created and started, what is its initial state?
69.
What is the purpose of finalization?
70.
What is the Locale class?
71.
What is the difference between a while statement and a do statement?
72.
What is the difference between static and non-static variables?
73.
How are this() and super() used with constructors?
74.
What are synchronized methods and synchronized statements?
75.
What is daemon thread and which method is used to create the daemon thread?
76.
Can applets communicate with each other?
77.
What are the steps in the JDBC connection?
78.
How does a try statement determine which catch clause should be used to handle an exception?
79.
Can an unreachable object become reachable again?
80.
What method must be implemented by all threads?
81.
What is Externalizable?
82.
What modifiers are allowed for methods in an Interface?
83.
What are some alternatives to inheritance?
84.
What does it mean that a method or field is "static"?
85.
What is the catch or declare rule for method declarations?
86.
Is Empty .java file a valid source file?
87.
Can a .java file contain more than one java classes?
88.
Is String a primitive data type in Java?
89.
Is main a keyword in Java?
90.
Is next a keyword in Java?
91.
Is delete a keyword in Java?
92.
Is exit a keyword in Java?
93.
What happens if you dont initialize an instance variable of any of the primitive types in Java?
94.
What will be the initial value of an object reference which is defined as an instance variable?
95.
What are the different scopes for Java variables?
96.
What is the default value of the local variables?
97.
How many objects are created in the following piece of code?
MyClass c1, c2, c3;
c1 = new MyClass ();
c3 = new MyClass ();
98.
Can a public class MyClass be defined in a source file named YourClass.java?
99.
Can main method be declared final?
100.
What will be the output of the following statement?
System.out.println ("1" + 3);
101.
What will be the default values of all the elements of an array defined as an instance variable?
102.
What is the Collections API?
103.
What is the List interface?
104.
What is the Vector class?
105.
What is an Iterator interface?
106.
Which java.util classes and interfaces support event handling?
107.
What is the GregorianCalendar class?
108.
What is the SimpleTimeZone class?
109.
What is the Map interface?
110.
What is the highest-level event class of the event-delegation model?
111.
What is the Collection interface?
112.
What is the Set interface?
113.
What is the typical use of Hashtable?
114.
I am trying to store an object using a key in a Hashtable. And some other object already exists in that location, then what will happen? The existing object will be overwritten? Or the new object will be stored elsewhere?
115.
What is the difference between the size and capacity of a Vector?
116.
Can a vector contain heterogenous objects?
117.
Can a ArrayList contain heterogenous objects?
118.
What is an enumeration?
119.
Considering the basic properties of Vector and ArrayList, where will you use Vector and where will you use ArrayList?
120.
What is a output comment?
121.
What is a Hidden Comment?
122.
What is a Expression?
123.
What is a Declaration?
124.
What is a Scriptlet?
125.
What are implicit objects? List them?
126.
Difference between forward and sendRedirect?
127.
What are the different scope valiues for the ?
128.
Explain the life-cycle mehtods in JSP?
129.
How do I prevent the output of my JSP or Servlet pages from being cached by the browser?
130.
How does JSP handle run-time exceptions?
131.
How can I implement a thread-safe JSP page? What are the advantages and Disadvantages of using it?
132.
How do I use a scriptlet to initialize a newly instantiated bean?
133.
How can I prevent the word "null" from appearing in my HTML input text fields when I populate them with a resultset that has null values?
134.
What's a better approach for enabling thread-safe servlets and JSPs? SingleThreadModel Interface or Synchronization?
135.
How can I enable session tracking for JSP pages if the browser has disabled cookies?
136.
What is the difference b/w variable declared inside a declaration part and variable declared in scriplet part?
137.
Is there a way to execute a JSP from the comandline or from my own application?
138.
Explain the life cycle methods of a Servlet.
139.
What is the difference between the getRequestDispatcher(String path) method of javax.servlet.ServletRequest interface and javax.servlet.ServletContext interface?
140.
Explain the directory structure of a web application.
141.
What are the common mechanisms used for session tracking?
142.
Explain ServletContext.
143.
What is preinitialization of a servlet?
144.
What is the difference between Difference between doGet() and doPost()?
145.
What is the difference between HttpServlet and GenericServlet?
146.
What is the difference between ServletContext and ServletConfig?
147.
What is Struts?
148.
What is Jakarta Struts Framework?
149.
What is ActionServlet?
150.
How you will make available any Message Resources Definitions file to the Struts Framework Environment?
151.
What is Action Class?
152.
What is ActionForm?
153.
What is Struts Validator Framework?
154.
Give the Details of XML files used in Validator Framework?
155.
How you will display validation fail errors on jsp page?
156.
How you will enable front-end validation based on the xml in validation.xml?
157.
How to get data from the velocity page in a action class?
158.
How EJB Invocation happens?
159.
Is it possible to share an HttpSession between a JSP and EJB? What happens when I change a value in the HttpSession from inside an EJB?
160.
The EJB container implements the EJBHome and EJBObject classes. For every request from a unique client, does the container create a separate instance of the generated EJBHome and EJBObject classes?
161.
Can the primary key in the entity bean be a Java primitive type such as int?
162.
Can you control when passivation occurs?
163.
What is the advantage of using Entity bean for database operations, over directly using JDBC API to do database operations? When would I use one over the other?
164.
What is EJB QL?
165.
Brief description about local interfaces?
166.
What are the special design care that must be taken when you work with local interfaces?
167.
What happens if remove( ) is never invoked on a session bean?
168.
What is the difference between Message Driven Beans and Stateless Session beans?
169.
How can I call one EJB from inside of another EJB?
170.
What is an EJB Context?