0% found this document useful (0 votes)
4 views

All Interview Imp

Uploaded by

chauhan844566
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
4 views

All Interview Imp

Uploaded by

chauhan844566
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
You are on page 1/ 4

### JVM Configuration

1. **Finalize Method**:
- The `finalize()` method in Java is called by the Garbage Collector (GC) on an object before the
object is garbage collected. It allows cleanup before memory is reclaimed.

2. **Invoke GC**:
- You can suggest the JVM to run the garbage collector using `System.gc()` or
`Runtime.getRuntime().gc()`, though it's not guaranteed to run immediately.

3. **Types of GC**:
- **Serial GC**: A single-threaded GC suitable for small applications.
- **Parallel GC**: Uses multiple threads for GC, useful for multi-core systems.
- **CMS (Concurrent Mark-Sweep) GC**: Targets low-pause applications by performing GC
concurrently with the application.
- **G1 (Garbage First) GC**: Designed for multi-core machines with large memory, focuses on low-
pause and high-throughput.

4. **PermGen and MetaSpace**:


- **PermGen**: Permanent Generation, an area in the heap memory used to store class metadata.
Removed in Java 8.
- **MetaSpace**: Replaces PermGen in Java 8, stores class metadata, and grows dynamically, unlike
PermGen.

5. **G1 GC**:
- Garbage First (G1) GC divides the heap into regions and prioritizes reclaiming the most garbage-
filled regions first, balancing pause times and throughput.

### Database

1. **All Types of Join**:


- **Inner Join**: Returns records that have matching values in both tables.
- **Left Join**: Returns all records from the left table and matched records from the right table.
- **Right Join**: Returns all records from the right table and matched records from the left table.
- **Full Join**: Returns all records when there is a match in either left or right table.
- **Cross Join**: Returns the Cartesian product of both tables.
- **Self Join**: Joins a table to itself.

2. **Clustered**:
- **Clustered Index**: A type of index where the table records are physically ordered based on the
indexed column(s).

3. **Indexing and Types of Indexing**:


- **Indexing**: A database optimization technique to speed up the retrieval of rows.
- **Types**:
- **Clustered Index**: Orders the physical data in the table.
- **Non-Clustered Index**: Creates a separate object within the table that points back to the
original table rows.

4. **Data Modeling**:
- **Data Modeling**: The process of creating a data model for the data to be stored in a database.
It includes conceptual, logical, and physical models.

5. **Data Sharding**:
- **Data Sharding**: The practice of splitting a large database into smaller, faster, more easily
managed parts called shards.
6. **Query for Second Highest Salary Employee**:
```sql
SELECT MAX(salary)
FROM employees
WHERE salary < (SELECT MAX(salary) FROM employees);
```

7. **Query Using GROUP BY and HAVING**:


```sql
SELECT department, COUNT(*)
FROM employees
GROUP BY department
HAVING COUNT(*) > 5;
```

### MultiThreading

1. **Runnable vs Callable**:
- **Runnable**: Doesn't return a result or throw a checked exception.
- **Callable**: Can return a result and throw a checked exception.

2. **Executor Service**:
- **Executor Service**: A higher-level replacement for working with threads directly. It provides
methods to manage the lifecycle of threads.

3. **Different Types of Thread Pool**:


- **Fixed Thread Pool**: A thread pool with a fixed number of threads.
- **Cached Thread Pool**: Creates new threads as needed, reusing previously constructed threads
when they are available.

4. **Difference between Fixed and Cached Thread Pool**:


- **Fixed**: Limited number of threads, useful for consistent load.
- **Cached**: Expands and contracts dynamically, useful for handling many short-lived tasks.

5. **What is Blocking Queue**:


- A thread-safe queue that supports operations that wait for the queue to become non-empty when
retrieving an element and for space to become available when storing an element.

6. **Reentrant Lock**:
- A lock that allows the thread holding the lock to reacquire it without getting blocked.

7. **Thread Local**:
- Provides thread-local variables, ensuring that each thread has its own independent instance of the
variable.

8. **Atomic Variable**:
- Variables that are updated atomically, ensuring thread-safe operations on single variables without
locking.

9. **Fork and Join Pool**:


- A framework for parallel execution in Java, breaking tasks into smaller subtasks recursively and
merging the results.

