Frequently asked interview questions on Java

Ask a question
          

Java FAQs

Java frequently asked interview questions with answers

Interface vs. an abstract class

Latest answer: An abstract class may contain code in method bodies whereas code is not allowed in an interface..........
Read answer

Synchronized block vs. synchronized method

Latest answer: Synchronized block is better since it places locks for shorter periods than synchronized methods...........
Read answer

Explain how to force garbage collection

Latest answer: Garbage collection can't be forced, it can explicitly be called using System.gc(), but there is not guarantee that GC will be started immediately.............
Read answer

Difference between the methods sleep() and wait().

Latest answer: wait() is defined in the class Object and sleep() is defined in the class Thread............
Read answer

Constructors vs. regular methods.

Latest answer: Constructors have same name as the class and can not return a value............
Read answer

What is package in JAVA?

Latest answer: Java packages help in organizing multiple modules. It helps in resolving naming conflicts when different packages have classes with the same names.............
Read answer

== vs. method equals().

Latest answer: The method equals() is used to compare the values of the Strings..............
Read answer

Go top

What are Native methods?

Latest answer: Native methods are the methods implemented in other language like C. These methods can be used in Java classes using JNI API...............
Read answer

What is Bytecode?

Latest answer: The Java class file contains bytecode which is being interpreted by JVM. Bytecode is introduced in Java to provide Java as platform independent language.................
Read answer

this vs. super keyword.

Latest answer: "this" refers to current object instance.
"super" refers to the member of superclass of the current object instance..................
Read answer

What are JAR, WAR and EAR files?

Latest answer: JAR - Java Archive File is used to package classes and property files.................
Read answer

Explain the significance of Classpath environment variables.

Latest answer: It is the list of directories which is used by JVM to find a class....................
Read answer

What is a Garbage collector?

Latest answer: Garbage collector cleans up objects which are no longer used. It is the thread running as part of JVM process....................
Read answer

What is Interning?

Latest answer: Interning is the process of converting duplicated strings to shared ones. Interned Strings avoid duplicate strings..............
Read answer

Go top

String vs. StringBuffer class.

Latest answer: String class is immutable which means it can't be modified once declared.
StringBuffer is not immutable which means strings can be appended to the original string..............
Read answer

Significance of StringTokenizer class

Latest answer: This class is used to break the string into tokens............
Read answer

What are the ways to create a thread?

Latest answer: A thread can be created extending from the Thread class................
Read answer

Preemptive scheduling vs. time slicing.

Latest answer: Preemptive scheduling ensures the highest priority thread to execute until it enters the waiting or dead states......................
Read answer

What is a daemon threads?

Latest answer: Daemon threads run at a low priority. The GC is an example of such thread...................
Read answer

Arraylist vs. Vector

Latest answer: Arraylist's methods are not synchronized which means they are not thread safe. Vector's methods are synchronized which means they are thread safe..............
Read answer

What is a Throwable class?

Latest answer: It is the superclass of all errors and exceptions in Java.................
Read answer

Go top

Significance of Finalize method.

Latest answer: The Finalize method of an object is called when GC is about to clean up the object. We can keep clean up code in the finalize block...............
Read answer

Define Polymorphism.

Latest answer: It is the ability of a method to behave differently based on the kind of input..............
Read answer

What is an Object Serialization?

Latest answer: It is the process of writing the contents of an object to a file and vice versa.............
Read answer

Significance of "transient" keyword.

Latest answer: The transient keyword is used within the object's member that need not be serialized...............
Read answer

What are inner classes?

Latest answer: Class that is nested within a class is called as inner class. The inner class can access private members of the outer class................
Read answer

What are the types of JDBC driver?

Latest answer: Type 1 - JDBC - ODBC bridge.
Type 2 - Native API partly Java technology enabled driver.............
Read answer

What is a connection pooling?

Latest answer: It is the technique which allows a connection object to be shared by multiple clients, thus improve program performance................
Read answer

Go top

What is the difference between C++ and Java?

Latest answer: Java does not support typedefs, defines, or a preprocessor. The declaration of named constants is supported in Java through use of the final keyword................
Read answer

What is JAR file?

Latest answer: JAR is a Java Archived file which allows many files to be stored. All applets and classes can be stored in a JAR file thereby reducing the size...................
Read Answer

What is JNI?

Latest answer: Java Native Interface is a framework that allows the Java code running in the Java Virtual Machine to interact and communicate with other applications and libraries written in some other languages................
Read Answer

What is serialization?

Latest answer: Serialization is an operation in which an object’s internal state is converted into a stream of bytes. This stream is then written to the disk..................
Read Answer

How are Observer and Observable used?

Latest answer: The observer pattern in java is known for its use in design. Whenever an observable object changes its state, its corresponding observer classes are notified...................
Read Answer

What is the difference between a break statement and a continue statement?

Latest answer: A break statement when applied to a loop ends the statement. A continue statement ends the iteration of the current loop and returns the control to the loop statement....................
Read Answer

What are synchronized methods and synchronized statements?

Latest answer: Synchronization does not allow invocation of this Synchronized method for the same object until the first thread is done with the object. Synchronization allows having control over the data in the class...............
Read Answer

Go top

What is a monitor?

Latest answer: A monitor works as a lock on the data item. When a thread holds the monitor for some data item, other threads are locked out and cannot inspect or modify the data......................
Read Answer

Explain how do we allow one thread to wait while other to finish.

Latest answer: Using the join() method, one can allow one thread to wait while other to finish.............
Read Answer

Explain the purpose of yield method.

Latest answer: Yield method causes the currently executing thread object to temporarily pause and allow other threads to execute..................
Read Answer

What is the difference between yielding and sleeping?

Latest answer: Sleep holds the threads execution for the specified time. On the other hand, yield will cause the thread to rejoin the queue..............
Read Answer

What is a task's priority and how is it used in scheduling?

Latest answer: A scheduler uses the priorities of a task to determine its execution. Priorities can be high or low determined by the integer values that are assigned to the tasks................
Read Answer

Can we have parameterized constructors in Java?

Latest answer: Yes, we can have.
This is also called as constructor overloading...................
Read Answer

Go top

More java interview questions with answers

How are Observer and Observable used?
What is the difference between preemptive scheduling and time slicing?
What are primitive types in java?
What is ResultSetMetaData?
Explain how to create and use sockets in java.
What is the difference between static and non-static variables?
What is synchronization and why is it important? Describe synchronization in respect to multithreading.
What is a task's priority and how is it used in scheduling?
What is transient variable?
What is the difference between a Vector and an Array. Discuss the advantages and disadvantages of both?



Write your comment - Share Knowledge and Experience

Discussion Board
Comments

very very useful material.thanks a lot

Kiran 12-7-2012 01:42 AM

 

 
Interview questions
 
Home | Login | About us | Sitemap | Contact us