Reserved words

Basic Syntax

Reserved words

🙋 Need help? Ask an expert now!

In Java, there are keywords that are reserved for the use of Java functions or other uses that cannot be identifiers like variables, classes and function names. When a reserved word is used as a variable, we will get an error or some other unexpected result. Examples of reserved words are shown below.
package exlcode;

public class ReservedWordsExample {
  public static void main(String[] args) {
    String exampleVariable = "George";
    // This prints Hello World! and exampleVariable
    System.out.println("Hello World!");

In our example above, we see that the reserved words are in a different color than the rest of the line. These are words that have a specific meaning to the system. For example, class means that a definition of "class" immediately follows. 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 the word. For this reason, even though it is not recommended, we could technically name a variable "Class" because the 'C' is capitalized so it is not our reserved word class.

The following are more examples of reserved words that we will learn how to use as we progress through the course.

abstract, if, private, this, double, implements, throw, boolean, else, import, public, throws, break, return, byte, extends, int, short, true, false, case, interface, static, try, catch, final, long, void.

Edit Me on GitHub!

Application Question

Which of the following is a Java reserved word?