r/programming • • Aug 09 '22

Don’t call it a comeback: Why Java is still champ

https://github.com/readme/featured/java-programming-language
8 Upvotes

86 comments sorted by

23

u/SeekDaSky Aug 09 '22 edited Aug 09 '22

For me there is a strong line between Java and the JVM. The JVM is one of the best VMs out there, it's ability to run any kind of well written, and less well written code fast is quite impressive, which gives it a good effort/performance ratio.

Java as a language for me is too rigid and forces you to use convoluted patterns to work around its lack of expressiveness.Yes, Java evolved a lot in the last years, but it's late, a lot of codebases are locked on Java 8-9 already.

As for new projects, why use Java 18 when you could have Kotlin, that does everything Java does, and more? I just don't see a place for java in new projects anymore.

9

u/dark_mode_everything Aug 09 '22

Kotlin is great and I know this a very polarising topic but I miss checked exceptions which I find is extremely useful in backend development. Also, java is a very simple language so understanding and maintaining large code bases with millions of lines of code is not that difficult. You can always follow the flow and easily understand what's going on. This is because of Java's verbosity even though most people complain about it. So yeah, kotlin is great but there's definitely still use for java in new large scale projects.

3

u/CAM1998 Aug 28 '22

I agree with you. I think this is a key part of Java's success.

3

u/kerkeslager2 Aug 09 '22

Yes, Java evolved a lot in the last years, but it's late, a lot of codebases are locked on Java 8-9 already.

Also, some of that evolution has fallen prey to having multiple ways of doing the same thing which don't interoperate very well, such as events, strategies and callbacks.

C++ started that fire, but a lot of languages, such as C# or JavaScript have fallen prey to this. Modifying a JS codebase that uses callbacks, promises, and async/await often forces you to write thin interop layers that just translate between the different ways of doing essentially the same thing.

1

u/jordus100 Aug 09 '22

I have Java taught in university and in my summer internship as a programmer I do Android development which convinced me to learn Kotlin as the official Google guide contains few Java examples. Now I'm thinking with dread about going back to Java for uni when the next semester starts. A throwback to the medieval times.

2

u/BoyRobot777 Aug 10 '22

What Java version is taught in university? Compared with Java 18, what are you missing?

1

u/jordus100 Aug 10 '22

Some very early versions. But even if it was Java 18 I would still miss the conciseness of Kotlin and handy stuff like coroutines I think.

2

u/BoyRobot777 Aug 10 '22

I'm using Java 18 in my quite big organisation.

conciseness of Kotlin

Any examples?

coroutines

Sure. This will be address in a year when virtual threads become stable feature. Now it's a preview feature in Java 19.

3

u/jordus100 Aug 10 '22

I'm sorry but have you ever seriously used Kotlin? The syntax is generally more concise, a lot of things are implied by default. As for big differences, getters and setters are automatic in Kotlin. That alone decreases the amount of boilerplate healthily. Off the top of my head, println() instead of System.Out.PrintLn(). Singleton and Builder patterns are ready to use with just a few words. I'm no expert on modern Java but I think delegations and functional programming are taken a step further in Kotlin because the language was designed with these in mind. As to virtual threads, nice to hear, didn't know that, thanks.

4

u/BoyRobot777 Aug 10 '22

You just had a very strong opinion about Java, stating it as "A throwback to the medieval times.". I was interested in what makes you think that way. For me, personally, println() instead of System.Out.PrintLn() is not an issue, but interesting to know.

1

u/jordus100 Aug 10 '22

Yeah that was an exaggeration, nothing wrong about Java, it's just sometimes painful to write/generate a lot of code for something you could do much faster in Kotlin. Also FP in Kotlin is very elegant.

2

u/jordus100 Aug 10 '22

alsp something that just popped to my mind while writing Kotlin code, extension functions and global static-like functions are convenient. as well as simpler function overloading without having to write a massive amount of code like in Java.

28

u/[deleted] Aug 09 '22

ITT: A bunch of non Java programmers saying how much java sucks and X, Y or Z is better.

Java 17 is not Java 6. The language has come a long way and when you are writing enterprise apps it is still hard to beat. And Java 19 adds even more modern stuff. C# (when on windows) is about the only one that truly beats it.

Python is fun to write and gets something out the door quick, but it is a nightmare to refactor and maintain a large codebase in.

