In the previous post you learned How to Download and Install Java on your System, Now today in this post you will learn How to Compile and How to Run Java programs on your system.
In our previous post we also post How to Program in Java Language, so you learned most of the basics of java. Now here start creating a Simple java program “HelloWorld” .
Step-1 . Open any text editor or you can use Notepad to write java programs. and now write down the following java program.
class HelloWorld
{
public static void main (String args[])
{
System.out.println("Hello World!");
}
}
Step-2. Save this program as HelloWorld.java
Step-3. Now you created the java HelloWorld Program. Now you have to compile this program and after successful compile you can run this program.
To compile this program open command prompt. Goto START—> RUN—> and type cmd and hit Enter
Step-4. Now navigate to the folder where your program file is saved. In our case it is c: drive
Step-5. Now compile the program type the following command to compile java program
javac HelloWorld.java
Step-6 . If program compiles successful then it is prompted to the new command prompt, otherwise the error will be displayed.
Step-7. Now our program is compiled successfully. To Run this program type the command below:
java HelloWorld
And the output of the program will be display.
Thats it!
0 comments:
Post a Comment