public class Main {
public static void main(String[] args)
//main() is called a method, it is the main method of the program.
//we use public so that the main method can be accessible in the whole program.
//void is used for no return type.
//we use static so that we can work in it without creating an object for it.
{
System.out.println("Hello World");//System is a class
}
}
Every line of code that runs in Java must be inside a class
.
Java is case-sensitive.
Boilerplate code - The code which we get as default skeleton
Every program must contain the main()
method.
Any code inside the main()
method will be executed.
Inside the main()
method, we can use the println()
method to print a line of text to the screen.
{}
mark the beginning and the end of a block of code.System
is a built-in Java class that contains useful members,
out
, which is short for "output".println()
method, is short for "print line". (each println()
will add a new line.)NOTE
In Java, the String[] args
is used to pass command-line arguments to the main method of a program. When you run a Java program from the command line, you can provide additional information (arguments) that can be accessed by the program during its execution.
Here's a brief explanation:
There is also a print()
method, which is similar to println()
.
Every line must end with the semicolon “ ; “.
NOTE