×

Java Naming Conventions

JAVA NAMING CONVENTIONS

Java naming convention is a standard pattern for writing your identifier name such as class, interfaces, methods, constants, variable, etc.

These patterns are not standard rules that you must have to follow, so it is known as the convention, not as rules. These conventions are approved and suggested by several JAVA communities such as Sun Microsystems and Netscape.

All the classes, interfaces, packages, fields, and constants are given according to the naming convention in Java. If you failed to follow these conventions in your code, then it may generate confusion or erroneous code.

Advantage of Java naming convention-

It increases the readability of the code. Readability is one of the important parts of the code, standard pattern makes your code is easy to read for yourself and also for others.

Important points for naming-

  • The name of an identifier must not contain any white spaces.
  • The identifier name should not start with any of special character like *(star), # (hash), $(dollar), & (ampersand) etc.
  • Always choose a meaningful name for the identifier.

Types of cases-

Lowercase-

Lowercase is a case notation where all the words are written in lower format.

e.g.-

identifier, character,  etc.

Uppercase-

In this case, all the words are written in capitalized format.

e.g.

VARIABLE, CHARACTER, FIRST_DAY,  etc.

Camel case-

In this case, each new word is starts with a capital letter.

e.g.

CamelCase , CustomerDeposit, LordRama, etc.

Mixed case-

In this case, the first word starts with a small character after that each new word start with a capital letter. It is the same as camel case notation except the first word.

e.g.

displayRate,  intrestEarned, deenDayalUpadhyaay, etc.

Java Naming Conventions-

Class-

A class name should be in CamelCase. As I told you before, try to use a meaningful name, so class name tries to take as any noun because the class deals with real-world object.

e.g.

class Student, class Car, class CustomerAccount, etc.

Variables-

A variable name should be in mixedCase because variables represent the value of something.

e.g.,

string studentName, int accountNumber,  float salary, etc.

Constants-

Constants name should be taken in UPPERCASE.

e.g.-

MAX_PRIORITY, DEFAULT_VALUE, MIN_HEIGHT etc.

Methods-

A method name should be in mixedCase notation. Try to taker verb name because it may describe what the method does.

e.g.

calculateSalary,  displayValue, getAmount etc.

Packages-

The package name should be taken in lowercase. Try to choose a short and meaningful name.

e.g.-

package awt, package newproject, package myclaculator etc.

Interfaces-

An interface name should be in CamelCase notation. Its name should be like a class can do.

e.g.-

ActionListener, Runnable, IEnumerable.

Related Topics

Java StringWriter Class

The StringWriter class is a character stream in which it is used to store the output consisting of characters into the string buffer. Upon collecting output into a string buffer,...

3 minutes read.

Binary Strings Without Consecutive Ones in Java

N, an integer, is provided. Our objective is to determine the overall number of strings with length N that do not include successive 1s. Example: Input: 3 Output: 6 Explanation The binary forms of length...

6 minutes read.

Palindrome Partitioning problem in Java

In this article, you will be acknowledged about partitioning of the palindrome. It can be done in many ways. This article makes sure every method is discussed. Palindrome If a string remains...

6 minutes read.

Difference between Constructor and Method in Java

What is Constructor? In Constructor, we will discuss constructors and also will discuss default constructors and finally, we will discuss overloading constructors. A constructor is a method that is used to...

13 minutes read.

Singleton Design Pattern in Java

In the singleton pattern, a class that only has one instance and offers a universal point of access is taken into consideration. It can also be defined in another way, a...

4 minutes read.

Java Pass-by-Reference

In Java, passing parameters can be done using one of two fundamental methods. Pass-by-value is used for the first and pass-by-reference is used for the second. One thing to keep...

2 minutes read.

Empty Statement in Java

The three sorts of statements in Java are control, expression, and declaration statements. Additionally, another statement is referred to as an empty statement. In this section, we will discuss about...

4 minutes read.

How to download Eclipse for Java

Introduction: We write a java program, and when we want to run it, we need software to run it. Eclipse is a kind of software used to execute a JavaFX...

3 minutes read.

Concurrent Modification Exception In Java

When an object is attempted to be updated concurrently when it is not allowed, the ConcurrentModificationException arises. This error typically occurs while using Java Collection classes. When another thread is iterating...

5 minutes read.

How to override toString() method in Java?

Java is an object-oriented language. It only works with classes and objects. Thus, whenever we need to calculate, we need an object or objects that belong to the class. The Java method...

2 minutes read.

Upcasting and Downcasting in Java

Type casting in Java is an important and very interesting topic to deal with. But here upcasting and downcasting is somewhat related to typecasting. In normal typecasting, we convert from...

6 minutes read.

Awesome explanation of Strings in Java

What do you mean by String? Strings are a collection of characters that are commonly used in Java programming. Strings are regarded as objects in the Java programming language. “String” is a...

4 minutes read.

Method and Block Synchronization in Java

The Synchronization is performed in multi-threading concept. The multi-threading is a concept of parallel running of a program for the execution. In the multi-threading concept, the threads are run by...

3 minutes read.

POJO in Java

Plain old Java Object, in short, is called POJO in Java. POJO is an everyday object that is not subject to any specific limitations. We can use POJO in any Java...

3 minutes read.

Java Program to Create Set of Pairs Using HashSet

HashSet in Java: HashSet is an assortment in Java that has a place with java.util bundle. It inside utilises HashMap to store components. It is an execution of the Set connection...

11 minutes read.

Java Map Interface

A map is a collection that maps keys to values, with no duplicate keys allowed. The elements in a map are key/value pairs. HashMap: HashMap stores the keys in a...

3 minutes read.

Java Integer shortValue() method

The shortValue() method of Java Integer class returns a short value for this Integer after a narrowing primitive conversion. Syntax public short shortValue () Parameters NA Overrrides: The shortValue () overrides : shortValue in class Number  Return Value This...

1 minute read.

How to create a linked list in Java

Introduction: The linked listing is one type of linear statistics shaped like an array. Not like arrays, linked listing factors aren't stored in a contiguous place. The elements have linked...

3 minutes read.

Topological Sort In Java

Topological Sort in Java Topological sort is mainly used in the linear ordering of vertices in a Directed Acyclic Graph (DAG). Topological sort in Java illustrates how to do the linear ordering of...

1 minute read.

AES 256 Encryption in Java

Now a days, security has grown in importance. Java programming supports a variety of encryption and hashing methods, which offers security for data transport and communication among various nodes. In...

4 minutes read.