Java Basics-Variables

Source: Internet
Author: User

There are four types of variables in Java:

  • instance variable (non-static field): A field in a Java class that does not have a static keyword modifier
  • class variable (static field): A field in a Java class with a static keyword modifier.
  • local variable: A variable defined within a closed flower registration (as in a method).
  • parameter: The variable passed to the method.

 

Variable naming

requires the name of the

  • variable to be case sensitive, the name of the variable can be any valid identifier--can have any length of Unicode letters and numbers, You cannot use white space characters
  • cannot start with a number, generally do not advocate the beginning of a $ or underscore, because some machines produce names that contain "$"
  • cannot use keywords or reserved names

Naming suggestions

Generic variable name Use English words, if the variable contains more than one word, generally except the first word, the first letter of the following words are capitalized, such as

 

 int  Numgears=6//Note the spelling of the name 

  and the constant name (final keyword decoration) the words are all capitalized, and the words are separated by underscores such as

  Static  final  int  num_gears=6// Note the spelling of the name 

 

Java Basics-Variables

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.