I'm always excited to take on new projects and collaborate with innovative minds.

Email

contact@niteshsynergy.com

Website

https://www.niteshsynergy.com/

Java

java-keywords-use 

✅ Java Keywords Till Java 5 (Java 1.0 to 1.5)

  • abstract – Used to declare a class or method as abstract (i.e., incomplete, to be implemented by subclass).
  • assert – Used to test assumptions in code; throws error if condition is false (mainly for debugging).
  • boolean – Primitive data type that holds true or false.
  • break – Exits from a loop or switch block.
  • byte – Primitive data type (8-bit signed integer).
  • case – Defines individual conditions inside a switch statement.
  • catch – Used to catch exceptions from a try block.
  • char – Primitive data type (16-bit Unicode character).
  • class – Used to declare a class.
  • const – Reserved keyword, not used in Java.
  • continue – Skips the current iteration in loops and jumps to the next.
  • default – Defines the default block in a switch or default method implementation in interfaces.
  • do – Starts a do-while loop.
  • double – Primitive data type for 64-bit decimal values.
  • else – Executes block when if condition is false.
  • enum – Introduced in Java 5 to define a fixed set of constants.
  • extends – Indicates inheritance (class or interface extension).
  • final – Used to declare constants, prevent method overriding or inheritance.
  • finally – Block that always executes after try-catch.
  • float – Primitive data type for 32-bit decimal values.
  • for – Loop construct for iteration.
  • goto – Reserved keyword, not implemented.
  • if – Executes block based on condition.
  • implements – Declares that a class implements an interface.
  • import – Imports classes or packages.
  • instanceof – Checks if an object is an instance of a class.
  • int – Primitive data type (32-bit signed integer).
  • interface – Defines an abstract type with method signatures.
  • long – Primitive data type (64-bit signed integer).
  • native – Indicates method is implemented in native code (e.g., C/C++).
  • new – Creates new objects.
  • package – Defines the package of a class.
  • private – Access modifier: only within the class.
  • protected – Access modifier: class, package, and subclass.
  • public – Access modifier: accessible from everywhere.
  • return – Returns a value from a method.
  • short – Primitive data type (16-bit signed integer).
  • static – Defines class-level fields or methods.
  • strictfp – Ensures consistent floating-point calculations across platforms.
  • super – Refers to superclass constructor or methods.
  • switch – Allows multi-branch conditional execution.
  • synchronized – Ensures only one thread can execute a block/method at a time.
  • this – Refers to the current object.
  • throw – Throws an exception.
  • throws – Declares exceptions a method can throw.
  • transient – Prevents serialization of a field.
  • try – Defines block to test code for exceptions.
  • void – Declares that a method does not return anything.
  • volatile – Ensures changes to a variable are visible to all threads.
  • while – Starts a while loop.

✅ Next: Java 6 & 7

No new keywords were introduced in Java 6 or Java 7. Only new features (like try-with-resources, strings in switch, etc.) — but no new reserved words.

 

✅ Java 8 Keywords (2014)

Java 8 introduced major features like lambdas and streams, but no new keywords were added.

👉 Functional interfaces, :: method references, -> lambda syntax — all added, but these are not reserved keywords.


✅ Java 9 to Java 12 — No new keywords

  • Java 9 (2017): Modules introduced (module-info.java) — but no new keywords.
  • Java 10–12: Added features like var (in Java 10), but let’s break it down below.

✅ Java 10 Keyword (2018)

  • var – Introduced for local variable type inference.
    Example: var name = "Nitesh";
    Java infers that name is of type String.

✅ Java 11, 12 – No new keywords

  • Java 11: Introduced enhancements like var in lambda parameters, HttpClient, etc.
  • Java 12: Switch expression preview — no new keywords, just syntax improvements.

✅ Java 13 to 14 – Still no new keywords

  • Java 14 introduced:
    • record (preview) — not yet a keyword.
    • Pattern matching (preview)
      These were not keywords yet — just preview features.

✅ Java 15 Keyword (2020)

  • sealed – Used to restrict class inheritance.
    Example: public sealed class Shape permits Circle, Square {}

✅ Java 16 Keyword (2021)

  • permits – Used with sealed classes to specify which classes can extend them.
    Example: sealed class A permits B, C {}
  • record – Became a full keyword in Java 16. Used to declare data-carrying immutable classes.
    Example: record User(String name, int age) {}

✅ Java 17 – No new keywords

Java 17 was a Long Term Support (LTS) release.
Many preview features like pattern matching improved — but no new keywords added.


✅ Java 18 – No new keywords

This release focused on incubation features, performance, and simple web server — no keyword changes.


✅ Java 19 Keyword (Preview)

  • non-sealed – Used to opt-out of sealing in a class hierarchy.
    Example:

     
     
    sealed class A permits B, C {} non-sealed class B extends A {} 

    Became a preview feature here and finalized in Java 21.


✅ Java 20 – No new keywords

Features like record patterns and scoped values were previewed, but no new keywords added.

 

✅ Java 21 Keywords (2023)

Java 21 finalized many keywords introduced in earlier previews:

  • sealed – Finalized.
  • permits – Finalized.
  • non-sealed – Finalized.

These keywords are now part of the official Java syntax.

 

🔚 Final Java Keywords List as of Java 21

