Location via proxy:   [ UP ]  
[Report a bug]   [Manage cookies]                
0% found this document useful (0 votes)
2 views

Core Java

Interview questions and answers for Core java

Uploaded by

streamer.0129
Copyright
© © All Rights Reserved
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
2 views

Core Java

Interview questions and answers for Core java

Uploaded by

streamer.0129
Copyright
© © All Rights Reserved
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
You are on page 1/ 3

Here are some common interview questions and answers for Core Java:

### 1. What is 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.

### 2. Explain the concept of OOP in Java.

**Answer:** Object-Oriented Programming (OOP) in Java is based on four main principles:

- **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.

### 3. What is the difference between JDK, JRE, and JVM?

**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.

### 4. What are the main features of Java?

**Answer:**

- **Platform Independence:** Java code can run on any platform with a JVM.
- **Object-Oriented:** Promotes code reusability and modularity.

- **Automatic Memory Management:** Garbage collection automatically manages memory allocation


and deallocation.

- **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.

### 5. What is the difference between `==` and `equals()` in Java?

**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).

### 6. What is a constructor in Java?

**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.

### 7. What are interfaces and abstract classes in Java?

**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.

### 8. What is exception handling in Java?

**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.

### 9. What are the different types of exceptions in Java?


**Answer:**

- **Checked Exceptions:** Must be declared in a method’s `throws` clause or caught. Examples include
`IOException` and `SQLException`.

- **Unchecked Exceptions:** Do not need to be declared or caught. Examples include


`NullPointerException` and `ArrayIndexOutOfBoundsException`.

### 10. Explain the Java Collections Framework.

**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`.

Feel free to ask for more specific topics or questions!

You might also like