×

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 Create File

A File is a hypothetical way, which has no genuine presence. It is very much like while "using" that File that the major real activity of putting away something in...

5 minutes read.

Hello Program in Java

Hello Program in Java The Hello program in Java displays the word Hello on the console. It is the basic program in Java. In this section, we will learn different ways...

3 minutes read.

Java Macros

Macros are additions to the JDK 7 compiler in Java. Compile time macros are added and supported. Macros are Java classes that are instantiated and executed during the compilation process....

2 minutes read.

Difference between this and super in Java

In this article, you will be very well equipped with the knowledge of this keyword and super keyword in java. You will be able to understand where to implement this...

3 minutes read.

Java Float Keyword

Float: In general, there are two categories of data types: primitive data types and non-primitive data types. So, float is the data type which is a primitive data type. Declarating the variables and...

3 minutes read.

MessageDigest in Java

The compression of mathematical numbers is accomplished using hash functions. In almost every data security application, hash functions are employed. The hashing, often called has values, returns a value called...

3 minutes read.

Permutation Coefficient in Java

In this tutorial, we will get familiar with the permutation coefficient in Java.  We will understand it through examples and see different approaches to solving the problem. A permutation is a...

5 minutes read.

Tetranacci Number in Java

This article mainly describes tetranacci number identification and the Java Program for Tetranacci numbers. Tetranacci number Tetranacci numbers and Fibonacci numbers are related. The key contrast is that a Tetranacci number depends...

3 minutes read.

Switch Case Program in Java

Switch Case Program in Java The switch case program in Java controls which code snippet gets executed on the basis of the value of the expression mentioned in the switch statement....

22 minutes read.

Sum of digits in string in java

To find the sum of all digits in a string, you need to traverse through the string one by one character; if the character is an integer, you need to...

2 minutes read.

Java Else Keyword

The else statement specifies a section of Java code that will run if an if statement's condition is false.The following conditional statements can be used in Java:To provide a block...

3 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.

The Diamond Operator in Java 7

The Diamond operator is a comparatively recent Java operator originally developed in JDK 7 to enhance type identification and eliminate boilerplate Java code. The Diamond operator is characterized by a...

2 minutes read.

Java Throw and Throws Keyword

Exceptions in Java enable us to construct high-quality programs where faults are checked at compile time rather than run time and where we may define unique exceptions that make code...

6 minutes read.

How to Convert Binary to Decimal in Java

How to Convert Binary to Decimal in Java There are two methods to convert binary to decimal. Using Integer.parseInt() method Using user-defined logic Using Integer.parseInt() method The parseInt() is a static method of...

2 minutes read.

Java Integer valueOf() method

The valueOf() method of Java Integer class returns an Integer object holding the specified int value. The second method returns an Integer object holding the specified String value. The third syntax returns...

2 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.

Shallow copy in Java

Java's most important task is making a copy or clone of an object. In this part, we'll talk about shallow copies in Java and how to make them of Java...

4 minutes read.

How to Convert Date to String in Java

How to Convert Date to String in Java We need to convert Date to String in Java may for displaying purpose. We can convert Date to String in Java using the format() method of java.text.DateFormat class. There...

2 minutes read.

Java Boolean hashCode() Method

The hashCode() method of Boolean class returns the hash code for the specified Boolean object or the given Boolean value. Syntax public int hashCode()public int hashCode(boolean value) Parameters The parameter ‘value’ represents the value...

2 minutes read.