
A snippet of Java code with keywords highlighted in blue and bold font
In the Java programming language, a keyword is any one of 68 reserved words that have a predefined meaning in the language. Because of this, programmers cannot use keywords in some contexts, such as names for variables, methods, classes, or as any other identifier. Of these 68 keywords, 17 of them are only contextually reserved, and can sometimes be used as an identifier, unlike standard reserved words. Due to their special functions in the language, most integrated development environments for Java use syntax highlighting to display keywords in a different colour for easy identification.
abstract
A method with no definition must be declared as assert
Assert describes a predicate (a true–false statement) placed in a Java program to indicate that the developer thinks that the predicate is always true at that place. If an assertion evaluates to false at run-time, an assertion failure results, which typically causes execution to abort. Assertions are disabled at runtime by default, but can be enabled through a command-line option or programmatically through a method on the class loader.
See assertion.
- false. In most other languages (such as C/C++, C#, and Rust), the Boolean type is usually simply called break
- Used to end the execution in the current loop body.
- Used to break out of a byte keyword is used to declare a variable or return type that can hold an 8-bit signed two's complement integer. As a wrapper class, it becomes switch block can be labeled with one or more switch statement evaluates its expression, then executes all statements that follow the matching catch
- Used in conjunction with a catch block specify what to do if a specific type of exception is thrown by the java.lang.Object. The class keyword can also be used in the form String.class can be used instead of doing continue resumes execution at the end of the enclosing labeled loop body.
- See continue statement.
- case matches the specified value; see default keyword can be used to allow an interface to provide an implementation of a method.
- while to create a do-while loop, which executes a block of statements associated with the loop and then tests a boolean expression associated with the false.
- See do while loop.
- java.lang.Double.
- if to create an if-else statement, which tests a boolean expression; if the expression evaluates to false, the block of statements associated with the java.lang.Enum.
- final class cannot be subclassed, a final.
- See final (Java).
- finally block is executed after execution exits the try or float
- The for
- The false.
- The java.lang.Iterable object; each iteration of the loop executes the associated block of statements using a different element in the array or java.lang.Iterable<T>.
- true, the block of statements associated with the if statement is executed. See import
- Used at the beginning of a source file to specify classes or entire Java packages to be referred to later without including their package names in the reference. Since J2SE 5.0, importmodule), automatically importing all exported packages.
- int
- The interface
- Used to declare an interface that only contains abstract or default methods, constant (implements keyword. As multiple inheritance is not allowed in Java, interfaces are used to circumvent it. An interface can be defined within another interface.
- new
- Used to create an instance of a class or array object.
- See Java object lifetime.
- private
- The protected keyword is used in the declaration of a method, field, or inner class; protected members can only be accessed by members of their own class, that class's subclasses or classes from the same package.
- See access modifiers.
- return
- Used to finish the execution of a method. It can be followed by a value required by the method definition that is returned to the caller.
- See return statement.
- static also is used to define a method as a class method. Class methods are bound to the class instead of to a specific instance, and can only operate on class fields. Classes and interfaces declared as super keyword is also used to forward a call from a constructor to a constructor in the superclass.
- Also used to specify a lower bound on a type parameter in Generics.
- See inheritance.
- case and case. If no yield to create switch expressions.
- synchronized.
- this keyword is also used to forward a call from one constructor in a class to another constructor in the same class.
- java.lang.Error or transient
- Declares that an instance field is not part of the default serialized form of an object. When an object is serialized, only the values of its non-transient instance fields are included in the default serial representation. When an object is deserialized, transient fields are initialized only to their default value. If the default form is not used, e.g. when a serialPersistentFields table is declared in the class hierarchy, all java.io.Serializable, but not if it implements try block, an optional try block and catch clause or a void keyword is used to declare that a method does not return any value. As a wrapper class, it becomes volatile, nor can local variables or parameters. Note that in C and C++, while keyword is used to create a while loop, which tests a boolean expression and executes the block of statements associated with the loop if the expression evaluates to do.
The following words are reserved as keywords, but currently have no use or purpose.
- const is typically used to define constants. For defining constants in Java, see the goto
- Although reserved as a keyword in Java, strictfp
- Although reserved as a keyword in Java, module
- Declares a module (a collection of related packages and resources that can be treated as a unit), used to encapsulate and expose only the public API of a library.
- See Java Platform Module System.
- opens
- Used to open a specific package for reflection to other modules.
- record
- A special kind of class that acts as a transparent carrier of immutable data, automatically providing equals(), hashCode(), and toString() methods. Records all implicitly inherit from sealed
- A sealed class or interface can only be extended or implemented by classes and interfaces permitted to do so.
- See sealed class.
- transitive
- Used with the var
- A special identifier that cannot be used as a type name (since Java 10). Used to declare a variable without explicitly specifying the type, rather relying on the compiler to infer the type based on the initialiser.
- See type inference.
- with
- Used with the caseL:).
Reserved words for literal values
edit
The following words refer to literal values used by the language.
- null
- A reference literal value of null.