A brief description of common JAVA keywords and their usage
Abstract: Abstract is a keyword in the Java language, used in class declarations 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 they need to be implemented in subclasses.
break: A Java keyword used to change the program execution flow and immediately start execution from the next sentence of the current statement. If it is followed by a label, execution starts from the location corresponding to the label.
case: A keyword in the Java language, used to define a set of branch choices. If a certain value is the same as the value given in switch, execution will start from that branch.
catch: A keyword in 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 in the Java language, used to define a character type
continue: A Java keyword used to interrupt the current loop process and restart execution from the end of the current loop. If it is followed by a label, execution starts from the place corresponding to the label.
do: A Java language keyword used to declare a loop. The end condition of this loop can be set through the while keyword.
double: A keyword in the Java language used to define a variable of type double
else: A keyword in the Java language that will be executed if the condition of the if statement is not met.
final: A keyword in the Java language. You can only define an entity once and cannot change it or inherit from it later. More strictly speaking: a final-modified class cannot be subclassed, a final-modified method cannot be overridden, and a final-modified variable cannot change its initial value.
finally: A keyword in the Java language that is used to execute a piece of code regardless of whether an exception or runtime error occurs in the previously defined try statement.
float: a Java language keyword used to define a floating point variable
for: A Java language keyword used to declare a loop. Programmers can specify statements to loop through, derive conditions, and initialize variables.
if: A keyword in the Java programming language, used to generate a conditional test. If the condition is true, the statement under if is executed. implements A keyword in the Java(TM) programming language that is optional in a class declaration and is used to indicate the interface that the current class implements.
import: A keyword in the Java(TM) programming language that specifies a class or the entire package that will be referenced later at the beginning of the source file, so that there is no need to add the name of the package when using it.
instanceof: A two-operand Java(TM) language keyword used to test whether the runtime type of the first parameter is compatible with the second parameter.
int: a keyword in Java(TM) used to define an integer variable
class: A keyword in Java(TM) used to define a series of methods and constants. It can be implemented by a class through the implements keyword.
long: A keyword in the Java language, used to define a long type variable.
private: A keyword in the Java language, used in the declaration of methods or variables. It means that this method or variable can only be accessed by other elements of this class.
protected: A keyword in the Java language, used in the declaration of methods and variables, which indicates that this method or variable can only be accessed by elements in the same class, a subclass, or a class in the same package.
public: A keyword in the Java language, used in the declaration of methods and variables, which indicates that this method or variable can be accessed by elements in other classes.
return: A keyword in the Java language, used to end the execution of a method. It can be followed by a value required in the method declaration.
short: A keyword in the Java language, used to define a variable of type short.
static: A keyword in the Java language, used to define a variable as a class variable. A class maintains only one copy of a class variable, regardless of how many instances of the class currently exist. "static" can also be used to define a method as a class method. Class methods are called by the class name rather than a specific instance, and can only operate on class variables.
this: A keyword in the Java language, used to represent an instance of the class in which it appears. this can be used to access class variables and class methods.
throw: A keyword in the Java language that allows users to throw an exception object or any object that implements throwable
throws: A keyword in the Java language, used in the method declaration to indicate which exceptions are not handled by this method, but submitted to a higher level of the program.
transient: A keyword in the Java language used to indicate that a field 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, whereas non-transient variables are included.
try: A keyword in the Java language, used to define a block of statements that may throw exceptions. If an exception is thrown, an optional catch block handles the exception thrown in the try block. At the same time, a finally block will be executed regardless of whether an exception is thrown.
void: A keyword in the Java language, used in a method declaration in the Java language to indicate that this method does not have any return value. "void" can also be used to express a statement without any function.
volatile: A keyword in the Java language, used in the declaration of a variable to indicate that the variable is modified asynchronously by several threads running at the same time.
while: A keyword in the Java language, used to define a loop statement that is executed repeatedly. The loop's exit condition is part of the while statement.
About break and continue
The continue statement is related to the break statement, but is less used. The continue statement is used to start the next loop of the for, while or do-while statement in which it is located. In the while and do-while statements, the execution of the continue statement means the immediate execution of the test part; in the for loop statement, the execution of the continue statement means passing control to the increment part.
About goto and const
These two keywords are reserved keywords in C++ and cannot be used in Java currently. If they appear in a Java program, the compiler will recognize them and generate an error message.
Java has 50 keywords, they are:
abstract do implements private throw Boolean double import protected throws break else instanceof public transient byte extends int return true case false interface short try catch final long static void char finally native super volatile
class float new switch while
continue for null synchronized const
default if package this gotoJava keyword list (51 groups in total in alphabetical order):
abstract, assert,boolean, break, byte, case, catch, char, class, const, continue, default, do, double, else, enum,extends, final, finally, float, for, if, implements, import, instanceof, int, interface, long, native, new, package, private, protected, public, return, short, static, strictfp, super, switch, synchronized, this, throw, throws, transient, try, void, volatile, while
Java reserved word list (a total of 14 groups in alphabetical order): Java reserved words are not used in existing Java versions but may be used as keywords in future versions.
byValue, cast, false, future, generic, inner, operator, outer, rest, true, var, goto, const,null
Haha, regardless of anything else, here are a few questions first, you are so right^_^
1, which of the following are keywords or reserved words in java?
a) if b)then c)goto d)while e)case f)sizeof
2, which of the following are java key words?
a)double b)Switch c)then d)instanceof
3, which of these are key words in java?
a) default b)NULL c)String d)throws e)long f)true
The answer is 1, acde 2, ad 3, adef. Did you do it right? ^_^
Here comes the explanation: 1. Then and sizeof are not keywords of Java. Experts who are familiar with c or c++ and are used to writing asp should be careful.
2. All keywords are in lowercase, so Switch is not a keyword. instanceof looks like a method name, but it is actually a keyword;
3. Capital NULL is not a keyword in the Java language. String is the class name of a package class in the Java language, and it is not a keyword.
Let’s talk about the system again:
It is very important to correctly identify the keywords and reserved words of the Java language. Java keywords have special meaning to the Java compiler. They are used to represent a data type, or to represent the structure of a program, etc. Reserved words are keywords reserved for Java. Although they are not used as keywords now, they may be used as keywords in future upgraded versions.
keyword list
abstract boolean break byte case
catch char class continue default
do double else extends false
finally finally float for if
implements import instanceof int interface
long native new null package
private protected public return short
static super switch synchronized this
throw throws transient true try
void volatile while
Reserved words const, goto
Note
Identify the keywords of the Java language and do not confuse them with the keywords of other languages such as c/c++.
const and goto are reserved words in Java.
All keywords are lowercase friendly, sizeof is not a java keyword