So I decided to give Java a go. Why? No real reason, it was the first language I tried many years ago and the first time I abandoned coding 😀 . Several reasons come to mind: This “coding thing” was just too abstract, at the moment my English was zero, and there was not as many resources as you can find today, it was just frustrating. Now, after many years of tinkering in other languages and creating real products and applications, approaching Java from zero feels like a different animal entirely, and I’m appreciating that so far looks pretty similar to C# ( no idea if they’re alike at all, I guess I’ll discover more about it along the journey ).
This post is the start of a series of trying to get out of the comfort zone by learning Java, I may write stuff that is not entirely correct as I learn as I go, so please feel free to correct me in the comments. Also don’t expect a step by step tutorial, there’s a ton of people out there much more qualified and this is just my own experimentation, so will be a series of TIL and real world projects filled with spaghetti code.
But first things first, as there’s different stuff out there:
- We’ll need to choose a JDK vendor (Java Development Kit). There’s a ton of them, Microsoft, Google, Amazon, etc, .. all of them have their own implementation but I went with Oracle’s JDK just because is the most used and open source.
- We’ll need to choose an IDE, you can write this on a plain text editor but will become lacking pretty soon, so an IDE is a good way to start from the get go. I went with IntelliJ Community, which is the most used and free as well.
- We’ll need to work on a Java version, last LTS (long term support) release is Java11, so there we go.
Installing Oracle JDK without login in:
Once I made the decision to start my Java journey, the first blocker was downloading the JDK, their website has been down the whole day and was impossible to download JDK without login into Oracle first:
At this point being a web developer paid off, pretty simple to skip this step ( no worries, is not Hackerman stuff):
To download from Oracle without signing in, go to the downloads page and click on the download link, when a window pops up saying you need to accept the license agreement, agree, but instead of clicking on the green download link (which will send you to the login page), right-click the download link and select “Copy Link Location”.
Paste this on a new tab and you’ll see the link points to something like
oracle.com/webapps/redirect/signon, but it has a query attached that starts with
nexturl=. The URL that follows
nexturl= is the actual link that will download the file to your computer. Once you have only this, the file will start to download automatically. TLDR, here’s the link:
We verify if this worked in the command line and that Java is installed, and voilá:
iamgabrielma@Gabriels-MacBook-Pro ~ % java -version java version "11.0.9" 2020-10-20 LTS Java(TM) SE Runtime Environment 18.9 (build 11.0.9+7-LTS) Java HotSpot(TM) 64-Bit Server VM 18.9 (build 11.0.9+7-LTS, mixed mode)
My first Java program: Hello Rogue . Input and Output.
What I’ve learned:
- You need at least one main() method as a single point of entry. This is static because we don’t want to get instances from the method at any point, is unique.
- If the main() method has no arguments, it does not run, by adding Strings args as parameters (it accepts an array of strings) this will work.
- There’s a built in user input method called Scanner, this can be imported via java.util.Scanner
- There’s a built in print method, for now I just used System.out.println (prints on a new line)
And that’s it for now, more to come!