How to write Hello World program in Java


To make your first program i.e. Hello world program in java you must need Java Environment with Java Virtual Machine.
For the detailed instruction how to install java and how to setup visit official website of Oracle.

public class Helloworld
public static void main(String args[])
System.out.println("Hello World");

Here we have defined class “Helloworld” as in Java everything you need to placed in the class.  After that as same as in C++ we have declare the main() function with String argument.
And to print any line in java we used function-println.

To run this program you need to copy above code and need to paste into Notepad.
Save the notepad file with name
Note that extension of file must be .java

If you save program with different name then it wouldn’t work. Because in Java, class name as well as file name must  be same.

How to compile and run “” program-

Go to the Command Prompt.
Make sure you are in the directory in which your java program is saved.
Type “javac” without quotes.
Here we are compiling java program by invoking the java compiler.
It will show error if any otherwise it will simply come to the next line.

Note:When compiling java program you must need to save the java file with extension .java

If no error found then write “java Helloworld”
It will run the program and will show you the output of the program.



Please enter your comment!
Please enter your name here