Skip to main content

Running a Java Program from Command Prompt

Running a Java Program from Command Prompt

  • Create a temporary folder C:\mywork.  Using Notepad or another text editor, create a small Java file HelloWorld.java with the following text:
    public class HelloWorld
    {
      public static void main(String[] args)
      {
        System.out.println("Hello, World!");
      }
    }
    Save your file as HelloWorld.java in C:\mywork.  To make sure your file name isHeloWorld.java, (not HelloWorld.java.txt), first choose "Save as file type:" All files, then type in the file name HelloWorld.java.
  • Run Command Prompt (found under All Programs/Accessories in the Start menu).  Type
    C:\> cd \mywork
    This makes C:\mywork the current directory.
    C:\mywork> dir
    This displays the directory contents.  You should see HelloWorld.java among the files.
    C:\mywork> set path=%path%;C:\Program Files\Java\jdk1.5.0_09\bin
    This tells the system where to find JDK programs.
    C:\mywork> javac HelloWorld.java
    This runs javac.exe, the compiler.  You should see nothing but the next system prompt...
    C:\mywork> dir
    javac has created the HelloWorld.class file.  You should see HelloWorld.java andHelloWorld.class among the files.
    C:\mywork> java HelloWorld
    This runs the Java interpreter.  You should see the program output:
    Hello, World!
    If the system cannot find javac, check the set path command.  If javac runs but you get errors, check your Java text.  If the program compiles but you get an exception, check the spelling and capitalization in the file name and the class name and the java HelloWorld command.  Java is case-sensitive!
  • It is possible to make the path setting permanent but you have to be very careful because your system might crash if you make a mistake. Proceed with extreme caution!In Windows XP, go to Control Panel, choose "System," click on the "Advanced" tab, click on the "Environment variables" button. In the lower list, "System variables," click on Path:

    Click "Edit" and at the end append
    ;C:\Program Files\Java\jdk1.5.0_09\bin
    (or the path to the appropriate folder where the latest version of JDK is installed).  Do not put spaces before the appended path string.
    Click OK on the path edit box and OK on the Ennvironment Variables box.  The new setting will go into effect next time you run Command Prompt.

Comments

Popular posts from this blog

How to Create a MOTION TWEEN in MACROMEDIA FLASH

    If you are new to flash, and trying to animate, try this. Tweening is the easiest way to animate in the complicated world of Flash, and I have tried to show it simply. I am assuming that you are basically familiar with Flash's tools. This tutorial is intended for Windows PC & Adobe Flash 8. 1 1 Open Flash . If it is not on the start menu or on the desktop, you can find it on Computer at Boot drive\Program Files\Macromedia\Flash 8. 2 Draw a shape . This will be what you animate. 3 Select the shape you have created with the "Selection Tool" and press "CTRL + F8" . 4 The "Convert To Symbol" dialogue will appear, and you should select "Graphic" . You can name it, but that is not necessary. 5 Now click OK . 6 Go to the Timeline and click on frame 10 . 7 Now right click frame 10 and select "Insert F...