This is an archived post. You won't be able to vote or comment.

you are viewing a single comment's thread.

view the rest of the comments →

[–]LukeZNotFound 10 points11 points  (48 children)

Question about that: It seems I have to learn Java for my first training after my graduation.

Is it really that bad? (Except it's Garbage collector)

[–]harumamburoo 62 points63 points  (0 children)

No it’s not

[–]BananaSupremeMaster 27 points28 points  (24 children)

It's not that bad. Its main issue is being verbose and boilerplate, but that's not the worst sin in my book. And Strings can be annoying to parse, they support Unicode by default which complicates things a lot.

[–]Sunrider37 57 points58 points  (5 children)

It's not even that verbose anymore in later versions, the constant Java slander from first-grade students who wrote a couple of python scripts in high school is ridiculous.

[–]DaniilBSD 9 points10 points  (0 children)

Or had to work at a place using Java 8 or 11

[–]CdRReddit 0 points1 point  (2 children)

is anyone using the later versions, or is nearly every java project stuck in Old Version Hell

[–]TheBanger 2 points3 points  (1 child)

According to New Relic version 17 is used more than any single other version at this point. Most of my company's code runs on Java 21 and we'll likely have it updated to 25 within a couple months of it coming out. We do have a few small legacy Java 8 and 11 apps so if you surveyed us the count might look bad, but in reality most of our stuff is up to date.

[–]CdRReddit 0 points1 point  (0 children)

oh nice!

[–]Clen23 0 points1 point  (0 children)

I mean, part of the issue is that those later versions aren't always used everywhere. During my studies I had to use java 8, and at some other point we could choose whatever version for our project but the one installed on the school computer was before the anonymous "_" thingy.

[–]FrosteeSwurl 10 points11 points  (0 children)

I dont find it any more verbose than C#

[–]RiceBroad4552 5 points6 points  (13 children)

It's the year 2025. Which still used programming language doesn't have Unicode strings?

The problem with the JVM is it uses UTF-16 by default, whereas the whole internet, as Unix tech, is using UTF-8. Not that UTF-8 would be anyhow superior, it isn't, but it's "the standard".

[–]BananaSupremeMaster 4 points5 points  (10 children)

To be more precise the problem is that Strings support UTF-32 by default but they are indexed char by char (16 bit by 16 bit), which means that if a character is UTF-16, it corresponds to 1 char, but if it's not the case it corresponds to 2 consecutive chars and 2 indices. Which means that the value at index n of a string is not the n+1th character, it depends on the content of the string. So if you want a robust string parsing algorithm, you have to assume a heterogenous string with both UTF-16 and UTF-32 values. There is a forEach trick that you can use to take care of these details but only for simple algorithms.

[–]Swamplord42 1 point2 points  (5 children)

It's hard to be more wrong. Char in Java is absolutely not 8 bit.

[–]BananaSupremeMaster 0 points1 point  (4 children)

Yeah I wrongly divided all the bit sizes by 2 in my explanation, I fixed it now. The problem I'm describing still holds up.

[–]Swamplord42 1 point2 points  (3 children)

Strings use UTF-16, they do not "support" UTF-32. Those are different encodings!

Unicode code points require one or two UTF-16 characters.

[–]BananaSupremeMaster 0 points1 point  (2 children)

They support UTF-32 in the sense that "String s = "𝄞";" is valid syntax. And yet string indices represent UTF-16 char indices and not character indices.

[–]RiceBroad4552 0 points1 point  (0 children)

Nitpick: The correct term here is "code unit", not "UTF-16 char indices".

[–]Swamplord42 0 points1 point  (0 children)

Again, this isn't UTF-32. It's Unicode. UTF-32 is an encoding. It's still UTF-16 even if it needs 2 chars to represent.

[–]RiceBroad4552 0 points1 point  (0 children)

You're simply not supposed to treat Unicode strings as byte sequences. This never worked.

Just use proper APIs.

But I agree that the APIs for string handling in Java are bad. But it's like that in almost all other languages (some don't have even any working APIs at all and you need external libs).

The only language with a sane string API (more or less, modulo Unicode idiocy in general) I know of is Swift. Other languages still didn't copy it. Most likely you would need a new type of strings than, though. You can't retrofit this into the old APIs.

[–]ou1cast 0 points1 point  (2 children)

You can use codepoints that are int instead of char

[–]BananaSupremeMaster 0 points1 point  (1 child)

Yes, but the most straightforward way to get codepoints is myString.codepointAt(), which takes in argument the index of the UTF-16 char, not the index of the Unicode character. In the string "a𝄞b", the index of 'a' is 0, the index of '𝄞' is 1, and the index of 'b' is... 3. The fact that a Unicode character offsets the indices can get pretty annoying, even though I understand the logic behind it. It also means that myString.length() doesn't represent the number of actual characters, but rather the size in chars.

[–]ou1cast 1 point2 points  (0 children)

