codingstuff.io
ExploreTutorialsProblemsCS Subjects
Get Started
ExploreTutorialsProblemsCS Subjects
Get Started
codingstuff.io

Master the art of building software through interactive tutorials, real-world problems, and guided projects.

Pune, Maharashtra, India

codingstuffmail@gmail.com

Product

  • Explore
  • Tutorials
  • Problems
  • CS Subjects

Company

  • About
  • Contact
  • Privacy Policy
  • Terms & Conditions
  • Sitemap

© 2026 codingstuff.io. All rights reserved.

Built with ❤️ for developers everywhere

/
/
All Tutorials
☕

Java Programming

61 / 65 topics
61Java Keywords62Java String Methods63Java Math Methods64Java Arrays Methods65Java Collections Methods
Tutorials/Java Programming/Java Keywords
☕Java Programming

Java Keywords

Updated 2026-05-12
30 min read

Java Keywords

In the world of programming, keywords are fundamental building blocks that have special meaning within a language. Java, like other programming languages, reserves certain words to perform specific tasks and control the flow of the program. Understanding these keywords is crucial for writing correct and efficient Java code.

Introduction

Java has a set of reserved keywords that cannot be used as identifiers (such as variable names, method names, or class names) because they are already defined by the language itself. These keywords have specific meanings and functions within the Java syntax. Knowing them will help you avoid common errors and write cleaner code.

In this tutorial, we'll explore all the reserved keywords in Java along with their meanings and usage examples. This knowledge is essential for any Java developer to ensure they use the language correctly and effectively.

List of Java Keywords

Java has 53 reserved keywords as of Java SE 17. Here's a comprehensive list categorized by their primary functions:

Access Modifiers

KeywordDescription
publicAllows access from any other class in the same or different package.
protectedAllows access within the same package and subclasses (in different packages).
privateAllows access only within the same class.

Non-Access Modifiers

KeywordDescription
staticBelongs to the class rather than any object of the class.
finalCannot be changed or overridden. Used for constants and final classes.
abstractMust be implemented by subclasses.

Primitive Types

KeywordDescription
byte8-bit signed two's complement integer.
short16-bit signed two's complement integer.
int32-bit signed two's complement integer.
long64-bit signed two's complement integer.
floatSingle-precision 32-bit IEEE 754 floating point.
doubleDouble-precision 64-bit IEEE 754 floating point.
char16-bit Unicode character.
booleanRepresents true or false values.

Control Flow Statements

KeywordDescription
ifConditional statement to execute a block of code if a condition is true.
elseAlternative block of code if the if condition is false.
switchSelects one of many code blocks to be executed based on a value.
whileLoops through a block of code as long as a specified condition is true.
do-whileExecutes a block of code at least once, then repeats the loop if a specified condition is true.
forLoops through a block of code a number of times.

Jump Statements

KeywordDescription
breakExits a switch or loop statement.
continueSkips the current iteration in a loop and continues with the next one.
returnExits a method and returns a value to the caller.

Classes and Objects

KeywordDescription
classDefines a class.
interfaceDeclares an interface.
extendsInherits from another class or implements an interface.
implementsImplements one or more interfaces.
newCreates a new instance of a class.

Error Handling

KeywordDescription
tryMarks a block of code to be tested for errors while it is being executed.
catchCatches the exception that was thrown by the try block.
finallyExecutes a block of code after try-catch blocks, regardless of whether an exception was thrown or not.
throwThrows an exception explicitly.
throwsDeclares an exception that might be thrown by a method.

Synchronization

KeywordDescription
synchronizedEnsures that only one thread can execute a block of code at a time.

Miscellaneous

KeywordDescription
thisRefers to the current instance of the class.
superRefers to the parent class (superclass).
voidIndicates that a method does not return any value.
nullRepresents a null reference, or a reference that does not point to any object.
trueBoolean literal representing true.
falseBoolean literal representing false.
instanceofChecks whether an object is an instance of a specified class or interface.

Usage Examples

Let's explore some usage examples for these keywords:

Access Modifiers

Java
1public class Example {
2 public int publicVar;
3 protected int protectedVar;
4 private int privateVar;
5
6 public void display() {
7 System.out.println("Public: " + publicVar);
8 System.out.println("Protected: " + protectedVar);
9 System.out.println("Private: " + privateVar);
10 };
11}
Output
Public: 0
Protected: 0
Private: 0

Control Flow Statements

Java
1public class ControlFlow {
2 public static void main(String[] args) {
3 int number = 10;
4
5 if (number > 5) {
6 System.out.println("Number is greater than 5");
7 } else {
8 System.out.println("Number is less than or equal to 5");
9 }
10
11 switch (number) {
12 case 10:
13 System.out.println("Number is 10");
14 break;
15 default:
16 System.out.println("Number is not 10");
17 }
18 }
19}
Output
Number is greater than 5
Number is 10

Jump Statements

Java
1public class JumpStatements {
2 public static void main(String[] args) {
3 for (int i = 0; i < 5; i++) {
4 if (i == 2) {
5 continue;
6 }
7 if (i == 4) {
8 break;
9 }
10 System.out.println(i);
11 }
12 }
13}
Output
0
1
3

Classes and Objects

Java
1class Animal {
2 String name;
3
4 public Animal(String name) {
5 this.name = name;
6 }
7
8 public void display() {
9 System.out.println("Animal: " + name);
10 }
11}
12
13public class Main {
14 public static void main(String[] args) {
15 Animal myDog = new Animal("Buddy");
16 myDog.display();
17 }
18}
Output

Synchronization

Java
1public class SynchronizedExample {
2 private int count = 0;
3
4 public synchronized void increment() {
5 count++;
6 }
7
8 public synchronized int getCount() {
9 return count;
10 }
11
12 public static void main(String[] args) throws InterruptedException {
13 SynchronizedExample example = new SynchronizedExample();
14 Thread t1 = new Thread(() -> {
15 for (int i = 0; i < 1000; i++) {
16 example.increment();
17 }
18 });
19
20 Thread t2 = new Thread(() -> {
21 for (int i = 0; i < 1000; i++) {
22 example.increment();
23 }
24 });
25
26 t1.start();
27 t2.start();
28
29 t1.join();
30 t2.join();
31
32 System.out.println("Final count: " + example.getCount());
33 }
34}
Output

Summary

KeywordDescription
public, protected, privateAccess modifiers for classes, methods, and variables.
static, final, abstractNon-access modifiers for classes, methods, and variables.
byte, short, int, long, float, double, char, booleanPrimitive data types.
if, else, switch, while, do-while, forControl flow statements.
break, continue, returnJump statements.
class, interface, extends, implements, newClasses and objects.
try, catch, finally, throw, throwsError handling.
synchronizedSynchronization.
this, super, void, null, true, false, instanceofMiscellaneous keywords.

What's Next?

Now that you have a comprehensive understanding of Java keywords, the next step is to explore Java String Methods. Strings are essential in any programming language, and learning how to manipulate them effectively will greatly enhance your Java skills.

In the next tutorial, we'll dive into various methods available for strings, such as substring, concat, toUpperCase, and many more. You'll learn how to perform common string operations and solve real-world problems using these methods.

Stay tuned!


PreviousJava LambdaNext Java String Methods

Recommended Gear

Java LambdaJava String Methods