r/javahelp • u/nutrecht Lead Software Engineer / EU / 20+ YXP • Mar 17 '21
[PSA] Java 16 has just been released which comes with a packaging tool and records!
Hi! I wanted to point this out because this comes up a LOT in this sub; 'how do I turn my Java program into an executable'. And then we also see a lot of responses from people who try to help, but are not aware of recent additions.
You can find what is in Java 16 here.
The two most important additions I think for people in this sub are records and the packaging tool
Records are mostly just immutable classes that take away most of the fuss of having to write getters, setters, hashcode, equals and toString. More info here.
Jpackage is a tool that lets you take your program and bundle it with a trimmed down JDK into a native executable / installer. So for Windows it supports msi and exe, for MacOS pkg and dmg. This makes it a lot easier to share whatever you created with others, be it a GUI or a service. More info here.
5
u/BusterBessie Mar 17 '21
Forgive my ignorance but do records replace the work I might use a tool such as Lombok to do? E.g @Getter, @Allargsconstructor etc?
9
u/nutrecht Lead Software Engineer / EU / 20+ YXP Mar 17 '21
Records are similar to the @Value annotation in lombok. So with records you get getters, equals, tostring, hashcode and a constructor for free. What records can't do, is create mutable classes.
So it depends on the code structure. Most projects I worked on with Java (I've been Kotlin a lot the last years) where we used Lombok we generally took the approach of creating immutable data carriers. So in that situation, Lombok really isn't needed anymore.
On the other hand; if you use Hibernate/JPA these need mutable classes (something I really hope they're going to finally fix) and these don't support Records afaik. So there you'd still need Lombok.
In addition records also tie into the upcoming release of Project Valhalla where Java will introduce value types.
0
Mar 17 '21
[deleted]
1
u/nutrecht Lead Software Engineer / EU / 20+ YXP Mar 18 '21
I don't really understand your question. Record fields are immutable.
3
u/knoam Mar 18 '21
For those not in the know, Records are not just a convenience. They can make for a big performance increase. And the work on them is leading to generics over primitives without boxing.
2
u/nutrecht Lead Software Engineer / EU / 20+ YXP Mar 18 '21
I think you're confusing records and valhalla value types. Current records are really just classes.
4
u/RushTfe Mar 17 '21
So you are saying that Java version is above 7?? I need to have a chat with my boss tomorrow....
But for real, I will test it soon, thanks for the info!
3
u/crystoll Mar 17 '21
That's very good stuff! I just did a short video clip on it as well, installing it and a very quick taste of the Records. Was about to post the link but then saw this post :)
2
u/HecknChonker Extreme Brewer Mar 17 '21
Should be a LTS release in 6 months, I cannot wait!
0
u/wildjokers Mar 17 '21
Or you can just use Java 16 now. Are you paying for support for the current LTS version?
3
u/HecknChonker Extreme Brewer Mar 17 '21
No, most companies will not adopt non-LTS versions. This is why the majority of the industry is on java 8 or 11. A ton of people are waiting for 17 so they can upgrade.
1
u/nutrecht Lead Software Engineer / EU / 20+ YXP Mar 17 '21
No, most companies will not adopt non-LTS versions.
Which is mostly due to them being completely misinformed on what LTS means. If you can upgrade there is no reason to stay on an LTS version.
1
u/HecknChonker Extreme Brewer Mar 17 '21
It about money. If you use a STS version you have to worry about upgrading legacy systems once they stop getting security patches. That means paying developers to waste time on old systems when they could be working on something more important.
0
u/wildjokers Mar 18 '21 edited Mar 18 '21
You’d seem to be misinformed about LTS. If you aren’t paying for support disregard anything about LTS.
1
u/HecknChonker Extreme Brewer Mar 18 '21
I don't see what any of this has to do with paying for support.
The last java 8 release from Adopt was 10 days ago. The last java 9 update was July 2017.
https://github.com/AdoptOpenJDK/openjdk-jdk8u/releases
https://github.com/AdoptOpenJDK/openjdk-jdk9/releases
All of these updates are available without paying for support. And given that java 9 has no been updated in almost 4 years it would be a huge risk for a company to continue running and java 9 applications in production. They would have to pay for someone to update the version of java on those legacy applications or shut them down. If they instead wrote the app in java 8 the updates are just a mostly automatic process.
0
u/nutrecht Lead Software Engineer / EU / 20+ YXP Mar 18 '21
LTS only matters if you somehow can't just upgrade to the latest version. So if 15 is out of the question, companies should try to at least upgrade to 11. But there is no reason to stick to LTS versions.
Outside of that; LTS versions are not guaranteed to get all updates at all. Most JVM improvements won't be backported. You only more or less get a guarantee that you're going to get security fixes and a few really important upgrades.
The paying for support matters mostly for companies using the Oracle JDK. The only reason to ever use that one is if you want to pay Oracle for support you're not going to need.
1
u/HecknChonker Extreme Brewer Mar 18 '21
You have not given a single point that addresses any of the issues I mentioned, so my only real take away here is that you must not have any experience running actual production java software.
1
u/nutrecht Lead Software Engineer / EU / 20+ YXP Mar 18 '21
Only been doing it for 20 years but sure...
3
1
1
u/DJCowGaming Jul 10 '21
Yet everyone still seems to download java 8 lmao
Kinda annoying on small projects when you just want to make a jar download, no installer and no packaged vms, but everyone has old java versions.
0
Mar 17 '21
[deleted]
3
u/see_recursion Mar 17 '21
Yes, but you have to maintain that generated code...something that doesn't always happen when you add a new field. Look at Lombok to get an idea about how much cleaner your code can be without all of the boilerplate stuff.
Additionally there's a big potential for the garbage collector to be able to take advantage of explicitly knowing that something is immutable.
•
u/AutoModerator Mar 17 '21
Please ensure that:
Your code is properly formatted as code block - see the sidebar (About on mobile) for instructions
You include any and all error messages in full
You ask clear questions
You demonstrate effort in solving your question/problem - plain posting your assignments is forbidden (and such posts will be removed) as is asking for or giving solutions.
Trying to solve problems on your own is a very important skill. Also, see Learn to help yourself in the sidebar
If any of the above points is not met, your post can and will be removed without further warning.
Code is to be formatted as code block (old reddit: empty line before the code, each code line indented by 4 spaces, new reddit: https://imgur.com/a/fgoFFis) or linked via an external code hoster, like pastebin.com, github gist, github, bitbucket, gitlab, etc.
Please, do not use triple backticks (```) as they will only render properly on new reddit, not on old reddit.
Code blocks look like this:
You do not need to repost unless your post has been removed by a moderator. Just use the edit function of reddit to make sure your post complies with the above.
If your post has remained in violation of these rules for a prolonged period of time (at least an hour), a moderator may remove it at their discretion. In this case, they will comment with an explanation on why it has been removed, and you will be required to resubmit the entire post following the proper procedures.
To potential helpers
Please, do not help if any of the above points are not met, rather report the post. We are trying to improve the quality of posts here. In helping people who can't be bothered to comply with the above points, you are doing the community a disservice.
I am a bot, and this action was performed automatically. Please contact the moderators of this subreddit if you have any questions or concerns.