50

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?

cgamrath
  • 1,951

3 Answers3

43

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

20

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.

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.

maple_shaft
  • 26,570