Topic 2: Android Environment Set Up - Hello World
📖 5 min read · 🎯 beginner · 🧭 Prerequisites: android-operating-systems-architecture, reasons-for-mobile-first-applicationsmobile-operating-systems
Why this matters
Here's the thing — before you can build anything in Android, you need the right workspace set up on your machine. Most beginners skip past this step thinking it's just "installation stuff," but this is actually where your journey as an Android developer begins. Today we install Android Studio, create your very first project, and get your device to display those two words every developer writes first: Hello World. It sounds small, but the moment you see it appear on screen, something clicks — you realize you can actually build things. Let's make that happen.
What You'll Learn
- Install and configure Android Studio on Windows, Mac, or Linux
- Create a new Android project with the correct package name, language, and minimum API level
- Navigate the generated project structure and understand where key files live
- Modify
MainActivity.javaandactivity_main.xmlto display a "Hello World!" message - Create an Android Virtual Device (AVD) and run the app on the emulator
The Analogy
Setting up an Android development environment is like outfitting a kitchen before you cook your first meal. Android Studio is the kitchen itself — the space where everything happens. The Android SDK is your collection of knives, pots, and measuring cups; without them you cannot prepare anything. The emulator is a test plate: you plate the food there first to see how it looks before serving it to a real guest. And MainActivity.java is your recipe card — the first thing you write down so you never forget the steps. You would not try to cook in an empty room with no tools; likewise, you cannot ship an app without this foundation in place.
Chapter 1: Installing Android Studio
Android Studio is the official IDE for Android development, built on IntelliJ IDEA. Download it from the official page and follow the platform-specific steps below.
Download: Visit the Android Studio download page and grab the latest stable release for your OS.
Install by platform:
- Windows — Run the downloaded
.exefile and follow the installation wizard. - Mac — Open the downloaded
.dmgfile and drag Android Studio into the Applications folder. - Linux — Extract the downloaded
.tar.gzfile, then run thestudio.shscript from thebin/directory.
Initial setup:
- Launch Android Studio.
- The setup wizard will detect missing components and prompt you to install the necessary SDKs and build tools. Accept the defaults and let it finish — this may take a few minutes on the first run.
Chapter 2: Creating a New Project
With Android Studio running, you are ready to scaffold a project.
- Click "Start a new Android Studio project" on the welcome screen.
- Choose the "Empty Activity" template and click "Next".
- Fill in the project details:
| Field | Value |
|---|---|
| Name | HelloWorld |
| Package name | com.example.helloworld |
| Save location | Any directory you prefer |
| Language | Java |
| Minimum API level | API 16: Android 4.1 (Jelly Bean) or higher |
- Click "Finish". Android Studio will generate the project and sync Gradle.
Chapter 3: Exploring the Project Structure
Once generation completes, the project tree looks like this:
HelloWorld/
├── app/
│ ├── build/
│ ├── libs/
│ ├── src/
│ │ ├── androidTest/
│ │ │ └── java/
│ │ │ └── com/example/helloworld/
│ │ ├── main/
│ │ │ ├── java/
│ │ │ │ └── com/example/helloworld/
│ │ │ │ └── MainActivity.java
│ │ │ ├── res/
│ │ │ │ ├── layout/
│ │ │ │ │ └── activity_main.xml
│ │ │ │ ├── mipmap/
│ │ │ │ └── values/
│ │ │ │ └── strings.xml
│ │ │ └── AndroidManifest.xml
│ │ └── test/
│ │ └── java/
│ │ └── com/example/helloworld/
│ ├── build.gradle
│ └── proguard-rules.pro
├── build/
├── .gradle/
├── .idea/
├── gradle/
├── gradle.properties
├── gradlew
├── gradlew.bat
├── settings.gradle
└── build.gradle
Key files to know right now:
MainActivity.java— the entry-point Activity; this is where your app's first screen logic lives.activity_main.xml— the layout file that describes what the screen looks like.AndroidManifest.xml— declares app components, permissions, and the launch Activity.app/build.gradle— controls dependencies and compile settings for the app module.strings.xml— centralized string resources; keeps UI text out of Java code.
Chapter 4: Writing the "Hello World" Application
Modify MainActivity.java
Open app/src/main/java/com/example/helloworld/MainActivity.java and replace its contents with:
package com.example.helloworld;
import android.os.Bundle;
import androidx.appcompat.app.AppCompatActivity;
import android.widget.TextView;
public class MainActivity extends AppCompatActivity {
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
// Find the TextView in the layout and set the text to "Hello World!"
TextView textView = findViewById(R.id.textView);
textView.setText("Hello World!");
}
}
What is happening here:
AppCompatActivitygives you backward-compatible Activity features.onCreateis called when the Activity is first created — this is your setup hook.setContentView(R.layout.activity_main)inflates the XML layout into the screen.findViewById(R.id.textView)retrieves theTextViewdeclared in the layout by its ID.setText("Hello World!")pushes the string onto the view at runtime.
Modify activity_main.xml
Open app/src/main/res/layout/activity_main.xml and replace it with:
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:orientation="vertical"
android:padding="16dp">
<TextView
android:id="@+id/textView"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="Hello World!"
android:textSize="24sp" />
</LinearLayout>
Key attributes:
android:id="@+id/textView"— declares an ID so Java code can reference this view viaR.id.textView.android:layout_width="match_parent"on theLinearLayout— fills the full screen width.android:layout_width="wrap_content"on theTextView— sizes to its text content.android:textSize="24sp"—sp(scale-independent pixels) respects the user's font-size accessibility setting.
Chapter 5: Running the Application
Configure the Emulator
Before running, you need a virtual device:
- Click the "AVD Manager" icon in the toolbar (a smartphone icon with an Android logo).
- Click "Create Virtual Device".
- Select a device definition — for example, Pixel 3 — and click "Next".
- Select a system image — for example, Q, API Level 29 — and click "Next".
- Click "Finish" to create the AVD.
- In the AVD Manager, click the play button next to your new emulator to start it.
Run the App
- Click the "Run" button in the toolbar (the green play triangle).
- Select your running emulator from the device list and click "OK".
The emulator will launch your app. You should see the text "Hello World!" rendered at 24sp on the screen.
sequenceDiagram
participant Dev as Developer
participant AS as Android Studio
participant Gradle as Gradle Build
participant AVD as Emulator (AVD)
Dev->>AS: Click Run
AS->>Gradle: Compile Java + inflate XML
Gradle-->>AS: APK built
AS->>AVD: Install APK
AVD-->>Dev: App launches → "Hello World!" on screen
🧪 Try It Yourself
Task: Change the greeting text and font size without touching MainActivity.java.
- Open
activity_main.xml. - Change
android:text="Hello World!"toandroid:text="Hello, Vizag!". - Change
android:textSize="24sp"toandroid:textSize="32sp". - Run the app again on the emulator.
Success criterion: The emulator screen shows "Hello, Vizag!" in larger text — and you did not change a single line of Java code. This demonstrates that layout and logic are intentionally separated.
<TextView
android:id="@+id/textView"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="Hello, Vizag!"
android:textSize="32sp" />
🔍 Checkpoint Quiz
Q1. Why does the TextView use sp for textSize instead of dp or px?
A) sp is the only unit Android supports for text
B) sp scales with the user's system font-size accessibility setting
C) sp is faster to render than dp
D) sp stands for "screen pixels" and maps 1:1 to physical pixels
Q2. Given this code:
TextView textView = findViewById(R.id.textView);
textView.setText("Hello World!");
What would happen if you changed the XML android:id from @+id/textView to @+id/label but left the Java code unchanged?
A) The app compiles and runs fine — Android resolves IDs at runtime
B) The app crashes at runtime with a NullPointerException because R.id.textView no longer exists
C) Android Studio shows a compile error because R.id.textView is undefined
D) The setText call is silently ignored
Q3. What is the role of AndroidManifest.xml in the project you just created?
A) It stores all string resources used in layouts
B) It declares app components, permissions, and which Activity launches first
C) It controls Gradle build dependencies
D) It defines the visual layout of each screen
Q4. You want to support as many Android devices as possible. Your project sets Minimum API level: API 16. A teammate suggests lowering it to API 1. What is the practical trade-off of using a very low minimum API level?
A) Lower API levels allow more users to install the app but restrict you from using newer APIs without compatibility checks
B) Lower API levels make the APK smaller
C) Lower API levels speed up the Gradle build
D) There is no trade-off — lower is always better
A1. B) sp scales with the user's system font-size setting, making your app respect accessibility preferences. dp is device-independent but does not scale with font size; px is raw pixels and varies across screens.
A2. C) R.id.textView is generated at compile time from the XML IDs. Renaming the XML ID to @+id/label removes R.id.textView from the generated R class, causing a compile error — not a runtime crash.
A3. B) AndroidManifest.xml is the app's declaration file: it registers Activities, Services, permissions, and specifies the launcher Activity via the MAIN/LAUNCHER intent filter.
A4. A) A lower minimum API level means more devices can install the app, but you cannot freely call newer APIs — you must use Build.VERSION.SDK_INT checks or compatibility libraries. API 1 is effectively unusable because modern libraries themselves require API 14+.
🪞 Recap
- Android Studio is the official IDE; install it via the platform-specific installer and complete the setup wizard to get the SDK.
- A new project needs a package name, a language (Java here), and a minimum API level — these cannot be easily changed later.
- The project tree separates source code (
java/), layouts (res/layout/), and configuration (AndroidManifest.xml) by design. MainActivity.javawires logic to layout viasetContentViewandfindViewById;activity_main.xmlowns the visual structure.- The AVD Manager lets you create emulated devices so you can test without a physical phone.
📚 Further Reading
- Official Android Studio docs — the source of truth on IDE features and setup
- Android API levels reference — maps API numbers to Android versions and market share data
- LinearLayout guide — deep dive on the layout container used in this lesson
- ⬅️ Previous: Reasons for Mobile-First Applications & Mobile Operating Systems
- ➡️ Next: Introduction to Android OS & Java Programming Language