Java Interview Question Basic to Advance
AWS Interview Question
C Language all Interview Question
Docker Interview Question Basic to Advance
Microservices Interview Questions

Topics (32)

  • 1. What is Java?
  • 2. Why was Java created?
  • 3. What problems does Java solve?
  • 4. Features of Java
  • 5. Why is Java platform independent? 
  • 6. What is Bytecode in Java?
  • 7. What is JVM?
  • 8. What is JRE?
  • 9. What is JDK?
  • 10. Difference between JVM, JRE, and JDK
  • 11. What is the JVM Architecture?
  • 12) What is a Classloader in Java?
  • 13) What is Just-In-Time (JIT) Compiler?
  • 14) What is WORA (Write Once, Run Anywhere)?
  • 15) What is a Class in Java?
  • 16. Object in Java
  • 17. Naming Convention in Java
  • 18. Package in Java
  • 19. Classpath in Java
  • 20. Identifiers in Java
  • 21. What are Primitive Data Types?
  • 22. Reference Data Types
  • 23. What is Type Casting?
  • 24. What is Automatic Type Conversion (Widening Conversion)?
  • 25. What is Narrowing Conversion?
  • 26. What is Autoboxing?
  • 27. What is Unboxing?
  • 28. What are Wrapper Classes?
  • 29. Difference between == and equals()
  • 30. Difference between equals() and hashCode()
  • 30. Difference between equals() and hashCode()
  • 31. What is the Purpose of the final Keyword?

Java Interview Question Basic to Advance Interview Questions with Answers - 32 Questions

Comprehensive list of real Java Interview Question Basic to Advance interview questions asked in campus placements and technical interviews. These questions are curated from previous company rounds and will help you understand important concepts and improve your problem-solving skills.

1. What is Java?

Java is a high-level, object-oriented programming language used to develop various types of applications such as:

  • Mobile applications

  • Web applications

  • Desktop applications

  • Games

  • Enterprise-level systems

Java is known for being simple, secure, platform-independent, robust, and reliable.
It follows the principle of "Write Once, Run Anywhere (WORA)", meaning code written in Java can run on any system that has the Java Virtual Machine (JVM).

2. Why was Java created?

Java was created to solve several problems in software development:

  1. To create a platform-independent language (run on any computer).

  2. To make programs more secure.

  3. To support network and internet-based applications.

  4. To reduce memory management issues through automatic garbage collection.

  5. To provide a simple, clean, and object-oriented programming style.

Its main idea was:

“Write Once, Run Anywhere (WORA)”

This means that Java programs can run on any system that has the Java Virtual Machine (JVM) installed.

3. What problems does Java solve?

Java solves many programming problems:
1. Platform dependency
Before Java, programmers had to write separate programs for Windows, Mac, and Linux.
Java solved this by introducing bytecode, which runs everywhere.
2. Security issues
Older languages had unsafe features.
Java is very secure and protects against viruses and harmful programs.
3. Memory management
Java manages memory automatically using Garbage Collection.
4. Complexity
Java is simpler than C/C++, which reduces errors.
5. Network programming
Java has built-in libraries for networking, making internet apps easy to build.

4. Features of Java

  • Simple
    Java is easy to learn and understand. It removes complex features like pointers and operator overloading found in C++.

  • Object-Oriented
    Java follows object-oriented principles such as encapsulation, inheritance, polymorphism, and abstraction.

  • Platform Independent
    Java programs are compiled into bytecode, which runs on the Java Virtual Machine (JVM), allowing them to run on any operating system.

  • Secure
    Java provides strong security through features like bytecode verification, no pointer access, and a secure runtime environment.

  • Robust
    Java is reliable and stable due to strong memory management, exception handling, and garbage collection.

  • Portable
    Java code can be easily transferred from one system to another without modification.

  • High Performance
    Java uses a Just-In-Time (JIT) compiler, which converts bytecode into native machine code for faster execution.

  • Multithreaded
    Java supports multithreading, allowing multiple tasks to run simultaneously.

  • Distributed
    Java provides built-in networking libraries to develop distributed and network-based applications.

5. Why is Java platform independent? 

Java is called platform independent because its programs can run on any operating system without modification.

How it works:

  1. Compilation to Bytecode
    • Java source code (.java) is compiled into bytecode (.class)
    • This is done by the Java Compiler
  2. Platform-Neutral Bytecode
    • Bytecode is not specific to any OS or hardware
    • It acts as an intermediate code
  3. Execution by JVM
    • JVM (Java Virtual Machine) converts bytecode into machine code
    • JVM is available for different platforms

Result:

Same Java program can run on:

  • Windows
  • macOS
  • Linux
  • Android
  • Any system with JVM

6. What is Bytecode in Java?

Bytecode is a special intermediate code created after compiling Java source code.
● Java source file (.java) → Compiled to Bytecode (.class)
● Bytecode is not machine code
● It is universal and can be executed on any system with a JVM
Bytecode makes Java platform independent.

7. What is JVM?

JVM = Java Virtual Machine
JVM does three things:
1. Loads the bytecode
2. Verifies it (for security)
3. Executes it
Every operating system has its own version of JVM, but all JVMs run the same bytecode.
JVM = The machine that runs Java programs

8. What is JRE?

JRE = Java Runtime Environment
JRE contains:
● JVM
● Java libraries
● Other files needed to run Java programs
JRE is used only for running Java programs, not for writing them.

9. What is JDK?

JDK = Java Development Kit
JDK includes:
● JRE
● JVM
● Development tools
 a) javac compiler
 b) debugger
 c) documentation tools
JDK is used to write, compile, and run Java programs.

10. Difference between JVM, JRE, and JDK

Components & Purpose

Component Contains Purpose
JVM Only Virtual Machine Runs Java bytecode
JRE JVM + Libraries Runs Java programs
JDK JRE + Tools + Compiler Develops & runs Java programs

Easy Way to Remember :-

JVM → Runs Java bytecode

JRE → Provides environment to run Java programs

JDK → Full package to create, compile & run Java programs

Page 1 of 4