I am a Software Engineer with a passion for UI/UX design, backend development, and DevOps. Outside of work, I enjoy calisthenics, yoga, acrobatics, running, drawing, and CAM.

You may already be familiar with Java, but if not, it’s worth noting that Java is a versatile and widely-used programming language. Known for its platform independence, Java allows developers to write code once and run it anywhere, thanks to the Java Virtual Machine (JVM). It’s a high-level, object-oriented language that has become a cornerstone of software development, powering everything from enterprise applications to Android mobile apps and web servers.
My recommended best practices for Java are both common and widely adopted. Moreover, these practices are versatile and can be applied to most object-oriented programming (OOP) languages.
Visit My General Coding Best Practices
ExceptionHandler class:
class ExceptionHandler {
public void handle(CustomException exception) {
// Handle my custom exception according to business logic
}
public void handle(NullPointerException exception) {
// Handle null pointer exception to aid in resolution
}
public void handle(NotFoundException exception) {
// Handle not foud exception as an http exception for example
}
}
java.util.concurrent package. This package offers utilities such as:
List<String> namesForPeopleVeryOld = persons.stream()
.filter(Person::isOld)
.map(Person::getName)
.collect(Collectors.toList());
var exclusively for local variables to enhance readability and reduce redundancy when writing code. This approach also ensures that type safety is maintened:
var name = "John";
var flavourDesignation = switch (flavour) {
case VANILLA -> "Sweety Vanilla";
case CHOCOLATE -> "Strong Cocoa Chocolate";
default -> "Raw for the strongest";
};
null, consider using the Optional API to enhance readability and eleminate unnecessary null checks:
Optional<Integer> age = Optional.ofNullable(form.getAge());
age.ifPresent(FormValidator::validateAge);
Optionaldoes not support primitive types
Consider using test extensions for complex setups and tear-downs when working with Junit 5. For Junit 4, create classes that extend ExternalResource and override the before and after methods, or implement the TestRule interface to achieve similar functionality.
public class MyLifeCycleExtension implements
BeforeTestExecutionCallback,
AfterTestExecutionCallback
{
@Override
public void beforeTestExecution(ExtensionContext context) {
// Setup before the test
}
@Override
public void afterTestExecution(ExtensionContext context) {
// Teardown after the test
}
}
Consider using the method doAnswer from Mockito for handling complex and dynamic return behaviours. However, avoid using it in new code, as tests should remain simple, and cyclomatic complexity should be minimized to ensure clarity and maintainability.
Consider using the ArgumentMatcher class from Mockito to validate complex arguments in tests. For improved reusability and maintainability, define these matchers in dedicated classes.
This page is still a work in progress