Core Java
Core Java
**Answer:** Java is a high-level, object-oriented programming language designed for portability and
ease of use. It runs on the Java Virtual Machine (JVM), which allows Java applications to run on any
device that has the JVM installed.
- **Encapsulation:** Bundling data (attributes) and methods (functions) that operate on the data within
a single unit (class).
- **Inheritance:** Mechanism where a new class inherits properties and behavior from an existing class.
- **Polymorphism:** Ability to perform the same action in different ways, primarily through method
overloading and overriding.
- **Abstraction:** Hiding complex implementation details and exposing only the essential features of an
object.
**Answer:**
- **JDK (Java Development Kit):** A software development kit that includes JRE, compilers, and tools
needed for Java development.
- **JRE (Java Runtime Environment):** Provides the libraries, Java Virtual Machine (JVM), and other
components to run Java applications.
- **JVM (Java Virtual Machine):** An abstract computing machine that enables a computer to run Java
programs by converting Java bytecode into machine code.
**Answer:**
- **Platform Independence:** Java code can run on any platform with a JVM.
- **Object-Oriented:** Promotes code reusability and modularity.
- **Multithreading:** Supports concurrent execution of two or more threads for efficient CPU usage.
- **Robustness:** Strong memory management, exception handling, and type checking contribute to
reliability.
**Answer:** The `==` operator checks for reference equality (whether two references point to the same
object), while the `equals()` method checks for value equality (whether two objects are logically
equivalent).
**Answer:** A constructor is a special method that is called when an object is instantiated. It has the
same name as the class and does not have a return type. Constructors can be overloaded.
**Answer:**
- **Interface:** A reference type in Java that can contain only constants, method signatures, default
methods, static methods, and nested types. A class implements an interface to provide the functionality.
- **Abstract Class:** A class that cannot be instantiated and can contain both abstract methods
(without body) and concrete methods (with body). It serves as a base for subclasses.
**Answer:** Exception handling in Java is a mechanism to handle runtime errors, ensuring the normal
flow of the application. It involves the use of `try`, `catch`, `finally`, `throw`, and `throws` keywords to
manage exceptions gracefully.
- **Checked Exceptions:** Must be declared in a method’s `throws` clause or caught. Examples include
`IOException` and `SQLException`.
**Answer:** The Java Collections Framework provides a set of classes and interfaces for storing and
manipulating groups of objects. It includes interfaces like `List`, `Set`, and `Map`, and their
implementations such as `ArrayList`, `HashSet`, and `HashMap`.