Why was Java chosen for Android, instead of something like C++? I have heard that Java uses quite a lot of memory and I would presume that low memory usage would be quite important on mobile devices. Is there any real advantage to using Java instead of a language like C++ on a mobile device?
-
@Paul: I'm sorry you feel that way. My post was not meant to promote C++, I just used C++ as an example. I just wanted to know what the advantage of using Java for a cellphone OS was. I was not saying that Java is a horrible language and that Google shuld have picked language X or Y instead. – cgt Mar 21 '12 at 13:38
-
30Minor point, Android wasn't started by Google. Google bought Android including its use of Java. – Mar 21 '12 at 13:43
-
1@Paul I like Thomas's edit, it is much more neutral now and a better question. He beat me to the edit, but I liked his better anyway. – maple_shaft Mar 21 '12 at 13:44
-
1@WorldEngineer quite relevant point indeed: given the massive **python** and **C++** assets Google had back then, using one of those for the main API would have proved more sensible, if starting from scratch. (let's not forget that for example, Nokia, before being *MS commissioned* was pushing for **Qt+Python**, so there was some potential there) – ZJR Mar 21 '12 at 13:51
-
1The answers are great. There aren't any "Java Sucks" answers... – Paul Mar 21 '12 at 13:59
-
2@ZJR: the main languages in use at Google have always been Java, Python and C++. Java was always there even before Android. – UncleZeiv Mar 21 '12 at 14:17
-
16Android uses the Java **Language** and **NOT** the Java Virtual Machine, there is a **big difference**, it even uses its own byte code format. This question is flawed in its intent and is not constructive either way! – Mar 21 '12 at 15:00
-
8@JarrodRoberson I think it is constructive as long as it doesn't devolve into a flamewar, BUT the community speaks... – maple_shaft Mar 21 '12 at 15:04
-
5I'm reopening based on [a Meta discussion about questions of historical importance](http://meta.programmers.stackexchange.com/a/3348/4). Questions about the history of software development and relevant topics are on-topic here and add value. Given the wording of this question and its answers, I think this question is a good fit for this community. – Thomas Owens Mar 22 '12 at 15:58
-
1Because they couldn't pick C# for political reasons. – Den Jun 20 '14 at 11:36
-
@JarrodRoberson when you say it uses the language and not the java virtual machine, that suggests somewhat that it doesn't use any virtual machine, but it does use Dalvik, a virtual machine(apparently java byte code goes to dalvik byte code). And dalvik was apparently written in C++. – barlop Jul 25 '14 at 07:27
-
@barlop - read my comment for comprehension, I specifically state that it uses it own byte code format. – Jul 25 '14 at 15:11
-
Also, Java's cross-platform capabilities probably make it easier for Google's developer tools to run apps on device simulators, since Google can leverage Oracle's JVM to translate Android-specific code to whatever the equivalent is on the computer. – moonman239 May 04 '18 at 01:26
3 Answers
This article sheds some light on the situation. The most pertinent link within that article is this. So you've got a massive install base with lots of programmers who know the language and it's widely taught at universities. C++ was dropped from my school's curriculum, Java is still here. Java has Java ME which has a massive install base on other cellphones. The Pantec Ease I have in my pocket right now has a little coffee cup in the corner of the screen. Anyone care to guess what that is?
This answer on Stack Overflow covers it pretty well too.
Summary of SO answer:
java is a known language, developers know it and don't have to learn it
its harder to shoot yourself with java than with c, c++ code since it has no pointer arithmetic
it runs in a vm, so no need to recompile it for every phone out there and easy to secure
large number of developement tools for java (see first)
several mobile phones already used java me, so java was known in the industry
the speed difference is not an issue for most applications, if it were you should code in assembly
-
1Ah, you beat me to it, so I'll just add to your list. I found this other SO question that adds another reason why Java was chosen (it's a managed language). - http://stackoverflow.com/questions/5605575/why-android-used-java-concept-instead-of-d-language-or-c-or-c-but-chromium-we – Shauna Mar 21 '12 at 13:32
-
1Thanks, this answered my question. Not having to recompile for every different Android running device actually seems like a huge pro for picking Java. I don't know why I didn't think of that. Thanks! – cgt Mar 21 '12 at 13:40
-
2Given how many Android devices the market has splintered into, it'd be nearly impossible to deal with otherwise. – Mar 21 '12 at 13:42
-
3This is correct, but they could have chosen any language. They could've written a new one even; they built the VM. Java does have the advantage of a clearly defined VM spec though. – Michael K Mar 21 '12 at 13:52
I'll hazard a guess that Google choose Java for familiarity, if nothing else. Many of Google's projects revolve at least concepts of Java schematics (GWT for example).
In addition, it's a language widely taught in technical schools (unlike say, Javascript (which Android also zealously supports)). Java's certainly not the best language for a mobile device in terms of performance and production, but it is well known.
Also remember that Android came in a little late to the party. Forcing developers to use C++, a low-level compiling language, would make it harder to generate a 'wow' factor, and if nothing else, Android needed numbers (of apps) and flashiness to get off the ground.

- 898
- 6
- 12
-
3I like your idea about the app development. I've never thought of that before, but it makes sense. +1 – Russell Mar 21 '12 at 13:40
-
6I think the aversion to C++ over Java in this case has less to do with flashiness and wow factor, and more to do with the ability for developers to more quickly and easily write apps for the marketplace. At the time when the specification was written, the common knowledge was that the success of the iPhone correlated with how successful Apple was at making app development attractive for developers. C++ would have been a little too difficult for most developers to swallow, so the minimal performance loss of Java was well worth it. – maple_shaft Mar 21 '12 at 13:42
-
9@maple_shaft: really?? it always seemed to me that the success of the iPhone was in spite of how UNattractive app development was, not due to how attractive it was! – Carson63000 Mar 21 '12 at 22:43
-
3@maple_shaft: Gotta agree with Carson here. iOS development is a nightmare. There's a reason nobody outside the Apple ecosystem is using Objective-C, and that's before you even touch on Apple's downright evil terms for when it comes to actually trying to deploy the app you created... – Mason Wheeler Apr 07 '12 at 05:13
-
-
@Pacerier Google is one of the biggest supporters of advancing web standards, web programming, and Javascript. The Android browser's JS support is evidence of this. However, colleges usually don't teach much about Javascript, apart from maybe educating students about the drop-down code Dreamweaver generates. – Jeffrey Sweeney Nov 21 '14 at 15:56
-
@JeffreySweeney I think you exaggerate JS support in Android. Until they switched to Chromium in Android 4.4, the WebView was relatively basic and also had [really serious issues](https://code.google.com/p/android/issues/detail?id=12987) in some versions. And web applications are, of course, still not first-class citizens. So I don't know where you see this zealous support. JS support has become fine in the last years, but that's about it. – Malcolm Dec 06 '16 at 14:59
Not sure why exactly Java was chosen but it was probably for a number of reasons
To capture the large group of developers who are familiar with and use Java
Fill the mobile gap in Java where technologies like J2ME where Java is lacking.
Secondly, there is not Java Virtual Machine specified for Android. Instead all Java code is compiled for running on Dalvik, which is a lightweight, optimized VM specifically designed for running in mobile environments. It purportedly enhances battery life and maximizes efficient use of resources.

- 26,401
- 11
- 57
- 131