1.Java keywords and reserved words

Source: Internet
Author: User
Tags goto null null stack trace switch case throwable true true try catch java keywords

Keywords and reserved words http://www.cnblogs.com/wwxbi/p/4292170.html

Access control

Private protected public

Class, method, and variable modifiers

Abstract class extends final implements interface native new static STRICTFP

Synchronized

Transient

Volatile

Program

Break continue return does while if-else for instanceof switch case default

Error handling

Try cathc throw throws

Package related

Import Package

Basic type

Boolean byte char double float int long short null true false

Variable reference

Super this void

Reserved words

Goto CONST

Second, detailed explanation

1. Access control

1) Private key is an access control modifier that can be applied to a class, method, or field (a variable declared in a class). These classes, methods, or fields can only be referenced in a class that declares private (inner) classes, methods, or fields. They are not visible outside of the class or for subclasses. The default access scope for all class members is package access, which means that class members can be accessed from any class in the same packet, unless there is a specific access control modifier.

2) The protected protected protected keyword is an access control modifier that can be applied to a class, method, or field (a variable declared in a class). These classes, methods, or fields can be referenced in a class that declares a protected class, method, or field, any other class in the same package, and any subclasses, regardless of which package the subclass is declared in. The default access scope for all class members is package access, which means that class members can be accessed from any class in the same packet, unless there is a specific access control modifier.

3) The public key is the access control modifier that can be applied to a class, method, or field (a variable declared in a class). The public class, method, or field may only be referenced in any other class or package. The default access scope for all class members is package access, which means that class members can be accessed from any class in the same packet, unless there is a specific access control modifier.

2. Classes, methods, and variable modifiers

1) Abstract declares that a class or method can be modified by abstracting a keyword. The abstract class can be extended (adding subclasses), but not directly instantiated. The abstract method is not implemented in the class in which it is declared, but must be overridden in a subclass. Classes that use the abstract method are inherently abstract classes and must be declared abstractly.

2) The class class keyword is used to declare a new Java class, which is a collection of related variables and/or methods. Class is the basic construction unit of object-oriented program design method. A class typically represents some kind of actual entity, such as a geometry or a person. A class is a template for an object. Each object is an instance of the class. To use a class, you typically instantiate an object of the class with the new operator, and then call the class's methods to access the functionality of the class.

3) extends inherited, extended extends keywords are used in class or interface declarations to indicate that the class or interface being declared is a subclass of the class or interface with the extends keyword followed by its name. Subclasses inherit all public and protected variables and methods of the parent class. Subclasses can override any non-final method of the parent class. A class can only extend one other class.

4) Final, immutable final keywords can be applied to a class to indicate that the class cannot be extended (no subclasses). The final keyword can be applied to a method to indicate that this method cannot be overridden in a subclass. A class cannot be both abstract and final. Abstract means that the class must be extended, and final means that the class cannot be extended. A method cannot be both abstract and final. Abstract means that the method must be overridden, and final means that the method cannot be overridden.

5) Implements implementation of the Implements keyword is used in the class declaration to indicate that the declared class provides an implementation of all methods declared in the interface specified by the name after the Implements keyword. The class must provide an implementation of all the methods declared in the interface. A class can implement multiple interfaces.

6) The interface interface interface keyword is used to declare a new Java interface, which is a collection of methods.

Interfaces are a powerful feature of the Java language. Any class can declare that it implements one or more interfaces, which means that it implements all the methods defined in these interfaces.

Any class that implements an interface must provide an implementation of all methods in that interface. A class can implement multiple interfaces.

7) Native local native keyword can be applied to methods to indicate that the method is implemented in a language other than Java.

8) New, create a new keyword to create a fresh instance of the class.

The argument after the new keyword must be a class name, and the class name must be followed by a set of constructor method parameters (which must be enclosed in parentheses).

The parameter collection must match the signature of the constructor method of the class.

= The type of the variable on the left must have an assignment compatibility relationship with the class or interface to be instantiated.

9) Static statics keyword can be applied to an inner class (a class defined in another Class), a method, or a field (a member variable of a class).

Typically, the static keyword means that the entity to which it is applied is available outside any specific instance of the class that declares the entity.

A static (inner) class can be instantiated and referenced by other classes, even if it is a top-level class. In the example above, the code in another class can instantiate the Mystaticclass class by qualifying its name with the class name that contains it, such as Myclass.mystaticclass.

