explaingit

cxxr/better-java

5,764Audience · developerComplexity · 2/5Setup · easy

TLDR

A written style guide for experienced Java developers covering modern coding practices, useful third-party libraries, build tools, and development environment recommendations to write cleaner and more maintainable Java code.

Mindmap

mindmap
  root((repo))
    Coding Style
      Builder Pattern
      Immutable Data
      Optional Type
      Dependency Injection
    Libraries
      Guava Utilities
      Gson JSON
      Lombok Codegen
      SLF4J Logging
    Testing
      JUnit Unit Tests
      AssertJ Assertions
    Deployment Tools
      Maven Build
      IntelliJ IDEA
    Further Learning
      Books Podcasts
      Video Resources
Click or tap to explore — scroll the page freely

Code map

Detail Auto

An interactive map of this repo's files and how they connect — its source is parsed live in your browser. Click Visualize to build it.

filefunction / class

Things people build with this

USE CASE 1

Learn modern Java style conventions to replace outdated boilerplate-heavy patterns like JavaBeans with getters and setters.

USE CASE 2

Discover vetted third-party Java libraries that fill gaps in the standard library for JSON, dates, logging, and utilities.

USE CASE 3

Improve Java project setup by learning recommended build tools, editors, and code quality analysis tools.

USE CASE 4

Use as an onboarding reference to bring team members up to speed on cleaner Java practices and tooling choices.

Tech stack

JavaGuavaGsonJoda-TimeLombokSLF4JJUnitAssertJ

Getting it running

Difficulty · easy Time to first run · 5min

No code to run. Read the guide directly on GitHub. Apply recommendations incrementally to any existing Java project.

No license information mentioned in the explanation.

In plain English

Better Java is a written guide for people who already know Java and want to write it in a cleaner, more modern style. It does not contain a library or runnable code. It is a long article organized into sections covering coding style, deployment choices, useful libraries, and development tools. The style section argues against older Java habits that produce a lot of repetitive boilerplate. It recommends treating data-holding classes more like simple structs rather than the traditional JavaBean pattern with getters and setters for every field. It covers patterns like the Builder pattern for constructing complex objects, using immutable data structures so that values cannot be accidentally changed after creation, and avoiding null values by using the Optional type introduced in Java 8. The section also touches on when to use checked exceptions versus runtime exceptions and how to structure dependency injection, which is a way of writing code that is easier to test. The libraries section lists third-party packages that fill gaps in the Java standard library. These include Guava for common data structure utilities, Gson for converting Java objects to and from JSON, Joda-Time for working with dates and times before Java 8's built-in time library existed, Lombok for generating repetitive code automatically, and SLF4J for logging. Testing libraries covered include JUnit for writing unit tests and AssertJ for writing clearer test assertions. The deployment section covers build tools, specifically Maven, and how to manage dependencies and packaging. The tools section recommends IntelliJ IDEA as an editor, lists code quality analysis tools, and mentions a memory analyzer for diagnosing performance problems. The guide ends with a short list of books, podcasts, and videos for going deeper. It was originally posted as a blog article by the author and is available translated into Chinese. The full README is longer than what was shown.

Copy-paste prompts

Prompt 1
I am reading the Better Java guide. Help me refactor this JavaBean class to use the Builder pattern and immutable fields instead of getters and setters: [paste class here]
Prompt 2
Using the recommendations from the Better Java guide, review this Java method and suggest how to replace null returns with Optional and improve exception handling: [paste method here]
Prompt 3
Based on Better Java's library recommendations, help me add Guava, Gson, and SLF4J to my Maven pom.xml and show me a minimal usage example for each: [paste pom.xml here]
Prompt 4
Help me apply Better Java's dependency injection advice to decouple this class so it is easier to unit test with JUnit and AssertJ: [paste class here]
Prompt 5
I want to follow Better Java's style guidelines. Audit this Java file and list every place it violates the guide's recommendations around boilerplate, nulls, and immutability: [paste file here]
Open on GitHub → Explain another repo

← cxxr on gitmyhub — every repo by this author, as a profile.

Verify against the repo before relying on details.