Preparing For A Job Interview

Java Interview Questions And Answers

Top 7 Java Interview Questions And Answers


A job interview is one of the toughest mental and psychological battles that we have to fight to fulfill our career dreams and give shape to our goals. If you are a java programmer and are wondering how to prepare for a great interview, then let us offer you the top 7 java interview questions and answers that will help you achieve success in your java job interview.

Q1. How it is possible for Java classes to direct program messages to a system console, but the error messages always says to a file?

Answer: In a Java class system, there is a variable out, which represents a standard output, and there is a variable err, which represents the standard error device. By default, both of them point only at the system console. As a result, the standard output can also be re-directed as:

Stream st = new Stream(new FileOutputStream("output.txt")); System.setErr(st); System.setOut(st);

Q2. Explain the difference between an abstract class and an interface?

Answer: An abstract class contains code within method bodies, but an interface doesn't. In abstract classes, you will need to inherit the class from within it and multiple inheritances is not allowed in Java but multiple interfaces can be implemented in your class.

Q3. Why synchronized block is preferred over synchronized method?

Answer: Synchronized blocks are preferred because they can place locks for shorter durations than synchronized methods.

Q4. Differentiate between the methods wait () and sleep ()

Answer: Using the sleep code (1000), you can put the threads aside for one second while the wait code (1000), will lead to a wait of one second. You can stop a thread from waiting earlier but for that you need to use a notify () or notify All () call. Method wait () can be defined within the class Object while method sleep () can be defined within the class Thread.

Q5. Can you write a Java class, which can be used as an applet and as an application as well?

Answers: Yes I can. For that I have to add a main() method to the applet.

Q6: Define collection API?

Answer: Collection API is basically a set of interfaces and classes, which supports a particular operation on a collection of objects. These interfaces and classes are flexible, and powerful than the arrays, vectors, and hashtables. Some examples of interfaces are: Set, Collection, List and Map. Some examples of classes are: HashMap, HashSet, ArrayList, TreeSet, LinkedList, and TreeMap.

Q7. Is there any difference between J2SDK 5.0 and J2SDK 1.5?

Answer: There is no difference as they are the re-branded versions of Sun Microsystems.

These are the top 7 java interview questions and answers that are most commonly asked in any Java interview. The most important thing apart from the Java job interview questions is that you need to be confident. Your practical and theoretical knowledge of Java will help build confidence. Lastly, always remember to speak smart, dress well and be focused.