To write the Hello World Application you will need the following:
The latest release of the Java SE Development Kit. If you don't already have it, you can download it Here
Other then that, all you need is a basic text editor, such as notepad.
About the Application and what you will be Required to do:
The application you will create will simply display the words "Hello world!" in the CMD Window.
There are Three steps:
Create Source File
(The code, written in JavaScript)
Compile the Source File into a .Class file
You will use a Java language compiler supplied in The Java SE Developement kit to translate the code into instructions (Bytecodes).
Run the Program!
If you don't get this one, your an idiot.
The First step:
(Creating the Source File)
1. Open your text editor. (EG. Notepad) And in a new document type (Or Copy and Paste, like the lazy a*** you are) the following piece of coding:
- Code:
/**
* The HelloWorldApp class implements an application that
* simply prints "Hello World!" to standard output.
*/
class HelloWorldApp {
public static void main(String[] args) {
System.out.println("Hello World!"); // Display the string.
}
}
Note: Type everything as shown, or you'll regret it. Java is case sensitive, and mis-spelling something is obviously going to be a problem.
2. Save the code with the following name: HelloWorldApp.java. (overwrite the default save-as name, the whole thing)
Once Saved, remember where you saved it and close the editor.
The Second Step!
(Compiling the Source File)
1. Bring up a shell, or CMD window. If your such a dumbass as to not even know wth that is,
Go to Start>Run and type 'cmd' (Windows XP)
OR
Start and type cmd, then click on the only search result (Windows Vista)
When you open it it should be in your computers home directory.
2. To compile the Source File we will need to manuever to the location you stored your HelloWorldApp.java file in. To do this, type in: cd 'file location'
(eg. cd 'C:\Java' if you saved it under C:\Java)
The prompt should now change to the location of your saved file.
Now type 'dir' and press enter, you should see your file, as well as a tonne of mumbo-jumbo about it. You know know you are in the right directory.
3. Now you should be ready to compile the file. (Hey! That rhymes...)
Type the following into the command prompt: javac HelloWorldApp.java
The compiler (javac) has generated a bytecode files which should be named 'HelloWorldApp.class'. To see this, type dir again and look for a .class file.
If you get the following error message: ''javac' is not recognized as an internal or external command, operable program or batch file' Windows cannot find the compiler. It get's a little tricky here. If this occured refer to the end of my tutorial.
Step Three!!
(The final step)
In the same directory, after you have filed the .class file type the following to execute your program: java HelloWorldApp
The program prints 'Hello World!' To the screen.
You may now bathe in chocolate, your program works!
If it doesn't please tell me any Problems you have encountered.
******************
''javac' is not recognized as an internal or external command, operable program or batch file'
As said before, windows can't find the compiler (javac). This could be one of two reasons.
1. Your download of the SE Developement kit failed, and you were the victem. Before you try to download it again, check the following directory and look for an .EXE file named 'javac'
C:\Program Files\Java\jdk1.6.0_11\bin (this is default location of the download, for the love of god I hope you didn't screw with it)
If you can the file 'Javac' Refer to the 2nd possible reason. If not, try reinstalling The Java Developement Kit.
2. This one is the fun one. You have the .EXE file but your computer is a dumbass and doesn't know where it is. In this case we will have to tell it where to find it by adding a User and System Variable. Follow the following instructions carefully.
Click Start > Control Panel > System (On XP)
Click Advanced > Environment Variables
Create a new variable in User variables and add the location of the Bin folder where the Javac file is located (Typically C:\Program Files\Java\jdk1.6.0_11\bin) in 'Value' and put 'Javac' in 'Name'
Now down to System Variables.
In system variables scroll around until you find a variable called 'PATH'. Click on it, then click on edit. These are all the adresses of the variables in user variables, it tells the system just where to find them. As you can see the adresses are sperated by semicolons, we will be adding a new adress, so go to the end of the list and put a semicolon in, then the location of Javac (Typically C:\Program Files\Java\jdk1.6.0_11\bin) and press okay.
NOTE: There are NO Spaces in variables, so don't bother using them because it will screw everything up. If you used a space, delete it.
Okay, now you have added javac as a variable. Unfortunately new variables only affect the CMD windows opened after they have been made, so you will need to close the current prompt and repeat steps 2 and finally, proceed to step 3!
***********************
Wasn't that fun?
Last edited by z0mgwtfbbq? on Tue Feb 03, 2009 7:45 pm; edited 4 times in total (Reason for editing : Link fix.)
















» I request.... a new and better principle
» Hakz
» School Holidays Start!
» Post Boosting!
» Suggestestions
» Were Back Online!
» Music
» has anyone else had this problem?