A1 Language Subset

Android uses a standard Java compiler to compile your source code into regular bytecodes and then translates those bytecodes into Dalvik instructions. Therefore, the entire Java language is supported, not just a subset. Compare this to the Google Web Toolkit (GWT), which has its own Java to JavaScript translator. By using the stock compiler and bytecodes, you don't even need to have the source code for libraries that you want to use in your applications.

Language Level

Android supports code compatible with Java Standard Edition 5 or earlier. Java 6 and 7 class formats and features are not yet supported but could be added in future releases.

Intrinsic Types

All Java intrinsic types including byte, char, short, int, long, float, double, Object, String, and arrays are supported. However, on some low-end hardware, floating point is emulated. That means it's performed in software instead of hardware, making it much slower than integer arithmetic. Although occasional use is fine, avoid using float or double in performance-critical code unless your algorithm really requires floating point or you're sure your application will be running on a high-end device.

Multithreading and Synchronization

Multiple threads are supported by time slicing: giving each thread a few milliseconds to run and then performing a context switch to let another thread have a turn. Although Android will support any number of threads, in general you should use only one or two. One thread is dedicated for the main user interface (if you have one), and another thread is used for long-running operations such as calculations or network I/O.

The Dalvik VM implements the synchronized keyword and synchronization-related library methods such as Object.wait(), Object.notify(), and Object.notifyAll(). It also supports the java.util.concurrent package for more sophisticated algorithms. Use them as you would in any Java program to keep multiple threads from interfering with each other.


Although the Android platform supports Java reflection, as a general rule you should not use it. The reason is simple performance: reflection is slow. Consider alternatives such as compile-time tools and preprocessors instead.


The Dalvik VM supports object finalization during garbage collection just like regular Java VMs. However, most Java experts advise you not to rely on finalizers because you cannot predict when (or if) they will run. Instead of finalizers, use explicit close() or terminate() methods. Android is targeted toward resource-constrained hardware, so it's important that you release all resources as soon as you no longer need them.

0 0

Post a comment