0/0
OOP Fundamentals

Java Coding Conventions

Master naming conventions, file organization, and formatting rules that make Java code readable, consistent, and professional.

Java Naming Convention Hierarchy
Loading diagram...
Anatomy of a Java Source File
Loading diagram...
Explore Topics
1
The goals and benefits of consistent coding style
Why Conventions Matter
🔍 Convention Lint Inspector— spot the violation (1/8)
class student_record {
📏

Why Conventions Matter

The goals and benefits of consistent coding style

Coding conventions are sets of guidelines covering coding style, naming rules, file organization, and best practices. They exist to maintain a unified code style across teams, minimize maintenance costs, improve readability, and speed up development. Without conventions, code becomes inconsistent and harder to understand — especially when multiple developers contribute to the same project.

Key Ideas
1Conventions cover: naming, formatting, comments, file organization, best practices
2Goal 1: Maintain unified code style across a team
3Goal 2: Minimize software maintenance costs (80% of software cost is maintenance)
4Goal 3: Improve code readability for current and future developers
5Goal 4: Speed up onboarding and development velocity
Strengths
  • ✦Makes code self-documenting through consistent naming
  • ✦Reduces cognitive load when reading unfamiliar code
  • ✦Enables automated tools (linters, formatters) to enforce rules
  • ✦Professional standard expected in industry
Weaknesses
  • △Learning and internalizing rules takes initial effort
  • △Debates over conventions can waste time ("tabs vs spaces")
  • △Rigid enforcement can feel restrictive for simple scripts
Used in:Every major company (Google, Oracle, Amazon) has a style guide; open-source projects enforce conventions via CI

Why Conventions Matter Quiz

Why Conventions Matter Quiz
QUIZ 1/7
What percentage of software cost is typically spent on maintenance?

Practice Exercises

Match each identifier to its correct naming convention:
EXERCISE 1/3
com.depaul.se450
StudentRecord
getFullName
MAX_RETRY_COUNT
firstName
Serializable
Package (all lowercase)
Class (UpperCamelCase)
Method (lowerCamelCase)
Constant (UPPER_SNAKE)
Field (lowerCamelCase)
Interface (UpperCamelCase)
Classify each rule: Oracle style or Google style?
EXERCISE 2/3
4-space indentation
2-space indentation
80-character line limit
100-character column limit
Wildcard imports allowed
Explicit imports only
Oracle Code Conventions (1999)
Google Java Style Guide (2018)
Sort these elements in the correct order within a Java source file:
EXERCISE 3/3
Import statements
Package declaration
Instance fields
Class declaration
Static constants
Constructors
1st
2nd
3rd
4th (inside class)
5th (inside class)
6th (inside class)