1. Which statement about finally is true?
finally runs after try or catch for cleanup, regardless of normal or exceptional flow. It can be skipped in rare cases like System.exit, JVM crash, or power loss.
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
Microsoft · Java
Practice Java questions specifically asked in Microsoft interviews – ideal for online test preparation, technical rounds and final HR discussions.
Questions
9
Tagged for this company + subject
Company
Microsoft
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 Microsoft Java round.
finally runs after try or catch for cleanup, regardless of normal or exceptional flow. It can be skipped in rare cases like System.exit, JVM crash, or power loss.
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.
HashMap grows when size > capacity × loadFactor (default 0.75). Resizing redistributes entries to a bigger table, keeping average O(1) operations.
Finalizers run at GC’s discretion and can cause leaks or latency spikes. Use explicit close patterns or Cleaner for safety and determinism.
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.
Call shutdown to reject new tasks and let running tasks finish. Await for a bounded time. If tasks still run, call shutdownNow to interrupt and drain the queue. This avoids leaks and dangling threads.
Streams are lazy: intermediate steps are recorded until a terminal operation triggers evaluation. There’s exactly one terminal operation per pipeline.
Streams are single-use. Create a new stream from the source for additional terminals, or collect data to a reusable structure first.
Entering a synchronized block acquires the monitor; exiting establishes a happens-before edge that flushes writes to main memory. It ensures mutual exclusion and visibility but not fairness.
Files.walk produces a Stream that must be closed (try-with-resources). Path can represent non-existing locations; Paths.get can be relative. readAllLines loads all content into memory.