Creating and Running a Java Program using JDK via DOS

* Create a file containing your JAVA source code using Notepad or Wordpad. Make sure that you save the file with a .java extension, or you will not be able to compile it.(If using Notepad, click the file type tab to display All Files when you save it, so that Notepad doesn’t append a .txt extension)

You will need to work in the MS-DOS window in order to translate and run your program. If there is not a shortcut on your desktop, select  Command Prompt from your choice of available programs.

---------------------------------

* If your source (.java) file is on a floppy disk, you should copy it to the hard drive at this point.   First move to the folder you want to work in. c:\temp is usually a good one. To move to a folder, use the cd command as follows:

cd c:\temp

The command line prompt should change to reflect the new folder you
are :

You can then copy the file from your floppy to this new location by using the DOS ‘copy’ command as follows:

copy YOURFILE c:temp\.

---------------------------------

* You must now compile your program into ‘byte code’. To do this type the following:

javac YOURCLASS.java

YOURCLASS must match the name of the public class in your file, and
the java extension must be present. If he command is not recognized by
DOS, then you do not have your path set properly and need to type the
full pathname when givng the javac command.

If you program compiles with no errors, you are ready to run it. Otherwise you need to minimize you DOS window, open the source file with Notepad, and fix any errors.

---------------------------------

* When your program compiles without any errors, a .class file is created.

You can execute this program using the JVM. To do this type:

java YOURCLASS

Make sure you do NOT type .java or .class when giving this command.

**If your program is comprised of a number of classes, using separate
files, you must compile all the files together on one command line, such
as:

javac YOURCLASS1.java YOURCLASS2.java

where YOURCLASS2.java is the file which contains the main method, and
uses a class in YOURCLASS1.

---------------------------------

* The program is then run by running the JVM with the class which contains
the main method:

java YOURCLASS2.java