free web tracker
Course Content
Java Programming Basics for Android
Learn the basics of Java programming for Android app development using Android Studio. This guide covers key concepts like variables, loops, and classes to help you start building your first Android apps with confidence. Perfect for beginners!
0/10
User Interaction and App Logic
Learn how to make your app respond to users! This section covers handling clicks, getting input, showing messages, switching screens, and saving simple data. A perfect start to build interactive Android apps with real logic.
0/10
Advanced Layouts and Components
Learn to build modern Android UIs using advanced layouts like RecyclerView, CardView, TabLayout, and more. This section helps beginners create beautiful, interactive, and user-friendly app interfaces step by step.
0/10
Media and Resources
Learn how to manage media and resources in Android Studio. This section covers adding audio, images, video, using drawables, custom fonts, and handling runtime permissions—essential for building rich, engaging Android applications.
0/4
Mastering Java Android Development – Beginner

In Android development using Java, conditional statements are essential for controlling app behavior based on different conditions. Here’s a beginner-friendly guide on how to use if, else, and switch statements effectively in Android Studio.

1. Using if Statement

The if statement allows your app to execute a block of code only if a specified condition is true.

int score = 80;

if (score > 70) {
    Log.d("Result", "You passed!");
}

2. Using if-else Statement

When you want to perform one action if a condition is true and another action if it is false, use if-else.

int score = 65;

if (score > 70) {
    Log.d("Result", "You passed!");
} else {
    Log.d("Result", "You failed!");
}

3. Using if-else if-else Statement

This is useful when you have multiple conditions to evaluate.

int score = 85;

if (score >= 90) {
    Log.d("Result", "Excellent");
} else if (score >= 75) {
    Log.d("Result", "Good");
} else if (score >= 60) {
    Log.d("Result", "Pass");
} else {
    Log.d("Result", "Fail");
}

4. Using switch Statement

The switch statement is best when you want to compare one variable against multiple constant values.

int day = 3;

switch (day) {
    case 1:
        Log.d("Day", "Monday");
        break;
    case 2:
        Log.d("Day", "Tuesday");
        break;
    case 3:
        Log.d("Day", "Wednesday");
        break;
    default:
        Log.d("Day", "Unknown day");
        break;
}

Tips:

    • Use if-else for range-based conditions (e.g., score > 80).
    • Use switch for exact value matching (e.g., menu options, day number).
    • Always include a default case in switch statements to handle unexpected values.

Conclusion

Mastering if, else, and switch statements in Java will help you control the flow of your Android apps and make decisions based on user inputs or app data. These statements form the core of logical thinking in programming.