Java Interview Questions – Introduction
1. (Asked in Infosys) What is Java? Explain briefly.
Answer:
Java is an object-oriented, platform-independent programming language widely used for building web, mobile, desktop, and enterprise applications. It follows the “write once, run anywhere” (WORA) principle, meaning the compiled Java code can run on any platform supporting Java Virtual Machine (JVM).
2. (Asked in TCS) Why is Java called a platform-independent language?
Answer:
Java is platform-independent because its source code is compiled into bytecode, which can run on any system that has Java Virtual Machine (JVM) installed. JVM interprets bytecode and executes it, making Java programs portable across different operating systems.
3. (Asked in Accenture) What is JVM in Java, and what role does it play?
Answer:
JVM stands for Java Virtual Machine. It is responsible for executing Java bytecode on various devices. JVM converts bytecode into machine-readable code, manages memory, and handles garbage collection, thus ensuring platform independence.
4. (Asked in Cognizant) Explain JDK, JRE, and JVM briefly.
Answer:
- JVM (Java Virtual Machine): Executes Java bytecode.
- JRE (Java Runtime Environment): Includes JVM and libraries needed to run Java applications.
- JDK (Java Development Kit): Includes JRE and tools like compiler (
javac) and debugger required to develop Java applications.
5. (Asked in Amazon) What are the main features of Java?
Answer:
The key features of Java are:
- Object-Oriented
- Platform-Independent
- Secure
- Robust (Strong memory management and error handling)
- Multithreaded
- High Performance
- Automatic Garbage Collection
6. (Asked in Wipro) What do you understand by the term bytecode in Java?
Answer:
Bytecode is an intermediate code generated by the Java compiler after compiling the source code. It is a platform-independent set of instructions executed by JVM. This allows Java programs to run on any device or OS that supports JVM.
7. (Asked in IBM) What is the difference between a compiler and an interpreter in Java?
Answer:
- Compiler: Converts Java source code (.java file) into bytecode (.class file).
- Interpreter (JVM): Converts bytecode into machine-specific instructions at runtime and executes them.
8. (Asked in Google) Why is Java known as an Object-Oriented Programming (OOP) language?
Answer:
Java is known as an OOP language because it organizes code into objects and classes. It follows OOP concepts such as encapsulation, inheritance, polymorphism, and abstraction, making code reusable and maintainable.
9. (Asked in Capgemini) What is garbage collection in Java, and how does it help developers?
Answer:
Garbage collection is an automatic memory management feature of Java that frees up memory occupied by objects that are no longer in use. This helps developers by reducing memory leaks and allowing them to focus on application logic rather than manual memory management.
10. (Asked in Facebook) Explain the entry point method of Java applications.
Answer:
The entry point of every Java application is the main() method. JVM executes the code inside this method when the program starts.
Example:
public class Main {
public static void main(String[] args) {
System.out.println("Hello, Java!");
}
}
When you run this program, “Hello, Java!” will be displayed on the console.
