Java / Java 21 Interview Questions
What major APIs were removed between Java 17 and Java 21?
Java 21 continues the cleanup of APIs that were deprecated in earlier releases. Understanding what was removed helps interviewers assess whether a candidate's Java knowledge is current.
| API/Feature | Deprecated | Removed | Replacement |
|---|---|---|---|
| Security Manager | Java 17 | Java 21 (JEP 411 warning) | OS-level security / security frameworks |
| Applet API | Java 9 | Java 23 target; Java 17 deprecated for removal | Web technologies |
| Thread.stop/suspend/resume | Java 1.2 | Not yet; flagged deprecated for removal | Cooperative interruption |
| finalize() | Java 9 | Java 18 (JEP 421 deprecated) | Cleaner API / try-with-resources |
| RMI Activation | Java 15 | Java 17 | Direct RMI or gRPC |
| Experimental AOT/JIT (Graal) | N/A | Java 17 | GraalVM as separate product |
| CMS Garbage Collector | Java 9 | Java 14 | G1, ZGC, Shenandoah |
// finalize() — use Cleaner instead (Java 9+)
// Old pattern:
class OldResource {
@Override protected void finalize() { /* cleanup */ } // unreliable, deprecated
}
// Modern pattern:
class ManagedResource implements AutoCloseable {
private static final Cleaner CLEANER = Cleaner.create();
private final Cleaner.Cleanable cleanable;
ManagedResource() {
cleanable = CLEANER.register(this, new CleanupAction());
}
@Override public void close() { cleanable.clean(); }
static class CleanupAction implements Runnable {
@Override public void run() { /* release native resource */ }
}
}
// SecurityManager — Java 17 deprecated, Java 21 warns, will be removed
// If your code calls System.setSecurityManager() → update now
// Migration: use OS-level security, module system, or third-party frameworksThe finalize() deprecation is particularly important: it was unreliable (not guaranteed to run, can be called on a different thread, delays GC), and caused memory leaks. The Cleaner API provides a reliable, predictable cleanup mechanism without the pitfalls of finalisation.
Invest now in Acorns!!! 🚀
Join Acorns and get your $5 bonus!
Acorns is a micro-investing app that automatically invests your "spare change" from daily purchases into diversified, expert-built portfolios of ETFs. It is designed for beginners, allowing you to start investing with as little as $5. The service automates saving and investing. Disclosure: I may receive a referral bonus.
Invest now!!! Get Free equity stock (US, UK only)!
Use Robinhood app to invest in stocks. It is safe and secure. Use the Referral link to claim your free stock when you sign up!.
The Robinhood app makes it easy to trade stocks, crypto and more.
Webull! Receive free stock by signing up using the link: Webull signup.
More Related questions...
