JavaRush/Java Blog/Random EN/How Android works. Introduction for Java Developers

How Android works. Introduction for Java Developers

Published in the Random EN group
members
Among Java programmers, you hear talk every now and then about developing for Android. Android is what has kept Java at the forefront for the past few years. How important is it for Java developers to understand or know Android? Well, it depends on whether you like app development and whether you want a lot of people to use your apps. If yes, then Android will give you this opportunity. The number of phones running the Android operating system is in the millions and continues to grow faster than the number of iPhones running iOS. This means that for a Java developer it makes sense to learn how to program for Android, which is what this article is dedicated to. This is also one of the good reasons to learn Java programming in the first place. From this review you will learn the basics of Android, without unnecessary details, but in sufficient volume. How Android works.  Introduction for Java Developers - 1One obvious advantage Java developers have over others is that the Android API is very similar to the Java language API, and Android supports, if not all the classes available in the J2SE SDK, then at least the most important ones. Another advantage: you can use the same tools for Android development as you do for Java. For example, Eclipse IDE, because Google provides a plugin for Eclipse for developing Android applications. When getting started with Android, it's worth checking out guides like Head First Android Development and Android in Action (3rd ed.), two of the best Android books for Java developers.
How Android works.  Introduction for Java Developers - 2
How Android works.  Introduction for Java Developers - 3
On the contrary, if you want to start developing for iOS, you will have a difficult process of learning the Objective-C language and the iOS SDK. It seems to me that switching to Objective-C and iOS makes more sense for a C++ developer than for a Java developer. So the classic war between Java and C++ continues with smartphone app development. In any case, let's understand the peculiarities of the internal functioning of Android.

How does Android work?

As I already mentioned, the Android operating system uses Java to develop applications. You can write Android application code using Google's provided Java API , which will then be compiled into class files. This is where the similarity ends. Android does not use a Java Virtual Machine (JVM) to execute class files; instead, it uses the Dalvik Virtual Machine , which is not a true JVM and does not run Java bytecode. For execution on Dalvik virtual machines, class files are compiled into DEX format (Dalvik EXecutable - Dalvik executable files). Once converted to DEX format, the class files along with other resources are bundled into Android packages (APKs) for distribution and installation on various devices. The main thing to know is that the base Dalvik virtual machine class library is based on a subset of the Apache Harmony project, and as a result does not support all of the J2SE APIs. If you use the Eclipse IDE to write code for Android applications, you don't have to worry too much, since it has code completion. Now let's understand how Android applications run on devices.

How Android apps run on devices?

If you are familiar with the Linux operating system and the concept of a process, it will be easy to understand how Android applications run. By default, the Android operating system assigns a unique user ID to each application. Once Android applications are launched, each one runs in its own process, in its own virtual machine.
How Android works.  Introduction for Java Developers - 4
The Android operating system controls the startup and termination of application processes as needed. This means that all Android applications operate in isolation from each other, but, of course, can request access to hardware and other system resources. If you are familiar with developing mobile applications, say, in J2ME, then you have probably come across the concept of access rights (permissions). When you install or launch an Android application, it requests the rights necessary to access the Internet, phone book, or other system resources. The user explicitly grants these rights, otherwise the action will be denied. All these permissions are described in the Android application's manifest file. Unlike Java, the Android manifest is an XML file that lists all the application components and the settings for them. The four main components of an Android application are activities, services, content providers, and broadcast receivers. Of these, the most common are activities that correspond to a separate screen form of an Android application. For example, a game for the Android operating system may have several screens: for login, records, instructions, and the game screen. Each of these elements corresponds to different activities in your application.
How Android works.  Introduction for Java Developers - 5
Like Java, the good thing about Android is that it does some tasks for the developer, such as creating activity objects. The class is responsible for organizing activities System. If you need to start an activity, you just need to call a method startActivity()with an object Intentas a parameter. In response to this call, the class Systemwill either create a new activity object or reuse the old one. Similar to Java's garbage collection, which handles the all-important task of memory reuse, Android manages the starting, stopping, creation, and destruction of applications. It may seem like it's limiting them too much, but it's not. Android provides lifecycle events that can be overridden to interfere with this process. That's all about how Android works . As a Java developer, it definitely makes sense to learn Android because it uses Java, so you can take advantage of your knowledge of Java programming techniques, design patterns, and best practices to create good Android applications. Of course, you will have to adapt to some Android-specific things, but that will come naturally with time. So, what are you waiting for? Go ahead, learn Android and write your first HelloWorld Android app! Finally, you might want to take a look at some good books on the basics of Android development, such as Head First Android Development , which is the best book on Android. Source: Introduction of How Android Works for Java Programmers
Comments
  • Popular
  • New
  • Old
You must be signed in to leave a comment
This page doesn't have any comments yet