Java Naming Standards

From bibbleWiki
Revision as of 00:26, 4 July 2025 by Iwiseman (talk | contribs) (Created page with "=Introduction= I guess I run with whatever the linter tells me but wanted to capture '''a way''' here =Naming Standards= Here we go. {| class="wikitable" ! Type !! Convention !! Example |- | Variables || camelCase || <code>String userName = "John";</code> |- | Methods || camelCase || <code>public void calculateTotal() { ... }</code> |- | Parameters || camelCase || <code>public User getUser(String userId) { ... }</code> |- | Classes || PascalCase || <code>public class Us...")
(diff) ← Older revision | Latest revision (diff) | Newer revision → (diff)
Jump to navigation Jump to search

Introduction

I guess I run with whatever the linter tells me but wanted to capture a way here

Naming Standards

Here we go.

Type Convention Example
Variables camelCase String userName = "John";
Methods camelCase public void calculateTotal() { ... }
Parameters camelCase public User getUser(String userId) { ... }
Classes PascalCase public class UserAccount { ... }
Interfaces PascalCase public interface UserProfile { ... }
Enums PascalCase public enum UserRole { ADMIN, EDITOR, VIEWER }
Enum constants UPPER_SNAKE_CASE public enum UserRole { ADMIN, EDITOR, VIEWER }
Constants UPPER_SNAKE_CASE public static final int MAX_RETRY_ATTEMPTS = 3;
Package names lowercase package com.example.project;
Instance fields camelCase private int accountBalance;
Static fields camelCase (non-final) private static int userCount;
Generic type parameters Single uppercase letter public <T> void process(T item) { ... }
File names PascalCase.java (match class name) UserAccount.java
Test class names PascalCase with Test suffix UserAccountTest.java
JUnit test methods camelCase with descriptive names void shouldThrowExceptionWhenInvalidInput() { ... }