400+ Java Q's and A's : Core Java, Servlets, JSP ...and more

1. What are the four corner stones of OOP ?
Abstraction, Encapsulation, Polymorphism and Inheritance.

2. What do you understand by private, protected and public ?
These are accessibility modifiers. Private is the most restrictive, while public is the least restrictive. There is no real difference between protected and the default type (also known as package protected) within the context of the same package, however the protected keyword allows visibility to a derived class in a different package.

3. Difference between a Class and an Object ?
A class is a definition or prototype whereas an object is an instance or living representation of the prototype.

4. What is Downcasting ?
Downcasting is the casting from a general to a more specific type, i.e. casting down the hierarchy.
5. What is Polymorphism ? What kinds ?

6. What is the difference between method overriding and overloading?
Overriding is a method with the same name and arguments as in a parent, whereas overloading is the same method name but different arguments.

7. What is the restriction on an Overridden methods’ accessibility ?
Overriding methods cannot reduce accessibility - they can either have same or greater accessibility.

8. What is the concept of a Virtual Function ?

9. What is the implication of a Virtual Destructor ? Virtual Constructor ?

10. Can a method be overloaded based on different return type but same argument type ?
No, because the methods can be called without using their return type in which case there is ambiquity for the compiler.

11. What is a "stateless" protocol ?
Without getting into lengthy debates, it is generally accepted that protocols like HTTP are stateless i.e. there is no retention of state between a transaction which is a
single request response combination.

12. What happens to a static var that is defined within a method of a class ?
Can't do it. You'll get a compilation error.

13. What is constructor chaining and how is it achieved in Java ?
A child object constructor always first needs to construct its parent (which in turn calls its parent constructor.). In Java it is done via an implicit call to the no-args
constructor as the first statement.

Link to Behavioural Interview Questions

14. How do you define a local inner class ?

15. How many static init can you have ?
As many as you want, but the static initializers and class variable initializers are executed in textual order and may not refer to class variables declared in the class whose
declarations appear textually after the use, even though these class variables are in scope.

16. What is passed by ref and what by value ?
All Java method arguments are passed by value. However, Java does manipulate objects by reference, and all object variables themselves are references.

17. How do you ensure size of a primitive data type ?
You can't.

18. Describe the Garbage Collection process in Java ?
The JVM spec mandates automatic garbage collection outside of the programmers control. The System.gc() or Runtime.gc() is merely a suggestion to the JVM to run the

GC process but is NOT guaranteed.

19. What is the difference amongst JVM Spec, JVM Implementation, JVM Runtime ?
The JVM spec is the blueprint for the JVM generated and owned by Sun. The JVM implementation is the actual implementation of the spec by a vendor and the JVM

runtime is the actual running instance of a JVM implementation.

20. Can RMI and Corba based applications interact ?
Yes they can. RMI is available with IIOP as the transport protocol instead of JRMP

21 .What is the diffrence between an Abstract class and Interface ?
Ans ) Interface defines the methods. There is no implementation.
Whereas Abstract class may have few implemented methods.If some common functionality needs to be shared.

22. What is user defined exception ?
Ans )

23. What do you know about the garbate collector ?
Ans ) Java has an inbuilt mechanisim for garbage collection.
All those objects not longer being referenced are garbage collected.i.e the memory used by these objects is released.

24.What is the difference between C++ & Java ?
25.Explain RMI Architecture?
26.How do you communicate in between Applets & Servlets ?

27.What is the use of Servlets ?
Ans ) To generate dynamic content based on the request.

28.What is JDBC? How do you connect to the Database ?
Ans ) Java Database connectivity.
Using jdbc drivers provided by db drivers.

29.In an HTML form I have a Button which makes us to open another page in 15 seconds. How will do you that ?

30.What is the difference between Process and Threads ?
Ans ) There could be no of processes(multi tasking) and every process could have no of threads(multi threading).

31. What is the difference between RMI & Corba ?
Ans ) Remote method invocation : java only. uses JRMP to communication between java objects
Common object request broker architecture : platform independent. Uses IIOP to communicate between objects.

32.What are the services in RMI ?
33.How will you initialize an Applet ?
34.What is the order of method invocation in an Applet?
35.When is update method called ?

36.How will you pass values from HTML page to the Servlet ?
Ans ) submitting the html form.

37.Have you ever used HashTable and Dictionary ?
Ans ) Dictionary is an abstract class. Hastable extends Dictionary.

38.How will you communicate between two Applets ?
39.What are statements in JAVA ?

40.What is JAR file ?
Ans ) Jar file is an archive of java classes.

41.What is JNI ?
Ans ) Java Native interfaces.

42.What is the base class for all swing components ?
43.What is JFC ?
Ans ) Java Foundation classes.

44.What is Difference between AWT and Swing ?

45.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 ?
Ans ) processes.

46.How does thread synchronization occurs inside a monitor ?
Ans ) A thread acquires the monitor.i.e it obtains a lock on the monitor.No other thread can acquire a lock on the same monitor until it is released by the previous thread.

47.What are 4 drivers available in JDBC ?
Ans ) jdbc-odbc bridge
Type 4 : pure java driver. no need to have db client installed on client mcs.

48.How you can know about drivers and database information ?
49.How will you perform transaction using JDBC ?
50.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?

51.What is serialization ?
Ans ) Process of persisting an object.

52.What is difference RMI registry and OSAgent ?

53.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 ?

54 What are the benefits of Swing over AWT ?
55 Where the CardLayout is used ?
56 What is the Layout for ToolBar ?
57 What is the difference between Grid and GridbagLayout ?
58 How will you add panel to a Frame ?
59 What is the corresponding Layout for Card in Swing ?
60 What is light weight component ?
63 What is Servlet API used for conneting database ?
64 What is bean ? Where it can be used ?
65 What is difference in between Java Class and Bean ?
66 Can we send object using Sockets ?
67 What is the RMI and Socket ?
68 How to communicate 2 threads each other ?
72 What is the functionality stubs and skeletons ?
74 Diff between Application and Applet ?
75 What is serializable Interface ?
76 What is the difference between CGI and Servlet ?
77 What is the use of Interface ?
78 Why Java is not fully objective oriented ?
79 Why does not support multiple Inheritance ?
80 What it the root class for all Java classes ?
81 What is polymorphism ?
82 Suppose If we have variable 'I' in run method, If I can create one or more thread each thread will occupy a separate copy or same variable will be shared ?
83 In servlets, we are having a web page that is invoking servlets username and password ? which is cheks in the database ? Suppose the second page also If we want to
verify the same information whethe it will connect to the database or it will be used previous information?

90 What are session variable in Servlets ?
91 What is client server computing ?
93 Why we use OOPS concepts? What is its advantage ?
94 What is the middleware ? What is the functionality of Webserver ?
95 Why Java is not 100 % pure OOPS ?
96 When we will use an Interface and Abstract class ?
97 What is an RMI?
98 How will you pass parameters in RMI ? Why u serialize?
100 What is the main functionality of the Remote Reference Layer ?