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, this has changed. Oracle has removed methods in the JDK from Java9 onwards as part of the tidy up for Jigsaw.
So it is probably time to have a general strategy to move away from deprecated methods. So how do you identify where your code uses 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!
Did you know...
IDRsolutions offers a whole range of online file converters to convert PDF and Microsoft Excel, Word and Office Documents to HTML5, SVG or image formats?
It is free to use for single file conversions and also includes Developer links if you want to use our commercial software for bulk conversions. Find out more on this page