The static field (the member variable of the class) exists only once in all instances of the class.

You can call the static method from outside the class without first instantiating the class. Such a reference always includes the class masterpiece as the qualifier for the method call.

Mode: Public final static <type> VarName = <value>; Typically used to declare class constants that can be used outside of a class. When you reference such a class constant, you need to qualify it with the class name. In the above example, another class can refer to the Max_objects constant in the form of myclass.max_objects.

STRICTFP Strict, accurate strictfp means fp-strict, that is, the meaning of precise floating point. When a Java virtual machine makes a floating-point operation, if the STRICTFP keyword is not specified, the Java compiler and the runtime's expression on floating-point operations take an approximation of their own behavior to accomplish these operations, so that the resulting results are often unsatisfactory. Once STRICTFP is used to declare a class, interface, or method, the compiler and the runtime environment for the declared scope of Java are executed exactly as the floating-point specification IEEE-754. So if you want to make floating-point arithmetic more accurate and not inconsistent with the results of different hardware platforms, then use the keyword STRICTFP.

You can declare a class, interface, and method as STRICTFP, but do not allow the STRICTFP keyword to be declared on methods and constructors in an interface

One) synchronized threads, synchronous synchronized keywords can be applied to methods or statement blocks, and protection is provided for critical snippets of code that should only be executed by a single thread at a time.

The Synchronized keyword prevents key code snippets from being executed by multiple threads at once.

If applied to a static method, the entire class is locked when the method is executed by one thread at a time.

If applied to an instance method, when the method is accessed by one thread at a time, the instance is locked.

If applied to an object or array, the object or array is locked when the associated code block is executed by one thread at a time.

Transient ephemeral transient a keyword can be applied to a member variable of a class to indicate that the member variable should not be serialized when the class instance that contains it is serialized.

When an object is serialized, the value of the transient variable is not included in the serialized representation, whereas the non-transient variable is included.

Java's serialization provides a mechanism for persisting object instances. When persisting an object, there may be a special object data member, and we do not want to use the serialization mechanism to save it.      In order to turn off serialization on a domain of a particular object, you can precede the field with the keyword transient. Transient is a keyword in the Java language that is used to indicate that a domain is not part of the serialization of that object. When an object is serialized, the value of the transient variable is not included in the serialized representation, whereas the non-transient variable is included.

Volatile volatile keywords are used to represent member variables that can be modified asynchronously by multiple threads.

Note: The volatile keyword is not implemented in many Java virtual machines. The purpose of volatile is to ensure that all threads see the same values for the specified variable.

Volatile variables in the Java language can be thought of as a "light synchronized", and volatile variables require less coding and run-time overhead than synchronized blocks, but the functionality they can achieve is only Part of the synchronized.

3. Program Control statements

1) Break jumps out, interrupt keyword is used to exit a for, while or do loop early, or to end a case block in a switch statement.

Break always exits the deepest while, for, do, or switch statement.

2) Continue continues the Continue keyword to jump to the next iteration of the for, while, or do loop.

Continue always jumps to the next iteration of the deepest while, for, or do statement.

3) Returning the return keyword causes the method to return to the method that called it, passing a value that matches the return type of the returned method.

If the method has a return type of non-void, the return statement must have parameters of the same or compatible type.

The parentheses on the sides of the return value are optional.

4) The Do run do keyword is used to specify a loop that checks its condition at the end of each iteration.

Do loop body executes at least once.

The conditional expression must be followed by a semicolon.

5) The While loop while keyword is used to specify a loop that repeats as long as the condition is true.

6) If if keyword indicates conditionally executed code block. The condition must evaluate to a Boolean value.

An If statement can have an optional ELSE clause that contains the code that will be executed when the condition is false.

An expression containing a Boolean operand can contain only a Boolean operand.

7) Else otherwise the Else keyword is always used in conjunction with the IF keyword in the if-else statement. The ELSE clause is optional, and if the IF condition is false, the clause is executed.

8) The For loop for keyword specifies a loop that checks its condition before the end of each iteration.

For statement in the form of for (initialize; condition; increment)

The Initialize statement is executed once when the control flow enters the for statement.

The result of the condition is calculated each time the loop body is executed. If condition is true, the loop body is executed.

