🌐
ThoughtCo
thoughtco.com › reserved-words-in-java-2034200
Reserved Words in Java
January 27, 2019 - // you can't use finally as it's a reserved word! class finally { public static void main(String[] args) { //class code.. } } Instead of compiling, the Java program will instead give the following error:
🌐
W3Schools
w3schools.com › java › java_ref_keywords.asp
Java Keywords
Java has a set of keywords that are reserved words that cannot be used as variables, methods, classes, or any other identifiers:
🌐
Wikipedia
en.wikipedia.org › wiki › List_of_Java_keywords
List of Java keywords - Wikipedia
October 20, 2025 - In the Java programming language, ... the language. Because of this, programmers cannot use keywords in some contexts, such as names for variables, methods, classes, or as any other identifier....
🌐
Oracle
docs.oracle.com › javase › tutorial › java › nutsandbolts › _keywords.html
Java Language Keywords (The Java™ Tutorials > Learning the Java Language > Language Basics)
Here is a list of keywords in the Java programming language. You cannot use any of the following as identifiers in your programs. The keywords const and goto are reserved, even though they are not currently used.
🌐
EXLskills
exlskills.com › courses › java syntax › java syntax
Reserved words | Java Syntax - EXLskills
August 22, 2018 - We must use reserved words only for their intended purpose; we cannot use "class" for any other purpose than defining class. Please notice that the Java reserved word must be written in the exact same way as Java states, including the case of ...
🌐
Saylor Academy
learn.saylor.org › mod › book › view.php
Small Java Programs: Identifiers and Reserved Words | Saylor Academy
It is conventional for a class ... easier to understand. A source file should always end with .java in lower case. A reserved word is a word like class that has a special meaning to the system....
🌐
Computer Hope
computerhope.com › jargon › j › java_reserved_words.htm
What Are Java Reserved Words?
Java reserved words are keywords that are reserved by Java functions or other uses that cannot be used as identifiers (e.g., variable names, function names, class names). If a reserved word was used as a variable, you would get an error or ...
🌐
Edureka
edureka.co › blog › java-keywords
What are Java Keywords and reserved words? Edureka
June 17, 2021 - These keywords are also known as reserved keywords which mean they cannot be used as a variable name, class, method or any other identifier. There are 57 reserved keywords in Java.
Top answer
1 of 4
37

Yes, you can use reserved words. The words are only for the compiler. They do not appear in the generated byte code.

An example of using reserved Java words is in the JVM-based Scala language. Scala has different constructs and syntax than Java, but compiles to Java byte code, for running on a JVM.

This is legal Scala:

class `class`

This defines a class named class with a no-arg constructor. Running javap (a disassembler) on the compiled class.class file shows

public class class {
    public class();
}

Scala can do the same with any other Java reserved word.

class int
class `while`
class goto

They can also be used for method or field names.

As you suspected, you would not be able to use these classes from Java, except for reflection. You could use these from a similarly "customized" class file, e.g. from a class file generated by the Scala compiler.

In summary, this is a limitation of javac (the compiler), not java (the VM/runtime environment).

2 of 4
29

The only restrictions on class names at the bytecode level are that they can't contain the characters [, . or ; and that they're at most 65535 bytes long. Among other things, this means that you can freely use reserved words, whitespace, special characters, Unicode, or even weird stuff like newlines.

You can theoretically even use null characters in a class name, but since it's impossible to have a null character in the filename, you can't include such a classfile in a jar. You might be able to create and load one dynamically though.

Here's an example of some of the things that you can do (written in Krakatau assembly):

; Entry point for the jar
.class Main
.super java/lang/Object

