1. What is Java and its features?
Java is a high-level, object-oriented, platform-independent programming language developed by Sun Microsystems (now Oracle). It is widely used for desktop, web, and mobile applications.
Key Features:
- Object-Oriented: Supports classes, objects, inheritance, polymorphism, encapsulation, and abstraction.
- Platform-Independent: Write once, run anywhere (WORA) using JVM.
- Simple: Easy syntax, automatic memory management, no pointers.
- Secure: Provides secure execution environment (bytecode verification, no direct memory access).
- Multithreaded: Supports concurrent execution of threads.
- Robust: Exception handling and strong type checking.
- Portable: Can run on any machine with a JVM.
Summary: Java is a secure, platform-independent, object-oriented language suitable for various applications.
2. Difference between JDK, JRE, and JVM
| Component |
Definition |
Purpose |
| JVM (Java Virtual Machine) |
Virtual machine that executes Java bytecode. |
Runs Java programs. |
| JRE (Java Runtime Environment) |
Contains JVM + core libraries. |
Allows running Java programs. |
| JDK (Java Development Kit) |
Contains JRE + development tools like javac. |
Used for developing and running Java programs. |
Summary: JDK is for development, JRE is for running, and JVM executes bytecode.
3. Explain JVM memory areas (Heap, Stack, Method Area)
JVM divides memory into several areas for execution and object management:
- Heap:
- Stores objects and class instances.
- Managed by Garbage Collector (GC).
- Stack:
- Stores method call frames and local variables.
- Each thread has its own stack.
- Follows LIFO (Last In First Out).