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

18

u/static_context Nov 03 '20

There are going to be a lot of people who can explain this better than me but...

Java is compiled to bytecode, which is interpreted by the virtual machine. It can be interpreted pretty damp fast, but it still needs to be converted from bytecode to machine code. I think this is called Just-In-Time compilation and is performed at run-time as the program executes.

C is compiled directly to machine code. So there are no additional runtime steps needed that might slow execution.

I think :).