Work when you want, how you want, wherever you want in the world.

Camel Case

Jul 25, 2023

Camel in the desert in front of a Pyramid in Egypt.

Camel case is a naming convention used in programming where multiple words are combined into one identifier. It is called camel case because the capital letters within the identifier resemble the humps of a camel. Camel case eliminates spaces between words. Instead, words are concatenated (combined together), and each subsequent word starts with a capital letter. There are two main styles of camel case: upper and lower camel case:

Lower Camel Case - The first letter of the identifier starts with a lowercase letter, and each subsequent word's initial letter is capitalized.

example:
lowerCamelCase

Upper Camel Case - The first letter of the identifier starts with an uppercase letter, and each subsequent word's initial letter is capitalized. Upper camel case is sometimes also called PascalCase.

example:
UpperCamelCase

Standard Practice

When using camel case, there are standard practices, or guidelines, that should be followed:

Avoid using special characters like hyphens, underscores, or any other punctuation in camel case identifiers. Stick to letters and numbers only.

You can use numbers in a camel case name, but the name should never begin with a number.

projectVersion1 - This is acceptable.

1stProjectVersion - This is NOT.

When Is Lower Case Preferred?

Lower Camel Case is commonly used for naming variables and methods, but usage is up to personal preference. Here are a few examples:

Variables
// Declaring and initializing variables
int myAge = 25;
double accountBalance = 1000.50;
String firstName = "John";
boolean isLoggedIn = false;
Methods
// Method declaration
public void printMessage() {
    System.out.println("Hello, world!");
}

public double calculateSum(double num1, double num2) {
    return num1 + num2;
}

When Is Upper Case Preferred?

Upper Camel Case is often used for naming classes, interfaces, and enums. Here's how you can use upper camel case in these scenarios:

Classes

public class Person {
    // Class code goes here
}

public class BankAccount {
    // Class code goes here
}

Interfaces

public interface MyInterface {
    // Interface code goes here
}

Enums

public enum DaysOfWeek {
    MONDAY,
    TUESDAY,
    WEDNESDAY,
    THURSDAY,
    FRIDAY,
    SATURDAY,
    SUNDAY
}

Camel case is a widely adopted convention across different programming languages. It's a useful naming convention for creating readable and consistent identifiers in code. Whatever your preference, whether you choose to code using lower or upper camel case, the key is to remain consistent. Following the accepted standard will make your code easier to understand for other developers on your team.

Latest Articles

Single Responsibility Principle

The Single Responsibility Principle (SRP) is one of the five SOLID principles of object-oriented programming and design, introduced by Robert C...

Read More

Singleton Design Pattern

The Singleton Design Pattern is one of the most commonly used design patterns in software engineering...

Read More

MVC: Model-View-Controller Design Pattern

Model-View-Controller (MVC) is a software architectural pattern used in the design and development of applications, particularly in the context of user interfaces...

Read More

The MEAN Stack

The MEAN stack is a popular technology stack used for building web applications...

Read More

The Internet of Things

The Internet of Things (IoT) refers to the interconnection of everyday objects and devices to the internet, allowing them to collect and exchange data with each other and with centralized systems or applications...

Read More

The Cloud

Cloud computing is a technology that enables users to access and use computing resources (such as servers, storage, databases, networking, software, and more) over the internet and on-demand...

Read More