Sign in

This article will guide you to build your first GraphQL application in java step by step.

Generate a springboot project here and add graphql-spring-boot-starter andgraphql-java-tools into dependencies.

We start by adding a simple schema with a type Customer and a query for it. Name this file with a .graphqls suffix and place it under resources directory. The GraphQL spring boot start will pick it up and configure everything automatically.

type Customer {
id: ID!
name: String!
age: Int!
}


type Query {
customer(id: ID): Customer!
}

Create a POJO class to represent the Customer type that we defined in the…


In this article I’m gonna write everything you need to know about the pattern matching for instanceof which is introduced in java 16. Let’s start.

Download and install jdk16 here. Verify in command line javac -version .

We prepare a simple interface Animal and two classes Bird And Dog which implement the interface.

interface Animal {

}

private static class Bird implements Animal {
public void fly() {
System.out.println("Flying");
}
}

private static class Dog implements Animal {
public void bark() {
System.out.println("Barking");
}
}

And let’s define two animals for test:

Animal animal1 = new Bird();
Animal animal2 = new…

This article shows how to use the new records feature introduced in java15 and compares it with lombok.

Let’s start with a simple immutable class which holds a couple of private fields.

Add lombok annotations on top of the class:

import lombok.AllArgsConstructor;
import lombok.Getter;

@AllArgsConstructor
@Getter
public class TransactionLombok {
private final String from;
private final String to;
private final int amount;
}

A constructor with all arguments and getters are generated by lombok.

TransactionLombok transactionLombok = new TransactionLombok("you", "me", 100);
assertThat(transactionLombok.getFrom()).isEqualTo("you");
assertThat(transactionLombok.getTo()).isEqualTo("me");
assertThat(transactionLombok.getAmount()).isEqualTo(100);

Define a record:

record TransactionRecord(String from, String to, int amount) {
}

You get constructor and…


This article tells everything you need to know about text blocks in code examples.

Where can I find it?

Download and install JDK 15 from here. Verify in command line.

How to write it in code?

String example = """
example string""";

A line terminator after the opening quotes are needed. So this won’t work:

// error: illegal text block open delimiter sequence, missing line terminator
String example = """example string""";

What are the beneficial use cases?

There are many use cases where we can get benefit from using text blocks but I only list 3 typical ones.

Before

@Language("HTML")
String htmlOldWay = "<!DOCTYPE html>\n" +
"<html>\n" +…

Will

A full stack(overflow) developer

Get the Medium app

A button that says 'Download on the App Store', and if clicked it will lead you to the iOS App store
A button that says 'Get it on, Google Play', and if clicked it will lead you to the Google Play store