After each execution of the loop body, the increment statement is executed before the condition of the next iteration is computed.

9) The instanceof instance instanceof keyword is used to determine the class to which the object belongs.

Switch Watch switch statement is used to select one of several code blocks to execute based on an expression.

The switch condition must evaluate to be equal to Byte, char, short, or int.

The case block does not have an implicit end point. Break statements are usually used at the end of each case block to exit the switch statement.

Without a break statement, the execution stream enters all subsequent case and/or default blocks.

One) case returns the result of the observation case is used to mark each branch in the switch statement.

The case block does not have an implicit end point. Break statements are usually used at the end of each case block to exit the switch statement.

Without a break statement, the execution stream enters all subsequent case and/or default blocks.

The default default keyword is used to mark the defaults branch in a switch statement.

The default block does not have an implicit end point. Break statements are typically used at the end of each case or default block to exit the switch statement when the block is completed.

If there is no default statement, the switch statement whose arguments do not match any case block will not take any action.

4. Error handling 1) The Try catch exception try keyword is used to contain a block of statements that may throw an exception.

Each try block must have at least one catch or finally clause.

If a particular exception class is not handled by any catch clauses, the exception is recursively propagated along the call stack to the next enclosing try block. If none of the enclosing try blocks catch an exception, the Java interpreter exits and displays the error message and stack trace information.

2) Catch handling exception catch keyword is used to define exception handling blocks in Try-catch or try-catch-finally statements.

The start and end tags {and} are part of the catch clause syntax and cannot be omitted even if the clause contains only one statement.

Each try block must have at least one catch or finally clause.

If a particular exception class is not handled by any catch clauses, the exception is recursively propagated along the call stack to the next enclosing try block. If none of the enclosing try blocks catch an exception, the Java interpreter exits and displays the error message and stack trace information.

3) Throw throws an exception object throw keyword is used to throw an exception.

The throw statement takes java.lang.Throwable as a parameter. The throwable propagates up in the call stack until it is captured by the appropriate catch block.

Any method that throws a non-runtimeexception exception must also use the throws modifier in the method declaration to declare the exception it throws.

4) throws declares that an exception may be thrown throws the keyword can be applied to a method to indicate that the method throws a particular type of exception.

The throws keyword takes a comma-delimited list of java.lang.Throwables as arguments.

Any method that throws a non-runtimeexception exception must also use the throws modifier in the method declaration to declare the exception it throws.

To include a call to a method with a throws clause in a try-catch block, you must provide the caller of the method.

5. Package correlation 1) Import imports the Import keyword to make one or all of the classes in a package visible in the current Java source file. You can reference the imported class without using the fully qualified class name.

When multiple packages contain classes with the same name, many Java programmers use only specific import statements (no "*") to avoid uncertainties.

2) The package packages keyword Specifies the Java package where the classes declared in the Java source file reside.

The package statement (if one appears) must be the first non-annotative text in the Java source file.

Example: Java.lang.Object.

If the Java source file does not contain a package statement, the classes defined in the file will be in the default packages. Note that classes in the default package cannot be referenced from classes in non-default packages.

6. Basic Type 1) The Boolean boolean bool is the Java primitive type. The value of the Boolean variable can be true or false.

A Boolean variable can only be a value with true or FALSE. Boolean cannot convert to and from numeric types.

An expression containing a Boolean operand can contain only a Boolean operand.

The Boolean class is the wrapper object class for the Boolean primitive type.

2) Byte byte type byte is the Java primitive type. Byte can be stored in an integer value that is within the range of [-128, 127].

The byte class is a wrapper object class of byte primitive type. It defines the Min_value and Max_value constants that represent the range of values of this type.

All integer values in Java are 32-bit int values, unless the value is followed by L or L (such as 235L), which means that the value should be interpreted as long.

3) Char character char is a Java primitive type. A char variable can store a Unicode character.

You can use the following Char constants: \b-space, \f-page break, \ n-newline, \ r-Carriage return, \ t-horizontal tab, \ '-single quote, \ "-double quote, \ \-Backslash, \xxx-Latin-1 character with XXX encoding. \x and \xx are legal forms, but may cause confusion. \uxxxx-Unicode character with hexadecimal-encoded XXXX.

The Character class contains some static methods that you can use to handle char variables, including isdigit (), Isletter (), Iswhitespace (), and toUpperCase ().

