## Java Summary: DOS Commands

Before Windows, there was the ugly, command line oriented Disk Operating System (DOS). if you're using Sun's JDK (SDK), you might use DOS to compile and execute your Java programs, or to run one of the Sun Java utilities. You can start a DOS window with Start menu, Programs, Accessories, Command Prompt.

## Command Summary

Abbreviations: f - file name or path, dir - directory name or path, r - drive. Case doesn't matter to DOS, but it does matter to java. CON is the console. \ is the name of the root directory on a drive.

CLS | Clear screen
EXIT | Exit from DOS
DIR | Prints the current directory.
DIR /O | Prints the current directory, sorted by file name.
DIR /P | Prints the current directory one screenful ("page") at a time. Useful when there too many files for one screen.
f | Entering a filename executes the program in that file It should have an extension of .EXE or .BAT (or a few others).
r: | Change to drive r. Eg, A: changes to the floppy disk.
CD dir | Make d the current directory. (CD is same as CHDIR)
CD .. | Move up one directory
CD \ | Move to root directory on the current drive.
MKDIR dir | Create a new directory
RMDIR dir | Delete (remove) directory d, which must be empty first.
COPY f dir | Makes a copy of the file f in directory d.
COPY f1 f2 | Makes a copy of the file f1 and names it f2.
REN f1 f2 | Renames the file f1 as f2. (Same as REN)
DEL f | Deletes the file f.
TYPE f | Copies the file f to the console screen.
MOVE f1 f2 | Copies file and deletes original. Supports wildcards.

## Java related commands

Setting up Sun's JDK/SDK may require changing the PATH and CLASSPATH environment variables. In addition, there are many utilities that can be run from the DOS command line.

APPLETVIEWER f | Runs the appletviewer. f can be any file containing an `<applet code="..." width="..." height="...">` tag.
JAVAC F.java | Compile the java source file and write the object code into a .class file. f must have an extension of .java
JAVA F | Run the Java file in F. F is the name of the .class file that contains a main method, but without the .class extension.
JAVAW -jar f.jar | Runs a program in the jar file, if it's set up for that.
JAR -xf f.jar | Unpacks jar file into current directory.
SET CLASSPATH=... | Java needs to know where packages and classes are located. To use additional classes, set this to the .jar file or directory containing the desired classes. For example, here is how my classpath is set: `SET CLASSPATH=.;C:\javaclasses;C:\javaclasses\jakarta-regexp-1.1.jar;` This sets the class path to . ("dot" is the current directory - you should always specify this if you do anything with classpath), the name of the directory C:\javaclasses that might have directories and classes in it, and a jar (Java Archive) file.
PATH | Shows current DOS search path for executable programs/commands.
PATH pathlist | Sets path to list of paths, separated by semicolons. Use %PATH% for current value.
SET | Shows current settings of environment variables (PATH, etc).

## Redirection

You can put the output from a command or program into a file but using redirection on the command line.
> appends the data to a file.
>> empties (creating if necessary) the file.

       java MyProgram >> results.txt

## Useful programs

doskey | If you can't use the up-arrow key to get previous commands, this program will activate that feature.
ipconfig /all | Shows your IP settings.
ping ip or hostname | Tells time to reach another machine
tracert ip or hostname | Tells time to each hop to another machine