What is Android Programming Language

If you want to be personal, You will have to be Android. Android is deep inside you. It is your private life. Android is you. Read this article till the end.

Java is an Object-Oriented programming language. The Java programming language implements the concept of reusability. Using reusability, the same programming construct is used again and again. 

Java transforms the real-world object into class. Thus, operation on class is done using objects.

To accomplish a particular task on Android, programs written in Java are used. First, the Java code interacts with the Android API. Then, the Java code is converted into DEX code and executed by DVM. Finally, this converted Java code interacts with the Linux Operating System.

Android devices use hardware such as CPU+GPU+GPS receivers. To interact with these hardware devices, drivers are used. These drivers interact with Linux Operating System to accomplish the desired task.

The compiled Java code and associated resources are combined and packed in an Android application (APK) file. The Dalvik Virtual Machine (DVM) use this APK to execute the application on the Android device.

To develop the Android application development environment is required. This Android application is developed using Java programming language, the Java code is coveted into DEX code to get executed on DVM, and DVM is on user Android Devices.

The Java code is executed on JDK. The JDK is Java Development Kit, and it is free software. Therefore, the JDK is different from Android API.

To develop Android applications, a set of Tools and Android API is required. These tools and Android API, when combined, it is known as software development kit (SDK). In addition, to use any Android application, its executable file has to be downloaded. This downloadable file is called Android Studio.

Android studio bridges the gap between the JDK and the Android API. 

There exist different types of software that are used to develop Android applications. For example, android applications can also be developed on Eclipse. However, most of the time, Java applications are developed and executed on Eclipse. The most common Java is Java Runtime Environment. When JDK is installed it automatically install JRE – Java Runtime Environment.

To develop Android Applications, Java code is written, this Java Code is converted into DEX code, and this DEX code is executed on DVM. This DVN is added with other resource files known as Android resources.

What are Android Resources?

Any Android application contains other components that are used to execute and deliver as per the expectation of the Android users. For example, any Android application requires components such as images, sounds, and user interfaces interactions. These components are added to Java code by putting them into a separate file.

The Android application also requires textual content for its successful execution. Therefore, the textual content is placed in a separate file that makes it easy to access. In addition, the text may address different languages. Thus an Android application may be used in different languages. 

The textual matter for Android applications is placed in an Extensible Markup Language XML file. The XML file is human and machine-readable. In addition, Android Studio provides an editor to interact with XML files.

Java Code of Android

Java code that is developed to be used in Android has a predefined structure. Android packages define this structure of Java code for Android.

When a new Android application is developed, it is given a new name known as a package. A package may also contain sub-packages. The sub-package is used to club similar packages. Package may also be treated as a folder, and sub-package may also be treated as a sub-folder. 

An example of the Android package includes Android. graphics, Android. database, and android.view.animation

These packages contain classes. These packages can be used in Android applications. The file name and class name is the same and has a .java extension.

The class contains methods, and these methods have their functionality to achieve the desired task. The class name specifies the class’s functionality, and it also specifies that all the methods within the class will have related functionality. 

Each Android application has one associated package. Since Java is an Object-Oriented language, part of the Java code can be used as per the requirement. To access any method of a class, the object of that class must be used. 

Java Code

The Java code implements many Java programming techniques such as the method structure, method overloading, method overriding, and influence of methods on variables. 

A Java method contains a signature. An example of Java structure is as follows:

Public boolean add_contact (boolean isFriend, string name)

A method has an opening and closing curly brackets. In between these curly brackets, programming instructions are written. Thus, a method has a signature and programming instructions between opening and closing curly brackets, known as the method’s definition.

The method signature defines how that method will be called and how the value will be returned. A method has modifiers – public, private, and package-private. The type of value returned from the method is to be specified using return type. For example, a method can return a boolean, float, double, char, int, and long type values. A method is also capable of returning user-defined types such as DOB, Address etc.

Access specifier/modifiers are capable of specifying how to use the code. For example, access specifier public and private has their definition that specifies how the method will be used. The method can also return value it is specified by return type. The return type is a data type associated with the method. 

The return type can be any data type defined in the Java compiler. If the method does not return a value, then it is appended with the void keyword.

The name of the method must specify its functionality. The name of the method is given in camel case notation.

The method can also contain parameters. The parameters are the values that are manipulated, and the results are returned.

In Java, method overloading can also be done. This is because all Java methods use variables. These variables are manipulated and operated upon within the method.

All the Java methods have variables. These variables are alive within the method’s scope and dead out-of-the scope of the method. 

Object-Oriented Programming

Java is an Object-Oriented Programming language. Object-Oriented Programming Language breaks a program into chunks so that it becomes more manageable.

Each chunk can be used and re-used as required. These chunks may also be treated as Objects. An object of a class is also known as an instance of a class. 

The three core principles of Object-Oriented programming are encapsulation, polymorphism, and inheritance.

Encapsulation in Object-Oriented Programming is used to provide type safety. Encapsulation keeps the internal working of the code type-safe. In addition, using encapsulation, the programs can be updated, extended, or improved as required. 

All the classes of Android API use encapsulation to provide data access and type safety.

Polymorphism is used to develop programming instructions that are less dependent on the types. As a result, polymorphism makes code clean and more effective and efficient. The definition of polymorphism is different forms.   

To re-use code, inheritance is used; all the methods and functionalities defined in a class can be used in other classes. To inherit a class extends keyword is used.

All the Object-Oriented Programming provide methods to add a new feature to existing programs. For example, when a definition of a class is changed, it rarely influences other parts of the program. This mechanism is known as encapsulation. 

