Java Shell Commands: javac java jar javadoc

By Xah Lee. Date: . Last updated: .


The purposes of these tools are:

Type man javac to read its manual page.

Following are examples of using these commands.

Compile Java File

javac → compile a source code file “”. It will generate a file named “Aa.class”. That's the compiled file.

Note: by convention, Java class file name starts with capital letter.

Run Java File

java Aa → run the class file “Aa.class”, starting with the class's method named “main”. (Note: do not add the “.class” suffix in the command line.)

Note: Class name and its corresponding file name have a sameness relation enfored by Java. Each file has class, and the class name is the same as file name (without the “.class” suffix.)

[see Java: Package]

java ff/Aa → run the class file “Aa.class” in directory “ff”.

Note: directory represents a package. A package name has a directory of the same name, and is enforced by Java. So, a package “hh” will be in directory “hh”, and a package “hh.ii” will be in directory “hh/ii”, etc. In the directory, are class files.

java -cp classpaths class_name → run the program class_name, and search classes in classpaths. The classpaths can be relative to the current dir, and multiple class paths are separated by colon :. By default, java search class files in current directory. (and also by environment variable CLASSPATH)

java -jar jar_file_path → run the jar file.

Classpath can contain both compiled java class file or jar file.

# run a java program
# search class files in current directory and gg.jar
# start program with package hh and class Jj
java -cp .:gg.jar hh.Jj

jar files

Java: working with jar file


  1. Install
  2. javac java jar javadoc

Java Basics

  1. Print String
  2. Strings
  3. Power Function
  4. Java Types and Type Conversion
  5. Function
  6. Arrays

Class, Inheritance

  1. extends
  2. Constructor
  3. Constructor Return Type
  4. Extending a Class that has Explicit Constructors
  5. static
  6. this
  7. super
  8. Access Specifiers

Abstract class, Interface

  1. abstract
  2. Interface


  1. Package


  1. Collection, Map
  2. Read/Write File
  3. Convert File Encoding
  4. Complex Numbers in Java
  5. Unicode
  6. Number Literals