case labels in switch
case labels in switch: A case label selects a switch branch by constant, enum value, String, or type pattern; Java 21 can also handle null explicitly.
CKTIS / Knowledge base
Programming syntax, operators and concepts. Find an explanation, explore an example and return to learning.
case labels in switch: A case label selects a switch branch by constant, enum value, String, or type pattern; Java 21 can also handle null explicitly.
The catch clause: A catch clause handles an exception thrown from its associated try when the exception’s run-time type is assignable to the declared catch parameter type.
class — class declaration: The class keyword starts a class declaration, a named reference type with fields, methods, constructors, initializers, and member types.
const — reserved unused keyword: const is a reserved but unused Java keyword; it declares no constant and cannot be used as an identifier.
continue — advance to the next iteration: continue ends the current iteration of a while, do, or for loop and transfers control to that loop’s continuation point.
default — fallback branch or implementation: default marks an unmatched switch branch, an interface method with an implementation, or an annotation element’s default value.
do — post-test loop: A do statement executes its body before testing the boolean expression after while, so the body runs at least once.
else — alternative if branch: else supplies the alternative statement for the nearest preceding if whose boolean condition evaluated to false.
enum — enumeration type declaration: enum declares an enum class with a finite set of instances; each constant may take arguments and have a constant-specific class body that overrides behavior.
exports — module package export: An exports directive in module-info.java gives other modules access to a package’s public top-level types. Public or protected members and nested types remain subject to the ordinary access-control rules.
extends — inheritance and upper bounds: extends names a class’s direct superclass, an interface’s direct superinterfaces, or the upper bound of a type parameter or wildcard.
final — restriction on further change: final restricts change: a variable can be assigned once, a method cannot be overridden, and a class cannot be subclassed.
finally — cleanup after try: A finally clause belongs to try and runs after the try block and any selected catch when control completes them normally or by most abrupt-completion reasons.
for — basic and enhanced loops: The for statement is either basic with initialization, condition, and update, or enhanced for, which successively assigns elements from an array or Iterable.
goto — reserved unused keyword: goto is a reserved but unused Java keyword: the parser accepts it neither as an identifier nor as a jump statement.
if — conditional selection: An if statement selects a branch from a boolean expression; an optional else belongs to the nearest unmatched if unless braces change the structure.
implements — implementing interfaces: An implements clause on a class or record declaration lists direct superinterfaces; a concrete class must provide inherited abstract methods.
import — names from other packages: An import declaration in a compilation unit makes a type or static member available by simple name; it neither loads a class at runtime nor creates an alias.
interface — type contracts: An interface declaration defines a reference type with member contracts; fields are public static final, while methods may be abstract, default, static, or private.
module — JPMS module declaration: module is a contextual keyword that begins a module declaration in module-info.java; outside that context it may be an ordinary identifier.
native — method outside Java: The native modifier declares a method implemented outside the Java language; the declaration ends with a semicolon and has no Java body.
new — creating objects and arrays: The new operator creates a class instance through a class instance creation expression or creates an array; for a class it allocates the object and then runs the selected constructor.
The keyword non-sealed: The non-sealed modifier reopens a class or interface that is a direct permitted subtype of a sealed type.
The keyword open: The open modifier on a module declaration opens every package for deep run-time reflection without exporting those packages.