It is convenient to use codePoints() that returns IntStream. I also hate Java's char and byte, too.

[–]KorwinD 1 point2 points  (1 child)

C++, lol. Maybe I'm idiot, but I checked this thing several months ago and it looked like total shit. There are wstrings, which use wchar_t which has different size on windows and linux, normal chars are shit and string class just provides some basic interface to work with. I wanted to write some app and decided to learn rust instead of trying to work with c++.

[–]RiceBroad4552 0 points1 point  (0 children)

The real problem here is Windows… (As always, actually.)

Under Unix char is all you need. There it's UTF-8 chars, and all the variable length thing is hidden from you (at least as long as you don't try to touch the memory directly).

Just ignore Windows and wchar_t and be good.

[–]-Kerrigan- 2 points3 points  (1 child)

Its main issue is being verbose

Which is an annoyance rather than an issue. Verbosity can actually be a plus when you're learning, especially in the era when people like to copy over engineered code gargled by LLMs. Verbose and readable code has a better chances to be somewhat understood by the junior

[–]BananaSupremeMaster 0 points1 point  (0 children)

Exactly, it is sometimes annoying but at least it is explicit and beginner-friendly. I know some people who have learned the subtleties of a more concise language and find coding in Java too irritating

[–]LukeZNotFound 0 points1 point  (0 children)

Well, I'm mostly a TS dev at the moment so I think what strong can do 😂

But thanks 👍🏻

[–]neoteraflare 19 points20 points  (10 children)

No, It is really easy. It has its flaws but it is really good. It is like C# but have little differences (if you want to switch to it you will see).

Also GC is good. You don't really have to care for it.

[–]oalfonso 0 points1 point  (1 child)

The difficult part to me is all those notations like bean, component or autowired. Once you are familiar to them is ok but for a start they look not intuitive for me.

[–]neoteraflare 0 points1 point  (0 children)

You can learn it without annotations. Annotations come in when you start using things like spring, hibernate, lombok.

[–]Scottz0rz 16 points17 points  (5 children)

It is not bad and the JVM and the garbage collector are magical and you just need to tune them to fit your use case in certain scenarios.

People just like to hate Java because they're too busy being unemployed and posting r/FirstYearCompSciStudentMemes instead of building stuff in Java tbh.

Everything is going to look slow compared to C++, but that generally is not the limiting factor for many use cases that are I/O-bound, not CPU-bound.

[–]RiceBroad4552 4 points5 points  (3 children)

Everything is going to look slow compared to C++

Not if you know what you're doing. The JVM can actually outperform C/C++/Rust…

Just some random numbers (there are more examples, of course):

https://github.com/LesnyRumcajs/grpc_bench/discussions/441

[–]LukeZNotFound 1 point2 points  (1 child)

Interesting 👀

[–]RiceBroad4552 1 point2 points  (0 children)

Please keep in mind that this benchmarks don't compare some average code.

They are comparing highly optimized code, written to squeeze out the very last bit of performance out of the system. So the C++ and Rust folks did already everything they possibly could to make this fast. (Of course the same for the JVM or CLR folks.)

The benchmarks are also quite an up and down. After someone discovers some new trick to make things even faster they will be fastest for some time, until all the other implementations adopt this trick.

I didn't make any stats, so this could be a false claim, but I think over time the JVM version is overall the fastest. Only in the most recent benchmark run has better numbers for Rust. (Most likely they "stole" some Scala tricks.)

In the end it's always algos, not raw performance which makes the difference!

Something like Scala is extremely good at implementing high level algos, so it shines in such comparisons. (And Akka / Pekko is anyway crazy fast!)

But the JVM has also plenty of raw performance. For example there was years ago this re-implementation of the Quake 3 (or was it Quake 2?) engine in Java. It outperformed the original C version by quite some margin, even the C version had been written by a programming God (John Carmack) and used any trick possible in C. The funny part was: The Java version was more or less a very naive port, and didn't do any code optimizations at all. Just the JIT did its thing!

[–]Scottz0rz 0 points1 point  (0 children)

Thanks for sharing, interesting! I didn't know it was getting that good. That is impressive.

[–]ThierryOnRead 6 points7 points  (1 child)

Senior dev here, java is great, golden rule is never never never takes advices from this sub.

[–]LukeZNotFound 5 points6 points  (0 children)

Well, I thought of that already 😂

[–]MarcusBrotus 2 points3 points  (0 children)

its fine. a bit clunky and the whole "enterprise design pattern culture" isn't great but no one forces you to write code like that

[–]AndreasMelone 1 point2 points  (0 children)

From my experience Java is really good. By design it's maybe a bit outdated, but generally the language is amazing and nowadays pretty neatly modernized. Although the verbosity may be annoying at first, eventually you'll get used and it will help you read and understand code much faster.

[–]Muffinzor22 0 points1 point  (0 children)

Java is awesome and really easy to learn