Second, the first Java program--helloworld

Source: Internet
Author: User

The operating mechanism of the 1.Java program.

Java source file suffix name is Java-shaped, such as *.java, compiled by the compiler to generate *.class files, the computer to run the class file execution Java program. However, the computer referred to at this point is not a physical computer but a Java virtual machine, the JVM.

All of the programs in Java run on the JVM, that is, all the *.class files run on the JVM, and for the *.class file, it only needs to be compliant with the JVM's specifications, without regard to hardware or other operating system compatibility. Again by the JVM to adapt to each operating system, so, with a Java slogan once compiled, run everywhere.

2.Hello World Program

The first things we think about are the small programs on the desktop in Windows, such as our browsers, text editors, game programs, and so on. These graphical interface programs, which I would call GUI applications, are not very easy to write in Java, and are not a way for us to learn, so the next possibility is that all the programs we write are "toy" programs designed to illustrate some of the relevant concepts. They can only enter the output through the Command line window.

Create the first Java program

Create a new text document under any folder, and modify the document name to Helloworld.java.

Open the Helloworld.java file with Notepad and enter the following.

 Public class helloworld{    publicstaticvoid  Main (String args []) {        System.out.println ("Hello world!!!" );    }}

Simple analysis of HelloWorld

①java languages are case sensitive, for example, HelloWorld, HelloWorld, HelloWorld are three different things

②public: An access modifier that controls the level of access to this program by code in other programs.

③class: Indicates that the entire contents of the program are contained in this class. Can be understood as a container for loading program logic. All content in a Java program must be placed in a class.

④ class Name: Class name is immediately followed. Class name naming rules, the beginning of the letter can be followed by any alphanumeric, the length of the basic unlimited, but not the use of reserved words, the first letter capital, multiple words, the first letter of each word capitalized, hump nomenclature. Example: CamelCase. The source code file must be the same name as the public class, and it is important to extend the case with Java.

⑤javac *.java compiler generates *.CLASS files, Java Classname.class runs Java programs. When you run a Java program, the Java Virtual machine starts executing from the main method in the specified class, so you must include a main method in the source file of the class in order for the code to execute.

⑥ uses {} to surround the code, spaces are ignored by the compiler, a pair of {} represents the beginning and end of the method body, and no sentence in Java must end with a semicolon.

  System.out.println ("Hello World!!!" )

① output text to the console, '. ' For calling method Object.Method (parameter)

②println () This method outputs a string on the console and wraps it, using a "" enclosed representation string. There is also a print method, and this is not a newline.

The ③java method can have no parameters or can have one or more parameters. For example, you can use: System.out.println (); the function is to print a blank line.

Reserved Word table

  

  Comments:

The ① comment does not appear in the executable program.

② three ways to annotate:

A. Single-line comment//comment content

B. Multiline comment/* Comment content */

C. Documentation Comments/**

* Comment Content

*/

D. Annotations cannot be nested

Second, the first Java program--helloworld

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.