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:
- Unix (like in the CS accounts)
- Windows command prompt (DOS prompt)
- Mac OS X Terminal prompt (which uses Unix)
Using the javac command
Using the java command
Working in a CS account on linprog
- Everybody enrolled in this course is allowed to sign up for a
temporary Computer Science department account. Instructions are here:
- You'll want to download SSH software for this, if you don't already
have it. See the account info page for download link
- Once you register for an account, you should log into
linprog.cs.fsu.edu if you want to use the SDK tools from your CS
account login. linprog has the latest Java SDK installed
- This machine is running Linux, so you would need to be familiar with
basic unix commands (like creating files, directories, moving around,
etc). Bob Myers created a basic unix tutorial here, which has just enough to
show you how to get around:
- This environment is fine for console applications. It will not be as
good when we get to GUI applications (although can be done through
tunnelling)
Working on a Windows PC on the command line
- Select "Start", then "Run", then type "cmd", to open a command
prompt
- Use "cd" command to change directories (similar to unix command)
- Use "dir" to see a directory listing
- Use javac and java commands as illustrated
earlier
- Recommend using a Windows-based text-editor to actually edit the
files. Wordpad is fine for this purpose.
- You will probably need to set the "PATH" variable. See below
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...
- 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
- From the Start menu, right-click "My Computer", and pick
"Properties"
- Click the "Advanced" tab
- Click the "Environment Variables" button
- 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"
- 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
- 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
- Changes won't apply until you close the "cmd" prompt and launch it
again