11.3 Scope

In this section we start talking about Java coding conventions and why they matter. A coding convention is a set of rules so everyone writes code in roughly the same style, which makes it easier to pick up and modify code that someone else wrote. Three main reasons justify these conventions: about 80% of a project's lifetime is spent on maintenance, code is rarely maintained by the same person who originally wrote it, and consistent conventions improve readability and let a new developer understand the code more quickly. In a company, a new joiner who knows the conventions can immediately read code written by a developer who left several years ago.

Packages, classes and methods

Package names are always written in lowercase, often based on a reverse domain name followed by the project name, for example com.sitedu0.tests.projet. Naming packages this way avoids conflicts between classes that share the same simple name. Classes use PascalCase: each word starts with a capital letter. Abbreviations should be avoided, and the name should describe the class well without being too long, for example Listener. Interfaces follow the same convention as classes.

Methods use camelCase: a lowercase first letter and capitals for the following words. A method name generally contains an action verb, for example closeWindow, getName. Inside a class you often find getters and setters, which let you read or update a class variable without touching it directly: they are typically named getXxx and setXxx based on the variable name. Other common verbs include add and remove when something is added to or removed from a collection.

Variables and constants

Variables also follow camelCase: they start with a lowercase letter and the name should be short, clear and meaningful. Single-character names should be avoided except for short temporary usage like loop counters (i, j) — examples include size, doorEntry, i, j. Constants, declared as static final, are written in upper case with words separated by underscores, for example MAX_SIZE.

In short, coding conventions make your life and the life of the developers who come after you a lot easier. See you in the next video.