Java Syntax

Java Syntax Course

Engineers From These Top Companies and Universities Trust EXLskills

1M+ Professionals | 100+ Institutions

This is the EXLskills free and open-source Java Syntax Micro Course. It guides learners via explanation, demonstration, and thorough practice, from no more than a basic understanding of Java, to a moderate level of understanding regarding Java syntax.

Is this course FREE?

Yes, this a 100% free course that you can contribute to on GitHub here!

Have more questions?

Feel free to reach out to us via live chat here!

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.

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?