1. Match use-cases correctly:
final modifies classes/methods/variables; finally executes regardless of exception; finalize() is legacy GC callback (discouraged).
Get the Preplance app for a seamless learning experience. Practice offline, get daily streaks, and stay ahead with real-time interview updates.
Get it on
Google Play
4.9/5 Rating on Store
Infosys · Java
Practice Java questions specifically asked in Infosys interviews – ideal for online test preparation, technical rounds and final HR discussions.
Questions
34
Tagged for this company + subject
Company
Infosys
View company-wise questions
Subject
Java
Explore topic-wise practice
Go through each question and its explanation. Use this page for targeted revision just before your Infosys Java round.
final modifies classes/methods/variables; finally executes regardless of exception; finalize() is legacy GC callback (discouraged).
For complete preparation, combine this company + subject page with full company-wise practice and subject-wise practice. You can also explore other companies and topics from the links below.
Encapsulation (data safety), Abstraction (hide detail), Inheritance (reuse), Polymorphism (flexible behavior).
LSP requires subtypes to be usable anywhere the base is expected without breaking semantics.
They define stable boundaries—hiding internals (private), exposing minimal extension points (protected), and clear public APIs—reducing coupling and easing evolution.
The pool enables reuse of identical String literals, saving memory and speeding equality checks.
equals is overridden to compare character content; == checks object identity.
ArrayList random access (O(1)) due to contiguous array; LinkedList insert/remove in middle (O(1) after locating node) due to links.
Fail-fast checks a modCount; external structural changes break the iteration contract.
Clients coded to the base shouldn’t observe incorrect behavior when given the subtype.
You can use try-finally to guarantee cleanup when you don’t need to handle the exception locally. The exception propagates after finally runs.
If both the try body and close() throw, the try body’s exception is primary, and close() exceptions are attached as suppressed, retrievable via getSuppressed().
The JMM specifies when a thread’s write becomes visible to other threads and which re-orderings are allowed. It’s about visibility and happens-before guarantees, not physical layouts or GC details.
HashMap grows when size > capacity × loadFactor (default 0.75). Resizing redistributes entries to a bigger table, keeping average O(1) operations.
Inheritance models an is-a relationship; composition/aggregation model has-a.
final cannot be overridden; static resolves by compile-time binding; private is not visible to subclasses.
javac produces bytecode; the platform-specific JVM interprets/JIT-compiles it, enabling WORA.
Each thread has its own JVM stack containing frames for method execution.
Encapsulation bundles state and behavior, typically with private fields and public getters/setters.
Weak references allow GC to reclaim entries aggressively—good for caches with no hard retention. Soft references are less aggressively reclaimed (historically for caches, though guidance now favors explicit policies). Phantom references are for post-mortem cleanup with ReferenceQueue; you cannot get the referent.
Read-write locks allow many readers to proceed in parallel, blocking only when a writer acquires the write lock. This improves throughput in read-heavy workloads.
Unboxing a null Integer to int throws NPE; wrappers are immutable and live on heap.
Most standard collections have fail-fast iterators that throw on structural modification. ConcurrentHashMap provides weakly consistent iterators that reflect some concurrent changes without throwing.
PriorityQueue is heap-based: head operations return the minimal (or maximal) element per comparator. Iteration does not guarantee sorted traversal.
For CPU-bound tasks, set the pool size near the number of cores to minimize context switches and maximize CPU utilization. Cached pools can oversubscribe threads and degrade performance.
Semaphores manage permits. Threads acquire a permit before proceeding and release it afterward, capping concurrency to available resources.
Good: return Optional from methods that may be empty; use terminal operations like orElse, orElseGet, orElseThrow instead of get(). Good: chain map/flatMap/filter to avoid nested ifs. Anti-patterns: use Optional for fields or parameters (adds overhead and ambiguity); call get() without checking presence; use Optional in performance-critical collections.
Runnable separates the work from the execution mechanism, allowing reuse with pools and avoiding subclassing limits. You start a thread with start(), which calls run() internally. A terminated thread cannot be restarted.
Stream classes move raw bytes; Reader/Writer classes decode and encode characters using a charset. They’re not interchangeable, but bridges like InputStreamReader and OutputStreamWriter adapt bytes to characters and vice-versa.
JVM searches for a public static void main(String[]). Varargs are allowed but return must be void.
Statics load top-down in hierarchy, then per-instance initialization proceeds super→sub.
Class must override and can delegate to a specific interface’s default via Interface.super.method().
Checked exceptions must be declared or handled; examples include IOException and SQLException. Unchecked exceptions extend RuntimeException; NullPointerException and ArithmeticException are typical. Errors are also unchecked and indicate serious VM problems.
A functional interface is defined by a single abstract method. @FunctionalInterface is optional and only enforces the rule at compile time. Default and static methods don’t change the SAM count.
serialVersionUID is a version stamp. Declaring it stabilizes compatibility decisions across builds and code changes. It has nothing to do with compression or encryption.