A Basic Java Program to print "Hello World".
public class HelloWorld {
public static void main(String[] args) {
System.out.println("Hello, World!");
}
}
public class HelloWorld {
This line declares a new class called HelloWorld
. In Java, a class is a template for creating objects, and everything in Java is an object. The public
keyword indicates that the class is accessible by any other class.
public static void main(String[] args) {
This line declares the main
method, which is the entry point for the program. The public static void
part indicates that the method is public (accessible by any other
class), static (belongs to the class itself, rather than an instance of
the class), and returns no value (void). The main
method takes an array of String
objects called args
, which can be used to pass command-line arguments to the program.
System.out.println("Hello, World!");
This line uses the println
method of the System.out
object to print the string "Hello, World!" to the console. The println
method prints the string and adds a newline character at the end.
}
This curly brace closes the main
method.
}
This curly brace closes the HelloWorld
class.
No comments:
Post a Comment