i
10405090xyzabc
Work with us
Filter interviews by
Checked exceptions require handling; unchecked exceptions do not. Use custom exceptions based on context and error handling needs.
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 exception...
The Java Memory Model defines thread interactions with memory, ensuring visibility and ordering in multithreaded environments.
JMM specifies how threads interact with shared variables and memory.
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 opti...
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 display()` in both parent and child classes)
Overloading...
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...
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: finally { resource.close(); }
finalize(): Cal...
The Singleton pattern restricts a class to a single instance, useful for shared resources like database connections.
Singleton ensures only one instance exists in the JVM.
Private constructor prevents instantiation from other classes.
Lazy initialization creates the instance when needed.
Eager initialization creates the instance at class loading time.
Thread safety can be achieved using synchronized methods or blocks.
D...
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 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().
Usefu...
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 { /* handle */ } finally { /* cleanup */ }
finalize(): A method called by the garbage collector. Example: protected void finalize() { /* cleanup cod...
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...
I appeared for an interview in Jun 2025, where I was asked the following questions.
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 for elements, making it ideal for frequent retrievals.
LinkedList allows O(1) insertions/deletions at both ends, suitable for queue implementations.
Example: Use ArrayList for a list of user names where retrieval is frequent.
Example: Use LinkedList fo...
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: Using synchronized methods to protect shared resources like counters.
It can lead to performance bottlenecks due to thread blocking and context switching.
Example: Multiple threads waiting for a synchronized bl...
== 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.
Wrapper classes like Integer cache small values (-128 to 127), affecting == behavior.
Override equals() when logical equalit...
Method overloading allows multiple methods with the same name but different parameters; overriding changes a method's implementation 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., `class Dog extends Animal { void sound()...
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...
The Singleton pattern restricts a class to a single instance, useful for shared resources like database connections.
Singleton ensures one instance: Only one instance of the class exists in the JVM.
Private constructor: Prevents instantiation from outside the class.
Lazy initialization: Instance is created only when needed, saving resources.
Eager initialization: Instance is created at class loading time, ensuring it's rea...
I appeared for an interview in Jun 2025, where I was asked the following questions.
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 increased context switching.
Deadl...
== checks reference equality, while .equals() checks value equality. Override equals() for custom comparison logic.
== 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, affecting == behavior.
Override equals() when logical equality differs from reference ...
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 GC, each with unique characteristics.
Memory is divided into regions: Young Generation (short-lived objects), Old Generation (long-lived objects),...
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...
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)` vs `double add(double a, double b)`)
Method Overriding: Subclass provides specific implementation of a parent method (e.g., `void sound()` in `Animal` class overridden in `Dog` class).
Overloading is resolved...
Functional interfaces in Java enable concise lambda expressions for single abstract methods, 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 include multiple default or static methods, allowing for ...
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: 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...
The Singleton pattern restricts a class to a single instance, useful for shared resources like database connections.
Singleton ensures only one instance exists in the JVM.
Private constructor prevents instantiation from outside the class.
Lazy initialization creates the instance when needed.
Eager initialization creates the instance at class loading time.
Thread safety can be achieved using synchronized methods or blocks.
Do...
I appeared for an interview in Jun 2025, where I was asked the following questions.
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 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, causing longer ...
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 becomes easier to read and understand. For instance, using streams with lambdas: list.st...
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) vs. double add(double a, double b)).
Method Overriding: Subclass provides specific implementation of a method defined in its superclass (e.g., class Animal has method sound(), class Dog overrides it).
Overloadi...
Singleton pattern restricts class instantiation to one object, 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 meth...
Java annotations provide metadata for classes, enhancing code readability and maintainability, especially in frameworks like Spring.
Annotations like @Component and @Service simplify bean management in Spring.
Dependency injection is streamlined with @Autowired, reducing boilerplate code.
Custom annotations can encapsulate common behaviors, improving code clarity.
Retention policies (e.g., @Retention(RetentionPolicy.RUNTIM...
I appeared for an interview in Jun 2025, where I was asked the following questions.
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 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 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 no explicit unlocking, reducing the chance of errors.
It prevents race conditions by allowing only one thread to access a block of code at a time.
Performance can degrade due to thread blocking, especially in high-contention scenarios.
Deadlocks can occur if multiple thr...
== 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.
Example: 'hello'.equals('hello') returns true.
Wrapper classes like Integer cache small values (-128 to 127), affecting == behavior.
Override equals() when logical equality differs from re...
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 suited for different scenarios.
Memory is divided into regions: Young Generation (short-lived objects), Old Generation (long-lived objects),...
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 becomes more expressive. For instance, using streams: list.stream().filter(x -> x >...
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 but different parameters, while overriding changes a parent method's implementation.
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 o...
Functional interfaces in Java enable concise implementation of single abstract methods using lambda expressions.
A functional interface has exactly one abstract method, e.g., Runnable, Callable.
Lambda expressions provide a shorthand way to implement functional interfaces.
Functional interfaces can have multiple default or static methods.
The @FunctionalInterface annotation helps prevent accidental addition of abstract met...
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.
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 multip...
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: 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 sette...
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 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 when first accessed.
Eager initialization creates the instance at class loading time.
Thread safety can be achieved using synchronized methods or block...
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, but have pitfalls like race conditions and performance issues with small datasets.
Use parallel streams for CPU-intensive tasks to leverage multiple cores.
Avoid shared mutable state to prevent race conditions; prefer immutable data structures.
Use the 'parallel()' method to convert a sequential stream to a parallel stream.
Be cautious with order-sensitive operations;...
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 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, 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.
Wrapper classes like Integer cache small values (-128 to 127), affecting == behavior.
Override equals() when logical equality is needed, e.g., in c...
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 readability and maintainability by simplifying syntax and promoting functional programming.
Concise Syntax: Lambda expressions reduce boilerplate code, making it easier to read. Example: (x) -> x * 2 instead of creating a separate class.
Improved Clarity: They express behavior more clearly, showing intent directly. Example: list.forEach(item -> System.out.println(item));
Encourag...
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, 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 simult...
Method overloading allows same method names with different parameters; 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 sound()` in `Animal` class overridden in `Dog` c...
Functional interfaces in Java enable concise lambda expressions for single abstract methods, 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 add...
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 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;
finally: A block that executes after try-catch. Example: try { /* code */ } catch { /* handle */ } finally { /* cleanup */ }
finalize(): A method called by the garbage collector. Example: protected void finalize() { /* cleanup code */ ...
The Singleton pattern restricts a class to a single instance, useful for shared resources like database connections.
Singleton ensures only one instance exists in the JVM.
Private constructor prevents instantiation from outside the class.
Lazy initialization creates the instance when needed.
Eager initialization creates the instance at class loading time.
Thread safety can be achieved using synchronized methods or blocks.
Do...
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, all...
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 ...
Top trending discussions
Some of the top questions asked at the 10405090xyzabc interview -
The duration of 10405090xyzabc interview process can vary, but typically it takes about 2-4 weeks to complete.
based on 68 interview experiences
Difficulty level
Duration
based on 43 reviews
Rating in categories
Software Developer
33.3k
salaries
| ₹5.4 L/yr - ₹12.5 L/yr |
Software Engineer
8k
salaries
| ₹4.4 L/yr - ₹10.1 L/yr |
Sales Officer
1.7k
salaries
| ₹1.5 L/yr - ₹5.4 L/yr |
Softwaretest Engineer
131
salaries
| ₹12 L/yr - ₹14.8 L/yr |
System Engineer
71
salaries
| ₹4.5 L/yr - ₹11.2 L/yr |
PwC
KPMG India
IQVIA
Max Healthcare