A class contains data member and member functions. The member functions of the class contain programming instructions that are developed using loops, variables et.

Object-Oriented Programming is used to develop programming applications that are complex and used on Android.

Example code of Java class is as follows:

public class Army_Solider
{
      int age;
      string solider_type;
     
      void shoot_Enemy( )
      {
              // programming instructions;
      }
}

This class contain two data members, age, solider_type and one member function shoot_Enemy( ).

To access these data members and member functions, an object of these classes are used. To create objects following method is used:

Army_Solider my_sol = new Army_Solider( );

my_sol is a new object of the Army_Solider class. To access data members, the object my_sol is used. The object my_sol can access data members in the following manner:

my_sol.age;
My_sol.solider_type;

To access the member function, the object my_sol is used. My_sol is used in the following manner:

my_sol.shoot_Enemy( );

To use this class in other classes, it has to be included in the program. 

A class can be declared as public. When a class is declared as public, it can be accessed by all other classes. Different access specifier has different visibility. Java supports public, protected, default, and private access specifiers.

A class’s data member and member function with a protected access specifier can access all the methods and classes belonging to the same package.

All the data member and member functions of a class having default access specifier are accessible to the sub-class. 

All the class data member and member functions with a private access specifier are accessible with the declared class. However, its sub-class can not access the private data member and member functions of the class.

All the methods in the Java code have an access specifier. The access modifier of the methods is the same as the of the access modifier of the class. 

Data member and member functions can be initialized either by using methods or by using constructors. Constructors are the same as that of methods. All constructors can be called at the time when the object of the class is created.

Constructors in Java has non return types, the name of the constructor is the same as that of the class, constructors can be parameterised, and constructors in Java can be overloaded. 

Java also supports this keyword. this keyword can be used to access a data member or variables of a method explicitly. 

Example code to illustrate the use of this keyword is as follows:

public class Army_Solider
{
      string Army_name;
      string Army_ype;
      int Army_health;  

      public Army_Solider(string Army_name, string Army_type, int Army_health)
      {
               this.Army_name;
               this.Army_type;
               int Army_health;
      }
} 

Here Army_Solider is the constructor that accesses the data members. The data members of the class are accessed using this keyword.

Java also supports static methods. The static methods can be used without the objects of the class. A class that has a static method must also be declared as a static class. A static class can have both static methods or non-static methods. All the non-static methods can be accessed using objects of the class. The static method can be accessed using the class name. 

A class having useful functionality can be accessed in another class by inheriting that class. The class can be inherited using the keyword extends. Following is the signature of the class that extends other classes:

public class Main_Activity extends App_Compact_Activity . .  

The class Main_Activity will use the data member and member functions of the class Main_Activity. 

The example of inheritance is as follows:

public class Animal_sheep
{
     public int age;
     public int weight;
     public string type;
     public int hunger_Level;
   
     public void eat ( )
     {
         hunger_level--;
     }

     public void walk( )
     {
           hunger_level--;
     }
}

This class can be inherited in  the following manner:

public class Ani_Elephant extends Animal_sheep
{
       

        public Ani_Elephant (int Ani_age, int Ani_weight) 
        {
            													 this.Ani_age = 57;
             this.Ani_weight = 1000;
             this .Ani_type=”elepphant”;
             	
              int hunger_level = 0;										
        }  
}

This code illustrates the use of inheritance and extends the class Animal_sheep. Thus, the class Ani_Elephant can access all the data members of the class Animal_sheep.

Java has the capability of implementing different forms of the same functions. Using polymorphism, simple and efficient code can be written.

Java also supports Abstract Class. However, an abstract class cannot be instantiated, and it is impossible to create abstract class objects. 

Abstract classes are used if the class has to be inherited before they are used. Since it cannot be instantiated, it has to be inherited first.

An abstract class is created in the following manner:

abstract class some_Class
{
   /*
         -----
       ------
          ------

  */
}   

Java also supports Interfaces. An interface is an entirely abstract class. All the members of the abstract class are abstract. An interface does not have any data members. An Interface can be declared in the following manner:

public interface my_interface
{
      void few_Abs_ex( );
      int ano_Abs_Me( );
}

All the methods declared within the interface have a body, but the methods’ signature is well defined. All the methods within theInterface will have a qualified name, a set of parameters and a return type.

To use interface implement keywords are used. Following is an example of an interface.

pubic class so_Class implements so_Intercae
{
     /*
          -----
               ------
         ---
    */
}
public void so_AbstractMethod ( )
{
     // code is to be written here    
}
public int another_Abstract_Method( )
{
     // code to written here
    // return integer number
}

Conclusion

This article has covered the basic theory of the language Java that can be used to develop Android applications. In addition, this article provides you with an insight into Android and its applications and language Java that can be used to develop Android applications. 

This article explains the concepts used in Object-Oriented Programming with examples. 

This article also explains Android resources and their importance in the development of Android applications. Further, the use of textual material to develop Android applications that can be used in different languages is also illustrated in this article. 

Developing an Android application that is robust and can deliver what is expected requires efficient use of programming principles illustrated in this article is required. Thus a thorough practice is required to use the programming principles illustrated in this example and Android applications. 

A sufficient amount of memory is required to use Android applications. These Android applications use memory that is allocated from the heap. Thus, a programmer developing Android applications must have a clear understanding and technicalities of allocation and deallocation of the memory is required. In addition, the programmer must possess the ability to work with DVM. The machine is responsible for allocating and deallocating the memory to the Android application on the Android device.      

Thus this is a comprehensive article covering the critical aspects of Android and the language used to develop Android applications.

This article requires a minimum number of two reads to get into it.