loading...
Cover image for Getting started with Java

Getting started with Java

kritner profile image Russ Hammett Originally published at blog.kritner.com on ・2 min read

It’s been many years since I’ve done anything substantial with Java. I’d like to try to do a series of posts to get a feel for the Java ecosystem.

The hello world

Just to start things off, the most simple thing. Hello world along with trying out VSCode w/ Java.

Most of these steps are from https://code.visualstudio.com/docs/java/java-tutorial - so this will be rehash of that, I just want to write it down as I learn better that way.

Install OpenJdk

Oracle is undergoing some changes with licensing for the Java SDK(?) - I won’t pretend to understand that, but it sounds like utilizing the open JDK is the route to go.

Install VSCode and extensions

Install VSCode from https://code.visualstudio.com. After installation, install VSCode extensions (Control + Shift + X):

  • Language Support for Java
  • Debugger for Java
  • Java Test Runner
  • Maven for Java
  • Java Dependency Viewer
  • Java Extension Pack

Lastly, install maven - I’d like to use it from the CLI.

Write some code

I need to get into how Java projects and the like work, but for now, a simple hello world should suffice for this post.

public class HelloWorld {
  public static void main(String[] args) {
    var helloWorld = "Hello world from Java!";
    System.out.print(helloWorld);
  }
}

Control F5 that bad boy and then get the output!

Program Output

Note I did initially have some VSCode output errors - one related to a missing classpath, and one was complaining about not being able to create a launch.json file.

The missing classpath appeared to be related to the fact that I’m working with a raw .java file, and the secondary error was resolved when I restarted VSCode /shrug.

Next time, I hope to be able to dive into some of the boilerplate and ceremony of Java, so that I can better understand how to get a project up and running from the ground up; or to modify an already existing project.

Photo by takeshi2 on Unsplash.

Posted on by:

kritner profile

Russ Hammett

@kritner

Dad, programmer, faux-chef, gamer, book reader

Discussion

markdown guide
 

Any reason why you're using VS Code and not IntelliJ?

 

Just playing around, I don't know much about java at this point. I know intellij community is out there and I've played a little with it (love rider :D) but I wasn't really clear on the restrictions intellij community has.

 

The differences are outlined here.

If you you're just starting out with Java then the community version will serve you well for now.

It's an amazing IDE which offers so much for developing Java. Plus the paid version is only £12 a month for individual users, and that's money well spent in my opinion!

 

My question is deep:
Why Java?
Do you have some special tasks, or just hobby/fun?

 

Inheriting (at least tangentially) a code base that's built in java/spring. I'm a .net core guy myself, and dabble a bit in python.

Java just feels super gross to me, all the ceremony around it related to maven, project setup, project structure. I wanted to explore it, so I could hopefully have a better understanding of it, rather than keep referring to it as "gross". .net core has really made me appreciate all the updates from even the .net OG framework, and made me get all the more frustrated with Java. It could very well be because I just don't yet know the "ceremony/boilerplate" of Java.

 

Ha, as a Java dev I used to have a feeling of "gross" when it comes to other languages (mostly Python and Javascript), but in time I came to conclusion that it has more to do with familiarity than objective reasons on either side. A project is only as gross as maintaining people make it. I've seen gross in all languages, and I've seen clean in all languages too. The key is to stop trying to shoehorn expectations from our usual way of working onto another ecosystem, as this always ends in grief and frustration. Try to understand and embrace, and things become much more pleasant.

A good IDE fit-for-purpose really helps to get on board with each language/ecosystem's "standard practice". For .NET it might be VSCode. For Java it's IntelliJ or Eclipse - go with the standard and you'll save yourself a world of pain. You absolutely can read / navigate through a Java project in VSCode, but you'll be 10 times more productive and less frustrated if you use a more common Java IDE - because the IDE will work with the project, and default to what is most-commonly-done, rather than try to hack-around-the-standards and try and adopt a Java project into how things are normally done in a .NET project.

BTW, does .NET not have any command-line, independent-from-IDE system for managing dependencies and building? If not: do you copy-paste this stuff across all projects, and/or are forced to use MS IDEs? If yes: well hello, maven/gradle equivalent. ;)

Oh yeah for sure, I know a fair amount of my current feelings are just my bias. And yeah, I definitely feel more comfortable with jetbrains products over eclipse, but that is likely just a matter of keybinds that I'm more used to.

I do love me some VScode, even for .net core, but I use it more for code navigation (at least when it comes to c# and java, that doesn't really hold true for front end based stuff, which I'm even still I'm not strong with). I will likely be playing around in intellij when it gets down to the nitty gritty, but wanted to get my feet wet in a tool I'm more used to.

I know we all sometimes have to go on a rant ;) It's now been long enough for me to not do it so much for front-end stuff, and when I had the daily cursing sessions I didn't have a blog so it helped not to do it publicly ;) but... yeah, I feel ya.
If you come across anything super frustrating / just not bending to your will - just shout. There aren't many things in the Java/Spring world that hold secrets from me :)

 

Java is still a highly sought after skill.

In both small and large companies, and the likes of Android.