Java Naming Convention — Java Technical Interview Questions & Answers

Java Naming Convention

Java Naming Convention

  • Java names follow a house style so teammates can read your code. Classes: PascalCase — StudentService, BankAccount. Methods and variables: camelCase — calculateTotal, studentName.
  • Constants: UPPER_SNAKE — MAX_SIZE, DEFAULT_TIMEOUT. Packages: lowercase with dots — com.company.app. Prefer daysLeft over d. The name should say the purpose.
  • Wrong style looks amateur: class student, or method CalculateTotal. Recite the four styles in fifteen seconds in an interview.
  • Let's take this on the board with one tiny Main class — no extra files. Java Naming Convention — output: 3 then 100. studentCount is camelCase; MAX_MARKS is a constant. Class names like Student use PascalCase. Start from main, go line by line, and stop at each print. That output is the proof for Naming Convention.

Technical Interview Tip: Four styles: class, method, constant, package — with one example each.

Code Examples for Java Naming Convention

Example

// Naming convention
public class Main {
  public static void main(String[] args) {
    int studentCount = 3;
    final int MAX_MARKS = 100;
    System.out.println(studentCount);
    System.out.println(MAX_MARKS);
  }
}

Java Naming Convention — output: 3 then 100. studentCount is camelCase; MAX_MARKS is a constant. Class names like Student use PascalCase.

How to Explain Java Naming Convention to an Interviewer

How do you name a class?

PascalCase BankAccount

How do you name a method?

camelCase calculateTotal

How do you name a constant?

UPPER_SNAKE MAX_SIZE

How do you name a package?

lowercase dots com.company.app