C is usually a compiled language, i.e., a compiler translates it into the native machine code of a specific target platform, so that platform's hardware processor can interpret it directly, yielding a considerable speed advantage. Java is also compiled, but its target platform is a virtual machine, the JVM, and it must be interpreted by an emulation of that machine, which itself will be a native machine-code program running on the physical processor.
One would therefore expect Java programs to be slower than C programs, and that was probably true when Java first appeared. However, modern JVMs take several steps to improve execution speed:
-
Java bytecode can be converted to native code by the JVM. Not all code is converted, but the JVM will try to identify the most used pieces of code.
-
The JVM can also in-line methods dynamically.
-
The JVM can be careful about loading only parts of the (rather large) standard library that are actually used.
These optimizations are less effective on short-lived programs, because they must be repeated anew for each execution, but a big advantage of applying run-time optimizations is that existing compiled Java programs can take advantage of them without having to be recompiled.
So, is C still faster than Java? It depends so much on things like program longevity and the type of activity, that there's no simple answer, and you will choose a language based on other needs.