Comparison of Java and Android API
Encyclopedia
This article compare the Java
Java (programming language)
Java is a programming language originally developed by James Gosling at Sun Microsystems and released in 1995 as a core component of Sun Microsystems' Java platform. The language derives much of its syntax from C and C++ but has a simpler object model and fewer low-level facilities...

 and Android API
Application programming interface
An application programming interface is a source code based specification intended to be used as an interface by software components to communicate with each other...

 and virtual machine machines
Virtual machine
A virtual machine is a "completely isolated guest operating system installation within a normal host operating system". Modern virtual machines are implemented with either software emulation or hardware virtualization or both together.-VM Definitions:A virtual machine is a software...

.

While most Android applications are written in Java
Java (programming language)
Java is a programming language originally developed by James Gosling at Sun Microsystems and released in 1995 as a core component of Sun Microsystems' Java platform. The language derives much of its syntax from C and C++ but has a simpler object model and fewer low-level facilities...

, there are many differences between the java API and the Android API, and Android does not use a Java Virtual Machine
Java Virtual Machine
A Java virtual machine is a virtual machine capable of executing Java bytecode. It is the code execution component of the Java software platform. Sun Microsystems stated that there are over 4.5 billion JVM-enabled devices.-Overview:...

 but another one called Dalvik.

Virtual machine

There is no Java Virtual Machine
Java Virtual Machine
A Java virtual machine is a virtual machine capable of executing Java bytecode. It is the code execution component of the Java software platform. Sun Microsystems stated that there are over 4.5 billion JVM-enabled devices.-Overview:...

 in the platform and Java byte code is not executed. Java classes are compiled into Dalvik executables and run on Dalvik, a specialized virtual machine designed specifically for Android. Unlike Java VMs
Java Virtual Machine
A Java virtual machine is a virtual machine capable of executing Java bytecode. It is the code execution component of the Java software platform. Sun Microsystems stated that there are over 4.5 billion JVM-enabled devices.-Overview:...

, which are stack machine
Stack machine
A stack machine may be* A real or emulated computer that evaluates each sub-expression of a program statement via a pushdown data stack and uses a reverse Polish notation instruction set....

s, the Dalvik VM is a register-based architecture
Register machine
In mathematical logic and theoretical computer science a register machine is a generic class of abstract machines used in a manner similar to a Turing machine...

.

Dalvik has some specific characteristics that differentiate it from other standard VMs:
  • The VM was slimmed down to use less space
  • The constant pool has been modified to use only 32-bit
    32-bit
    The range of integer values that can be stored in 32 bits is 0 through 4,294,967,295. Hence, a processor with 32-bit memory addresses can directly access 4 GB of byte-addressable memory....

     indexes to simplify the interpreter
    Interpreter (computing)
    In computer science, an interpreter normally means a computer program that executes, i.e. performs, instructions written in a programming language...

  • Standard Java bytecode
    Java bytecode
    Java bytecode is the form of instructions that the Java virtual machine executes. Each bytecode opcode is one byte in length, although some require parameters, resulting in some multi-byte instructions. Not all of the possible 256 opcodes are used. 51 are reserved for future use...

     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 of the fact that the bytecode loaded by the Dalvik virtual machine is not Java bytecode
Java bytecode
Java bytecode is the form of instructions that the Java virtual machine executes. Each bytecode opcode is one byte in length, although some require parameters, resulting in some multi-byte instructions. Not all of the possible 256 opcodes are used. 51 are reserved for future use...

, and of the specific way Dalvik load classes, it is not possible to load Java libraries packages as jar files
JAR (file format)
In software, JAR is an archive file format typically used to aggregate many Java class files and associated metadata and resources into one file to distribute application software or libraries on the Java platform.JAR files are built on the ZIP file format and have the .jar file extension...

, and even a specific logic must be used to load Android libraries (specifically the content of the underlying dex file must be copied in the application private internal storage area, before being able to be loaded).

System properties

As it is the case for the Java SE class , the Android class allows to retrieve 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 return 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

Dalvik does not align to Java SE nor Java ME class library
Java Class Library
The Java Class Library is a set of dynamically loadable libraries that Java applications can call at run time. Because the Java Platform is not dependent on any specific operating system, applications cannot rely on any of the existing libraries...

 profiles (e.g., Java ME classes, AWT
Abstract Window Toolkit
The Abstract Window Toolkit is Java's original platform-independent windowing, graphics, and user-interface widget toolkit. The AWT is now part of the Java Foundation Classes — the standard API for providing a graphical user interface for a Java program.AWT is also the GUI toolkit for a...

 or Swing
Swing (Java)
Swing is the primary Java GUI widget toolkit. It is part of Oracle's Java Foundation Classes — an API for providing a graphical user interface for Java programs....

 are not supported). Instead it uses its own library built on a subset of the Apache Harmony
Apache Harmony
Apache Harmony was an 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...

 Java implementation.

java.lang package

By default, the default output streams and do not output anything, and developers are encouraged to use the class, which logs Strings on the LogCat tool.

Graphics and Widget library

Android does not use the Abstract Window Toolkit
Abstract Window Toolkit
The Abstract Window Toolkit is Java's original platform-independent windowing, graphics, and user-interface widget toolkit. The AWT is now part of the Java Foundation Classes — the standard API for providing a graphical user interface for a Java program.AWT is also the GUI toolkit for a...

 nor the Swing
Swing (Java)
Swing is the primary Java GUI widget toolkit. It is part of Oracle's Java Foundation Classes — an API for providing a graphical user interface for Java programs....

 library. User Interface is built using View objects. Android use a framework similar to Swing based around s rather than s. However, Android widgets are not JavaBeans: 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
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....

 architecture; The Look and Feel of Android widgets must be embedded in the widgets themselves. There is however a limited capability to set styles and themes for an application.

Layout manager

Contrary to Java where Layout manager
Layout manager
Layout managers are software components used in widget toolkits which have the ability to lay out widgets by their relative positions without using distance units. It is often more natural to define component layouts in this manner than to define their position in pixels or common distance units,...

s can be applied to any container widget
Container (data structure)
In computer science, a container is a class, a data structure, or an abstract data type whose instances are collections of other objects. In other words; they are used for storing objects in an organized way following specific access rules...

, Android layout behavior is encoded in the containers.

See also

  • Android (operating system)
  • Dalvik (software)
  • Java (programming language)
    Java (programming language)
    Java is a programming language originally developed by James Gosling at Sun Microsystems and released in 1995 as a core component of Sun Microsystems' Java platform. The language derives much of its syntax from C and C++ but has a simpler object model and fewer low-level facilities...

The source of this article is wikipedia, the free encyclopedia.  The text of this article is licensed under the GFDL.
 
x
OK