I’m a recent grad of 2 years, okay not that recent, and I’ve come to realize that university made a lot of things either: overly complicated or overly simplified. There’s no middle ground! In the final two years of my university career, I finally had a handle on development. Assignments made sense. Setting up my environment was a breeze. I had a set of IDEs I was comfortable using. Everything made sense, and I didn’t spend so much time learning how to handle things and spent more time cracking code. Now that I’m working in the industry, more often than not, things don’t make much sense. Your language version isn’t right. You’re missing a couple of different dependencies. You’ve never worked with a particular tool before, but it’s a pretty cool tool, and you want to be a cool kid too. There are so many hiccups I’ve encountered, and still battling, that eat away at my development time. To be honest, it made me want to return my degree and get a refund.
So in this series, Chronicles of a Junior Dev, I look to offer you, my fellow junior, some helpful tips when you’ve hit a roadblock. Don’t be afraid, although I’m still afraid. It’s okay to be a “noob.” We’re learning, and there’s no shame to say that you don’t know something.
What is a JDK
JDK stands for Java Development Kit, and the simplest way to think of what this does is to imagine a toolkit/toolbox. Each JDK version is a different toolbox with a different set of tools. Some tools might be similar to tools in other toolboxes. Maybe some tools are an improvement of other tools. Perhaps you have a new set of tools altogether. Just like a toolkit, the JDK helps developers create programs and execute them using the JVM and JRE (I’ll touch on those another time).
When starting on a Java driven project, you’ll need to download a particular version of a JDK. Your colleagues will probably tell you to “Just download Java.” On your quest to download Java, you’ll need to select a “package.” When I was in school, I never thought much about which package was appropriate for my project. For the most part, whatever I had on my machine just worked. Naive, I know. A package targets a particular development type, like enterprise, mobile, standard. So you’ll see packages such as Java SE (Standard Edition) or Java EE (Enterprise Edition). Don’t be alarmed!
Tip 1: Ask your colleague which package is appropriate for the project
Tip 2: If they don’t know, default to SE.
How to change your systems Java SDK — MAC
So if you’re not sure what I mean by system, open your terminal and type
java --version or java -version
Your system version is the version of Java your machine is using when you’re executing programs.
You can see all the different JDK’s available on your system by running
/usr/libexec/java_home -V
The output should look something like this:
Matching Java Virtual Machines (3):13.0.2, x86_64: "Java SE 13.0.2" /Library/Java/JavaVirtualMachines/jdk-13.0.2.jdk/Contents/Home1.8.0_242, x86_64: "AdoptOpenJDK 8" /Library/Java/JavaVirtualMachines/adoptopenjdk-8.jdk/Contents/Home
I have two different JDKs on my machine, versions 13.0.2 and 1.8.0. Take note of those version numbers; you’ll need them! Also take note of the paths for each of the JDK versions, those paths are where your JDKs reside.
To change your systems JDK, open/create a bash profile. I use nano for quick changes, but you can use whatever editor you like.
nano ~/.bash_profile
Add this export to your bash_profile
export JAVA_HOME=$(/usr/libexec/java_home -v <VERSION NUMBER>)
JAVA_HOME is an environment variable that points to the location of a JDK version. The location are those paths in the previous step.
Replace <VERSION NUMBER> with the version you need. It should look something like this:
export JAVA_HOME=$(/usr/libexec/java_home -v 13.0.2)
Save your file, and don’t forget to source your bash profile.
source ~/.bash_profile
Now when you query for your system version of Java, it should be the version you specified in your bash_profile.
java 13.0.2 2020-01-14Java(TM) SE Runtime Environment (build 13.0.2+8)Java HotSpot(TM) 64-Bit Server VM (build 13.0.2+8, mixed mode, sharing)
If that was helpful to you or you’d like a quick tutorial on another topic, let me know in the comments below. Thanks for reading and happy coding!