1. You catch ArithmeticException and Exception in that order. Which is correct?
Catch blocks are matched top-down. If a broader type comes first, narrower types are unreachable, causing a compile-time error.
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
Goldman Sachs · Java
Practice Java questions specifically asked in Goldman Sachs interviews – ideal for online test preparation, technical rounds and final HR discussions.
Questions
8
Tagged for this company + subject
Company
Goldman Sachs
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 Goldman Sachs Java round.
Catch blocks are matched top-down. If a broader type comes first, narrower types are unreachable, causing a compile-time error.
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.
Exception translation means catching a low-level exception and throwing a higher-level, more meaningful one. It’s appropriate when moving across layers—for example, converting SQLException into a domain-specific DataAccessException. Preserve the cause using the constructor so the original stack trace remains available.
TreeMap uses natural ordering or a comparator; null keys cannot be compared and thus are not supported. Null values are allowed.
ReentrantLock provides advanced features: timed/interruptible acquisition, optional fairness, and separate Lock/Condition objects. Performance depends on the workload; it’s not universally faster.
volatile guarantees visibility and ordering for a single variable: writes by one thread become visible to others, and reads/writes are not reordered across that variable. It does NOT make compound actions atomic (like ++), nor does it protect invariants across multiple variables. Use locks or atomics for atomicity and compound state changes.
`distinct` tracks seen elements to remove duplicates, requiring state. `sorted` is also stateful. `filter`, `map`, and `peek` are stateless.
ReentrantLock supports tryLock (with or without timeout) and lockInterruptibly, plus optional fairness policy at construction. It does not inherently prevent deadlocks.
Default Java object serialization activates when a class implements Serializable. You can customize via writeObject/readObject, but the marker interface is the trigger.