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:
- class: Defines a new class.
public class Example { }
- public: Specifies the access level for classes, methods, and variables (accessible from anywhere).
public void method() { }
- static: Indicates that a method or variable belongs to the class rather than instances of the class.
public static void main(String[] args) { }
- void: Specifies that a method does not return any value.
public void display() { }
- 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
, andfalse
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
Boost your coding skills with our essential coding questions catalog.
Take a step towards a better tech career now!
Explore Answers
Related Courses
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.
Grokking Data Structures & Algorithms for Coding Interviews
Unlock Coding Interview Success: Dive Deep into Data Structures and Algorithms.
Grokking Advanced Coding Patterns for Interviews
Master advanced coding patterns for interviews: Unlock the key to acing MAANG-level coding questions.
One-Stop Portal For Tech Interviews.
Copyright © 2024 Designgurus, Inc. All rights reserved.