Java variables (translated from Java tutorials)

Source: Internet
Author: User

From http://www.cnblogs.com/ggjucheng/archive/2012/12/07/2806907.html

English from http://docs.oracle.com/javase/tutorial/java/nutsandbolts/variables.html

The object uses a field to save its status:

 
Int Cadence = 0; int speed = 0; int Gear = 1;

 

JavaProgramming LanguageDefine the following types of variables:

Instance variable (non-static field)

Class variable (static field)

Local variables (variables in the method that store the temporary state)

Parameter (variable corresponding to the method signature)

 

The following general guidelines are used for fields and variables discussed in the rest of this tutorial. If we are talking about "general fields" (excluding local variables and parameters), we can simply say "fields ". If the discussion applies to "all the above variables", we can simply say "variables ". If the differences are made based on context calls, we will use the appropriate specific names (static fields, local variables, etc ). You can also occasionally see and use "members", such as fields of type A, methods, and nested types, collectively referred to as their members.

 

Name

Each programming language has its own set of rules and conventions, and you can use the name category. It is no different for Java programming languages. Naming rules and conventions of variables can be summarized as follows:

Variable names are case sensitive. The variable name can be any legal Identifier-a sequence of Unicode letters and numbers with an unlimited length, starting with a letter, dollar sign "$", or "underline. By convention, variables generally start with letters, rather than "$" and "_". In addition, dollar signs should never be used. You may find that in some cases, the automatically generated name will contain the dollar sign, but your variable name should be avoided. The same convention exists for the underscore "_". It is technically legal to start using "_" in a variable, but this practice is not encouraged. Spaces are not allowed.

It can be followed by letters, numbers, dollar signs, or underscores. When you select a variable, use the complete word instead of the mysterious abbreviation. This will enable yourCodeIt is easier to read and understand. In many cases, it will make your code like a document (the Translator's note: code is a document, a very high level ). For example, the field is namedCadence,Speed, AndGear, Which is much more intuitive than abbreviated versions, such as S, C, and G. Remember that the name you selected must not be a keyword or reserved word.

If the name you selected contains only one word, Use lowercase letters to spell all the words. If multiple words are contained, the first letter of each subsequent word is capitalized. If your variables store constant values such as static final int num_gears = 6, the conventions are slightly changed. Each letter is capitalized and each word is separated by an underscore. By convention, underlines should never be used (except for variable names that represent constants ).

Related Article

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.