Java Interview Questions
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 thecompiler.
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.
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 maynot refer to class variables declared in the class whose declarations appear textually after the use, even though these class variables are in scope
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.
How do you ensure size of a primitive data type ?
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 actualimplementation of the spec by a vendor and the JVM.Runtime is the actual running instance of a JVM implementation.
Can RMI and Corba based applications interact ?
Yes they can. RMI is available with IIOP as the transport protocol instead of JRMP
What is the diffrence between an Abstract class and Interface ?
Interface defines the methods. There is no implementation.
Whereas Abstract class may have few implemented methods.If some common functionality needs to be shared.
What do you know about the garbage collector ?
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 isreleased.
What is the use of Servlets ?
To generate dynamic content based on the request.
What is JDBC? How do you connect to the Database ?
Java Database connectivity.
Using jdbc drivers provided by db drivers.
What is the difference between RMI & Corba ?
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.
What is JAR file ?
Jar file is an archive of java classes.
What are 4 drivers available in JDBC ?
Type 4 : pure java driver. no need to have db client installed on client mcs.
What is serialization ?
Process of persisting an object.
How to call EJB from Struts?
We can call EJB from struts by using the service locator design patteren or by Using initial context with create homeobject and getting return remote referenc object.
What are the four corner stones of OOP ?
Abstraction, Encapsulation, Polymorphism and Inheritance.
What is Downcasting ?
Downcasting is the casting from a general to a more specific type, i.e. casting down the hierarchy.
What is the restriction on an Overridden methods accessibility ?
Overriding methods cannot reduce accessibility – they can either have same or greater accessibility.
What is a “stateless” protocol ?
Without getting into lengthy debates, it is generally accepted that protocols like HTTP are stateless i.e. there is noretention of state between a transaction which is a single request response combination.