public class Hello {
public static void main(String[] args) {
System.out.println("Hello, Rittwick");
}
}
1. Defining the Class
JAVA has specific keywords. public
and static
are two of many keywords in JAVA. Keywords are case sensitive.
The pubic java keyword is an access modifier. An access modifier allows us to define the scope or how some other parts of my code or someone else's code can access this code. public access modifier is used to give full access.
The class keyword is used to define a class with the name following the keyword. Hello in this case.
To define a class requires an optional access modifier, followed by the class, followed by left and right curly braces.
2. Defining the main method
main method is a special method that JAVA looks for when running a program. It is the entry point of any JAVA code.
public static void main(String[] args) {
System.out.println("Hello, Rittwick");
}
public
is the access modifier.
static
is a JAVA keyword. More about this later.
void
is another JAVA keyword used to indicate that this method will return nothing.
Left and right parenthesis in a method declaration are mandatory and can optionally include one or more parameters - which is a way to pass information to a method.
System.out.println("Hello World");
- This is a statement.
Statement is a complete command to be executed and can include one or more expressions.
Top comments (0)