Frequently asked Interview Questions on Java

Interface vs. an abstract class - An abstract class may contain code in method bodies whereas code is not allowed in an interface......
Synchronized block vs. synchronized method - Synchronized block is better since it places locks for shorter periods than synchronized methods.....
Explain how to force garbage collection - Garbage collection can't be forced, it can explicitly be called using System.gc(), but there is not guarantee....
Difference between the methods sleep() and wait() - wait() is defined in the class Object and sleep() is defined in the class Thread...
Constructors vs. regular methods - Constructors have same name as the class and can not return a value...
What is package in JAVA? - Java packages help in organizing multiple modules. It helps in resolving naming conflicts when different.
== vs. method equals() - The method equals() is used to compare the values of the Strings.....
What are Native methods? - Native methods are the methods implemented in other language like C. These methods can be used in Java...
What is Bytecode? - The Java class file contains bytecode which is being interpreted by JVM. Bytecode is introduced in Java to...
this vs. super keyword - 'this' refers to current object instance....
What are JAR, WAR and EAR files? - JAR - Java Archive File is used to package classes and property files......
Significance of Classpath environment variables - It is the list of directories which is used by JVM to find a class.....
What is a Garbage collector? - Garbage collector cleans up objects which are no longer used. It is the thread running as part of JVM......
What is Interning? - Interning is the process of converting duplicated strings to shared ones. Interned Strings avoid duplicate......
String vs. StringBuffer class - String class is immutable which means it can't be modified once declared.....
Significance of StringTokenizer class - This class is used to break the string into tokens.....
What are the ways to create a thread? - A thread can be created extending from the Thread class......
Preemptive scheduling vs. time slicing - Preemptive scheduling ensures the highest priority thread to execute until it enters the waiting or dead states..
What is a daemon threads? - Daemon threads run at a low priority. The GC is an example of such thread....
Arraylist vs. Vector - Arraylist's methods are not synchronized which means they are not thread safe. Vector's methods are....
What is a Throwable class? - It is the superclass of all errors and exceptions in Java....
Significance of Finalize method - The Finalize method of an object is called when GC is about to clean up the object. We can keep clean up....
Significance of Finalize method - The Finalize method of an object is called when GC is about to clean up the object. We can keep clean up......
What is an Object Serialization? - It is the process of writing the contents of an object to a file and vice versa.....
Significance of transient keyword - The transient keyword is used within the object's member that need not be serialized...
What are inner classes? - Class that is nested within a class is called as inner class. The inner class can access private members...
What are the types of JDBC driver? - Type 1 - JDBC - ODBC bridge...
What is a connection pooling? - It is the technique which allows a connection object to be shared by multiple clients, thus improve program....
What is the difference between C++ & Java? - Java does not support typedefs, defines, or a preprocessor. The declaration of named constants is...
What is JAR file? - JAR is a Java Archived file which allows many files to be stored. All applets and classes can be stored...
What is JNI? - Java Native Interface is a framework that allows the Java code running in the Java Virtual Machine to interact..
What is serialization? - Serialization is an operation in which an object’s internal state is converted into a stream of bytes.........
How are Observer and Observable used? - The observer pattern in java is known for its use in design. Whenever an observable object changes its state.......
Difference between a break statement and a continue statement - A break statement when applied to a loop ends the statement. A continue statement ends the iteration of the.......
What are synchronized methods and synchronized statements? - Synchronization does not allow invocation of this Synchronized method for the same object until the first...
What is a monitor? - A monitor works as a lock on the data item. When a thread holds the monitor for some data item, other....
How do we allow one thread to wait while other to finish - Using the join() method, one can allow one thread to wait while other to finish....
Explain the purpose of yield method - Yield method causes the currently executing thread object to temporarily pause and allow other threads to execute....
What is the difference between yielding and sleeping? - Sleep holds the threads execution for the specified time. On the other hand, yield will cause the thread to rejoin the queue....
What is a task's priority and how is it used in scheduling? - A scheduler uses the priorities of a task to determine its execution. Priorities can be high or low determined.....
Can we have parameterized constructors in Java? - Yes, we can have. This is also called as constructor overloading.....