Java/J2EE and SOA (324 Blogs) Become a Certified Professional
AWS Global Infrastructure

Programming & Frameworks

Topics Covered
  • C Programming and Data Structures (41 Blogs)
  • Comprehensive Java Course (2 Blogs)
  • Java/J2EE and SOA (323 Blogs)
  • Spring Framework (8 Blogs)
SEE MORE

MI-new-launch

myMock Interview Service for Real Tech Jobs

myMock-widget-banner-bg

Everything you need to know about Identifiers in Java

Published on Aug 20,2019 73 Views

MI-new-launch

myMock Interview Service for Real Tech Jobs

myMock-mobile-banner-bg

myMock Interview Service for Real Tech Jobs

  • Mock interview in latest tech domains i.e JAVA, AI, DEVOPS,etc
  • Get interviewed by leading tech experts
  • Real time assessment report and video recording

Identifiers in Java is a very important aspect of Programming. They are mainly used for Identification Purposes. Following pointers will be covered in this article,

The name given to a package, interface, class, method or a variable is known as a java identifier. In simpler terms, it can be defined as identification through symbolic names.

Identifiers-in-java

Let’s take a look at an example for a better understanding:

 

Sample of Identifiers in Java

public class A
{
    public static void main(String[] args)
    {
        int s = 18;
    }
}

 

In the above code, five identifiers are present as such:

  • A: The class name defined by the user.
  • main: The name of the method.
  • String: Class name that is predefined in java.
  • args: The name of a variable.
  • s: Variable name.

 

Rules for defining Identifiers in Java:

  • The characters that are allowed for identifiers are limited to all the alphanumeric characters ([A-Z],[a-z],[0-9]), ‘$‘(dollar sign) and ‘_‘ (underscore). For example, “edureka@” is an invalid name as a special character “@” is present in it.

  • The identifiers should not begin with digits ([0-9]). For example, “123edureka” is invalid.

  • Identifiers in java are case sensitive.

  • While there is no such limit on the length of an identifier, programmers are advised to use an appropriate length of 4-15 letters.

  • It must be noted that Reserved Words should not be used as identifiers. For example, “int while = 18” is invalid in java, as while is a reserved word.

  • No white space must be given while defining a variable name.

  • All the variable names are case-sensitive.

 

Legal Variable Names:


MyVariable
MYVARIABLE
myvariable
x
i
_myvariable
$myvariable
sum_of_numbers
edureka123

 

Invalid Variable Names:


My Variable // contains a white space
456edureka // Begins with a digit
c+d // plus sign is not an alphanumeric character
variable-5 // hyphen is not an alphanumeric character
add_&_sub // ampersand is not an alphanumeric character

 

Reserved words in Java:

To represent certain functionalities, java reserves some words. These words are known as reserved words. They cannot be used as identifiers as they are already used by the java syntax.
Reserved Words can be differentiated into keywords (50) and literals(3). While the functionality is defined by a keyword, the value is defined by a literal.

Identifiers are a necessity as they make the program readable and efficient.

Check out the Java training by Edureka, a trusted online learning company with a network of more than 250,000 satisfied learners spread across the globe. Edureka’s Java J2EE and SOA training and certification course are designed for students and professionals who want to be a Java Developer. The course is designed to give you a head start into Java programming and train you for both core and advanced Java concepts along with various Java frameworks like Hibernate & Spring.

Got a question for us? Please mention it in the comments section of this blog and we will get back to you as soon as possible.

Comments
0 Comments

Browse Categories

webinar REGISTER FOR FREE WEBINAR
REGISTER NOW
webinar_success Thank you for registering Join Edureka Meetup community for 100+ Free Webinars each month JOIN MEETUP GROUP

Subscribe to our Newsletter, and get personalized recommendations.