Enterprise Java with Spring Boot

Managing Java VM Distributions

Josh Long
Broadcom
Enterprise Java with Spring Boot

Lesson Description

The "Managing Java VM Distributions" Lesson is part of the full, Enterprise Java with Spring Boot course featured in this preview video. Here's what you'd learn in this lesson:

Josh introduces SDKMAN for installing and managing Java distributions on your computer and within a project. The .sdkmanrc configuration file can specify the Java VM used in a project, and SDKMAN will automatically switch to that version when the project directory is entered.

Preview
Close

Transcript from the "Managing Java VM Distributions" Lesson

[00:00:00]
>> Josh Long: First things first, if you're on a Mac or on a Unix of some sort, including Cygwin or Linux Subsystem for Windows Subsystem for Linux rather. Then I recommend you use something called SDKman to manage your JVM versions. SDKman is a great tool for managing JVM infrastructure. It's like a package manager.

[00:00:20]
So I can install Kotlin and Java and Graalvm and so on. So SDKman IO. Here you go. This is very common in the Java ecosystem. It's a software development kit manager. You just pipe this straight to Bash. What could go wrong? It'll be fine. Probably right? Pipe that straight to Bash, let it set up everything for you.

[00:00:37]
It'll in turn install a package manager called SDK. Okay, so let's, that's your first thing. So you can say SDK list Java, right? And then you can see it down here. It shows all the different JDK versions out there. Remember, one of the things that's so interesting about the Java ecosystem is that there's no one true distribution of Java, right?

[00:00:57]
Even in the Python world, for example, or in the Node world they have Bun, Deno and node, right? That's three. In Java we have 30. At least these are all different versions of different JDKs and all these are different vendors. Zulu, Tencent, Temarin, Semru. So these are all different implementations of the open source code.

[00:01:17]
Some of them are clean room reimplementations, some of them are value added distributions on top of OpenJDK, okay? The one we're gonna be using is actually a value added distribution on top of OpenJDK called Graalvm Community Edition. You can also use the Oracle. This is not open source, but it is free.

[00:01:33]
And as far as I understand, I could be wrong, but as far as I understand this is usable in any context where you would otherwise use this. Except you can't give away the runtime for this. But since it's used to create native images, you're not giving away the runtime anyway.

[00:01:45]
So, so graalvm24graalce so if you want to install that, you say SDK install Java24graal CE once you've got SDK installed. So you'll do that. I've already got it installed, and then if you want to say SDK default Java24 Graal CE that'll make it the global operating system wide default.

[00:02:05]
So when you do Java minus version, there you go, you should see something like that. There's a bunch of things that I think are just worth understanding that are germane to any Java programmer, not just a spring developer. And I want to talk about some of those things right now in more depth, right.

[00:02:20]
We did a speedrun just a minute ago, we did a speedrun looking at a few of these different things. We didn't really talk about them. I just wanted you to see what the effect of having it all set up and moving quickly can be. A few minutes to get something that is talking to a database that statically compiled, self deployed, observable, has an HTTP endpoint, talks to an ORM.

[00:02:40]
It's like, what was it, less than 10 lines of Java code to get all that working and some configuration details for your data source. That's all well and good, but I know what I'm doing and I know how these parts come together. We're going to walk through all those things in detail in the spring layer.

[00:02:58]
But right now I want to look at some of the things that were relevant before we even got started, before we even get to the spring code. I mentioned SDKman. One of the things I love about SDKman is that it gives you the ability to manage versions of your SDK.

[00:03:11]
So I'm using, if you look at this, I'm using Java SDK, Java SDK list, Java rather. You can see it says I'm using GraalVM Community Edition 24 Graal CE. So if you do SDK install, Java 24 Graal CE, you'll get that version installed as well. And then you say SDK default Java 24 gral CE and you'll get that same version, made it globally available on your operating system.

[00:03:43]
One of the things I love about that though is you can see like a bit of trivia. Who knows what the most popular JDK distribution is? I read last year, and I don't know if this is true still, but I read that it's actually Amazon's Corretto. So Amazon has a JVM distribution that they provide on top of aws.

[00:04:01]
Of course, that's what our shop uses. Yeah, and it's so very, very, very. I mean, I don't know what they do to it. It's just, it just happens to be the default it's the default used in so many places. So that by dint of having been so installed, it's already the most widely used distribution, which is pretty amazing if you think about it.

[00:04:18]
But nonetheless there's no reason they're all compatible. There's no reason you couldn't take code that's compiled against graalvm and then run it on Amazon or vice versa. So we have a bunch of different distributions and as you move from one project to another, you might even have different ranges of versions.

[00:04:32]
Like you might have GraalVM, but you're using Java 17 and using Java 21 and using Java 24. You might have different distributions proper. You might have Amazon Coretta over there and you might have OpenJDK, java.net over here, whatever. And so what you want is a nice tool to make it easy to manage and move around with all of them.

[00:04:50]
One that I actually quite like as well is also Liberica. They have everything. They have graalvm support, they have Project crack. We'll get into that in a little bit here. Support crac, coordinated Restore at Checkpoint, they have support for javafx, they have all this extra stuff on top of their distribution.

[00:05:09]
So there's Liberica and Liberica Nik. Okay, but for now, just keep it simple. Use GraalVM. There's different distributions here. These are proprietary. I think I could be wrong. These are not the OpenJDK distributions. These are the proprietary packagings of OpenJDK. Some extra stuff right from Oracle. And there's just, I mean, just a lot of them, A lot of them are just available.

[00:05:30]
So let's say you're moving around from project to project and you want people to be using the right version of Java when they go to your project, okay? So you can do SDK env init in the folder where you want this managed. I hit that. I did that.

[00:05:42]
And it created this file here called stkman rc. So that's now in this folder here, stkmnrc and it says Java equals 24 graalce. Sorry, when you set up SDK, man. Now if I'm, let's say I do SDK list Java, I'm going to switch to a different version of Java.

[00:06:00]
Now I'll switch to. Which one do I have installed? Do I have anything? Okay, here I'll use Java 24 open. Okay, so I'm going to say SDK default Java 24 open. So that's now my operating system wide open version of Java. If I go here, you can see it's just Java 24 now.

[00:06:17]
And it says there's nothing about Graalvm in there, right? So if I go now to the front end Masters spring boot course. You can see now it's switched automatically to graalvm. So I do Java within this folder and now it says graalvm. So that's very, very convenient. Now you can put that in version control.

[00:06:34]
What we want to support is that git clone run lifestyle right? I want people to be able to get your code CD into the directory type idea pom XML and start working. They should have all the sort of infrastructure via docker, they should have the versions of the JVM infrastructure managed by sdkman.

[00:06:53]
And they should be able to open it up in their IDE of choice without having to import or configure or check in the IDE droppings, the IDE config files, you want your build file and that's it, okay? So I'm going to go SDK default Java. That's me, right?

[00:07:13]
But now that I've added this SDKman. So that's SDKman. I quite like that a lot, right? Sdkman is super useful for making sure people can get your code.

Learn Straight from the Experts Who Shape the Modern Web

  • In-depth Courses
  • Industry Leading Experts
  • Learning Paths
  • Live Interactive Workshops
Get Unlimited Access Now