Carl Martensen

I’m a Software Engineer in New York City

Read this first

Java 9’s Immutable Collections Are Easier To Create But Use With Caution

Code is easier to reason about when collections cannot be altered after their creation. Having to keep track of the current state of a collection as it gets passed around from this method to that equates to more mental balls to juggle. Mutating the state of methods` arguments is called a side effect and is a cardinal sin of functional programming. Since immutability is almost inarguably better why do Java developers generally completely ignore it?

 Instantiating an Immutable Collection in Java 8

Creating immutable collections in Java is convoluted to the point that it’s probably not worth the price of admission. This is a best practice implementation of an immutable set in Java 8:

Set<String> set = Collections.unmodifiableSet(new HashSet<>(Arrays.asList("darth", "plagueis", "the", "wise")));

By comparison, here’s the same thing in Scala:

val set = Set("darth", "plagueis", "the",

Continue reading →

Create a Asynchronous REST API with Spring MVC and CompletableFutures

Spring MVC is a versatile framework for building RESTful APIs. Spring has long supported asynchronous endpoints through its DeferredResult, which frees up request processing threads to handle other requests while responses are built in the background. This can greatly increase throughput for IO intensive APIs. Here’s a simple example.


public class DeferredController {
  public DeferredResult<String> get(@RequestParam String input) {
    DeferredResult<String> defResult = new DeferredResult<>();

    new Thread(() -> { 
      String apiResponse = callApi(input)

    return defResult;

  String callApi(String str) {
    // restTemplate.invoke(...)
    return str.toUpperCase();


Java 8 introduced CompletableFuture which can be used

Continue reading →

Step-by-Step Guide to Deploying Your First Full-Stack Spring Boot Application in AWS

Feel free to email me if you have suggestions or questions about this tutorial or Spring Boot AWS setup in general.


This guide starts with a simple Spring Boot hello world application, wires it into a database, and goes through each step in deploying it to AWS backed by a Postgres database.

We will first build and deploy the application locally and then deploy it to AWS.

 Setting up your dev environment

The first thing is getting your environment set up with the Java 8 JDK, git, Maven 3, and PostgresSQL. For mac users with homebrew installed, this may be as simple as:

brew install java
brew install maven
brew install git
brew install postgresql

 Building the application locally

Now that our dev environment is configured, lets build a web application. Pull down the sample application from git using git clone

Continue reading →