Java Keywords and Identifiers

In this tutorial you will learn about the Java Keywords and Identifiers and its application with practical example.

Let’s know more about java keywords and identifiers

Java Keywords

In Java Programming Language there are is a set of reserved words that you cannot use as an identifier. These words are known as “reserved” words or “Keywords”. Keywords are standard identifiers and their functions are predefined by the compiler.

We cannot use keywords as variable names, class names, method names, or any other identifier. Keywords in java are case sensitive, all characters being lower case.

abstract assert boolean break byte
case catch char class const
continue default do double else
enum extends final finally float
for goto if implements import
instanceof int interface long native
new package private protected public
return short static strictfp super
switch synchronized this throw throws
transient try void volatile while

Keywords goto and const are reserved but never used.

Java Identifiers

Like in any other programming language we must aware of the naming conventions in Java Programming Language before starting programming. An identifier is a name given to program elements such as class, variable, field, method, or constructor. In Java programming language an identifier is a sequence of alphabets or digits.

Following rules must be kept in mind while naming an identifier.

  • The first character must be an alphabet (uppercase or lowercase) or can be an underscore.
  • Subsequent characters may be letters, digits, dollar signs, or underscore characters
  • No two successive underscores are allowed.
  • Keywords should not be used as identifiers.
  • A variable name cannot contain spaces.

Java Valid identifier examples

Java Invalid identifier examples

Java naming conventions for identifiers

  • Use CamelCase for most identifiers (classes, interfaces, variables, and methods).
  • Use an initial capital letter for classes and interfaces and a lower case letter for variables and methods.
  • For named constants, use all capital letters separated by underscores.
  • Avoid using $ characters in identifiers.

 

In this tutorial we have learn about the Java Keywords and Identifiers and its application with practical example. I hope you will like this tutorial.