Comparison of Java and Android API

Last updated

This article compares the application programming interfaces (APIs) and virtual machines (VMs) of the programming language Java and operating system Android.

Contents

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 by a traditional Java virtual machine (JVM), but instead by a Dalvik virtual machine in older versions of Android, and an Android Runtime (ART) in newer versions, that compile the same code that Dalvik runs to Executable and Linkable Format (ELF) executables containing machine code.

Java bytecode in Java Archive (JAR) files is not executed by Android devices. Instead, Java classes are compiled into a proprietary 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 machines (stack-based architecture), the Dalvik VM is a register machine (register-based architecture).

Dalvik has some traits that differentiate it from other standard VMs: [1]

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. [2]

System properties

As is the case for the Java SE class System , the Android System 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:

Class library

Current versions of Android use the latest Java language and its libraries (but not full graphical user interface (GUI) frameworks), not the Apache Harmony Java implementation, that older versions used. Java 8 source code that works in latest version of Android, can be made to work in older versions of Android. [3]

java.lang package

By default, the default output stream System.out and System.err do not output anything, [4] and developers are encouraged to use the Log class, which logs Strings on the LogCat tool. [5] This has changed at least from HoneyComb, and they now output to the log console also.

Graphics and widget library

Android does not use the Abstract Window Toolkit nor the Swing library. User interfaces are built using View objects. Android uses a framework similar to Swing, based on View s rather than JComponent s. However, Android widgets are not JavaBeans: the Android application Context must be provided to the widget at creation.

Look and feel

Android widget library does not support a pluggable look and feel 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. [6]

Layout manager

Contrary to Swing where layout managers can be applied to any container widget, Android layout behavior is encoded in the containers. [7]

java.beans package

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

See also

Related Research Articles

Java (programming language) Object-oriented programming language

Java is a class-based, object-oriented programming language that is designed to have as few implementation dependencies as possible. It is a general-purpose programming language intended to let application developers write once, run anywhere (WORA), meaning that compiled Java code can run on all platforms that support Java without the need for recompilation. Java applications are typically compiled to bytecode that can run on any Java virtual machine (JVM) regardless of the underlying computer architecture. The syntax of Java is similar to C and C++, but has fewer low-level facilities than either of them. The Java runtime provides dynamic capabilities that are typically not available in traditional compiled languages. As of 2019, Java was one of the most popular programming languages in use according to GitHub, particularly for client-server web applications, with a reported 9 million developers.

Java virtual machine 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 describes what is required in a JVM implementation. Having a specification ensures interoperability of Java programs across different implementations so that program authors using the Java Development Kit (JDK) need not worry about idiosyncrasies of the underlying hardware platform.

Lua (programming language) Lightweight programming language

Lua is a lightweight, high-level, multi-paradigm programming language designed primarily for embedded use in applications. Lua is cross-platform, since the interpreter of compiled bytecode is written in ANSI C, and Lua has a relatively simple C API to embed it into applications.

In computing, cross-platform software is computer software that is implemented on multiple computing platforms. Cross-platform software may be divided into two types; one requires individual building or compilation for each platform that it supports, and the other one can be directly run on any platform without special preparation, e.g., software written in an interpreted language or pre-compiled portable bytecode for which the interpreters or run-time packages are common or standard components of all platforms.

A computing platform or digital platform is the environment in which a piece of software is executed. It may be the hardware or the operating system (OS), even a web browser and associated application programming interfaces, or other underlying software, as long as the program code is executed with it. Computing platforms have different abstraction levels, including a computer architecture, an OS, or runtime libraries. A computing platform is the stage on which computer programs can run.

Bytecode, also termed portable code or p-code, is a form of instruction set designed for efficient execution by a software interpreter. Unlike human-readable source code, bytecodes are compact numeric codes, constants, and references that encode the result of compiler parsing and performing semantic analysis of things like type, scope, and nesting depths of program objects.

In computing, just-in-time (JIT) compilation is a way of executing computer code that involves compilation during execution of a program – at run time – rather than before execution. Most often, this consists of source code or more commonly bytecode translation to machine code, which is then executed directly. A system implementing a JIT compiler typically continuously analyses the code being executed and identifies parts of the code where the speedup gained from compilation or recompilation would outweigh the overhead of compiling that code.

GNU Classpath

