My JAVA/J2EE Interview Experience
1. Architecture of my last project. Few questions based on that.
2. List<Object> obj = new ArrayList<String>();
Will the above compile?
Why polymorphism works for List and ArrayList, why not for generic types <Object> and <String> in the above line?
3. What are the access specifiers?
4. What is the difference between default and protected access specifiers?
5. Can I access protected variable in the following code?
Package pack1;
Class A
{
Protected int variable = 10;
}
Package pack2;
Import pack1.*;
Class B extends A
{
Public void display()
{
A obj = new A();
System.out.println( obj.variable ); //Will this give output????
}
}
6. Write an interface. Write an abstract class? Write a class which extends and implements the above two? Will the code compile. If yes, whether the display method implementation is applicable to interface sample1 or abstract class sample2. If no, why it won’t compile?
interface sample1
{
void display();
}
absctract class sample2
{
abstract void display();
}
class A extends sample2 implements sample1
{
public void display()
{
System.out.println( “display method implementation” );
}
}
7. Method Overriding rules? Do I need to take care anything about access specifiers while method overriding?
8. From the following code,
import java.io.*;
Class A
{
protected void display() throws IOException
{}
}
Class B
{
public void display() throws Exception
{}
}
Will the above code compile? Justify?
9. I have an Employee object with attributes like employee ID, employee name. I have stored these employee objects in an ArrayList. I want to display the arraylist of employees sorted by employee ID as well as employee name. How you will do that? (NOTE: They asked me to write complete code. They mainly focused on the logic)
10. I have a class. I want to execute the class without any method()? Is it possible?
11. From the following code,
Public void display()
{
——- int variable;
}
What are the access level specifiers can be declared with the above variables? (NOTE: Explained the local variables rules)
12. Can I serialize static variable?
13. From the following code in Servlet
Map mymap = new HashMap();
Mymap.put( “1”, “a” );
Mymap.put( “2”, “b” );
Mymap.put( “3”, “c” );
Mymap.put( “4”, “d” );
Mymap.put( “5”, “e” );
Request.setAttribute( “mycollection”, mymap );
Write the JSP code to retrieve the elements and load it in a combo box.
14. What is ServletContext and ServletConfig?
15. How you declare servlet in deployment descriptior? (NOTE: I wrote the complete list of tags)
16. What is load on startup? How you declare in deployment descriptor? What kind of value we need to mention there?
17. From the following code,
Class A
{
int a = 10;
void display()
{
System.out.println( “class a” );
}
}
Class B extends A
{
Int a = 100;
Void display()
{
System.out.println( “class b” );
}
Public static void main( String [] args )
{
A aobj = new B();
Aobj.display(); //What is the output????? Why???
System.out.println( Aobj.a ); //What is the output????? Why???
}
}
18. How you will the forward the request from Servlet to other web component?
19. What is the difference between forward() and include() methods of ServletRequestDispatcher?
20. From how many ways we can get the reference to ServletRequestDispatcher?
21. What is the difference between getSession(false) and getSession() and getSession(true)?
22. What are the implicit objects in JSP?
23. How you will handle exception handling in JSP?
24. Write the JAVA code to retrieve data from database? (NOTE: I wrote the complete JDBC code. They are mainly focusing on how you are catching the exception)
25. Write the code showing an example try, catch and finally?
26. How you implemented the AJAX? What object we use?
27. Write an SQL query to display the top 2 salary from the following table,
Table: employee
EmpID EmpName Salary DepartmentID
1 A 1000 2
2 B 3000 1
3 C 2500 2
4 D 5000 3
5 E 3000 3
Table: department
deptID deptName
1 production
2 development
3 testing
4 management
28. Write an SQL query to display the department ID of the employee having salary greater than 2500?
29. Second Round – Asked questions from all the projects mentioned in the resume? Questions like how you implemented? How it works?