A Java deprecated method is one that should not be used because it is going to be removed (and often there is a better, more modern alternative). It is a correction to the API. In the past, Java did not remove any methods and kept backwards compatibility with everything.
But with the new modular and non-monolithic JDK from Java9 onwards, this has changed. Oracle has started to remove methods in the JDK as part of the tidy up for Jigsaw.
So it is probably time to have a general strategy to move away from deprecated methods.
How do you identify deprecated methods?
In previous versions of Java, messages would be displayed at compile time. Here are examples from IDEA and NetBeans IDE
This is now so familiar, my conscious mind just ignores it (and I suspect I am not the only one!).
From Java9 however, there is a new command line tool which will also give this information call jdeprscan. This has lots of interesting options to show deprecated methods. Running with default values shows the deprecated methods we use in our code:-
jdeprscan build-jpedal-1.0-SNAPSHOT.jar Jar file build-jpedal-1.0-SNAPSHOT.jar: class org/jpedal/examples/viewer/gui/swing/SwingMouseListener uses deprecated method java/awt/event/InputEvent::getModifiers()I class org/jpedal/objects/acroforms/creation/ListListener uses deprecated method javax/swing/JList::getSelectedValues()[Ljava/lang/Object; class org/jpedal/objects/acroforms/creation/SwingFormFactory uses deprecated method javax/swing/JList::getSelectedValues()[Ljava/lang/Object; class org/jpedal/examples/viewer/gui/swing/SwingMenuItems uses deprecated class java/awt/Event class org/jpedal/examples/viewer/gui/swing/AnnotationEditor$DragListener uses deprecated method java/awt/event/InputEvent::getModifiers()I
There some really interesting additional methods also such as -for-removal or -release which allow more precise details on the deprecated methods.
So an action for us to update these usages of deprecated methods with alternatives. And if you want to ensure your code continues to work cleanly on later versions of Java as well as Java8, now is the time to experiment with JDeprscan and update that old codebase!
Do you need to work with PDF or Image Files in Java?
|Convert PDF to HTML5 or SVG||Convert AcroForms and XFA to HTML5|
|Java PDF SDK for working with PDF files||Java Image SDK for working with Image files|