47

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?

13
  • 30
    Minor point, Android wasn't started by Google. Google bought Android including its use of Java.
    – user28988
    Mar 21, 2012 at 13:43
  • 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, 2012 at 14:17
  • 16
    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!
    – user7519
    Mar 21, 2012 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, 2012 at 15:04
  • 5
    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, 2012 at 15:58

3 Answers 3

40

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

4
  • 1
    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). - stackoverflow.com/questions/5605575/…
    – Shauna
    Mar 21, 2012 at 13:32
  • 1
    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, 2012 at 13:40
  • 2
    Given how many Android devices the market has splintered into, it'd be nearly impossible to deal with otherwise.
    – user28988
    Mar 21, 2012 at 13:42
  • 3
    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, 2012 at 13:52
19

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.

7
  • 3
    I like your idea about the app development. I've never thought of that before, but it makes sense. +1
    – Russell
    Mar 21, 2012 at 13:40
  • 6
    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, 2012 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! Mar 21, 2012 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... Apr 7, 2012 at 5:13
  • @Jeffrey, Why do you say that Android supports JavaScript?
    – Pacerier
    Nov 20, 2014 at 10:45
9

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.

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