Javascript is the lowest common denominator of all languages. The ONLY reason anybody writes it is because you have to for modern web apps. It's soo bad (as a language) that there have been multiple attempts to fix it: TypeScrpt and Dart.

c# is a really good language, and the tooling is even better, but if you need a library to do something, it exists in Java, but might not exist in C#.

10

u/holo3146 Aug 10 '22 edited Aug 10 '22

tooling is even better

Interesting, I worked with Java for several years and recently I moved to a team that uses C# and I feel the other way around, the JVM ecosystem feels so much better in almost every aspect, including tooling.

The only thing I feel C# does better is few features here and there, which is not enough to make feel like it is above Java.

The only feature I really think C# did better is extension methods, but stuff like Loom solves it.

Edit: Loom should be Lombok in the last line

2

u/Muoniurn Aug 10 '22

Not disagreeing, but how are extension methods related to Loom?

2

u/holo3146 Aug 10 '22

Oops, I meant Lombok, sorry

2

u/Tenderhombre Aug 10 '22

I've worked in .Net and Java. Both are pretty comparable in their new features. At this point I just prefer .Net because of familiarity. I've used it more and am more familiar with the eco system.

3

u/vegetablestew Aug 09 '22

Now how many orgs are actually using Java 17? Pretty sure most shops are still stuck at Java 8.

3

u/holo3146 Aug 10 '22

I believe that Java 11 is more used than Java 8 as for the end of 2021.

While your point is correct, it can be said about almost all languages, new versions are slow to become popular. Realistically Java 17 is the next version after Java 11, so in like 3 years it should catch up.

1

u/vegetablestew Aug 10 '22 edited Aug 10 '22

Its not just about "new languages". Its about a language that is widely used in enterprise and has a big legacy baggage. C, C++ has the same issue. So did Python until it did the fork.

Backward compatibility is a boon in some ways, but also holds the language back.

3

u/mpinnegar Aug 10 '22

Pythons 2/3 split is a gigantic cluster fuck and for what appears from the outside to be little practical gain. The fact that you can still take super old Java code and use it just as easily in the latest version of Java is a huge advantage that can't be understated. There's a reason Java doesn't have the "library of the week" problem that the JavaScript community has because problems get solved once or twice correctly and then don't need to be solved again.

0

u/vegetablestew Aug 10 '22

No Java doesn't have library of the week problem because Java has a solid standard library and because Java is way less popular than JS, and because starting a new project in Java, unless you are enterprise is mostly a legacy endeavor.

2

u/Muoniurn Aug 10 '22

It is not way less popular. Js, Java and Python are the 3 most popular languages. Depending on problem domain one has much more flourishing ecosystem then the others. E.g. python has plenty of ML libs, JS has plenty UX-oriented, and Java has a healthy mix of everything. In my opinion their quality is also superb.

1

u/nacaclanga Aug 10 '22

Yes but backward compatibility is essential, because not every single employee can be retrained and every single codebase can be rewritten after every single technological advancement. This is also why anybody bothers with releasing new standards (which are usually new, but highly compatible languages) and we are still have code in a bunch of older languages by now.

The problem is, that backward compatibility issues pile up in the long run.

The real task is finding a good progression method. Usually you do not need infinite backwar compatibility, what you instead need is full compatibility with the previous iterations and a clear stategy on how to advance stuff. Approaches like Kotlin or Rust editions are a step in the right direction. Keep backward compatibility but push "legacy" features into nices, that can be eventually removed entirely.

3

u/vegetablestew Aug 10 '22

I agree, but Java came out at a time when the stuff we expect from modern language hasn't been fully figured out such as shitty build systems, no type reification, better dependency management and imports, no default UTF8 compatibility in resource files(this is fixed relatively recently).

Due to the legacy baggage, they are just starting to catch up to what other language had for decades. And it shows.

Imo, a company not tied down by legacy bs should probably either use Kotlin or Clojure. Keep the JVM, ditch the Java.

1

u/crimzonphox Aug 11 '22

We have some kotlin apps mixed with our Java ones.

I’ve really started editing kotlin over Java

0

u/throwaway99kajillion Aug 09 '22

C# (when on windows)

