Get started Bring yourself up to speed with our introductory content.

Java command-line interface tools every JDK developer should know

In the world of IDE-based development, programmers can easily become detached from JDK and the underlying technology that makes their applications work. Here is a list of the five most useful Java command-line tools that developers need to master to become productive members of their teams.

1. The Java compiler: javac

The javac utility is the most important command-line interface (CLI) tool you will find in the JDK's bin directory. This is the Java compiler, and whether you use Maven, Gradle, the SpringSource IDE or Jenkins CI, it's this JDK tool that's used under the covers when Java source code gets compiled.

But why does a developer need to know the javac command-line program if all of the popular build frameworks just abstract its use away? Well, when difficult-to-diagnose problems occur within a project's build and deployment pipelines, troubleshooting begins with the most basic components in the toolchain, and that's quite often the point at which your code is compiled. When builds go sideways, developers often need to put aside all of their fancy packaging and deployment tools and revert to first principles. That means compiling code with JDK's javac utility.

The javac tool
Create bytecode with a Java command-line interface tool.

2. The Java profiler: javap

You can consider the Java command-line tool javap a complement to the javac utility. While javac compiles code, the javap utility reverses that compilation and provides information about a compiled class, such as the variable types it declares, along with the various methods and APIs it provides. The javap JDK tool doesn't completely return a compiled class into its original source code format, but it does provide insight on how the original source code was designed.

The javap command-line program can also be used to view the compiler version used to create the class file, which can be helpful for troubleshooting. Furthermore, the javap tool can show you the bytecode that the compiler created for the class and provide insight about how the component performs its logic.

javap CLI tool
The javap command-line interface tool decompiles Java bytecode.

3. The Java statistics aggregator: jstat

Do you run into a runtime problem with your application? Why not turn on the jstat utility?

Two of the most commonly tuned Java virtual machine (JVM) parameters are the heap size and the Java Runtime Environment's (JRE) garbage collection algorithm. This statistics monitoring Java CLI tool provides class loader metrics, insights on how the just-in-time compiler works and, most importantly of all, data on how often garbage collection occurs. With these statistics in hand, you can make informed decisions about how to configure the JVM for optimum performance.

4. The Java dependency manager: jdeps

With Java 12, any code base that references internal APIs will not be allowed to compile. In the near future, even linking to a compiled component that references an internal API will trigger a build fail. If you want to know if any of your existing code uses or references an internal Java API, the jdeps Java CLI application will tell you. Also, if it does identify a reference to an internal API in your source code, it will often have suggestions about a newer, preferable API that you can use to replace the bad one.

5. The Java archive utility: jar

There's nothing particularly magical about the creation of a compressed archive file, which is the main purpose of the Java jar utility. But there are other features of this Java command-line tool that can be helpful as well. Along with the ability to create a compressed zip file, the jar utility can be used to specify the entry point for executable or embedded JAR files, configure options to be used when run on JRE and even log the internal contents of a JAR file. Jar can be useful when you want to compare one version of a code release to another. And, of course, along with the ability to compress files, the JDK tool jar can be used to extract the contents of an archive file as well.

There are a variety of other interesting Java command-line interface tools packaged within the bin directory of JDK, and it is in the best interest of every Java developer to investigate them and explore their utilities. But these aforementioned Java command-line tools -- namely, javac, javap, jstat, jdeps and jar -- are the five that serious software developers need to know.

View All Videos

Join the conversation

2 comments

Send me notifications when other members comment.

Please create a username to comment.

Which of the various Java command-line tools do you think are the most useful for software developers?
Cancel
Java includes a number of tools that can be used to monitor applications and this article will help us to understand that. Looking forward to read such more articles in future .
Cancel

-ADS BY GOOGLE

SearchCloudApplications

SearchSoftwareQuality

SearchHRSoftware

SearchSAP

SearchERP

DevOpsAgenda

Close