Java is an object-oriented programming language independent of the platform used to create native applications for Android. It is a popular programming language developed by Sun Microsystems, now owned by Oracle. Java contains many of its predecessors’ powerful tools, such as C or C++ while trying to avoid their shortcomings.

The Android SDK contains many standard Java libraries such as those focusing on data structure, mathematics, graphics or network. It also contains libraries especially developed for Android.

There are many apps using Java for Android, such as Whatsapp, Facebook, Linkedin or FlipKart.

Difference between Java for Android and Java

As for syntax, Java for Android and Java are the same language. The difference is the availability of libraries where some Java libraries cannot be used in Java for Android and vice versa – some Java for Android libraries cannot be used in standard Java.

A great difference is the form of API. Android does not run bytecode in Java through the classic JVM (Java Virtual Machine), but uses Dalvik for older versions or Android Runtime (ART) for newer versions instead.

Android devices do not trigger JAR files, but classes are compiled into proprietary bytecode format and triggered by Dalvik and a specialized virtual Android machine.

Dalvik has some characteristics distinguishing it from ordinary virtual machines:

  • It is designed to use less space.
  • Constant pool was modified to use 32-bit indexes only to simplify the interpreter
  • A standard Java bytecode triggers 8-bit instructions. Local variables must be copied from or to running stack by separate commands. Instead, Dalvik uses 16-bit instructions working directly with local variables. Those are often collected by a four-bit virtual register.

Because the bytecode loaded into Dalvik virtual machine isn’t the same as Java bytecode and because of the way Dalvik load classes, it isn’t possible to load class packages using jar files. For Android libraries, it is essential to use a different procedure that uses copying the dex file into the private app storage before the file is loaded.

The advantages of using Java for Android

  • Understandability. Java is easy to understand for both developers and users.
  • Security. Java is considered to be quite safe due to used security procedures and safe programming.

The disadvantages of using Java for Android

  • Speed. Java is slower and is using more memory than other programming dialects derived from C and C++.
  • One-paradigm language. Java is an object-oriented programming language that basically doesn’t support other paradigms.