Java basics: Lecture 6: compiling Java applications

Source: Internet
Author: User

First, let's look at a basic example.

File Name: Hello. Java . Purpose: output" Hello !". The file content is as follows: Package packages;   Public class Hello {   /** * Main Method, all applications should provide such Main Method */ Public static void main (string [] ARGs ){ System.Out. Println ("Hello! "); } } The following code is analyzed: The 1 Line, is the package declaration, Package Is the keyword of the famous bag, Bytes Is the package name. Compile any Java File, the first line should be the package Declaration (although not), you can first understand the package as a folder. The 3 The definition of rows and classes. Public Is a public class, Class Is a famous keyword, Hello Is the class name. Note that the class name and file name should be the same. Write Java Applications mainly write classes and interfaces (which can be understood as special classes ). Class is the basic logical unit of a file. The 5 Line 7 Line, comment. The function of the interpreter is one of the annotation methods. The 8 Line 10 Line is a method. Method is the main content of the class. The method here is Main Method, is a special method, each Java Each application should have Main Method is the entrance to the entire application. Main The method definition format is fixed: Public static void main (string [] ARGs) . In the future, there should be such an entry class and method regardless of the program function size. The 9 Line is the content of the method, used to output a full stop on the console" Hello ". This is the simplest application. However, no matter how complicated the application is, it is such a structure. The difference is that there is only one output statement, and more code is available for the complex application. The 11 The right parenthesis of the row and 4 The left parenthesis of the row corresponds. You can try to modify the comments and output content of the method, such as outputting your own name to see how to modify it? Although the Code here is very simple, you should pay attention to the following aspects and develop a habit:L Declaration package;L Add empty rows as appropriate;L Appropriate indentation;L The class name and file name must be consistent, and the class name should be meaningful as much as possible;L The appropriate annotations are described later in the format of the annotations;L Do not drop the brackets;L There is basically an ending character" ; ";L The output string uses double quotation marks;L Note that double quotation marks, Parentheses, and semicolons are all in English. People who have just learned the language can easily write them in Chinese. Java Is a plain text file, so Java You can use any text editor, such as Notepad, WordPad, Editplus . However, these tools are all common tools. Java For applications, you need Java Is very familiar with the basic syntax and class library, otherwise it is prone to many syntax errors. To provide development efficiency, you can use the inherited development environment ( IDE ). IDE It can help us generate some code, for example, for the above Code, use IDE Only a few codes need to be written by yourself. IDE In the wizard, you only need to enter the package name and class name, and then modify the comment content and Main Method. In addition, we can compile the property generation method for us, complete the code we have written, and provide a lot of prompts during code writing. Popular Java ide Yes Eclipse , Netbeans , Jbuider And Intelli J . Many companies use Eclipse So we will use Eclipse As the development environment for our lectures. Many schools will Java The Jcreator , This is also a good tool, especially the Fast startup speed. Remember: Java File Suffix: . Java , Java The class name and file name are the same, Main The method is the entry of the entire application and Main Method form, how to output information.   Last Lecture: fifth, the basic process of developing Java applications Next Lecture: Chapter 7 compiling and running Java programs Next time we will introduce how to compile and run the program. Li xucheng Csdn blog : Http://blog.csdn.net/javaeeteacher Csdn Student base camp: Http://student.csdn.net/invite.php? U= 124362 & C = 7be8ba2b6f3b6cc5

 

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.