Here are a few reasons why Google chose Java for its Android operating system

Google hit a bullseye with smartphone users when it brought out the first version Android operating system. At that time when Nokia and its proprietary Symbian operating system, ruled the roost in smartphone market, Google brought out the first version of Android in 2007. Today Android smartphones rule the world with over 85 percent of the smartphones in the world running on various versions of Android operating system.
Android’s source code is released by Google under open source licenses, although most Android devices ultimately ship with a combination of open source and proprietary software, including proprietary software required for accessing Google services.

Android

Android is based on the Linux kernel and designed primarily for touchscreen mobile devices such as smartphones and tablets. Android’s user interface is mainly based on direct manipulation, using touch gestures that loosely correspond to real-world actions, such as swiping, tapping and pinching, to manipulate on-screen objects, along with a virtual keyboard for text input.
The Android Apps and games, which are so popular among smartphone users are compiled by developers using the Android software development kit (SDK). This Android SDK is compiled using Java programming language. So, why Java?

So why did Google choose Java over other programming languages

The basic advantages of having Java programming language for Android SDKs is given below :
  1. Java is a known language, developers know it and don’t have to learn it. Java has yet again emerged as the world’s most popular programming language. Also there are lots of engineers who specialise in Java making it easier for them to compile Apps and Games.
  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 Java is easy to secure. This is Java’s very important feature. Running on a VM (thus no recompiling) is a huge plus. Also, it easily separates processes from each other, preventing a rogue application from destroying your phone or interfering with other applications. Every App has assigned its own address. All addresses are translated by MMU. This provides base level security to the App and the Android ecosystem by preventing leakages.
  4. As said in point number 1 above, since Java is the most popular programming language, a large number of development tools are available for developers. Java has huge open source support, with many libraries and tools are available to make developers life easier.
  5. Several mobile phones already used Java ME, so Java was known in the mobile industry and the engineers.
  6. The speed difference is not an issue for most applications; if it was you should code in low-level language
  7. Also Android as a operating system runs on many different hardware platforms including smart TVs, Android wear etc. Given that almost all VMs JIT compile down to native code, raw code speed is often comparable with native speed. A lot of delays attributed to higher-level languages are less to do with the VM overhead than other factors (a complex object runtime, ‘safety’ checking memory access by doing bounds checking, etc).
  8. Java allows developers to create sandbox applications, and create a better security model so that one bad App can’t take down your entire OS.
In addition to above points, at the time of development of first version of Android, the available languages like Go and Rust werent exactly popular and quite niche programming languages, so prioritising native languages would’ve meant the Android development team going with C or C++.
Go was used in the earlier versions of Android and found to have its limitations. Rust was smaller still, so betting Android’s whole OS’s development ecosystem on such a niche language would’ve been a bad idea.
Even the most diehard of programmers and coders will agree that C and C++ are notoriously difficult to work with, and even very senior engineers make dangerous mistakes very often. This is the reason, Microsoft chose to develop its on .NET architecture, however developing a separate language for Android would not have been feasible for Google at that time.
Also during the time the first Android version was being worked on, the JVM/CLR languages (i.e. the Java family and the C#/.NET family) were under ownership of Sun and Microsoft respectively. So it would not have been feasible for Google to use its ‘enemies’ programming language. Only after Oracle bought out Java and Google reached an understanding with Oracle that all proprietary issues were resolved.
Java is an absolutely massive ecosystem, and you have an embarrassing wealth of both libraries and tooling available for it, which mitigates how mediocre the language itself is. Where Apple had home field advantage by using Objective C in iOS (with Obj-C being the primary language for OS X development), Google’s choice of Java meant not having to build that ecosystem from scratch.
As seen above, Java was simply the best choice available at the time. Google has never officially commented on why it is using Java for Android SDKs but the above reasons are enough for Google and the Android team to back Java all the way.