Java Practices Every Developer Must Avoid

Common Java Coding Pitfalls (and How to Avoid Them)

Skilled Coder
4 min readDec 11, 2024

--

Below are several Java “bad practices” that you should avoid. These examples highlight subtle pitfalls or questionable approaches that can lead to confusion, maintenance headaches, or performance issues.

While some of these are known to experienced developers, they’re often overlooked by newcomers.

1. Using System.out.println for Logging

Why avoid it
Relying solely on System.out.println makes it difficult to manage output, filter messages by importance, or handle logging in production environments. A proper logging framework (like java.util.logging, Log4j, SLF4J, or Logback) provides levels, formatting, and better control.

Bad Example

public class UserService {
public void createUser(String name) {
// Bad: Using println for “logging”
System.out.println("Creating user: " + name);
// ... creation logic
}
}

Better Approach

import java.util.logging.Logger;

public class UserService {
private static final Logger LOGGER = Logger.getLogger(UserService.class.getName());

public void createUser(String name) {…

--

--

Skilled Coder
Skilled Coder

Written by Skilled Coder

Sharing content and inspiration on programming.

Responses (4)