Have a question?
Message sent Close
View Categories

Naming Conventions

Naming Conventions

  • Convention: Class names should be in PascalCase (also known as UpperCamelCase).
  • Rule: The first letter of each word is capitalized.
  • Example: CustomerAccount, EmployeeDetails, LinkedList.

  • Convention: Interface names should also be in PascalCase.
  • Rule: They often describe a capability or behavior.
  • Example: Runnable, Comparable, Serializable.

3. Methods #

  • Convention: Method names should be in camelCase.
  • Rule: The first letter of the first word is lowercase, and the first letter of each subsequent word is capitalized.
  • Example: getName(), calculateTotal(), processData().

4. Variables #

  • Convention: Variable names should be in camelCase.
  • Rule: The first letter of the first word is lowercase, and the first letter of each subsequent word is capitalized.
  • Example: firstName, totalAmount, employeeList.

  • Convention: Constants should be in all uppercase letters with words separated by underscores.
  • Rule: They are usually declared as static final.
  • Example: MAX_VALUE, DEFAULT_TIMEOUT, PI.

  • Convention: Package names should be in all lowercase letters.
  • Rule: They often start with the top-level domain name followed by the company name and project or module name.
  • Example: com.example.project, org.openai.chatgpt.

  • Convention: Annotation names should be in PascalCase.
  • Rule: The first letter of each word is capitalized.
  • Example: @Override, @Deprecated, @SuppressWarnings.

  • Convention: Enum names should be in PascalCase.
  • Rule: The first letter of each word is capitalized, and enum constants are usually in all uppercase letters with words separated by underscores.
  • Example: public enum Day { SUNDAY, MONDAY, TUESDAY, WEDNESDAY, THURSDAY, FRIDAY, SATURDAY }

  • Convention: Type parameter names should be single, uppercase letters.
  • Rule: Commonly used letters are T for type, E for element, K for key, V for value, and so on.
  • Example: public interface Comparable<T>, public class HashMap<K, V>.

📄
filename.js
package com.example.project;

public class CustomerAccount {

    private String firstName;
    private String lastName;
    private static final int MAX_CREDIT_LIMIT = 10000;

    public CustomerAccount(String firstName, String lastName) {
        this.firstName = firstName;
        this.lastName = lastName;
    }

    public String getFirstName() {
        return firstName;
    }

    public void setFirstName(String firstName) {
        this.firstName = firstName;
    }

    public String getLastName() {
        return lastName;
    }

    public void setLastName(String lastName) {
        this.lastName = lastName;
    }

    public static int getMaxCreditLimit() {
        return MAX_CREDIT_LIMIT;
    }
}

interface Printable {
    void print();
}

enum Status {
    NEW, PROCESSING, COMPLETED, FAILED
}