Sign up
Forgot password?
FAQ: Login

Hock Martin. Elegant Java: Hands-on Guide to write Clean Code in Java

  • pdf file
  • size 560,60 KB
Hock Martin. Elegant Java: Hands-on Guide to write Clean Code in Java
Leanpub, 2023. — 74 p.
This book discusses the best practices for writing better code. It also contains many code examples in Java of increasing complexity.
Java Best Practices:
Avoid instantiation for utility classes.
Use immutable objects.
Prefer records for immutability.
Provide immutable decorators for sensitive mutable classes.
Consider using sealed classes and interfaces.
Avoid constant interfaces.
Avoid global constant classes.
Favor composition over inheritance.
Consider using lambdas.
Use meaningful return types.
Use the @Override Annotation.
Use the @FunctionalInterface Annotation.
Prefer returning Null-Objects over null.
Avoid null as a method parameter.
Prefer enhanced loops over for loops.
Code against interfaces, not implementations.
Use existing exceptions.
Validate method parameter.
Minimize method parameters for improved readability.
Prevent NullPointerException for String comparison.
Safely cast long to int.
Convert integers to floating-point for floating-point math operations.
Use generics in favor of raw types.
Prefer enums over int constants.
Prefer the == operator over equals for comparing enum values.
Be aware of the contract between equals and hashCode.
Use text blocks for multi-line strings.
Use always braces for the body of all statements.
Simplifying boolean expressions.
Pre-calculate the length in loops.
Avoid constructor instantiation of String.
Use StringBuilder for concatenation.
Reduce lookups in collection containers.
Instantiate wrapper objects with valueOf.
Use entrySet for iterating.
Use isEmpty() for String length.
Avoid using the default case in switch statements for sealed classes.
Prefer method references over lambdas for conciseness.
Use the orElse and orElseGet methods for optional values.
Enhance code clarity with EnumMap.
  • Sign up or login using form at top of the page to download this file.
  • Sign up
Up