Sunday, August 17, 2008

Java Interview Questions

Based on my exposure and experience with the language, I have listed some important Java(Core) questions that I think can be asked in any interview related to Java. I'm not listing the answers with them over here, but that does not mean that I do not know them :))
The only reason for not writing answers here, is that it would unnecessarily increase the length of the entry, but if you have doubts in any question, you can ask me in the comments section or can mail me.


Ques. 1 What makes Java Portable?
(The answer can spark discussion of things like Bytecode, VM so be clear with your concepts)

Ques. 2 List some features of Java that are not present in C++
(List 5-6 main features that makes the language more powerful)

Ques. 3 Is Java Slow as compared to C/C++?
(Google over it if you do not know or ask me)

Ques. 4 Differentiate between JDK. JRE and JVM.
(Ok, read this link and you are through) :-)

Ques. 5 How are interfaces different from Abstract Classes.
(Pretty simple one)

Ques. 6 List major OOPS principles and tell how each can be implemented using Java.
(simple & still Frequently asked)

Ques. 7 Parameter passing in Java.
(may be this can can be indirectly asked by giving a piece of code)

Ques. 8 How many classes can you have in 1 .java file?? How many of them can be public ? Why so ?
(if you do not know this, its high time you clear your basic concepts)

Ques. 9 Is Java a compiled language or interpreted language ??
(Ans: It is both compiled & interpreted. You need to explain in detail the conversion(compilation) of .java file into .class file(s) using javac and then execution(interpretation) of the .class file by the JVM)

Ques. 10 Talk about Garbage Collection in Java.
(very frequently asked)

Ques. 11 Can we force Garbage collector to run in Java ??
(ans is no, we can only give it a hint, not a command.... Google to know more)

Ques. 12 Is Java purely object-oriented ??
(perhaps this would help)

Ques. 13 Can we call C++ code in Java ??
(can be done using Java Native Interface (JNI), if you need to know more, Google is your best friend)

Ques. 14 Tell 3 uses of final keyword.
(typically textbook based question)

Ques. 15 Why an abstract class cannot be final ?
(don't tell me you don't know this :p)

Ques. 16 Which version of Java have you worked on ? What are the different versions of Java ? How they differ from each other ??
(Tough one if you don't know it. At least remember 2 or 3 main points of differences between Java 4, 5 & 6 such as with Java 5 new features such as Auto-boxing, variable arguments, co-variant returns (in overriding) but you also need to know what they mean. Explaining them here would require another blog post)

Ques. 17 Tell how many different types of variables are possible in Java.
(Tricky! Talk about Local Variables, Instance Variables & Class Variables)

Ques. 18 What are immutable objects? Give an example of immutable object in Java.
(Hint: Eg is String objects are you have to find it your way)

Ques. 19 What is Serialization ? How it can be implemented in Java.
(If you can answer this in an interview, they would seriously consider you as not many ppl can answer this so read about it & talk about the concept first and then talk abt Serializable interface)

Ques. 20 Discussion restrictions placed on method overloading & method overriding and compare the two.
(another textbook based.......but consult a good textbook :p)

Will keep on posting new questions that I feel every Java developer (rather every aspiring student) must know, whether he wants to clear his interview or not !!

Waiting for Comments :-)


Agraj said...

An interview is way more than a healthy discussion. Its like a game, where you could win only by getting your point across & convincing the interviewer that you are correct, even if you are not !!

Anonymous said...

First of all. Thanks very much for your useful post.

I just came across your blog and wanted to drop you a note telling you how impressed I was with the information you have posted here.

Please let me introduce you some info related to this post and I hope that it is useful for community.

Source: google interview questions

Thanks again

Indrayani said...

Hey Agraj, Very nice posts. It really helps to clear little and important concepts......Keep posting