r/programming • u/[deleted] • Mar 04 '20
Java 14 Arrives with a Host of New Features
https://blogs.oracle.com/javamagazine/java-14-arrives-with-a-host-of-new-features21
Mar 04 '20
whats the deal with the yield keyword? dont lambdas normally use return?
I guess because its not really a lambda?
17
u/PeksyTiger Mar 04 '20
Yeah, they are arrow switch expressions not exactly lambdas.
A switch can have a return value, yield will return the switch without exiting the enclosing function.
6
u/TheThiefMaster Mar 04 '20
Yeah it's not a lambda, it's a kind of compound expression (it's evaluated immediately).
2
u/shellac Mar 04 '20 edited Mar 04 '20
To provide the result of an expression from a block, rather than return from the containing method / lambda / function? (It was originally
break)However I don't think you can
returnin a switch expression, but I can't check that at the moment.Edit: yep,
attempt to return out of a switch expressionerror.
18
u/Davipb Mar 04 '20
So records generate accessors as .value() instead of .getValue()? That makes them useless for libraries that rely on the JavaBeans .getX()/.setX() conventions like Spring and Jackson
21
u/pron98 Mar 04 '20
Those libraries will change.
12
u/G_Morgan Mar 04 '20
Why violate an existing and well established convention? The fact you can work around stupidity does not justify stupidity.
37
u/pron98 Mar 04 '20
Maybe because the people who designed this know nothing about Java or are very stupid. Or maybe it's because records aren't Java Beans, there is no well-established convention for records, and that when you consider the next 25 years it might be easier to do it this way.
9
u/G_Morgan Mar 04 '20
Why is it easier? It is just a convention.
30
u/pron98 Mar 04 '20 edited Mar 04 '20
Records are equal to their set of property values. Think of them as immutable, type-safe maps. Requiring them to express their keys using a convention that adds three more letters and changes the capitalization of the properties just because there is such a convention for a different kind of objects will make using them less pleasant.
Nevertheless, if you want to migrate an existing immutable "data class" to a record type, you can add bean-like getters yourself. In fact, if you're migrating, then those methods are already there and you can just delete your implementations of equals, hashCode and toString.
0
u/_INTER_ Mar 06 '20
then those methods are already there and you can just delete your implementations of equals, hashCode and toString.
Not directly if you're using Lombok.
-4
u/pushupsam Mar 05 '20
Nevertheless, if you want to migrate an existing immutable "data class" to a record type, you can add bean-like getters yourself. In fact, if you're migrating, then those methods are already there and you can just delete your implementations of equals, hashCode and toString.
So you really do expect people to go through all their legacy codebase and change their code... for no value add whatsoever?
How ridiculous is that?
there is such a convention for a different kind of objects will make using them less pleasant.
This is pure subjective bullshit. How do you even know they're less pleasant? Have you worked on a large codebase where 90% of the objects are using standard getters but a few objects aren't? Do you imagine that kind of massive inconsistency with 20-years worth of code is a good idea?
I suppose this will have to get to a different point because hearing this kind of nonsense just eliminates all confidence in Java. If we are going to have to rewrite all our code to take advantage of immutability there's absolutely no reason to rewrite it in a language who's records don't even deliver half the value of Kotlin's data classes. At this point, given that you guys have abandoned backwards compatibility, I see absolutely no reason to recommend Java as a language going forwards.
6
u/pron98 Mar 05 '20
So you really do expect people to go through all their legacy codebase and change their code
Did I say that? I don't think so.
Do you imagine that kind of massive inconsistency with 20-years worth of code is a good idea?
What inconsistency? How do you call your existing record methods?
in a language who's records don't even deliver half the value of Kotlin's data classes
To know what records are and what they're intended to do read this.
At this point, given that you guys have abandoned backwards compatibility
Have we? How is that a given?
-6
u/pushupsam Mar 05 '20 edited Mar 05 '20
Did I say that? I don't think so.
Ah, yes, so a developer who has existing data classes is supposed to do what?
Do you actually believe until you guys came up with records nobody else was using data classes?
Oh, right, he's not supposed to use this feature at all. His choice is either (1) ignore the feature or (2) go through the codebase and make this irritating change that serves no point other than to stroke your ego. Yeah, he's going to do that. For sure. Just like all the people eagerly adopting modules.
I don't think you know what records are and what they're intended to do. Read this.
And there it is. This is the something so deeply toxic in the Java leadership these days. You have a bunch of guys like yourself who really do think you're much more clever than you are and everybody else is an idiot jamming this absolutely useless shit down the unwashed masses throat. After the absolute shit-show that is Java modules that absolutely nobody asked for or needed since most Java programmers work on the server we were assured that there would be no more jarring changes. But here we are. And it's not like you've learned anything -- the condescension is still there, loud and proud.
The worst thing is that it's beyond obvious that you guys don't actually work on large Java codebases. This total disconnection between the people designing the language and people actually using it is why we have to deal with this shit.
Personally I used to be one of Java's few remaining staunch defenders but at this point I've lost all confidence. I strongly recommend again and again that if you've got an existing codebase there's absolutely no reason to rewrite and rejiggle all your code purely because Goetz has an irrational hatred of getters. The only rational thing to do at this point is go straight to Kotlin. This can be done in a piecemeal fashion and, best of all, you will actually get real value out of such a rewrite. Kotlin isn't backwards compatible at all but it already has all the useful features Java might get in the next 5 years and, best of all, the guys designing Kotlin are actually it's biggest users.
5
u/pron98 Mar 05 '20 edited Mar 05 '20
go through the codebase and make this irritating change
Just to be clear, this "irritating change" involves deleting code, which is what you'd get had Java implemented a different feature you might be thinking about.
that serves no point.
It does serve a point, the point explained in the document I linked.
This is the something so deeply toxic in the Java leadership these days.
Let me understand this. This is a feature that's been discussed and developed in the open, with community feedback, for a few years now, and is now a preview feature aimed to get even more feedback from a wider set of people. And to make it easier for those less involved, Brian wrote a document summarizing the insight gained during this open design process, explaining the alternatives and why these choices were made rather than others, and you see that as condescension towards the community?
that absolutely nobody asked for or needed since most Java programmers work on the server
How do you know that? (It's 100% false, BTW) Don't you think that the OpenJDK team just might have a better perspective on the Java ecosystem than you? Even on social media more people are more excited by this than not.
The worse thing is that it's beyond obvious that you guys don't actually work on large Java codebases.
Right. Almost every large company that uses Java is in contact with us in one way or another, and everyone is invited and encouraged to participate and contribute feedback (after actually trying the feature, not ranting about it without understanding what it is and what it's for).
there's absolutely no reason to rewrite and rejiggle all your code
Right, and there's no need to rewrite and rejiggle all your code at all even if you want to migrate existing data classes to records. All you need to do is change
classtorecord. Then, if you like, you can delete some code.purely because Goetz has an irrational hatred of getters.
So you think that, instead, Java should do what you say, and you say that without participating in the discussions or even reading their summary?
The only rational thing to do at this point is go straight to Kotlin.
Yep, that's what we do, too.
→ More replies (0)-4
u/simon_o Mar 05 '20
This is the something so deeply toxic in the Java leadership these days. You have a bunch of guys like yourself who really do think you're much more clever than you are and everybody else is an idiot jamming this absolutely useless shit down the unwashed masses throat. After the absolute shit-show that is Java modules that absolutely nobody asked for or needed since most Java programmers work on the server we were assured that there would be no more jarring changes. But here we are. And it's not like you've learned anything -- the condescension is still there, loud and proud.
This, a thousand times. Arrogant, obnoxious, toxic.
God is it annoying when a feature is discussed and people refer to experience with existing implementations – and the "designers" come in and point to their totally NIHed definition of stuff and how nothing except their own opinion could possibly apply to that new feature (because "look, the only existing definition (we just wrote ourselves) agrees with us".
→ More replies (0)1
u/Fenxis Mar 05 '20
As much as it would be nice to automate away the boilerplate of mutable JavaBeans, one need only look at the many such attempts to do so (Lombok, Immutables, Joda Beans, etc), and look at how many "knobs" they have acquired over the years, to realize that an approach that is focused exclusively on boilerplate reduction for arbitrary code is guaranteed to merely create a new kind of boilerplate. These classes simply have too many degrees of freedom to be captured by a single simple description.
From the link
1
u/nobodyman Mar 05 '20
Yes, but also a dumb convention. I'd prefer the newer versions of java dispense with dumb conventions rather than continue them. But by all means, add a getValue() method to your records.
-3
u/simon_o Mar 04 '20
If you want your records to follow the convention, you can declare them as ...
record Person(String getFirstName, String getLastName)... instead of ...
record Person(String firstName, String lastName)But yeah, some Java designers have an issue with NIH and trying to look very smart (often without the results that could justify it) while behaving obnoxiously arrogant.
-1
u/pushupsam Mar 05 '20
Yeah, this is a ridiculous response. There are plenty of people today using JavaBeans to model records: immutable bags of data. DTOs. All of these people use the standard convention of getters. The idea that you can take a well-known concept and invent a new keyword and use that to justify breaking a 20 year old convention doesn't fly at all.
What's really bothersome is that the guys designing this like /u/pron90 and Goetz really seem to not give a fuck whether people actually use all these shiny new features. They don't care about backwards compatibility of existing codebases at all. What do they think is going to happen? Do they think people are going to go through their 10+ year old codebases and change all the getX()'s to x()'s just because Goetz doesn't like getters?
This is going to be another feature that the vast majority of Java programmers working on legacy codebases will never even touch because it's not worth the effort. So what is the point?
3
u/pron98 Mar 05 '20 edited Mar 06 '20
Again, I suggest you read this to know what records are.
They don't care about backwards compatibility of existing codebases at all.
If you followed the OpenJDK mailing list, you will see how incredibly wrong you are. Backward compatibility is a central requirement that drives the design of every feature, including records. It's just that you might be confusing records with a different feature (Kotlin's data classes, maybe?) that they're not.
This is going to be another feature that the vast majority of Java programmers working on legacy codebases will never even touch because it's not worth the effort.
Another feature? What other feature is like that? You may not remember that, but people said the same about generics. And what about all the projects that will be written in 2022 and will be "legacy" in 2035?
0
u/pushupsam Mar 05 '20
Another feature? What other feature is like that?
Hehe, I would think you might've heard about modules, a feature that nobody wanted, that virtually everybody regrets, and that has actually what has triggered all these big discussions of whether it is to upgrade from Java 8 to Java 11 or just to consider alternate languages. Again this is the reason why I think you guys really have no clue about what goes on with the people who actually work on and maintain large Java codebases.
Backward compatibility is a central requirement that drives the design of every feature, including records
I don't think you guys really care about actual people working with Java. Maybe it's because we all have day jobs and don't have time to hang out on the list and discuss the finer points of language design or maybe just because you think we're all idiots and you know better. Frankly it doesn't really matter either way -- at this point we all see the way Java is going. Our 20-year investment in Java unfortunately has reached its end-of-life. Fortunately with the rise of Kotlin, Typescript and cross-platform .NET core we live in a time of many amazing alternatives. If the Java leadership is going to piss on that investment and make upgrades such a pain then the only rational thing to do is to get off the train.
2
u/pron98 Mar 05 '20 edited Mar 05 '20
Again this is the reason why I think you guys really have no clue about what goes on with the people who actually work on and maintain large Java codebases.
Yeah, the thing is every Java developer on 9+ enjoys modules every day. Modules are what allows us to significantly reduce the maintenance effort of the JDK and work on new features, some you may like more than others.
I don't think you guys really care about actual people working with Java.
We actually care about all of them, except for a few.
Fortunately with the rise of Kotlin
You do know that Kotlin runs on Java, right?
Our 20-year investment in Java unfortunately has reached its end-of-life.
Why unfortunately? There's all this much better stuff out there that cares so much more about backward compatibility, and you're finally getting rid of Java.
If the Java leadership is going to piss on that investment and make upgrades such a pain then the only rational thing to do is to get off the train.
Sure. Which is why we've drastically cut down the cost of upgrades. Give it a try.
I suggest that you calm down and actually read about the things happening in OpenJDK. I think you might enjoy that.
0
u/pushupsam Mar 05 '20
Yeah, the thing is every Java developer on 9+ enjoys modules every day. . Modules are what allows us to significantly reduce the maintenance effort of the JDK and work on new features, some you may like more than others.
Yes, that's right. Modules definitely help you. They cause nothing but pain for the other 99% of Java developers.
This is the point. This is why I've lost virtually all confidence in the future of Java. When the people designing the language aren't thinking about the other 99% we're just going to get more and more nonsense like modules. The end result is just more and more busy work with every upgrade. It's totally pointless. As somebody who's been writing Java for literally 20 years it's sad it's come to this but it's been a good run and we all got rich. At this point I think it's important people understand where the language is going and carefully consider whether they want to follow. There was a time when the only real alternatives to Java was shudder C++ or ObjC. Those days are over. There are lots of great languages out there and if you're going to pay the big upgrade cost you should get the best bang for your buck.
4
u/pron98 Mar 05 '20 edited Mar 06 '20
They cause nothing but pain for the other 99% of Java developers.
No, they make the JDK more secure and more maintainable, and they are what frees up resources to work on other stuff. It's like saying that the city tearing up your street to put in cable ducts is just thinking about themselves and how it would make it easier for them to install and upgrade your broadband lines.
And that pain they're causing some people? It's because of technical debt in the ecosystem that relied on internal implementation details and had to be paid sometime. Once that reliance is scraped off, upgrades are much easier than ever before.
aren't thinking about the other 99%
Oh, we are thinking about the 99% (and more!) all the time. There's just this 0.01% that we don't think much about. Some of them are on Reddit, I think.
and we all got rich
Are you sure you're in touch with the 99%?
It's nice to vent from time to time, but if you actually sat down and learned about all the changes in OpenJDK, I think you'll be pleased.
→ More replies (0)
9
u/ang0123dev Mar 04 '20
Java itself is a sort of old programming language, but like C++, Java is actively evolving now!
2
u/nemec Mar 05 '20
It's starting to catch up to C# in terms of features :D
But it's nice that Java now has record types, that feature has been sitting in development by the C# team for a few years now.
-10
u/shevy-ruby Mar 04 '20
Yes, but snail-pace evolution.
Essentially they copy/paste from saner languages such as ruby and python, primarily. C++ also did that.
The awkward thing is that "auto" in Java, or rather var, is ... stupid. It does hardly provide any real advantage.
The biggest problem is that Java is so addicted to verbosity.
I am also annoyed at "import" being required to see your code structured in some way. Both ruby and python use a better approach.
Literally putting everything into a single (!!!) .java file is simpler than having to use this retarded default structure that java came up with...
4
u/oorza Mar 05 '20
The biggest problem is that Java is so addicted to verbosity.
This is Java's biggest benefit.
I'd rather read decade old Java than month-old Javascript or year-old python.
2
u/ang0123dev Mar 04 '20
As you mentioned, a lot of developers complained about its verbosity. I think introducing var keyword is to reduce its verbosity though itself is controversial improvement.
Some of improvements are derived from other great programming languages since Java is a kind of old programming language, and it needs modernizing. It is not that easy when its old and complex structures are considered. Despite that, releasing new version every 6 months is a huge.
Real problems I feel are some libraries and frameworks are not support latest Java not fast enough. Actually there are still a lot of developers sticking to Java 8.
4
4
5
Mar 04 '20
Looks great
4
Mar 04 '20
I was hoping they would implement something similar to this
var name = user?.getLocation()?.getCity()?.getName();where no exception would be thrown and the 'var name ' would just evaluate to null.
15
-14
u/monicarlen Mar 04 '20
Bad idea, very bad results has produced in ruby the same feature
1
u/elastic_psychiatrist Mar 06 '20
I think you got down voted because you didn't justify it at all, though I completely agree.
2
u/AbyssExpander Mar 04 '20
I'm going to be the ignorant, smug guy and say: Java is like a chicken. It used to be a dinosaur. It's so old that now, it's this smaller, annoying, clucky thing that you hear about every once in a while, and you certainly consume its neat and convenient products (eggs) that people into dealing with chickens package up real nice for the rest of us food cooks.
IANAJD, though
-3
u/danopkt Mar 04 '20 edited Mar 05 '20
Definitely cool, although the implementation looks very similar to Kotlin:
Record = Kotlin data class
Text block = Kotlin raw string
Pattern matching for instanceof = Kotlin smart casting
Switch expression works just like Kotlin's when expression
Not that these features were unique to Kotlin by any stretch, or that it's even a bad thing to copy the implementations, I just thought it was interesting.
EDIT: FWIW, I understand these things are in other languages as well. The record / data class thing and the similarity of some of the syntax is what primarily caught my eye, but it sounds like there's more to some of these new features in Java. Learning!
EDIT: Just updated the wording to note that I was referring to the implementation similarities with Kotlin. As many people have noted, these concepts significantly predate both languages.
23
u/IceSentry Mar 04 '20
All of these things are becoming popular in most modern languages not just kotlin. Almost everything there comes from functional languages that have had those things forever.
1
u/danopkt Mar 04 '20 edited Mar 04 '20
Fair point. The record / data class and syntax similarities is what really caught my eye, but as other users have explained, there's more to the Java implementations than I initially realized.
5
u/IceSentry Mar 04 '20
I do believe that kotlin is indeed putting pressure on java to improve, but kotlin also doesn't do that much that isn't found somewhere else, except the JVM integration.
1
u/danopkt Mar 04 '20
Agreed on Kotlin not being super revolutionary. I think it contains a smart combination of pragmatic features, but a lot of its ideas originate from elsewhere. Still though, to your point, some of the recent changes in Java do seem to be geared towards countering Kotlin's gains in adoption.
4
u/possessed_flea Mar 04 '20
You are aware that the idea of records/structs predates kotlin by approximately half a venture
1
u/danopkt Mar 05 '20
Yes, I'm quite familiar with structs, I got into programming originally with C / C++ :). The specifics of Java's record implementation are what caught my eye. The way you define a constructor, then get equals, toString, etc for free - that piece is identical to the implementation in Kotlin.
I'm well aware other languages have features like this, which is why I called that out. What I found interesting was how closely Java's proposed implementation of these features mirrors Kotlin. It's probably not a coincidence, but it's also not a bad thing.
1
u/possessed_flea Mar 05 '20
Omg, I just re read my comment and realised the last word was supposed to be century, but I digress.
The reason why java records “feel” a little bit like objects/enums and have all the free bonus plumbing is due to how objects are structured in bytecode is because everyone involved in any form of engineering effort would tremble in fear at the thought of proposing the first new “primitive” type in 25 years....
On that note java records SHOULD have been a primitive type and exist inplace in memory and not allocated elsewhere,
1
u/danopkt Mar 05 '20
Hehe, no worries, I figured out what you meant by context. Auto correct gets to the best of us :)
12
u/KagakuNinja Mar 04 '20
Scala had those features before Kotlin, and Scala probably borrowed many of them from other languages.
5
u/chucker23n Mar 04 '20
Definitely cool, although it looks like they're mainly borrowing concepts from Kotlin:
That's not a problem, though.
Many concepts first arrive in different languages. C# heavily takes inspiration from languages like F#, which by virtue of being niche are also allowed to be more experimental.
1
u/danopkt Mar 04 '20
Agreed. Like I said, I don't think it's a bad thing, just thought the similarities were interesting.
5
u/pron98 Mar 04 '20
Records don't work like Kotlin's data classes but more like ML's product types or Scala's case classes, and Kotlin doesn't currently have pattern-matching.
1
u/danopkt Mar 04 '20
Cool, thanks for the explanation! I hadn't looked into it too carefully, I was just basing that off a quick skim of the description where they mentioned it provided equals, copy, toString, etc. Good to know there's more to it!
-2
u/shevy-ruby Mar 04 '20
Quite true - and kotlin in turn took ideas from ruby and python.
It's interesting that the big compiled languages don't come up with ideas on their own anymore.
5
u/pron98 Mar 04 '20
Java was designed to be a conservative language. Back in 1997 James Gosling wrote that Java's design philosophy (which it has mostly adhered to) is to adopt features only after they've been tried and proven elsewhere and have become familiar enough.
3
u/DangerousStick2 Mar 04 '20
...and a few decades have passed.
1
u/pron98 Mar 04 '20
Sometimes, sure. That's what it takes for language features to prove their worth and become sufficiently familiar.
1
u/DangerousStick2 Mar 05 '20
> That's what it takes
When I first encountered things like Scala's case classes and pattern matching, it didn't take more than a couple of weeks for them to prove their worth and become sufficiently familiar to me. The fact that it's taken the custodians of Java many years to even start to realise the same thing is certainly a true (and sad and astonishing) fact, but wasn't in any way necessary.
3
u/pron98 Mar 05 '20 edited Mar 05 '20
I am not talking about personal familiarity and benefit. Product types and pattern matching were very well-known to Java's designers in 1995. After all, they've been around since the '70s. And lambdas? They're well known since the '50s. Just think of the even more powerful programming constructs of '80s (like synchronous programming) that are known to Java's designers today and haven't even made it to Scala. The considerations that go into these decisions are not at all what some PL fans imagine.
-6
u/Gravybadger Mar 04 '20
What's the pricing model like with Java now?
32
u/tetroxid Mar 04 '20 edited Mar 04 '20
Free if you use the reference implementation, OpenJDK
8
u/Visticous Mar 04 '20
Not just gratis, it's free: Covered by the GPL 2.0. Even most additional libraries are licensed LGPL or even more liberal.
-5
u/vman81 Mar 04 '20
What if APIs are copyrightable?
20
u/sindisil Mar 04 '20
Then you'll need to take that into account if you decide to create your own implementation of the Java standard library.
If not, then probably not so much.
12
u/pron98 Mar 04 '20
Then you'll need to take that into account if you decide to create your own implementation of the Java standard library.
... and not comply with the OpenJDK open-source license.
3
u/sindisil Mar 04 '20
I would consider one piece of software (e.g. a clean room impl of a library) having to comply with the license of another piece of software (e.g., the library in question) to be something to be "taken into account", no?
3
u/vman81 Mar 04 '20
No, I wasn't asking about re-doing an implementation. I was curious if that kills OpenJDK
15
u/DemonicSavage Mar 04 '20
OpenJDK is owned by Oracle and released under the GPLv2. It's what the "official", commercial Java is based on.
It ain't going nowhere.
3
12
u/devraj7 Mar 04 '20
It's free.
Has been for years.
10
u/pron98 Mar 04 '20
It's been semi-free forever. But for many years there were field-of-use restrictions (since the beginning) and then some commercial features until Oracle open-sourced the entire JDK about year-and-a-half ago. Now it's really free.
6
u/paranoidi Mar 04 '20
Make it big enough and Oracle sues for billions and ruins whole software industry while at it.
1
u/myringotomy Mar 04 '20
It’s open source.
I guess it’s too much to expect somebody in this subreddit to know that.
-9
-3
-13
u/shevy-ruby Mar 04 '20
So essentially Java just learns from Ruby and Python. That's good!
The names are just so weird.
I mean ... "text blocks"? What kind of name is that??
0
Mar 04 '20
[deleted]
15
2
u/Bogosorting Mar 04 '20
Is Java not free?
4
u/RSveti Mar 04 '20
It is free he does not know what he is talking about. Only Oracle or some other company soport is payed.
81
Mar 04 '20
[removed] — view removed comment
39
u/aradil Mar 04 '20
I have to say the jump to 8 was a bajillion times more difficult than the jump from 8 -> 11. That took hours instead of weeks.
12
u/rpgFANATIC Mar 04 '20
Did you say that backwards?
Java 8 was largely backwards compatible. I thought the big problem was Jigsaw in JDK9 (which most people will experience in the long-term release of JDK11). That thing knocked over a lot of really sturdy build tools and required updating a bunch of libraries
9
u/aradil Mar 04 '20
Really depends on when you upgraded. When we upgraded to 11, all of our third party libs had already sorted out their module related problems.
When we went from 7-8, we had gotten so complacent and terrified of upgrading literally any library for fear of incompatibility between different dependency chains for the third party libraries we had, that the upgrades we needed to do that were broken by the relatively few breaking changes in Java 8 that it meant mixing a matching a bunch of new third party libraries.
Once that work was done once, the next hops were much narrower.
I guess what I’m saying is the short release cycles are forcing more frequent, manageable upgrades, and the 7-8 cycle was so long that third party code rot was almost unmaintainable.
Really our own fault.
3
u/simon_o Mar 04 '20
all of our third party libs had already sorted out their module related problems
Interesting, I'm currently stuck because some JavaEE ("Jakarta") libraries ship with broken module declarations. (Broken in the sense of "the JVM fails to start with these modules on the module path".)
The Java module ecosystem routinely feels like I'm the first person on this planet that is actually trying to use it outside toy examples.
1
u/aradil Mar 04 '20
Ya, most of the libraries I’m using right now seem to be slowly working on modules outside of production releases without forcing them through broken, thankfully.
I’ve been lucky in that I got to start a green field project 3 years ago. My java 7 migration was on a legacy project.
2
u/yoden Mar 04 '20
Really? This is the exact opposite of our experience. Outside of a few hiccups on Mac OS and in AWT, 8 worked pretty easily for us. Meanwhile we've been updating almost every dependency to work around issues from modularity and removal of private API. It's definitely good code hygiene, it's just taking forever.
5
u/Southy__ Mar 04 '20
I feel really lucky that my company lets me upgrade to current LTS, so we are on 11 now, and when 17 (the Corretto version) drops we will upgrade all our infrastructure.
It amazes me that this isn't the standard, my infrastructure team have automated all of this, we test against the version of JDK we want, they update a config and on my next automated deploy I get the new version. Only reason we don't upgrade every 6 months is because we want the stability of the LTS.
8
u/SomeShittyDeveloper Mar 04 '20
Java library we support goes back to Java 6. I do not like working in that codebase.
I used py4j in another project (main code is Python, but a library we needed was only in Java) and compiled the JAR in Java 11, I think? Weird compiling to something so “current”.
3
11
u/Keith Mar 04 '20 edited Mar 04 '20
Java is one of the most "boring" and backward-compatible techs around, so I'm always surprised to hear people struggle with upgrades. Would you mind explaining to a non-Java programmer what the cause is (since it's not due to language changes)?
Edit: downvoted for a reasonable question that got good responses. Stay classy Java programmers.
16
u/bobzfishmart Mar 04 '20
Not OP but my company struggled with getting from Java 6 to 7 and eventually to 8 mainly due to coupling many enterprise solutions to the application server distribution. Migrating from java 6 to 7/8 at compile/ build was simple but runtime was a nightmare as we had to completely migrate the applications to new app server versions and change our code to replace the functionality that changed with the server version.
Incredibly asinine, but we eventually moved away from that model so upgrades are much easier now.
5
2
u/StabbyPants Mar 04 '20
why not install multiple jres and use the appropriate one or build images per component?
7
u/pron98 Mar 04 '20 edited Mar 04 '20
Many libraries rely on internal implementation details that do change from release to release. This ties them to a specific JDK version, say N. Then they release a version that supports N+1, but not before they introduce some breaking change to the library that makes upgrades hard. So if their client wants to update the JDK, they might be forced to update to an incompatible version of that third-party library.
2
u/segv Mar 04 '20
In my experience majority of the time it was because, somewhere down the chain, some library had the great idea to shade ASM/cglib, which would barf at the sight of the new bytecode it didnt understand
3
u/evil_burrito Mar 04 '20
The biggest issue is because an enterprise Java application uses hundreds of libraries you did not write. Each of these libraries has numerous versions over its lifetime. Not only do these libraries need to be compatible with your implementation, but, they also need to be compatible with the other libraries if the other libraries happen to use it, too. One of the things that can cause a problem is if you are trying to run a version of a library that was compiled with a compiler newer than the one you're trying to use. You can get caught in a constraint web of libraries, binary compatibility, and compiler versions.
There's a tendency to, once you've got a combination of libs that works, be very very slow to change the recipe because one change can snowball into a huge project.
3
u/aoeudhtns Mar 04 '20 edited Mar 04 '20
That was the case until Oracle took over. 8 → 9 started warning about things that would be dropped or blocked, and then 11 followed through with that. IIRC first time ever a Java release was not backwards compatible. And now there's a whole new module system (although that should be optional still); Oracle dropped support for ecosystem things like JNLP (if you were using it - not me); and now even the way you distribute Java applications is different (ideally you're supposed to use modules and bundle your own JRE instead of relying on one pre-installed).
Edit: as has been pointed out to me, my wording makes it sound like it's Oracle's fault and that isn't the case and wasn't my intention. Just trying to ground a rough timeline.
7
u/pron98 Mar 04 '20 edited Mar 04 '20
Oracle took over before Java 7, and Java is run at Oracle by a group of people that are largely the same ones who did it at Sun, so the change has nothing to do with the new corporate owner, and a lot to do with keeping the JDK maintainable and Java competitive.
While you are correct that there have been intentionally breaking changes since 9, they were quite minimal, and not a major reason for upgrade difficulties. Things that were removed were mostly non-standard, separated into modules outside the JDK without requiring code changes, or methods and classes that virtually no one used and/or had been long deprecated. Changes to internal implementation details have been more disruptive, but there were disruptive changes in the past. Upgrading from 7 to 8 wasn't a walk in the park for many, either.
As to the new deployment model that uses a custom runtime, it does not require modularizing your application.
1
Mar 04 '20
The main thing that gave me problems were dependencies that used deprecated/internal interfaces that were removed before 11. There were some behaviors that were different around SSL before (I don't recall correctly, but some specific sort of SSL operation worked in 8 but failed in 11 with some big error message. I think that one may have been a JDK bug or my own mistake, but it was something that was difficult to work around).
1
u/StabbyPants Mar 04 '20
so is your company okay with being out of support? 11 isn't much of a jump and has some nice gimmes
72
u/LadyKitten Mar 04 '20
Helpful NPEs seem like a dream come true.
I'm quite excited about records, particularly if they manage to make them work well with @ Entity and other database nonsense in Spring!
I've pretty much always argued that switch statements were implemented backwards - they should have had a "fallthrough" keyword rather than a break; - so the absence of that behavior should make them much easier to use. I'm a bit neutral on the arrow format in switch statement - I don't really care about line count I suppose :D
Also *finally* the explicit casting after successful instanceof is (well, might be) gone - that felt SO CLUNKY, espcially in streams. .filter(String::instanceOf).map(s -> (String) s) should now just be .filter(String::instanceOf) if I'm reading this correctly?