Introduction to Java · Introduction to Java Programming

Naming Conventions in Java

Watch lectures

Naming Conventions in Java

1. Why Names Matter

Good names = readable code = fewer bugs + marks for style. Java community follows camelCase + PascalCase rules (not enforced by compiler, but checked by teachers/reviewers).

2. Rules Table (memorize)

Element Rule Good Bad
Class PascalCase (noun) Student, BankAccount student, bank_account
Method camelCase (verb) getMarks(), printBill() GetMarks(), print_bill()
Variable camelCase, short but clear totalMarks, i (loop ok) TotalMarks, x1x
Constant UPPER_SNAKE MAX_MARKS, PI maxMarks
Package lowercase, reversed domain com.college.fees Com.College

3. Code — Good vs Bad

// BAD (works but ugly, loses style marks)
class student { int TOTAL; void Print() { TOTAL = 100; } }
// GOOD (clean, professional)
class Student {
    static final int MAX_MARKS = 100;
    int totalMarks;
    void printTotal() { System.out.println(totalMarks); }
}

4. Beginner Rules That Break Code

  • Must start with letter/_/$ (not digit): marks1 ok, 1marks error.
  • Case-sensitive: Marks ≠ marks.
  • No keywords: class, int, new cannot be names.

5. Exam Points

  • Table of 4-5 conventions with examples — 5 marks, very frequent.
  • Constant + package rules — 2-3 marks, frequent.
Official AppAndroid App

PYQDeck for Android

Solve BEU previous-year exam papers anywhere, anytime. Fast search, offline paper viewing, and step-by-step solutions designed specifically for your phone.

← All Introduction to Java Programming modules