-
Nov 9th, 2007, 03:58 PM
#1
Thread Starter
Member
CMD to run a java program
i have tried to set up the cmd to run java programs by doing this:
how to output 'Hello World'.
So I will show you how to do it in java.
Before we actually begin the programming you will need to set up your computer up to compile Java. To do this you must download the latest Java Runtime Environment which can be found here
After you have downloaded and installed the software, You will need to add some system variables. To do this go Control Panel > System and click on the Advanced tab. At the bottom you will see a button called 'Environment Variables', Click it.
In the top box you will need to add a new variable, so click New and enter these details:
Variable name: lib
Variable value: C:\Program Files\Java\jre\lib
Now click ok and create a new variable and enter these details:
Variable name: PATH
Variable value: C:\Program Files\Java\bin;C:\Program Files\Java\jre\bin
Click ok. Only one more to add, but this time on the bottom box:
Variable name: CLASSPATH
Variable value: C:\Documents and Settings\User\My Documents\Source (This can be anywhere, it's where you'll store your .java files)
Also it will be easier for you later, if you go to C:\WINDOWS\system32 and copy and paste the file cmd (which is dos prompt) and paste it into your CLASSPATH directory which you defined earlier.
Ok, now thats out of the way, we can get down to some Java Programming!
STEP 1
Open your favourite text editor and type the following:
class HelloWorld {
public static void main (String args[]) {
System.out.println("Hello World!");
}
}
Now Save the file as HelloWorld.java file (if your notepad make sure All Files is selected). Another point is that the name of the file has to be the same as the class name for it to work.
STEP 2
Now go to your CLASSPATH directory and load cmd.exe. Then type: javac HelloWorld.java
Wait until it has completed. That has now saved a .class file along woth your java file. To run the file type: java HelloWorld
the results should appear in the cmd box http://tymononline.co.uk/?section=tu...tut=helloworld
And thats it, you have successfully written some java!
but it gives me an error "The system cannot find message text for message number 0x2350in the message file for application. can someone please help me thanks.
Posting Permissions
- You may not post new threads
- You may not post replies
- You may not post attachments
- You may not edit your posts
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|