Java Foundation--java Programming specification

Source: Internet
Author: User
Tags java keywords

Iscoder Tags: Java basics, Java programming specification

Absrtact: Java, although there is no mandatory programming specifications, but for the sake of unification, Java has unwritten programming norms, in order to form good programming habits, it is recommended to familiar with and adhere to the Java programming norms, improve the reading of code.

One, Java identifiers

In any language, you have to have your own set of identifier rules. Java identifiers include: Java keywords, identifiers for Java special features, and legitimate user-defined identifiers. Where we can change only the custom identifiers, like most computer programming languages, the Java identifiers originally only support ASCII encoding, but with Java in the world, Java currently supports Unicode encoding, that is, support for any current natural language. It should be noted that even though Java supports languages other than English, such as Chinese, it is mainly used in English in the actual development, which avoids all kinds of strange and strange mistakes.

1.1 The composition of the Java identifier:

①26 English letters (including case)

② Digital 0~9

③ Dollar sign $

④ Underline _

1.2 Java identifier considerations

① cannot start with a number

② named to be known

③ conforms to the Java programming specification

④ cannot be the same as Java keyword and special function identifier

II. Java Programming Specification 2.1 Java identifier naming conventions

Identifier

Naming conventions

Example

Package Name

Company domain name reverse + module name (module division)/company domain name reverse + function name (functional division) "Lowercase"

Com.itheima.teacher/com.itheima.add

Class name

Interface

Hump Naming method

Capitalize each word to make it easier to distinguish each word from the new word

Class Studentmanage

Method name

Variable name

The first word is all lowercase, starting with the second word capitalized (if any)

public void SetName ()

String Name

Constant

Words are all capitalized, and words are separated from each other by underscores (if any)

Max_value
2.2 Java Programming specification

As with the Java identifier naming conventions, Java programming specifications are not mandatory rules, but good programming habits are not a bad thing for improving programming.

First, always explicitly give the compiler system hidden keywords, statements, modifiers, constructors ...

Second, curly braces are written in pairs, and are aligned with a space in front of the left curly brace

Third, there are spaces on both sides of the operator

Four, add a space between the statements, such as the For statement

Add a blank line between the method and the code block to make the code look clearer

Six, the function of the method to add a multiline comment, member variables to be added a single comment, class to add document comments

... ...

Third, Java note 3.1 single-line comment

Java comments, followed by C and C + + code annotation style, single-line comment, is a C + + annotation style, with "double left Slash//" comment, General single-line comment for variables and constants of the comments.

3.2 Multi-line comments

Multiline comments, like the C-language annotation style, use "/*...*/". Multi-line annotations are often used to annotate the functionality of various methods when the comments are not detailed enough to be written on a single line.

3.3 Documentation Comments

Document annotations, which are unique to Java's annotation style, facilitate the refinement of the class's instruction manual (API usage Guide), often used to describe the classes, interfaces, and methods in detail.

3.4 Function of the annotations

First, annotations can improve the readability of the program, whether it is reading code or reading others, comments are essential.

Second, when the compilation error occurs, if the number of programs is very many, you can comment out the wrong line, reduce the scope of exclusion, improve the efficiency of the bug check.

Java Foundation--java Programming specification

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.