What are the Java keywords?

Source: Internet
Author: User
Tags java keywords

What are the Java keywords?

Keywords of Java [Personal arrangement]

Keyword Overview:
-----------
Abstract, assert, boolean, break, byte, case, catch, char, class, continue, default, do, double, else, enum, extends, final, finally, float,, if, implements, import, instanceof, int, interface, long, native, new, package, private, protected, public, return, strictfp, short, static, super, switch, synchronized, this, throw, throws, transient, try, void, volatile, while

 

Keyword explanation:
-----------
Package declares the package (folder) where the class is located)

Import the import package and import the API class library.

Byte bytes (8 bits) (range:-128 ~ 127)

Short INTEGER (16 bits) (range:-32768 ~ 32767)

Int INTEGER (32-bit) (range:-2147483648 ~ 2147483647)

Long integer (64-bit) (range:-923372036854775808 ~ 923372036854775807)

Float Single-precision floating point number (32-bit) (range: 1.4E45 ~ 3.4028235E38)

Double-precision floating point number (64-bit) (range: 4.9E324 ~ 1.7976931348623157E308)

Char (16 characters) (range:-32768 ~ 32767)

Boolean (8 bits) (range: true or false)

Public (permission modifier) public and public

This indicates the class object itself.

Super indicates the parent class Object (if a parent class exists)

A keyword used by finally to pair with try exceptions. (No matter whether the try-catch statement is abnormal, the code inside the keyword block is executed)

Abstract (modifier) abstract object (can be used for classes and methods)

Continue to the end of the loop

Throw an exception

Throws may throw an exception statement.

Return

Break bounce cycle

For Loop statement

Static (modifier) static

Create an instance/Object

Interface (modifier) declares an interface

If logical condition judgment statement

Gotojava reserved words cannot be used in java

Constjava reserved words cannot be used in java

Default and switch are used in pairs. (if no matching identifier is found, the code of this keyword block is executed)

Do and while Pairs

Use case and switch pairs. (when the parameters passed by the switch are the same as the case identifier, the code of this keyword block is executed)

Strictfp (modifier) exact floating point (this modifier is added to a class, interface, or method to make floating point operations more accurate)

Void (modifier) NULL return value

Try to catch the exception keyword and use it with catch.

Switch select the structure statement. (Match the id after case based on the input parameters, and execute the code after the case block)

Keyword of the else logical condition judgment statement branch structure, which is used together with if

Catch one of the exception keywords (if an exception is caught, the program executes the code of this statement block)

Implements implementation Interface

Private (permission modifier) private

Final (modifier) is used to declare constant (final state) fields, methods, classes, etc.

Class (modifier) Declaration class

Extends implementation class inheritance

Keyword of a slightly weaker volatile JAVA synchronization mechanism

While loop statement

Synchronuzed (modifier) Lock (when two concurrent threads access the same object, only one thread can be executed within a time period, the other thread must wait until the current thread finishes executing this code block before executing this code block)

Instanceof determines whether the object on the left is an instance of the class on the right of the object.

In addition to the package, class, and subclass, protecte (permission modifier) cannot access this object.

