public is an access modifier. It simply means that whatever it's applied to can be seen by external classes and classes outside the module.
class means you're declaring a class, and
Displayer is the name of the class
For number 1, it means
you're declaring a publicly visible class named "Displayer".
You do not have permission to view the full content of this post.
Log in or register now. is the official documentation from Java™ tutorials
Code:
public static void main(String args[]) {
static means you're defining a
class method.
Class methods (commonly referred to as
static methods) are functions that belong to the class and is shared by all instances of that class. This means you don't need to create an object to invoke this method.
static can be used in methods and fields; I'll just refer you
You do not have permission to view the full content of this post.
Log in or register now. for more info
public static void main(String args[]) {
is the method signature: it should have (optional) modifiers, return type, method name, parameter list, and exception list.
For number 2,
you're defining a publicly visible class method called "main" that takes an array of String named "args" as an argument, and returns nothing (void). A matching pair of brackets encloses the
method body.
Again,
You do not have permission to view the full content of this post.
Log in or register now. a link to the docs
Code:
System.out.println("You'll love Java!");
System.out.println(); is a call on method named "println".
We observe that class
System has a
static field "out" which is an instance of
PrintStream. It prints to the
standard output and you invoke one of its methods, println (print line), to do just that.
Note the semicolon. It
terminates a statement, in our case the statement is a method call. For now, just remember that it is necessary to terminate all statements because it's the syntax of java.
"You'll love Java!"
we omitted this from the above explanation. This is the
string that you pass to the method call above. Stitching everything together, number 3 is a statement that roughly translates to:
Invoke the [method println of object out] on [class System] with the string "You'll love Java!" as an argument -- done.
These two closing curly brackets are simple: brackets enclose "bodies" and blocks (a group of statements):
- number 4 is the closing brackets for the [body of the static method main].
- number 5 is the closing brackets for the [body of the class Displayer].