r/programming • • Sep 21 '17

Java 9 Released

http://mail.openjdk.java.net/pipermail/announce/2017-September/000230.html
504 Upvotes

154 comments sorted by

View all comments

Show parent comments

102

u/thesystemx Sep 21 '17

JDK 8 had a very high adoption rate. Within a year many ordinary Java developers were using it for commercial development.

I'm afraid JDK 9 may take a bit longer...

101

u/caagr98 Sep 21 '17

That's probably because Java 8 had lambdas. I didn't see anything particularly exciting in the feature list for Java 9.

0

u/[deleted] Sep 22 '17

[deleted]

12

u/apemanzilla Sep 22 '17

There's Jigsaw, but existing building tools already do a good job of managing dependencies and things.

30

u/sammy8306 Sep 22 '17

And they will keep doing that. However, Java modules now enable you to strongly encapsulate internal implementation details of modules in your application, while only sharing APIs. This is a pretty big deal if you're developing (moderately) large applications in a team-setting. In fact, this is one of the main reasons the JDK is now modularized.

Also, Maven/Gradle etc. don't have a role beyond build-time. Java modules carry their meta-data to run-time, where you can now rely on module resolution to tease out any dependency problems. What's more, a new tool called jlink allows you to leverage this explicit dependency information to create custom runtime images. These images contain only the modules your application needs (incl. modules from the JDK).

So all in all having modules as part of the platform will be a big step forward. It will take time, for sure.

(full disclaimer: I'm author of Java 9 Modularity, O'Reilly, see https://javamodularity.com)

→ More replies (6)

4

u/tetroxid Sep 22 '17

What exactly will modules do for me in my daily life? How is it an improvement over maven already automatically downloading the "modules" I depend on when building?

7

u/Linvael Sep 22 '17

One thing I heard that is neat is that libraries you use will be able to hide their internal APIs resulting in less clutter when searching for right import.

5

u/tetroxid Sep 22 '17

Isn't that what private and package-only methods are for?

10

u/duhace Sep 22 '17 edited Sep 22 '17

They aren't enough. Take for example the factory pattern. Perhaps you want some implementation classes of interface A that are only available to users through the AFactory class, and perhaps you want all those classes to be passed out as A, completely hiding their implementation details

You could make these impl classes private inner classes of the factory, but that can cause an unwieldy mess. JPMS modules let you hide them while structuring your code better by saying "this module only makes interface A and the AFactory class visible outside the module". It's much stronger encapsulation than private public and protected provided

Edit: a very good instance of what jpms solves is the sun.misc problem. The java.* classes are the API, sun.* is the implementation. You're explicitly warned not to use sun.* packages cause they could change from release to release (or not even exist in future releases or on other JVMs). But people still dip into them for many reasons. This creates two problems. It makes changing the implementation harder, and it removes an important impetus to improve the API. With modules, those classes can be hidden away from everyone but those working on the JVM itself, causing less headaches from upgrading the JVM than before. It also drives the Java devs to implement into the standard API what users were reaching for in the implementation(for example, sun.misc.Unsafe should have a java.* analogue in java 9)

edit2: I'll fix this post when I get to my laptop, thanks Reddit phone app for making code snippet markdown near impossible

4

u/tetroxid Sep 22 '17

I see. Thank you for taking the time to explain that to me, I appreciate it!

3

u/R_Sholes Sep 22 '17

No, package-private doesn't work like that, and private is even more limited.

Package-private means only the exact same package, not children, not parent, not siblings. If you have public class org.wtf.A and (package-private) class org.wtf.sub.B, A cannot access B, the same would apply for public class org.wtf.sub.A and class org.wtf.B.

You can define common utilities for a single part of your project with package-private access, but not something that you need to share between your project's different packages.

3

u/Fenris_uy Sep 22 '17

Sometimes you need to make a method public because you use it somewhere else outside of their package, but you don't want it to be part of your api, you solve that with the modules. Think of all the com.sun.* packages that are the private implementation of Java, but that are public because the classes from java.* uses them.

→ More replies (1)
→ More replies (2)

5

u/Fenris_uy Sep 22 '17

Jshell and the module system.

I want to try both of them, but none are needed for running your code, just for building it, so I might not change production to it.

When wildfly switchs I might switch.

0

u/[deleted] Sep 22 '17

[deleted]

3

u/renatoathaydes Sep 22 '17

The latest Java 8.x version is *8u144, so, no.

4

u/[deleted] Sep 22 '17

Collection Factories might be cool

4

u/pkulak Sep 22 '17

Yeah, kinda. But we've all been using the Guava ones forever now anyway.

→ More replies (1)

13

u/mscheifer Sep 21 '17

We're still on Java 7 here. :-/

39

u/Sun_Kami Sep 21 '17

Why? I don't understand why any company would do this. We upgraded from Java 6 to Java 8 a few years ago and hardly had to change anything... And at that point we were using Struts 1.4 or some nonsense which was so deprecated (no longer on that stack, thankfully)

12

u/langebangen Sep 22 '17

We still use Java 7 and the reason for this is because of our IT department. We use Debian and Java 8 was not introduced in a stable release until Debian Stretch which was released in June this year. Sure, it is possible to add a backport to get Java 8 but this is where the IT problem comes in. We (the developers) are not allowed to upgrade the machines were our Java applications are running (not even our own workstations), and IT has never prioritized our demands so unfortunately we have no choice but to wait until IT has time to upgrade the machines to the latest Debian release.

We are thinking of including the JRE with all the java applications we develop to be able to upgrade to Java 8.

4

u/Fenris_uy Sep 22 '17

Look at jlink to be able to do that with java 9.

2

u/synn89 Sep 22 '17

Yeah, this can be fairly standard and unfortunately upgrading can often be very difficult because of vendor software breaking. I still have a huge amount of Ubuntu 12 servers in our environment and we don't even have that many systems.

Unfortunately upgrades are often pretty tricky and it can be a hard sell to management: "I want to probably break this server that isn't having any current problems."

I'd definitely look into the JRE bundling if that's an option. It'll be a PITA to implement, but once it's done it'll probably save you a lot of future headaches.

13

u/Dreamtrain Sep 22 '17

You're probably thinking for internal use to make coding better, but if you're giving maintenance to a client's already robust application, upgrading the web server's environment and testing everything is a cost your client may not want.

→ More replies (1)
→ More replies (1)

10

u/thesystemx Sep 21 '17

I feel for you

6

u/tetroxid Sep 22 '17

You should upgrade. Java 8 is a massive improvement over 7.

→ More replies (1)
→ More replies (1)
→ More replies (1)