Writing about Java at this point may seem a little late to the party, but I wanted to organize my knowledge again, so here are the things worth knowing when getting started with Java in IntelliJ Idea. These are just my personal study notes.
Things to watch out for when installing Java
Currently, if you use OracleJDK, free usage is limited to personal use and development purposes only. If you are only using Java for learning, there is nothing to worry about, but if you are planning to use Java in production, it costs money, so be careful.
All kinds of binaries are available, and all kinds of vendors offer paid support—the Java scene positively reeks of money. lol From my quick research I could not really tell which one is best, but if you just want to use Java without worrying about money, picking the LTS of AdoptOpenJDK(HotSpot) should be fine. Unless you are in a serious enterprise environment—or as long as you can solve problems on your own—you can keep using it for free forever.
You can check how long the support period (bug fixes and so on) lasts here:
https://adoptopenjdk.net/support.html
That said, compare it to Swift: open source, yes, but locked into Apple, with face-to-face support offered only once a year at WWDC—and even that is a pricey lottery. Next to that, paid support may actually make sense depending on your use case. Swift does have forums, but answers are best-effort at most, and getting help with your specific case is next to impossible. (I mainly use Swift in my day-to-day work.)
What am I going to use Java for?
First of all, I plan to use it for studying algorithms and for competitive programming. On top of that, so many libraries and architectures were born out of Java, and programming paradigms that traditional Java never had—such as Functional Programming—have been adopted as well, so as material for studying CS comprehensively, Java is probably the best choice. It is not edgy like Go or Rust, so it used to have a somewhat dull image for me, but having come full circle, it is a genuinely convenient language.
——Finally, please tell us what you think is “the good thing about Java.”
Kishida: Java is a language that can do everything. Desktop apps, server-side, mobile apps, business applications, service applications—it can do them all. It is not that well suited to machine learning yet, but I am sure it will become much easier in the future. By learning Java, you can dip into all kinds of domains—that is its advantage, I believe.
And as came up earlier, Java keeps making the effort to fit in with new fundamental technologies, so following that flow becomes motivation to study new technologies yourself. It is not just the language—the libraries, frameworks, and runtime all together are Java. That breadth of coverage is the best thing about Java.
(from: https://employment.en-japan.com/engineerhub/entry/2019/10/29/103000)
Creating a main function
One of Java’s quirks(?) is that it is a long way to Hello World.
To run a Java application, you first need a main function.
Copy-pasting it every time is a hassle, so it is handy to have the function generated automatically just by starting to type main…
https://www.jetbrains.com/help/idea/creating-and-running-your-first-java-application.html
Getting to know the build tools
The following ones are well known:
When starting a new Java project today, it is almost always gradle, with maven every now and then. I use gradle and maven regularly, so I am comfortable with them, but I have hardly ever used ant. I probably never will, but let me jot down a few notes anyway.
ant
The oldest build tool of the ones listed above. It was still being used in NetBeans (surprise!).
It is written in Java and was designed as a general-purpose build tool—apparently you can even use it to compile C code, though I have never actually seen anyone do that. lol You can write your own extensions (antlibs) to add custom tasks.
To define tasks, it uses a file called build.xml instead of a Makefile.
ant itself does not include any module dependency management. You can add dependencies by putting jar files on the classpath, but to manage them automatically, you bring in ivy.
ivy
A dependency management tool. It lets you describe dependencies in simpler XML than maven. It seems to be commonly used as a complement to ant.
You create an ivy.xml like this:
<ivy-module version="2.0">
<info organisation="org.apache" module="hello-ivy"/>
<dependencies>
<dependency org="commons-lang" name="commons-lang" rev="2.0"/>
<dependency org="commons-cli" name="commons-cli" rev="1.0"/>
</dependencies>
</ivy-module>
Then add the following to build.xml:
<project xmlns:ivy="antlib:org.apache.ivy.ant" name="hello-ivy" default="run">
...
<!-- =================================
target: resolve
================================= -->
<target name="resolve" description="--> retrieve dependencies with Ivy">
<ivy:retrieve/>
</target>
</project>
When you build with ant, the dependencies get resolved automatically.
This must have been revolutionary back in the day…
Get comfortable with IntelliJ
There is really no way around opening it every single day. Riding the current work-from-home wave (as of April 2020, a novel virus called the coronavirus is raging around the world), I too have been moping around at home, and I try to spend the spare time opening IntelliJ and writing some kind of code. Personally, I find writing Java in a text editor painful (not impossible, though). Mastering IntelliJ’s hot keys will get you far more productivity, I think. That said, near-IDE functionality is now available through LSP-powered extensions in various text editors, so things have become easier than they used to be.
Above all else, I feel the most important thing is to simply shut up and write code. For now, I will keep Effective Java within reach and do my best.