To run Java in your machine you have to install Java Development Kit (JDK). You can download JDK and NetBeans fom this link .
And we have to set the Java bin path to the path-variable.
1st Step :
C Drive -> Program Files -> Java -> jdk -> bin-> copy the path .
(when you click on the bar with the folder icon which contains the folder path you can copy the path)
2nd Step :
Computer -> Properties -> Advanced system settings -> Environment variables... -> select 'path' variable in System variables -> Edit... -> type a semicolon(;) and paste the path and then type a backslash(\) ->OK
Now let's write our first code.
1. Type this code in your text editor.
The method is declared inside a class. When we run a Java code ,the main method body will be to execute from top to bottom. We can't run a Java code without the main method, but we can compile without the main method. In run time it seeks the main method.
File -> Save As... -> File name : MyFirstJavaProgram.java -> Save
Save as type: All Files
The name of the source file should be our class name with .java file extension.
3. Open the Command prompt and go to the place where you have saved your source file.
Shift + Right click -> Open command window here
4. type javac MyFirstJavaProgram.java in the command prompt and press enter.
If there aren't any errors it will move onto the next line.
When we type our file name (class name) with .java extension in front of javac command we can compile our code. In our text editor we can see our code in a human readable format. When we compile the code, a class file will be automatically generated and it is in computer readable format. If you go to the place where you have saved your source file you can see MyFirstJavaProgram.class file.
If there aren't any errors the output will be displayed.
When we type our file name(class name) with the java command and press enter we can run our code.
Now let's see how to use NetBeans I.D.E. to run our first program.
1. Main Menu -> Run -> Build Project
2.Use f11 keyboard short cut.
Here we have several ways to run a program also.
1. Main Menu -> Run -> Run Project
2.Use f6 keyboard short cut.
by Dinuka Jayaweera