How to specify a different directory for your compiled bytecode classes

Use the -d option if  want to specify explicitly where you would like the compiled bytecode class files to go:

$ pwd
/tmp/src

$ ls
HelloWorld.java

$ ls /tmp/classes

$ javac -d /tmp/classes HelloWorld.java

$ ls
HelloWorld.java

$ ls /tmp/classes
HelloWorld.class

$ java -cp /tmp/classes HelloWorld
Hello, World