Compiling on the Command line with Java SDK

Primary SDK tools

The primary Java SDK tools, which can be accessed from a command prompt/shell, are:
  javac             // the compiler
  java              // loader/interpreter
Windows versions of these filenames would be:
  javac.exe
  java.exe
These commands (discussed below) will work in any of the following command-line prompts, as long as the SDK is installed:

Using the javac command

Using the java command

Working in a CS account on linprog

Working on a Windows PC on the command line

Setting the PATH environment variable

To run a program from the command line from any directory, you either have to type its full location and name every time (annoying) or set its location in your "PATH". To set the path...
  1. You'll need to know where your Java SDK was installed. Usually it goes (by default) into a folder like this:
      C:\Program Files\Java\jdk1.8.0_16
    
    Make sure you take note of the exact folder name and location
  2. From the Start menu, right-click "My Computer", and pick "Properties"
  3. Click the "Advanced" tab
  4. Click the "Environment Variables" button
  5. At the top of the window, where it says "User variables for ...." look to see if there is a "PATH" variable in the window. If there is, highlight it and click Edit. If there isn't, click "New"
  6. Make sure Variable name says, "PATH". Under "Variable value", add in the expression that matches where the java installation is, along with "\bin". Example:
      C:\Program Files\Java\jdk1.8.0_16\bin
    
  7. IF there's already something in the PATH variable, separate it from the new item (above) with a semi-colon. Example:
     C:\Program Files\SSH Communications Security\SSH Secure Shell;C:\Program Files\Java\jdk1.8.0_13\bin
    
  8. Changes won't apply until you close the "cmd" prompt and launch it again