Java Reserved Keywords: 67 in Total, But How Many Do You Use Daily?

𝗜'𝘃𝗲 𝗯𝗲𝗲𝗻 𝘄𝗿𝗶𝘁𝗶𝗻𝗴 𝗝𝗮𝘃𝗮 𝗳𝗼𝗿 𝗮 𝘄𝗵𝗶𝗹𝗲 𝗻𝗼𝘄 — 𝗮𝗻𝗱 𝗜 𝘀𝘁𝗶𝗹𝗹 𝗰𝗼𝗺𝗲 𝗮𝗰𝗿𝗼𝘀𝘀 𝗸𝗲𝘆𝘄𝗼𝗿𝗱𝘀 𝗜 𝗻𝗲𝘃𝗲𝗿 𝗳𝘂𝗹𝗹𝘆 𝘂𝗻𝗱𝗲𝗿𝘀𝘁𝗼𝗼𝗱. Turns out Java has 67 reserved keywords. Most of us use ~20 in our daily code. Here's what the rest actually do. 𝗖𝗮𝘁𝗲𝗴𝗼𝗿𝘆 𝟭 — Data Types (11) byte · short · int · long · float · double · char · boolean · void · var · enum var (Java 10) enables local type inference. enum values are full objects under the hood — not just constants. 𝗖𝗮𝘁𝗲𝗴𝗼𝗿𝘆 𝟮 — Control Flow (13) if · else · switch · case · default · yield · for · while · do · break · continue · return · when yield (Java 13) returns a value from a switch expression. when (Java 21) is a pattern matching guard — case Integer i when i > 0. 𝗖𝗮𝘁𝗲𝗴𝗼𝗿𝘆 𝟯 — Modifiers (10) public · protected · private · static · final · abstract · synchronized · transient · volatile · native volatile forces reads from main memory, not thread cache. transient skips fields during serialization. native calls JNI-based C/C++ code. 𝗖𝗮𝘁𝗲𝗴𝗼𝗿𝘆 𝟰 — Exception Handling (6) try · catch · finally · throw · throws · assert assert validates assumptions in dev. Enable with -ea JVM flag. Never use it for production logic. 𝗖𝗮𝘁𝗲𝗴𝗼𝗿𝘆 𝟱 — Class & Module (18) class · interface · extends · implements · package · import · sealed · non-sealed · permits · record · module · exports · requires · opens · uses · provides · with · to sealed (Java 17) restricts subclassing. record (Java 16) eliminates boilerplate — auto-generates constructors, getters, equals(), hashCode(). Module keywords power JPMS (Java 9). 𝗖𝗮𝘁𝗲𝗴𝗼𝗿𝘆 𝟲 — Object Reference (4) new · instanceof · super · this instanceof now supports pattern matching (Java 16) — no explicit cast needed. 𝗖𝗮𝘁𝗲𝗴𝗼𝗿𝘆 𝟳 — Literals (3) true · false · null null is not an object — it's the absence of a reference. Still a top cause of NullPointerException in production. 𝗖𝗮𝘁𝗲𝗴𝗼𝗿𝘆 𝟴 — Unused & Obsolete (4) goto · const · strictfp · _ Reserved but non-functional. strictfp is a no-op since Java 17. _ is illegal as an identifier from Java 21+. Java's keyword list grows every LTS release. yield, record, sealed, when — all added in the last few years. Not tracking Java releases = working with an incomplete language. A special thanks to Syed Zabi Ulla sir at PW Institute of Innovation for their clear explanations and continuous guidance throughout this topic. Which category is most underused in your day-to-day Java code? #Java #JavaDeveloper #CoreJava #Programming #SoftwareDevelopment #BackendDevelopment #LearnJava

To view or add a comment, sign in

Explore content categories