What is a keyword in Java?

Free Coding Questions Catalog
Boost your coding skills with our essential coding questions catalog. Take a step towards a better tech career now!

A keyword in Java is a reserved word that has a specific meaning and purpose within the language. Keywords cannot be used as identifiers (like variable names, method names, or class names) because they are part of Java's syntax. Each keyword has a predefined function and plays a vital role in defining the structure and behavior of the Java program.

Examples of Common Java Keywords:

  1. class: Defines a new class.
    public class Example { }
  2. public: Specifies the access level for classes, methods, and variables (accessible from anywhere).
    public void method() { }
  3. static: Indicates that a method or variable belongs to the class rather than instances of the class.
    public static void main(String[] args) { }
  4. void: Specifies that a method does not return any value.
    public void display() { }
  5. if: Used to create conditional statements.
    if (a > b) { }

Java has 52 Reserved Keywords, including:

  • Control flow statements: if, else, for, while, switch, case
  • Access modifiers: public, private, protected
  • Data types: int, char, boolean, float, etc.
  • Exception handling: try, catch, finally, throw, throws
  • OOP keywords: class, extends, implements, this, super

Special Keywords:

  • null, true, and false are not technically keywords but are reserved literals in Java.

Reference Sources:

TAGS
Coding Interview
CONTRIBUTOR
Design Gurus Team

GET YOUR FREE

Coding Questions Catalog

Design Gurus Newsletter - Latest from our Blog
Boost your coding skills with our essential coding questions catalog.
Take a step towards a better tech career now!
Explore Answers
When can I expect my interview?
What tech job is the highest in demand?
What is round 3 of interview?
Related Courses
Image
Grokking the Coding Interview: Patterns for Coding Questions
Grokking the Coding Interview Patterns in Java, Python, JS, C++, C#, and Go. The most comprehensive course with 476 Lessons.
Image
Grokking Data Structures & Algorithms for Coding Interviews
Unlock Coding Interview Success: Dive Deep into Data Structures and Algorithms.
Image
Grokking Advanced Coding Patterns for Interviews
Master advanced coding patterns for interviews: Unlock the key to acing MAANG-level coding questions.
Image
One-Stop Portal For Tech Interviews.
Copyright © 2024 Designgurus, Inc. All rights reserved.