del *.tmpwhich requires 10 keystrokes. There is a way to get the same effect using the Windows `Explorer' program, but it will take much longer.
However, the main reason for using the command prompt is to operate software that can only be used this way. This includes the Sun JDK tools. Remember that this software is designed for professional programmers; on the whole these people will not be put off by the need to use the command prompt.
Although it is not usual to do so, all Windows programs can be activated and, to a certain extent, controlled by the command prompt.
c:\windows> _
command_name argument1 argument2...The odd word `argument' is the term used for anything that is not a command name. The number of these arguments depends on the command; some require none at all, and some can accept a variable number. In most cases the arguments will be the names of the files that the command is to process. Note that command names and arguments are separated by spaces.
For example, the command
copy Prog1.java Prog1.java.bakMakes a copy of the file `Prog1.java' called `Prog1.java.bak'. Here `copy' is the command name, and the arguments are the two filenames. The prompt itself displays the current working directory. This is the directory in which commands will be looked for first, if no other information is given. In the example above, the command `copy' would look for the file `Prog1.java' in the current directory, whatever that happened to be. The file `prog1.java.bak' will be created in the current directory as well.
fred is not recognized as an internal or external command, not the name of a file on this systemor
Bad command or filenameThis message varies from system to system.
You can find the setting of the current path by typing the command
pathIt will display something like this:
C:\WINDOWS;C:\WINDOWS\COMMAND;C:\This means that the command prompt will first look in the directory C:\WINDOWS, then in C:\WINDOWS\COMMAND, then in C:\. You can change the path by typing
path=[something]but this change will only last while the command prompt is running. If you start a new command prompt the path will be reset to its original value. If you want to make a permanent change to the path you need to edit the system configuation or start-up files. This process is explained in how to set up the Sun JDK. If you have installed the JDK tools correctly, the path should display the directory where the JDK program files are installed, something like this:
C:\WINDOWS;C:\WINDOWS\COMMAND;C:\;C:\JDK1.2.2\BINIf I type
notepadat the prompt, it will start the Windows Notepad program, because it finds the program `notepad.exe' in the directory C:\WINDOWS.
cd directory_nameIf the directory names starts with the character `/', this indicates that the directory is specified from the top level directory of the current drive. For example,
cd \windowswill change to the directory `windows' which is at the top level. The comamnd
cd week1will change to the directory `week1', which is assumed to be a sub-directory of the current directory (whatever that happens to be). After executing the command, the prompt wil change to show the new current directory.
To change between disk drives, rather than directories, use the command
X:where X is replaced with the letter of the drive you want. On some systems you can use `cd' to do this as well.
Note that `cd' does not create or otherwise modify any directories or files; it merely changes the location where subsequent commands will look for files.
md directory_nameThe same considerations apply here as for `cd': if the directory name starts with a `\' is is relative to the top level directory, otherwise it is a subdirectory of the current directory. To create a new directory and then change to that directory, use
md directory_name cd directory_nameAll subsequent commands will look for files in your new directory. Note that this operation is almost the same as selecting `New, Folder' in the Explorer program, then clicking on the name of the new directory.
A directory can be deleted using the command
rd directory_namebut it will only work on directories that contain no files.
dirNote that this is more authoratative than the file listings in Explorer, because the dir command will show filenames exactly. It will not hide file extensions nor hide files whose names end in `dll' nor any of the other daft things that Explorer does (you can stop Explorer doing this as well, and if you are programming you should certainly find out how to do this).
Files can be deleted with the command
del fileNote that multiple files can be deleted in one go, by specifying a `*' as part of the filename. The * matches any part of a filename. So for example,
del *.javadeletes all files whose names end in `.java'. This is a powerful technique and needs to be used with caution:
del *deletes all files in the current directory. Do this in your \WINDOWS directory and you will need to re-install Windows, which is a drag.
There is no specific way to create files; this is the job of the software you are using. For example, to create a file `Test.java' using Notepad, enter
notepad test.javaThe file will be created in the current directory.
javac Test.javaThis will only work if (1) the file Test.java is in the current directory, and (2) the JDK tools have been set up correctly. In the event of (1) not being true, you can use `cd' to change the working directory to wherever your Java program is stored. The compiler will produce one or more files whose names in `.class'. There will be one for each Java class defined in the program. Note that the input to `javac' is a filename (or several filenames).
To run a Java program that is a stand-alone application, enter
java class_namewhere class_name is replaced by the name of the class that contains the `main' method. For example, if the program I compiled defined only one class, called `Test', I would enter
java TestNote that the Java tools are case-sensitive in filename. For example,
java Testis a different thing to
java testThis is because the Java language itself is case-sensitive. Most other commands are not case-sensitive, either in their own names or the names of the files they are operating on. This means that you can't have two files in the same directory whose names are `test.java' and `Test.java' as the system would not be able to tell them apart.
Unlike the other commands I have explained, `java' does not require a filename, but a class name. It is an error to enter
java Test.javaor even
java Test.classEven though it is Test.class that is actuall read by the `java' program.
To show a Java applet using the applet viewer, enter
appletviewer html_filewhere html_file is the name of the HTML file that loads the applet. This process is explained in more detail in how to use the JDK applet viewer.
command_name /?by displaying a summary of their operation, but this can be very daunting for non-specialists. On some systems, the command
helpdisplays a list of commands that are available.
©1994-2003 Kevin Boone, all rights reserved