How to Run Java Applications using the Windows Command by hcj


									How to Run Java Applications using the
    Windows Command Prompt.
             Julian Falasca
             May 11th, 2010
               ENGL 393
• Purpose: Most IS courses don’t touch this
• Target Audience: Students already familiar
  with Java programming. (CMSC and IS majors)
• When to Use: On the job.
• Safety Information: Don’t get too excited.
             Materials Needed
• At least 1 valid java source file.
   – Must know where this file is located.

• Java Development Kit (JDK) already installed.
                    Step 1
• Click on Start, Programs, Accessories, and
  select Command Prompt.
Example Command Prompt
                     Step 2
• This example uses a java file which is located:

• Type d: and press enter.
  – This command changes directories to the D drive.
Example Command Prompt
                     Step 3
• Type cd Workspace and press enter.
  – This takes you into the Workspace directory.
Example Command Prompt
                         Step 4
• Type dir and press enter.
• This displays a list of files in the current directory.
   – Confirm that is in the list.
Example Command Prompt
                       Step 5
• Type javac and press enter.
  – This compiles the file, allowing you to run it.
     • A new file has been created named HelloWorld.class.
Example Command Prompt
                      Step 6
• Type java HelloWorld and press enter.
  – The Java application will run.
Example Command Prompt
• Warranty Information: N/A
• Technical Support: Lookup commands on google.
• FAQs:
  – Why do I get the error “javac command not
     • Most likely you have not installed the JDK correctly.
  – How do I go to the previous directory?
     • Type cd .. and press enter.
                Conclusion Continued
         Problem                     Cause                      Solution
  When compiling you get    You typed javac HelloWorld You must include the file
 the following error: Class                            extension when compiling.
  names, ‘HelloWorld’, are                             Type javac
only accepted if annotation
   processing is explicitly
      When running the           You typed java          You cannot include the
   application you get the      HelloWorld.class        extension when running.
 following error: Exception                               Type java HelloWorld
      in thread “main”
  Error: HellowWorld/class

To top