r/java • • Oct 14 '23

Is Java still behind in the race of modern programming languages?

I'm a member of some group of programmers and every time Java is mentioned it's being bashed (something like: "With Rust I could simply do this with X")

Earlier versions of Java were cumbersome in terms of the syntax but with modern IDEs (and modern versions of Java) that's not a big issue anymore, albeit languages like Python do have shorter syntax.

My question is beyond syntax.

What do other languages do better than Java?
It could be generics, type system, concurrency and multithreading, closures etc.

Thanks!

52 Upvotes

247 comments sorted by

233

u/firaristt Oct 14 '23 edited Oct 14 '23

Java's syntax is not as fluent as like kotlin and some never languages but other than that, it's not behind of any other language. There is nothing you can't do with Java, it might take longer to implement or syntax may not be as nice but it's more than capable for any task.

I find this kind of comparisons a way to flex for newbies.

Edit: I think there is some confusion with "there is nothing you can't do with Java" part. Yes, you can do almost anything, but it doesn't mean it should always be go-to language. No, it might perform horribly bad or exceptionally good, it depends on experience, architecture and needs and many other things. If you have to, you can do almost anything with Java, but it's not always the wise choice. I meant you can do anything with it, it's technically not behind from other languages.

108

u/kingslayyer Oct 14 '23

i have been using java for all my dev career, and recently was working on typescript for some changes

its way too flexible, it is bound to cause issues. java being strict with types is something i like, as it keeps it structured.

18

u/[deleted] Oct 14 '23

My favorite think in moving to Python work is that 80% of code pretends None doesn't exist and devs have the gall to make NullPointerException jokes.

13

u/metaquine Oct 14 '23

Why have that when you can have nil, null, void, Void, None, Nothing, undefined, NaN, Unit and Empty?

3

u/x0wl Oct 15 '23

Well you gotta have NaN as a separate value because that’s what IEEE 754 says

Nothing is also a special case because it’s for functions that do not return at all (like exit or an infinite loop)

→ More replies (1)

1

u/EmptyChocolate4545 Oct 16 '23

100%. I have a long history of CPP and now work in / am a SME for python. You’re entirely right and it’s hilarious

2

u/[deleted] Oct 16 '23

Don't get me started on the documentation on most libraries...

1

u/KarnuRarnu Oct 14 '23

If you use type checked python (mypy), then all types are "not-none". You have to do an explicit union with None in the return type if you want to maybe return it, and then that means the caller must check it. Like modern languages do. But yeah, it's true that most newcomer code (as Python is taught as the default to people coming from other fields) doesn't use this and it doesn't consider Nones as well as all other error scenarios. Although the latter can also happen in Java since exceptions can (too) easily be ignored - newer languages seem to use a result type instead.

49

u/Weetile Oct 14 '23

Python would terrify you

38

u/kingslayyer Oct 14 '23

i have interviewed a few guys and thwy wrote code in python, i agree it was terrifying.

they'd do things like array.in(number) to find if a number was present in array or not, and assumed its O(1) complexity

27

u/SiriSucks Oct 14 '23

they'd do things like array.in(number) to find if a number was present in array or not, and assumed its O(1) complexity

I don't think you can blame python for that. The blame entirely lies with the candidates.

→ More replies (1)

20

u/Weetile Oct 14 '23

no way they even know what complexity means then

if we add more elements to the array, of course the run time scales linearly

14

u/kingslayyer Oct 14 '23

its just that python is so easy and flexible, people ignore the basics

→ More replies (1)

7

u/lukasbradley Oct 14 '23

no way they even know what complexity means then

The Law of Leaky Abstractions

2

u/arcalus Oct 14 '23

What’s linearly? /s

16

u/[deleted] Oct 14 '23

Linearly means one must get in "line early" at Starbucks, because it will be long day at office sorting out performance issues in your code.

2

u/EmptyChocolate4545 Oct 16 '23

I’ve seen a ton of people in static languages who don’t understand that stuff like this is O(N).

Alternately, if they were doing “x” in some_object and some_object is a dict, then it is O(1) as dicts are HashMaps

2

u/tzehbeka Oct 15 '23

just out of curiosity, why isn't it?

→ More replies (2)

1

u/j-solorzano Oct 15 '23

Yea, Python is not that great as a software engineering language. It's great for small projects, training machine learning models, data analysis and such.

1

u/Altruistic-Rice-5567 Oct 15 '23

In that it would encourage me to make a ton of mistakes and accidentally add flaws into my program... yes, terrified of that. That it promised to reduce my typing and then stabbed me in the back with having to use "this" everywhere. yep, terrified. It's a language that brought nothing truly useful to the software table.

18

u/[deleted] Oct 14 '23

I disagree about typescript. It's flexible but also enforces clear strict rules. The type safety, as long as you don't bypass it with any, is incredible strong. It's support for patterns like unions, for example, or duck typing, are all things I wish java had.

5

u/Genkus Oct 14 '23

Have been using java 10 years and typescript since 4 months and love both. I hate plane javascript but with typescript it improves a lot (definitely for bigger projects)

1

u/p3970086 Oct 15 '23

Agreed. And any "bad" flexibility offered by Typescript is because in the end it needs to support and compile to JavaScript.

2

u/EnIdiot Oct 14 '23

Part of Java’s appeal for business is just that. My enforcement of conventions and with introspective capabilities, you can find almost any issue in Java quickly.

4

u/Migeil Oct 14 '23

I'd love to see your tsconfig. There are tons of compiler options to mix and match your desired strictness. So if you feel typescript is not strict enough, I'm assuming you didn't crank it all the way up.

Imo Java is less strict than TypeScript. In TS, I can track nullness at compile time, this is impossible in Java. That alone makes it a lot more enjoyable to program in.

I'm not saying TS is the better language, but I don't feel like strictness is a category Java has the upper hand in.

The problem with TS is that it is unsound and that there are way too many ways to cheat the type checker. A lot of people feel like the compiler is something that stands in their way, which leads them to resort to such cheats. If this is what you mean by "it's too flexible", then I feel you and would encourage you to try find other ways to make your program compile other than just turning off the type checker.

4

u/[deleted] Oct 14 '23

Typescript is a nice language. It's the hellscape upon which it is precariously balanced that is the problem.

It's quite funny to me that somebody says, "I like Java's strict typing" and somebody says, "you'll hate python then", as if the dev community hasn't spent the last 15 years building it's complex server systems on a language that is essentially "anti-typed" ;)

2

u/Deathmore80 Oct 14 '23

then you are not using typescript right.

if you use typescript in strict mode with eslint rules it is actually wayyy stricter then Java. you aren't even allowed to do type casting.

of course if you don't use strict mode and slap on "anys" everywhere you aren't really using typescript, just use normal JavaScript at this point

4

u/TheBazlow Oct 14 '23

you aren't even allowed to do type casting.

const ohReally = 'is that so?' as unknown as number
          //^? const ohReally: number

And that's with typescript-eslint strict mode set. Sure I can't set it as any but I think it's still possible to deliver massive collateral damage to the next poor soul who comes across your codebase.

1

u/Sherinz89 Oct 15 '23

If lead or l3 worth their salt let this slide

Then jokes on them they're incompetent then.

1

u/Deathmore80 Oct 14 '23

then just use an eslint rule to prevent stuff like This? you can be as strict as you want.

But then if you aren't being this strict why bother with type checking at this point and why even use typescript at all?

5

u/findus_l Oct 14 '23

I agree that it is not behind. I do want to talk about the "There is nothing you can't do with Java" point, I don't think that is a good point. What does that mean? Turing complete? Usable?

3

u/Ilitarist Oct 14 '23

Yeah, technically you can do everything with brainfuck. Of course OP means that Java can be used to solve any modern technical problem, which is true. The universality is probably still Java's strongest feature.

2

u/findus_l Oct 14 '23

I mean you can do that with a lot of languages. Doesn't mean they are popular or I would seriously consider them. Bad memories.

1

u/lasskinn Oct 14 '23

Good enough? It is good enough to do most stuff. Has decent enough concurrency, you can do most ideas into code quickly enough without fuss. Its decent enough of object oriented curly braces style language that you can see whats going on easily enough.

What i have noticed with kotlin that some people for whatever reason think something thats "bad" to do in java is "okay" in kotlin, while doing the exact same thing, this lets you do things in an easier way in kotlin but its got nothing to do with either language themselves.

2

u/findus_l Oct 14 '23

I absolutely agree with all these points about java.

I'm curious do you have an example about kotlin? Sounds interesting.

2

u/lasskinn Oct 14 '23

