Assuming test.java does not have a package statement, your class (which should be named Test, not test) is in the unnamed package, so do this:
javac 'path/to/test.java'
java -cp 'path/to' test
If your test.java file starts with a package to; statement, then you do this:
java -cp 'path' to.test
And if it says package path.to;, then you do this:
java path.to.test
or this to be explicit:
java -cp . path.to.test
If your package statement says any other name, then your directory structure is wrong, since the directory must match the package statement, starting at the directory named in the classpath (-cp).
path/to/Test.javaneeds to be relative to a sourcepath. Thejavacommand doesn't take a path, it takes a fully-qualified class name - periods, not slashes. It is relative to a classpath. (And the class name should start with an upper-case letter.) docs.oracle.com/javase/8/docs/technotes/tools/windows/… docs.oracle.com/javase/8/docs/technotes/tools/unix/…