This is the first of a series of three articles I want to put together around some Interview questions that could be used for interviewing Java developers. In this first article, we will look at easier, basic concepts that should be covered in any introduction to Java programming. So many of the questions will deal with concepts around defining and declaring classes
- What is the difference between an interface and an abstract class?
An interface is just a contract with no implementation. All methods in an interface are public and abstract. An abstract class can have some state and implementation. - What are the main differences between Java and C++?
Java is compiled to platform independent byte code that is interpreted in a virtual machine. C++ is compiled into native binaries that are not portable. Java gives automatic memory management. C++ memory management is handled by the programmer. - What is the difference between a while statement and a do statement?
A while statement may not execute, a do statement is guaranteed to execute at least once. - Explain the main() method in a java program?
What is passed to it and what is its return type? The main method is the starting point for a java application. The return type is void and the arguments to the java application are passed in an array of Strings to the main method. - What's the first thing that happens in a constructor?
The first call of every constructor must be a call to super() or this(), but never both in the same constructor. If you call this(), eventually super() must be called. - What access can classes have?
public or default. protected and private are also only allowed on methods and instance variables. - What modifiers can classes have? abstract, final or strictfp
- What types are allowed to be in a case statement?
byte, char, short, int and enum. In java 7 we can also switch on String - Interfaces allow inheritance so can an interface have protected methods?
No, an interface can only have public abstract methods. Update for Java 8, interfaces can now have default method implementations. - Java concept of the day 25 basic questions
- Java concept of the day