i
10405090xyzabc
Work with us
Filter interviews by
Immutability in Java ensures objects cannot be changed after creation, enhancing thread safety and reducing side effects.
Immutable objects cannot be modified after creation, e.g., String class in Java.
Thread-safe: Since they cannot change, they prevent issues in multi-threaded environments.
Prevent unintended side effects, making code easier to understand and maintain.
To create an immutable class, use final fields ...
Java Streams enable parallel processing using ForkJoin framework, but have pitfalls like race conditions and performance issues with small datasets.
Use parallelStream() for parallel processing: Example: list.parallelStream().map(...).collect(Collectors.toList());
Avoid shared mutable state to prevent race conditions: Use immutable objects or thread-safe collections.
Consider the size of the dataset: Parallel streams...
Java Streams enable parallel processing via ForkJoin, enhancing performance but posing risks like race conditions and debugging challenges.
Use parallel streams for CPU-intensive tasks to leverage multiple cores effectively.
Avoid using parallel streams for small datasets, as overhead may outweigh benefits.
Minimize shared mutable state to prevent race conditions; prefer immutable data structures.
Use operations like ...
Immutability in Java ensures objects cannot be modified after creation, enhancing thread safety and consistency.
Immutable objects cannot be changed after creation, e.g., String class.
Thread-safe by nature, as they prevent concurrent modifications.
Prevent unintended side effects in multi-threaded applications.
To create an immutable class, use final fields and avoid setters.
Collections can be made immutable using Co...
Java Streams enable parallel processing using ForkJoin framework, but have pitfalls like race conditions and performance issues with small datasets.
Use parallel streams for CPU-intensive tasks to leverage multiple cores.
Avoid using parallel streams for small datasets as overhead may outweigh benefits.
Minimize shared mutable state to prevent race conditions; prefer immutable objects.
Use forEachOrdered() for order-s...
Java's synchronized keyword offers simplicity for thread safety but can lead to performance issues and deadlocks.
Synchronized is easy to use and requires less code, making it suitable for simple scenarios.
It automatically releases the lock when the thread exits the synchronized block, reducing the risk of forgetting to unlock.
Performance can degrade due to thread contention, leading to blocking and context switchi...
Immutability in Java ensures objects cannot be modified after creation, enhancing thread safety and consistency.
Immutable objects cannot be changed after creation, e.g., String class.
Thread-safe by nature, as they prevent concurrent modifications.
Prevent unintended side effects in multi-threaded applications.
To create an immutable class, use final fields and avoid setters.
Collections can be made immutable using Co...
The Java Memory Model defines thread interactions with memory, ensuring visibility and ordering in multithreaded environments.
JMM specifies how threads see shared variables and ensures visibility of updates.
Volatile keyword ensures that changes to a variable are visible to all threads immediately.
Synchronized blocks provide mutual exclusion, preventing multiple threads from executing critical sections simultaneous...
Functional interfaces in Java enable lambda expressions for concise implementation of single abstract methods.
A functional interface has exactly one abstract method, e.g., Runnable, Callable.
Lambda expressions provide a shorthand way to implement functional interfaces, e.g., () -> System.out.println("Hello World").
Functional interfaces can include multiple default or static methods, allowing for added functiona...
Java annotations provide metadata for classes and methods, enhancing code readability and reducing boilerplate in frameworks like Spring.
Annotations like @Component and @Service simplify Spring's dependency injection.
Built-in annotations such as @Override clarify method behavior and intent.
Custom annotations can be created using @interface to encapsulate specific behaviors.
Annotations reduce the need for XML confi...
I appeared for an interview in Jun 2025, where I was asked the following questions.
ArrayList offers fast access and is memory efficient, while LinkedList excels in insertions and deletions but has higher memory overhead.
ArrayList provides O(1) access time, ideal for frequent retrievals.
LinkedList allows O(1) insertions/deletions at both ends, suitable for dynamic data.
Example: Use ArrayList for a list of user names where frequent access is needed.
Example: Use LinkedList for a playlist where songs are...
Java's synchronized keyword offers simplicity for thread safety but can lead to performance issues and deadlocks.
Synchronized is easy to use and requires less code, making it suitable for simple scenarios.
It automatically releases the lock when the thread exits the synchronized block, reducing the risk of forgetting to unlock.
Performance can degrade due to thread contention, leading to blocking and context switching.
De...
== checks reference equality; .equals() checks value equality. Override equals() for custom comparison in user-defined classes.
== compares memory addresses, while .equals() compares actual content.
Example: new String("hello") == new String("hello") returns false.
"hello".equals("hello") returns true, showing value equality.
Wrapper classes like Integer cache values from -128 to 127, affecting == behavior.
Override equals(...
Java's garbage collector reclaims memory from unused objects, optimizing performance and managing memory regions.
Garbage collection in Java is automatic, freeing developers from manual memory management.
The heap is divided into Young Generation (short-lived objects) and Old Generation (long-lived objects).
Minor GC occurs in the Young Generation, quickly reclaiming memory from short-lived objects.
Major GC (Full GC) clea...
Lambda expressions enhance Java code by making it more concise, readable, and easier to maintain through functional programming.
Conciseness: Lambda expressions reduce boilerplate code. Example: Instead of writing an anonymous class for Runnable, use () -> System.out.println("Hello").
Readability: They express behavior more clearly. Example: list.forEach(item -> System.out.println(item)) is clearer than using an it...
Checked exceptions require handling; unchecked exceptions do not. Custom exceptions can be either, based on use case.
Checked exceptions must be caught or declared (e.g., IOException, SQLException).
Unchecked exceptions do not require explicit handling (e.g., NullPointerException, ArithmeticException).
Use checked exceptions for recoverable conditions and unchecked for programming errors.
Custom exceptions can be created f...
The Java Memory Model defines thread interactions with memory, ensuring visibility and ordering in multithreaded environments.
JMM specifies how threads read and write shared variables.
Volatile keyword ensures visibility of changes across threads.
Synchronized blocks provide mutual exclusion and visibility guarantees.
Without synchronization, threads may see stale or inconsistent data.
Compiler and CPU optimizations can re...
Method overloading allows multiple methods with the same name in a class, while overriding allows subclass methods to redefine parent methods.
Method Overloading: Same method name, different parameters (e.g., `int add(int a, int b)` and `double add(double a, double b)`)
Method Overriding: Subclass provides a specific implementation of a method defined in its superclass (e.g., `void display() { System.out.println('Subclas...
Functional interfaces in Java enable lambda expressions for concise implementation of single abstract methods.
A functional interface has exactly one abstract method, e.g., Runnable, Callable.
Lambda expressions provide a shorthand way to implement functional interfaces, e.g., () -> System.out.println("Hello").
Functional interfaces can have multiple default or static methods, allowing for added functionality without b...
Java Streams enable functional operations on collections, differing from Iterators in performance and usage.
Parallel streams can improve performance by utilizing multiple CPU cores, e.g., processing a large list of numbers concurrently.
They are best suited for CPU-intensive tasks, like complex calculations or data transformations.
However, they can introduce overhead due to thread management, which may negate performanc...
Immutability in Java ensures objects cannot be modified after creation, enhancing thread safety and consistency.
Immutable objects cannot be changed after creation, e.g., String class.
Thread-safe: Multiple threads can access immutable objects without synchronization issues.
Prevents unintended side effects in multi-threaded applications.
To create an immutable class, use final fields and avoid setters.
Collections can be m...
final, finally, and finalize serve different purposes in Java: constants, cleanup, and garbage collection respectively.
final: Used to declare constants. Example: final int MAX_VALUE = 100;
finally: Block that executes after try-catch. Example: try { ... } catch { ... } finally { cleanup(); }
finalize(): Method called by the garbage collector. Example: protected void finalize() { ... }
final variable cannot be reassigned a...
Singleton pattern restricts class instantiation to one object, useful for shared resources management.
Private constructor prevents instantiation from outside the class.
Static instance variable holds the single instance of the class.
Lazy initialization creates the instance only when needed.
Eager initialization creates the instance at class loading time.
Thread safety can be achieved using synchronized methods or blocks.
D...
Java annotations provide metadata for classes and methods, enhancing code readability and reducing boilerplate in frameworks like Spring.
Annotations like @Component and @Service simplify bean management in Spring.
Dependency injection is streamlined with @Autowired, reducing manual wiring.
Built-in annotations like @Override improve code clarity by indicating overridden methods.
Custom annotations can encapsulate specific...
Java Streams enable parallel processing using ForkJoin framework, but have pitfalls like race conditions and performance issues with small datasets.
Use parallelStream() for parallel processing: List<String> parallelList = myList.parallelStream().filter(...).collect(Collectors.toList());
Avoid shared mutable state to prevent race conditions: Use immutable objects or thread-safe collections.
Consider the size of the ...
I appeared for an interview in Jun 2025, where I was asked the following questions.
ArrayList offers fast access and is memory efficient, while LinkedList excels in insertions and deletions.
ArrayList allows O(1) access time, ideal for frequent retrievals (e.g., accessing elements by index).
LinkedList provides O(1) insertion/deletion at both ends, suitable for queue implementations.
ArrayList has lower memory overhead compared to LinkedList, which uses extra memory for pointers.
In scenarios with frequen...
Java's synchronized keyword offers simplicity for thread safety but can lead to performance issues and deadlocks.
Synchronized is easy to use and requires less code, making it suitable for simple scenarios.
It automatically releases the lock when the thread exits the synchronized block, reducing the risk of forgetting to unlock.
Performance can degrade with high contention, as threads may block each other, leading to incr...
== checks reference equality; .equals() checks value equality, can be overridden for custom comparison.
== compares memory addresses, while .equals() compares actual content.
Example: new String('hello') == new String('hello') returns false.
'hello'.equals('hello') returns true, as it compares values.
For wrapper classes like Integer, caching affects == behavior for small values (-128 to 127).
Override equals() when logical...
Java's garbage collector automatically manages memory, reclaiming space from unused objects through various algorithms.
Garbage collection in Java is automatic, freeing developers from manual memory management.
The JVM uses different GC algorithms: Serial, Parallel, CMS, and G1, each with unique characteristics.
Memory is divided into Young Generation (short-lived objects) and Old Generation (long-lived objects).
Minor GC ...
Lambda expressions enhance Java code by making it more concise, readable, and easier to maintain through functional programming.
Conciseness: Lambda expressions reduce boilerplate code. Example: Instead of writing an anonymous class for Runnable, use () -> System.out.println("Hello").
Readability: Code becomes more expressive. Example: Using lambdas with Collections: list.forEach(item -> System.out.println(item)).
M...
Checked exceptions require handling; unchecked exceptions do not. Custom exceptions can be either based on use case.
Checked exceptions must be caught or declared (e.g., IOException, SQLException).
Unchecked exceptions do not require explicit handling (e.g., NullPointerException, ArithmeticException).
Checked exceptions enforce robust error handling but can clutter code.
Unchecked exceptions indicate programming errors tha...
The Java Memory Model defines thread interactions with memory, ensuring visibility and ordering in multithreaded environments.
JMM specifies how threads see shared variables and their updates.
Volatile keyword ensures visibility of changes across threads.
Synchronized blocks provide mutual exclusion and visibility guarantees.
Without synchronization, threads may read stale or inconsistent data.
Compiler and CPU optimization...
Method overloading allows same method name with different parameters; overriding changes parent method behavior in subclasses.
Method Overloading: Same method name, different parameters (e.g., `int add(int a, int b)` and `double add(double a, double b)`)
Method Overriding: Subclass provides specific implementation of a parent method (e.g., `void sound()` in `Animal` class and `void sound()` in `Dog` class).
Overloading is...
Functional interfaces in Java enable concise lambda expressions for single abstract methods, enhancing API flexibility and usability.
A functional interface has exactly one abstract method, e.g., Runnable, Callable.
Lambda expressions provide a shorthand way to implement functional interfaces, e.g., () -> System.out.println("Hello World").
Functional interfaces can include multiple default or static methods, allowing f...
Java Streams enable functional operations on collections with lazy evaluation, differing from Iterators in several key aspects.
Streams support functional-style operations like filter(), map(), and reduce().
Example: stream.filter(x -> x > 10).map(x -> x * 2).collect(Collectors.toList());
Streams are not reusable; once consumed, they cannot be used again.
Iterators can be reset and reused, allowing for multiple tr...
Immutability in Java ensures objects cannot be changed after creation, enhancing thread safety and preventing unintended side effects.
Immutable objects cannot be modified after creation, e.g., String class.
Thread-safe by nature, as they prevent concurrent modification issues.
To create an immutable class, use final fields and avoid setters.
Collections can be made immutable using Collections.unmodifiableList().
Useful for...
final, finally, and finalize serve different purposes in Java: constants, cleanup, and garbage collection respectively.
final: Used to declare constants. Example: final int MAX_VALUE = 100;
final: Prevents method overriding. Example: final void display() {}
final: Prevents inheritance. Example: final class Constants {}
finally: Executes after try-catch for cleanup. Example: try { ... } catch { ... } finally { closeResource...
Singleton pattern ensures a class has only one instance, providing a global access point to it.
Private constructor prevents instantiation from outside the class.
Static instance variable holds the single instance of the class.
Lazy initialization creates the instance only when needed.
Eager initialization creates the instance at class loading time.
Thread safety can be achieved using synchronized methods or blocks.
Double-c...
Java annotations provide metadata to enhance code readability and reduce boilerplate in frameworks like Spring.
Annotations serve as metadata, providing additional information about classes, methods, and fields.
Common built-in annotations include @Override, @Deprecated, and @SuppressWarnings.
Spring framework uses annotations like @Component for defining beans and @Autowired for dependency injection.
Annotations reduce bo...
Java Streams enable parallel processing using ForkJoin framework, but have pitfalls like race conditions and performance issues with small datasets.
Use parallel streams for CPU-intensive tasks to leverage multiple cores.
Avoid using parallel streams for small datasets as overhead may outweigh benefits.
Minimize shared mutable state to prevent race conditions; prefer immutable objects.
Use forEachOrdered() for order-sensit...
I appeared for an interview in May 2025, where I was asked the following questions.
ArrayList offers fast access, while LinkedList excels in insertions/deletions. Choose based on operation needs.
ArrayList provides O(1) access time, ideal for frequent retrievals.
LinkedList allows O(1) insertions/deletions at both ends, suitable for dynamic data.
Example: Use ArrayList for a list of user IDs accessed frequently.
Example: Use LinkedList for a playlist where songs are added/removed often.
Memory overhead is ...
Java's synchronized keyword offers simple thread synchronization but can lead to performance issues and deadlocks.
Prevents race conditions by allowing only one thread to access a block of code at a time.
Can lead to performance bottlenecks due to thread blocking and context switching.
May cause deadlocks if multiple threads are waiting for each other to release locks.
Starvation can occur if a thread is perpetually denied...
== checks reference equality; .equals() checks value equality. Override equals() for custom comparison in classes.
== compares memory addresses, while .equals() compares actual content.
Example: new String('hello') == new String('hello') returns false.
'hello'.equals('hello') returns true, as it compares values.
Wrapper classes like Integer cache small values, affecting == behavior.
Override equals() when logical equality d...
Java's garbage collector automatically manages memory, reclaiming space from unused objects through various algorithms.
Garbage collection (GC) in Java reclaims memory from objects that are no longer in use.
The JVM uses different GC algorithms: Serial, Parallel, CMS, and G1 GC.
Memory is divided into Young Generation (short-lived objects) and Old Generation (long-lived objects).
Minor GC occurs in the Young Generation, wh...
Lambda expressions enhance Java code by improving readability and maintainability through concise syntax and functional programming.
Concise Syntax: Lambda expressions reduce boilerplate code, making it easier to read. Example: (x) -> x * 2 instead of creating a full class.
Functional Programming: Encourages a functional style, allowing developers to focus on 'what' to do rather than 'how' to do it.
Improved Readabilit...
Checked exceptions require handling; unchecked exceptions do not. Custom exceptions can be either, depending on use case.
Checked exceptions must be caught or declared (e.g., IOException, SQLException).
Unchecked exceptions do not require explicit handling (e.g., NullPointerException, ArithmeticException).
Use checked exceptions for recoverable conditions and unchecked for programming errors.
Custom exceptions can be creat...
The Java Memory Model defines thread interactions with memory, ensuring visibility and ordering in multithreaded environments.
JMM specifies how threads interact with shared variables, ensuring visibility and ordering.
Volatile keyword ensures that changes to a variable are visible to all threads immediately.
Synchronized blocks provide mutual exclusion, preventing multiple threads from accessing critical sections simulta...
Method overloading allows same method names with different parameters; overriding changes method behavior in subclasses.
Method Overloading: Same method name, different parameters (e.g., `int add(int a, int b)` and `double add(double a, double b)`)
Method Overriding: Subclass provides a specific implementation of a method defined in its superclass (e.g., `void sound()` in `Animal` class and `void sound()` in `Dog` class)...
Functional interfaces in Java enable concise lambda expressions and API evolution without breaking changes.
A functional interface has exactly one abstract method, e.g., Runnable, Callable.
Lambda expressions provide a shorthand way to implement functional interfaces, e.g., () -> System.out.println("Hello").
Functional interfaces can include multiple default or static methods, enhancing functionality without breaking e...
Java Streams enable functional operations on collections with lazy evaluation, differing from Iterators in several key aspects.
Streams support functional-style operations like filter(), map(), and reduce().
Unlike Iterators, Streams cannot be reused once consumed.
Streams can be processed in parallel, improving performance on large datasets.
Parallel streams utilize the ForkJoin framework for efficient multi-threading.
Tra...
Immutability in Java ensures objects cannot be changed after creation, enhancing thread safety and consistency.
Immutable objects cannot be modified after creation, e.g., String class.
Thread-safe: No risk of concurrent modification issues.
Prevents unintended side effects in multi-threaded applications.
To create an immutable class, use final fields and avoid setters.
Collections can be made immutable using Collections.unm...
final, finally, and finalize serve different purposes in Java: constants, cleanup, and garbage collection respectively.
final: Used to declare constants. Example: final int MAX_VALUE = 100;
final: Prevents method overriding. Example: final void display() {}
final: Prevents inheritance. Example: final class Constants {}
finally: Executes after try-catch, ensuring cleanup. Example: try { ... } catch { ... } finally { cleanup...
Singleton pattern restricts a class to a single instance, useful for shared resources like database connections.
Private constructor prevents instantiation from outside the class.
Static instance variable holds the single instance of the class.
Lazy initialization creates the instance only when needed.
Eager initialization creates the instance at class loading time.
Thread safety can be achieved using synchronized methods o...
Java annotations provide metadata for classes and methods, enhancing code readability and reducing boilerplate in frameworks like Spring.
Annotations like @Component and @Service in Spring simplify bean management and dependency injection.
Built-in annotations such as @Override and @Deprecated improve code clarity by indicating method behavior and deprecation status.
Custom annotations can be created using @interface to e...
Java Streams enable parallel processing but come with challenges like thread safety and performance issues.
Java Streams can be parallelized using the 'parallelStream()' method, which splits the data into multiple chunks for processing.
Pitfalls include thread contention, where multiple threads compete for shared resources, leading to performance degradation.
Not all operations benefit from parallelism; for example, small...
I appeared for an interview in May 2025, where I was asked the following questions.
ArrayList offers fast access and is memory efficient, while LinkedList excels in insertions and deletions but has higher memory overhead.
ArrayList provides O(1) access time for elements, making it ideal for frequent retrievals.
LinkedList allows O(1) insertions/deletions at both ends, suitable for dynamic data structures.
Example: Use ArrayList for a list of user names where frequent access is needed.
Example: Use LinkedL...
Java's synchronized keyword provides thread safety but can lead to performance issues and deadlocks.
Prevents race conditions by allowing only one thread to access a block of code at a time.
Can lead to performance bottlenecks due to thread blocking and context switching.
May cause deadlocks if multiple threads are waiting for each other to release locks.
ReentrantLock offers more control with methods like tryLock() for no...
== checks reference equality; .equals() checks value equality, can be overridden for custom classes.
== compares memory addresses, while .equals() compares actual content.
Example: new String("hello") == new String("hello") returns false.
"hello".equals("hello") returns true.
Wrapper classes like Integer cache small values (-128 to 127), affecting == behavior.
Override equals() when logical equality is needed, e.g., in cust...
Java's garbage collector reclaims memory from unused objects, optimizing performance and managing memory efficiently.
Garbage collection is automatic, freeing developers from manual memory management.
Java uses different GC algorithms: Serial, Parallel, CMS, and G1, each suited for different scenarios.
Memory is divided into Young Generation (short-lived objects) and Old Generation (long-lived objects).
Minor GC occurs in ...
Lambda expressions enhance Java code by making it more concise, readable, and easier to maintain through functional programming.
Conciseness: Lambda expressions reduce boilerplate code. For example, instead of creating an anonymous class for a Runnable, you can use: Runnable r = () -> System.out.println('Hello');
Readability: Code using lambda expressions is often more intuitive. For instance, using streams: list.stre...
Checked exceptions require handling; unchecked exceptions do not. Custom exceptions can be either, based on use case.
Checked exceptions must be caught or declared (e.g., IOException, SQLException).
Unchecked exceptions do not require explicit handling (e.g., NullPointerException, ArithmeticException).
Use checked exceptions for recoverable conditions and unchecked for programming errors.
Custom exceptions can be created f...
The Java Memory Model defines thread interactions with memory, ensuring visibility and ordering in multithreaded environments.
JMM specifies how threads see shared variables and the rules for visibility.
Volatile keyword ensures that updates to a variable are visible to all threads immediately.
Synchronized blocks provide mutual exclusion, preventing multiple threads from accessing critical sections simultaneously.
Without...
Method overloading allows same method name with different parameters; overriding changes parent method behavior in subclasses.
Method Overloading: Same method name, different parameters (e.g., `int add(int a, int b)` and `double add(double a, double b)`)
Method Overriding: Subclass provides specific implementation of a method defined in its superclass (e.g., `void sound()` in `Animal` class overridden in `Dog` class)
Over...
Functional interfaces in Java enable lambda expressions for concise implementation of single abstract methods.
A functional interface has exactly one abstract method, e.g., Runnable, Callable.
Lambda expressions provide a shorthand way to implement functional interfaces, e.g., () -> System.out.println("Hello").
Functional interfaces can have multiple default or static methods, allowing for added functionality without b...
Java Streams enable functional operations on collections with lazy evaluation, unlike Iterators which are more imperative.
Streams support functional-style operations like filter, map, and reduce, enabling cleaner and more readable code.
Example: `List<String> filtered = list.stream().filter(s -> s.startsWith("A")).collect(Collectors.toList());`
Streams are not reusable; once a terminal operation is performed, th...
Immutability in Java ensures objects cannot be changed after creation, enhancing thread safety and preventing unintended side effects.
Immutable objects cannot be modified after creation, e.g., String class.
Thread-safe by nature, as they prevent concurrent modifications.
Prevent unintended side effects in multi-threaded applications.
To create an immutable class, use final fields and avoid setters.
Collections can be made ...
final, finally, and finalize serve different purposes in Java: constants, cleanup, and garbage collection respectively.
final: Used to declare constants. Example: final int MAX_VALUE = 100;
finally: A block that executes after try-catch. Example: try { ... } catch { ... } finally { cleanup(); }
finalize(): A method called by the garbage collector. Example: protected void finalize() { ... }
final variable cannot be reassign...
Singleton pattern ensures a class has only one instance, providing a global point of access to it.
Private constructor prevents instantiation from outside the class.
Static instance variable holds the single instance of the class.
Lazy initialization creates the instance only when needed.
Eager initialization creates the instance at class loading time.
Thread safety can be achieved using synchronized methods or blocks.
Doubl...
Java annotations provide metadata for classes and methods, enhancing code readability and reducing boilerplate in frameworks like Spring.
Annotations like @Component and @Service simplify bean management in Spring.
Dependency injection is streamlined with @Autowired, reducing manual wiring.
Custom annotations can encapsulate repetitive logic, improving code clarity.
Annotations reduce the need for XML configuration, making...
Java Streams enable parallel processing using ForkJoin framework, but have pitfalls like race conditions and debugging challenges.
Use parallel streams for CPU-intensive tasks to leverage multiple cores.
Avoid using parallel streams for small datasets as overhead may outweigh benefits.
Be cautious with shared mutable state to prevent race conditions.
Use forEachOrdered() for order-sensitive operations, but be aware of perf...
I appeared for an interview in May 2025, where I was asked the following questions.
ArrayList offers fast access and is memory efficient, while LinkedList excels in insertions and deletions but has higher memory overhead.
ArrayList provides O(1) access time, ideal for frequent retrievals.
LinkedList allows O(1) insertions/deletions at both ends, suitable for dynamic data.
Example: Use ArrayList for a list of user names where retrieval is frequent.
Example: Use LinkedList for a playlist where songs are fre...
Java's synchronized keyword offers simplicity for thread safety but can lead to performance issues and deadlocks.
Synchronized is easy to use and requires less code, making it suitable for simple scenarios.
Example: synchronized void method() { // critical section }
It prevents race conditions by allowing only one thread to execute a block of code at a time.
Performance can degrade due to thread blocking and context switch...
== checks reference equality; .equals() checks value equality, can be overridden for custom comparison.
== compares memory addresses: new String('hello') == new String('hello') returns false.
.equals() compares actual content: 'hello'.equals('hello') returns true.
Override equals() when logical equality is needed, e.g., in custom classes like Point or Person.
When overriding equals(), also override hashCode() to maintain c...
Java's garbage collector automatically manages memory, reclaiming space from unused objects through various algorithms.
Garbage collection (GC) in Java reclaims memory from objects that are no longer in use.
The JVM uses different GC algorithms: Serial, Parallel, CMS, and G1 GC.
Memory is divided into Young Generation (short-lived objects) and Old Generation (long-lived objects).
Minor GC focuses on cleaning the Young Gene...
Lambda expressions enhance Java code by improving readability and maintainability through concise syntax and functional programming.
Concise Syntax: Lambda expressions reduce boilerplate code, making it easier to read. Example: (x) -> x * 2 instead of creating a full class.
Functional Programming: Encourages a functional style, allowing developers to focus on 'what' to do rather than 'how' to do it.
Improved Readabilit...
Checked exceptions require handling, while unchecked exceptions indicate programming errors. Custom exceptions can be either type.
Checked exceptions must be caught or declared (e.g., IOException, SQLException).
Unchecked exceptions do not require explicit handling (e.g., NullPointerException, ArithmeticException).
Use checked exceptions for recoverable conditions and unchecked for programming errors.
Custom exceptions can...
The Java Memory Model defines thread interactions with memory, ensuring visibility and ordering in multithreaded environments.
JMM specifies how threads interact with shared variables, ensuring visibility and ordering.
Volatile keyword ensures that changes to a variable are visible to all threads immediately.
Synchronized blocks provide mutual exclusion, preventing multiple threads from accessing critical sections simulta...
Method overloading allows same method names with different parameters; overriding changes parent method behavior in subclasses.
Method Overloading: Same method name, different parameters (e.g., `int add(int a, int b)` vs `double add(double a, double b)`)
Method Overriding: Subclass provides specific implementation of a method defined in its superclass (e.g., `void sound()` in `Animal` class overridden in `Dog` class).
Ove...
Functional interfaces in Java enable concise lambda expressions and support API evolution through default methods.
A functional interface has exactly one abstract method, e.g., Runnable, Callable.
Lambda expressions provide a shorthand way to implement functional interfaces, e.g., () -> System.out.println("Hello").
Functional interfaces can have multiple default or static methods, allowing for added functionality witho...
Java Streams enable functional operations on collections with lazy evaluation, differing from Iterators in several key aspects.
Streams support functional-style operations like filter(), map(), and reduce() for cleaner code.
Unlike Iterators, Streams cannot be reused; once consumed, they cannot be reset.
Streams can be processed in parallel, leveraging multi-core architectures for performance gains.
Parallel streams use th...
Immutability in Java ensures objects cannot be changed after creation, enhancing thread safety and consistency.
Immutable objects cannot be modified after creation, e.g., String class.
Thread-safe by nature, as they prevent concurrent modifications.
Prevent unintended side effects in multi-threaded applications.
To create an immutable class, use final fields and avoid setters.
Collections can be made immutable using Collect...
final, finally, and finalize serve different purposes in Java: constants, cleanup, and garbage collection respectively.
final: Used to declare constants. Example: final int MAX_VALUE = 100;
final: Prevents method overriding. Example: final void display() {}
final: Prevents inheritance. Example: final class Constants {}
finally: Executes after try-catch for cleanup. Example: try { ... } catch { ... } finally { closeResource...
The Singleton pattern restricts a class to a single instance, useful for shared resources like database connections.
Private constructor prevents instantiation from outside the class.
Static instance variable holds the single instance of the class.
Lazy initialization creates the instance only when needed.
Eager initialization creates the instance at class loading time.
Thread safety can be achieved using synchronized metho...
Java annotations provide metadata for classes and methods, enhancing code readability and reducing boilerplate in frameworks like Spring.
Annotations like @Component and @Service simplify Spring's dependency injection.
Built-in annotations such as @Override and @Deprecated improve code clarity and intent.
Custom annotations can be created using @interface to encapsulate specific behaviors.
Retention policies (e.g., @Retent...
Java Streams enable parallel processing using ForkJoin framework, but have pitfalls like race conditions and performance issues with small datasets.
Use parallel streams for CPU-intensive tasks to leverage multiple cores effectively.
Avoid using parallel streams for small datasets as overhead may outweigh benefits.
Be cautious with shared mutable state to prevent race conditions; prefer immutable data structures.
Use opera...
I appeared for an interview in May 2025, where I was asked the following questions.
ArrayList offers fast access and is memory efficient, while LinkedList excels in insertions and deletions.
ArrayList allows O(1) access time, making it ideal for frequent retrievals.
LinkedList provides O(1) insertions/deletions at both ends, suitable for dynamic data.
Example: Use ArrayList for a list of user names where frequent lookups are needed.
Example: Use LinkedList for a playlist where songs are frequently added o...
Java's synchronized keyword offers simplicity for thread safety but can lead to performance issues and deadlocks.
Synchronized is easy to use and requires no explicit unlocking.
It prevents race conditions by allowing only one thread to access a block of code.
Performance can degrade due to thread blocking and context switching.
Deadlocks can occur if multiple threads wait on each other for locks.
ReentrantLock offers more ...
== checks reference equality; .equals() checks value equality, can be overridden for custom comparison.
== compares memory addresses, while .equals() compares actual content.
Example: new String("hello") == new String("hello") returns false.
"hello".equals("hello") returns true, showing content comparison.
Wrapper classes like Integer cache small values, affecting == behavior.
Override equals() when logical equality is need...
Java's garbage collector reclaims memory from unused objects, optimizing performance and managing memory regions efficiently.
Garbage collection in Java is automatic, freeing developers from manual memory management.
The heap is divided into Young Generation (short-lived objects) and Old Generation (long-lived objects).
Minor GC occurs in the Young Generation, while Major GC (Full GC) affects the Old Generation and can ca...
Lambda expressions enhance Java code by making it more concise, readable, and easier to maintain through functional programming.
Conciseness: Lambda expressions reduce boilerplate code. Example: Instead of writing an anonymous class for Runnable, use () -> System.out.println("Hello").
Readability: Code becomes more expressive. Example: Using lambdas with Collections: list.forEach(item -> System.out.println(item)); ...
Checked exceptions require handling, while unchecked exceptions indicate programming errors. Custom exceptions can be either type.
Checked exceptions must be caught or declared (e.g., IOException, SQLException).
Unchecked exceptions do not require explicit handling (e.g., NullPointerException, ArithmeticException).
Use checked exceptions for recoverable conditions and unchecked for programming errors.
Custom exceptions can...
The Java Memory Model defines thread interaction with memory, ensuring visibility and ordering in multithreaded environments.
JMM specifies how threads read and write shared variables.
Volatile keyword ensures visibility of changes across threads.
Synchronized blocks provide mutual exclusion and visibility guarantees.
Without synchronization, threads may see stale or inconsistent data.
Compiler and CPU optimizations can reo...
Method overloading allows same method name with different parameters; overriding allows subclass to redefine parent method.
Method Overloading: Same method name, different parameters (e.g., `int add(int a, int b)` and `double add(double a, double b)`)
Method Overriding: Subclass provides specific implementation of a method defined in its superclass (e.g., `void sound()` in `Animal` class overridden in `Dog` class)
Overloa...
Functional interfaces in Java enable concise lambda expressions for single abstract methods, enhancing API evolution and compatibility.
A functional interface has exactly one abstract method, e.g., Runnable, Callable.
Lambda expressions provide a shorthand way to implement functional interfaces, e.g., () -> System.out.println('Hello').
Functional interfaces can have multiple default or static methods, allowing addition...
Java Streams enable functional operations on collections with lazy evaluation, differing from Iterators in several key aspects.
Streams support functional-style operations like filter(), map(), and reduce() for cleaner code.
Unlike Iterators, Streams do not store data; they operate directly on the source.
Streams are not reusable; once consumed, they cannot be reset, while Iterators can be reused.
Parallel streams can impr...
Immutability in Java ensures objects cannot be modified after creation, enhancing thread safety and consistency.
Immutable objects cannot be changed after creation, e.g., String class.
Thread-safe by nature, as they prevent concurrent modifications.
Prevent unintended side effects in multi-threaded applications.
To create an immutable class, use final fields and avoid setters.
Collections can be made immutable using Collect...
final, finally, and finalize serve different purposes in Java: constants, cleanup, and garbage collection respectively.
final: Used to declare constants. Example: final int MAX_VALUE = 100;
final: Prevents method overriding. Example: final void display() {}
final: Prevents inheritance. Example: final class MyClass {}
finally: Executes after try-catch, ensuring cleanup. Example: try { ... } catch { ... } finally { closeReso...
Singleton pattern ensures a class has only one instance, providing a global access point to it.
Private constructor prevents instantiation from outside the class.
Static instance variable holds the single instance of the class.
Lazy initialization creates the instance only when needed.
Eager initialization creates the instance at class loading time.
Thread safety can be achieved using synchronized methods or blocks.
Double-c...
Java annotations provide metadata for classes and methods, enhancing code readability and reducing boilerplate in frameworks like Spring.
Annotations like @Component and @Service in Spring simplify bean management and dependency injection.
Built-in annotations such as @Override improve code clarity by indicating overridden methods.
Custom annotations can be created using @interface to encapsulate specific behaviors or con...
Java Streams enable parallel processing using ForkJoin framework, but have pitfalls like race conditions and performance issues with small datasets.
Use parallelStream() for parallel processing: Example: list.parallelStream().map(...).collect(Collectors.toList());
Avoid shared mutable state to prevent race conditions: Use immutable objects or thread-safe collections.
Limit the use of order-sensitive operations: Prefer for...
ArrayList offers fast access and is memory efficient, while LinkedList excels in insertions and deletions.
ArrayList: Fast random access (O(1)), ideal for frequent retrievals. Example: Accessing elements in a list of user IDs.
LinkedList: Fast insertions/deletions (O(1) at head/tail), suitable for dynamic data structures. Example: Implementing a queue.
Memory Overhead: LinkedList has higher memory usage due to additional ...
Java's synchronized keyword offers simplicity for thread safety but has limitations like performance issues and potential deadlocks.
Synchronized is easy to use and requires less code, making it suitable for simple scenarios.
It automatically releases the lock when the thread exits the synchronized block, reducing the risk of forgetting to unlock.
Performance can degrade with high contention, as threads may block each oth...
== checks reference equality; .equals() checks value equality, can be overridden for custom comparison.
== compares memory addresses, while .equals() compares the actual content of objects.
Example: new String('hello') == new String('hello') returns false, but 'hello'.equals('hello') returns true.
For wrapper classes like Integer, small values (-128 to 127) are cached, affecting == behavior.
Override equals() when logical ...
Java's garbage collector reclaims memory from unused objects, optimizing performance and managing memory efficiently.
Garbage collection in Java is automatic, freeing developers from manual memory management.
The heap is divided into Young Generation (short-lived objects) and Old Generation (long-lived objects).
Minor GC occurs in the Young Generation, while Major GC (Full GC) affects the Old Generation and can cause appl...
Lambda expressions enhance Java code by promoting functional programming, improving readability, and simplifying code maintenance.
Concise syntax: Lambda expressions reduce boilerplate code, making it easier to read. Example: (x) -> x * 2 instead of creating a separate class.
Improved focus: They allow developers to focus on the 'what' rather than the 'how', enhancing clarity. Example: list.forEach(item -> System.o...
Checked exceptions require handling; unchecked exceptions do not. Custom exceptions can be either, based on use case.
Checked exceptions must be caught or declared (e.g., IOException, SQLException).
Unchecked exceptions do not require explicit handling (e.g., NullPointerException, ArithmeticException).
Checked exceptions promote robust error handling but can clutter code.
Unchecked exceptions indicate programming errors th...
The Java Memory Model defines thread interactions with memory, ensuring visibility and ordering in multithreaded environments.
JMM specifies how threads read and write shared variables.
Volatile keyword ensures visibility of changes across threads.
Synchronized blocks provide mutual exclusion and visibility guarantees.
Without synchronization, threads may see stale or inconsistent data.
Compiler and CPU optimizations can re...
Method overloading allows multiple methods with the same name but different parameters, while overriding changes a parent's method in a subclass.
Method Overloading: Same method name, different parameters (e.g., int add(int a, int b) vs. double add(double a, double b)).
Method Overriding: Subclass provides a specific implementation of a method defined in its superclass (e.g., class Animal has method sound(), class Dog ov...
Functional interfaces in Java enable concise implementations using lambda expressions, enhancing code readability and flexibility.
A functional interface has exactly one abstract method, e.g., Runnable, Callable.
Lambda expressions provide a shorthand way to implement functional interfaces, e.g., () -> System.out.println("Hello").
Functional interfaces can have multiple default or static methods, allowing for added fun...
Java Streams enable functional operations on collections with lazy evaluation, unlike Iterators which are more imperative.
Streams support functional-style operations like filter(), map(), and reduce().
Example: list.stream().filter(x -> x > 10).collect(Collectors.toList());
Streams are not reusable; once consumed, they cannot be used again.
Iterators can be reset and reused, allowing for multiple traversals.
Parallel...
Immutability in Java ensures objects cannot be modified after creation, enhancing safety and consistency in multi-threaded environments.
Immutable objects cannot be changed after creation, e.g., String class.
Thread-safe by nature, preventing unintended side effects in multi-threaded programs.
To create an immutable class, use final fields and avoid setters.
Collections can be made immutable using Collections.unmodifiableL...
final, finally, and finalize serve different purposes in Java: constants, cleanup, and garbage collection respectively.
final: Used to declare constants. Example: final int MAX_VALUE = 100;
finally: A block that executes after try-catch. Example: try { /* code */ } catch (Exception e) { /* handle */ } finally { /* cleanup */ }
finalize(): A method called by the garbage collector. Example: protected void finalize() { /* cl...
Singleton pattern ensures a class has only one instance, providing a global point of access to it.
Private constructor prevents instantiation from outside the class.
Static instance variable holds the single instance of the class.
Lazy initialization creates the instance only when needed.
Eager initialization creates the instance at class loading time.
Thread safety can be achieved using synchronized methods or blocks.
Doubl...
Java annotations provide metadata for classes and methods, enhancing code readability and reducing boilerplate in frameworks like Spring.
Annotations like @Component and @Service in Spring simplify bean management and dependency injection.
Built-in annotations such as @Override and @Deprecated improve code clarity by indicating method behavior and deprecation status.
Custom annotations can be created using @interface to e...
Java Streams enable parallel processing using ForkJoin framework, but have pitfalls like race conditions and performance issues with small datasets.
Use parallelStream() for parallel processing: List<String> parallelList = list.parallelStream().filter(...).collect(Collectors.toList());
Avoid shared mutable state to prevent race conditions: Use immutable objects or thread-safe collections.
Use appropriate data struct...
final, finally, and finalize serve different purposes in Java: constants, cleanup, and garbage collection respectively.
final: Used to declare constants. Example: final int MAX_VALUE = 100;
finally: A block that executes after try-catch. Example: try { ... } catch { ... } finally { cleanup(); }
finalize(): A method called by the garbage collector. Example: protected void finalize() { ... }
final variable: Cannot be reassig...
The Singleton pattern restricts a class to a single instance, useful for shared resources like database connections.
Private constructor prevents instantiation from outside the class.
Static instance variable holds the single instance of the class.
Lazy initialization creates the instance only when needed.
Eager initialization creates the instance at class loading time.
Thread safety can be achieved using synchronized metho...
Java annotations provide metadata for classes, enhancing readability and reducing boilerplate in frameworks like Spring.
Annotations like @Component and @Service simplify bean configuration in Spring.
Using @Autowired allows for automatic dependency injection, reducing manual wiring.
Custom annotations can encapsulate repetitive logic, improving code clarity.
Annotations like @Transactional manage database transactions dec...
Java Streams enable parallel processing via ForkJoin framework, enhancing performance but with potential pitfalls.
Use parallelStream() for parallel processing: Example: list.parallelStream().map(...).collect(Collectors.toList());
Avoid shared mutable state to prevent race conditions: Use immutable objects or thread-safe collections.
Consider the size of the dataset: Parallel processing is beneficial for large datasets bu...
I appeared for an interview in May 2025, where I was asked the following questions.
final, finally, and finalize serve different purposes in Java: constants, cleanup, and garbage collection respectively.
final: Used to declare constants. Example: final int MAX_VALUE = 100;
finally: A block that executes after try-catch. Example: try { ... } catch { ... } finally { cleanup(); }
finalize(): A method called by the garbage collector. Example: protected void finalize() { ... }
final variable cannot be reassign...
Singleton pattern ensures a class has only one instance, providing a global point of access to it.
Private constructor prevents instantiation from outside the class.
Static instance variable holds the single instance of the class.
Lazy initialization creates the instance only when needed.
Eager initialization creates the instance at class loading time.
Thread safety can be achieved using synchronized methods or blocks.
Doubl...
Java annotations provide metadata for classes and methods, enhancing code readability and reducing boilerplate in frameworks like Spring.
Annotations like @Component and @Service simplify bean registration in Spring.
Dependency injection is streamlined with @Autowired, reducing manual wiring.
Custom annotations can encapsulate repetitive configurations, improving code clarity.
Annotations reduce the need for XML configurat...
Java Streams enable parallel processing using ForkJoin framework, but have pitfalls like race conditions and debugging challenges.
Use parallelStream() for parallel processing: Example: list.parallelStream().map(...).collect(Collectors.toList());
Avoid shared mutable state to prevent race conditions: Use immutable objects or thread-safe collections.
Consider the size of the dataset: Parallel streams are beneficial for lar...
Top trending discussions
Some of the top questions asked at the 10405090xyzabc Test Engineer interview -
The duration of 10405090xyzabc Test Engineer interview process can vary, but typically it takes about 2-4 weeks to complete.
based on 36 interview experiences
Difficulty level
Duration
based on 5 reviews
Rating in categories
Software Developer
30.9k
salaries
| ₹4 L/yr - ₹15 L/yr |
Software Engineer
8k
salaries
| ₹7 L/yr - ₹10.1 L/yr |
Sales Officer
1.7k
salaries
| ₹2.8 L/yr - ₹3.6 L/yr |
System Engineer
71
salaries
| ₹7.5 L/yr - ₹7.5 L/yr |
Project Manager
71
salaries
| ₹12 L/yr - ₹12 L/yr |
PwC
KPMG India
IQVIA
Max Healthcare