Understanding javac, java and jar tools in JDK
- Details
- Written by Nam Ha Minh
- Last Updated on 08 November 2021   |   Print Email
- Java compiler: javac
- Java application launcher: java
- Java archive tool: jar
1. Java compiler and Java application launcher
When you are using an editor or an IDE (Integrated Development Environment) like Sublime or NetBeans to develop Java applications, the editor/IDE invokes the java compiler (javac.exe) to compile the source files (.java) and calls the Java launcher (java.exe) to run the compiled files (.class). The following picture illustrates this process:
- Compile: javac HelloWorld.java
- Run: java HelloWorld
2. The Java archive tool
Besides javac and java, there’s another one in JDK which is also an important tool in Java programming. It is the Java Archive tool - hence the jar name for its executable file.Typically, jar is one of the tools that participate in the process of building a Java application, as shown in the following picture:
Painter.java, Shape.java, and Canvas.javaUsing the javac tool, you compile these .java files into the following .class files:
Painter.class, Shape.class and Canvas.classThen type the following command to put all these .class files into a single file named Painter.jar:
jar cf Painter.jar Painter.class Shape.class Canvas.classThe result is a jar file created: Painter.jarThe following picture illustrates the content of this jar file:

java -jar Painter.jarType jar -help to see all available options for this tool.For full syntax description, check the following official documentation from Oracle:
http://docs.oracle.com/javase/8/docs/technotes/tools/windows/jar.html
Over the years, I compile my experiences with this tool in the following article:You can find useful and practical examples about using the jartool in this article.Here are some key points regarding the Java archive tool:- Java libraries and applications are packed in jar files.
- A jar file is actually a Zip file. That means you can use any archive tools such as WinZip, WinRar, 7-Zip,… to view and extract content of a jar file.
- The jar tool provided by JDK is a command-line program that allows us to create, view and extract jar files.
- You can use the jar tool to extract a zip file or compress a file to zip format.
3. Conclusion
When you are working with the editor or IDE, they do all the interactions with javac, java and jar to hide the complex details and increase productivity.That’s good! You can build Java applications without manually touching these tools. However, from my experience, I recommend you to study and play with these tools because of the following benefits:- You understand the nuts and bolts of Java, which gives you experiences to solve problems related to compilation and execution of Java programs.
- You equip yourself with skills of working with or without IDEs. Sometimes, working directly with javac, java and jar saves you a lot of time than using an IDE, hence increasing your productivity.
- You have more control over Java programming, e.g. you can easily work with various tools that rely on javac, java and jar such as Ant, Maven, Gradle, etc.
- javac command examples
- java command examples
- Java jar command examples
- Java serialver command examples
- The Java Shell (jshell) Tutorial
- How to compile, package and run a Java program using command-line tools (javac, jar and java)
About the Author:

Comments