Java javac

From wikinotes

javac is java's builtin compiler.

Install

You'll need to install a jdk to get javac.

sudo pacman -S jdk-openjdk       # archlinux
sudo apt-get install java-devel  # debian

Usage

single file example

class HelloWorld
{
    public static void main(String args[])
    {
        System.out.println("Hello World");
    }
}

compile .java file

javac hello_world.java
>> hello_world.class

run .class file

java hello_world.class
>>> 'Hello World'

multifile project


src/
    Conversation.java
    PrintHi.java
    PrintBye.java
class Conversation
{
    public static void main(String[] args)
    {
        PrintBye bye = new PrintBye();
        PrintHi hi = new PrintHi();
        hi.print();
        bye.print();
    }
}
class PrintHi
{
    public void print()
    {
        System.out.println("hi!");
    }
}
class PrintBye
{
    public void print()
    {
        System.out.println("bye!");
    }
}

build instructions:

cd yourproject/
javac src/* -d bin/
cd bin/
java Conversation