Java Reference ยท Language Features by Version
Deprecated and removed Java APIs
Reference for @Deprecated and forRemoval in Java: how deprecation works, which common APIs to stop using, and the modern replacements for each.
An API is deprecated when the JDK team recommends against using it: it may be dangerous, broken by design, superseded, or simply obsolete. Deprecation is a warning, not a removal; the API keeps working until it is removed in a later release. Java marks this with the @Deprecated annotation, which carries two optional elements: since (the release that deprecated it) and forRemoval (whether removal is planned).
Deprecated with forRemoval = true is the serious kind. The compiler reports a "removal warning" that you cannot silence with a plain @SuppressWarnings("deprecation"), and your code will break when the API disappears.
@Deprecated(since = "3.0", forRemoval = true) public void legacyExport() { ... }
Try it
Press Run (or Ctrl + Enter) to see the result here.
Program input ยท what you'd type while the program runs
Type the answers before you press Run, one per line. Each time the program reads a line (with IO.readln() or a Scanner), it gets the next line from this box.
Press Run (or Ctrl + Enter) to see the result here.
Program input ยท what you'd type while the program runs
Type the answers before you press Run, one per line. Each time the program reads a line (with IO.readln() or a Scanner), it gets the next line from this box.
Notable deprecations and removals
| API | Status | Use instead |
|---|---|---|
new Integer(...), new Long(...), new Boolean(...) and the other wrapper constructors |
Deprecated since 9 | Integer.valueOf(...), autoboxing |
Object.finalize(), System.runFinalization() |
Deprecated for removal since 18 | try-with-resources, Cleaner |
Thread.getId() |
Deprecated since 19 | Thread.threadId() |
Thread.stop() |
Deprecated for removal since 1.2; throws UnsupportedOperationException since 20 |
Interrupts, cooperative flags |
Thread.suspend(), resume() |
Removed | Locks and conditions |
new URL(String) and its siblings |
Deprecated since 20 | URI.create(...).toURL() |
new Locale(...) |
Deprecated since 19 | Locale.of(...), Locale.forLanguageTag(...) |
java.util.Date constructors and getters |
Deprecated since 1.1 | java.time |
Runtime.exec(String) |
Deprecated since 18 | ProcessBuilder or exec(String[]) |
SecurityManager |
Deprecated for removal in 17; permanently disabled in 24 | OS and container isolation |
Applet API (java.applet) |
Deprecated for removal since 17 | Web technologies |
| Nashorn JavaScript engine, Pack200 | Removed in 15 and 14 | GraalJS, other compressors |
Java EE and CORBA modules (java.xml.bind, java.corba, ...) |
Removed in 11 | Jakarta EE libraries |
sun.misc.Unsafe memory-access methods |
Deprecated for removal since 23 | VarHandle, foreign memory API |
Usage notes
- A deprecation warning says "please migrate"; a removal warning says "this will break". Treat the second as a bug to schedule.
- Compile with
-Xlint:deprecation(details) and-Xlint:removal(on by default) to see them.jdeprscanscans compiled classes and jars for use of deprecated JDK APIs. @SuppressWarnings("deprecation")hides ordinary deprecation warnings; use"removal"for the other kind.- Deprecating your own API: add
@Deprecated(since = "...")and the Javadoc tag@deprecatedthat explains the replacement. The annotation drives tools; the tag tells people. - Removal timelines are not fixed. Read the release notes of every JDK upgrade ("Removed APIs", "Deprecated APIs").
- Deprecation is never a reason to panic about old code that works; it is a reason not to start new code with it.