To do our Java programs we will need to use the DOS environment. More and more people have little or no experience with using the DOS operating system. This handout is intended to cover the minimum you need to understand about DOS for this course. Hopefully you will find it helpful. As you will see, some of the steps in this review assume that you have downloaded and/or stored your Java SDK (jdk) in a folder on your hard drive.
1. Finding DOS
Where you find DOS on your computer will depend on how you or your system administrator set up your computer. Unless you have a DOS icon on your desktop, your best bet is probably to go to Start on the Task bar at the bottom of your screen and select Programs and then select "MS-DOS Prompt". Click on it and you should get a DOS window.
2. DOS Window:
Once a DOS window is open, an icon menu bar will appear at the top. The third icon from the right is Properties. Check it out, especially the Screen tab. I would suggest that you have the Window and not the Full-screen selected. If you minimize the DOS window, an MS-DOS Prompt icon will appear on the Task bar. Try it. Right clicking on it produces a menu with Properties being one of the selections. Selecting Restore, or left-clicking on the Status bar icon, will restore the DOS window.
Inside the window will be a DOS prompt. So what do I do then?
Before answering that question, there are a few other things that you need to understand, but unfortunately each before the other. They include the DOS prompt itself, changing directories, executing DOS commands, changing drives and paths. So bear with me as you try to get all this under your belt. Let's start with the DOS prompt.
3. DOS Prompt and Changing Directories:
Again, depending on how your system is set up, there will be a default DOS prompt setting and a default directory that it is set to. OK, what does that mean? Well first of all, be aware that DOS calls folders directories, so that is what I'll do.
A common default DOS prompt setting is the path to a directory (more about paths shortly). A common default directory is the Windows directory, called WIN. (Be aware that DOS does not care about the case, upper or lower.) So this means that you might see C:\WIN>. The path is from C to the WIN directory, the default in this case. A better place for us to be is at the top of the file structure, called the root, with the prompt, C:\>. Let's go there, if you are not there. The quickest way is to get there is to enter cd \. You should now have the prompt, C:\>. Ah, so the prompt shows me where I am? Yes (if it is set to do that by the System administrator or you). If you really care to know more about the DOS prompt, read up on dosprompt under help when we get to it shortly.
Next let's take on changing directories, but before we do, use Windows Explorer and locate the path to some folder (where something is stored). For example you could locate the jdk1.2 folder where you saved the Java 1.2 SDK (System Development Kit) that you downloaded from the Sun Web page (see the handout, Guidance on Using Java). If you don't know where a folder is stored on your C drive, use Start and then Find. In our example, after finding the java1.2 folder, look in one of its folders called bin. See if bin contains java.exe, javac.exe and appletviewer.exe. Write down the full or "absolute" path name from the root, C:\ to bin. Mine would be: C:\ted\jdk1.2\bin, for example.
Return to the DOS window. In case you don't know it, you can use Alt Tab to move between open applications in Windows. Try it. You should have the DOS prompt, C:\>.
At the DOS prompt enter cd, for change directory, a space and the full or "absolute" path to the java.exe file that you wrote down, i.e. cd C:\ted\jdk1.2\bin. Your prompt should change to C:\ted\jdk1.2\bin>. When you get the correct prompt, enter dir, for directory. Try it. Does java.exe show up in the list of files? It should. OK, now you have mastered the DOS prompt and changing directories. Let's next take on executing DOS commands.
4. Executing commands:
We have used the DOS commands dir and cd
Entering dir, for example, will display the contents of a directory. If there are more than a screen full of files in the directory, you need to add /p, or dir /p, in order to make the screen pause with a screen full. As you can see, some commands take one or more arguments or options. cd also takes an argument. cd needed to know what directory. The directory is the argument or option, i.e. cd C:\ted\stuff.
Usually you need to leave a space between the command and the option, i.e. dir /p or cd C:\ted\stuff. However notice that earlier we entered cd\ and it worked, but so will cd \. We will see what seems like another exception when we change drives.
The only other DOS commands that you should need to use are /?, more, path, edit, doskey and exit. Their arguments/options will be explained as we go along.
5. Changing drives:
For historical reasons, the A drive is typically the floppy drive and C is the hard drive. Changing drives throws beginners off. Why? Because you just enter A: or a: at the DOS prompt to change your prompt to the floppy drive. Entering C: or c: will change you to the C hard drive. Note that there is no cd to change drives. Also be aware that these drive names can be different if you have multiple drives.
Before taking on path, let's review what help you can get from DOS. You will see why in a moment.
In Win95, click on Start then Help then select the Index tab. Enter "MS-DOS" in the window and select "MS-DOS commands, displaying help for
". Select Display. Review the explanation of using "/?" to obtain an explanation of a DOS command. Unfortunately in WIN 95 you must know the DOS commands. In NT, you can enter "help" at the DOS prompt, and get a list of all the DOS commands. Not so in Win95.
Return to the DOS window and at the DOS prompt enter a DOS command followed by " /?" Or, if you expect more than a screen full, also append a space and " | more ". The "|" is the pipe symbol and more is a DOS command. To "pipe through more" means to take the output from the DOS command, in this case "/?" and run it through the more command. The more command display one screen full at a time. OK, let's try out help on "more". Try "more /? | more".
Now that you have the big picture of DOS addressing, let's review path. Also, now that we understand how to find information about DOS commands, enter "path /? | more" at the DOS prompt. You should have discovered that the path entries tell DOS to search in the specified directories for commands that you enter.
Now enter "path" at the DOS prompt to see the path setting set by the System Administrator or yourself for your computer. Does a path to the bin directory, that contains java.exe, exist in your path (at home)?
If you saw SET PATH= C:\ted\jdk1.2\bin, it would mean that if we enter the Java command "javac" at the DOS prompt, DOS will look in the bin subdirectory of jdk1.2, which is stored in the ted directory under the root, agree? Hopefully it will find javac.exe there and the java compiler will run. Let's review how you can add a path. First, you need to understand your autoexec.bat file.
Autoexec.bat is a DOS batch file (.bat) which does the setup and some other tasks. Find your autoexec.bat using Win 95/NT Explorer or Find (hint: it should be in C:\ after all the folders). Note the path to it. Open Win95/NT Notepad and look at the file. Does it contain a path statement? It should be the same one you just looked at.
If you determine that you want to add to your autoexec.bat file, FIRST make a backup of the autoexec.bat file. Call it autoexec.bak or some suitable unused filename. Then use Notepad or DOS Edit and alter/amend the path. Save the changes. (See the Guidance on Using Java handout for an example). Note: You need to reboot in order to make changes to autoexec.bat last more than the current session.
Finally, we are almost done but I have saved the best for last. That is the Doskey.
Using doskey allows you to quickly access previous DOS entries. Let's try it. At the DOS prompt enter "doskey" (unless it is already loaded). Now press the up arrow. Press it again. Press the down arrow. What is happening? Press F7. It should display a short history of the previously entered commands, while up and down arrow displays just one. Ok, once you have a previous command, you can edit it.
By the way you can use the standard editing keys. For example Home takes you to the beginning and End takes you to the end of the command. Arrow keys move a letter at a time. The delete and insert keys will then edit at the specific position. Useful? Faster and more accurate than retyping the entire command? Review doskey with /?.
If you don't have it set on your computer at work, say in a networked system, you can enter doskey at the beginning of each use of DOS. However, the way to have it available all the time is to add it to your autoexec.bat. Again see the example in the handout, Guidance on Using Java.
The CLASSPATH variable is used by the Java Run Time Environment to find your class file. Add a CLASSPATH variable to your Autoexec.bat You should start the CLASSPATH variable with a reference to the local directory. SET CLASSPATH = .;%CLASSPATH% This will allow you to run a class file in your current directory.
To close the DOS window, enter "exit" at the DOS prompt.