Transient automatically serializes the object (use this keyword to modify an attribute. the lifecycle of this attribute exists only in the caller's memory and will not be written to the disk for persistence)

True | false | nullJava Literal Value

 

Keyword details:
---------------
Keywords are pre-defined in computer languages. They have special identifiers, sometimes reserved words, and special variables.

Java keywords have special significance for java compilers. They are used to represent a data type or program structure, the keyword cannot be used as a variable name, method name, class name, or package name.

Abstract

Keywords in a Java language are used in class declaration to indicate that a class cannot be instantiated, but can be inherited by other classes. An abstract class can use abstract methods. abstract methods do not need to be implemented, but must be implemented in subclasses.

Break

A Java keyword that is used to change the Program Execution Process and immediately starts execution from the next sentence of the current statement. If there is a tag next to it, it will be executed from where the tag corresponds. It is used to interrupt the execution of the program. It is generally used in loop statements to jump out of this layer of loop and go to execute the following program.

Case

Java keywords are used to define a set of Branch selection. If a value is the same as the value given in the switch, it is executed from this branch.

Catch

A keyword of Java, used to declare a block that runs when a runtime error or non-runtime exception occurs in the try statement block.

Char

A keyword of the Java language used to define a character type.

Int

A keyword of the Java language used to define an integer type data or variable.

For

A keyword of the Java language is a frequently used keyword in the loop structure, in the form:

For (expression 1; expression 2; expression 3)
{
// Code block
}

Expression 1 is used to assign values to corresponding variables, expression 2 is a condition judgment statement, and expression 3 is a loop control statement.

If

A keyword in Java is used to determine conditions.

This section describes how to edit and collapse data.
Class and Interface

Abstract to be an abstract or a member in an abstract class must be implemented through a class derived from the abstract class.

Class,

Format:

Class name extends parent class name {

Attribute declaration and initialization; method declaration and method body;

}

Implements implementation

Import

Interface.

Format:

Interface name [extends parent interface list]

[Public] [static] [final] attribute type attribute name = constant value; java keyword
Java keywords

[Public] [abstract] Return Value Type method name (parameter list );

Package. The declaration only specifies the package of the class defined in the file.

Static attributes are used to describe the attributes shared by all objects in a class.

Throws are thrown. An exception occurs in a method but is not captured. The method header declaration is handled by the method caller. // Other statements are not allowed after throw.

Void is empty

Data Type

Boolean values can only be true or false, instead of 0 or 1, and must be in lower case.

Byte type

Char character type

Double Floating Point Type

Float Single-precision floating point

Int integer

Long Integer

Short integer

Process Control

The break interrupts the execution of the switch statement. In the loop statement, it also ends the execution of the loop statement.

Continue only jumps out of this loop and continues to execute the next loop. The break exists completely or is marked as a loop.

Do and while are used together,

Format:

Do {

Loop body;

} While (loop condition); // do not forget the semicolon;

For

Format:

For (expression 1; expression 2; expression 3 ){

Loop body ;}

If final does not want a class to be inherited by another class, you must use the modifier final to indicate that a class is the ultimate class and cannot be a parent class.

If

Format:

If (conditional expression)

{Function code block 1}

Else

{Function code block} // if the return value of the conditional expression is true, the function block is executed. Otherwise, the else function block is executed.

Return

Switch

Format:

Switch (expression ){

Case value 1:

Function Code 1;

[Break;]

Case value 2:

Function Code 2;

[Break;];

......

Case value n:

Function Code n;

[Break;]

Default: Function Code others ;}

While

Format:

While (loop condition)

{Loop body ;}

Access Scope

Private: Private statements are used at the module level to declare private variables and allocate buckets.

Default access control (package). If no access permission modifier is added before the member variables and methods, it is called default access control or package access control. This means that all other classes in the same package can access this member, but not all classes outside the package.

Protected indicates that the modified member variables are of the protection type, which is the same in the same package as the public type and accessible. However, if the member variables of the protected type in different packages can only be accessed through subclasses, this modifier is different from other modifiers.

Public indicates that a variable or function is a global function. For example, publicinta indicates that the integer variable a is a global variable.

Class instance

New this clause creates a new object instance. The New clause must specify a defined class that can be used to create an instance. You can use New in declaration or value assignment statements. When this statement is executed, it calls the constructor of the specified class and passes all provided parameters.

This references a property. When a parameter in a method has the same name as a property, this is a local variable with priority and the property is hidden. However, sometimes in order to be able to use hidden attributes in the method, we can use this to distinguish between attributes, which are referenced by this. If this is not referenced, it is a local variable or a parameter.

The super inherited class is called a superclass, And the inherited class is called a subclass.

Others

1. catch the wrong statement.

2. finally is designed to complete the executed code, mainly for the robustness and integrity of the program. The code is executed no matter whether exceptions occur.

3. native is a method modifier. The Native method is a local method implemented by another language (such as c/c ++, FORTRAN, assembly. Because methods are implemented externally, they do not need to be declared in java code, which is somewhat similar to interface methods. Native can be used with other modifiers, but abstract and Interface methods cannot be modified using native.

4, strictfp modifier class and method, meaning FP-strict, precise floating point, in line with IEEE-754 specifications. When a class or interface is declared using strictfp, all internal float and double expressions will become strictfp. Interface method cannot be declared as strictfp, and class can.

5. When a line of code in the try clause encounters an exception, the program will be terminated and the catch clause will be redirected to execute.

6. transient variable modifier. Variables marked as transient are not persistent during object storage. When the object is serialized and stored in the memory, some field data is not expected to be saved. To ensure security, you can declare these fields as transient.

7. Modify the variable volatile. Every time a thread is accessed, the value of the member variable is forcibly re-read from the shared memory. In addition, when the member variables change, the thread is forced to write the change value back to the shared memory. In this way, two different threads always see the same value of a member variable at any time.

8. Although the goto keyword table in the goto and java keywords have the goto keyword, this word cannot be used when declaring the variable because goto is a unused keyword in Java, you can also use reserved words.

Generally, structured programs do not need to use the Goto statement. After branch, loop, or recursive call, goto can be completely unavailable. To simplify the program code, break and continue are also used to redirect the loop structure. In addition, both break and continue can carry tags, which increases their flexibility.

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.