r/learnjava • u/IIwarrierII • Nov 03 '20
Why is c faster than java?
If I were to make the same thing in java would it now be as fast ?
58
Upvotes
r/learnjava • u/IIwarrierII • Nov 03 '20
If I were to make the same thing in java would it now be as fast ?
2
u/llc_Cl Nov 04 '20 edited Nov 04 '20
Some might argue that Java is faster than C in some cases, because often times you can write the program so much faster. Let the processors do the rest - they’re fast enough.
But to understand why c is faster, I think you need to do some hardware programming. At least I did.
Maybe an analogy will work, because I don’t think I can explain it without one. It’s like in C you have more ability to customize how your programs interact with the specific hardware you’re running it on. Whereas Java just ‘translates’ or interprets the code for the given hardware.
Like if instead we substitute code with clothes, and speed with how those clothes fit. You’re going to get much better fitting clothes if they’re custom made, rather than getting some generic clothes that are ‘interpreted’ to fit you - like clothes from target or Walmart, say. Those clothes might be the right size, and work just fine. But if you needed clothes to reduce drag, like for a bicycle race, you would want a bicycle suit. I don’t think you can get a bicycle suit at Walmart or target. Even if you could, it probably wouldn’t fit well, defeating the purpose of trying to reduce drag. So, you probably wouldn’t buy that suit at a normal store, you would probably get it custom made.
Made a bunch of edits; sorry, writing on a cellphone.