Comparison Of Java And Android API
   HOME

TheInfoList



OR:

This article compares the
application programming interface An application programming interface (API) is a connection between computers or between computer programs. It is a type of software Interface (computing), interface, offering a service to other pieces of software. A document or standard that des ...
s (APIs) and
virtual machine In computing, a virtual machine (VM) is the virtualization or emulator, emulation of a computer system. Virtual machines are based on computer architectures and provide the functionality of a physical computer. Their implementations may involve ...
s (VMs) of the programming language
Java Java is one of the Greater Sunda Islands in Indonesia. It is bordered by the Indian Ocean to the south and the Java Sea (a part of Pacific Ocean) to the north. With a population of 156.9 million people (including Madura) in mid 2024, proje ...
and operating system Android. While most Android applications are written in Java-like language, there are some differences between the Java API and the Android API, and Android does not run
Java bytecode Java bytecode is the instruction set of the Java virtual machine (JVM), the language to which Java and other JVM-compatible source code is compiled. Each instruction is represented by a single byte, hence the name bytecode, making it a compact ...
by a traditional
Java virtual machine A Java virtual machine (JVM) is a virtual machine that enables a computer to run Java programs as well as programs written in other languages that are also compiled to Java bytecode. The JVM is detailed by a specification that formally descr ...
(JVM), but instead by a Dalvik virtual machine in older versions of Android, and an
Android Runtime Android Runtime (ART) is an application runtime environment used by the Android operating system. Replacing Dalvik, the process virtual machine originally used by Android, ART performs the translation of some of the application's bytecode i ...
(ART) in newer versions, that compile the same code that Dalvik runs to
Executable and Linkable Format In computing, the Executable and Linkable FormatTool Interface Standard (TIS) Portable Formats SpecificationVersion 1.1'' (October 1993) (ELF, formerly named Extensible Linking Format) is a common standard file format for executable files, obje ...
(ELF) executables containing
machine code In computer programming, machine code is computer code consisting of machine language instructions, which are used to control a computer's central processing unit (CPU). For conventional binary computers, machine code is the binaryOn nonb ...
. Java bytecode in Java Archive ( JAR) files is not executed by Android devices. Instead, Java classes are compiled into an android bytecode (dex bytecode) format and run on Dalvik (or compiled version thereof with newer ART), a specialized virtual machine (VM) designed for Android. Unlike Java VMs, which are
stack machine In computer science, computer engineering and programming language implementations, a stack machine is a computer processor or a Virtual machine#Process virtual machines, process virtual machine in which the primary interaction is moving short- ...
s (stack-based architecture), the Dalvik VM is a
register machine In mathematical logic and theoretical computer science, a register machine is a generic class of abstract machines, analogous to a Turing machine and thus Turing complete. Unlike a Turing machine that uses a tape and head, a register machine u ...
(register-based architecture). Dalvik has some traits that differentiate it from other standard VMs: * The VM was designed to use less space. * The constant pool has been modified to use only
32-bit In computer architecture, 32-bit computing refers to computer systems with a processor, memory, and other major system components that operate on data in a maximum of 32- bit units. Compared to smaller bit widths, 32-bit computers can perform la ...
indexes to simplify the
interpreter Interpreting is translation from a spoken or signed language into another language, usually in real time to facilitate live communication. It is distinguished from the translation of a written text, which can be more deliberative and make use o ...
. * Standard Java bytecode executes 8-bit stack instructions. Local variables must be copied to or from the operand stack by separate instructions. Dalvik instead uses its own 16-bit instruction set that works directly on local variables. The local variable is commonly picked by a 4-bit ''virtual register'' field. Because the bytecode loaded by the Dalvik virtual machine is not Java bytecode and due to the way Dalvik loads classes, it is impossible to load library packages as jar files. A different procedure must be used to load Android libraries, in which the content of the underlying dex file must be copied in the application private internal storage area before it is loaded.


System properties