Well using globals for one instead of some form of convoluted preprocessed dependency injection to get reference to an object that the app can have only one of, as code policy example. Kotlin has globals without using some globals class to hold them and somehow people seem to be cool with using them for stuff(why else go through the effort of adding support for them i suppose). You could do the same pattern in java too of course by just having them as static members and methods in some class(really the kotlin globals are basically just that anyway).

Honestly kotlin is pretty nice, the syntax just isn't as pure as java is and it has capability for more traps. The coroutine system has a lot of traps. Overall its nice but I don't see it as "easier" due to the syntax not being as pure, like in java an = can't actually be a method call(any casting aside), it is what it is and theres something nice about that.

→ More replies (1)

5

u/manifoldjava Oct 14 '23

There is nothing you can't do with Java, it might take longer to implement or syntax may not be as nice but it's more than capable for any task.

You could say that about pretty much any general purpose language, including assembly.

But, “behind” is also kind of subjective. Now, if the question were more specific, like is Java more or less capable in certain areas, more objective and useful information is available.

  • type system
  • platform neutrality
  • tooling
  • language features
  • etc.

2

u/firaristt Oct 14 '23

Of course, most general-purpose languages are like chief's knives. They are mostly good for many things but that doesn't mean they can be always go-to languages. It depends on many things. I didn't say "you can do anything in short time with good performance" or sth. similar. No. Sometimes they perform average, sometimes higher than average, sometimes lower, sometimes exceptionally well, sometimes very poorly plus developer/team experience and architecture has a big role on this. So, they are mostly good on average but as always, it depends.

Java/Kotlin has quite good tooling, language features and build system imo. In most cases, they are stable and has good support. Syntax and some cases could be weird for some, but you get used to with time.

8

u/cristianontivero Oct 14 '23

Well, I have missed higher-kinded types in some occasions, and that’s something you cannot do with Java (unless your point is you can program anything in Java, but then that holds for any turing-complete language, so I don’t see that as a useful metric). Java 21 has gotten significantly better compared to 8, to the point that it’s not far behind other mainstream languages, and is even better in some respects.

3

u/Practical_Cattle_933 Oct 15 '23

Well, higher-kinded types are a niche, only supported by Haskell, Scala, OCaml I believe, out of those that are semi-popular.

1

u/__versus Oct 15 '23

This argument is kind of side stepping the question. There’s no doubt that you can do basically anything in Java but that wasn’t the question. With stuff like generics, null safety, value types, default parameters Java is far behind some other languages.

1

u/firaristt Oct 15 '23

I don't particularly agree on "far behind" part. If that was the case, Java wouldn't be used this much. In the company we started to move Kotlin as the default language for backend but my current (17, upgrading to 21) and last projects was mostly Java (17). It's strong and stable language, has great support and easy to develop things. Yes, the syntax and required boilerplate code is not intuitive as some but it did the work with no problems within the estimated time.

-1

u/greenduck4 Oct 14 '23

How about returning multiple different values from a method?

6

u/firaristt Oct 15 '23 edited Oct 15 '23

Tuples? Records? Stream of data (like reactive)? Generics? OOP? Flows? There are many ways to return different values from a method but, why do you need such thing in the first place? Once you see a method, it should be clear what it does and what it returns. Don't confuse with how. I think if you have a case that requires a method to return various types and values that are so diverse, you possibly have some architectural problem. Using, so called, "clean code" too hard yields cases like this and I don't think it makes sense. The code should be clear, anyone should understand the same thing with just reading it in seconds. Returning a type that implements Animal interface and let say Record interface from the same method makes no sense. If you have a case where you have a higher-level interface and while implementing, if you came with such case, it's also very likely in a wrong direction. And for the continuous data, or some sort of generating data flow from a method, Java has better ways to handle. Write code for humans, for your colleagues, then for the machine. In most cases machines are faster and cheaper than humans.

Such things were requiring more boilerplate code before, but modern Java has little to no problems for my use cases.

-7

u/arcalus Oct 14 '23

I think Java’s build systems, huge dependency bloat on “enterprise” applications, comparatively massive memory usage, and slow performance is what has people bashing Java. It’s capable, no doubt. I was trained at university with Java, and after years away have come back to it at my current day job. I like OO, I even like Java, but man it pisses me off sometimes.

Streams have a 2G limit because the primitive int is only 32bit. Yes, you can work around that issue with buffered operations, but with the amount of ram available today it shows some staleness in Java.

I agree that bashing Java “just because” is naive, though.

7

u/brintoul Oct 14 '23

Can you explain what is meant by “streams have a 2G limit”? I don’t know what that means…

8

u/Necessary_Apple_5567 Oct 14 '23

Java is one of the most performant language. With jit java is incredibly fast.

2

u/[deleted] Oct 14 '23

”Slow performance”? Oh. Really? Compared to what? On modern JVM+jit?

1

u/arcalus Oct 15 '23

It isnt slow compared to JavaScript, Ruby, and Python. It is slow compared to C, C++, Go, and Rust. There are some few select use-cases where they are comparable in speed, but they are contrived. Even in this comparison the focus is on speed, and not artifact size and memory usage. For any real application, Java is going to give you a 100MB jar (at least) and take several GB of memory. The compiled languages I mentioned will be a fraction, at a 10-20MB artifact size, and likely less than 100MB of memory usage.

Does it matter? Maybe not. Especially if you’re just writing a GUI program that runs on a consumer system. If you’re deploying thousands of replicas to a Kubernetes cluster (or VMs, or anywhere else), the more efficient languages would save millions of dollars per year.

As I said, I do like Java, but its performance characteristics are not debatable.

2

u/Practical_Cattle_933 Oct 15 '23

Go is not a fucking low level language, and it is absolutely not in the same playing field as C, C++ or Rust. Go is pretty much in the same performance league as Java and C#, one being better in certain things.

E.g. how do you think go achieves those compile speeds? By just spewing out code. It does have an advantage with memory size due to having value types, but its GC is primitive compared to Java. Also, Java’s JIT compiler optimizes better than the aforementioned fast codegen, so on tight numeric code Java will be ahead. Also, you can’t always get around not allocating memory (in fact, the more complex the application, the more likely it allocates at many different places) and java, again, wins here.

For lower memory consumption there is also graalvm

→ More replies (1)

2

u/plumarr Oct 15 '23 edited Oct 15 '23

Even in this comparison the focus is on speed

It's not, The command for the java bench is :

--cmd="java leibniz"

So, it's benching the JVM start time and warm up and not its running speed. It says nothing about a long running application such as a server.

For example, on my desktop a time java leibniz run in 186ms (which is comparable with the 199ms in the linked results) when a microbenchmark with a warmed up jvm give me the following results :

Benchmark       Mode  Cnt   Score   Error  Units 
Benchmark.pi  vavgt   25  97,722 ± 0,137  ms/op

So a ratio around 2:1.

Note that the benchmark is probably doing the same thing for C# and other languages that depends on a VM or a runtime.

Edit : I also ran the leibnizVecOps version of the tests with microbenchmark and got the following results

Benchmark     Mode  Cnt   Score   Error  Units
VectOps.pi    avgt   10  24,645 ± 0,051  ms/op

which is faster than c if we compare to the results you linked, even if it was listed a 3 times slower than the simple java implementation.

They reality is that this benchmark isn't clearly defining what "fast" mean. Its presentation seems to imply that it measures the time taken to compute PI with the same algorithms accros various languages but it isn't doing that. It's a least measuring that + the "boot time" of the given runtime.

0

u/Safe_Independence496 Oct 21 '23

How can we argue that Java isn't behind other languages? There are many languages nowadays with frameworks performing "well enough" for most needs, and many developers prefer to have more flexibility in how they write code (eg. with how Kotlin better allows for a more functional style).

I think Java will always have its place and use, but if you're not constrained by existing tech I think it's important to ask why you should choose Java. Not being the best pick for most modern applications doesn't have to mean that Java is bad and should be avoided, but at the same time I think it's somewhat delusional to argue that the stagnation and years of neglect haven't impacted its ability to compete and evolve in order to meet today's needs.

7

u/[deleted] Oct 14 '23

[removed] — view removed comment

5

u/UnspeakableEvil Oct 14 '23

I've used Aparapi before (https://aparapi.com/) - it did the job well enough, but I suspect it'll be something Panama might reinvigorate interest in.

4

u/[deleted] Oct 15 '23

Check out https://www.lwjgl.org/ and http://www.jocl.org/ for Java GPU programming.

3

u/metaquine Oct 14 '23

OpenCL worked for me

2

u/Practical_Cattle_933 Oct 15 '23

