- Create a temporary folder
C:\mywork
. Using Notepad or another text editor, create a small Java fileHelloWorld.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
inC:\mywork
. To make sure your file name isHeloWorld.java
, (notHelloWorld.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 seeHelloWorld.java
among the files.C:\mywork> set path=%path%;C:\Program Files\Java\jdk1.6.0_21\bin
This tells the system where to find JDK programs.C:\mywork> javac HelloWorld.java
This runsjavac.exe
, the compiler. You should see nothing but the next system prompt...C:\mywork> dir
javac has created theHelloWorld.class
file. You should seeHelloWorld.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!
10/13/2010
Running a Java Program from Command Prompt
Subscribe to:
Post Comments (Atom)
Cara download Installer windows 10 dalam format ISO
1. Jika anda bercadang untuk download windows 10 melalui website rasmi windows - pilihan untuk download dalam format ISO tidak di berikan. ...
-
ANSWERS TO CHAPTER EXERCISES (CHAPTER 8) Review Questions 1. List and describe various types of output, including technolog...
-
Based on real life scenario on any local company/ organization which you are very familiar, define the problem that could be addressed thr...
-
A. Response to the following statements by circling either T (TRUE) or F (FALSE). [10M] I. 1. Java enables users...
No comments:
Post a Comment