Keywords in Java_ Power node Java college sorting

Common keywords in Java:

Related to data type (10)

Related to process control (13)

If: indicates conditional judgment, General usage if (relational expression), followed by else or {...} else: conditional transition, such as if (relational expression) {statement block 1} else {statement block 2}. If the value of relational expression is true, statement block 1 will be executed, otherwise statement block 2 will be executed. Do... While...: do and while are generally used together to represent circular statements. Do {...} while (relational expression)...; when the value of the relational expression is true, the loop continues. For: used to represent the loop. For loop is the most commonly used loop. The format for (expression a; expression B; expression C) the book in parentheses is usually used to control the number of loops. It is generally counted with a variable class of type int, such as (int i = 0; I < 10; I + +) expression a is used for the start value of process control, expression B represents the loop termination condition, and expression C is used for counting. Switch (condition a) case...: switch and case are used together to represent the conditional branch process. For example:

If C is 1, execute statement block 1; If C is 2, execute statement block 2; And so on, if C is n, the statement block n is executed. Default indicates what happens except case.

Default: it can be seen from the switch... Case... Branch statement that default is used when all case conditions are not tenable. Used to represent the current package under s "RC" folder; If used for a class, it means that it can only be accessed by other classes in this file.

Break: used to end this layer loop or jump out of a layer loop.

Continue: used to jump out of the current loop and break out of the current loop. Break and continue can realize the usage similar to goto statement in C \ C + +: label0:

Return: returns a value, which is usually used in functions to return a value of a specific type. For example:

Try {...} places a statement block that may cause exceptions. Catch() {...} is used to catch exceptions, and {} defines the handling method when exceptions occur. Finally {...} means that the processing in finally {} must be carried out regardless of whether the exception occurs or not.

Modifier related (12)

Access rights for different access modifiers

For example, there can only be one public class in a file with ". Java" suffix. Such as com There is HelloWorld under the bjpowernode package Java file with the following code:

There are the following codes under the default package:

At this time, it runs normally, and the result is: HelloWorld! If you change the public class HelloWorld to privateclass HelloWorld, you will run an error because private is private and cannot be referenced by objects in other packages.

Final: (similar to const in C + +), the usage is as follows: a. the value of the variable of final cannot be changed; b. The method of final cannot be overridden; c. The class of final cannot be inherited.

Void: null type, used to represent null return value before function.

Static: can be used to define static member variables or methods

Strict FP: it means FP strict, which means exact floating point. When the Java virtual machine performs floating-point operations, if the strictfp keyword is not specified, the java compiler and the running environment take a behavior similar to their own way to complete these operations on the expressions of floating-point operations, so that the results often can not satisfy you. Once strictfp is used to declare a class, interface or method, the java compiler and running environment within the declared scope will be executed in full accordance with the floating-point specification IEEE-754. Therefore, if you want to make your floating-point operation more accurate and not because the results executed by different hardware platforms are inconsistent, please use the keyword strictfp. You can declare a class, interface and method as strictfp, but you are not allowed to declare the strictfp keyword on the methods and constructors in the interface, such as the following code:

1. Legally use the keyword strictfp

2. Wrong usage

Once the keyword strictfp is used to declare a class, interface or method, all floating-point operations within the declared range of this keyword are accurate and comply with IEEE-754 specification. For example, if a class is declared as strictfp, all methods in the class are strictfp.

Abstract: the meaning of abstraction can be used to define abstract classes and abstract functions. The usage rules of an abstract class are as follows: A. when a class is modified with the abstract keyword, the class is called an abstract class; When a method is modified with abstract, it is called abstract method; b. Classes containing abstract methods must be declared as abstract classes, abstract classes must be inherited, and abstract methods must be overridden; c. Abstract classes cannot be instantiated; d. Abstract methods only need to be declared, not implemented.

Transient: a keyword of the Java language used to indicate that a domain is not part of the serialization of the object. When an object is serialized, the values of transient variables are not included in the serialized representation, while non transient variables are included. Use object: field introduction: a field is not a persistent part of an object and should not be concatenated with an object.

Synchronized: lock the current object. Other threads are not allowed to interrupt the insertion when executing the current object. This is the note I made during my summer vacation

(1),

(2),

Volatile: volatile variables are accessible to only one thread at a time. Ensure thread safety. These valid values that can be written to volatile variables are independent of the state of any program, including the current state of the variable. Therefore, volatile variable is a very simple but fragile synchronization mechanism, which will provide better performance and scalability than lock in some cases.

Native: it is used for cooperation between Java and other languages (such as C + +), that is, the implementation of the function after native is not written in Java. Native means to notify the operating system. You must implement this function for me because I want to use it. Therefore, the functions of the native keyword are implemented by the operating system, and Java can only be called.

Action related (10)

Package: package, write the Java program in a package.

Import: Import Registration. Usage: A. write the full package name: jsxt java140. Cat c = new com. bjsxt. java140. Cat a, introduce a specific object in a package: XT java140. Cat; b. Introduce all objects in a package: import com bjsxt. java140. Cat.*;

Throw: throw user-defined exception

Throws: throws system exceptions

Extensions: inheritance (class inherits class or interface inherits interface)

Implements: implements the interface through classes

This: is the identifier pointing to the object itself

Super: call the constructor of the base class

Instanceof: judge whether an object is the object you want

New: used to create a new object, that is, the instantiation of a class

Others (5)

True: indicates the true value of boolean type

False: indicates the false value of boolean type, that is, it is not tenable

Null: indicates a null value. If it is an object, it indicates that the object is null. If it is a data type, it indicates the default value of the corresponding data type. For example, the default value of int is 0.

Goto: unconditional turn statements are implemented in C \ C + +. They are generally not used in Java for structured programming.

Const: like const, in Java, const is used as a reserved word for expansion. Const can be replaced by final. Const is generally used in C + + and final in Java.

The content of this article comes from the network collection of netizens. It is used as a learning reference. The copyright belongs to the original author.
THE END
分享
二维码
< <上一篇
下一篇>>