Hacker News new | ask | show | jobs
by da39a3ee 1730 days ago
> There are ... many well-written books on how to program it effectively

Would anyone be able to recommend a good resource for quickly learning modern Java for experienced programmers that already know, let's say, one of {Python,Javascript} AND one of {Go,Rust,C,C++}, but have zero JVM experience?

(Ideally the resource would also teach some relevant things about the JVM itself rather than the Java language specifically.)

5 comments

Hmm. Great question. I've always liked Josh Bloch's "Effective Java" because it's targeted toward experienced programmers, and he expressed (correct) opinions about things like immutability. But the book is very old (2001).

One way to get into it is to build something real, first on bare bones (e.g. 'javac Main.java; java Main'), then bare bones Maven, then finally pick a great starting project which itself curates some of the best techniques and libraries currently available for the platform. I am partial to Dropwizard. Do not skip the first two steps though, because if you dive immediately into Dropwizard you'll be disoriented.

I would also suggest avoiding IDEs at the beginning. They hinder more than help at the beginning. One fun thing to do is download the JDK and the docs and source (usually a separate download, alas) and then disconnect your laptop from the internet. See how far you can get with it! Sadly, File IO in Java has always been verbose, but it is probably useful for you to suffer through it.

The 3rd edition of Effective Java was published in 2017, it's been updated to java 9.
I would still recommend Effective Java, many of its items are still relevant. If you want to avoid being bitten by Java's gotchas, this is the book. Also Java Concurrency in Practice is a must in my opinion.
I'd be surprised if you found any dramas with the language.

What will keep you in the office to all hours is the ecosystem. Now the ecosystem is probably best in class so don't mistake this as a slight, but it's huge and complex.

Learning Gradle (or Maven), understanding how to make building java apps fast (because the default is slow package assembly times), learning some of the large frameworks (if you go down that route) can keep you occupied for years.

If you're fresh to java, i'd probably encourage you to try avoiding the incumbents like Spring and see how you go? Without Spring, Java is actually pretty efficient. A hello-world rest service with spring results in around 6,000 classes being loaded.

That said - spring, used idiomatically, is a productivity boosting powerhouse.

You can’t avoid spring unless you’re in a small shop. It’s basically mandated/standardized at most places since “everyone knows it”.
Sadly, Java and Spring are basically a package deal these days. Enterprise shops are likely to run on Spring.
I forgot where I read this, but I think it's true: With Gradle to do anything you have to understand everything.

(Not a fan of Gradle)

Thanks. I have to say, this sounds awful -- it sounds like it will be a huge time sink and an impediment to learning about areas of software engineering that transcend specific languages (say, service orchestration, distributed systems, system architecture patterns, workflows, etc)
It is awful.

However it’s not all accidental complexity. To pick a random example, there’s a reason typo squatting is a thing in npm or pypi but not in maven/gradle. The mitigation’s that prevent this are not free, they add complexity (e.g. signing before publication, dns records, immutable packages etc).

But there’s definitely some areas of accidental complexity remain. While gradle CAN be used well (e.g. <3 min build on large code base), the default in large teams seems to resemble a kind of tragedy of the commons. Full of sharp edges and >45 min builds.

Modern Java in Action is a fantastic book. It goes into Streams, Optionals, new Date Time API, basically the "big features".

More recent changes are relatively smaller and probably don't need a full book to cover.

Would recommend it after Effective Java (3rd edition).

I don't have an answer to your question, but I would suggest the following:

skim over Java 5 syntax. It should be very easy to understand for anyone with programming experience.

Explore Java 8, 11, 17 features, but try to map all the syntax to Java 5, because those features usually are just a syntax sugar and I think that it's easier to understand those features this way.

Do not dive into standard library too much. It's vast and you can spend a lot of time studying it, but that's not necessary to start.

It should take few days of learning and experimenting.

After that you have to choose a framework, because Java applications are very framework-heavy ones. And that's where most of complexity comes from. People usually use Spring these days, so that's probably would be the most reasonable choice. There's no easy path, you'll struggle a lot and that's unavoidable. Modern Java Frameworks are full of hard to grasp concepts, tricky magic code and 20-year old roots buried in the depths of stacktraces.

Stackoverflow a lot, and you'll eventually naturally learn most things you need to know.

At some point I'd recommend to prepare for Oracle Java Certification (Oracle Certified Professional). It's a very good exam with lots of core Java topics and with some gained experience you'll structurize everything in your brain and you'll learn few things that avoided your attention before. I don't suggest to actually pass the exam, as that would cost some money and effort, so it's up for you to decide, but preparing to exam is very worthwhile time investment.

> After that you have to choose a framework, because Java applications are very framework-heavy ones. And that's where most of complexity comes from. People usually use Spring these days, so that's probably would be the most reasonable choice. There's no easy path, you'll struggle a lot and that's unavoidable. Modern Java Frameworks are full of hard to grasp concepts, tricky magic code and 20-year old roots buried in the depths of stacktraces.

Honestly that does not sound like a culture/ecosystem it is pleasurable to work within. Why wouldn't people choose something more modern and lightweight than Spring?

One of the strongest points of using a framework is that it's easy to find other people who already know that framework. And that depends on framework popularity. It's like old motto "nobody was fired for choosing IBM".

Spring is not well suited for modern microservices running in the cloud. Its startup time is slow and its memory usage is high. There are other frameworks emerging, optimized for GraalVM native image, most notable ones are Quarkus, Micronaut, Helidon. But their popularity is nowhere near Spring. May be in 5 years things will change.

> Honestly that does not sound like a culture/ecosystem it is pleasurable to work within.

I agree. Of course I’ve heard people criticizing and making fun of java over the years, but I didn’t realize the (very helpful and thoughtful) answers to my question would be so depressing.

Spring is largely "Java: the missing parts", implemented in a very poor way. It's semi-standard, even though it's not part of the core language.
What's weird is that every app in Java uses a DI container, while just about no apps that I've encountered in the rest of the world worry about anything that heavy. Most apps just cheat and use a bit of global state or maybe roll their own service locator pattern and don't worry about it. From the outside it seems like Java's sweet spot is really massive applications where you can't just cheat in one or two well-known spots in the code and call it good.
The sad thing is that DI doesn't need to be heavy. I looked into this for some projects I was planning, and there are some lightweight (if technically off-putting, IMO - see Dagger 2 syntax) ways to achieve this. But everyone just reaches for the big frameworks in the first instance.
I'm currently reading Cay Horstmann's "Core Java for the Impatient" and like it a lot.