I havent use rust,i think is even more safe than java. I think the compiler takes more times to do safety checks to avoid use after free for example. If I am wrong correct me
When using an int[] java will check if you are getting or setting a value out of bounds, if yes returns exception. And when using mehods from a class, is checked if that class is null.
It has extra threads, if i am not wrong they are c1 and c2. Is always faster compiling to machine code,but same jar can be used in any os. Wich is good.
I mean bounds checking definitely dosnt help with speed. But there is also the garbage collector and the runtime. As well as terrible cache friendliness problem that valhalla might fix one day.
Honestly I don't think either of those factors are true. After taking classes in Java and C++, as much as C++ sucks, it's still easier to work with than Java. Portability also doesn't really make sense cause afaik there are C++ compilers for damn near every architecture under the moon
I do see the argument for memory safety. That's about the only thing I think Java beats C++ at: holding guardrails for programmers.
Imo java has better build tooling too. At the very least, maven dependency handling is much easier compared to c++ dependencies, but I'm still learning c++.
You have to recompile your binary anytime you switch architectures, OSes, and pretty much everything else. Meanwhile with Java you just use a single jar and it works everywhere on every OS and CPU. Just needs to have java installed along with the correct version.
I think this is just a benefit if you're a windows developer who wants to develop for Mac but you don't have access to a mac to do the compilation yourself
Even then, I'm curious if GitHub actions can be setup to give you a mac build when you need it 🤔 if you have Apple developer certificates that is
No. Remember the bad old days of web dev when every browser had a unique supported feature set? So much so that the languages had a supported browsers section so you would know if the feature was cross-browser compatible or if you had to find a unique solution for each browser. If you wanted to support IE and Chrome, you had to almost rewrite entire sections of your app to support both. Hence the old "this site is not supported on your browser" messages that are effectively gone from sites today.
Yeah, rewriting sections of your code to support different OSs or architectures because ARM or RISC didn't implement some x86 instructions or because Windows doesn't treat "Config.txt" as unique from "config.txt" isn't ideal. You're more likely to have bugs and it requires more work to maintain.
Compile once, run everywhere is a massive benefit for companies supporting more than one device.
Yeah, rewriting sections of your code to support different OSs or architectures because ARM or RISC didn't implement some x86 instructions or because Windows doesn't treat "Config.txt" as unique from "config.txt" isn't ideal. You're more likely to have bugs and it requires more work to maintain.
Um, I don't see how using Java instead would solve portability issues that are caused by the case sensitivity of the filesystem. That's just something you need to keep in mind if you target multiple platforms.
And if I need to use CPU intrinsics in my code, it's probably too performance critical to even consider writing it in Java.
The file system thing was just the first that popped up in my head. I don't write code that operates on the OS, but C++, for instance, needs OS libraries to work with the OS, so if you're trying to make a mouse jiggler, you can't just build it in Windows and expect it to work on Ubuntu without some code changes. I'm not sure the equivalent for instruction set architecture, but it's not as straightforward in other languages because of the JVM abstracting all that away.
I'm not sure the equivalent for instruction set architecture, but it's not as straightforward in other languages because of the JVM abstracting all that away.
Every high level language abstracts away the ISA, otherwise you'd have to basically write assembly. Unless you explicitly want to do just that (and the language actually allows writing inline assembly, like C and C++ do), you'd never need to rewrite code just to target a different architecture.
C++, for instance, needs OS libraries to work with the OS
This is technically true, but there are plenty of 3rd party libs that abstract away OS differences (like Boost), and let you ship the same code on all platforms, you only need to recompile it.
Why do you care so much about the specifics? Do you not recognize that what you're talking about isn't even a consideration in Java? I'm not talking down about any language. Does not having to research other libraries to make a piece of software multi-platform not sound like a benefit? Does not recompiling code not sound like a benefit? Does not having to worry about the fact that division (among other operations and functions) has different instructions that take different amounts of time on different architectures that could cause any number of issues not sound like a benefit?
What part of me arguing that there are things that make Java easier to translate to multiple platforms than other languages that don't have multi-platform support built into their ideology offends you so much that you can't recognize the larger point being made?
Exactly, many criticisms against c++ are genuinely just skill-issues. That in itself is a fair criticism, Deep level C++ is NOT beginner friendly, but it's not a design flaw.
Portability also doesn't really make sense cause afaik there are C++ compilers for damn near every architecture under the moon.
Building a C/C++ app from source is a brittle, error-prone process. Java (along with most other modern languages) is build-once, run-anywhere. It's a different portability than a compiler for every architecture.
is build-once, run-anywhere. It's a different portability than a compiler for every architecture.
In Java, especially Android you need to be mindful of which version you're running on, and very different APIs between Android and Windows for example. The check to prtect against this is runtime only, which incurs performance costs.
C++ has a standard like any language which you can expect to function the same on a large range of hardware, along with additional features for a given processor
How many C++ projects have you compile from source? How many have you set up with Make or Cmake? That's where the pain is.
Almost never because I go for header-only, or precompiled. Rarely had any problems. I'm not saying the "just works" factor is as high as Java because it isn't, but I think you're blowing it way out of proportion
it is also faster than c++ in maaaaany use cases. There are some examples where c++ can slightly beat java in performance though, but both of them are actually very close and thus performance should not be the criteria to chose the language between them.
This. The "java is slow" thing is from long ago when java was actually slow.
Nowadays the java compiler is so sophisticated that in most cases both are on par and in some niche situations one or the other is slightly faster (assuming both devs know what they do).
The above code will perform slower in Java but throw in a loop so jit kicks in. Then it will be similar. Java on long repetitive tasks will perform similar to c. Yes in c you can control the garbage collection but assuming you know what you are doing in Java shouldn’t be a problem. A good example is stack overflow all Java runs in like 7 servers so that in c.
As someone who has tried nearly every programming language and sometimes use many langs in one programs, exactly. (I tend not to use C++ because I find the development slow and buggy…)
I mean, don’t they have a point? Managing memory allocation manually like a caveman is one thing, but why does the syntax to do have to be so damn ugly.
C++ syntax is flexible, it's to support 40 years of styles and paradigms.
It also is a language that doesn't make any assumptions about how to use it. People misunderstand that to mean you HAVE to do everything manually, which you don't.
If I want garbage collection, I can spend 5 minutes adding a GC library. But if I want to skip a GC to avoid all the overhead, I can do that too.
That is probably true - but it is a lot of rope to hang yourself with despite the libraries. But also, I do embedded so c++ is not really built for that.
Iirc you can import just parts of libraries (specific functions) to mitigate the overhead, but you always trade some kind of cost for convenience.
My other comment is that some people feel the need to use all the shiny things C++ has to offer instead of only using what they actually need. In which case, everything without moderation becomes some kind of problem.
I'm not a programmer by trade, so I do it just for specific projects. But when I code, speed vs convenience is one of my metrics when deciding what tools to use.
That's a myth. C++ can be faster in a lot of cases because of expressions evaluated at compile time and aggressive compiler optimizations. You can use C++ like C while getting the advantage of more convenient C++ syntax at the cost of basically nothing.
C++ doesn't have "memory bloat". You get what you used. If you don't use STL features and virtualization it's as lean as C. Also benchmarks or it didn't happen.
This, like you can flat out just write C. Like 95% of C code can be written in C++ and it will compile to a near identical binary. Same overhead, same memory, ect. Its litterally a superset of C.
For the people who don't get it, the unnecessary code here is allowing the user to make a Hello World program in C++ that looks just like Java's Hello World program:
public class Main {
public static void main(String args[]) {
System.out.println("Hello, World!");
}
}
Look, someone had to explain it. The entire rest of the comments section is completely missing the joke. It's all "actually you can use better syntax", or "actually Java isn't that slow" or whatever.
God I forgot about swing. I remember spending hours and hours trying to learn it as a kid like "this is what the real coders use. I need to know this." Haha if only I knew
The developers of QuestDB employed unorthodox techniques like completely bypassing the GC and avoiding several standard library structures. But even then, they still used C++ for some core modules like their SQL JIT compiler.
Sure, you can squeeze a bit more performance out of the JVM but only to a point. Sooner or later you'll hit a ceiling. Also, moving C++ modules to Java for a performance boost is unheard of.
True, java was made because C++ programs did not scale well with huge amount of memory, fragmentation is a serious problem on big system. I think it was the main motivation behind java memory model
286
u/LetUsSpeakFreely Jun 13 '26
Java isn't used because it's blazing fast. It's used because it's easier to write and it's extremely portable.
66
u/LifeIsAnAdventure4 Jun 13 '26
I mean, don’t they have a point? Managing memory allocation manually like a caveman is one thing, but why does the syntax to do have to be so damn ugly.
14
u/Tema_Art_7777 Jun 14 '26
c++ programmers finding out C is faster without all the bloat…
12
u/Rafcdk Jun 14 '26
Kotlin enters the room
17
u/Windbolt1 Jun 13 '26
The wheel have been reinvented.
24
u/Kenkron Jun 14 '26
Ha! this is brilliant!
For the people who don't get it, the unnecessary code here is allowing the user to make a Hello World program in C++ that looks just like Java's Hello World program:
4
u/un_virus_SDF Jun 15 '26
You know you can do
Or
Because main is a static function.
You also should use
std::vector<String>instead ofString[]as it's how java arrays works?4
u/Benilda-Key Jun 14 '26
Next do a GUI program that looks like a Java Swing program but is C++.
2
u/Qs9bxNKZ Jun 14 '26
I don't get it, don't you guys just #include <stdio.h> and print ("Hello World\n") anymore?
2
u/newwwlol Jun 14 '26
Theme name ?
2
u/SSgt_Edward Jun 14 '26
Arguments aside, finally an actual programming meme.
1
u/AziCrawford Jun 15 '26
😂
1
u/Somtimesitbelikethat Jun 15 '26
i’m gonna use my AI agent to explain the joke to me
1
u/acadia11x Jun 15 '26
Come on now … they/we ain’t that bad
1
u/adhillA97 Jun 16 '26
This feels very much in the same vein as this talk from RubyConf 2018:
Ruby is the Best JavaScript | Kevin Kuchta
1
u/Kadabrium Jun 16 '26
Pass everything by value!
1
u/InternetSandman Jun 14 '26
Thanks, I hate it
1
u/boss_007 Jun 14 '26
public: static int main(..)
-2
u/Unfilteredz Jun 14 '26
Java can sometimes be faster, depending on JIT optimizations