Java – “Hello World” program

Step 1:
We will create our first Java file, which can be done in any text editor (e.g. Notepad++, Atom, or Sublime Text).

Step 2: Below is the content of Hello World program file, all lines are required:

public class MyClass { public static void main(String[] args) { System.out.println(“Hello World”); } }

See Explanation of above program

Step 3:
Save the file as “MyClass.java” because our program name is MyClass. File name must be the same as the main function name.

Step 4:
Open a terminal (cmd, putty, git-bash), navigate to the directory where you saved your file.

Step 5:
Type following command in command line, to compile the code:

javac MyClass.java

In case if there is any syntax or code error, the command prompt will point it.

Step 6:
You will find an executable file “MyClass.class” in the directory where you saved your java program file.

Step 7:
Type following command in command line, to run the file:

java MyClass

It will show you the result of the file. In our case it is printing:
Hello World


Congratulations

Leave a Reply

Your email address will not be published. Required fields are marked *

© 2024 Faraz Jafri All rights reserved. Privacy Policy

Proudly powered by WordPress. Special thanks to Bootstrap, FontAwesome & Open Source Community.