GNU Classpath is a free software implementation of the standard class library for the Java programming language. Most classes from J2SE 1.4 and 5.0 are implemented. Classpath can thus be used to run Java-based applications. GNU Classpath is a part of the GNU Project. It was originally developed in parallel with libgcj due to license incompatibilities, but later the two projects merged.

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 project. The Harmony project achieved 99% completeness for J2SE 5.0, and 97% for Java SE 6. The Android operating system has historically been a major user of Harmony, although since Android Nougat it increasingly relies on OpenJDK libraries.

JamVM is an open-source Java Virtual Machine (JVM) developed to be extremely small compared with other virtual machines (VMs) while conforming to the Java virtual machine specification version 2.

Jazelle DBX is an extension that allows some ARM processors to execute Java bytecode in hardware as a third execution state alongside the existing ARM and Thumb modes. Jazelle functionality was specified in the ARMv5TEJ architecture and the first processor with Jazelle technology was the ARM926EJ-S. Jazelle is denoted by a "J" appended to the CPU name, except for post-v5 cores where it is required for architecture conformance.

Java (software platform)

Java is a set of computer software and specifications developed by James Gosling at Sun Microsystems, which was later acquired by the Oracle Corporation, that provides a system for developing application software and deploying it in a cross-platform computing environment. Java is used in a wide variety of computing platforms from embedded devices and mobile phones to enterprise servers and supercomputers. Java applets, which are less common than standalone Java applications, were commonly run in secure, sandboxed environments to provide many features of native applications through being embedded in HTML pages.

In software development, the programming language Java was historically considered slower than the fastest 3rd generation typed languages such as C and C++. The main reason being a different language design, where after compiling, Java programs run on a Java virtual machine (JVM) rather than directly on the computer's processor as native code, as do C and C++ programs. Performance was a matter of concern because much business software has been written in Java after the language quickly became popular in the late 1990s and early 2000s.

Eclipse OpenJ9 is a high performance, scalable, Java virtual machine (JVM) implementation that is fully compliant with the Java Virtual Machine Specification.

Dalvik is a discontinued process virtual machine (VM) in Android operating system that executes applications written for Android. Dalvik was an integral part of the Android software stack in the Android versions 4.4 "KitKat" and earlier, which were commonly used on mobile devices such as mobile phones and tablet computers, and more in some devices such as smart TVs and wearables. Dalvik is open-source software, originally written by Dan Bornstein, who named it after the fishing village of Dalvík in Eyjafjörður, Iceland.

The Java Development Kit (JDK) is an implementation of either one of the Java Platform, Standard Edition, Java Platform, Enterprise Edition, or Java Platform, Micro Edition platforms released by Oracle Corporation in the form of a binary product aimed at Java developers on Solaris, Linux, macOS or Windows. The JDK includes a private JVM and a few other resources to finish the development of a Java application. Since the introduction of the Java platform, it has been by far the most widely used Software Development Kit (SDK).

Java bytecode is the instruction set of the Java virtual machine (JVM).

JEB decompiler

JEB is a disassembler and decompiler software for Android applications and native machine code. It decompiles Dalvik bytecode to Java source code, and MIPS, ARM, x86 32-bit, x86 64-bit machine code to C source code. The assembly and source outputs are interactive and can be refactored. Users can also write their own scripts and plugins to extend JEB functionality.

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 the application's bytecode into native instructions that are later executed by the device's runtime environment.

References

  1. Rose, John (2008-05-31). "with Android and Dalvik at Google I/O". Archived from the original on 2008-06-04. Retrieved 2008-06-08.
  2. Fred Chung (2011-07-28). "Custom Class Loading in Dalvik". Google. Archived from the original on 2014-02-18. Retrieved 2011-11-27.
  3. "Use Java 8 language features and APIs". Android Developers. Retrieved 2021-01-23.
  4. "Android Debug Bridge". Google . Retrieved 2009-05-31. By default, the Android system sends stdout and stderr (System.out and System.err) output to /dev/null.
  5. "Reading and Writing Logs". Google. Archived from the original on 2011-11-22. Retrieved 2011-11-27.
  6. "Applying Styles and Themes". Google. Archived from the original on 2014-03-28. Retrieved 2011-09-03.
  7. "Common Layout Objects". Google . Retrieved 2011-09-03.