Interview Questions

1.                  What is garbage collection? What is the process that is responsible for doing that in java?
Reclaiming the unused memory by the invalid objects. Garbage collector is responsible for this process
2.                  What kind of thread is the Garbage collector thread?
It is a daemon thread
3.                  What is a daemon thread? 
These are the threads which can run without user intervention. The JVM can exit when there are daemon thread by killing them abruptly.
4.                  How will you invoke any external process in Java? 
Runtime.getRuntime().exec(….)
5.                  What is the finalize method do? 
Before the invalid objects get garbage collected, the JVM give the user a chance to clean up some resources before it got garbage collected.
6.                  What is mutable object and immutable object? 
If a object value is changeable then we can call it as Mutable object. (Ex., StringBuffer, …) If you are not allowed to change the value of an object, it is immutable object. (Ex., String, Integer, Float, …)
7.                  What is the basic difference between string and stringbuffer object? 
String is an immutable object. StringBuffer is a mutable object.
8.                  What is the purpose of Void class? 
The Void class is an uninstantiable placeholder class to hold a reference to the Class object representing the primitive Java type void.
9.                  What is reflection? 
Reflection allows programmatic access to information about the fields, methods and constructors of loaded classes, and the use reflected fields, methods, and constructors to operate on their underlying counterparts on objects, within security restrictions.
10.              What is the base class for Error and Exception? 
Throwable
11.              What is the byte range? 
128 to 127
12.              What is the implementation of destroy method in java.. is it native or java code? 
This method is not implemented.
13.              What is a package? 
To group set of classes into a single unit is known as packaging. Packages provides wide namespace ability.
14.              What are the approaches that you will follow for making a program very efficient? 
By avoiding too much of static methods avoiding the excessive and unnecessary use of synchronized methods Selection of related classes based on the application (meaning synchronized classes for multiuser and non-synchronized classes for single user) Usage of appropriate design patterns Using cache methodologies for remote invocations Avoiding creation of variables within a loop and lot more.
15.              What is a DatabaseMetaData? 
Comprehensive information about the database as a whole.
16.              What is Locale?
A Locale object represents a specific geographical, political, or cultural region
17.              How will you load a specific locale? 
Using ResourceBundle.getBundle(…);
18.              What is JIT and its use? 
Really, just a very fast compiler… In this incarnation, pretty much a one-pass compiler — no offline computations. So you can’t look at the whole method, rank the expressions according to which ones are re-used the most, and then generate code. In theory terms, it’s an on-line problem.
19.              Is JVM a compiler or an interpreter? 
Interpreter
20.              When you think about optimization, what is the best way to findout the time/memory consuming process? 
Using profiler
21.              What is the purpose of assert keyword used in JDK1.4.x? 
In order to validate certain expressions. It effectively replaces the if block and automatically throws the AssertionError on failure. This keyword should be used for the critical arguments. Meaning, without that the method does nothing.
22.              How will you get the platform dependent values like line separator, path separator, etc., ? 
Using Sytem.getProperty(…) (line.separator, path.separator, …)
23.              What is skeleton and stub? what is the purpose of those? 
Stub is a client side representation of the server, which takes care of communicating with the remote server. Skeleton is the server side representation. But that is no more in use… it is deprecated long before in JDK.
24.              What is the final keyword denotes? 
final keyword denotes that it is the final implementation for that method or variable or class. You can’t override that method/variable/class any more.
25.              What is the significance of ListIterator? 
You can iterate back and forth.
26.              What is the major difference between LinkedList and ArrayList? 
LinkedList are meant for sequential accessing. ArrayList are meant for random accessing.
27.              What is nested class? 
If all the methods of a inner class is static then it is a nested class.
28.              What is inner class? 
If the methods of the inner class can only be accessed via the instance of the inner class, then it is called inner class.
29.              What is composition? 
Holding the reference of the other class within some other class is known as composition.
30.              What is aggregation? 
It is a special type of composition. If you expose all the methods of a composite class and route the method call to the composite method through its reference, then it is called aggregation.
31.              What are the methods in Object?
clone, equals, wait, finalize, getClass, hashCode, notify, notifyAll, toString
32.              Can you instantiate the Math class?
You can’t instantiate the math class. All the methods in this class are static. And the constructor is not public.
33.              What is singleton? 
It is one of the design pattern. This falls in the creational pattern of the design pattern. There will be only one instance for that entire JVM. You can achieve this by having the private constructor in the class. For eg., public class Singleton { private static final Singleton s = new Singleton(); private Singleton() { } public static Singleton getInstance() { return s; } // all non static methods … }
34.              What is DriverManager? 
The basic service to manage set of JDBC drivers.
35.              What is Class.forName() does and how it is useful? 
It loads the class into the ClassLoader. It returns the Class. Using that you can get the instance ( “class-instance”.newInstance() ).
36.              What is the difference between an Interface and an Abstract class?
An abstract class can have instance methods that implement a default behavior. An Interface can only declare constants and instance methods, but cannot implement default behavior and all methods are implicitly abstract. An interface has all public members and no implementation. An abstract class is a class which may have the usual flavors of class members (private, protected, etc.), but has some abstract methods.
37.              What is the purpose of garbage collection in Java, and when is it used?
The purpose of garbage collection is to identify and discard objects that are no longer needed by a program so that their resources can be reclaimed and reused. A Java object is subject to garbage collection when it becomes unreachable to the program in which it is used.
38.              Describe synchronization in respect to multithreading.
With respect to multithreading, synchronization is the capability to control the access of multiple threads to shared resources. Without synchonization, it is possible for one thread to modify a shared variable while another thread is in the process of using or updating same shared variable. This usually leads to significant errors.
39.              Explain different way of using thread?
The thread could be implemented by using runnable interface or by inheriting from the Thread class. The former is more advantageous, ’cause when you are going for multiple inheritance..the only interface can help.
40.              we instantiate an abstract class?
abstract class can never be instantiated. Its sole purpose is to be extended (subclassed).
41.              Do interfaces have member variables?
Interfaces may have member variables, but these are implicitly public, static, and final- in other words, interfaces can declare only constants, not instance variables that are available to all implementations and may be used as key references for method arguments for example.
42.              Can we instantiate an interface?
You can’t instantiate an interface directly, but you can instantiate a class that implements an interface.
43.              What is super?
super is a keyword which is used to access the method or member variables from the superclass. If a method hides one of the member variables in its superclass, the method can refer to the hidden variable through the use of the super keyword. In the same way, if a method overrides one of the methods in its superclass, the method can invoke the overridden method through the use of the super keyword.
44.              What is method overriding?
Method overriding occurs when sub class declares a method that has the same type arguments as a method declared by one of its superclass. The key benefit of overriding is the ability to define behavior that’s specific to a particular subclass type.
45.              What is Dynamic Binding?
Binding refers to the linking of a procedure call to the code to be executed in response to the call. Dynamic binding (also known as late binding) means that the code associated with a given procedure call is not known until the time of the call at run-time. It is associated with polymorphism and inheritance.
46.              How does Java implement polymorphism?
(Inheritance, Overloading and Overriding are used to achieve Polymorphism in java).
Polymorphism manifests itself in Java in the form of multiple methods having the same name.
In some cases, multiple methods have the same name, but different formal argument lists (overloaded methods).
In other cases, multiple methods have the same name, same return type, and same formal argument list (overridden methods).
47.              What is final?
A final class can’t be extended ie., final class may not be subclassed. A final method can’t be overridden when its class is inherited. You can’t change value of a final variable (is a constant).
48.              What is an Iterator?
Some of the collection classes provide traversal of their contents via a java.util.Iterator interface. This interface allows you to walk through a collection of objects, operating on each object in turn. Remember when using Iterators that they contain a snapshot of the collection at the time the Iterator was obtained; generally it is not advisable to modify the collection itself while traversing an Iterator.
49.              What is HashMap and Map?
Map is Interface and Hashmap is class that implements that.
50.              Describe synchronization in respect to multithreading.
With respect to multithreading, synchronization is the capability to control the access of multiple threads to shared resources. Without synchonization, it is possible for one thread to modify a shared variable while another thread is in the process of using or updating same shared variable. This usually leads to significant errors.

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s