In this tutorial, we will learn the basic syntax of Java language. We will go through the key components of a simple Java program.
public class HelloWorld {
public static void main(String[] args) {
System.out.println("Hello, World!");
}
}
Hello, World!
public class HelloWorld
HelloWorld
. In Java, every application must contain at least one class definition, which encloses the program's entry point.public static void main(String[] args)
public
means the method is accessible from outside the class, static
means it can be called without creating an instance of the class, void
means it does not return a value, and String[] args
is an array of strings that stores arguments passed to the program.{
System.out.println("Hello, World!");
System.out
is an output stream, and println
is a method that prints the provided string followed by a new line.}
}
HelloWorld
class definition.;
).//
for single-line comments or /* ... */
for multi-line comments.{}
.Main
and main
would be considered different identifiers.