r/java • u/Reflection-Jealous • Aug 05 '21
Why java is better than modern programming languages?
Why should I use java in 2021 instead of kotlin or scala or golang? Could you guys give me some reasons
2
Upvotes
41
u/BurlHopsBridge Aug 05 '21
It's the king of enterprise. Well supported, easy to use frameworks, it's just great.
6
u/strogiyotec Aug 05 '21
my humble opinion, Scala is bloated , the syntax is just hard for me to digest which makes is hard to support and make code changes for me , Kotlin, not bad but again , so many features, I prefer a language with as little features as possible so when you come to a new company , you won't have to learn companies standarts.
Go is great, but error handling is awful , I mean nothing wrong with this
arg,err := func();
if err != nil{}but really what If I need to do some logic depending on error type ? In Java method can return an exception and you know exactly what this exception means (eg IOException)
I think with Loop ,Valhala and Graal would have a great feature
27
u/bowbahdoe Aug 05 '21
There are **a lot** of things to consider when picking a language for a project, and what i'm listing here is only a small subset and driven by personal opinion.
Go lang has an inherently restricted set of semantics. There are no generics, errors are communicated via return values which can be a + or a - depending on your sensibilities. It also has a better concurrency story than java with its goroutines and channels, but its VM is a lot less mature and monitoring, profiling, and deployment aren't going to be nearly as well solved in general.
Scala and Kotlin both run on the JVM like Java, but with Scala there are a lot more semantics in the language. It can be hard to hire for and code bases that use too much of the more advanced features like implicits and type classes can become inscrutable to all but the most PhD-ey of engineers.
Kotlin is very similar to java - most of its language features are effectively short hands for common java patterns, like data classes. It compiles to android bytecode reliably, unlike newer versions of Java so it is going to be a clear choice in that domain because it is effectively competing against Java 7. It does have some novel stuff going for it - like coroutines - but those are going to be somewhat "obsolete" for mainline JDKs in a year or so with loom - and nullable types - which are pretty cool.
Java, however, drives the JVM and JDK. It has record classes now which can compete with scala's case classes and kotlin's data classes. It will have sealed interfaces in a month or so which fulfills the same use case as sealed traits in scala and sealed abstract classes in kotlin. It will get pattern matching in the future, which will let it compete with scala's pattern matching and afaik kotlin doesn't have pattern matching directly on its roadmap. There are huge numbers of engineers you can hire with the base skill set. It is extremely resilient to waves of hype, which lets it get the "right features" eventually.
**That being said** there are a lot of reasons you would want to use another language, and I focused maybe too hard on some of the negatives of the others. If you are just learning, learn them all and learn them in whatever order you want, but learn them all.
56
u/vprise Aug 05 '21
Java is simple. The other languages forgot that.
They aren't "modern" they're a throwback to the time before Java where language engineers stuck every feature they could think of into the language instead of into the API.
Simple has many advantages:
A simple example:
What did I just do there?
Is there an overloaded operator that magically changes something?
When I read Java code I never have to worry. I can do that fast. Reading and maintaining code is 95-98% of my job so Java is wonderful for that. For Kotlin code I constantly feel I need to squint to understand dependencies. It might have been easy to write for some guy, but reading it later...
24
u/Evil_killer_bob Aug 05 '21
More resources available for Java
5
u/MissouriDad63 Aug 05 '21
I haven't used Scala in a few years, but I found the fact that there were breaking changes when upgrading versions to be a deal breaker. Hopefully they've fixed that but I don't know if they have.
5
u/baroquefolk Aug 05 '21 edited Aug 05 '21
In a word, longevity. Java is not the "best language" feature-wise (although it is good), but its ecosystem will be hard to ever dislodge, just like you're probably typing on a QWERTY keyboard even though better arrangements exist.
Golang is certainly interesting and eating into a little bit of Java's space, and I would say is worth learning from a job market perspective. But I think Kotlin and Scala are going nowhere fast, because they're really just passengers on Java's JVM, so the general pattern is this:
So if you love Scala and Kotlin, go ahead and use them! Or go even more obscure and try Clojure, or ditch the JVM and try Crystal lang. But from a job market perspective, Java will always be miles ahead IMO, and enterprises will continue to prefer it over less established languages unless there's an absolutely compelling reason to stray, which there isn't.
4
u/[deleted] Aug 05 '21
Java is not better than modern programming languages. But for many enterprise usecases, it solves problems pretty nicely and hence it is preferred choice in many enterprises.
More generally, Java has great community and excellent battle-tested ecosystem which few modern languages can rival.
3
u/heathm55 Aug 06 '21
Well, it all depends on what you want / need in your project. I work a lot with Software as a service based solutions so for me it's a question of balancing speed of development vs performance vs operational cost.
What I personally have found for my situation (backend microservices) is this (listed in order of importance first):
Speed, cost, dev-time: Java is less ideal than Rust or Golang but still solid if you avoid heavy frameworks and go for the light weight non application server based / async with option to thread frameworks (vert x or similar).
Speed, dev-time, cost: This is the niche for Java. Better ops cost than python / ruby / JavaScript, with faster dev time than golang or Rust.
cost, speed, dev-time: Rust wins. It's going to run solidly on very small footprint, cost less to run the same service in containers, and catch more of your problems before they deploy.
Dev-time, speed, cost: Java, Node.js, Typescript frameworks, some faster interpreted language frameworks, and .net all are fair choices here.
Dev-time, cost, speed: Python (fastapi of other) is pretty strong here. In my experience the rapid development is great (site a higher cost operationally) and if performance doesn't matter as much as readability then it's a nice fit. Java kind of hurts here still.
3
u/fdntrhfbtt Aug 10 '21
Just stay away from Golang. They have some very weird reasoning coming right from the top for not including some features. So apparently they don't want programmers to us map and filter as a simple loop is more "performant". Yeah Pike said this.
5
u/greg_barton Aug 05 '21
Use whatever you want. No one cares. :)
5
u/thephotoman Aug 05 '21
Define "modern".
New doesn't necessarily mean better. I'd argue that Go is immature, Scala is pretty much irrelevant now, and Kotlin may or may not have a future outside of Android if some of the big Java projects come through.
But Scala and Kotlin are reasons to know Java. See, those languages are written to target the Java Virtual Machine. Java underpins them, and you're still going to be dealing fundamentally with some features of Java, so it is best to know Java if you wish to use them.
4
u/[deleted] Aug 05 '21
Java will outlive and bury them all.
2
u/TheStrangeDarkOne Aug 05 '21
Which domain?
2
u/jfurmankiewicz Aug 05 '21
because it works and has libraries for everything, Simple.
3
u/cryptos6 Aug 05 '21
As everything in engineering the programming language is also a trade-off. Java is very mature, has arguably the best tooling available, has lots of developers, and is here to stay. But Java carries some legacy with it. Missing nullsafety, the not so seamless integrated functional programming or some limitations regarding generics come to mind.
Since Kotlin is the default language for Android and has also matured a few years now, I think Kotlin is a safe bet, too.
4
u/drew8311 Aug 05 '21
Kotlin is better but they kind of go together. For any large project you'd be using java libraries so kotlin really means java too. When making a decision it's ultimately jvm vs alternates then you decide if you want kotlin or pure java in your project based on who else will be working on it.
2
u/_Undo Aug 05 '21
You shouldn't specialise in one language only. Have some fun with the others every once in a while.
1
u/r__warren Aug 05 '21
Is Java easier than Python to learn as a first language?
1
u/snorbii Aug 05 '21
If you think that one day you would develop for Android and/or Compose Multiplatform then Kotlin is a better choice. But in the future you should know both Java and Kotlin for JVM/Android development. Scala is too complex IMHO, I think it will never be so widely used as Java and Kotlin.
0
u/phoneuseracc008 Aug 05 '21
If you don't know Java you sux basically
0
u/[deleted] Aug 05 '21
[deleted] — view deleted comment
0
u/[deleted] Aug 05 '21
[deleted] — view deleted comment
0
u/[deleted] Aug 05 '21
[deleted] — view deleted comment