Course · Training · Workshop

Clean Code with Java

Two days hands-on: make Java code readable with fitting names, value objects, Optional and functional elements, secure legacy code with characterisation tests and evolve it test-first.

Java applications live for a long time. Over the years they collect services with too many jobs, data classes made of getters and setters, null checks at every other line and methods nobody fully grasps any more. This course shows Java teams how to improve such code step by step. Participants clarify names and levels of abstraction, recognise code smells and refactor with the automated refactorings of IntelliJ IDEA. They weigh duplication against premature abstraction, combine object-oriented design with functional elements, replace getters and setters with behaviour, flatten conditionals with Optional and introduce value objects for primitive types. On top of that come null-safe programming, exception handling, custom collection extensions, dependency injection and test-driven development. Participants practise in pairs on Java projects with Maven and JUnit 5, complemented by two katas on legacy code and object calisthenics. The course is part of the letsboot clean code family with one shared quality bar: code the team can read, change safely and test. For teams with several languages there is Clean Code Hands-On, for .NET Clean Code with C#, for the frontend Clean Code with TypeScript, and teams that want to tackle the structure of a whole Spring Boot application will find that in Clean Architecture with Spring Boot. At the end participants have applied every technique to exercise code of their own and hold a checklist for their team.

What participants say

These customers booked courses in the same topic cluster.More customers →

Content

The course is for Java teams that maintain and evolve existing applications. Participants practise in pairs in IntelliJ IDEA on Maven projects with JUnit 5.

The course consists of the following topics and can be adapted to the audience.

Naming, abstraction and code as communication

  • Names for variables, methods, classes and constants, magic numbers
  • Naming as a process: the seven stages from a missing name to a fitting one
  • Finding the right level of abstraction
  • Code as a story: who code is written for
  • Hands-On: improve names and levels of abstraction in a Java example

Refactoring and lean code

  • Cognitive load as a driver for refactoring
  • Categories of code smells and matching heuristics
  • Lean code and just-enough design
  • Automated refactorings in IntelliJ IDEA
  • Hands-On: Spot the Smell and guided refactoring of a Java method in pairs

Design strategies and principles

  • Balance between specific and abstract code
  • Reification: making implicit concepts visible as types of their own
  • DRY, WET and AHA: avoiding premature abstraction
  • Hands-On: refactor a task management system with reification

OOP and functional programming

  • Rich domain objects: bringing data and behaviour together
  • SOLID and the Law of Demeter
  • Do or Die Principle (DOD)
  • Pure functions for calculations, objects for responsibility
  • Hands-On: split a procedural payment flow into classes and pure functions

Null-safe programming and the Stepdown Rule

  • Strategies for null safety and how to choose one
  • Optional and the Null Object pattern
  • The Stepdown Rule: reading methods from top to bottom
  • Hands-On: make a class null-safe

Elegant and expressive code

  • From data to behaviour: replace getters with queries and setters with domain methods
  • Flattening nested conditionals with Optional
  • Guard clauses and small methods
  • Hands-On: turn the Messy Booking Processor into expressive domain objects

Object design and primitive obsession

  • Elegant Objects: small, immutable, with behaviour
  • Recognising primitive obsession, introducing value objects
  • Mutation and immutability, immutable collections
  • Hands-On: build an Address value object with validation and business rules

Exception handling, data classes, collections and dependency injection

  • Handling exceptions consistently, pluggable exception handling
  • Designing data classes with behaviour
  • Encapsulating collection logic in types of their own, example Eclipse Collections
  • Dependency injection: resolving hard-wired dependencies
  • Hands-On: write a custom collection extension with filterAdmins, findActiveUsers and sortByLastLogin

Test-driven development and legacy code

  • Red, green, refactor and the difference to test-after
  • Characterisation tests with ApprovalTests as a safety net
  • Object calisthenics as practice rules, checked with PMD
  • Hands-On: Legacy Code Prime Printer kata and Object Calisthenics LCD Numbers kata

At the end participants have practised every technique on Java code and created a clean code checklist for their team. Does your team work in several languages? Then Clean Code Hands-On is the fit. For the structure of whole applications with use cases, ports and modules there is Clean Architecture with Spring Boot.

The actual course content may differ from the above depending on the trainer, delivery, duration and the composition of participants.

Request this course in-house

By submitting you accept our Privacy Policy.

Request a public date

No suitable public date? Register without obligation — once there is enough interest we schedule a new public date and let you know first.

Number of participants (approx.)

More than 3 participants? Best to request a dedicated in-house date directly.

By submitting you accept our Privacy Policy.

More about Clean Code with Java

Clean code in Java combines the principles from the book by Robert C. Martin (2008, second edition 2025) with the means of the language. Lambdas, streams and Optional have been part of it since Java 8, and newer versions add records, sealed classes and pattern matching as further building blocks for value objects and expressive code. Joshua Bloch's «Effective Java» and the ideas of Elegant Objects still shape how Java teams talk about object design.

Further resources:

Related courses