Keywords and identifiers in Java __java

Source: Internet
Author: User
Tags goto reserved

I. Java processing of the GOTO keyword

In Java, we can't use the Goto keyword, but we use the loop tag, but in order to avoid the programmer using goto, we keep goto as a keyword. Similar keywords are also const.

Two. True, false, NULL is the keyword

In Java, True, FALSE, and Null are not keywords, but literal constants (also called direct quantities), where true and false are literal constants of Boolean types, and Null is literal constants of reference types. These three literal constants cannot be used as identifiers either.

Three. Keywords in Java

Key words Meaning
Abstract Indicates that a class or member method has an abstract property
Assert Used for program debugging
Boolean One of the base data types, Boolean type
Break Jump a block ahead of time
Byte One of the base data types, byte type
Case Used in a switch statement, a table is one of the branches
Catch Used in exception handling to catch exceptions
Char One of the basic data types, character types
Class Class
Const Reserved keywords, no specific meaning
Continue Back to the beginning of a block
Default Default, for example, in a switch statement, indicating that a default branch
Todo Used in the Do-while cycle structure.
Double One of the basic data types, double-precision floating-point number types
Else Used in conditional statements to indicate a branch when the condition is not established
Enum Enumeration
Extends Indicates that one type is a subtype of another type, where common types have classes and interfaces
Final Used to describe the final attribute, indicating that a class cannot derive a subclass, or that a member method cannot be overwritten, or that the value of a member field cannot be changed
Finally Used to handle exception situations that declare a block of statements that are essentially sure to be executed
Float One of the basic data types, single-precision floating-point number type
For A guide word for circular structure
Goto Reserved keywords, no specific meaning
If Guide Words for conditional statements
Implements Indicates that a class implements the given interface
Import Indicates that you want to access the specified class or package
instanceof Used to test whether an object is an instance object of a specified type
Int One of the basic data types, integer type
Interface Interface
Long One of the base data types, long integer types
Native Used to declare that a method is implemented by a computer-related language (such as the C/c++/fortran language)
New Used to create a new instance object
Package Package
Private An access control method: Private mode
Protected An access control approach: protection mode
Public An access control approach: Shared mode
Return Returning data from a member method
Short One of the basic data types, short integer types
Static Indicates a static property
Strictfp Use to declare fp_strict (single-precision or double-precision floating-point number) expressions follow the IEEE 754 arithmetic specification
Super Indicates the reference of the parent type of the current object or the method of constructing the parent type
Switch Guide words for Branching statement structures
Synchronized Indicates that a piece of code needs to be executed synchronously
This Reference to the current instance object
Throw Throws an exception
Throws Declares all exceptions that need to be thrown in the currently defined member method
Transient Declaring a member domain without serialization
Try Try a program block that might throw an exception
void Declaring the current member method has no return value
Volatile Indicates that two or more variables must change synchronously
While Used in the loop structure
Four. Definition rules for Java identifiers

1. The definition rules of Java identifiers that most people understand:

(1). Identifiers consist of letters, numbers, currency symbols (¥, $), and join symbols (_).

(2). The first letter of an identifier can be a letter, a currency symbol, and a join symbol, but not a number.

(3). Identifiers cannot be identical to keywords in java.

(4). Identifiers cannot be the same as predefined literal constant names in Java (such as true, false, null).

The rules above are correct most of the time, but note that the letters here are not just the 26 English letters in the tradition, but the Unicode character set, the Unicode character set is U+0000~U+10FFFF, but not every Unicode value corresponds to a character , which means that not all Unicode character sets can be used as identifiers in Java. There is the character set that cannot be used as the first letter of a Java identifier, nor is it a simple 0~9 10 digits. So how do we determine if a Unicode can be used as a Java identifier? There are two methods in character that can be judged:

public static Boolean Isjavaidentifierstart (char ch); Determines whether the corresponding character can be used as the first character of a Java identifier

public static Boolean Isjavaidentifierpart (char ch); determine if the corresponding character can be used as a Java identifier

Because of the expansion of the Unicode character set, in order to be able to handle the supplemental character (U+10000~U+10FFFF), an additional two methods are added to the jdk1.5 for this purpose:

public static Boolean isjavaidentifierstart (int codepoint); determine if the character corresponding to the code point can be the first character of the Java identifier

public static Boolean isjavaidentifierpart (int codepoint); determine if the character corresponding to the code point can be used as a Java identifier

2. Now, we redefine the definition rules for identifiers:

(1). The code point corresponding to the first letter of the identifier must make the Isjavaidentifierstar () method of the character class return a value of true. The corresponding code point for subsequent characters must make the return value of the Isjavaidentifierpart () of the character class true.

(2). Identifiers cannot be identical to keywords in java.

(3). Identifiers cannot be the same as predefined literal constant names in Java.

(4). The length of the identifier must be within the scope supported by the system.

Five. Note the use of the symbol "$"

When defining a Java identifier, we can use $ and can use it as the first letter of the identifier, but we need to be aware that the $ this symbol can be used in the inner class, so we need to take this into account when we use $ as the keyword character.

public class User$vip {public

	static void Main (string[] args) {
		
	}
}

class user{
	class vip{
		void Print ()
		{
			System.out.println ("VIP");
		}
	}

The above example is because of the use of $ in class markers, and in the internal class of the $ conflict, so compile the error, prompt User.vip class repeat. The reason is that when compiled into a class file, there will be two user$vip.class, so it will be an error.

Six. Maximum length of identifiers

In the Java language Specification, there is no limit to the length of Java markers, but in the Java Virtual Machine specification, identifiers are length-limited. In the class file, a constant string representing the identifier is stored in the Constant_utf8_info table, which uses two bytes to represent the length of the string. Therefore the maximum expression of 65535.










Related Article

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.