.method public static main : ([Ljava/lang/String;)V
    .limit stack 10
    .limit locals 10
    invokestatic int                                hello ()V
    invokestatic "-42"                              hello ()V
    invokestatic ""                                 hello ()V
    invokestatic "  some  whitespace and \t tabs"   hello ()V
    invokestatic "new\nline"                        hello ()V
    invokestatic 'name with "Quotes" in it'         hello ()V
    return
.end method
.end class


.class int
.super java/lang/Object
.method public static hello : ()V
    .limit stack 2
    .limit locals 0
    getstatic java/lang/System out Ljava/io/PrintStream;
    ldc "Hello from int"
    invokevirtual java/io/PrintStream println (Ljava/lang/Object;)V
    return
.end method
.end class

.class "-42"
.super java/lang/Object
.method public static hello : ()V
    .limit stack 2
    .limit locals 0
    getstatic java/lang/System out Ljava/io/PrintStream;
    ldc "Hello from -42"
    invokevirtual java/io/PrintStream println (Ljava/lang/Object;)V
    return
.end method
.end class

; Even the empty string can be a class name!
.class ""
.super java/lang/Object
.method public static hello : ()V
    .limit stack 2
    .limit locals 0
    getstatic java/lang/System out Ljava/io/PrintStream;
    ldc "Hello from "
    invokevirtual java/io/PrintStream println (Ljava/lang/Object;)V
    return
.end method
.end class

.class "  some  whitespace and \t tabs"
.super java/lang/Object
.method public static hello : ()V
    .limit stack 2
    .limit locals 0
    getstatic java/lang/System out Ljava/io/PrintStream;
    ldc "Hello from   some  whitespace and \t tabs"
    invokevirtual java/io/PrintStream println (Ljava/lang/Object;)V
    return
.end method
.end class

.class "new\nline"
.super java/lang/Object
.method public static hello : ()V
    .limit stack 2
    .limit locals 0
    getstatic java/lang/System out Ljava/io/PrintStream;
    ldc "Hello from new\nline"
    invokevirtual java/io/PrintStream println (Ljava/lang/Object;)V
    return
.end method
.end class

.class 'name with "Quotes" in it'
.super java/lang/Object
.method public static hello : ()V
    .limit stack 2
    .limit locals 0
    getstatic java/lang/System out Ljava/io/PrintStream;
    ldc "Hello from name with \"Quotes\" in it"
    invokevirtual java/io/PrintStream println (Ljava/lang/Object;)V
    return
.end method
.end class

Execution output:

Hello from int
Hello from -42
Hello from
Hello from   some  whitespace and        tabs
Hello from new
line
Hello from name with "Quotes" in it

See Holger's answer for the exact quote of the rules from the JVM specification.

🌐
The Codest
thecodest.co › home › dictionary › reserved word
Reserved Word - The Codest
June 6, 2024 - Some examples of reserved words in popular programming languages include: Java: public, static, void, class, interface, extends, implements, new, return, if, else, switch, case, break, default, while, do, for, try, catch, finally, throw, throws · ...
Find elsewhere
🌐
EXLskills
exlskills.com › courses › java basics › java basics
Reserved words | Java Basics - EXLskills
August 1, 2018 - We must use reserved words only for their intended purpose; we cannot use "class" for any other purpose than defining class. Please notice that the Java reserved word must be written in the exact same way as Java states, including the case of ...
🌐
YouTube
youtube.com › watch
Reserved Words in Java Explained - Java Tutorial For Absolute Beginners - YouTube
In this video, I am talking about Reserved words in Java.In the Java programming language reserved words are keywords that have a predefined meaning in the J...
Published   February 25, 2020
🌐
Medium
medium.com › codestorm › reserved-words-in-java-f71e7260933f
Reserved words in Java. Here is a list of keywords in the Java… | by Asep Saputra | Code Storm | Medium
July 3, 2021 - Here is a list of keywords in the Java programming language. You cannot use any of the following as identifiers in your programs. The keywords const and goto are reserved, even though they are not currently used.
🌐
Medium
medium.com › @mukherjeesourabh07 › reserved-keywords-in-java-791b65df5707
Reserved keywords in Java. Reserved keywords | by Sourabh Mukherjee | Medium
January 15, 2024 - Based on Exception Handling: try, catch, finally, throw, throws, assert(came in 1.4 version of java onwards) — 6 keywords · Based on Class level: class, package, import, interface, extends, implements, enum — 7 keywords · Based on the Object level: new, instanceof, this, super — 4 keywords · Based on the return type of the method: void — 1 keyword ... All the reserved keywords are in lowercase only. There is no reserved keyword for deleting the object because it is the job delegated to the Garbage collector program in Java.
🌐
Reddit
reddit.com › r/learnprogramming › when are reserved words not keywords?
r/learnprogramming on Reddit: When are reserved words not keywords?
November 23, 2020 -

I read this link: https://stackoverflow.com/questions/1078908/what-is-the-difference-between-keyword-and-reserved-word#:~:text=Keywords%20have%20a%20special%20meaning,reserved%20words%20and%20vice%20versa.

I understand how reserved words are keywords and how some keywords cannot be reserved words, but I do not understand how some reserved words cannot be keywords? The answer to the post says how goto is not a keyword, but the java docs say how goto is a reserved word but also a keyword. Does this mean that reserved words are always keywords, or is there an instance/example in some language where a reserved word is not a keyword, would this mean that the StackOverflow post is wrong?

Certain language such as Python and C++ seem to use both of these terms interchangeably, so it depends on the language as well?

🌐
GeeksforGeeks
geeksforgeeks.org › java › java-identifiers
Java Identifiers (Variables Naming) - GeeksforGeeks
October 6, 2025 - Java identifiers are case-sensitive. There is no limit on the length of the identifier, but it is advisable to use an optimum length of 4 - 15 letters only. Reserved Words can't be used as an identifier.
🌐
Java Challengers
javachallengers.com › home › keywords vs reserved words in java
Keywords VS Reserved Words in Java
January 18, 2021 - To make a comparison between the most recent reserved identifiers and the previous keywords or reserved words; reserved identifiers can be used as a class, method, or variable names and keywords can’t!
🌐
GeeksforGeeks
geeksforgeeks.org › java › reserved-words-in-java
Reserved Words in Java - GeeksforGeeks
October 6, 2025 - In Java, reserved words are predefined identifiers that have a specific meaning in the language. They cannot be used as variable names, method names, class names, or identifiers, because they are part of the syntax of Java.