r/learnjava • • 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

26 comments sorted by

View all comments

Show parent comments

7

u/IIwarrierII Nov 03 '20

But once java is compiled isn’t it fast ?

79

u/gtrley Nov 03 '20

Whoops thought i replied but made a whole new thread

Edit: pasted response below :)

Faster than python since you're running a pre-compiled program vs interpreted as you go, but C is going to be compiled specifically for the platform you run it on, where Java is more half-compiled, then the JVM does final translations to the platform

This is why Java is "write once run anywhere" and C is not. I.e. if i wanted to run a C program on say, a linux machine, then later decide I want to run it on windows, I would need to recompile it, where with Java I compile a .class file and I can run that on any system with a JVM

25

u/IIwarrierII Nov 03 '20

Thanks a lot I learnt a lot from you

11

u/gtrley Nov 03 '20

Happy to help! Im sure someone out there can go into much more granular detail than what I can provide lol, but that is my understanding of it :)