0% found this document useful (0 votes)
47 views

How Java and Android Work Together

Java code is compiled into bytecode, then translated by ART into machine code for fast execution on Android devices. ART also enhances memory management and lowers battery usage. Android is built on a modified Linux kernel and includes the Android API, which makes it easy to access device features through simple calls that hide complex underlying processes.
Copyright
© © All Rights Reserved
Available Formats
Download as PPTX, PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
47 views

How Java and Android Work Together

Java code is compiled into bytecode, then translated by ART into machine code for fast execution on Android devices. ART also enhances memory management and lowers battery usage. Android is built on a modified Linux kernel and includes the Android API, which makes it easy to access device features through simple calls that hide complex underlying processes.
Copyright
© © All Rights Reserved
Available Formats
Download as PPTX, PDF, TXT or read online on Scribd
You are on page 1/ 7

1

How Java and Android work together

After we write a program in Java for Android, we click a button and our code is transformed into another
form, the form that is understood by Android. This other form is called bytecode and the transformation
process is called compiling.

Then, when the user installs our application, the bytecode is translated by another process known as the
Android Runtime (ART) into machine code. This is the fastest possible execution format. So, if you
have ever heard people saying that you shouldn't use Java because it is slow, then you know they are
mistaken. Java is fast for the programmer to program and is then, upon installation, changed to machine
code that is fast for the device.
2
How Java and Android work together

Not only does ART enable super-fast execution of our apps, but it also lowers battery use. Furthermore,
the ART system doesn't just create the machine code and then sit back and relax; it provides hooks into
our application that enhance memory management while the application is running.

The ART itself is a software system written in another language that runs on a specially adapted version
of the Linux operating system. So, what the user sees of Android is itself just an app running on yet
another operating system.
3
How Java and Android work together

Android is a collection of sub-systems. The typical Android user doesn't see the Linux operating system
or know anything of the presence of ART but they are both there making things tick.

The purpose of the Linux part of the system is to hide the complexity and diversity of the hardware and
software that Android runs on, but at the same time exposing all its useful features. This exposing of
features works in two ways:

 First, the system itself must have access to the hardware, which it does.

 Second, this access must be programmer-friendly and easy to use – and this is
because of the Android API.
4
Understanding the Android API

The Android API is code that makes it easy to do exceptional things. A simple analogy could be drawn
with a machine, perhaps a car. When you press on the accelerator, a whole bunch of things happen
under the hood. We don't need to understand combustion or fuel pumps because some smart engineer
has made an interface for us – in this case, a mechanical interface: the accelerator pedal.
For example, the following line of Java code probably looks a little intimidating at this stage, but it
serves as a good example of how the Android API helps us:

locationManager.getLastKnownLocation(LocationManager.GPS_PROVIDER)
Once you learn that this single line of code searches for available satellites in space, and then
communicates with them in their orbits around the Earth, then retrieves your precise latitude and
longitude on the surface of the planet, it becomes easy to begin to glimpse the power and depth of the
Android API in conjunction with the compiled bytecode and ART.
5
Java is object-oriented

Java is a programming language that has been around a lot longer than Android. It is an object-oriented
language. This means it uses the concept of reusable programming objects. If this sounds like technical
jargon, another analogy will help. Java enables us and others (such as the Android development team) to
write Java code that can be structured based on real-world things, and here is the important part: it can
be reused.

What software engineers do when they write their code is build a blueprint for an object. We then create
an object from their blueprint using Java code and once we have that object, we can configure it, use it,
combine it with other objects, and more besides.

Furthermore, as well as this, we can design blueprints ourselves and make objects from them as well.
The compiler then transforms (manufactures) our bespoke creation into bytecode.
6
Java is object-oriented

Java is a language that allows us to write code once that can then be used repeatedly. This is very useful
because it saves us time and allows us to use other people's code to perform tasks we might otherwise
not have the time or knowledge to write ourselves. Most of the time, we do not even need to see this
code or even know how it works! One last analogy: we just need to know how to use the code just as we
need to learn how to drive a car.
7
Run that by me again – what exactly is Android?

To get things done on Android, we write Java code of our own, which also uses the Java code of the
Android API. This is then compiled into bytecode and translated by ART when installed by the user into
machine code, which in turn has connections to an underlying operating system called Linux, which
handles the complex and extremely diverse range of hardware that are the different Android devices.

The manufacturers of the Android devices and the individual hardware components obviously know this
too and they write advanced software called drivers, which ensure that their hardware (CPU, GPU, GPS
receivers, memory chips, hardware interfaces, and so on) can run on the underlying Linux operating
system.

The bytecode (along with some other resources) is placed in a bundle of files called an Android
Application Package (APK) and this is what ART needs to run to prepare our app for the user

You might also like