Java Tutorials

Identifiers and Naming Conventions – Java Tutorial

Identifiers in Java:

An identifier is one that identifies something. In Java, variable name, interface name, class name, method name etc. are identifiers. E.g. in example no. 1, Hello is identifier and used as class name. You should also learn about what is class, object, variable, constructor and method in Java.

Rules for giving names to identifiers in Java:

  1. Identifiers in Java are case sensitive. Upper case letters are not considered the same as lower case letters. For example, Recipe and recipe are considered different. Similarly, Hello and hello are distinct.
  2. A reserved keyword cannot be used as identifier name e.g. class, abstract, public, private, new, short, package, int, this, void etc.
  3. Special characters and whitespaces are not allowed in naming identifiers e.g. %number or number 1, are invalid identifiers.
  4. An identifier can start with $, _ or a letter and can have a digit after first letter or symbol e.g. $number, _value, sum, NaMe, na5ME, NAx9me, $name, _name.
  5. An identifier cannot start with any digit (0-9).

You may be interested in learning how to get input from user in Java.

Naming conventions in Java:

To make your code easily readable, more understandable and easy to maintain for yourself as well as other programmers, Java naming conventions must be followed. Following is the list of standard Java naming conventions.

  1. Package name should contain only lower case letters e.g. lang, awt, net, etc.
  2. A class name should be name of an entity or noun that start with uppercase letter e.g. Car, House, Products, Food etc.
  3. Interface should be named against attribute of a known or adjective that start with uppercase letter e.g. ActionListener, Collection etc.
  4. Method name should represent some very or action and start with lowercase letter e.g. moveForward(), toString(), etc.
  5. Variable or field name must be meaningful & should contain only lowercase letters e.g. sum, number, result etc.
  6. Constant can be any value that you want to keep same throughout the program. A constant name should contain only uppercase letters e.g. BASE_URL, SIZE, MAX_ATTEMPTS etc.

 

Arslan ud Din Shafiq

Alibaba Cloud MVP, Alibaba Cloud Technical Author, Dzone MVB, Software Engineer, Software Developer, Software Designer, Web Engineer, Web Developer, Web Designer, Database Designer, Database Developer, Cloud Computing Specialist, Linux Expert, Servers, 3D Modeling, Blogger, Facebook Map Editor, Google Map Editor

Share
Published by
Arslan ud Din Shafiq

Recent Posts

I have 20 years of experience in computer security advancement. What I can recommend to regular PC users

If you are living in a digital world you must know how to protect your…

4 years ago

Software Development Life Cycle Model (SDLC)

Software Development Life Cycle Model, also known as SDLC or Software Development Process, is base…

4 years ago

How to Install Go Lang on CentOS 8

Go, often referred to as golang is a modern open-source programming language created by Google…

4 years ago

SE Ranking in [2020]. What is SEO in marketing?

Torque published an article on October 18, 2016, about WordPress statistics. According to this article,…

4 years ago

PostgreSQL Version via Command Line & SQL Shell

PostgreSQL, often known simply as Postgres, is an open-source general-purpose object-relational database management system. In…

4 years ago

Google SEO: 15 Best ways about how can I do SEO for Free?

SEO is free as well as paid. To achieve SE ranking, money is not enough.…

5 years ago