### Collection

1. **LinkedList and ArrayList Difference**:


- **ArrayList**: Resizable array, faster access by index.
- **LinkedList**: Doubly-linked list, faster insertion and deletion at both ends.

2. **HashMap, Hashtable, and ConcurrentHashMap Difference**:


- **HashMap**: Not synchronized, allows one null key.
- **Hashtable**: Synchronized, does not allow null keys/values.
- **ConcurrentHashMap**: Thread-safe, better performance than Hashtable.

3. **Contract between equals and hashCode**:


- If two objects are equal according to `equals()`, they must have the same `hashCode`.

4. **Internal Working of HashMap and ConcurrentHashMap**:


- **HashMap**: Uses an array and linked list or binary tree (since Java 8) for storing entries.
- **ConcurrentHashMap**: Divides the map into segments, locking only the relevant segment
during updates.

5. **Fail-Fast vs Fail-Safe Difference**:


- **Fail-Fast**: Iterators throw `ConcurrentModificationException` if the structure is modified.
- **Fail-Safe**: Operate on a cloned copy, so no exception is thrown.

6. **Time Complexity of All Operations of All Collections**:


- **ArrayList**: O(1) for get, O(n) for add/remove.
- **LinkedList**: O(n) for get, O(1) for add/remove at ends.
- **HashMap**: O(1) for put/get, O(n) in worst-case scenarios (high collisions).

7. **CopyOnWriteArrayList**:
- A thread-safe variant of `ArrayList` where all mutative operations create a new copy of the
underlying array.

### Language Fundamentals

1. **Explanation and Implementation of SOLID Principle**:


- **SOLID**: A set of design principles to create more understandable, flexible, and maintainable
software.
- **S**: Single Responsibility Principle (SRP)
- **O**: Open/Closed Principle (OCP)
- **L**: Liskov Substitution Principle (LSP)
- **I**: Interface Segregation Principle (ISP)
- **D**: Dependency Inversion Principle (DIP)

2. **Create a Custom Immutable Class**:


```java
public final class ImmutableClass {
private final int value;
public ImmutableClass(int value) {
this.value = value;
}
public int getValue() {
return value;
}
}
```

3. **Serialization, Deserialization, and Externalization**:


- **Serialization**: Converting an object into a byte stream.
- **Deserialization**: Converting a byte stream back into an object.
- **Externalization**: Customizing the serialization process, giving more control over the
serialization process.
4. **Use of serialVersionUID**:
- Used to ensure that a deserialized object is compatible with the class definition by verifying that
the sender and receiver of a serialized object have loaded classes for that object that are compatible.

5. **Comparable vs Comparator**:
- **Comparable**: Used to define the natural ordering of objects (e.g., `compareTo()`).
- **Comparator**: Used for custom sorting, allows sorting by multiple criteria.

6. **Generics and Wildcard in Generics**:


- **Generics**: Enable types (classes and interfaces) to be parameters when defining classes,
interfaces, and methods.
- **Wildcard**: Represents an unknown type (`?`), allows for more flexible generic type usage.

7. **Object Cloning and Types of Cloning**:


- **Object Cloning**: Creating an exact copy of an object.
- **Shallow Cloning**: Copies the object and its references.
- **Deep Cloning**: Copies the object and all objects referenced by the object.

8. **Checked Exception, Unchecked Exception, and Runtime Exception with Difference**:


- **Checked Exception**: Must be handled or declared (e.g., `IOException`).
- **Unchecked Exception**: Does not need to be declared or handled (e.g., `NullPointerException`).
- **Runtime Exception**: Subclass of `UncheckedException`, indicates programming errors.

9. **OOPS Concept (Polymorphism, Overriding, and Overloading Program Questions)**:


- **Polymorphism**: The ability to process objects differently based on their data type or class.
- **Overriding**: Providing a specific implementation in a subclass that already exists in the parent
class.
- **Overloading**: Multiple methods with the same name

but different parameters.

### Any Library (Json, XML, etc.)

- **JSON Library**: Used for parsing and generating JSON data in Java. Popular libraries include
Jackson and Gson.
- **XML Library**: Used for processing XML documents in Java. Examples include JAXB and DOM4J.

You might also like