Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Does Android C has better performance comparing to Java? [closed]

Tags:

java

c

android

jvm

On Android NDK website you can read:

The Android NDK is a companion tool to the Android SDK that lets you build performance-critical portions of your apps in native code.

...

If you write native code, your applications are still packaged into an .apk file and they still run inside of a virtual machine on the device

...

Using native code does not result in an automatic performance increase, but always increases application complexity.

How then can you gain on performance using C and NDK, if C is also compiled to VM code? You can bypass API, or C compiles to more optimal code, or what?

Or it is only "development speedup", so if you have some C code you dont have to port it to Java?

Edit:

I do not ask if "Java is slower than C". My consideration is, if C is compiled with gcc, then how the portability is solved (but this is a second question, in the background)

What are the portability implications of using the NDK?

like image 441
Jakub M. Avatar asked May 13 '26 20:05

Jakub M.


1 Answers

The C code that the NDK allows you to add to your app is not compiled into VM code. It is compiled using gcc and links as a shared library that can be loaded and linked via JNI to Java. Therefore, you can gain performance by writing in C instead of relying on JVM optimization when writing Java code.

like image 124
Dan Aloni Avatar answered May 15 '26 09:05

Dan Aloni