Jump to content

List of Java keywords

From Wikipedia, the free encyclopedia

Template:Short description

File:Java keywords highlighted.svg
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[1] 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.[2] 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.

Reserved keywords

The following words are reserved keywords and cannot be used as identifiers under any circumstances.

<syntaxhighlight lang="java" inline>_</syntaxhighlight>
An underscore is used in place of an identifier of a variable (or pattern) when that variable (or pattern) goes unused.[3]
<syntaxhighlight lang="java" inline>abstract</syntaxhighlight>
A method with no definition must be declared as <syntaxhighlight lang="java" inline>abstract</syntaxhighlight> and the class containing it must be declared as <syntaxhighlight lang="java" inline>abstract</syntaxhighlight>. Abstract classes cannot be instantiated. Abstract methods must be implemented in the subclasses. The abstract keyword cannot be used with variables or constructors. Note that an abstract class is not required to have an abstract method at all.
See abstract type.
<syntaxhighlight lang="java" inline>assert</syntaxhighlight>
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.[4]
See assertion.
<syntaxhighlight lang="java" inline>boolean</syntaxhighlight>
Defines a boolean variable or return type for the values "<syntaxhighlight lang="java" inline>true</syntaxhighlight>" or "<syntaxhighlight lang="java" inline>false</syntaxhighlight>" only. By default, the value of boolean primitive type is <syntaxhighlight lang="java" inline>false</syntaxhighlight>.[5][6] In most other languages (such as C/C++, C#, and Rust), the Boolean type is usually simply called <syntaxhighlight lang="cpp" inline>bool</syntaxhighlight>. As a wrapper class, it becomes Template:Javadoc:SE.
<syntaxhighlight lang="java" inline>break</syntaxhighlight>
Used to end the execution in the current loop body.
Used to break out of a <syntaxhighlight lang="java" inline>switch</syntaxhighlight> block.
See break statement.
<syntaxhighlight lang="java" inline>byte</syntaxhighlight>
The <syntaxhighlight lang="java" inline>byte</syntaxhighlight> keyword is used to declare a variable or return type that can hold an 8-bit signed two's complement integer.[6][5]Template:SfnTemplate:Sfn As a wrapper class, it becomes Template:Javadoc:SE.
<syntaxhighlight lang="java" inline>case</syntaxhighlight>Template:Anchor
A statement in the <syntaxhighlight lang="java" inline>switch</syntaxhighlight> block can be labeled with one or more <syntaxhighlight lang="java" inline>case</syntaxhighlight> or <syntaxhighlight lang="java" inline>default</syntaxhighlight> labels. The <syntaxhighlight lang="java" inline>switch</syntaxhighlight> statement evaluates its expression, then executes all statements that follow the matching <syntaxhighlight lang="java" inline>case</syntaxhighlight> label; see <syntaxhighlight lang="java" inline>switch</syntaxhighlight>.[7]Template:Sfn
See switch statement.
<syntaxhighlight lang="java" inline>catch</syntaxhighlight>
Used in conjunction with a <syntaxhighlight lang="java" inline>try</syntaxhighlight> block and an optional <syntaxhighlight lang="java" inline>finally</syntaxhighlight> block. The statements in the <syntaxhighlight lang="java" inline>catch</syntaxhighlight> block specify what to do if a specific type of exception is thrown by the <syntaxhighlight lang="java" inline>try</syntaxhighlight> block.
See Java exception handling syntax.
<syntaxhighlight lang="java" inline>char</syntaxhighlight>
Defines a character variable or return type capable of holding any character of the Java source file's character set.[6][5] As a wrapper class, it becomes Template:Javadoc:SE.
<syntaxhighlight lang="java" inline>class</syntaxhighlight>
A type that defines the implementation of a particular kind of object. A class definition defines instance and class fields, methods, and inner classes as well as specifying the interfaces the class implements and the immediate superclass of the class. If the superclass is not explicitly specified, the superclass is implicitly Template:Javadoc:SE. The class keyword can also be used in the form <syntaxhighlight lang="java" inline>X.class</syntaxhighlight> to get a java.lang.Class<X> object without needing an instance of that class (see Template:Javadoc:SE). For example, <syntaxhighlight lang="Java" inline>String.class</syntaxhighlight> can be used instead of doing <syntaxhighlight lang="Java" inline>new String().getClass()</syntaxhighlight>.
<syntaxhighlight lang="java" inline>continue</syntaxhighlight>
Used to resume program execution at the end of the current loop body. If followed by a label, <syntaxhighlight lang="java" inline>continue</syntaxhighlight> resumes execution at the end of the enclosing labeled loop body.
See continue statement.
<syntaxhighlight lang="java" inline>default</syntaxhighlight>Template:Anchor
The <syntaxhighlight lang="java" inline>default</syntaxhighlight> keyword can optionally be used in a switch statement to label a block of statements to be executed if no <syntaxhighlight lang="java" inline>case</syntaxhighlight> matches the specified value; see <syntaxhighlight lang="java" inline>switch</syntaxhighlight>.[7]Template:Sfn Alternatively, the <syntaxhighlight lang="java" inline>default</syntaxhighlight> keyword can also be used to declare default values in a Java annotation. From Java 8 onwards, the <syntaxhighlight lang="java" inline>default</syntaxhighlight> keyword can be used to allow an interface to provide an implementation of a method.
<syntaxhighlight lang="java" inline>do</syntaxhighlight>Template:Anchor
The <syntaxhighlight lang="java" inline>do</syntaxhighlight> keyword is used in conjunction with <syntaxhighlight lang="java" inline>while</syntaxhighlight> 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 <syntaxhighlight lang="java" inline>while</syntaxhighlight>. If the expression evaluates to <syntaxhighlight lang="java" inline>true</syntaxhighlight>, the block is executed again; this continues until the expression evaluates to <syntaxhighlight lang="java" inline>false</syntaxhighlight>.[8]Template:Sfn
See do while loop.
<syntaxhighlight lang="java" inline>double</syntaxhighlight>
Touhe <syntaxhighlight lang="java" inline>double</syntaxhighlight> keyword is used to declare a variable or return type that can hold a 64-bit double precision IEEE 754 floating-point number.[6][5]Template:SfnTemplate:Sfn As a wrapper class, it becomes Template:Javadoc:SE.
<syntaxhighlight lang="java" inline>else</syntaxhighlight>Template:Anchor
The <syntaxhighlight lang="java" inline>else</syntaxhighlight> keyword is used in conjunction with <syntaxhighlight lang="java" inline>if</syntaxhighlight> to create an if-else statement, which tests a boolean expression; if the expression evaluates to <syntaxhighlight lang="java" inline>true</syntaxhighlight>, the block of statements associated with the <syntaxhighlight lang="java" inline>if</syntaxhighlight> are evaluated; if it evaluates to <syntaxhighlight lang="java" inline>false</syntaxhighlight>, the block of statements associated with the <syntaxhighlight lang="java" inline>else</syntaxhighlight> are evaluated.[9]Template:Sfn
<syntaxhighlight lang="java" inline>enum</syntaxhighlight>
A Java keyword used to declare an enumerated type.[4] Enumerations implicitly inherit from the base class Template:Javadoc:SE.
<syntaxhighlight lang="java" inline>extends</syntaxhighlight>
Used in a class declaration to specify the superclass; used in an interface declaration to specify one or more superinterfaces. Class Y inherits from (extends) class X to add functionality, either by adding fields or methods to class X, or by overriding methods of class X. An interface J inherits from (extends) one or more interfaces I1, I2, ..., by adding methods. Class Y is said to be a subclass of class X; Interface J is said to be a subinterface of the interfaces I1, I2, ... it inherits from.
Also used to specify an upper bound on a type parameter in Generics.
See inheritance.
<syntaxhighlight lang="java" inline>final</syntaxhighlight>
Define an entity once that cannot be changed nor derived from later. More specifically: a <syntaxhighlight lang="java" inline>final</syntaxhighlight> class cannot be subclassed, a <syntaxhighlight lang="java" inline>final</syntaxhighlight> method cannot be overridden, and a <syntaxhighlight lang="java" inline>final</syntaxhighlight> variable can occur at most once as a left-hand expression on an executed command. All methods in a final class are implicitly <syntaxhighlight lang="java" inline>final</syntaxhighlight>.
See final (Java).
<syntaxhighlight lang="java" inline>finally</syntaxhighlight>
Used to define a block of statements for a block defined previously by the <syntaxhighlight lang="java" inline>try</syntaxhighlight> keyword. The <syntaxhighlight lang="java" inline>finally</syntaxhighlight> block is executed after execution exits the <syntaxhighlight lang="java" inline>try</syntaxhighlight> block and any associated <syntaxhighlight lang="java" inline>catch</syntaxhighlight> clauses regardless of whether an exception was thrown or caught, or execution left method in the middle of the <syntaxhighlight lang="java" inline>try</syntaxhighlight> or <syntaxhighlight lang="java" inline>catch</syntaxhighlight> blocks using the <syntaxhighlight lang="java" inline>return</syntaxhighlight> keyword.
See Java exception handling syntax.
<syntaxhighlight lang="java" inline>float</syntaxhighlight>
The <syntaxhighlight lang="java" inline>float</syntaxhighlight> keyword is used to declare a variable or return type that can hold a 32-bit single precision IEEE 754 floating-point number.[6][5]Template:SfnTemplate:Sfn As a wrapper class, it becomes Template:Javadoc:SE.
<syntaxhighlight lang="java" inline>for</syntaxhighlight>
The <syntaxhighlight lang="java" inline>for</syntaxhighlight> keyword is used to create a for loop, which specifies a variable initialization, a boolean expression, and an incrementation. The variable initialization is performed first, and then the boolean expression is evaluated. If the expression evaluates to <syntaxhighlight lang="java" inline>true</syntaxhighlight>, the block of statements associated with the loop are executed, and then the incrementation is performed. The boolean expression is then evaluated again; this continues until the expression evaluates to <syntaxhighlight lang="java" inline>false</syntaxhighlight>.[10]
The <syntaxhighlight lang="java" inline>for</syntaxhighlight> keyword can also be used to create a <syntaxhighlight lang="java" inline>for</syntaxhighlight>-each loop,Template:Sfn which specifies an array or Template:Javadoc:SE object; each iteration of the loop executes the associated block of statements using a different element in the array or java.lang.Iterable<T>.[10]
<syntaxhighlight lang="java" inline>if</syntaxhighlight>
The <syntaxhighlight lang="java" inline>if</syntaxhighlight> keyword is used to create an if statement, which tests a boolean expression; if the expression evaluates to <syntaxhighlight lang="java" inline>true</syntaxhighlight>, the block of statements associated with the if statement is executed. See <syntaxhighlight lang="java" inline>else</syntaxhighlight>.[9]Template:Sfn
<syntaxhighlight lang="java" inline>implements</syntaxhighlight>
Included in a class declaration to specify one or more interfaces that are implemented by the current class. A class inherits the types and abstract methods declared by the interfaces.
<syntaxhighlight lang="java" inline>import</syntaxhighlight>Template:Anchor
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, <syntaxhighlight lang="java" inline>import</syntaxhighlight> statements can import <syntaxhighlight lang="java" inline>static</syntaxhighlight> members of a class. A Java module may itself be imported (by writing <syntaxhighlight lang="cpp" inline>import module</syntaxhighlight>), automatically importing all exported packages.[11]
<syntaxhighlight lang="java" inline>instanceof</syntaxhighlight>
A binary operator that takes an object reference as its first operand and a class or interface as its second operand and produces a boolean result. The <syntaxhighlight lang="java" inline>instanceof</syntaxhighlight> operator evaluates to true if and only if the runtime type of the object is assignment compatible with the class or interface.
<syntaxhighlight lang="java" inline>int</syntaxhighlight>
The <syntaxhighlight lang="java" inline>int</syntaxhighlight> keyword is used to declare a variable or return type that can hold a 32-bit signed two's complement integer.[6][5]Template:SfnTemplate:Sfn As a wrapper class, it becomes Template:Javadoc:SE.
<syntaxhighlight lang="java" inline>interface</syntaxhighlight>
Used to declare an interface that only contains abstract or default methods, constant (<syntaxhighlight lang="java" inline>static final</syntaxhighlight>) fields and <syntaxhighlight lang="java" inline>static</syntaxhighlight> interfaces. It can later be implemented by classes that declare the interface with the <syntaxhighlight lang="java" inline>implements</syntaxhighlight> keyword. As multiple inheritance is not allowed in Java, interfaces are used to circumvent it. An interface can be defined within another interface.
<syntaxhighlight lang="java" inline>long</syntaxhighlight>
The <syntaxhighlight lang="java" inline>long</syntaxhighlight> keyword is used to declare a variable or return type that can hold a 64-bit signed two's complement integer.[6][5]Template:SfnTemplate:Sfn As a wrapper class, it becomes Template:Javadoc:SE.
<syntaxhighlight lang="java" inline>native</syntaxhighlight>
Used in method declarations to specify that the method is not implemented in the same Java source file, but rather in another language (typically C).Template:Sfn
See Java Native Interface.
<syntaxhighlight lang="java" inline>new</syntaxhighlight>Template:Anchor
Used to create an instance of a class or array object.
See Java object lifetime.
<syntaxhighlight lang="java" inline>package</syntaxhighlight>
A Java package is a group of similar classes and interfaces, declared with the <syntaxhighlight lang="java" inline>package</syntaxhighlight> keyword.
See Java package.
<syntaxhighlight lang="java" inline>private</syntaxhighlight>
The <syntaxhighlight lang="java" inline>private</syntaxhighlight> keyword is used in the declaration of a method, field, or inner class; private members can only be accessed by other members of their own class.[12]
See access modifiers.
<syntaxhighlight lang="java" inline>protected</syntaxhighlight>
The <syntaxhighlight lang="java" inline>protected</syntaxhighlight> 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.[12]
See access modifiers.
<syntaxhighlight lang="java" inline>public</syntaxhighlight>
The <syntaxhighlight lang="java" inline>public</syntaxhighlight> keyword is used in the declaration of a class, method, or field; public classes, methods, and fields can be accessed by the members of any class.[12]
See access modifiers.
<syntaxhighlight lang="java" inline>return</syntaxhighlight>
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.
<syntaxhighlight lang="java" inline>short</syntaxhighlight>
The <syntaxhighlight lang="java" inline>short</syntaxhighlight> keyword is used to declare a variable or return type that can hold a 16-bit signed two's complement integer.[6][5]Template:SfnTemplate:Sfn As a wrapper class, it becomes Template:Javadoc:SE.
<syntaxhighlight lang="java" inline>static</syntaxhighlight>
Used to declare a field, method, or inner class as a class field. Classes maintain one copy of class fields regardless of how many instances exist of that class. <syntaxhighlight lang="java" inline>static</syntaxhighlight> 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 <syntaxhighlight lang="java" inline>static</syntaxhighlight> members of another class or interface are behaviorally top-level classes.[13]
See static variable.
<syntaxhighlight lang="java" inline>super</syntaxhighlight>
Inheritance basically used to achieve dynamic binding or run-time polymorphism in Java. Used to access members of a class inherited by the class in which it appears. Allows a subclass to access overridden methods and hidden members of its superclass. The <syntaxhighlight lang="java" inline>super</syntaxhighlight> 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.
<syntaxhighlight lang="java" inline>switch</syntaxhighlight>Template:Anchor
The <syntaxhighlight lang="java" inline>switch</syntaxhighlight> keyword is used in conjunction with <syntaxhighlight lang="java" inline>case</syntaxhighlight> and <syntaxhighlight lang="java" inline>default</syntaxhighlight> to create a switch statement, which evaluates a variable, matches its value to a specific <syntaxhighlight lang="java" inline>case</syntaxhighlight> (including patterns), and executes the block of statements associated with that <syntaxhighlight lang="java" inline>case</syntaxhighlight>. If no <syntaxhighlight lang="java" inline>case</syntaxhighlight> matches the value, the optional block labelled by <syntaxhighlight lang="java" inline>default</syntaxhighlight> is executed, if included.[7]Template:Sfn The switch keyword can also be used with the non-reserved keyword <syntaxhighlight lang="java" inline>yield</syntaxhighlight> to create switch expressions.
<syntaxhighlight lang="java" inline>synchronized</syntaxhighlight>Template:Anchor
Used in the declaration of a method or code block to acquire the mutex lock for an object while the current thread executes the code.Template:Sfn For static methods, the object locked is the class's Template:Javadoc:SE. Guarantees that at most one thread at a time operating on the same object executes that code. The mutex lock is automatically released when execution exits the synchronized code. Fields, classes and interfaces cannot be declared as <syntaxhighlight lang="java" inline>synchronized</syntaxhighlight>.
<syntaxhighlight lang="java" inline>this</syntaxhighlight>
Used to represent an instance of the class in which it appears. <syntaxhighlight lang="java" inline>this</syntaxhighlight> can be used to access class members and as a reference to the current instance. The <syntaxhighlight lang="java" inline>this</syntaxhighlight> keyword is also used to forward a call from one constructor in a class to another constructor in the same class.
<syntaxhighlight lang="java" inline>throw</syntaxhighlight>
Causes the declared exception instance to be thrown. This causes execution to continue with the first enclosing exception handler declared by the <syntaxhighlight lang="java" inline>catch</syntaxhighlight> keyword to handle an assignment compatible exception type. If no such exception handler is found in the current method, then the method returns and the process is repeated in the calling method. If no exception handler is found in any method call on the stack, then the exception is passed to the thread's uncaught exception handler.
See Java exception handling syntax.
<syntaxhighlight lang="java" inline>throws</syntaxhighlight>
Used in method declarations to specify which exceptions are not handled within the method but rather passed to the next higher level of the program. All uncaught checked exceptions in a method (extend Template:Javadoc:SE but not Template:Javadoc:SE or Template:Javadoc:SE) must be declared using the <syntaxhighlight lang="java" inline>throws</syntaxhighlight> keyword.
See checked exceptions.
<syntaxhighlight lang="java" inline>transient</syntaxhighlight>
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 <syntaxhighlight lang="java" inline>transient</syntaxhighlight> keywords are ignored.[14][15] The <syntaxhighlight lang="java" inline>transient</syntaxhighlight> specifier only applies if the type implements Template:Javadoc:SE, but not if it implements Template:Javadoc:SE (a sub-interface of java.io.Serializable).
See transient.
<syntaxhighlight lang="java" inline>try</syntaxhighlight>
Defines a block of statements that have exception handling. If an exception is thrown inside the <syntaxhighlight lang="java" inline>try</syntaxhighlight> block, an optional <syntaxhighlight lang="java" inline>catch</syntaxhighlight> block can handle declared exception types. An optional <syntaxhighlight lang="java" inline>finally</syntaxhighlight> block can be declared that will be executed when execution exits the <syntaxhighlight lang="java" inline>try</syntaxhighlight> block and <syntaxhighlight lang="java" inline>catch</syntaxhighlight> clauses, regardless of whether an exception is thrown or not. A <syntaxhighlight lang="java" inline>try</syntaxhighlight> block must have at least one <syntaxhighlight lang="java" inline>catch</syntaxhighlight> clause or a <syntaxhighlight lang="java" inline>finally</syntaxhighlight> block.
See Java exception handling syntax.
<syntaxhighlight lang="java" inline>void</syntaxhighlight>
The <syntaxhighlight lang="java" inline>void</syntaxhighlight> keyword is used to declare that a method does not return any value. As a wrapper class, it becomes Template:Javadoc:SE.
See void type.
<syntaxhighlight lang="java" inline>volatile</syntaxhighlight>
Used in field declarations to guarantee visibility of changes to variables across threads. Every read of a volatile variable will be read from main memory, and not from the CPU cache, and that every write to a volatile variable will be written to main memory, and not just to the CPU cache.[16] Methods, classes and interfaces thus cannot be declared <syntaxhighlight lang="java" inline>volatile</syntaxhighlight>, nor can local variables or parameters. Note that in C and C++, <syntaxhighlight lang="cpp" inline>volatile</syntaxhighlight> is not used for thread safety, but rather indicates that the value of the variable may change outside of the program's control, and cannot be optimised.
See volatile variable.
<syntaxhighlight lang="java" inline>while</syntaxhighlight>Template:Anchor
The <syntaxhighlight lang="java" inline>while</syntaxhighlight> 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 <syntaxhighlight lang="java" inline>true</syntaxhighlight>; this continues until the expression evaluates to <syntaxhighlight lang="java" inline>false</syntaxhighlight>. This keyword can also be used to create a do-while loop; see <syntaxhighlight lang="java" inline>do</syntaxhighlight>.[8]Template:Sfn

Unused

The following words are reserved as keywords, but currently have no use or purpose.

<syntaxhighlight lang="java" inline>const</syntaxhighlight>
Although reserved as a keyword in Java, <syntaxhighlight lang="java" inline>const</syntaxhighlight> is not used and has no function.[2]Template:Sfn In other languages, <syntaxhighlight lang="java" inline>const</syntaxhighlight> is typically used to define constants. For defining constants in Java, see the <syntaxhighlight lang="java" inline>final</syntaxhighlight> keyword.
See constant and <syntaxhighlight lang="cpp" inline>constexpr</syntaxhighlight>.
<syntaxhighlight lang="java" inline>goto</syntaxhighlight>
Although reserved as a keyword in Java, <syntaxhighlight lang="java" inline>goto</syntaxhighlight> is not used and has no function.[2]Template:Sfn In other languages, <syntaxhighlight lang="java" inline>goto</syntaxhighlight> is typically used as a one-way control statement to jump to a label at another line of code.
<syntaxhighlight lang="java" inline>strictfp</syntaxhighlight>
Although reserved as a keyword in Java, <syntaxhighlight lang="java" inline>strictfp</syntaxhighlight> is obsolete, and no longer has any function.[4][17] Previously, this keyword was used to restrict the precision and rounding of floating point calculations to ensure portability; since Java 17 all floating-point evaluation runs with strict semantics.Template:Sfn

Contextual keywords

The following identifiers are contextual keywords, and are only restricted in some contexts:

<syntaxhighlight lang="java" inline>exports</syntaxhighlight>
Used in a module declaration to specify which packages are available to other modules.
<syntaxhighlight lang="java" inline>module</syntaxhighlight>
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.
<syntaxhighlight lang="java" inline>non-sealed</syntaxhighlight>
Used to declare that a class or interface which extends a sealed class can be extended by unknown classes.[18]
See sealed class.
<syntaxhighlight lang="java" inline>open</syntaxhighlight>
Indicates that all classes in a package are accessible via reflection by other modules.
<syntaxhighlight lang="java" inline>opens</syntaxhighlight>
Used to open a specific package for reflection to other modules.
<syntaxhighlight lang="java" inline>permits</syntaxhighlight>
The permits clause specifies the classes that are permitted to extend a sealed class.[18]
See sealed class.
<syntaxhighlight lang="java" inline>provides</syntaxhighlight>
Used to declare that a module provides an implementation of a service interface.
<syntaxhighlight lang="java" inline>record</syntaxhighlight>
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 Template:Javadoc:SE.
See record (computer science).
<syntaxhighlight lang="java" inline>requires</syntaxhighlight>
Used in a module declaration to specify that the module depends on another module.
<syntaxhighlight lang="java" inline>sealed</syntaxhighlight>
A sealed class or interface can only be extended or implemented by classes and interfaces permitted to do so.[18]
See sealed class.
<syntaxhighlight lang="java" inline>to</syntaxhighlight>
Used with the <syntaxhighlight lang="java" inline>opens</syntaxhighlight> directive to specify which module is allowed to reflectively access the package.
<syntaxhighlight lang="java" inline>transitive</syntaxhighlight>
Used with the <syntaxhighlight lang="java" inline>requires</syntaxhighlight> directive to indicate that a module not only requires another module but also makes that module's dependencies available to modules that depend on it.
<syntaxhighlight lang="java" inline>uses</syntaxhighlight>
Used in a module to declare that the module is using a service (i.e. it will consume a service provided by other modules).
<syntaxhighlight lang="java" inline>var</syntaxhighlight>
A special identifier that cannot be used as a type name (since Java 10).[19] 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.
<syntaxhighlight lang="java" inline>when</syntaxhighlight>
Used as an additional check for a <syntaxhighlight lang="java" inline>case</syntaxhighlight> statement.[20]
<syntaxhighlight lang="java" inline>with</syntaxhighlight>
Used with the <syntaxhighlight lang="java" inline>provides</syntaxhighlight> directive to specify which implementation of a service is provided by the module.
<syntaxhighlight lang="java" inline>yield</syntaxhighlight>
Used to set a value for a switch expression, when using labelled statement groups (for example, <syntaxhighlight lang="java" inline>case L:</syntaxhighlight>).[21]

Reserved words for literal values

The following words refer to literal values used by the language.

<syntaxhighlight lang="java" inline>true</syntaxhighlight>
A boolean literal value of truth.
<syntaxhighlight lang="java" inline>false</syntaxhighlight>
A boolean literal value of falsehood.
<syntaxhighlight lang="java" inline>null</syntaxhighlight>
A reference literal value of null.

See also

References

Template:Reflist

Template:Refbegin


Template:Refend

  1. ↑ {{#invoke:citation/CS1|citation |CitationClass=web }}
  2. ↑ 2.0 2.1 2.2 {{#invoke:citation/CS1|citation |CitationClass=web }}
  3. ↑ https://openjdk.org/jeps/456
  4. ↑ 4.0 4.1 4.2 {{#invoke:citation/CS1|citation |CitationClass=web }}
  5. ↑ 5.0 5.1 5.2 5.3 5.4 5.5 5.6 5.7 {{#invoke:citation/CS1|citation |CitationClass=web }}
  6. ↑ 6.0 6.1 6.2 6.3 6.4 6.5 6.6 6.7 {{#invoke:citation/CS1|citation |CitationClass=web }}
  7. ↑ 7.0 7.1 7.2 {{#invoke:citation/CS1|citation |CitationClass=web }}
  8. ↑ 8.0 8.1 {{#invoke:citation/CS1|citation |CitationClass=web }}
  9. ↑ 9.0 9.1 {{#invoke:citation/CS1|citation |CitationClass=web }}
  10. ↑ 10.0 10.1 {{#invoke:citation/CS1|citation |CitationClass=web }}
  11. ↑ {{#invoke:citation/CS1|citation |CitationClass=web }}
  12. ↑ 12.0 12.1 12.2 {{#invoke:citation/CS1|citation |CitationClass=web }}
  13. ↑ {{#invoke:citation/CS1|citation |CitationClass=web }}
  14. ↑ {{#invoke:citation/CS1|citation |CitationClass=web }}
  15. ↑ {{#invoke:citation/CS1|citation |CitationClass=web }}
  16. ↑ {{#invoke:citation/CS1|citation |CitationClass=web }}
  17. ↑ {{#invoke:citation/CS1|citation |CitationClass=web }}
  18. ↑ 18.0 18.1 18.2 {{#invoke:citation/CS1|citation |CitationClass=web }}
  19. ↑ {{#invoke:citation/CS1|citation |CitationClass=web }}
  20. ↑ {{#invoke:citation/CS1|citation |CitationClass=web }}
  21. ↑ {{#invoke:citation/CS1|citation |CitationClass=web }}