Notes 20180508:java keywords and identifiers for Basic program design structures

Source: Internet
Author: User
Tags goto modifier modifiers java keywords

After we have successfully written the HelloWorld, we also have a deep understanding of the main function, and mentioned that main is not a keyword, but what is the keyword? This is actually the chapter to study the content, this section of the study of keywords and identifiers, in the identifier we will also explain the Java in the name of the hump;

1.1 Key Words

In Hello World, we found that many of the words are fixed, this is actually a key word in Java, the keyword in Java has a special meaning, let's take a concrete look at the following, here is a brief introduction to the Java keyword, In the following we will be in the study of some specific keywords for special analysis.

definition and characteristics of 1.1.1 keywords
    • Keywords are pre-defined in the Java language, with special meanings , sometimes called reserved words, and variables with special meanings.
    • Java's keywords have special meanings for Java compilers, which are used to represent a data type, or to represent the structure of a program.
    • The keyword cannot be used as a variable name, method name, class name, package name, and parameter .
    • The Java language specifies that the keyword cannot be used as an identifier.
    • There are currently 50 Java keywords, of which the two keywords "const" (constant) and "goto" (goto) do not have a specific meaning in the Java language. The Java language lists them as keywords, just because "const" and "goto" are keywords for some other computer language.
    • All letters in the keyword are lowercase.
categories of 1.1.2 keywords

Keywords can be divided into several categories depending on the purpose:

1.1.2.1 keywords used to define data types
    • Class: Classes
    • Interface: interface
    • BYTE: One of the basic data types, byte type
    • Short: One of the basic data types, the shorter integer type
    • int: One of the basic data types, integer type
    • Long: One of the basic data types, the length integer type
    • float: One of the basic data types, single-precision floating-point number types
    • Double: One of the basic data types, two-precision floating-point number types
    • Char: One of the basic data types, character type
    • Boolean: One of the basic data types, Boolean type
    • Void: Declares that the current member method has no return value
1.1.2.2 keywords used to define data type values
    • True: True
    • False: False
    • Null: Empty
1.1.2.3 Keywords for defining Process Control
  • If: The Guide Word of a conditional statement
  • else: used in a conditional statement to indicate a branch when the condition is not true
  • While: used in the loop structure
  • Do: used in the Do-while loop structure
  • Switch: The guide word for the branch statement structure
  • Case: used in a switch statement, the table is one of the branches
  • Default: defaults, for example, used in a switch statement to indicate a default branch
  • For: A guide word for a looping structure
  • Break: jump out of a block early
  • Continue: back to the beginning of a block
  • Return: Returning data from the member method
1.1.2.4 keyword used to define access rights modifiers
    • Private: An access control method: Private mode, only own access
    • Protected: A type of access control: Protected mode, allowing subclasses and the same package class to access
    • Public: One access control mode: Common mode, allowing all external classes to access

The access permission modifier permission is public, protected private, from high to low.

1.1.2.5 keywords for defining classes, functions, variable modifiers
    • Abstract: Indicates that a class or member method has an abstraction attribute
    • Final: Used to describe the final attribute, indicating that a class cannot derive a subclass, or that a member method cannot be overridden, or that the value of a member field cannot be changed
    • Static: Indicates that the property is statically
    • Synchronized: Indicates that a piece of code needs to be executed synchronously
1.1.2.6 Keywords used to define the relationship between classes and classes
    • Extends: Indicates that one type is a subtype of another type, where the common types have classes and interfaces
    • Implements: Indicates that a class implements a given interface
1.1.2.7 is used to define instance and reference instances, and to determine the keywords
    • NEW: Used to create an instance object
    • This: reference to the current instance object
    • Super: Indicates a reference to the parent type of the current object or a constructor for the parent type
    • instanceof: Used to test whether an object is an instance object of a specified type
1.1.2.8 keywords for exception handling
    • Try: Attempt a block that might throw an exception
    • Catch: Used in exception handling to catch exceptions
    • Finally: used to handle exception cases, to declare a block of statements that are essentially bound to be executed
    • Throw: Throws an exception
    • Throws: Declares all exceptions that need to be thrown in the currently defined member method
1.1.2.9 keywords for packages
    • Import: Indicates that you want to access the specified class or package
    • Package: Packages
1.1.2.10 other modifier keywords
    • Native: Used to declare a method that is implemented by a computer-related language (such as the C/c++/fortran language)
    • STRICTFP: Used to declare fp_strict (single-precision or double-precision floating-point number) expressions that follow the IEEE 754 arithmetic specification
    • Transient: Declaring a member domain without serialization
    • Volatile: Indicates that two or more variables must be changed in a synchronized manner
    • Assert: Used for program debugging
1.2 identifiers

In the above we know that the keyword can not be used for variable names, class names, method names, and so on, what are the words in Java to denote these nouns? What are the naming rules? A: identifiers; let's read it.

definition, characteristics and naming of 1.2.1 identifiers
  • In the Java language, the sequence of characters used to name features such as various variables, methods, and classes is called an identifier.
  • Identifiers are made up of any order of letter case, number, underscore ' _ ', dollar sign $
  • The letters in the identifiers in the Java language are strictly case-sensitive. The Java language uses the Unicode standard character set, which can identify up to 65,535 characters, so the letters in the Java language include not only the usual Latin characters a, B, C, and so on, but also Chinese, Japanese, and many other languages.
  • The Java identifiers have the following naming conventions:
    • identifiers should start with letters, underscores , dollar breaks "The following identifiers are valid: MyName, My_name,Points,$points, _sys_ta,OK,_23b ,_3_

< Span style= "FONT-FAMILY:CALIBRI;" > < Span style= "FONT-FAMILY:CALIBRI;" > Span style= "font-family: Imitation;" > #name, 25name,class,&time,if ".

      • The identifier cannot be a keyword. Note: Java identifier selection should be noted "see the name" and not be the same as the Java language keyword.
      • Strictly case-sensitive in Java. For example, good and good are different two identifiers. Cannot have spaces in identifiers;
1.2.2 Name Specification in Java-hump naming
    • Package Name: All letters are lowercase when multiple words are composed. xxx.yyy.zzz Example: cn.itcast.student, domain reversal
    • Class name Interface name: When multiple words are composed, the first letter of all words is capitalized. Xxxyyyzzz
    • Variable name and function name: When multiple words are composed, the first letter is lowercase, the second word starts with the first letter of each word big xxxyyyzzz
    • Constant name: All letters are capitalized. For multiple words, each word is connected with an underscore. Xxx_yyy_zzz

Notes 20180508:java keywords and identifiers for Basic program design structures

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.