Java _ keywords

Source: Internet
Author: User

The Java keywords are as follows:

Abstract Default If Private This
Boolean Do Implements Protected Throw
Break Double Import Public Throws
Byte Else Instanceof Return Transient
Case Extends Int Short Try
Catch Final Interface Static Void
Char Finally Long Strictfp Volatile
Class Float Native Super While
Const For New Switch  
Continue Goto Package Synchronized  

The above are the keywords defined in Java specifications, a total of 48, three of which seem to be Keywords of true, false, null, are not keywords, but as a separate identification type.

Among them, the uncommon keywords are: const, Goto, native, strictfp, transient, volatile.

Const and goto are reserved words in Java.

Native

To put it simply, a native method is a Java interface that calls non-Java code. A native method is such a Java method: the implementation of this method is implemented by a non-Java language, such as C. This feature is not unique to Java. Many other programming languages use this mechanism, for example, in C ++, you can use extern "c" to notify the C ++ compiler to call a C function.

The identifier native can be used with all other Java identifiers, except abstract. This is reasonable, because native implies that these methods have implementation bodies, but these implementations are non-Java, but abstract clearly specifies that these methods have no implementation bodies.

Strictfp

Strictfp, that is, strict float point (precise floating point ).
The strictfp keyword can be applied to classes, interfaces, or methods. When a method is declared using the strictfp keyword, all float and double expressions in the method strictly abide by the restrictions of FP-strict and comply with the IEEE-754 specification. When the strictfp keyword is used for a class or interface, all the code in the class, including the initial set value and code in the nested type, will be strictly calculated. Strict constraints mean that the results of all expressions must be the result expected by the IEEE 754 algorithm for the operands, expressed in a single-precision and double-precision format.
If you want to make your floating point operations more accurate and do not execute inconsistent results on different hardware platforms, you can use the keyword strictfp.

Transient

Variable modifier. If an instance variable is declared with transient, its value does not need to be maintained during object storage.
Java serialization provides a mechanism for persistence object instances. When a persistent object is stored, there may be a special object data member. We do not want to use the serialization mechanism to save it. To disable serialization on a domain of a specific object, you can add the keyword transient before this domain. When an object is serialized, the value of the transient variable is not included in the serialized representation. However, non-transient variables are included.

Volatile

Like the more familiar const, volatile is a type modifier ). It is designed to modify variables accessed and modified by different threads. If there is no volatile, it will basically lead to the following results: either you cannot write multi-threaded programs, or the compiler loses the chance of a lot of optimization.

Final

Final can be modifiedNon-Abstract variable,Non-abstract method,Non-abstract class

Final modified class:

  • The final class cannot be inherited.
  • The variables and methods in the final class are final by default.

Final modified variables:

  • The final variable is a constant and cannot be assigned a value.
  • Final variables (if not private) can be inherited

Final modification method:

  • The final method (if not private) can be inherited.
  • The final method cannot be rewritten.

(The default private method is final, because the private method cannot be inherited or rewritten. However, you can add a final modifier to the private method, but this does not make sense)

Static

Static is an area allocated in the memory for the entire class. That is to say, no matter how many instances the class has, the static variables of these instances are shared.

Static variables and methods can also be called directly through classes without calling an instance of classes.

Static can be modifiedVariable,Method,Code block,Class. (The static modifier class is special. The static modifier can only modify internal classes)

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.