HelloWorld.java - Java Program to Print Hello World

1. Introduction


In this tutorial, We'll learn how to print "Hello World" in java. This is called as first java program to beginners to the programming language. If you understand each and every word in this program then you are good to start learning java concepts.



2. Java Hello World Program


The following is the program is the basic and introductory program for freshers or graduate students.

package com.java.w3schools.blog.java.program.to;

/**
*
* hello world program in java.
*
* @author JavaProgramTo.com
*
*/
public class HelloWorld {

public static void main(String[] args) {

System.out.print("Hello World!");

}

}

Output:


Hello World!

3. Understand Hello World Program


If a java program has main() method means that the main() method will be invoked by JVM when you run it. But, Every program needs not to have a main() method and it is optional.

Understand "public static void main()" which is already discussed in previous articles.

And also need to understand "System.out.println()".

System: It is a class in java.lang package and it works with standard input and output streams. That means reading and printing the values on to the console.
out: out is an instance of PrintStream class. out is a static variable that can be accessed with a class name directly. Object creation is not required to call static members.
println(): println() method is a static method and it is called on out variable.

4. Conclusion


In this article, We've seen how to print "Hello World" in java and understanding each keyword in it with an example program.

GitHub Code





0 Comments