Build project using Java

Android programming is based on Java programming language so if you have basic understanding on Java programming then it will be easier for you to learn Android application development. See the steps below to develop your Android app using Java. 

There are two ways to create User Interface (UI) on Android: (1) Write Java codes; (2) Layout via XML descriptions and let the system generates the Java code for you.

Let’s begin with writing Java codesWe shall continue from the “Hello Android” project created earlier.

Expand the “app” node. Expand the “java” node. Expand the “com.example.helloandroid” package node. Open the “” (which actually has already been opened). REPLACE the onCreate() method as follows and add the import statement. Do not touch the rest of the codes.

package ......;
import ......;
import android.widget.TextView;   // Add this line
public class MainActivity extends ...... {

    // REPLACE the ENTIRE onCreate() method as follows:
    protected void onCreate(Bundle savedInstanceState) {
        TextView textView = new TextView(this);   // Construct a TextView UI component
        textView.setText("Hello, from my Java code!"); // Set the text message for TextView
        setContentView(textView);  // this Activity sets its content to the TextView
    // Do not touch the rest of the codes, if any

Run the application (“Run” ⇒ “Run app”). You shall see the message “Hello, from my Java code!” displayed.

Dissecting the “” – Application, Activity & View

An Android application could have one or more Activity.

An Activity, which usually has a screen, is a single, focused thing that the user can interact with the application (hence called activity). The MainActivity extends the class (or in the later version), and overrides the onCreate() method. The onCreate() is a call-back method, which is called back by the Android system when the activity is launched.

A View is a UI component (or widget, or control). We construct a TextView (which is a subclass View for showing a text message), and set its text. We then set the content-view of the MainActivity screen to this TextView.

Android Application Descriptor File – “AndroidManifest.xml

Each Android application has a manifest file named AndroidManifest.xml under “app” ⇒ “manifests”. It describes the Android app.

For example, our “Hello Android” application, with an activity called MainActivity, has the following manifest (generated automatically by the Android Studio when the project was built):

<?xml version="1.0" encoding="utf-8"?>
<manifest xmlns:android=""
    package="com.example.helloandroid" >
        android:label="Hello Android"
        <activity android:name=".MainActivity">
                <action android:name="android.intent.action.MAIN" />
                <category android:name="android.intent.category.LAUNCHER" />
  • The <manifest> element specifies the package name.
  • The <manifest> contains one <application> element.
  • The <application> element specifies the icon, label (the app’s title) and theme of this application. It contains one ore more <activity> elements.
  • This application has one activity. The <activity> element declares its program name (“MainActivity” in current package “.“). It may contain <intent-filter>.
  • The <intent-filter> declares that this activity is the entry point (android.intent.action.MAIN) of the application. This activity is to be added to the application launcher (android.intent.category.LAUNCHER).