Java – hello world

Here we will write Hello World in java and try to understand basics of how it works.

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

  • How to run?
    • Save the above code in a file with name –
    • if you are using an IDE like Eclipse/Intellij , right click on file and click run
    • or from command line
      • first run javac
      • then run java HelloWorld
  • Now Let’s understand
    • First of all we have described a class here with Name HelloWorld public class HelloWorld
    • In this we described a function with name main as public static void main
    • Main function with this signature is special to java as it calls this main function when your program runs.
    • Now in this main function we have written System.out.println("Hello World");
    • With this line we are telling the System to print the text passed(which is “Hello World” in this case) and system prints this on the command line.


Leave a Reply

Fill in your details below or click an icon to log in: Logo

You are commenting using your account. Log Out /  Change )

Facebook photo

You are commenting using your Facebook account. Log Out /  Change )

Connecting to %s