Basic Syntax of Java language (1) ---- keyword & amp; identifier (Java language identifier naming convention & amp; java package name, class name, Interface Name, variable name, function name, constant name naming rule), java basic syntax

Source: Internet
Author: User

Basic Java syntax (1) ---- keywords & Identifiers (Java language identifiers naming rules & Java language package name, class name, Interface Name, variable name, function name, constant name naming rules), java basic syntax

I. Keywords

Keyword definition and features

Definition: a special character string (Word) that is used for special purposes ).

Feature: All letters in the keyword are in lower case.

Some common keywords are listed below.

Keywords used to define data types: byte, short, int, long, float, double, char, boolean, class, interface, enum, void

Keywords used to define data type values: false, true, null

Keywords used to define Process Control: if, else, switch, case, default, while, do, for, break, return, and continue

Keywords used to define access permission modifiers: public, private, protect

Keywords used to define classes, functions, and variable modifiers: abstract, static, final, and synchronize

Keywords used to define the relationship between classes: extend, implement

Defines the creation of instances and application instances, and determines the keywords of instances: new, this, super, instanceof

Keyword used for exception handling: try, catch, finally, throw, throws

Keyword used for the package: package, import

Other modifier keywords: native, strictfp, transient, volatile, assert

Ii. identifier:The string sequence used for naming variables, methods, classes, and other elements in Java is called an identifier (any name that you can start with is called an identifier)

Rule for defining valid identifiers:

It consists of uppercase and lowercase letters, numbers, $, and _ (underline.

The number cannot start

Keywords and reserved words cannot be used. (keywords, such as goto and const, may be used in future versions.

It is case sensitive, but the length is not limited.

The identifier cannot contain spaces.

Try your best to know your name

Example: incorrect

1abc (numbers cannot start)

Class (keyword unavailable)

Abc 1 (cannot contain spaces)

Correct:

ABc1 _

Class (the class keyword is lower case. It can contain the keyword)

 

 

Naming rules in Java:

Package name: when multiple words are made up, all letters are in lowercase: xxxyyyzzz

Class Name & Interface Name: when multiple words are made up, the first letter of the word is capitalized: XxxYyyZzz

Variable name and function name: when multiple words are used, the first letter of the first word is lowercase, and the second word starts with the first letter of each word: xxxYyyZzz

Constant name: All letters are capitalized. When multiple words are used, each word is connected by an underscore: XXX_YYY_ZZZ

 

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.