March 19 2015

Legal Identifiers In Java

Legal Identifiers In Java

Names used for classes,methods,interfaces and variables are called Identifiers. An identifier is a sequence of one or more characters. It must be composed of only unicode characters,numbers,currency symbol($) and underscore symbol(_).

Following are the rules for legal identifiers

  • The first character must start with a letter or currency character($) or underscore(_). It cannot start with number

  • After first character,identifier can contain letters,numbers,currency symbol($) and underscore(_) in any combination

  • Idetifiers in Java are case sensitive,name and NAME are considered as two different identifiers

  • Java keywords cannot be used as identifier


package com.answersz.identifiers;

public class LegalIdentifier {

 // Legal Identifiers In Java

 int $total;
 int _marks;
 int prices;
 int subject1;

 // Illegal Identifer

 int for; // Keyword not allowed
 int &d; // & not allowed
 int 1subject; // Cannot start with number
 int ?question; // ? not allowed


Copyright © 2014. All rights reserved.

Posted March 19, 2015 by answersz in category Core Java

Leave a Comment

Your email address will not be published. Required fields are marked *