Char value is not signed.

4) Double Doubles is the Java primitive type. A double variable can store dual-precision floating-point values.

Because the floating-point data type is an approximation of the actual numeric value, it is generally not a comparison of whether a floating-point value is equal.

Java floating-point values can represent infinity and NaN (non-numeric). The Double wrapper object class is used to define constants Min_value, Max_value, Negative_infinity, positive_infinity, and NaN.

5) Float floating point float is the Java primitive type. The float variable can store single-precision floating-point values.

The following rules should be followed when using this keyword:

Floating-point literals in Java always default to double precision. To specify a single-precision literal value, add F or F, such as 0.01f, after the value.

Because the floating-point data type is an approximation of the actual numeric value, it is generally not a comparison of whether a floating-point value is equal.

Java floating-point values can represent infinity and NaN (non-numeric). The Float wrapper object class is used to define constants Min_value, Max_value, Negative_infinity, positive_infinity, and NaN.

6) int integer int is the Java primitive type. An int variable can store a 32-bit integer value.

The Integer class is the wrapper object class for an int primitive type. It defines the Min_value and Max_value constants that represent the range of values of this type.

All integer values in Java are 32-bit int values, unless the value is followed by L or L (such as 235L), which means that the value should be interpreted as long.

7) A long length integer is the Java primitive type. A long variable can store a 64-bit signed integer.

The long class is a long primitive type of wrapper object class. It defines the Min_value and Max_value constants that represent the range of values of this type.

All integer values in Java are 32-bit int values, unless the value is followed by L or L (such as 235L), which means that the value should be interpreted as long.

8) Short is a Java primitive type. The short variable can store 16-bit signed integers.

The short class is the wrapper object class for the short primitive type. It defines the Min_value and Max_value constants that represent the range of values of this type.

All integer values in Java are 32-bit int values, unless the value is followed by L or L (such as 235L), which means that the value should be interpreted as long.

9) NULL NULL is a reserved word for Java, indicating no value.

Assigning NULL to a non-primitive variable is equivalent to releasing the object previously referenced by the variable.

You cannot assign null to the original type (byte, short, int, long, char, float, double, Boolean) variables.

True True the keyword represents one of the two valid values of a Boolean variable.

False false the keyword represents one of the two legal values of a Boolean variable.

7. Variable reference 1) Super Parent class, the super-class Super keyword is used to refer to the superclass of the class that uses the keyword.

As a stand-alone statement, super represents the construction method that calls the superclass.

Super.<methodname> () represents the method that calls the superclass. You need to use this usage only if you want to invoke a method that is overridden in the class to specify that the method should be called in the superclass.

2) This class The This keyword is used to refer to the current instance.

You can use the This keyword to refer to the current instance when the reference may be ambiguous.

3) void no return value void keyword denotes a null type.

Void can be used as the return type of a method to indicate that the method does not return a value.

8. It is important to retain words that correctly identify the Java language's keywords (keyword) and reserved words (reserved word). 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. Reserved words are keywords reserved for Java, although they are not now keywords, but are likely to be keywords in later versions of the upgrade.

Identify the keywords in the Java language, and do not confuse other languages such as C + + keywords. Const and Goto are reserved words for Java. All the keywords are lowercase

1) Goto Jump goto preserves the keyword, but has no effect. Structured programming completely does not require a goto statement to complete a variety of processes, and the use of the goto statement tends to make the program less readable, so Java does not allow Goto jump.

2) const static const reserved Word, is a type modifier, object declared with const cannot be updated. Something similar to final.

3) Native native Java is not perfect, Java is not enough to run faster than the traditional C + + slower, Java can not directly access to the operating system underlying (such as system hardware, etc.), for this Java uses the native method to extend the functionality of Java programs.

The native method can be likened to the Java program's interface to the C program, and its implementation steps:

1, declare the native () method in Java, and then compile;

2. Create an. h file with Javah;

3, write a. cpp file to implement the native export method, which needs to include the second step produced by the. h file (Note that it also contains the JDK jni.h file);

4, the third step of the. cpp file is compiled into a dynamic link library file;

5, in Java with the System.loadlibrary () method to load the fourth step generated by the dynamic link library file, the native () method can be accessed in Java.

1.Java keywords and reserved words

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.