Line-by-line the code reads as follows:class Echo { public static void main (String[] args) { System.out.println(args[0]); System.out.println(args[0]); } }
class
keywordEcho
. It is good practice and often obligatory to let
the name of the
source file (Echo.java
) correspond with the name of
the main class (Echo
) defined. Also use separate files for separate
classes.
main
methodmain
.
It refers to the main execution loop and is invoked by the Java
interpreter at start-up.
public
, static
, and
void
main
method that looks like:
The keywordpublic static void main(String[] args) { ... }
public
indicates that the method can be
called by any object. The keyword static
turns main
in what is called a class method, which does not need an object to
be invoked. void
is the type of the value
returned by the method; in this case, no value is returned.
These keywords will be discussed later in more detail.
String[] args
main
method has one parameter:
an array of strings. This array will enable your program to operate
on actual arguments passed to application in the command-line.
System.out.println
System.out.println
prints out its argument, which in this
case is the first of the command-line arguments, on standard output
(mostly your terminal screen).
System.out.println
as follows: along with the Java system
comes the class System
that contains a variable out
of type PrintStream
; its full name is
java.lang.System.out
. This object or instance
implements the standard output stream. On this object we apply
the println
belonging to the PrintStream
class.
Soon you will see easier examples of the use of periods.
()
[]
{}