As is the case for the
Java SE Java Platform, Standard Edition (Java SE) is a computing platform for development and deployment of portable code for desktop and server environments. Java SE was formerly known as Java 2 Platform, Standard Edition (J2SE). The platform uses th ...
class , the Android class allows retrieving system properties. However, some mandatory properties defined with the Java virtual machine have no meaning or a different meaning on Android. For example: * java.version property returns 0 because it is not used on Android. * java.specification.version invariably returns 0.9 independently of the version of Android used. * java.class.version invariably returns 50 independently of the version of Android used. * user.dir has a different meaning on Android. * user.home and user.name properties do not exist on Android.


Class library

Current versions of Android use the latest Java language and its libraries (but not full
graphical user interface A graphical user interface, or GUI, is a form of user interface that allows user (computing), users to human–computer interaction, interact with electronic devices through Graphics, graphical icon (computing), icons and visual indicators such ...
(GUI) frameworks), not the
Apache Harmony Apache Harmony is a retired open source, free Java implementation, developed by the Apache Software Foundation. It was announced in early May 2005 and on October 25, 2006, the board of directors voted to make Apache Harmony a top-level projec ...
Java implementation, that older versions used.
Java 8 The Java language has undergone several changes since JDK 1.0 as well as numerous additions of classes and packages to the standard library. Since J2SE 1.4, the evolution of the Java language has been governed by the Java Community P ...
source code that works in latest version of Android, can be made to work in older versions of Android.


java.lang package

By default, the default output stream and do not output anything, and developers are encouraged to use the class, which logs Strings on the LogCat tool. This has changed at least from
HoneyComb A honeycomb is a mass of Triangular prismatic honeycomb#Hexagonal prismatic honeycomb, hexagonal prismatic cells built from beeswax by honey bees in their beehive, nests to contain their brood (eggs, larvae, and pupae) and stores of honey and pol ...
, and they now output to the log console also.


Graphics and widget library

Android does not use the
Abstract Window Toolkit The Abstract Window Toolkit (AWT) is Java's original platform-dependent windowing, graphics, and user-interface widget toolkit, preceding Swing. The AWT is part of the Java Foundation Classes (JFC) — the standard API for providing a graphic ...
nor the Swing library.
User interface In the industrial design field of human–computer interaction, a user interface (UI) is the space where interactions between humans and machines occur. The goal of this interaction is to allow effective operation and control of the machine fro ...
s are built using View objects. Android uses a framework similar to Swing, based on s rather than s. However, Android widgets are not
JavaBean In computing based on the Java Platform, JavaBeans is a technology developed by Sun Microsystems and released in 1996, as part of JDK 1.1. The 'beans' of JavaBeans are classes that encapsulate one or more objects into a single standardized ob ...
s: the Android application must be provided to the widget at creation.


Look and feel

Android widget library does not support a
pluggable look and feel Pluggable look and feel is a mechanism used in the Java Swing widget toolkit allowing to change the look and feel of the graphical user interface at runtime. Swing allows an application to specialize the look and feel of widgets by modifying the ...
architecture. The look and feel of Android widgets must be embedded in the widgets. However, a limited ability exists to set styles and themes for an application.


Layout manager

Contrary to Swing where
layout manager Layout managers are software components used in widget toolkits which have the ability to lay out graphical control elements by their relative positions without using distance units. It is often more natural to define component layouts in this mann ...
s can be applied to any container widget, Android layout behavior is encoded in the containers.


java.beans package

Android includes only a small subset of the java.beans package ( and related classes).


See also

*
Android (operating system) Android is an operating system based on a modified version of the Linux kernel and other open-source software, open-source software, designed primarily for touchscreen-based mobile devices such as smartphones and tablet computer, tablets. Andr ...
*
Java (programming language) Java is a High-level programming language, high-level, General-purpose programming language, general-purpose, Memory safety, memory-safe, object-oriented programming, object-oriented programming language. It is intended to let programmers '' ...


References

{{DEFAULTSORT:Java and Android API comparison Android (operating system) Android API comparison Computing comparisons