Java Tutorials
  • Introduction to Java
    • What is Java?
    • History and Features of Java
    • Java Virtual Machine (JVM) and Bytecode
    • Why Java?
  • Setting up Java Development Environment
    • Installing Java Development Kit (JDK)
    • JDK vs JRE
    • Setting up IDE (Eclipse, IntelliJ, NetBeans) or Text Editor (VS Code, Sublime Text)
  • Basic Java
    • First Java Program : Hello World
    • Variable
    • Data Type
    • Constant
    • Date and Format
    • Operator
    • Condition
    • Looping
    • Function
    • Variadic Function
    • Enums
    • Array
    • Collection
    • Exception and Exception Handling
    • Naming Convention
  • Object Oriented Programming (OOP)
    • Classes and Objects
    • Inheritance and Polymorphism
    • Encapsulation and Abstraction
  • File Handling
    • Reading and Writing Binary File
    • Reading and Writing Text File
    • Serialization and Deserialization
  • Multithreading
    • Creating and Running Threads
    • Synchronization
    • Thread Pools and Executors
  • Collections API
    • Sorting and Comparable
    • Searching and Comparator
  • Java Database Connectivity (JDBC)
    • Introduction and Life Cycle
    • Connection to Database (MySQL)
    • Downloading JDBC Drivers for Various Databases
    • Maven and Gradle JDBC Drivers for Various Databases
    • JDBC URL Formats
    • Statement and PreparedStatement
    • CallableStatement
    • Selecting Data using JDBC
    • Inserting Data using JDBC
    • Updating Data using JDBC
    • Deleting Data using JDBC
    • Invoking Function and Stored Procedure using JDBC
  • Lambda
    • Introduction to Lambda Expressions
    • Functional Interface
    • Filtering, Mapping, Reducing
    • Lambda Expressions in Collections
    • Method References
    • Functional Programming Concepts
    • Stream API
    • Error Handling in Lambda Expressions
    • Optional in Functional Programming
    • Parallel Processing with Lambda
    • Functional Programming Patterns
    • Advanced Topics in Lambda Expressions
    • Best Practices and Design Patterns
    • Real-World Use Cases and Examples
Powered by GitBook
On this page
  1. Basic Java

Naming Convention

Naming conventions in Java are a set of rules and guidelines used to create meaningful, descriptive, and consistent names for classes, variables, methods, packages, and other elements in Java programs. Adhering to these conventions enhances code readability, maintainability, and collaboration among developers.

Here are some common naming conventions in Java:

  1. Classes and Interfaces:

    • Class names should be nouns and start with an uppercase letter. Use camel case for compound words (e.g., Car, StudentInformation, Calculator).

    • Interface names should also follow the same rules as class names.

    public class Car {
        // class body
    }
    
    public interface Vehicle {
        // interface body
    }
  2. Methods:

    • Method names should be verbs and start with a lowercase letter. Use camel case for compound words (e.g., calculateArea(), printDetails()).

    public void calculateArea() {
        // method body
    }
    
    public void printDetails() {
        // method body
    }
  3. Variables:

    • Variable names should be descriptive, using meaningful names that convey the purpose of the variable. Use camel case for compound words (e.g., count, totalAmount, userName).

    • Instance variables should start with this keyword to distinguish them from local variables.

    public class Example {
        private int count; // instance variable
    
        public void setCount(int count) {
            this.count = count; // using "this" for instance variable
        }
    }
  4. Constants:

    • Constant names should be all uppercase letters with underscores separating words (e.g., MAX_VALUE, PI).

    public class Constants {
        public static final double PI = 3.14159;
        public static final int MAX_VALUE = 100;
    }
  5. Packages:

    • Package names should be in lowercase letters. Use a reverse domain name as the prefix to ensure uniqueness (e.g., com.example.project).

    package com.example.project;
  6. Enums:

    • Enum types should be in uppercase letters. Enum constants should be in uppercase letters with underscores separating words.

    public enum DaysOfWeek {
        MONDAY, TUESDAY, WEDNESDAY, THURSDAY, FRIDAY, SATURDAY, SUNDAY
    }
  7. Boolean Variables and Methods:

    • Boolean variables should sound like predicates and start with "is" or "has" (e.g., isReady, hasPermission).

    • Boolean methods should start with "is" or "has" and return a boolean value.

    public class User {
        private boolean isActive;
    
        public boolean isActive() {
            return isActive;
        }
    }

By following these naming conventions, your Java code becomes more readable and consistent, making it easier for you and other developers to understand and maintain the codebase.

PreviousException and Exception HandlingNextClasses and Objects

Last updated 1 year ago