- Java Tutorial
- Java Introduction
- Java Features
- Java Simple Program
- JVM, JDK and JRE
- Java Syntax
- Java Comments
- Java Keywords
- Java Variables
- Java Literals
- Java Separators
- Java Datatypes
- Java Operators
- Java Statements
- Java Strings
- Java Arrays
- Control Statement
- Java If
- Java If-else
- Java If-else-if
- Java Nested If
- Java Switch
- Iteration Statement
- Java For Loop
- Java For Each Loop
- Java While Loop
- Java Do While Loop
- Java Nested Loop
- Java Break/Continue
- Java Methods
- Java Methods
- Java Method Parameters
- Java Method Overloading
- Java Recursion
- Java OOPS
- Java OOPs
- Java Classes/Objects
- Java Inheritance
- Java Polymorphism
- Java Encapsulation
- Java Abstraction
- Java Modifiers
- Java Constructors
- Java Interface
- Java static keyword
- Java this keyword
- Java File Handling
- Java File
- Java Create File
- Java Read/Write File
- Java Delete File
- Java Program To
- Add Two Numbers
- Even or Odd Numbers
- Reverse a String
- Swap Two Numbers
- Prime Number
- Fibonacci Sequence
- Palindrome Strings
- Java Reference
- Java String Methods
- Java Math Methods
Java Keywords
In the world of Java, keywords are the fundamental building blocks of the language's syntax. These are reserved words that have a special, predefined meaning to the Java compiler. Because they are part of the internal vocabulary of the language, you cannot use them to name your variables, classes, or methods.
Think of keywords as the "commands" that tell the Java Virtual Machine (JVM) exactly what to do whether it's creating a new object, starting a loop, or defining a decimal number.
Reserved Words:
- Identifiers: Java keywords cannot be used as identifiers (e.g., you cannot name a variable
intor a classpublic). - Case Sensitivity: All Java keywords are written in lowercase. For example,
whileis a keyword, butWhileis not. - Functionality: Each keyword is reserved for a specific structural or logical purpose within the code.
true, false, and null might look like keywords, they are technically "literals." However, they are still reserved, meaning you cannot use them as names for your variables or methods.
const and goto are in the keyword list, they are not currently used in Java. They are "reserved" just in case Java developers decide to implement them in the future.
Practical Example
In the following example, we use several keywords to build a functional logic flow. Pay attention to how the keywords define the structure and visibility of the data.
package com.tutorial.example; // 'package' keyword organizes our code
public class Calculator { // 'public' and 'class' define our blueprint
// 'static' and 'final' create a constant tied to the class
public static final double PI = 3.14159;
// 'int' and 'void' define data types and return types
public void runDemo() {
int limit = 3;
// 'new' creates a new instance of an object
String message = new String("Starting loop...");
System.out.println(message);
// 'for' starts a looping construct
for (int i = 1; i <= limit; i++) {
// 'if' and 'else' handle conditional logic
if (i % 2 == 0) {
System.out.println(i + " is even.");
} else {
System.out.println(i + " is odd.");
}
}
}
public static void main(String[] args) {
Calculator myCalc = new Calculator();
myCalc.runDemo();
}
}
int class = 5;. This will result in a compiler error. To fix this, use a more descriptive name like int classLevel = 5;.
final keyword for variables that should not change after being assigned. This makes your code more predictable and prevents accidental bugs in large applications.
Summary
Java keywords are the "verbs" and "nouns" of the programming language. By mastering these 50+ reserved words, you gain the ability to control program flow, manage memory, and define complex data structures. As you gain experience, you'll stop thinking of them as a list to memorize and start seeing them as the natural tools needed to solve coding problems.