How to Build Java Applications Today: July 12, 2021
Tags: java, bpf
Published: 2021-07-12 21:54:32

## TL;DR
TIOBE Index July 2021, Spring blesses GraphQL, tuning Hibernate’s query plan cache, GitHub previews AI coding assistant, Quarkus 2.0.1, Spring Cloud Hoxton.SR12, and a terrible chart.
 
***

## README
This is **issue 44** of my weekly newsletter, “How To Build Java Applications Today”. I read all the Java newsletters, so **you** don’t have to! And it’s “Java news with a smile”.

If you like my newsletter, then [subscribe to it on Substack](https://bpfnl.substack.com)! Or read it on [dev.to](https://dev.to/ksilz/series/11995),  the [Java Cafe](https://thejavacafe.com/ksilz/series/1), or [Medium](https://ksilz.medium.com). Even better: Share it with people who may be interested.

***

## Quote of the Week
*If everything seems under control, you're not going fast enough‌.*
[Mario Andretti](http://www.quotationspage.com/quote/39999.html), American race car driver ([born 1940](https://en.wikipedia.org/wiki/Mario_Andretti)), encourages us to release faster. Or so I think.

***

## Stand-Up
My host country England [lost the European Football Championship to Italy](https://www.bbc.co.uk/sport/football/51198762) last night (that’s soccer for my US readers). Adding insult to injury: The final game [was in London](https://en.wikipedia.org/wiki/UEFA_Euro_2020#Final), and England lost in a penalty shoot-out, as they have so often in the past.

And yes, the United Kingdom has four different football teams: England, Wales, Scotland, and Northern Ireland. Except for Northern Ireland, [all took part](https://en.wikipedia.org/wiki/UEFA_Euro_2020#Qualified_teams) this time.

I can relate to the pain: When Germany hosted the Football World Cup in 2006, [Italy defeated us Germans](https://en.wikipedia.org/wiki/2006_FIFA_World_Cup#Semi-finals) in the semi-final and [went on to win](https://en.wikipedia.org/wiki/2006_FIFA_World_Cup#Final) (against France, also in a penalty shoot-out). BTW: [England lost](https://en.wikipedia.org/wiki/2006_FIFA_World_Cup#Quarter-finals) in a penalty shoot-out against Portugal back then…

***

## Code Review
### Issue 42 from June 28, 2021
I [wrote about the Scala 3 release](https://bpfnl.substack.com/p/how-to-build-java-applications-today-ff1) - eight years in the making - two weeks ago. Want to hear more? Then listen to [Java Pub House podcast episode 97](https://javapubhouse.libsyn.com/episode-97-hey-there-scala-3-looking-good-with-those-new-features)! Dean Wampler, the author of the just-published O'Reilly book [“Programming Scala” book](https://deanwampler.github.io/books/programmingscala.html), explains what’s new in Scala 3.
 
***

[Two weeks ago](https://bpfnl.substack.com/p/how-to-build-java-applications-today-ff1), I also wrote about “Java Applications in the Windows 11 App Store”. And [last week](https://bpfnl.substack.com/p/how-to-build-java-applications-today-b5c), I told you that you can download a preview. What I forgot to mention is that The Verge, like many other sites, has a [video preview of Windows 11](https://www.youtube.com/watch?v=eSajMxAelcc).

***

## Bookmarks
### Java
#### TIOBE Index July 2021: Java Strikes Back - For Now
When we last looked at the popular monthly programming language ranking, Python placed ahead of Java two months in a row (see [issue #40](https://bpfnl.substack.com/p/how-to-build-java-applications-today-457)). Well, this month, Java recaptured second place with 11.17%, a hair ahead of Python at 10.95%. But C at the top is only ahead of Python by 0.67%, so expect frequent changes in the first three spots over the next few months.

The good news: Java can bounce back! The bad news: The long-term trend for Java is “down”. Check this [TIOBE graph](https://www.tiobe.com/tiobe-index/java/): Java fell from 26.5% in June 2001 to 11.2% today, which is a loss of 58%. 

Good news again: Java has a **shrinking** slice of a **growing** pie because the number of software developers [grows every year](https://www.daxx.com/blog/development-trends/number-software-developers-world). And more good news: In a world of microservices, it’s easier for us to write our code in Java, even if another team writes their code in Python, TypeScript, or C#.

[TIOBE Index July 2021](https://www.tiobe.com/tiobe-index/?20210704)

***

### Frameworks & Libraries
#### Spring Blesses GraphQL
GraphQL a statically typed query language for APIs that has [advantages over JSON REST APIs](https://graphql.org/faq/#why-should-i-use-graphql). Spring now integrates GraphQL with a project predictably named [Spring GraphQL](https://spring.io/blog/2021/07/06/hello-spring-graphql). It’s the successor of the [GraphQL Java project](https://www.graphql-java.com) that has existed for six years.

No matter if you use Spring or not: An official Spring project lends credibility to GraphQL. So if you already use GraphQL: Good for you! If not: Why not [learn it](https://graphql.org/learn/)?

A Spring GraphQL 1.0 milestone is available now. The 1.0 release will probably arrive early next year. That’s why Spring GraphQL will have to wait two more Spring Boot releases before it gets included there - in May 2022, if this year is any indication.

Talking about Spring Boot: Given the expected version jump of the Spring framework from 5.3 to 6.0 this fall, I thought Spring Boot would follow suit and go from 2.5 to 3.0. Well, I was wrong: The announcement talks about Spring Boot 2.6 and 2.7. 😒

[Announcement](https://spring.io/blog/2021/07/06/introducing-spring-graphql)

***

#### How to Tune Hibernate’s Query Plan Cache
Chances are, our Java projects use Hibernate to access data sources. Did you know that Hibernate needs to compile queries and store them in a cache with a default size of 2048 entries? I didn’t either.

Now, if our application uses more queries, then performance will suffer: Preparing [JPQL](https://en.wikipedia.org/wiki/Jakarta_Persistence_Query_Language) queries from scratch takes five times as long as using a cached version. And preparing native SQL queries is 50% slower.

We can fix this with the setting `hibernate.query.plan_cache_max_size`. Read the article below for more details on the benchmarks and how you can check and measure Hibernate’s Query Plan Cache.

[Article](https://thorben-janssen.com/hibernate-query-plan-cache/)

***

### Tools
#### GitHub Previews AI Coding Assistant
We humans can screw things up a lot. But if we believe in science-fiction movies like “Terminator 2”, then we need a machine to truly create a mess. Now here’s our chance to make a bigger mess in our code than usual: Use a machine to write code!

The machine I’m talking about is GitHub Copilot, an “AI pair programmer”, as GitHub [calls it](https://copilot.github.com). In the example, a human enters this:

```
// Determine whether the sentiment of text is positive
// Use a web service
async function isPositive(text: string): Promise<boolean> {
```

And the machine writes this code:

```
  const response = await fetch(`http://text-processing.com/api/sentiment/`, {
    method: "POST",
    body: `text=${text}`,
    headers: {
      "Content-Type": "application/x-www-form-urlencoded",
    },
  });
  const json = await response.json();
  return json.label === "pos";
}
```


The Copilot works best with Python, JavaScript, TypeScript, Ruby, and Go. But I assume that Java is among the “dozens of languages” that it also knows.

So how the heck does this work?

As the example suggests, the Copilot analyzes comments (English only for now) and method names and then creates the method body. GitHub trained it with - you guessed it - code from GitHub repositories. This works because if we developers excel at something, it’s expressing succinctly what our code is to do, writing comments, and naming things.

Haha! Just kidding, of course: We developers typically suck at these three things. If that’s how the Copilot got trained, then our jobs are safe for now! 😅

There are more questions beyond “Does it work?”: Will Copilot add “[bugs faster than the speed of thought](https://mempko.wordpress.com/2021/06/30/bugs-faster-than-the-speed-of-thought/)” (nice heading)? Or is it the “[new Stack Overflow](https://twitter.com/monkchips/status/1410246942156861441)” (also a nice one)? Will it add open-source into proprietary projects? Or violate licensing notice requirements of open-source projects?

I’m sure that this won’t be the last we hear of this!

[InfoQ article](https://www.infoq.com/news/2021/07/github-copilot-pair-programmming/)

***

### Releases
#### Quarkus 2.0.1
This first maintenance release of Red Hat’s modern microservice framework comes one week after 2.0.0 (see last week’s issue). It’s a “safe upgrade for anyone already using 2.0.0.Final”.

[Announcement](https://quarkus.io/blog/quarkus-2-0-1-final-released/), [Release notes](https://github.com/quarkusio/quarkus/releases/tag/2.0.1.Final)

***

#### Spring Cloud Hoxton.SR12
The [Spring version scheme change](https://spring.io/blog/2020/04/30/updates-to-spring-versions) can’t come soon enough! Why? Because I don’t want to write slightly bizarre-sounding sentences like “This will be the last regularly scheduled release of the Hoxton Release Train”. 

Anyhow, this release is for Spring Boot 2.3.x and 2.2.x. 23 issues got closed this time around.

[Announcement](https://spring.io/blog/2021/07/07/spring-cloud-hoxton-sr12-has-been-released)

***

### And Now For Something Completely Different
#### Candidate for “Most Terrible Chart of The Year”
Charts make it easier to spot important information in a sea of data and can highlight trends. Well, most do. Not [this CNN one](https://twitter.com/antumbral/status/1407861007209222151?s=21). Go ahead and spot what’s wrong with it.

Did you [look at it yet](https://twitter.com/antumbral/status/1407861007209222151?s=21)? I’m waiting.

Ok, so what did you find?

1. Although the big title is “Violent crime is a very big problem”, it doesn’t report on crime **rates**. The chart shows **survey** responses: “% of US adults who believe that violent crime is a ‘very big problem’” would have been the correct title.
2. The chart goes from right to left.
3. Different durations have the same length on the X-axis: 5 months (October 2018 - March 2019), 16 months (March 2019 - June 2020), and 10 months (June 2020 - April 2021).
4. The Y-axis doesn’t start at 0 but at 35%, making the differences seem more significant than they are.
5. The margin of error of survey responses is +/-3%, as the fine print below the survey reveals. So the “52% in October 2018 vs. 48% in April 2021” could also be “49% in October 2018 vs. 51% in April 2021”. In other words: Most differences are not statistically significant and don’t prove anything.
6. The one statistically significant change was an 8% drop from 49% in March 2019 to 41% in June 2020. Maybe there is [an explanation for this](https://en.wikipedia.org/wiki/COVID-19_pandemic#2020)?

[Tweet with terrible chart](https://twitter.com/antumbral/status/1407861007209222151?s=21)

***

## About
Karsten Silz is the author of this newsletter. He is a full-stack web & mobile developer with 22 years of Java experience, author, speaker, and [marathon runner](https://resultsbase.net/event/5809/results/3294285). Karsten got a Master's degree in Computer Science at the Dresden University of Technology (Germany) in 1996.

Karsten has worked in Europe and the US. He co-founded a software start-up in the US in 2004. Karsten led product development for 13 years and left after the company was sold successfully. He co-founded the UK SaaS start-up "[Your Home in Good Hands](https://yourhomeingoodhands.co.uk/)" as CTO in 2020. Since 2019, Karsten also works as a contractor in the UK.

Karsten has [this newsletter](https://bpfnl.substack.com/), a [developer website](https://betterprojectsfaster.com/), and a [contractor site](https://ksilz.com/). He's on [LinkedIn](https://www.linkedin.com/in/ksilz/), [Twitter](https://twitter.com/karsilz), and [GitHub](https://github.com/ksilz). Karsten is also an [author at InfoQ](https://www.infoq.com/profile/Karsten-Silz).