16 ms·
Revisiting Java in 2021 – Part II
- daxfohl 5y agoChanging companies led me from C# to Java. I feel so much less productive in Java, so much extra boilerplate everywhere. C# is just as mainstream as Java, so learning curves and nicheness arguments don't apply, it's just better. I wonder if MSFT will ever make C# run on JVM.
- pjmlp 5y agoOnly if they want to cripple C#, as the JVM isn't able to support all the C++ like features from C#.
- Zababa 5y ago> C# is just as mainstream as Java, so learning curves and nicheness arguments don't apply, it's just better. Java has way more web framworks from what I've seen (could be a good or bad thing), and more alternative languages that you can pick from.
- lucian1900 5y agoThere’s IKVM for running Java libraries in .NET.
- invalidname 5y agoC# was designed in a way that makes it very hard to run on the JVM in a performant way. It has slightly different scope behaviors, slightly different asthmatics etc. Source: worked on a JVM running on C# which was hard, I think the reverse is even harder.
- native_samples 5y agoIt might be easier these days with GraalVM/Truffle. You wouldn't run C# directly, you'd implement CIL in a Truffle interpreter, so you bypass JVM bytecode and its semantics entirely.
- lbruder 5y agoThat's basically how C# came into being in the first place. Microsoft "bought" Anders Hejlsberg of Borland Delphi fame, and had him create a "better Java". And IMHO Visual J++ was a much superior Java, with a visual designer that was much more advanced than anything else available back then. The problem? It was very much Windows Only (tm) if you wanted to use the advanced features. Sun was not happy about this. And the end result of the legal struggle was that Microsoft used Visual J++ as a base for C# and scrapped Java compatibility.
- carltheperson 5y agoThis was a great read! Think I might pick up Kotlin
- vbezhenar 5y agoThanks for article. Today I learned about Project Leyden, whose primary goal will be to address the long-term pain points of Java’s slow startup time, slow time to peak performance, and large footprint. I just recently started to explore Quarkus, GraalVM to optimize Java microservices for cloud architecture. It's good to know that Java moves into that direction. https://mail.openjdk.java.net/pipermail/discuss/2020-April/005429.html https://mail.openjdk.java.net/pipermail/discuss/2020-April/0...
- smallerfish 5y ago> to optimize Java microservices for cloud architecture I'm kind of curious about this. What kind of lifetimes are you looking at for JVMs? Are you trying to use Java in lambdas on demand to user requests? What kind of warmup time are you seeing right now?
- oweiler 5y agoLambdas, commandline applications, everything which needs startup times in the range of a few milliseconds.
- vbezhenar 5y agoI'm personally interested in reducing RAM consumption. Right now Spring Boot application with very little functionality (like few REST endpoints, talking to database) easily eats few hundreds of megabytes RAM. Similar node.js application eats few dozens of megabytes RAM. Cost of using Java is high, when there are plenty of those services, especially when we're talking about resilient services and launching 2-3 instances of every service. Fast startup time is just a good bonus. That's for my use-case. Lambdas, obviously, demand fast start-up.
- smallerfish 5y agoTo be fair, that's spring boot. It's a bloated ecosystem. If you write using lean libraries (which you'd want to do for lambda anyway) then you're looking at 0.1-0.3s jvm startup times. If that's supposed to be serving a user then it may be taking too long, but in that case use an EC2 instance rather than trying to be serverless.
- 0xCMP 5y agoI'm not a huge fan of Java, but a lot of the improvements being worked on here are promising. I'm 90% certain I would only really start working on a project if we could use Kotlin just because the ergonomics are vastly superior. If that requires the trial-by-error mentioned ITA to figure out the best practices of various approaches available I think I'd take that trade off.
- melling 5y agoHave the ergonomics of Scala improved with version 3? I‘m planning on revisiting Scala at some point
- eeperson 5y agoYes, a large part of Scala 3 was explicitly about improving ergonomics and making language features clearer to use. Some examples of this are: - Greatly improved error messages [1] - Revamped implicit syntax that makes it more straightforward to declare type classes and extension methods. [2] - Simplified support for macros [3] [1] - https://www.scala-lang.org/blog/2020/05/05/scala-3-import-suggestions.html https://www.scala-lang.org/blog/2020/05/05/scala-3-import-su... [2] - https://dotty.epfl.ch/docs/reference/contextual/type-classes.html https://dotty.epfl.ch/docs/reference/contextual/type-classes... [3] - https://docs.scala-lang.org/scala3/guides/macros/index.html https://docs.scala-lang.org/scala3/guides/macros/index.html
- nsonha 5y agooptional braces if you are into that sort of thing. https://docs.scala-lang.org/scala3/reference/other-new-features/indentation.html https://docs.scala-lang.org/scala3/reference/other-new-featu...
- brabel 5y agoI've been using Kotlin since 1.0 but I have to say the ergonomics of it are not vastly superior to Java. As others have mentioned, with Kotlin you're pretty much limited to Jetbrains' IDE, you have a new runtime dependency, not just a compiler, which is rapidly changing and requires updates on the code base frequenly (one of my projects used Kotlin for testing with KotlinTest - which recently changed names to KTest I think - and it was horrible to have to re-write most of my hundreds of tests to be able to upgrade when they went from JUnit 4 to 5 and in the process re-wrote all of it, basically), the compiler is slower and it starts to feel very much once you have thousands of lines of code... not to mention that there's a fairly big overhead of not only having to have javac installed, but also the Kotlin compiler and standard library... also, you probably want to use Gradle with the Kotlin DSL which in my view is really, really slow and unpleasant to work with - though they've finally been improving this recently - in the last couple of years. So, yeah, I like to write Kotlin code better than Java, but due to all of these factors and the fact that Java is now fairly close to Kotlin in functionality, if I had to start a big project today, I would pick Java for sure.
- da39a3ee 5y 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.)
- CraigJPerry 5y agoI'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.
- pm90 5y agoYou can’t avoid spring unless you’re in a small shop. It’s basically mandated/standardized at most places since “everyone knows it”.
- selfhoster11 5y agoSadly, Java and Spring are basically a package deal these days. Enterprise shops are likely to run on Spring.
- javajosh 5y agoI 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)
- 5y ago
- javajosh 5y agoI use Java every day, but we're stuck with Java 8 because of the confusing and frankly scary licensing around later JDKs. I would love to move to 17 but I need something to show to the C-levels that gives them warm and fuzzies around the license. Does such a thing exist? EDIT: I find it quite depressing that so many want to attack people for being confused around Java licensing. I submit that it is confusing on its face, but moreover insiders seems to understand how confusing it is, too: https://softwareengineering.stackexchange.com/questions/119436/what-does-gpl-with-classpath-exception-mean-in-practice https://softwareengineering.stackexchange.com/questions/1194... https://medium.com/@javachampions/java-is-still-free-2-0-0-6b9aa8d6d244 https://medium.com/@javachampions/java-is-still-free-2-0-0-6...
- cdblades 5y agoOpenJDK: "Oracle’s free, GPL-licensed, production-ready OpenJDK" I don't know what could be more convincing than an explicit open license.
- javajosh 5y agoThe Oracle License FAQ is scary and opaque. https://www.oracle.com/za/java/technologies/javase/jdk-faqs.html https://www.oracle.com/za/java/technologies/javase/jdk-faqs....
- cdblades 5y agoIt is, I definitely agree, but the statement I quoted is pretty darn straight-forward.
- javajosh 5y agoBut it's also wrong. Is there any legal precedent establishing what the "GPL with classpath exception" even means? Does each build of the OpenJDK come with it's own license? https://softwareengineering.stackexchange.com/questions/119436/what-does-gpl-with-classpath-exception-mean-in-practice https://softwareengineering.stackexchange.com/questions/1194...
- dboreham 5y agoThe comments about Scala resonated. I've been working in a a large Scala codebase for the past few months. I've become a partial fan of the language, however: there have been multiple conversations like : (in screen share with colleague) "See that double right arrow there? What's that mean? (after attempts to find answer in books, SO, etc, and trying to guess based on the three/four other uses the language makes of double right arrow that I've already grokked). Colleague: "Uhh, dunno, beats me". On reflection, I think if the Scala creators had been a bit less obsessed with symbology and had either a) used keywords rather than symbols more often or b) consistently only ever used a symbol for the same one purpose; the outcome would have been significantly better. There are just too many symbols to cover them all in a short book or cheat sheet, and symbols are very SEO-unfriendly. And even if you do find the relevant medium article, it's not necessarily clear that you're looking at the same use case for that particular symbol.
- weego 5y agoI've been a Scala and FP developer since 2009ish and it suffered initially from over-enthusiasm to make it seem 'futuristic' as a rejection of the overly verbose reality of enterprise java codebases. There's been a lot of sensible work in the core codebase since then to move towards more coherent idioms, unfortunately the 'we can make Scala into Haskell' crowd have since taken up the mantle and everyone has become obsessed with the idea that no boilerplate starter project is complete without cats or similar which perpetuates barely-legible and unnecessary confusion in situations that should be simple.
- nerdponx 5y agoIf you can't use an IDE to jump to the definition (or list all possible definitions) of a function, then aren't you missing one of the main benefits of a statically-typed language? If you can't use the static types for static analysis, what's the point?
- sk5t 5y agoYou can indeed jump to the method definition in IDEA, although getting the IDE to a good point of dealing with implicits, typeclasses, and their ilk has been a long road.
- hn_throwaway_99 5y agoI think when Project Loom comes out that Kotlin on top of the JVM will be a tough combo to beat. Kotlin is basically the language Java should be after 20 years of lessons learned, e.g. language-supported Optionals. The JVM is a battle tested platform. Once Project Loom comes out, you'll get the "best of both worlds" - the easier (i.e. "no functions 'colors'") programming model of multiple threads like in Java, but the scalability and performance of things like async in NodeJS.
- 5e92cb50239222b 5y agoI think for Kotlin that ship has sailed with the introduction of suspend functions.
- nsonha 5y agoI remember reading that you can plug any continuation model into the suspense mechanism?
- Zababa 5y agoJava seems to be heading for ML-like features while Kotlin is a "better Java". I think Kotlin lack a vision for the future, and might lose market share as Java itself gets better.
- javajosh 5y agoThe biggest real-world benefit of Kotlin is nullity prevention and immutables (of which Optional is a corollary). It's not clear whether Loom will be a big hit. Personally, I think the Actor model is the best application level concurrency "primitive", and Loom is just about fibers & continuations, both of which are parts of Actors but aren't really Actors themselves.
- smallerfish 5y agoOverall, good, but I quibble in favor of Kotlin with a couple of points: > Building large teams (think hundreds or thousands of developers) requires talent, and talent is easier to find if more people know the language (although, if you want the absolute best people, you might be better off choosing a more niche language). It's very easy to hire good Java devs and crosstrain them to Kotlin. > Java also arguably has the best tooling in the business. I'd argue that IntelliJ IDEA (and family) is the best IDE out there, more so if you are coding Java. Even if you prefer VS Code, Java is well supported. Jetbrains of course make Kotlin also, and theoretically their Kotlin IDE support will be better than Java's once they complete the mainlining of the Kotlin plugin into the IDE code base. (Right now the Kotlin plugin has recurrent stability issues.)
- jillesvangurp 5y agoOne point that the author fails to mention regarding Jetbrains is that they developed Kotlin and that Intellij at this point is largely implemented in it. Their whole strategy features a lot of Kotlin at this point. So, the best IDE for Java is built by the company that develops a drop in replacement for it. Not a minor point to make. The IDE that Oracle acquired along with Sun (Netbeans) is still there of course but it's rare that I meet someone who even knows what that is. This is actually also a weakness because there is no good competition in terms of alternative Kotlin IDEs. Eclipse and VS Code have Kotlin plugins but they are nowhere near as good as their Java support. Nice in a pinch if you really can't be bothered to install Intellij. Java undeniably has great alternative IDEs. I think it's still unrivaled in the wide variety of very decent IDEs and by pretty much every other language. And that has been the case for a long time. Eclipse and Netbeans are still around and both still do a fine job. If you use emacs or vi, there are decent plugins for those as well. VS Code of course has pretty decent support. Kotlin support for all of those is not at the same level. But one positive thing that has come out of Kotlin (and Scala) keeping the pressure on Oracle is that they have rapidly rolled out a lot of new Java and JVM features in the last few years. JDK 17 is a nice piece of technology with lots of under the hood changes that benefit all JVM languages. So is Graal. I think the efforts to make Java more usable are also going to be nice for people with Java code bases. Like the author though, Kotlin is my main language at this point.
- hugi 5y agoKotlin's dependency and relationship with IntelliJ is one of the largest reasons why I don't use it. I really dislike IntelliJ and Kotlin is mostly unusable without it. I don't see why I should force my company into vendor lock-in (IntelliJ/Kotlin) on what is otherwise an open platform (Java/OpenJDK).
- erokar 5y agoThis is unfortunate indeed. I'm hoping the Kotlin language server for VS Code will get some love, it doesn't seem to be working at this point.
- anotherevan 5y ago
- rnentjes 5y agoAlternative way to count the vowels in Kotlin: val numVowels = countVowels(getDTO()?.string ?: "")
- ptx 5y agoOr alternatively, closer to the original, doing both null checks the same way the original does the first one: val numVowels = getDTO()?.string?.let(::countVowels) ?: 0
- tomohawk 5y ago> Build tools such as Maven and Gradle are fast, stable and effective Exactly the opposite of what comes to mind when I think of these.
- selfhoster11 5y agoGradle is not fast. I want to pull my teeth out every time IntelliJ decides to launch my application through Gradle rather than via the IDE directly because of the added boot time.
- lenkite 5y agoMaven is quite stable and effective - maven pom's can remain unchanged for years and still build. However it is not fast.
- geokon 5y ago1 - I just do some Clojure programming, and I'm not deep into JVM things - but why does Android not even make a mention? Isn't it the most widely used JVM platform..? 2 - > This does come with some restrictions and caveats; for example, it's not as straightforward to use Reflection in your Java code. Is GraalVM going to push Reflections out of Java/JVM? I guess my angle is I'd like to use the JVM to make (desktop) apps. Last I did, using cljfx/JavaFX reflections were a huge sore point. Ever dependency would drag in the whole kitchen sink - and reflections are an ugly wart that prevent unused classes/namespaces from being pruned. I know technically there is Proguard.. but it's clunky and ugly I've never gotten it to work with Clojure. Graal native looked like a sort of light at the end of the tunnel. 3- Whats the story with WASM and the JVM? Both designs seem eerily similar - but I don't know if the gap between the two is too large to bridge
- karussell 5y agoAndroid is not a JVM platform. Android uses Dalvik as VM.
- SubjectToChange 5y agoDalvik was replaced by ART nearly seven years ago.
- karussell 5y agoSorry, just wanted to make the point that it is not JVM. Wasn't in Android dev since some years it seems ;)
- AmpsterMan 5y agoAfaik, android has its own VM. It compiles Java the language into bytecode for that VM. Android didn't even include the standard Java library, instead providing its own.
- native_samples 5y agoWell, dynamic languages like Clojure and static analysis like ProGuard will never mix that well. The module system helps though. You can get rid of the parts of the JDK you don't need. I very much doubt reflection is going anywhere. For one, GraalVM native images support reflection, you just have to state ahead of time what you plan to reflect over. WASM+JVM works. You can run WASM on top of the JVM. There's a Truffle interpreter for it, which means WASM code gets JITCd by the JVM itself and you can interop in and out. Check out GraalWASM.
- pharmakom 5y agoJava is not expressive enough to do without reflection for some complex problems. I suppose you might resort to code generation instead?
- nsonha 5y agoBoy JDK really accelerated their releases in recent years did they. 6 years ago when I've just graduated, Java 9 was around the corner.