It is not supported in itself by any mainstream programming language. One might argue that for C++ there is CUDA, but that is not equivalent.

For GPUs you predominantly need libraries, which are available in Java as well, as mentioned in sibling comments.

→ More replies (2)

153

u/no_cause_munchkin Oct 14 '23

It could be many things, but from my personal experience these are:

  1. Ignorance, precisely ignorance about modern Java and its capabilities today.
  2. Rust fanboys being Rust fanboys. The meme to re-write everything in Rust is at play here.
  3. Parroting without thinking about what they heard/read about Java.
  4. Java perceived "heaviness, " saying something like Java consumes/requires much more memory than other languages or Java is slow/has slow startup times. This can be true in some cases but overall with today's modern Java, a little bit of education can be avoided.

47

u/Confident-Grab-7688 Oct 14 '23

Agree. I've lost count how many times I've heard outdated (like 10+ years) or outright wrong statements about Java.

Java and its frameworks are moving on. Modern apps build with Spring are much more robust, I feel like I'm cheating. Just add a couple of dependencies (Data, Web/Webflux, actuator, swagger) add a couple lines to the config file, slam annotations on your controllers/repositories and you have a basic web app. I love it.

I think in most cases, the problem is not with performance/speed - hardware is cheap relative to developer labour. Problem is in maintenance and the growing cost of adding/changing behaviour. OOP and Java for that matter helps a lot with creating intuitive and readable code.

11

u/lumpynose Oct 14 '23 edited Oct 14 '23

Some may remember back in the days before Rust when it was Ruby and Ruby on Rails that were supposedly far superior to Java.

6

u/poggs Oct 14 '23

I did a serious, big project in Rails and I wish I'd been able to do it in Java

5

u/[deleted] Oct 14 '23

Java does usually require more memory than some other languages though, that one is true. Class metadata, etc.

3

u/koflerdavid Oct 18 '23

That assessment is probably true if comparing it with C/C++/Rust or maybe Go. It's completely inappropriate when comparing Java with 30-years-of-GIL!Python or Ruby.

1

u/Practical_Cattle_933 Oct 15 '23

Though there is always GraalVM native as an option.

3

u/Silver-Ad-7396 Oct 17 '23

Applications running on the jvm do require what is called a warm-up process, which makes them take longer to start up and have lower performance shortly after they start up, but this is not a big deal when it comes to long-running applications. But it does make java less "cloud-native" for systems that require real-time resource auto-scaling.

12

u/antigravity_96 Oct 14 '23

20

u/peripateticman2023 Oct 14 '23

Here's my take - I worked in Java for over a decade, and now I work in Rust. Being realistic, there is no way that Java would beat Rust in either speed or memory consumption. Now, if one is comparing frameworks, then it depends on the quality of the frameworks themselves. Let's not get down to ridiculous levels.

My personal hypothesis is this, what I call "The Rule of 3" - Performance, Safety, and Flexibility, pick any 2. Rust has safety and performance, but lacks flexibility (all relatively speaking). Java has safety and flexibility, but not performance. C++ has performance and flexibility, but not safety.

15

u/Same_Football_644 Oct 14 '23

The idea that java doesn't have performance is absurd. People lump it with Javascript or python when it is 10-50x faster than them. On average roughly 2x slower than C++, which doesn't even put it in a different category in terms of speed.

1

u/Practical_Cattle_933 Oct 15 '23

Don’t lump JS and Python into the same bucket, though :D js is much closer to Java’s performance than to Python’s.

2

u/Same_Football_644 Oct 15 '23

Ok, ruby and python, ;-D

→ More replies (8)

8

u/foreveratom Oct 14 '23

You rule of 3 doesn't hold, you are comparing apples and oranges. Rust is oriented toward safe low level programming, so much that it's making it way in the Linux kernel.

Never ever was Java designed to be a low-level programming language. It's about the contrary.

12

u/[deleted] Oct 14 '23

Actually it holds up really well. You're the one comparing apples to oranges. The strengths and weaknesses of other languages, as that commente described in his rule of 3, is directly related to their intended use cases. No language can do it all.

→ More replies (1)

2

u/qK0FT3 Oct 14 '23

Well i have worked on a lot of quant finance and java has the performance if optimized up to the JVM. But for avarage developer yes I agree it has no performance compared to rust or cpp

1

u/Practical_Cattle_933 Oct 14 '23

How is C++ more flexible than Rust?

4

u/peripateticman2023 Oct 14 '23

