From http://www.cnblogs.com/ggjucheng/archive/2012/12/06/2805408.html
English from http://docs.oracle.com/javase/tutorial/getStarted/application/index.html
You can see the Java "Hello world! "ProgramHere it isCode:
Class helloworldapp {public static void main (string [] ARGs) {system. Out. println ("Hello world! "); // Display the string .}}
"Hello world! "The program contains three main parts:Source codeAnnotation, helloworldapp class declaration, main method. The following instructions will provide you with a basic understanding of the code, but a deeper understanding requires you to read the subsequent tutorials.
Source code comments
The bold text is "Hello world! "Program comments
/*** The helloworldapp class implements an application that * simply prints "Hello world! "To standard output .*/Class helloworldapp {public static void main (string [] ARGs) {system. Out. println ("Hello world! ");// Display the string.}}
Annotations are ignored by the compiler, but they are useful to programmers. JavaProgramming LanguageThree annotations are supported:
-
/*Text*/
-
The compiler ignores/* to */everything in the middle.
-
The compiler ignores everything from
/*
To
*/
.
-
/**Documentation*/
-
This is a document comment. The Compiler ignores this type of comment, just like other annotations. However, the javadoc tool can use document annotations when preparing to automatically generate documents.
-
//Text
-
The compiler ignores // all the things starting from the end of the row
Helloworldapp class declaration
The bold text below is "Hello world! "Program class declaration
/*** The helloworldapp class implements an application that * simply displays "Hello world! "To the standard output .*/Class helloworldapp {Public static void main (string [] ARGs) {system. Out. println ("Hello world! "); // Display the string .}}
As shown above, the most basic class declaration is:
ClassName{...}
The class keyword starts the class declaration of the class name, and the code is between braces.
Main Method
The bold text below is the beginning of the main method declaration:
/*** The helloworldapp class implements an application that * simply displays "Hello world! "To the standard output. */class helloworldapp {Public static void main (string [] ARGs ){System. Out. println ("Hello world! "); // Display the string.}}
Java programming language, each program must contain a main method, and its signature is as follows:
Public static void main (string [] ARGs)
Public and static modifiers can be any order (Public static
OrStatic public
), But is commonly usedPublic static
. Command line parameters can be named as any name, but most programmers choose "ARGs" or "argv ".
The main method is similar to the main functions of C and C ++. This is the entry point of your application and will then call all the other methods required by your program.
The main method accepts a separate argument: A String Array
Public static void main (String [] ARGs)
The array mechanism is to pass information to the application through the runtime system. For example:
JavaMyApp Arg1 Arg2
Each string in the array is called a command line parameter. Command line parameters allow your application to modify the operation of the program without re-compiling it. For example, the sorting program may allow users to sort data in descending order. This command line parameter:
-Descending
"Hello world! "The program ignores its command line parameters, but you should know that such command line parameters do exist.
Last line:
System. Out. println ("Hello world! ");
Print "Hello World!" using the system class of the core library! "Message to standard output.