Recently I have attend the interview in one of the reputed MNC company for JAVA/J2EE technologies. I tried my level best to recollect all interview questions that I have faced are listed here:
JAVA/J2EE Interview questions
- What are the features newly introduced in JAVA SE 5.0
- What is the necessity of Generic Programming?
- Syntax of Generic Class and Methods declaration
- Give collection hierarchy
- Which collections are sorted.
- Difference between Arraylist and Vector
- Difference between Collection and Collections
- If I want to sort ArrayList, what we need to do.
- Difference between Comparable and Comparator.
- What compareTo() method will return and explain each returned data.
- Difference between checked and unchecked exception
- Hierarchy of Exceptions
- Do we need to catch Error? Difference between Error and Exception
- List some checked and unchecked exception
- Do we need to make sure anything when we write try-catch blocks
- Will the statements after catch block run when after an exception was raised in try block.
- When finally block executes
- What is the use of throws keyword
- What are the methods to create thread? Which is best method?
- Does the Thread class implements Runnable interface.
- When we implement Runnable interface, which method do we need to implement.
- How you will start the thread for execution.
- What will happen when you call start () method. Can I start thread without start () method?
- What will happen when we explicitly call run() method to start execution without start() method
- Difference between sleep() and wait() methods
- When sleep time expired, will the thread enters runnable state or running state.
- Difference between notify() and notifyall() methods
- Difference between abstract and interface
- When we go for abstract and when we go for interface.
- How do you implement synchronization? What are the methods?
- What is polymorphism? How do you implement it?
- Difference between overriding and overloading?
- Do return type should be same when we implement method overriding
- Can I override Static methods? Are you sure?
- Default access specifiers of method declarations in Interface
- Default access specifiers of variable declarations in Interface
- Can I declare abstract method in non-abstract class
Continues….
34.
Class A {
void display()
{
S.o.p( “class A” );
}
}
Class B extends A
{
void display()
{
S.o.p (“Class B” );
}
}
A obj = new B();
Obj.display(); //what is the output of this line.
————————————————————————-
Class A {
Static void display()
{
S.o.p( “class A” );
}
}
Class B extends A
{
Static void display()
{
S.o.p (“Class B” );
}
}
A obj = new B();
Obj.display(); //Are you sure what is the output of this line. Why??
Class A {
Static int I = 10;
}
Class B extends A
{
Static int I = 30;
}
A obj = new B();
System.out.println(Obj.I); //what is the output of this line.
——————————————————-
- When garbage collector will run?
- Can we call garbage collector? What is the method to call the same?
- What is serialization? How do you implement it?
- What happens when serializable object has reference to another object as instance variable?
- Difference between private, protected and public access specifiers.
- Can I declare static class?
- How do you create object for inner class?
J2EE
- Lifecycle of Servlet
- What is the purpose of init() method. We can use the servlet constructor for initialization right? Why do we need init() method still?
- Difference between ServletConfig and ServletContext?
- Where do you implement ServletConfig and ServletContext parameters?
- Do we need to override Service() method while writing Servlet class
- Difference between RequestDispatcher and SendRedirect
- Can I forward the request if I have already commited the response. What exception will throw if we already commited a response and forwards the request?
- Having Servlet classes, can I use Java Swing instead of JSP in presentation layer? How do you do that?
- How do you create session?
- What is the difference between getSession(true), getSession() and getSession(false)?
- How do you declare session timeout in the Deployment Descriptor?
Continues…
- What is the difference between GET and POST methods? What happen If I didn’t declare method attribute in <form> tag?
- What are the other HTTP methods? Purpose of TRACE method?
- What is the use of setContentType() method?
- How may ways to get reference to ServletContext object?
- What is the purpose of ServletContextListener? Give some example when we can use this?
- What is the purpose of HttpSessionAttributeListener? What is the event type of this listener?
- Purpose of SingleThreadModel interface?
- How does the web container guarantee a servlet gets only one request at a time?
- Life cycle of JSP?
- List of implicit objects in JSP?
- What is the use of application object? What is the API of out object?
- How do import packages in JSP?
- How to use <jsp:useBean>….purpose…how to set and get property..?
- How do you implement exception handling in JSP?
- Difference between include directive and <jsp:include>
- What is difference between Statement and Prepared Statement?
- What is the use of Callable Statement?
- What is inner join?
- How do you implement AJAX concept in JavaScript?