Mark Stephens Mark has been working with Java and PDF since 1999 and is a big NetBeans fan. He enjoys speaking at conferences. He has an MA in Medieval History and a passion for reading.

Are you a Java Developer working with PDF files?

Find out why you should be using JPedal

How to find deprecated methods in Java

1 min read

Java icon

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

deprecated methods warning

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!



Our software libraries allow you to

Convert PDF to HTML in Java
Convert PDF Forms to HTML5 in Java
Convert PDF Documents to an image in Java
Work with PDF Documents in Java
Read and Write AVIF, HEIC, WEBP and other image formats
Mark Stephens Mark has been working with Java and PDF since 1999 and is a big NetBeans fan. He enjoys speaking at conferences. He has an MA in Medieval History and a passion for reading.