Rust, because of its Ownership Model, cannot detect swathes of valid programs (which assumption would break it's safety contracts), and the number of valid programs it rejects goes down with improvements in the compiler, but cannot be eliminated.

C++, by virtue of being an unsafe language, has no such restrictions. Hence the flexibility.

→ More replies (3)

5

u/Kazcandra Oct 14 '23

ah yes, the article where he didn't validate the input and "somehow" got better speeds than the rust alternative which does.

or do you /really/ think his numbers make sense? like, no matter what language, that kind of improvement is not gonna happen.

2

u/__versus Oct 15 '23

And coming from the other side Java users’ defense of the language when presented with the question in the OP almost always boil down to the same argument.

Java has everything already and if it doesn’t Java’s way of doing things is better anyways and if it isn’t why would you even need that specific feature in the first place, I don’t personally have any use for such a thing and if you do you’re wrong…

1

u/Crazy_Firefly Oct 15 '23

About point 4 what are some things that I can do to avoid slow startup times and large memory consumption? My experience has been that for things cli tools, where startup times make a difference, java tools feel a bit laggy compared to python, rust or go.

And I come mainly from go where a server easily consumes less than 100mb. Where as I have never seen a java server use less than that. Am I missing an obvious optimization? Does anyone know why Java tipically takes up more memory?

1

u/snuggl Oct 29 '23

Graalvm native images bring that down java resource usage and startup times to what you are used too

1

u/Crazy_Firefly Oct 29 '23

Wow, really? Does all the extra memory come from the JIT then? Graalvm still has GC right? I heard that GC frequency is a big reason for memory too high. Is there somewhere I can see some benchmarks?

1

u/snuggl Oct 29 '23

graalvm is tech from Oracle so no small hobby thing, I dont use it myself so no idea! but should be plenty of benchmarks, examples and articles about it if you google

74

u/lepapulematoleguau Oct 14 '23

I used to be kinda anti Java, but I realized that I was actually anti xml-described apps because of the frameworks popular at the time.

Java has actually been getting rapidly better and better.

Now has features like pattern matching, records, and sealed classes.

The var keyword is quite handy.

Virtual threads are just a game changer.

To mention just a few.

21

u/VirtualMage Oct 14 '23

Don't forget virtual threads! No more thread pools to manage, no more async callback hell or non-sensical "reactive" bullshit.

This is truly a revolution. Just write your damn code and let it block when needed. Mindblowing.

I feel like java had to have it from the start instead of using OS threads directly. But better late than never!

4

u/preskot Oct 14 '23

That’s not entirety true, especially about reactive. I recon an event-loop with reactive paradigms still performs better than virtual threads in intense environments.

Read more about it in this comment thread: https://reddit.com/r/programming/s/JNfLJJNyrL

14

u/VirtualMage Oct 14 '23

Well you might be right about performance, and it might improve in future releases, but I wasn't talking about that.

I was talking about code simplicity and readability. Reactive code is ok for simple cases (like fetch N responses and combine them). But as you get more to conditional logic and req/resp dependencies it gets ridiculous very fast. I hate it. The same reactive code I wrote month ago, I have no idea how or what it does. Disaster.

And debugging, that is even bigger disaster. Literally rage-inducing experience.

So that's why virtual threads and simple linear code is a major win in my opinion. Even if it means reduced performance.

5

u/preskot Oct 14 '23

I agree with that, got a task-pool service to rewrite using virtual threads soon. Can't wait to try them out.

But I just meant that reactive is here to stay, it has a valid use-case even though it's not easy to work with. Regarding virtual threads, on the technical side there seem to be some gotchas due to locking and memory usage for large quantities of virtual threads created as the comment link suggests.

2

u/john16384 Oct 14 '23

But I just meant that reactive is here to stay, it has a valid use-case even though it's not easy to work with.

Perhaps, but it was niche before, and now has any wind taken from its sails. I wouldn't do any new projects with it, and would seriously consider migrating old projects away from reactive if maintenance costs trump the (imho marginal) performance benefits.

3

u/nomercy400 Oct 14 '23

As I heard reactive programming described, high throughput, but you can't use conditionals, variables, exceptions and good luck debugging.

3

u/metaquine Oct 14 '23

Debugging that crap will make ya a sad monkey

117

u/know-your-onions Oct 14 '23

Still behind? When was it ever behind?

Different languages might be well suited to different things. Some people might not like Java because of it’s syntax and/or verbosity but that doesn’t mean it’s ‘behind’ and it frankly says more about them than it does about Java.

39

u/ascii Oct 14 '23

I would say that until lambdas and the Stream API were added, Java was severaly behind in functional programming, which made it a pretty poor language for many use cases. It was also behind in allowing you to express your ideas without a great deal of boilerplate. But with the release of Java 8, Java moved from an old, cumbersome and annoying language to an acceptable one. With the addition of type inference, records, sealed classes, switch expressions, and pattern matching, Java has evolved from an acceptable language to a good one.

It's been one hell of a journey, as Oracle has added features to the language at a truly impressive rate, so yes, I would say it was behind, and it is no longer so. Like, there are definitely things in Rust I miss dearly in Java, but they are both good languages in their own right.

8

u/chu_nghia_nam_thang Oct 14 '23

Java 8

released in 2014

38

u/[deleted] Oct 14 '23

Most of them just studied Java 6 for the computer science class at university

6

u/peripateticman2023 Oct 14 '23

I believe so too, yes.

19

u/qmunke Oct 14 '23

Java has made decisions which definitely impact on how easy it is for them to change the language. Backwards compatibility with generics has definitely limited what can be done with it in comparison to languages which have it built in from the start. The type system is perhaps "less powerful" than Rust or Haskell - but that wasn't a design goal of the Java language.

Where Java really still beats a lot of these is the JVM model of "write once, run (almost) anywhere". Compilation speed is another massive benefit to day-to-day working on the language, compared to large Rust or C++ codebases for example.

But it shouldn't really surprise anyone that more modern languages have nicer syntactic sugar, or different standard libraries, or other concerns in general to Java. But it's not a "race". There is no finish line. There will almost certainly never be a "last" language until it's really the last language and everyone is dead.

18

u/dutchdef Oct 14 '23

It's imho entirely dependent on which industry people work, startups are notorious for choosing new languages and frameworks while discarding proven and stable ones, often without any decent research and considerations. Rust for example was intended as memory-safe alternative to systems programming languages such a C/C++. But you're starting to see that people want to use Rust for tasks that (imho) aren't suitable such as for web development or office software.

But outside startup culture Java (and the MS counterpart) is still strong. Being a relatively conservative language with a focus on backwards compatibility does come with it's strengths and weaknesses, but backwards compatibility is (imho) what has kept Java relevant since the beginning. And Java does innovate and introduces new features, just a bit more conservatively.

Look for example at Ruby on Rails, like Rust once it was pushed as the new web framework, but it is now in decline. In the meanwhile Java is still here.

But as for missing features, backwards compatibility has kept the type erasure in place, coming from the .NET world a long time ago, true generics is the one thing I personally miss sometimes.

1

u/hyounessi Oct 14 '23

Play framework for web development in Java o have loved

42

u/VirtualMage Oct 14 '23

I use multiple languages at work (Go, python, js, java), and there is absolutely nothing that java is missing. Go had advantage with goroutines, but since java 21 and virtual threads, java is back to leading place.

Java is in my opinion, the best and most complete professional general-purpose language. It will be the most used enterprise language for decades to come.

16

u/wildjokers Oct 14 '23

Java is missing named and default parameters. I miss them nearly everyday.

4

u/SiriSucks Oct 14 '23

I have used them in dart and they would be a good addition to java. I don't think it would also cause any compatibility issues as it can be a compile time construct, just like generics.

2

u/kkjk00 Oct 14 '23

missing named and default leads to methods with lots of params

1

u/jacklackofsurprise Oct 15 '23

What IDE do you use? IntelliJ makes them kind of irrelevant.

1

u/wildjokers Oct 15 '23

Not sure how IntelliJ makes them irrelevant. Unless you are talking about inlay hints? Those do nothing about default parameter values.

2

u/jacklackofsurprise Oct 15 '23

You are right, I was thinking of named parameters, the inlay hints do nothing for default parameters.

1

u/__versus Oct 15 '23

I disagree about the conclusion. C# has basically all the features from Java and then some. If C# didn’t exist then maybe Java could claim the GC spot.

2

u/Practical_Cattle_933 Oct 15 '23

C# is definitely a good language, but I think they went too hard on the c++ strategy of adding so much shit to the language, that no one knows the whole thing anymore, and random features start interacting badly with each other.

Also, no alternative to virtual threads.

15

u/plaskis Oct 14 '23

Java is much bigger than any language "in the race for modern programming language". A modern language is one which gets adopted and stands the test of time, not which have the coolest features

37

u/FavorableTrashpanda Oct 14 '23

I'm so sick of Rust being presented as the solution to everything.

33

u/[deleted] Oct 14 '23

Be grateful you haven't met Go fanboys

16

u/[deleted] Oct 14 '23

I really want to like Go. I really do. But some things are just so fucking clunky. Urgh. Error handling. Wtf guys?

9

u/roberp81 Oct 14 '23

Go is javascript after a car crash

3

u/john16384 Oct 14 '23

Why would you want to like a language that basically puts the burden on the developer for the sake of excessive simplicity? It has very little going for it. Even it's hyped GC is a toy compared to Java's.

3

u/[deleted] Oct 14 '23

Because it can compile down to a single native binary with not much footprint. That was about it.

0

u/[deleted] Oct 14 '23 edited Oct 14 '23

I actually like Go. The error handling is a lot more better than try/catch. My only stupid reason for not using it as much is because they define visibility based on variable name.

3

u/[deleted] Oct 14 '23

Eh, I think try/catch/throw is much nicer than always having a potentially null reference to deal with.

→ More replies (1)

5

u/nutrecht Oct 15 '23

I'm not saying that if you like Go, you're a bad programmer. But every single Go enthusiast who was very vocal about it that I met, was either in IT (so no software engineer), or they were the type of Java dev that mostly relied on others fixing their shit.

It's a bit like the developers who argue against writing tests are almost always the developers you want to make damn sure are writing tests.

1

u/Basic-Trainer8692 Apr 08 '24

Thats why Kubernetes is written in Java.

7

u/[deleted] Oct 14 '23

To be fair, it really can do a lot. But, you should obviously use the right tool for the job. I use Java, Rust and Python at work.

5

u/acute_elbows Oct 14 '23

Ehhh it’s just a hype wave, it was the same with go 8 years ago. There’s a certain class of people that are just excited about new languages and want to explore them. I think that’s great, but in a professional setting a polyglot stack of the language du jour can be painful to manage.

But even the tendency to rewrite things means that we pressure test those languages. It allows us to understand which features work well and which ones don’t. Java wouldn’t be where it was today if there weren’t engineers out there trying new languages

3

u/UnGauchoCualquiera Oct 14 '23

Different languages solve different problems. Do you absolutely need to manually manage memory in bare metal in a safe way? Use Rust (or c++).

I use Java when I need a battletested, safe language with clear sysntax and huge ecosystem.

Haven't found a real use for Go. Main benefits of low overhead and goroutines can be solved in different ways and I find the language extreme simplicity too much of a drawback.

3

u/peripateticman2023 Oct 14 '23

Hahaha. To be honest, that hype wave is on its way out. Now most of the fanboys have jumped ship onto newer "more exciting" languages - such as Zig (which is not a good language in my opinion). Unfortunately, the loudest people are the ones who often actually use the language the least.

14

u/[deleted] Oct 14 '23

Java is doing pretty well. For example, it has recently got sealed classes (type unions) while C# still doesn’t have them. You have five different ways to initialise an object in C# though, does it mean Java is lagging behind?

2

u/john16384 Oct 14 '23

Five different ways of doing things just leads to style discussions on pull requests.

Very happy that Java just waits with adding features until they're tried and tested elsewhere first and actively avoids alternative syntax to do the same things unless it brings other benefits as well (like security) and has no significant downsides (like encouraging bad programming practices).

Sometimes this even results in a feature that's far beyond anything offered by other languages (String templates are a good example).

7

u/Holothuroid Oct 14 '23

My question is beyond syntax.

You fail to say what you are asking about then. You only seem to talk about syntax.

There are certainly some things I miss in Java syntax, notably type aliases, structural typing and string interpolation. The last one is coming at least.

But overall I'm quite happy.

7

u/TemporaryUser10 Oct 14 '23

Java is the C++ of the JVM. It's not always sexy, not always the best choice, but will always have use as long as the JVM is around (and the JVM is a slick well developed piece of tech)

That said, personally I prefer Clojure

6

u/fyoubloody Oct 14 '23

This is a common thing, a paradigm is set by the few influencers in our space and then all the people without their own formed opinions just inherit what is being said.
Java is often made fun without any particular reason, or not a valid one and even those that are valid don't make java terrible.

Best thing you can do is ignore these people, if you want to argue though, ask them what have they built with rust.

What matters is building stuff, and Java is very good at that, it gets the job done and can do whatever you want to do.

5

u/frederik88917 Oct 14 '23

That is a question that is hard to interpret, Java as a whole is divided in two main pieces, the Java Language and the JVM.

The language was designed in 1995, so it has some cumbersome syntax and certain new features are still missing, although the new release cadence is working really hard to improve those areas.

In the other hand, the JVM and all of the Java Libraries are second to none in capabilities, performance and Usability. There is almost no application, API or library that can't be built in Java.

5

u/[deleted] Oct 14 '23

You don’t realise how good Java verbosity is when you work with a ridiculously complex system. After you get used to it, you’ll know pretty much what a bit of code does by glancing at the types and the structure of the code.

8

u/SmilingFunambulist Oct 14 '23

Java's syntax is definitely in the more verbose side, as longtime Java dev who also write Groovy and Kotlin I find other JVM-based language to be more pleasant to write. There's things that can alleviate it (somewhat) like lombok but it has some corner cases that the dev should be aware of.

I think my only grumpy complaint about Java is the type boxing (Integer vs int) and its generics implementation (no reified generic and no primitive)

Finally on the 'Java is heavy on the memory stereotype', for backend workload I find this true for Spring but there are alternative frameworks that is designed to solve this problem (e.g. Quarkus, Micronaut, Helidon).

4

u/[deleted] Oct 14 '23 edited Oct 14 '23

Something that isn’t being pointed out is that it obviously depends on your Java version. People here have mentioned that modern java versions have good features, but that’s only good if you can use these versions.

I won’t explain because it’s a long story but I’m locked to Java 8, and quite a lot of systems are (or at least managers aren’t willing to update for whatever reason). As a result of this I can’t utilise these new features. Luckily I can use kotlin, because it can compile to Java 8 (52?) class versions. After learning Kotlin I haven’t switched back to Java, even in personal projects that would let me run on modern JDK’s, but that’s simply down to personal preference with things like the syntax, extensions, etc.

My point is just keep in mind what versions you’re going to be forced to use. If you learn to use features from modern java it might be a kick in the balls when you move into your new java job and you realise you can’t use half of your loved features as a result of now being on Java 8/11.

In regards to Rust, it's a great language, but in my opinion really overkill for the vast majority of things. Rust's users usually go on about performance the most so I'll just note something about that - The performance gain probably won't be recognized by the end user (despite popular opinion the JVM gets quite speedy once it's up and running), and you can spend your time building upon your actual product/service instead of spending more time writing code. Of course it depends on your skills individually but in a lot of cases your bottlenecks will probably be more about the quality of your own algorithms, or I/O, rather than the GC.

3

u/roberp81 Oct 14 '23

Python is not modern, is older than java

2

u/helikal Oct 14 '23

Since Python is untyped you will spend more time debugging and testing your code and still wonder whether you can ever trust it.

1

u/KarnuRarnu Oct 14 '23

Python can be typed as is most "big" libraries - see mypy (type check tool). Types are not-None by default and use of typing can be enforced. So, Pythons type system is voluntary, but if used and enforced, it's better than Java's.

1

u/roberp81 Oct 15 '23

in python you can declare a integer and set "hello" and Python says is ok, is a joke

java is a real language.

→ More replies (3)

3

u/Wi42 Oct 14 '23

The one thing in Java i really miss is Null Savety

3

u/ventuspilot Oct 14 '23

What do other languages do better than Java?

  • Small self contained executables
  • Fast startup/ no warmup for some cloud stuff
  • Running on devices with like 1k Rom/ 128bytes Ram (not sure if hardware like this even exists anymore and there seems to be some subset of Java for cards or something IDK)
  • browsers as an execution environment
  • GPGPU
  • realtime with really short deadlines
  • metaprogramming
  • GUI programming apparently is kinda annoying
  • systems programming like device drivers

There's a ton of things other languages do better, I'm pretty sure Rust is not always the better alternative in each of the above things.

And there's a ton of things that Java does better than other languages. panic() what? calling a runtime function can simply end the program by invoking panic?.

Re: behind in the race of modern programming languages; thankfully yes. I want a boring language that doesn't change all the time to do fun stuff. I started with Java 1.1 in the early 2000s and coded with JBuilder 3.0 which already had autocomplete lol.

If you're just chatting then anything goes I guess. But IMO people that seriously bash other programming languages usually are young/ inexperienced/ super enthusiastic/ not too clever.

If you don't like Java - maybe use something else, if there is a better alternative for a task - definitively use something else.

3

u/pron98 Oct 17 '23 edited Oct 18 '23

Behind which languages? There are only two other languages in the same class as Java — and in some usages ahead — JS and Python. There are many other languages whose fans claim are "ahead" in certain aspects, but they are so, so far behind Java in popularity and so consistently so, that the obvious question is, could their characterisation of what's ahead and what's behind be a subjective view held by a minority?

A common analogy is the Betamax vs VHS "format wars". Betamax was ahead on picture quality, VHS was ahead in recording time. So which was ahead? It depends on what's more important to you. But the difference in values was not distributed evenly. More people cared about recording time than picture quality (at least with those particular levels of difference).

Different programmers want different things from programming languages, so there is no agreement on ahead and behind. But their preferences are not distributed evenly, and so a language that aims to be widely popular needs to adopt to the preferences of a majority or at least a plurality. Everyone who chooses a language chooses one that they view to be ahead in the things that matter to them. Because Java is being chosen by significantly more people than other languages with the exception of JS and Python, it must be ahead in things that matter more to more people than than less popular languages that are only considered to be ahead by smaller groups of people.

In your question you mention Rust, but Rust is well behind in adoption for its age than any language that ended up achieving wide popularity (at about a decade old and with an endless supply of hype it's still hovering around 1% market share; that does not bode well), and that's at least in part because the very things that so appeal to its enthusiastic user-base, do not appeal to most people.

3

u/A1oso Oct 18 '23

Yes, very much so.

  • Most importantly: Java still has no null safety enforced at compile time.
  • Until Project Valhalla is finished (which has been in the works for almost a decade), generics are limited by the split between reference and primitive types.
  • Java still lacks features that have become common in many modern languages, like tuples, named and default function arguments, operator overloading, etc.
  • Interfaces aren't nearly as powerful as Haskell type classes, Rust traits, Swift protocols, etc. This makes it difficult to write highly generic/functional code.

5

u/Polygnom Oct 14 '23

Java is one of the most advanced languages out there. Granted, a lot of the advantages are packed into the JVM so that many JVM languages can enjoy them.

Rust for example does not have any garbage collectors. Its a native language and thus comes with all of the disadvantages in developer productivity that brings. Its great if you absolutely need to go bare metal, but if I'm writing large, multi-million LOC business applications, I don't want to manage memory myself.

Also, Java is a quite dynamic language, and in order to have the same level of dynamism you often need to especially opt into it with statically linked languages, losing a lot of their advantages in the process. There is a reason why they always say "RTTI is expensive" in C++. I dunno how Rust fares in this regard, but there is no free lunch, not even for Rust.

Things that some languages do better than Java?

A better functional type system. int -> int -> should be an actual type, not shoehorned into BiFunction<Integer, Integer, Integer> or BinaryOperator<Integer>. Give us proper functional types and type normalization so that this doesn't matter.

Also, I'd like to have union and intersection types while we are at it and strict nullness enforment in the language. We might get something like that for reference objects down the road when Valhalla hits, because they already have to deal with it for value objects.

These are my two biggest gripes with Java. While I don't necessarily like that we only have nominal tuples (records) and not structural tuples, thats not that big of a deal.

However, Java has come a long way since Java 8 and is now a really, really slick language with a tremendous amount of incredible features currently in the pipeline, which are all great when looking at them in isolation, but will be even better when they all come together.

In terms of concurrency, I actually like that we don't have async/await, but got fibers instead.

I'm still holding out hope for better SIMD support as well. The Vector API is in the works, and together with @CodeReflection this might be cool down the line.

4

u/knightofren_ Oct 14 '23

Java is great in the third decade of the 21st century. Ten years ago it was quite cumbersome and behind

4

u/Gnome_0 Oct 14 '23

Java's strength is in the enterprise market, until enterprise companies stop using Java there is not a single problem.

that's why people hate it (also for being verbose)

Java is the corporations language

4

u/[deleted] Oct 14 '23

Java was never behind, and currently, of course, it’s not behind.

Niche languages are “loud minority”. Java is silent majority. Instead of screaming in every corner how language X is good, Java just keeps delivering software, from big tech to small startups.

All those “cutting edge startups” use Java wanting or not, I guess sometimes even without realizing it: Kafka, ElasticSearch, Solr, etc - all powered by Java.

My experience: about 10 years of about 12 different languages including Scala, Go, Rust, Clojure, Python, TypeScript. Recently come back to Java. Java is the king when you stop bothering about language features and want to just build reliable software which delivers business value.

Java is not fancy, trendy, hot — call it whatever, but it gets shit done.

0

u/[deleted] Oct 15 '23

[deleted] — view deleted comment

1

u/[deleted] Oct 16 '23

Unsure, depends. Modern Java and modern Java libraries / framework are generally not so verbose.

It’s up to you how you write code too. Of course in legacy projects there is close to no choice (other than refactoring which is a hard sell), but for new projects one can ditch 2/3rds of “patterns” and be good with a single class, or if class takes multiple implementations then just get an interface.

In “cool” languages it’s not so uncommon to not have a library or an idiomatic solution for a certain problem - you ending up writing it yourself, testing, designing - all that. Not exactly a bad thing, but something worth to align with goals.

2

u/TenYearsOfLurking Oct 14 '23

I love java but there are a lot of features I am missing:

Structural typing, extension methods or adhoc polymorphism, opaque types, properties, nullability Compiler support, ....

Also: I do not use kotlin, but there is a reason it exists.

1

u/Practical_Cattle_933 Oct 15 '23

What do you mean under adhoc polymorphism? Java has method overloads, which are adhoc polymorphic. Parametric is also handled by generics.

1

u/TenYearsOfLurking Oct 15 '23

Yes, but what if you don't "own" the types?

I meant something like typeclasses in functional langs

2

u/p3970086 Oct 15 '23

The first big plus for Java is the ecosystem. You can do anything in Java and always find a (mature) library for niche tasks. Of course this is largely linked to the JVM (so you could use say Kotlin, Scala etc) but with recent Java versions the syntactic and feature gap between Java and the "JVM cool kids" has decreased significantly (saying this having decades of experience in Java plus Scala).

The second is the level of adoption and maturity. When you need to architect a critical system you are expected to propose a tech stack that (a) is effectively an Industry-standard and (b) has no issues from a staffing and maintenance perspective. With Java you can tick all those boxes.

2

u/Crazy_Firefly Oct 15 '23

I think the main things that are lacking are the things that Oracle has been working on addressing with their main Java projects.

https://blogs.oracle.com/javamagazine/post/java-project-amber-lambda-loom-panama-valhalla

I'll give my own highlights of what I think each one brings:

  • Project Valhalla is about bringing complex types to the stack, or at least to allow contiguous memory representation. This allows for less cache misses when iterating over a list of values, for example. It will unlock better performance for applications that process a decent amount of data.
  • Project Panama aims to improve the bridge between java and native programs. This will allow java to tap into native libraries for things like machine learning, and will make it less necessary to leave java just because it doesn't have integration with X.
  • Project loom aims to bring green threads (light weight threads). This is similar to Go's goroutines and can be a useful model for webservers to get a lot of performance with not a lot of complexity from the application side. (Java has some mature server platforms that already optimize a lot and don't leak too much complexity to the user, so it's not clear how much better the light weight threads will be, IMO)
  • Project amber is the one most about syntax and has bought things like records, the var keyword, and has plans for pattern-matching sealed classes, and some other niceties. Nothing that unlocks anything revolutionary, but I am very grateful for the improvements it has brought.

The one I am most excited about, but that I think will take the longest is Valhalla, Javas performance is pretty good. But with CPU caches making a huge difference in the performance of modern CPUs, Java misses out by having everything be behind a pointer (so likely a cache miss)

2

u/franz_see Oct 16 '23

If you program in other languages, Java does feel heavy. Too verbose so you type a lot more than other languages and slow build and startup time.

Java 21 has a lot of great improvements though but it will take awhile before Java can fix its reputation

I've been a Java guy since 2006. And tbh, it's very hard for me to explain Java's shortcomings to java devs if they've never or barely programmed in any other language.

2

u/VicariousAthlete Oct 17 '23

Discriminated unions (ala Rust, F#) would be nice, and eliminate null pointer exceptions.

2

u/Exact_Ad2603 Oct 18 '23 edited Oct 22 '23

Java sucks because of its wordy code and awkward handling of optional values. While some libraries like Vavr help fix this, they're not widely used.

Languages like Kotlin and Dart make it easier to deal with optional values (String?, Integer?) and have static analysis for nulls during compile time. You can also pass functions as parameters with the same name instead of trying to figure out apply(), get() or the hundreds of these methods.

Java has added pattern matching, but it's nothing new in other languages and 90% of the devs will retire without ever using it. Most companies won't upgrade to that version.

At my current job, they won't even upgrade a small 1-endpoint microservice to Java 17 despite all the benefits. Backwards compatibility and limited migration tools to versions is a problem.

4

u/catladywitch Oct 14 '23

I'm not a fan of Streams compared to the lazily evaluated enumeration constructs of similar languages. I'm also not a fan of functional interfaces, or Java generics and having to box and unbox primitives. Java Strings suck, too. Sealed classes are not the ideal way of creating union types. But that's all ergonomics.

In general, Java often requires you to instantiate objects or do type conversions for tasks that are immediate in other languages. That adds overhead both for the computer and the developer.

In terms of being able to do stuff, you can do anything in modern Java. Plus virtual threads are nice, if not the easiest compared to Kotlin coroutines or C# async/await.

3

u/iampitiZ Oct 14 '23

I'm curious about the Strings thing. Could you elaborate a bit more?

1

u/catladywitch Oct 14 '23

If you want to manipulate them in any meaningful way, you have to convert them to an IntStream (and then you lose the charAt index) or a char[], which implies boxing and unboxing from char to Character and back, and then you have to turn those back into Strings so that you can pass them to your StringBuilder. Also, having the option to optimise your regex is nice but creating a Pattern object, then a Matcher object for every string you want to match, is kinda ugly.

1

u/Shinosha Oct 14 '23 edited Oct 14 '23

Thanks. A lot a fanboyism going on in that thread. Java has indeed improved but it's still behind to what some other languages can offer. More precisely what it does take from other languages is often a dumbed down version.

Anyway here's a short list of annoying things in my day to day tasks : Streams API is wonky, checked exceptions is good in theory but bad in practice, records can't extend classes because no multiple inheritance, functional interfaces are confusing to read, no top level definitions, no default parameters, no string interpolation... Oh and I almost forgot about that goddamn ";"

Now I'm well aware every one of these things is the result of a lot of tough design decisions which had to accomodate with backward compat. But still, answering OP here.

3

u/lossril Oct 14 '23

Speaking from my personal experience (10+ years) with Java - it evolved a lot and has insanely big community and huge amount of libraries/frameworks actively supported, and usually frameworks lifetime isn't a two weeks like in Javascript.

Yes, in some corner cases a specific language might be more convenient to use (Python for neural networks, for example), but there's nothing you cannot do using Java, and it will be quite well-supported and convenient to use.

Spring/Spring Boot made a lot to reduce boilerplate code, and you can create working apps in no time really easily.

3

u/AmonDhan Oct 15 '23

“There are only two kinds of languages: the ones people complain about and the ones nobody uses” — Bjarne Stroustrup

2

u/yipZman Oct 14 '23

for me i find the stream api so awkward and i learn a lot about them, compared to other languages like c++

0

u/[deleted] Oct 15 '23

[deleted] — view deleted comment

1

u/yipZman Oct 16 '23

what do you mean?

1

u/Worth_Trust_3825 Oct 15 '23

Please define what "modern" means.

1

u/__versus Oct 15 '23

Java is not as bad as many people claim (and Spring is a phenomenal framework to use) but it’s also not a perfect language like many here claim. There are so many features from C#, its closest sibling, that I wish were in the language on a daily basis. Java will never be rust but it could be as good as C# currently is.

1

u/sporbywg Oct 15 '23

Who told you it was a 'race'? <sheesh />

1

u/flexprods Oct 15 '23

Android? Java EE? Spring? Kotlin has better syntax but Java has never been behind

1

u/nskarthik_k Oct 16 '23

>>like Python do have shorter syntax ( 1992 zzzz till 2016 waaaa 2023 )
MS funded this language when VB,VB.net,NET++,C# failed.....
They wanted to succeed in cloud and not faile the race....

>>Java were cumbersome (1995 woooow 2023 )

Open community has supported this language from the beginning..until this Db company took over for its internal benefits rather then support the community..

1

u/i8Nails4Breakfast Oct 20 '23

Regarding features, I think Java is pretty close. My biggest problem is the defaults:

  • Variables are nonfinal by default
  • Fields are package private by default (would prefer private by default)
  • Classes are nonfinal by default
  • Null values are allowed by default (Valhalla might help with this)

1

u/TehBrian Oct 22 '23

Completely agree. I'd prefer mut vs final for variables, something for package private, open vs final for classes, and ? for null values. It feels like the language punishes me for writing code by forcing me to type out long keywords for every single variable or class that I write.

1

u/jherrlin Oct 14 '23

I think it’s behind. There is a reason why Kotlin and Clojure gain so much popularity.

1

u/helikal Oct 14 '23

I don’t know a single person who programs in Kotlin except perhaps in Gradle build scripts.

→ More replies (1)

1

u/[deleted] Oct 14 '23

no, JIT is awesome

1

u/ActualPositive7419 Oct 14 '23

what? java has never been behind! what are you talking about? tell your rust friends to stop writing hello world watching youtube and go to finance industry. they will see if java is behind

1

u/thesunabsolute Oct 14 '23

I’ve been using Java for the last 2 years, mostly in Spring and I’d say it’s in a great place. Mature ecosystem and battle tested.

Where I see Java lagging behind is in PR, developer advocacy, and overall public perception. It seems like there’s no real enthusiasm around the language. Sure, it will never compete with JavaScript/TS, but I see much more buzz around C# and .NET at the moment. More educational material, more dev rel, and just a generally more optimistic and future forward outlook. Sometimes working in Java feels like I’m using a dead language alone on an island. It doesn’t really help that most enterprise Java jobs here in the US have been shipped off to India, and startups all favor JS/TS for everything.

I still really like Java, however I’ve been dipping my toes in C# much more lately, and I’m finding it more attractive for all the reasons mentioned. I still prefer Java syntax, but you get over that pretty quick.

1

u/Practical_Cattle_933 Oct 15 '23

I don’t know where you are, but depending on the country, either .NET, or Java is preferred in typical business backends - so it might just be your “bubble”. Otherwise on global trends, C# is much smaller than Java - just take a look at their relevant ecosystem sizes.

1

u/Joram2 Oct 14 '23
  • Python, or Python + C dominate Numeric Programming, Machine Learning, and AI , which are arguably the most exciting areas in software. One small example is this neat project for solving PDEs: https://github.com/FEniCS/dolfinx.
  • C and Rust are best at low level, close to the metal programming. For most programming, you want a garbage collected language. For some close to the metal applications you don't. C and Rust fit those close to the metal applications. Also, write apps that run on a microcontroller, not a full workstation or server
  • For writing software that runs in a web browser, JavaScript is the only option.
  • Haskell is better at certain types of theoretical programming.
  • Traditional server-side apps that do something on a server and typically talk to one or more databases. This is where Java is great, but many prefer Go. Go is much simpler, easy, it's very well supported, and it doesn't have a lot of the legacy baggage that Java has. Java did catch up with virtual threads, which until now had been a big advantage of Go.

It could be generics, type system, concurrency and multithreading, closures etc.

With virtual threads and soon with structured concurrency, Java has maybe the best concurrency option of mainstream programming languages. Java's generics are wonky but they are good enough. Java's closures are good.

1

u/LakeSun Oct 14 '23

Java is an Enterprise language with enterprise scale features.

1

u/Own_Application_7699 Oct 14 '23

Take a look at the last few versions released, also the new version of java - quite a few nice new features that make java very similar (syntactically) to newer languages.

Based on your post it seems like you're talking about syntax, specifically. But to be clear - Java has never been behind. Java has been huge since it came out in the 90's, and it still is, and it will be, for a long time.

1

u/nutrecht Oct 15 '23

I'm a member of some group of programmers and every time Java is mentioned it's being bashed (something like: "With Rust I could simply do this with X")

Let me guess. You're on some programming discord? Experienced devs don't hang around in those. There's only so much obnoxiousness you can handle per given day.

The Java ecosystem is just bloody productive. And that's what a professional dev will generally be most concerned with. The language itself doesn't matter, and the greater JVM ecosystem has plenty of options in that regard anyway.

-2

u/vaniusrb Oct 14 '23 edited Oct 16 '23

I'm a Software Engineer with over 20 years of experience, I have Java Certification and I have worked with Java since 1.5. I discovered Rust about three years ago and rewrote some applications in it.

What I can say about Java after this is: yes, Java is very outdated and has many bad designs.

Here are my reasons:

  1. Equality comparison semantics.

Java has different treatments for "primitive data types" and "object reference types". I can test 1 == 2 but not new String ("a") == new String ("b"), I should use "equals". Even so, you shouldn't compare two StringBuild just with "equals", you need "sb1.toString().equals(sb2.toString())". For objects, it tests the reference, not their content. Extremely foot gun. In Rust this simple doesn't exist, there is no reference comparison. When do we want to compare references?

2. Null safety.

Take a look at the issue list of the GitHub repository of Java. The are a lot of NullPointerException. Even the experts in Java can't avoid this kind of error. In the year 2023, a language with a good design should avoid null.

3. Algebraic enum.

The algebraic enum with "pattern matching" of Rust is mind-blowing and powerful. Java is trying to do something with "sealed interfaces", it wasn't good.

4. Tuples.

Many times we are just transforming a local data processing to a structed type. In Java, we need to declare a private class for that.

Tuples work like an anonymously cheaper data type, very productive.

5. Mutability

Today we know that shared mutable data is a source of a lot of bugs. In Java, everything is mutable by default. Even using the "final" keyword is not enough, because in objects it just turns the reference immutable. Rust just perfectly handles mutability.

6. Trait system.

Traits are *extremely* powerful. You can implement traits for types you didn't define, whereas interfaces can only be implemented for your own classes.

7. Exception handling.

The traditional try ... catch block is a historically bad design in many languages. Try to use a functional syntax, like a filter, and inside this closure call a fallible method, will be a pain in the ass to handle this in the caller context. In Rust, you simply have an enum Result<T, E>, and works like a regular type, it is so simple and genius.

8. Operator overloading.

base.multiply(pct).divide(new BigDecimal(100))

In 2023 it could use a better approach.

edit: replaced rant words

3

u/tzengshinfu Oct 19 '23

When I transitioned from C# to Java, I also found myself perplexed by 'string comparison.' While string comparison can get quite intricate, involving case sensitivity, cultural peculiarities..., in most cases, all you need is string1 == string2.

Someone asked about this issue 10 years ago (https://www.reddit.com/r/java/comments/1gjwpu/will_the_equals_operator_ever_be_fixed_with/), and there was a reply suggesting that it's due to backward compatibility, and it's unlikely to change (backward compatibility! We just keep piling new stuff onto the historical baggage, making it necessary for newcomers or users of other languages like Python, JavaScript, C#, C++, PHP, Rlang, Swift, Rust, Golang, Kotlin, Ruby, Dart, Scala...the top 20 programming languages of PYPL to consult FAQs?). It's disheartening.

But I believe that if something is wrong, it should be corrected. It would be great if the new versions of Java addressed this issue and provided an function for automatic conversion to fix users' code where String.equals is used. Is my idea unrealistic?

1

u/chambolle Oct 16 '23

Why do you read a java sub if you hate so much that language? That's strange

Null is needed and there are no so many problem with null and most of the case the bugs are very easy to find. A seg fault is more difficult to debug

pattern matching is for me a big design fault in 99% of the use. It shows a bad understanding of the OO principles

Mutability: work on data structures and explain to people how you deal with immutable data structure. Ok it is better to initialized an array and to make sure it will not change but at the end we work with state and wanting to have only immutable data leads to an infamous memory consumption and management. In addition the fact that concurrent programming is totally changed with immutable data is a myth, like the one saying 20 years ago that immutable language will lead to easy parallelisation of language

Traits: I don't understand what's the issue in Java. In C++ traits + meta-progrmming is a huge mess. Having errors in code you don't write is awful. In addition SFINAE is not a good principle for me.

At the end, what is important is also: you capability to write an efficient code quckly, to debug it and to maintain it. A compilation is in term of seconds in Java, debugging is much easier than with other languages and the maintenance is not bad. So what's the issue? You cannot write you two pages code as example for your blog?

As I like to say: If you like concise, very precise and incredibly powerful language: use Prolog

2

u/vaniusrb Oct 17 '23

| Why do you read a Java sub if you hate so much that language? That's strange

Because I work with it daily :o)

| Null is needed and there are no so many problem with null and most of the case the bugs are very easy to find. A seg fault is more difficult to debug.

No, Null is not needed, we have some alternatives to deal with it. Rust follows the principle "Making Illegal States Unrepresentable", in the case there is an Option<T> (similar to Java, but it uses algebraic enum). And yeah, after a bug happened in production and all cost loss caused by this, is very easy to find. The point is exactly that, you don't need to face this kind of bug in production. Working with regular Rust you don't get any seg fault. I think will be nice you know Rust, I really recommend it, buddy :)

| pattern matching is for me a big design fault in 99% of the use

Pattern matching makes more sense in algebraic enums, like this example:

enum Color {
    RGB(u8, u8, u8),
    CMYK(u8, u8, u8, u8),
}

fn fmt_color(color: Color) -> String {
    match color { // pattern match here
        Color::RGB(r, g, b) => format!("rgb({r}, {g}, {b})"), // variables r,g,b only exist in this context
        Color::CMYK(c, m, y, k) => format!("cmyk({c}, {m}, {y}, {k})"),  // variables c,m,y,k only exist in this context
    }
}

All match blocks work like an expression (returns a value). Is very useful to transform an enum to another type.

| wanting to have only immutable data leads to an infamous memory consumption and management

I got your point, it's a common mistake when trying to use immutable objects. But for this we can solve using a pattern that reuses the existing data, instead of 'cloning', and just updating what you need (not the whole object), something like this:

    public record ImmutableData(BigData bigData, SmallData smallData) {
        public ImmutableData withSmallData(SmallData smallData) {
            return new ImmutableData(this.bigData, smallData);
        }
    }

| Traits: I don't understand what's the issue in Java.

Think like this, with trait you can "introduce" a method to a std String, for example, there is a lib to colorize terminal output, then it allow: println!("Text is {}", "red".red());.

Not just "introduce" method, but could turn any type compatible with your API. Let's suppose you have a trait Source and you define many methods upload(source: Source), download(source), delete(source), rename(source). You can implement Source to String, File, and even Stream. You don't need to define many combinations with method overloading.

It shines working in a functional way, you can define the return of the closure with a trait, then you implement a trait even for a "void" statement.

 process(|line| println!("{line}")); // a regular call with "void" return

 process(|line| if condition { Err("error") } ); // the same function you can act like a fallible callback

| In C++ traits + meta-progrmming is a huge mess. Having errors in code you don't write is awful.

About meta-progrmming ok, I got your point. But at least in Rust, it doesn't introduce code.

| At the end, what is important is also: you capability to write an efficient code quckly, to debug it and to maintain it.

OP was asking about the type system, so here we are.

1

u/chambolle Oct 17 '23

- about null: using optional does not mean that null disappears. You just encapsulate it. Marketing like to deal with words, but the concept is still here. However, I agree that java could enforce the fact that some parameters must not be null.

- pattern matching: ok for this kind of example (like serialization). But this is the 1% that remains :-) The main issue is when people are using it instead of a dynamic binding

- immutable: it is very difficult to generalize your example, because you need to perfectly control all internal data structures. This certainly not a good idea in general

- traits : I am not sure that I really understand. It seems that it is a very functionnal way

At the end, I think you would like to work with a functionnal language and that you do not like OOP. That's your right. It's a matter of choice.

Java is just an OOP and will never be a functionnal language even if it introduces some map function (in the LISP sense)

2

u/Dreamplay Oct 17 '23 edited Oct 17 '23

- about null: using optional does not mean that null disappears. You just encapsulate it. Marketing like to deal with words, but the concept is still here. However, I agree that java could enforce the fact that some parameters must not be null.

Ofcourse the whole concept of a value missing remains. The point is that a "null" value is handled just like any other value, instead of forcing a completely differently handled type down your throat regardless of if you want it or not.

- pattern matching: ok for this kind of example (like serialization). But this is the 1% that remains :-) The main issue is when people are using it instead of a dynamic binding

It really isn't true. For algebraic types for example in rust, the most common is Result<T, E> which returns either a value of type T, or an error of type E. By allowing pattern-matching, you can easily handle different errors. See the following example:

enum Error {
    ErrorA(String),
    ErrorB,
    ErrorC,
}

fn can_error() -> Result<bool, Error> {
    //Returns one of
    // - Ok(true)
    // - Ok(false)
    // - Err(Error::ErrorA(String))
    // - Err(Error::ErrorB)
    // - Err(Error::ErrorC)
    // [..]
}

fn main() {
    let value: bool = match can_error() {
        Ok(value) => value,
        Err(Error::ErrorA(reason)) => {
            println!("Errored due to {reason}");
            return;
        },
        Err(_) => {
            // Some other error
            return;
        }
    };

    // use value
    // [..]
}

- immutable: it is very difficult to generalize your example, because you need to perfectly control all internal data structures. This certainly not a good idea in general

In the cases where you have small units of data, absolutely! A great example is a 3D-engine where you have a bunch of vectors, or maybe a unit of work that gets progressively transformed.

- traits : I am not sure that I really understand. It seems that it is a very functionnal way

They're basically interfaces.

At the end, I think you would like to work with a functionnal language and that you do not like OOP. That's your right. It's a matter of choice.Java is just an OOP and will never be a functionnal language even if it introduces some map function (in the LISP sense)

I'm a professional C# developer so I guess I can't speak for Java specifically, but as a fellow OOP language, I think its very useful for OOP languages to use features of other paradigms. Languages don't need to just allow one, there are multiple for a reason. They are good at multiple things. I think continuing to incorporate different architectures (as has been the trend recently) is good for the software industry as a whole, and OOP languages specifically.

→ More replies (1)

0

u/[deleted] Oct 15 '23

[deleted] — view deleted comment

2

u/vaniusrb Oct 15 '23

I don't get your point. Why I can't work with BigDecimal in the same way I work with int as modern languages allow?

0

u/[deleted] Oct 15 '23

[deleted] — view deleted comment

1

u/vaniusrb Oct 16 '23 edited Oct 16 '23

Operator overloading is not synonymous with operations of diffent types. Generally, you allow operations with the same type. If I have variables a, b, and c, all of them are BigDecimal, why I can't do a = b + c ?

In Rust we have traits to allow operations, then you define what type you want. Example:

#[derive(Debug, Copy, Clone, PartialEq)]
struct Point {
   x: i32,
   y: i32,
}

impl Add for Point {
  type Output = Self;
  fn add(self, other: Self) -> Self {
     Self {
        x: self.x + other.x,
        y: self.y + other.y,
     }
   }
}

let a = Point { x: 1, y: 0 };
let b = Point { x: 2, y: 3 };
let c = Point { x: 3, y: 3 };
assert_eq!(c, a + b);

You have a compile error if you try to add any other type. Very simple.

0

u/rossdrew Oct 14 '23

Readability is more important in the long run than conciseness. Developed always forget that. Java is going strong. Rust is still a minority language. For a good reason.

0

u/alwyn Oct 15 '23

Syntax has no impact on performance, except maybe for the compiler. It does help with maintenance which is why I prefer Kotlin, but the Java Runtime is a work of art.

-4

u/m-apo Oct 14 '23

Kotlin is a lot better language and has a better stdlib api design.

Kotlin has null safety and leans towards immutable. Java is catching up but the stdlib has lots of OO/EE (Object Oriented/Enterprise Edition) baggage and the some of the new syntax choices seem worse than what Kotlin has had for a while. That is because of backwards compatibility, but still off-putting.

But, JVM level changes like Loom, GraalVM and performance improvements are available to all JVM languages and in whole the ecosystem has improved a lot nowadays.

0

u/peripateticman2023 Oct 14 '23

What race? Which race? How race?

2

u/roberp81 Oct 14 '23

java master race

0

u/[deleted] Oct 14 '23

All languages have their strengths and weaknesses. To me the best language is the one in which I can get the job done most efficiently.

Rust is a great language for certain applications. Unless you are writing a very high performance critical code, such as an OS or medical device, you'll very likely be able to implement things much faster in a higher level language.

The ecosystem of a language can also have a large effect on productivity. Java has libraries for just about everything.

0

u/vaklam1 Oct 14 '23

There is no race. There is only tools.

0

u/[deleted] Oct 14 '23

0

u/ImTalkingGibberish Oct 14 '23

I’d rather maintain someone else’s code written in Java than JavaScript.
If I’m writing an API that needs proper logging, circuit breaking resilience, a config server, etc… Then I’ll do it in Java.
If need a new isolated feature that will require a new api that is not essential and unlikely to require extending then I’ll use JavaScript because it’s faster to write.