1. In try-with-resources, where do exceptions thrown during close() appear?
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().
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
Meta · Java
Practice Java questions specifically asked in Meta interviews – ideal for online test preparation, technical rounds and final HR discussions.
Questions
11
Tagged for this company + subject
Company
Meta
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 Meta Java round.
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().
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.
Throwing and capturing exceptions involves filling stack traces and unwinding frames. Use exceptions for exceptional cases, not routine branching.
Executors pool and reuse threads, reducing overhead and providing lifecycle control. Ordering and mutual exclusion are not guaranteed unless you choose specific executors or add your own coordination.
PECS: Producer Extends, Consumer Super. If you read items from a structure, use ? extends T. If you insert items into it, use ? super T. This preserves type safety with variance.
Phaser allows parties to register and deregister at runtime and supports multiple synchronization phases with custom phase-advance logic, making it a superset of many barrier patterns.
volatile publishes the latest value to all threads and prevents certain re-orderings. It does not make compound updates atomic; use locks or atomics for that.
There are four forms: static, instance of particular object, instance of arbitrary object of a particular type, and constructor. `objectRef::instanceMethod` is the particular object form.
Deserialization can trigger gadget chains leading to remote code execution when untrusted data is accepted; the object graph is opaque, brittle across versions, and slow. Safer options: JSON or CBOR with vetted mappers, ProtoBuf/Avro/FlatBuffers for schema-driven, version-tolerant formats, or dedicated DTOs with explicit parsing. If you must deserialize, enable object filters (JEP 290), restrict classes, and do input validation.
ConcurrentHashMap is designed for high concurrency—reads proceed without locking; writes use fine-grained locking or CAS. It disallows null keys and values to avoid ambiguity with missing mappings.
ForkJoinPool keeps per-worker deques; when a worker runs out of local tasks, it steals from the tail of another's deque, reducing contention and balancing work for divide-and-conquer algorithms.
Channels integrate with selectors and ByteBuffers for non-blocking or zero-copy patterns, allowing efficient, scalable I/O. Throughput still depends on workload and hardware.