You do know that the .NET runtime lives on Windows, macOS, and Linux, right? In fact there is some argument to be made that it runs better on Linux, because that is where the majority of deployments are on Azure (Microsoft's real cash cow).

8

u/[deleted] Aug 09 '22

Yes the runtime does but not all of the frameworks do.

1

u/nocgod Aug 10 '22

All the major and main frameworks are OS independent. except some that specifically use OS APIs like winforms and wcf, those were ported to the latest netstandard 2.1, net5, net6 only for legacy compatibility. No one today starts a new project using anything that'd nail em to windows. VS default projects with asp.net use docker ootb.

For experience with both java and c#, I take c# every day (10 years professional software engineer, today an architect in a major enterprise company)

-8

u/CodeCocina Aug 09 '22

I still rather write javascript over Java lol. But c# is best, it runs on macOS too, so looks like you’re not up to date on C#, most orgs are running old Java, so most of what you said is irrelevant

4

u/KieranDevvs Aug 10 '22

Sorry but .NET core / 5+ (specifically C#, never used F# and the one that shall not be named, will not be named...) beats current Java to a pulp, strains the juice and then drinks it.

  1. Reflection is still to this day, far better in .NET and even then, most common reflection use cases are being fazed out by source generators for AOT compilation, tree shaking and full assembly trimming

  2. LINQ. The streams API in Java just doesn't cut it.

  3. Source generators (mentioned in the first point), opens up so many scenarios for quality of life and performance benefits by not having to rely on the runtime. i.e Static analysers to spot common mistakes and give developers warnings and automatic fixers, or a regex generator that gives me an expression that is ready to execute from the assembly, compile time dependency injection, compile time dynamic domain object mapping... the list is very big.

  4. UI. You have WinForms and WPF for native windows development, then you have MAUI for cross platform (barring linux officially, there is a community project to extend this to linux also), then you have Blazor WASM, AvaloniaUI, Uno Platform, and then the more bare metal wrappers like Silk.NET for OpenGL, Vulkan and DX cross platform hardware accelerated graphics. If there's something you want to build on some platform, .NET has a solution.

  5. I've used Visual Studio since VB6 and if you would have asked me 5 years ago, I would have said its one of the worst IDE's. Everything from the licencing model to the 32 bit single threaded plugin system. But, I must say, VS2022 17.3 is an absolute pleasure to work with. I don't know exactly at what point it became this way but I feel like 2019 was a good step in the right direction. Injelij is decent but its not even a fair fight.

  6. Web frameworks, APIs and libraries. Cmon, an explanation isn't needed for this one.

  7. The language. The fact that Kotlin and Project Lombok exist, should tell you enough.

2

u/vlakreeh Aug 09 '22 edited Aug 09 '22

I'm not someone who's super tapped-in to the Java ecosystem but reads a bit like "Java is still popular and it's development is now at a pace similar to other languages". Not to say that's a bad thing, but something I've thought about the past while is what are Java's big advantages over other languages meant for similar problem spaces?

Relatively safe, cross platform, with lots support aren't as rare anymore and often have some more notable differentiating factors that Java doesn't have because of it's age. I can't really think of a problem space where I think "Java is the perfect tool for that job".

Edit: I should probably clarify that I mean besides Android where that's pretty much your only practical option besides Kotlin (which is also becoming the go-to Android language).

14

u/repeating_bears Aug 09 '22

what are Java's big advantages over other languages meant for similar problem spaces?

The ecosystem. Established, stable, and not trend-driven. From IDE, to libraries, frameworks, build tools, dependency management, I've never seen another language that had its shit together like Java does in all those respects.

There's so much more to a language than just the syntax, which is admittedly dated.

7

u/sureshg Aug 09 '22

There's so much more to a language than just the syntax, which is admittedly dated.

Modern java is not that bad. See some of the new stuffs used here - https://www.infoq.com/articles/data-oriented-programming-java/ . I think the problem is many folks (especially in enterprise) are stuck at JDK 8, which sucks.

4

u/repeating_bears Aug 09 '22

Yeah, I use it every day and very rarely find myself wishing it were different. It's perfectly usable. I guess my biggest gripe is the type system. Kotlin's approach to null is objectively better, and all the stuff surrounding that (Elvis operator etc.) is stuff Java will probably never be able to do.

-2

u/mizu_no_oto Aug 09 '22

Sounds like they've dragged it a third of the way to Scala.

3

u/vlakreeh Aug 09 '22

The ecosystem is pretty good, I'm personally not a huge fan of Java tooling but I can definitely see it's ecosystem being a huge pro for someone trying to choose a language for a project. That and Java IDEs are pretty much magic when it's behaving, I miss the quality of Intellij when I write things nowadays.

1

u/repeating_bears Aug 09 '22

Is there one that you think is better? I've heard good things about C# but never tried it. All the others I've tried (C++, JS/TS, Python, Ruby) were worse.

6

u/[deleted] Aug 09 '22

Rust tooling is fantastic

3

u/TheNamelessKing Aug 10 '22

I have minor PTSD from how java/Scala dependencies work.

It’s the most nightmarish combination of “basically everything goes good luck”.

Oh look I can have a dependency that may or may not be included, or it may or may not be shaded, and it may or may not be overrideable or provided at runtime and the number of places and things you have to check when ✨something✨ goes wrong with ✨some✨ dependency in your stack is a thoroughly unpleasant experience.

1

u/repeating_bears Aug 10 '22

Really those are aspects of Maven rather than Java, but is there a lang in which you think it works better?

3

u/TheNamelessKing Aug 10 '22

Rust mostly, Haskell was also quite pleasant.

I’m just really not a fan of the late-binding style dependency loading favoured by languages like java and C#. “Guess we’ll just figure it out when we start up and see what happens” is not an approach that fills me with confidence. In my experience the bizarre hoops you jump through to get the much lauded “just swap the implementation at runtime bro” are absolutely not worth the tradeoffs and inevitably just lead to confusion. When something compiles “correctly”, I expect it to then run correctly. JVM languages break that expectation on my experience.

2

u/vlakreeh Aug 09 '22

For tooling? IMO the problem with Java's tooling (but many languages share this problem) is that it's incredibly fragmented. There's nothing I hate more than an ecosystem with wildly different views on formatting, documentation, build systems, dependency management, linting, etc. I think it leads to a lot of uninteresting work that makes it harder to do your job actually using that ecosystem. Granted, that's my opinion and many people disagree and have fair arguments for a fragmented tooling ecosystem.

Some of the ecosystems I think handle this really well are newer ones with: Go, Deno, and Rust being really pleasant to work with tooling in my experience. For the most part you'll see all libraries in that ecosystem with the same formatting, nicely interlinked documentation, dead simple dependency management, with the ability to understand how to work on a project nearly instantly as your understanding of the tooling transfers.

2

u/repeating_bears Aug 09 '22

I guess Java projects have different ideas on formatting, and there aren't great linters for automatically fixing issues (those things are probably related), but in every other respect I don't really know what you're talking about. Documentation? JavaDoc. Build system + dep management? Maven (2/3 of projects) + Central.

JavaScript and C++ are what I'd call fragmented.

1

u/vlakreeh Aug 09 '22

The problem for Java isn't that the tools don't exist, it's that no one agrees. Sadly many people something other than JavaDoc for their hosted documentation, and even they do the documentation generally doesn't interlink past the library scope as maven central doesn't host the documentation along side the libraries. As for dep management Maven is obviously the winner and is pretty universal thankfully but as a build system it still contends with Gradle which isn't directly compatible making it a bit of a chore when you do need to dig into your dependencies.

The JS ecosystem is definitely fragmented with NPM, but other JS runtimes ecosystems like Deno's are pretty cohesive. And then there's C++, the go-to example of a fragmented ecosystem.

3

u/repeating_bears Aug 09 '22

many people something other than JavaDoc for their hosted documentation

I can't think of a single example. Do you have any?

even they do the documentation generally doesn't interlink past the library scope

What's the use-case? I use some library which has a transitive dependency on something else, and you want a link to the transitive one?

I guess I could see that being handy but generally speaking transitive dependencies will be used for implementation details and shouldn't actually leak into the public API.

I can't say I've ever missed this feature but I guess it could be handled better.

maven central doesn't host the documentation along side the libraries.

Actually, it does. It's an extra artifact to push, which not every project will do, but all the big projects do it. The convention is to use a Maven classifier named "javadoc", e.g. the first JAR here: https://repo1.maven.org/maven2/joda-time/joda-time/2.10.14/

Unfortunately Central doesn't directly serve the HTML - though it could - but there are sites like this which are effectively just downloading the JAR, unzipping and serving it for free:

https://javadoc.io/doc/org.springframework/spring-core/latest/index.html

Also IntelliJ understands the classifier convention and can download the docs into your IDE.

1

u/sureshg Aug 09 '22 edited Aug 09 '22

dead simple dependency management,

Yeah, it's simpler for relatively small projects and cli applications. JVM builds tools like Maven/Gradle does more than dep mgmt and has rich plugin ecosystem to do most of the stuff from the build file itself. In go, you will end up writing all those things in Makefile (see https://github.com/kubernetes/kubernetes/tree/master/build/root ). So you made the mod file simpler and moved all your other concerns to some other build tool (Make)

0

u/vlakreeh Aug 09 '22

Those ecosystem's dependency management is capable of much more than small projects and CLI applications. Deno, a JS runtime implemented in Rust, even uses Rust's standard dependency management and that's hardly a small project.

Also, one example of a huge non-trivial body of software using a makefile doesn't mean that you can't use Go for your project, K8s is a pretty unique case.

Cargo/Deno/Go also aren't just dependency management so your comparison to Gradle and Maven is pointless for the most part.

10

u/sureshg Aug 09 '22 edited Aug 09 '22

I would add few more,

  • Best performace for a GCed language (https://web-frameworks-benchmark.netlify.app/result)

  • Massive ecosystem of libraries

  • JIT and AOT support (Using GraalVM, there are some limitations though)

  • Runtime observability (JFR, built into the VM) and Debugging (Local and Remote)

8

u/vips7L Aug 09 '22

JFR and remote debugging is really undersold.

3

u/vlakreeh Aug 09 '22

Performance can depend on the benchmark but the JVM is solid so that's a fair point, but I don't know how well the other points hold up as they aren't exactly unique to Java. NPM has an even bigger ecosystem, granted quality varies massively, but even then you could use Kotlin on the JVM and still have the ecosystem. JIT and AOT support are definitely nice, but again aren't unique to Java.

I hope I'm not coming off too harsh on Java, I just have a hard time seeing huge differentiators for a language that was disruptive 25+ years ago.

9

u/repeating_bears Aug 09 '22

NPM has an even bigger ecosystem, granted quality varies massively

That is a huge caveat. The JS ecosystem is absolutely awful in comparison to Java. Even if you ignore the left-pad nonsense and dependency hell and only focus on the good projects, there's still a million different ways to do the same thing.

Even without writing a single line of code, just setting up a basic build you might choose any number of NPM, Gulp, Webpack, Rollup, Vite, Babel, Typescript, blah blah blah.

Little care for backwards compatibility. Breaking changes and painful migrations are the norm.

even then you could use Kotlin on the JVM and still have the ecosystem

Sure, and that's a great way to have the best of both worlds, but the existence of Kotlin in no way detracts from Java.

1

u/flatfinger Aug 10 '22

...there's still a million different ways to do the same thing.

Given a choice between having many ways of doing overlapping sets of things, with the effect that some common tasks will be achievable with any of them, or having one way of doing one set of things, which has difficulty doing well--if at all--some things that were easy in some of the original set, I think it's generally better to err in the former direction.

In a language with two-dimensional arrays, there are at least three useful ways of handling a request to read element [row,column] when column exceeds (width-1), but (row*width+column) is less than (height*width):

  1. Flag an error

  2. Return whatever value is presently in [row + column/width, column % width]

  3. Return any value that ever has been, or ever will be, in [row + column/width, column % width]

Rather than trying to argue about which of those approaches a language should take, or declaring that any program which would rely that such an action not trigger completely arbitrary side effects is "broken", it would be more useful for a language to provide an easy way of indicating when each of the above treatments best allow a programmer to accomplish the task at hand.

0

u/vlakreeh Aug 09 '22

there's still a million different ways to do the same thing.

Definitely but that's going to happen in any big ecosystem, including the Java ecosystem. There's always going to be multiple bodies of software to solve the same problem with subtle differences, that's just the nature of software.

Good point about the headache of setting up fresh project, one of my biggest problems with the NPM ecosystem is unopinionated it is for the basics most projects will need.

but the existence of Kotlin in no way detracts from Java.

It definitely doesn't! Kotlin's existences undoubtedly improved the JVM ecosystem and writing Java is better because of it. But Kotlin (and other JVM languages) also caused Java to lose the some of it's uniqueness with respect to selling points.

1

u/flatfinger Aug 10 '22

But Kotlin (and other JVM languages) also caused Java to lose the some of it's uniqueness with respect to selling points.

The lack of any kind of unsigned array types other than char[] in the Java language, and the need to cast integer values when storing into a byte[] are needless major nuisances. While saying that all integer computations are performed using int or long is a better design that the mish-mosh of signed and unsigned rules that C ended up with, adding unsigned array types wouldn't need to break that simplicity if reading from a uinteger[] would yield a long, but long could be stored into uinteger[]. Such improvements are more likely to happen if other JVM languages can lead the way than if they'd have to originate with Java.

BTW, I wonder what the implications would be if Java's Thread class were to add a few fields of type long, and double, with the intention that any called function could set them however it saw fit? This would make it possible for a language to support compound primitive return types without requiring new JVM features, provided any code using those fields was used with a current version of the Thread class.

3

u/CandidPiglet9061 Aug 09 '22

There’s even AOT support for Spring Boot apps now. Does it take a literal eternity to compile? Yes. Is it also mind bogglingly fast? It’s a yes from me

1

u/entityadam Aug 09 '22

LL Cool Java

2

u/entityadam Aug 09 '22

Mama said knockout.js.

-1

u/nooneisanon Aug 10 '22

Java programmers are the original cryptobros. Always chirping about how great java is. We get it. You think it's the best. Us full stack guys appreciate you but....

... we know it's hard out there for you java guys in modern times. Saber toothed tigers thought they were champs too.

-22

u/triffid_hunter Aug 09 '22

Champ at excessive memory usage and horrific performance perhaps..

Literally never had any other experience with a java program

27

u/Birk Aug 09 '22

Yeah, you sound very inexperienced with Java.

-14

u/triffid_hunter Aug 09 '22

Never tried to write any, but every time I've encountered a Java app in the wild it's reliably had those traits

13

u/[deleted] Aug 09 '22

I can almost (90+% certainty) that you have used plenty of java apps without knowing it that didn't have performance issues so you never even knew it was java.

5

u/random8847 Aug 09 '22 edited Feb 20 '24

I enjoy watching the sunset.

4

u/spoonman59 Aug 09 '22

Java uses less memory and has vastly superior performance to Python, CPython. I wonder how it does compared to modern JavaScript?

Java is quite excellent in performance and memory for a managed language. I doubt C# provides superior performance, and it is not historically as portable. (I know much of the eco system was open sourced, but some APIs aren’t cross platform.)

Obviously it doesn’t compare as favorable to non-memory managed languages.

So in my years of programming and performance tuning Java, as well as big data processing using Java based frameworks like Hadoop and Spark.

So tell me more about your experience of poor performance and excessive memory use? 90s meme, or is it your actual experience?

2

u/mxz3000 Aug 09 '22

structs in C# (i.e. stack allocated objects) are critical for writing high performance code, by reducing allocations.

There's no equivalent in java, so reducing allocations in Java often requires crazy state mutating logic, which is way more brittle.

I would be interested in seeing how java compares to JavaScript. Tbh, I wouldn't be surprised if JavaScript generally outperformed java, due to the insane black magic happening inside JS runtimes. Certainly at my old job, when we were writing serverless services, switching to NodeJS from Java, massively reduced latency (i.e. cold start) and memory requirements.

12

u/spoonman59 Aug 09 '22
  1. The JVM runtime performance escape analysis since 1.6. This allows the runtime to stack allocate objects which do not escape the scope. Even though the language might not let you explicitly state that something should be on the stack, the runtime often makes a similar optimization.

Don’t confuse the semantics of a language with the runtime characteristics.

The JVM spec does not actually specify what data is stored on the heap or the stack, so the runtime has some latitude to optimize here. Then it becomes all about what you can prove!

2. Value semantics in C# means that allocation and copying of structs needs to occur when returning a struct from a function, or passing it as a parameter. So, in some code, heap allocated objects might perform better. Whether struts are good in your use case really depends on how you use them. It’s not always a win.

3. The hotspot JVM can also do automatic object object reuse and other optimizations for shortly lives objects. This also greatly reduced allocations depending on the code. So, for example, loops that create objects that don’t live long for whatever reason, can be optimize.

Structs are a nice feature, and I’m sure they can reduce memory usage when applied appropriately. That said, I don’t think they are the sort of “killer feature” that will make C# perform significantly better (indeed, if at all) than Java in terms of memory or runtime.

The CLR is good, but I don’t believe it does as much runtime profiling or dynamic optimizations as Java. At least when I worked in C#, assemblies where generally JIT compiled in a single pass.

For example, the JVM can inline methods which are part of an inheritance hierarchy as long as there is only a single implementation currently loaded. The JVM then dynamically “de-lines” the method as soon as you load a new class which provides an additionally implementation.

It’s impossible to do this with an ahead of time JIT approach because you don’t know what assemblies will be ultimately loaded, so you have to leave dynamic dispatch in.

I’m not sure what the modern CLR is like in terms of this. But the adaptive compiler is quite sophisticated and does quite a bit. The CLR is also quite good, but I don’t think it’s probably comparable to Java performance wise.

1

u/didibus Aug 09 '22

Everything has trade offs, anyone who speak in absolute as a software engineer is a red flag, and best not to hire them.

A Java backend will outperform NodeJS when run as a long-lived server. But if all your backend does is a proxy for IO to it's clients, a IO blocking Java backend might underperform compared to a non-blocking NodeJS backend. A non-blocking IO Java backend will still outperform NodeJS.

But if you want a short-lived server backend, and expect to launch a new instance per-request, now a NodeJS backend might make up for its slower performance with its faster start time. Is this worth it for you depends how much the backend does. If the backend does heavy compute, and the runtime is your biggest bottleneck, faster start time might still not beat it.

Now an AOT compiled Java backend, using GraalVM, will outperform a NodeJS backend even on start time, once again being faster.

There's similar tradeoffs between C# and Java runtimes. Trade offs are everywhere.

That's why all languages are able to deliver on your business use cases. None of them is so deficient as to not be able too, and none of them is so much better as to kill off the others.

Often it comes down more too tooling, familiarity, what university teaches, and what companies already use.

And for performance and scale, your own architecture is often much more important.

1

u/sureshg Aug 09 '22

But if all your backend does is a proxy for IO to it's clients, a IO blocking Java backend might underperform compared to a non-blocking NodeJS backend.

That might change in JDK 21 (with virtual threads). See this https://github.com/ebarlas/project-loom-c5m . It achieve 5 million persistent connections (again depends on the server capacity and kernal tuning) using normal simple blocking code (https://github.com/ebarlas/project-loom-c5m/blob/main/src/main/java/loomtest/EchoServer.java) . It's a far better better programming model compared to JS async/await.

1

u/didibus Aug 09 '22

That still uses non-blocking IO, it's just hidden underneath the API for you. If you call a typically blocking IO Java API within the context of a virtual thread, under the hood the API will actually do non-blocking IO. But if you call it within the context of a real thread, it will do typical blocking IO.

That said you're right, that makes it a lot easier to switch traditional blocking code to use non-blocking IO. Much easier than using the NIO APIs directly with CompletableFuture and all that.

-6

u/triffid_hunter Aug 09 '22

Java uses less memory and has vastly superior performance to Python, CPython.

Ooh strawmen.

Python never promised performance or memory efficiency as far as I know, and doesn't even attempt to deliver on them - it's a 100% convenience-focused language at the expense of many performance metrics.

I wonder how it does compared to modern JavaScript?

No idea, no-one I know uses javascript for its performance outside of html5 games that demand to be run in chromium - nodejs is a crutch for coders who don't want to learn something suitable, no?

I doubt C# provides superior performance

C# was directly inspired by Java, and largely came into existence because Microsoft wanted Microsoft Java to be a thing but there were far too many legal problems.

Unity3D leans heavily on C#, and most Unity games I've encountered typically have abysmal performance.

Hard to say if I've encountered C# in other places in the wild, got any suggestions?

So tell me more about your experience of poor performance and excessive memory use?

Azureus, JBidWatcher, Minecraft come to mind - admittedly not much, but I've only been online for two and a half decades and sometimes it's hard to remember random product names from that long ago.

I always remember having to close everything else before running something that used Java though…

90s meme, or is it your actual experience?

You underestimate how long I've been online, I started with powwow before I found IRC and ICQ took over…

I've been around long enough to have created some of your '90s memes :P

I guess your next argument is 'but Java is way better now!', and all I can offer is "probably, but no-one cares" - did your university offer it as the ultimate language?
These days, literally the only folk I know who 'like' Java are folks with CS degrees who haven't managed to branch out yet due to overly rigid thinking.

7

u/spoonman59 Aug 09 '22

I’m probably as old as you. I used Java 1.1 back in the late 90s, when it TRULY sucked.

Back then, the memory overhead for GC was a much more significant chunk of available resources. And the compilers weren’t so great, particularly the “client” compiler.

Also people still thought Applets was a thing, which was weird.

I used other languages professionally at the time, and used C# and Java at the same time from 2011 to 2015 for a high frequency trading company. We were doing the distributed real time event processing in C#, and the batch work in Hadoop using Java. So, I had a good bit of experience performance profiling, optimizing, and debugging both platforms at the time.

To be honest I like both languages and platforms. Java is an it more cross platform, but cough Oracle. C# has some very nice language and platform advantages over Java. I also hate MS way less than Oracle.

I didn’t bring up Python as a strawman. It’s quite simply that opinions about about memory usage or performance are all relative. Relative to the same program in rust, C, or C++, Java would look absolutely lousy on memory and start up time.

But relative to dynamic languages it’s usually much better. I was just trying to understand where you were coming from is all.

Also, the reference to 90s memes was not intended to be rude at all. I was programming then as well. I was just trying to understand if you were sharing your perspective for what it was known for based on that time, or if you had some recent experience to inform that opinion.

Indeed I very much remember the Visual J++ incident you mentioned, which was Anders Hejlsberg first language at Microsoft. And indeed they were sued by Sun badly! But you can see some C# stuff in there, like multicast delegates. Your history is pretty spot on. Anders moved immediately to C#, codenamed COOL ( c like object oriented language). He was responsible for Visual J++!

I actually used Delphi as well. This was a Borland language derived from pascal. True facts, Anders Hejlsberg wrote that compiler when he worked at Borland before Microsoft. So I’m a fan of his work!

Thanks for replying. That was informative! And now I understand the context of your perspective a little more.

-19

u/[deleted] Aug 09 '22

lol still no real generics or value types in 2022.

How anyone can continue to put up with that fucking disgusting language is beyond me.

4

u/[deleted] Aug 14 '22

Hey, it's the C# is the best language and everything else is trash dude. How you keeping?

-23

u/CevicheCabbage Aug 09 '22

Java is antiquated technology.

Everything Java can do, Python and JavaScript will do better.

12

u/[deleted] Aug 09 '22

No. just... NO.

-13

u/CevicheCabbage Aug 09 '22

In the words of Douglas Crockford: "Do you even JavaScript bro?"

8

u/CorrectProgrammer Aug 09 '22

Maybe one day, but until proper support for parallel execution is added to Python and JavaScript, Java won't be replaced by them.

-17

u/CevicheCabbage Aug 09 '22

My statement did not declare Java would be replaced whatsoever.

JavaScript in the hands of someone as knowledgeable as Douglas Crockford is superior to every programming language available to us right now and capable of replacing them all.

Java is presently a systemic plague on technology which exists because bad developers and uninformed financing exists.

9

u/sureshg Aug 09 '22

as Douglas Crockford is superior to every programming language

lol :) .... JS and Python (dynamic languages) suck for anything more than small scripts. Ecosystem and dependency management are also PITA. There is a reason why java is selected for data platforms and database servers. JVM can also run languages like Clojure, Scala and Kotlin with full interop.

1

u/[deleted] Aug 14 '22

Didn't Crockford recently say it's time to move on from JavaScript?

https://evrone.com/douglas-crockford-interview

The best thing we can do today to JavaScript is to retire it. Twenty years ago, I was one of the few advocates for JavaScript. Its cobbling together of nested functions and dynamic objects was brilliant. I spent a decade trying to correct its flaws. I had a minor success with ES5. But since then, there has been strong interest in further bloating the language instead of making it better. So JavaScript, like the other dinosaur languages, has become a barrier to progress. We should be focused on the next language, which should look more like E than like JavaScript.

1

u/CevicheCabbage Aug 14 '22

Crockford has advocated for "the next language" for the entire past decade.

That next language is already here in the form of "The Good Parts" of JavaScript.

https://www.amazon.com/JavaScript-Good-Parts-Douglas-Crockford/dp/0596517742

1

u/[deleted] Aug 15 '22

Yeah, I know. That doesn't stop anyone from using the 'bad parts'.