Clean Code
Last modified on Fri 17 Apr 2026

Working code does not mean good code. Bad code works too. It would be easier if it didn't, but it does. In this chapter we'll mention some good practices when writing code, so the code will be easier to read, understand and maintain.

Before we get to real work, let's define what good code means.

Okay, now we are off to a good start. You know how good code looks, now let's see how we can achieve it.

Clear names

The first rule of elegant code is: write clear names. Here are some general guidelines:

Methods

Java is an object-oriented language. This means that objects communicate with each other, usually by methods. It is important to write good structured methods:

Objects and data structures

While coding, you are going to deal with objects and data structures. There is a difference between the two: objects hide their data behind abstractions and expose methods that operate on that data. Data structure expose their data and have no meaningful methods.

When working with objects, make sure to implement these rules:

Error Handling

Error handling is an important part of your code. It can make or break your application, so make sure you do it right:

Boundaries

Classes

A class is a template for an object. The goal is to code good classes because that leads to good code: