English | 简体中文 | 繁體中文 | Русский язык | Français | Español | Português | Deutsch | 日本語 | 한국어 | Italiano | بالعربية

Java Basic Tutorial

Java Flow Control

Java Arrays

Java Object-Oriented (I)

Java Object-Oriented (II)

Java Object-Oriented (III)

Java Exception Handling

Java List (List)

Java Queue (Queue)

Java Map Collection

Java Set Collection

Java Input/Output (I/O)/O)

Java Reader/Writer

Java Other Topics

Java Keywords and Identifiers

In this tutorial, you will learn about keywords. Reserved words in Java programming. You will also learn about identifiers.

Java Keywords

Keywords are predefined reserved words used in Java programming that have special meaning to the compiler. For example:

int score;

Here, int is a keyword. It indicates that the variable score is of integer type (32A signed two's complement binary integer.

You cannot use keywords like int, for, class, etc. as variable names (or identifiers) because they are part of the syntax of the Java programming language. This is the complete list of all keywords in Java programming.

List of Java Keywords
abstractassertbooleanbreakbyte
casecatchcharClassconst
continuedefaultdodoubleelse
enumextendsfinalfinallyFloat
forgotoifimplementsimport
instanceofintinterfacelongnative
newpackageprivateprotectedpublic
returnshortstaticstrictfpsuper
switchsynchronizedthisthrowthrows
transienttryvoidvolatilewhile

In addition to these keywords, true, false, and null cannot be used as identifiers. This is because they are literals.

Java Identifiers

An identifier is a name given to variables, classes, methods, and so on.

int score;

Here, score is a variable (identifier). You cannot use keywords as variable names because keywords have predefined meanings. For example,

int float;

The code above is incorrect because float is a keyword and cannot be used as a variable name.

To learn more about variables, please visitJava Variables.

Identifier Naming Rules

  • Identifiers cannot be keywords.

  • Identifiers are case-sensitive.

  • It can have a sequence of letters and numbers. However, it must start with a letter, $, or \, and the first letter cannot be a number.

  • By convention, identifiers start with a letter rather than $ or _.

  • Spaces are not allowed.

  •  Similarly, symbols such as @, #, etc., cannot be used.

The following are some valid identifiers:

  • Score

  • Level

  • highestScore

  • Number1

  • convertToString

The following are some invalid identifiers:

  • Class

  • Float

  • 1Number

  • Highest Score

  • @pple