Firstly download The Java SE Development Kit 6 (JDK 6) from this link.
Once you download and install the "JDK" (not just jre).
Open notepad and start writing your first java program as follows
class HelloWorld {
public static void main(String[] args)
{
System.out.println("Hello World!"); // Display the string on a new line.
System.out.println("- Nimish Prabhu");
}
}
You can try different texts instead of 'Hello World!'
Click File>Save As>HelloWorld.java
Now open Command Prompt
Firstly you will need to set path so that you can execute commands such as "javac", "java" etc to execute your java files.
You can set path as follows :
set path=C:\Program Files (x86)\Java\jdk1.6.0\binIn your case the path to the bin folder of JDK might be different so change the command accordingly and press enter
Now we will go the location where we saved the java file
In my case it is D:\Java
and compile the file you just made by using the following command
javac HelloWorld.javarun the file using following command
java HelloWorld
Heres what you will get :

In this method you will have to set path to your bin folder every time you run a java file, inorder to avoid that we can permanently set path to bin folder as follows :
FOR VISTA/WINDOWS 7
Right Click on My Computer and Click Properties
Click Advanced System Settings
CLick Environment Variables
Select Path under System Variables
Click Edit
Go to the end of the text and add
;C:\Program Files (x86)\Java\jdk1.6.0\bin
(It will be different for you, depending on the location of your jdk bin folder)
Click Ok 3 times and Reopen Command Prompt
Now you can compile and run java programs as explained above.

------------------------------------------
Setting Path on Windows XP :
Start -> Control Panel -> System -> Advanced
Click on Environment Variables, under System Variables, find PATH, and click on it.
In the Edit windows, modify PATH by adding the location of the class to the value for PATH. If you do not have the item PATH, you may select to add a new variable and add PATH as the name and the location of the class as the value.
Close the window.
Reopen Command prompt window, and run your java code.
0 comments:
Post a Comment