Programmers Stack Exchange is a question and answer site for professional programmers interested in conceptual questions about software development. It's 100% free.

Sign up
Here's how it works:
  1. Anybody can ask a question
  2. Anybody can answer
  3. The best answers are voted up and rise to the top

Why was Java chosen for Android, instead of something like C++? While I certainly am no expert, 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?

share|improve this question
Minor point, Android wasn't started by Google. Google bought Android including its use of Java. – World Engineer Mar 21 '12 at 13:43
@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
Android 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! – Jarrod Roberson Mar 21 '12 at 15:00
@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
I'm reopening based on a Meta discussion about questions of historical importance. 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
up vote 35 down vote accepted

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

share|improve this answer
Ah, 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). -… – Shauna Mar 21 '12 at 13:32
Thanks, 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
Given how many Android devices the market has splintered into, it'd be nearly impossible to deal with otherwise. – World Engineer Mar 21 '12 at 13:42
This 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.

share|improve this answer
I 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
I 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
@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
@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 7 '12 at 5:13
@Jeffrey, Why do you say that Android supports JavaScript? – Pacerier Nov 20 '14 at 10:45

Not sure why exactly Java was chosen but it was probably for a number of reasons

  1. To capture the large group of developers who are familiar with and use Java

  2. 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.

share|improve this answer

protected by gnat Jun 26 '14 at 6:37

Thank you for your interest in this question. Because it has attracted low-quality or spam answers that had to be removed, posting an answer now requires 10 reputation on this site.

Would you like to answer one of these unanswered questions instead?

Not the answer you're looking for? Browse other questions tagged or ask your own question.