Mac OSX:
In /Work folder:
mkdir -p src build/classes # program name(included package): com.happysuo.test.Test.java cd src; mkdir -p com/happysuo/test # save .java file to com/happysuo/test folder javac -sourcepath src -d build/classes src/com/happysuo/test/Test.java java -cp build.classes com.happysuo.test.Test
This is anormal workflow of compiling and running java file:
package com.happysuo.test; import java.util.*; public class Test { public static void main(String[] args) { System.out.println("This is Test.java"); } }