Ever been stumped by a fairly innocuous question during a job interview for a Java developer position? It happens to the best of us. The secret is to go over some of the most common questions ahead of time so that you are prepared with an answer to each of them. Keep in mind that interviewers tend to start with fairly broad topics and then drill down based on your answers. For that reason, this tutorial starts with the basics before moving onto more specialized areas.
What is Java?
Some developers list every popular language in their resume or CV, even if they have only seen it in passing or know just the basics. This first question is designed to quickly weed these people out.
You do not need to cover the entire history of Java in your answer; something like this should suffice:
“Java is a high-level, Object-oriented, programming language originally developed by Sun Microsystems and released in 1995. Java runs on a variety of platforms, such as Windows, Mac OS, and the various versions of UNIX. It’s currently maintained by the Oracle Corporation and is one of the most popular programming languages in the world.”
What is the Java Virtual Machine?
The question, “What is the Java Virtual Machine?” is a slightly more technical question, but one that goes to the heart of Java, because it is what makes the language platform-independent and supplies its garbage collection features.
For this question, your answer might go as follows:
“The Java Virtual Machine, or JVM, is a program that interprets the intermediate Java byte code and generates the machine code for that specific Operating System. It is because of bytecode and the JVM that programs written in Java are highly portable. The JVM is also responsible for garbage collection and resource allocation, as well as other performance optimizations.”
You can learn more about the JVM to further speak on the topic in our tutorial: What is the Java Virtual Machine?
What are Some of the Features of JAVA?
There are many features that set Java apart from other programming languages. As a professional Java developer, you will be expected to know at least a handful of them. Here are a few:
- OOPs Concepts: Java possesses all of the features that you would expect from an Object-oriented language, including abstraction, encapsulation, inheritance, object-oriented, and polymorphism.
- Platform independent: The same program should work on different platforms without any modification.
- High Performance: The Just In Time compiler (JIT) enables high performance in Java. JIT converts the bytecode into machine language and then JVM starts the execution.
- Multi-threaded: A flow of execution is known as a Thread. JVM creates a thread which is called the main thread. The user can create additional threads by extending the thread class or by implementing the Runnable interface.
You can learn more about OOP concepts in the following tutorial: What is Object-oriented programming in Java?
Which Java IDE Do You Use?
An IDE (or Integrated Development Environment) is a software application that increases developer productivity by combining capabilities such as software editing, building, testing, and packaging in an easy-to-use application.
Hopefully you have used at least one IDE prior to your interview. If not, take some time to get acquainted with the top two – Eclipse and IntelliJ IDEA – at the very least. NetBeans is another good choice.
You can learn more about popular Java IDEs in our roundup: The Top Java IDEs.
What is a Class in Java?
In an OOP language like Java, classes are the bedrock. They are so fundamental that you really can’t write even the most basic program without one. A class is a blueprint from which individual objects are created. A class can contain fields and methods to describe the state and behavior of an object.
You can learn more about classes and objects in our tutorial: Classes and Objects in Java
What is the difference between a class and an object?
This is a variation of the previous question that forces the interviewee to define both classes and objects.
A class is a template used for the creation of objects whereas an object is an instance of a class. While a class is a logical entity, an object is a physical entity. Each object has a state in which all the member variables have specific values.
How Do You Create an Object Instance?
Here, the interviewer is likely looking for information about the new keyword.
To create an object, specify the class name, followed by the object name, and use the new keyword as demonstrated in the following code example:
Classname myObject = new Classname()
What is Inheritance?
Inheritance is a very important concept in Java, so a knowledgeable developer would be quite familiar with it.
Inheritance means that one class can extend to another class. This allows the code of the parent class to be reused in the child class. The technical terms for the parent and child classes are super class and sub class.
You can learn more about inheritance in our tutorial: What is Inheritance in Java?
What is Encapsulation?
Java classes have several distinct features, including polymorphism, inheritance, encapsulation, and abstraction.
Encapsulation in Java refers to integrating variables and methods into a single unit. In encapsulation, a class’s variables are hidden from other classes and can only be accessed by the methods of the class in which they are found.
You can learn more in our tutorial: What is Encapsulation in Java?
What is Meant by the Term “Access Modifier”?
This question is related to the previous one in that, as part of encapsulation, classes may be granted access to another class and members to varying degrees.
In Java, access modifiers set the access levels for classes, variables, methods and constructors. There are four levels: public, protected, package, and private. A member has package or default accessibility when no accessibility modifier is specified.
Final Thoughts on Java Interview Questions
This tutorial presented a few of the most commonly asked interview questions pertaining to the position of Java Developer. While it is impossible to predict what an interviewer might ask, knowing the answer to these questions will certainly put you in a much stronger position.
Looking to learn more about Java? We have a list of some of the Top Online Courses to Learn Java to help you get started.