Skip to main content

Java

  • Baeldung continues to be one of the best online resources for Java and Spring developers. Their content is very well written.

I am working on a tech tree to cover several popular, valuable concepts that I feel Java developers should know. This is a work-in-progress. Clicking on the image below will take you to the Graphviz source.

Libraries​

JPA​

JPA is Java’s built-in persistence mapper. It’s all annotation-driven.

Mocking​

Mockito is my preferred mocking library. It does support static mocking when required, although static code is a code smell and a sign something should be refactored.

See: Mocking Static Methods With Mockito, Baeldung

Example:

// The static mock is scoped within the try statement. Neat!
try (MockedStatic<MyClass> myClass = mockStatic(MyClass.class)) {
myClass.when(MyClass::performOperation).thenReturn("foo");
myClass.when(() -> MyClass.withArguments("foo")).thenReturn("bar");
}

One-to-One Mappings​

Assume the following structure. The COMPANY table is the owner of the data.

An entity relationship diagram of two tables, &#39;COMPANY&#39; and &#39;COMPANYADDRESS&#39;. The company table has an ID and name, and the company address table has an ID, company ID foreign key, and street. There is a one-to-one relationship between the two tables.

The entities would look like this:

@Entity
public class Company {
private Long id;

private String name;

@OneToOne(mappedBy = "company")
private CompanyAddress address;
}

@Entity
public class CompanyAddress {
private Long id;

@OneToOne
@JoinColumn(name = "company_id", referencedColumnName = "id")
private Company company;

private String street;
}

Spring​