Android Programming
Android Programming
Dr. K. ANANDHARAJ
ASSISTANT PROFESSOR
PG AND RESARCH DEPARTMENT OF COMPUTER SCIENCE
SRI RAMAKRISHNA COLLEGE OF ARTS & SCIENCE
COIMBATORE
How Java and Android Work Together
• 1. Writing Code
• Android apps are written in Java (or Kotlin, in modern versions).
• After writing Java code, compile it before it can run on Android devices.
• 2. Compiling Java Code
• When the “Run” or “Build” button is clicked in Android Studio, the Java
code is compiled (converted) into another form called Dalvik Executable
(DEX) code.
• DEX Code: A special format understood by Android systems.
• This compilation happens on the development machine (your
computer).
Dalvik Virtual Machine
• Dalvik Virtual Machine (DVM) is the part of Android that runs
(executes) the compiled DEX [Link] is similar in purpose to the Java
Virtual Machine (JVM) but is optimized for mobile devices (limited
memory and battery).
•The DVM itself is a software program written in another programming
language.
•It runs on top of a special version of the Linux operating system.
• What the user sees as Android is actually an app running on top of
Linux — the DVM manages and runs all Android apps.
• The purpose of the DVM is to hide the complexity and diversity of the
hardware and software that Android runs on but, at the same time, its
purpose is to expose all of its useful features. This exposing of
features generally works in two ways.
• The DVM itself must have access to the hardware, which it does, but
this access must be programmer friendly and easy to use.
• The way the DVM allows us access is easy to use because of the
Android Application Programming Interface (API).
The Android API
• The Android API, or Application Programming Interface, refers to the
set of tools, functions, and protocols that enable developers to build
applications for the Android platform.
• It provides a standardized way for apps to interact with the underlying
Android system and its various features.
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 that it
uses the concept of reusable programming objects.
• 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.
• In Java, a blueprint is called a class. When a class is transformed into a
real working thing, it is called as an object.
Android
• Java code is written on own, which also uses the Java code of the
Android API. This is then compiled into DEX code and run by the DVM,
which in turn has connections to an underlying operating system
called Linux.
• Then the manufacturers of the Android devices and individual
hardware components write advanced software called drivers, which
ensure that their hardware (CPU, GPU, GPS receivers, and so on) can
run on the underlying Linux operating system.
• Our compiled Java code, along with some other resources, is placed in
a bundle of files called an Android application package (APK), and this
is what the DVM needs to run our app.
The development environment
• A development environment is a term that refers to having everything you
need in order to develop, set up, and be ready to go in one place
• Java code is written and translated into DEX code that will run on the DVM,
on people's Android devices.
• In order to use Java code, a free software is neede called the JDK. The JDK
also includes other people's code, which is separate from the Android API.
• There is a whole range of tools that are required to develop for Android,
and we also need the Android API, of course. This whole suite of
requirements is collectively known as the Android software development kit
(SDK).
• Downloading and installing a single application will give these things all
bundled together. This single application is called Android Studio.
• Android Studio is an integrated development environment (IDE) that
takes care of all the complexities of compiling our code and linking
with the JDK and the Android API
Eclipse
• Eclipse® is famous for being an Integrated Development
Environment (IDE) for the Java® programming language but is also
well capable of other languages like C/C++, JavaScript or TypeScript,
to just name a few.
• At its core Eclipse is a highly extensible platform and a
comprehensive set of frameworks and common services that
collectively provide a powerful software development infrastructure
used for numerous free and open as well as for commercial products
and applications.
The JDK
• Common version of Java is called the Java Runtime Environment (JRE).
When JDK is installed, it will also install the JRE.
• Installing the JDK
Installation of the JDK
• Now we are ready to install the JDK
• 1. Visit the Java JDK downloads page at [Link]
technetwork/java/javase/downloads/[Link].
2. If the link has changed, conduct a web search for Java JDK
download. The only potential stumbling block at this stage is that you
click on a link for the JRE instead. JDK is what we need.
• The following is a screenshot of the important part of this page:
• There will be a newer version of the JDK by the time you read these words, so the
8u51 will be different.
• Simply click on the Accept License Agreement radio button that is highlighted in
the previous screenshot and then click on the download link, which is on the right-
hand side column corresponding to your operating system in the Product/File
Description column.
• Wait while the JDK is downloaded to your hard drive. 5. In the folder where you've
downloaded the JDK, right-click on the jdk-8u51- [Link] file and select
Run as administrator.
• The precise name of the file you have will vary based on whether you have 32-bit
or 64-bit Windows and what the current version of the JDK happens to be at the
time. 6. There will be a series of windows that will guide us through the installation
process.
• The most we have to do is just click on Next to proceed.
• The following is a screenshot of the first window that you will see during the
installation: