The keyword provides
The keyword provides: The provides S with P directive in module-info declares that a module supplies service S through provider class P.
CKTIS / Java
Programming syntax, operators and concepts. Find an explanation, explore an example and return to learning.
The keyword provides: The provides S with P directive in module-info declares that a module supplies service S through provider class P.
The keyword public: The public modifier gives a declaration the widest accessibility allowed by its context, package, and module boundary.
The keyword record: A record declaration creates a nominal data class whose components determine private final fields, accessors, and a canonical constructor.
requires — module dependency: A requires directive in module-info.java establishes a module dependency and a readability edge to a named module.
return — exit from a method or lambda: return ends execution of the current method, constructor, or lambda body and optionally supplies a value to the caller.
sealed — restricted type hierarchy: sealed restricts a class or interface’s direct subtypes to those named by permits or inferred in the same compilation unit.
static — class-level member: static associates a field, method, initializer, or nested class with the declaring class rather than a particular instance.
strictfp — historical floating-point strictness: strictfp historically requested strict floating-point evaluation, but since Java 17 all floating-point expressions are always-strict, so the modifier does not change results.
super — superclass access: super selects a constructor, hidden field, or overridden method of the current object’s direct superclass; fields are hidden, not overridden. InterfaceName.super.m() selects a direct superinterface method.
switch — multi-way selection: A Switch expression selects a value among case labels; arrow rules written case ... -> do not fall through and in Java 21 support patterns and when guards.
synchronized — monitor locking: synchronized acquires an object monitor before entering a block or method and releases it on every normal or abrupt exit.
this — current instance: this denotes the current instance in an instance method or constructor and disambiguates fields from same-named parameters.
throw — explicit exception raising: A throw statement evaluates a Throwable expression and completes abruptly, passing the exception to the nearest compatible catch or caller.
The throws keyword in a method or constructor declaration specifies exception types that may escape its body. It matters especially for checked exceptions: calling code must handle them or declare that they can propagate further.
In Java SE 21, `to` is a contextual keyword used in `exports` and `opens` directives. It identifies the modules to which the declaring module makes a particular package available.
The transient keyword excludes a field from Java's implicit list of serializable fields. If the field is omitted, it retains its default value after an ordinary Serializable object is read back, unless restoration code assigns another value.
During module resolution, `requires transitive` makes modules that read the declaring module also read the specified dependency. A read edge added later with `Module.addReads` does not automatically extend to the target module’s transitive dependencies. `exports` and access-control rules still apply.
The reserved keyword `try` starts a block associated with exception handling or automatic resource closing. Ordinary `try` requires `catch`, `finally`, or both; `try`-with-resources can omit them.
The uses directive in module-info.java identifies a service type whose providers the module may discover through ServiceLoader. It neither selects a particular implementation nor starts discovery by itself. uses is a contextual keyword, not a reserved keyword.
`var` lets the compiler infer a local variable's type from its initializer. The type remains static and does not change with later assignments. In Java SE 21, `var` is a contextual keyword, not a type name.
volatile is a reserved keyword marking a field used for communication between threads. It provides visibility and happens-before ordering guarantees, but does not provide mutual exclusion or make operations such as count++ atomic.
In Java SE 21, the contextual keyword when introduces an additional condition (a guard) after a case pattern in a switch statement or expression. The branch is selected only when the value matches the pattern and the guard evaluates to true.
The while keyword introduces a loop that checks its condition before each execution of its body. The body may never execute; the condition must have type boolean or Boolean.
In Java SE 21, `with` is a contextual keyword in the `provides` directive of a module declaration. It separates the service type from its provider list; outside that context, it can be an identifier.