Comparison of Java and Android API

This article compares the Java and Android API and virtual machines.

While most Android applications are written in Java-like language, there are many differences between the Java API and the Android API, and Android does not use a Java Virtual Machine but two other ones called either Dalvik or Android Runtime (ART).

There is no Java Virtual Machine in the Android platform. Java bytecode is not executed. Instead Java classes are compiled into a proprietary bytecode format and run on Dalvik, a specialized virtual machine (VM) designed specifically for Android. Unlike Java VMs, which are stack machines, the Dalvik VM is a register-based architecture.

Dalvik has some specific characteristics 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 specific way Dalvik loads classes, it is not possible to load libraries 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 the retrieval of 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

Dalvik does not align to Java SE nor Java ME class library profiles[3][4] (e.g., Java ME classes, AWT or Swing are not supported). Instead it uses its own library[5] built on a subset of the Apache Harmony Java implementation.

java.lang package

By default, the default output stream System.out and System.err do not output anything,[6] and developers are encouraged to use the Log class, which logs Strings on the LogCat tool.[7] (this has changed at least from HoneyComb, and they now output to the log console as well)

Graphics and Widget library

Android does not use the Abstract Window Toolkit nor the Swing library. User Interface is built using View objects. Android uses a framework similar to Swing-based around Views rather than JComponents. 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 themselves. There is, however, a limited capability to set styles and themes for an application.[8]

Layout manager

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

See also

References

  1. Rose, John (2008-05-31). "with Android and Dalvik at Google I/O". Retrieved 2008-06-08.
  2. Fred Chung (2011-07-28). "Custom Class Loading in Dalvik". Google. Retrieved 2011-11-27.
  3. "Google's Android SDK Bypasses Java ME in Favor of Java Lite and Apache Harmony". infoq.com. 2007-11-12. Retrieved 2009-05-31. Instead of providing a full version of the Java SE or Java ME Google has diverged on two fronts. First, a limited subset of the core Java packages is provided. (...) By going this route Android is following in the footsteps of another Google project GWT which uses Java as its development language but does not support the full JDK
  4. "Alternative to Point2D". Droid Tutorials. 2010-02-12. Retrieved 2010-02-17. Given that AWT is not supported in Android API, the Point2D class, which is useful for writing 2D graphics, is missing either
  5. "Package Index". Google. Retrieved 2011-11-27.
  6. "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.
  7. "Reading and Writing Logs". Google. Retrieved 2011-11-27.
  8. "Applying Styles and Themes". Google. Retrieved 2011-09-03.
  9. "Common Layout Objects". Google. Retrieved 2011-09-03.
This article is issued from Wikipedia - version of the Friday, June 26, 2015. The text is available under the Creative Commons Attribution/Share Alike but additional terms may apply for the media files.