Java syntax base identifiers and keywords

Source: Internet
Author: User
Tags goto

First, identifiers

The variable names, method names, class names, and object names in Java are identifiers, and the program requires identifiers to be uniquely identified in the process of writing the program. The naming rules for identifiers in Java are as follows:

    • Can consist of uppercase and lowercase letters, numbers, underscores, and dollar signs in any order.

    • Cannot start with a number.

    • cannot be a reserved keyword in java.

    • There are no length restrictions, but case sensitivity, such as Hello and hello are different identifiers.

Second, the key word

Like other languages, there are many reserved keywords in Java (that is, special meaning in Java), such as public, break, and so on, which cannot be used as identifiers. We don't need to memorize any of the keywords and know that this is enough, and if you accidentally use these keywords, the compiler can tell us the error. The Java keyword is shown in the following table:


Abstract Boolean Break Byte Case Catch
Char Class Continue Default Do Double
Else Extend False Final Finally Float
For If Implement Import instanceof Int
Interface Long Native New Null Package
Private Protected Public Return Short Static
Super Switch Synchronized This Throw Throws
Transient True Try void Volatile Ehile
Goto Const



Note : Gogo, const, and so on are no longer used in the Java language, but you cannot use Goto or const as the variable name.

III. naming conventions for Java identifiers

From the Java language syntax, the name is very arbitrary, but in our daily programming process, in order to improve the readability of the code, maintainability and convenient debugging, the name of the best "see", correctly use the case, and follow the following rules:

Package name: In lowercase English words, preferably have a hierarchy, such as: Com.hq.core.

Class name and interface name: usually nouns, denoted by one or several English words, with the first letter of each word capitalized, for example: Color, FileInputStream.

Method name: Usually a verb, the first letter is lowercase, and if there are other words, start with the first letter capitalized from the second word, such as: Main (), Draw (), SetColor ().

Variable name or object name: Same as method casing rules.

Constant name: declared as public static final, all uppercase letters, words and words separated by underscores, such as: Max_value.

This article is from the "Jianggujin blog" blog, make sure to keep this source http://jianggujin.blog.51cto.com/6808292/1715681

Java syntax base identifiers and keywords

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.