Syntax and development rules for Java basics

Source: Internet
Author: User

The rules of code writing

Take the following example:

Write a good structure first

Note: In order to avoid errors, write the code when the parentheses are aligned, and then fill in the content, each "{}" in the beginning of the content to write a 8 more space than the previous line. For convenience, you can use the keys on the keyboard instead (usually the leftmost part of the keyboard from the third row), this one click is 8 spaces.

There are a few things you should be aware of when writing code:

And there can only be one public class in a file, and no one will have the following situation.

2. No public at the front of the contemporary code

3, when there is a public class in the file, there are a number of not public classes, the result of the compilation is this look

First, some good habits when writing code

1, write code to keep the regular, shortcut keys are ctrl+s, so you can avoid some uncertainties caused by the Code rewrite, such as power outages, computer blue screen, computer crashes and so on.

2, write code to regular backup, this can be used for later work to establish a good habit, for example, feel where the code problem can be followed, you back up the work log to find, then more convenient.

3, file naming and daily file processing, computer desktop by the amount of keeping tidy, daily do the best name of the file to change to the relevant name, in order to avoid the future to find trouble.

Third, the syntax rules of Java

1, case-sensitive:

Java is very strict in case sensitivity, such as int a and int A, are completely different two concepts, there are some key words of the case, it is very important not to confuse.

2, each code must have a semicolon end, and here and C + + similar

3. All grammatical symbols are half-width symbols:

Half-width: one byte

Full width: two bytes

Here is a description, a Chinese character accounted for two bytes, an English letter accounted for a byte, so the general English is full-width symbols, English is used are half-width symbols.

4. Naming specification

Java is not strictly pointed out to be sure to name in English, we can also use, pinyin, or initials, or Chinese, so, the future development should take the team into account, the application of the people can understand the name.

Second, the note

Note: It is not executed as code

1. Single-line Comment

What you have in mind

Cases:

2, multi-line Comment

/* Content */

Cases:

3. Documentation Comments

Document comments generate help documents for others to see

/**

* Content

* Content

*/

Cases:

4. Some questions about document comments

1),

A: If the ligatures document comment, the following will overwrite the above.

2),

A: Only classes with public are included in the build.

Syntax and development rules for Java basics

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.