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