+3  A: 
  1. It would be better to add javac to your PATH environment variable instead of putting the .java files into the same directory with it. It'll get awfully crowded in there.
  2. To run, you just need

    java Main

    instead of putting every class on the command line.

  3. Did you declare a package in your .java files? Like,

    package myjava;

    ? If so, the command string must be

    java myjava.Main

Does that answer your questions?

Michael Myers
A: 

Follow these steps (code examples are just examples, you will need to tweak some for your setup):

  1. Set your JAVA_HOME to the directory where the JDK is installed.

    set JAVA_HOME="c:\Program Files\Java\jre1.6.0_12"

  2. Set your PATH to include the bin directory in JAVA_HOME.

    set PATH=%PATH%:%JAVA_HOME%\bin

  3. Change to the root directory of your source code. If you have declared your code to be in packages, this is the root directory of your package structure. If not, this is the directory that contains your .java files:

    cd c:\My\Source\Directory

  4. Execute javac with your Java files as the argument:

    javac Class1.java Class2.java

  5. (Assuming everything compiles correctly) Execute java with the name of the class containing your main method as the argument (if you included package declarations, then your class name is fully-qualified, meaning it should include the package name before the class name, with a '.' separating the package name from the class name):

    java Main

Jared
As Java Home's use may conflict with other tools, I'd recommend setting the JRE into the path directly rather than using Java Home. For instance, that Java home won't work with Maven, because it assumes Java Home is the JDK root path...
MetroidFan2002
If you don't set JAVA_HOME in the control panel, but just in your local shell, it won't effect anything else.
Jared
+4  A: 

The best way to do it is this:

1) create a directory with src\ and tests\ in it (the tests is optional if you are not using JUnit).

2) assuming you have "package myjava;" at the top of your files (and make sure that this is what your prof wants, it becomes a pain to mark things if they are not in the right place), make a src\myjava directory (and if you are doing junit a tests\myjava directory).

3) copy your files into the src\myjava directory

4) delete your NetBeans project and recreate it as a new on with exising sources. When you are setting up the src (and optional test) directories add the src\ (and optionally the tests) directory. DO NOT add the src\myjava directory or it won't work in NetBeans.

5) make a directory called classes\ (so you you have src\ classes\, and maybe \tests all in the same place)

6) on the command line type javac -d classes -cp classes src/myjava/*.java

  • -d tells the compiler where to put the .class files
  • -cp tells the compiler where to look for classfiles
  • src/myjava/*.java tells it to compile all of the .java files in src/myjava

7) run it via java -cp classes myjava.Main

  • -cp classes tells it to look in the classes directory for the .class files
  • myjava.Main is the name of the class to run
TofuBeer