[MUSIC] Welcome to Part 2 in our lesson on Infrastructure Middleware, where we focus on Android's Runtime execution environment. After completing this part of the lesson, you'll understand the role of the execution environment in Android's Runtime layer and you'll also know the two execution environments that have been part of Android's Runtime which are known as ART and Dalvik. Apps rarely access ART or Dalvik directly, but it's still useful to understand what they do so you'll be a more effective full-stack developer. Start with an overview of the Android Runtime's Execution Environment. Android's Runtime layer is largely used to execute Java apps on mobile devices such as tablets, smart phones, or wearables. These apps can now also run in the Chrome browser on laptops and desktops. Android's Runtime layer contains an execution environment that resides atop the Linux kernel. This environment executes app byte code and/or native byte code typically inside a Linux process. The code itself is generated from Java source files by the javac compiler. The execution environment is created when a process starts and is destroyed whenever the process exits. A process can run apps or system services. The execution environment enhances portability and productivity by shielding higher layers of Android, as well as application developers, from low-level details of the underlying hardware. This hardware can include different instruction sets such as Intel x86, ARM, or various types of emulators. Android apps typically run in their own process and their own instance of the execution environment. It is possible in some rare circumstances, however, to have apps share the same process address space. Let's now talk about the evolution of the Android Execution Environment, which has changed over time. Android apps are typically written in Java, but they don't run in a standard Java Virtual Machine or JVM. Originally, the Dalvik virtual machine, or DVM, was used to interpret so-called Dalvik bytecode. This Dalvik bytecode uses a register machine model. In contrast, the Java platform uses a stack machine model. These two types of bytecode, Dalvik bytecode and Java bytecode, are not directly compatible. Therefore, Android originally defined a utility program called dx that transforms Java bytecode in class files into .dex-formatted bytecode. Dalvik was later enhanced to add support for Just-in-time, or JIT compilation. A JIT optimizes bytecode dynamically while a program is running. During the past several years Dalvik has been phased out and replaced with an improved execution environment called the Android Runtime, or ART. There's a number of enhancements in ART. For example, it provides an ahead-of-time compiler which is used to compile .dex files into native code when an app is installed. Needless to say, native code execution time is substantially faster than interpreted bytecode. It also provides better support for garbage collection. It has fewer garbage collection pauses and also the ability to execute garbage collection in parallel with other computations taking place in an application. It also provides a Just-in-time compiler that further optimizes ART's ahead-of-time compiled code at runtime. Irrespective of whether ART or Dalvik is used, Android's execution environments implement core Java concurrency features. For example, they implement the threading and synchronization mechanisms defined in the Java programming language specification. Such as threads that run computations concurrently, as well as built-in monitor objects that provide synchronization mechanisms by the synchronized statement and synchronized method constructs, as well as notification features via the wait, notify, and notify all methods. My website contains many more digital learning resources related to Android and Java concurrency, so I recommend you check it out. Note that Android's concurrency features also involve capabilities at multiple levels. There are kernel threads, there are Android virtual machine threads, there are POSIX threads, there's Java threads, and there's also higher-level Android concurrency frameworks. There's also support in Android for multi-core hardware. It's now widely available for many mobile devices. This concludes the end of Part 2 of our lesson on Infrastructure Middleware, which focused on the Android Runtime Execution Environment. [MUSIC]