Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Android: Java, C or C++?

Tags:

java

c++

c

android

I wrote some simple apps in Android using Java.
But later I found this:

It provides headers and libraries that allow you to build activities, handle user input, use hardware sensors, access application resources, and more, when programming in C or C++. (Source)

How is it related to this:

Android applications are written in the Java programming language. (Source)

Are all three languages possible?
Sorry for the dumb question.

like image 885
Evgenij Reznik Avatar asked Jan 17 '12 20:01

Evgenij Reznik


People also ask

Is Android written in Java or C?

The official language for Android development is Java. Large parts of Android are written in Java and its APIs are designed to be called primarily from Java. It is possible to develop C and C++ app using the Android Native Development Kit (NDK), however it isn't something that Google promotes.

Is C used in Android?

The Android Native Development Kit (NDK): a toolset that allows you to use C and C++ code with Android, and provides platform libraries that allow you to manage native activities and access physical device components, such as sensors and touch input.

Should I use Java or C?

C is a procedural, low level, and compiled language. Java is an object-oriented, high level, and interpreted language. Java uses objects, while C uses functions. Java is easier to learn and use because it's high level, while C can do more and perform faster because it's closer to machine code.

Is C faster or Java?

C is normally faster than Java, if it is written efficiently, but it always depends on the compiler. Some compilers support optimization on the compile time, to produce more efficient code, by removing redundant code and other unnecessary artefacts.


2 Answers

The article you link to has good information. It also links to http://developer.android.com/sdk/ndk/overview.html which says:

The NDK will not benefit most applications. As a developer, you need to balance its benefits against its drawbacks; notably, using native code does not result in an automatic performance increase, but always increases application complexity. In general, you should only use native code if it is essential to your application, not just because you prefer to program in C/C++.

Typical good candidates for the NDK are self-contained, CPU-intensive operations that don't allocate much memory, such as signal processing, physics simulation, and so on. Simply re-coding a method to run in C usually does not result in a large performance increase. When examining whether or not you should develop in native code, think about your requirements and see if the Android framework APIs provide the functionality that you need. The NDK can, however, can be an effective way to reuse a large corpus of existing C/C++ code.

like image 97
Michael Levy Avatar answered Sep 24 '22 23:09

Michael Levy


Android is Linux underneath so you can run any language on it. I have run Perl scripts on an Android phone for fun. From a practical, application development point-of-view, Google's implementation of Java running on Dalvik would be the typical route to take.

like image 20
Rob Kielty Avatar answered Sep 24 '22 23:09

Rob Kielty