Why does Android use Java? [closed]

Solution 1:

Some points:

  1. Java is a known language, developers know it and don't have to learn it

  2. it's harder to shoot yourself with Java than with C/C++ code since it has no pointer arithmetic

  3. it runs in a VM, so no need to recompile it for every phone out there and easy to secure

  4. large number of development tools for Java (see point 1)

  5. several mobile phones already used Java ME, so Java was known in the industry

  6. the speed difference is not an issue for most applications; if it was you should code in low-level language

Solution 2:

On the byte-code level, Android doesn't use Java. The source is Java, but it doesn't use a JVM.

Solution 3:

The improvement to system stability is very important on a device like a cell phone.

Security is even more important. The Android environment lets users run semi-trusted apps which could exploit the phone in truly unpleasant ways without excellent security. By running all apps in a virtual machine, you guarantee that no app can exploit the OS kernel unless there is a flaw in the VM implementation. The VM implementation, in turn, is presumably small and has a small, well-defined security surface.

Perhaps most important, when programs are compiled to code for a virtual machine, they do not have to be recompiled for new hardware. The market for phone chips is diverse and rapidly-changing, so that's a big deal.

Also, using Java makes it less likely that the apps people write will be exploitable themselves. No buffer-overruns, mistakes with pointers, etc...

Solution 4:

Native code is not necessarily any faster than Java code. Where is your profile data showing that native code could run faster?

Why Java?

  • Android runs on many different hardware platforms. You would need to compile and optimize your native code for each of these different platforms to see any real benefits.

  • There are a large number of developers already proficient in Java.

  • Java has huge open source support, with many libraries and tools available to make developers life easier.

  • Java protects you from many of the problems inherent in native code, like memory leaks, bad pointer usage, etc.

  • Java allows them to create sandbox applications, and create a better security model so that one bad App can't take down your entire OS.

Solution 5:

First of all, according to Google, Android doesn't use Java. That's why Oracle is suing Google. Oracle claims that Android infringes on some Java technology, but Google says it's Dalvik.

Secondly, I haven't seen a Java byte code interpreter since 1995.

Can you back up your performance conjecture with some actual benchmarks? The scope of your presumptions don't seem justified given the inaccurate background information you provide.