In total, Java 21 has 57 reserved keywords:

  • From Java 1.0 – 50 core keywords
  • Java 5 – enum
  • Java 10 – var
  • Java 15 – sealed
  • Java 16 – record, permits
  • Java 21 – non-sealed (finalized)

 

 

PART 1: Java 7 and Earlier – Segment-Based ConcurrentHashMap

 Internal Architecture:

ConcurrentHashMap<K, V>
 └── Segment<K, V>[] segments  // Default size: 16
       └── HashEntry<K, V>[] table (inside each segment)
             └── Bucket (linked list of HashEntry)
 

Key Internal Classes:

  • Segment<K,V>: Extends ReentrantLock, manages one portion of the map.

  • HashEntry<K,V>: Represents a single key-value pair (like Node in Java 8).

 Example Layout:

segments[0] → table[3] → HashEntry(keyA) → HashEntry(keyB)
segments[1] → table[2] → HashEntry(keyC)
 

Locking Behavior:

  • Each Segment has its own ReentrantLock.

  • Concurrent writes are only allowed across different segments.

  • Within a segment, only one writer at a time is allowed.

 

Limitations:

  • Max 16 concurrent writers (default concurrencyLevel = 16).

  • If multiple keys hash into the same segment → lock contention increases.

  • Tree-based collision handling not available — long linked lists degrade performance.

 

 

PART 2: Java 8 and Beyond – Bucket-Based ConcurrentHashMap

 Internal Architecture:

ConcurrentHashMap<K, V>
 └── Node<K, V>[] table
       └── Each table[i] = Bucket = Linked List or TreeBin
 

Key Internal Classes:

  • Node<K,V>: A key-value pair with next pointer.

  • TreeNode<K,V>: Subclass used when the bucket is converted to a red-black tree.

  • TreeBin: Wrapper for red-black tree logic.

 

Example Layout:

table[3] → Node(key1) → Node(key2) → Node(key3)
        (Linked List or TreeBin)
 

Locking Behavior:

  • Locking is done on the head node of the bucket, using:

synchronized (Node1) {
  // Mutate bucket
}
 

  • Lock is only for mutating (put, remove) operations.

  • Read operations are lock-free, using volatile and CAS.

TreeBin Conversion:

  • If a bucket has > 8 nodes, it converts to a red-black tree (TreeBin) for performance.

  • TreeBin uses its own locking (synchronized and internal ReentrantLock) for rotations.

 

Java 7 and Earlier: Segment-Based Structure

ConcurrentHashMap
  └── Segment[0] ──┬── table[0] ──► Entry1 ─► Entry2
                   ├── table[1] ──► null
                   └── table[2] ──► Entry3 ─► Entry4

  └── Segment[1] ──┬── table[0] ──► Entry5
                   └── ...
         :
  └── Segment[15]
 

Key Points:

  • Each Segment contains its own internal table[] (buckets).

  • Segment uses ReentrantLock for segment-level locking.

  • Default concurrency = 16 (only 16 writers can modify in parallel).

  • Inside each segment's table, buckets are just linked lists (Entry → Entry).

 

 

Java 8 and Beyond: Bucket-Based Structure

ConcurrentHashMap
  └── Node[0] ──► null
  └── Node[1] ──► NodeA ─► NodeB ─► NodeC
  └── Node[2] ──► null
  └── Node[3] ──► TreeBin(root)
  └── Node[4] ──► NodeX
      :
  └── Node[N]
 

Key Points:

  • No Segment[] array — just a flat Node[] table.

  • Each Node[i] is a bucket and may contain:

    • A linked list of entries: NodeA → NodeB → NodeC

    • Or a TreeBin (red-black tree) if entries > 8

  • Locking is done by:

synchronized (NodeA) // NodeA is head of bucket
 

Each bucket can be locked independently, allowing much higher concurrency (hundreds of parallel threads).

 

 

FeatureJava 7 (Segment-based)Java 8+ (Bucket-based)
Top-level structureSegment[]Node[] (bucket array)
Locking granularityOne lock per Segment (ReentrantLock)One lock per bucket (synchronized(Node))
Concurrency levelLimited by number of segments (default = 16)Limited by number of buckets (e.g., 64, 128…)
Tree support❌ Not available✅ Yes (TreeBin for high-collision buckets)
Read operationsLock-free (volatile)Lock-free (volatile + CAS)

 

 

 Segment vs Bucket: 

AspectSegment-based (Java 7)Bucket-based (Java 8+)
Data StructureSegment[] array, each with internal tableNode[] table directly
Lock TypeReentrantLock on Segmentsynchronized(Node) on head node
Lock GranularityCoarse-grained (Segment-level)Fine-grained (per bucket/bin)
Max Concurrent WritersLimited to #segments (default 16)Up to number of non-colliding buckets (64, 128...)
Memory UsageHigher (Segment overhead)Lower (no Segment objects)
Read OperationLock-freeLock-free
Write OperationLocks entire SegmentLocks only specific bucket
Collision HandlingLinked list onlyLinked list or Red-Black tree
Tree Support✅ Red-Black Tree (TreeBin)
ResizingComplex, Segment by SegmentParallel-friendly resizing
ScalabilityModerateHigh
9 min read
Jun 12, 2025
By Nitesh Synergy
Share

Leave a comment

Your email address will not be published. Required fields are marked *