Review Day: Core Concepts Review

Day 14 Java review: revisit core concepts like variables, operators, loops, arrays, and methods with examples and mini exercises.
Review Day: Core Concepts Review

Day 14 is a review day. So far, you have learned the foundations of Java programming: variables, data types, operators, conditionals, loops, arrays, and methods. Today, you will revisit these topics with short explanations and mini exercises to strengthen your understanding.

1. Variables & Data Types

Variables store data of specific types (int, double, boolean, char, String). Practice by declaring variables and printing their values.


int age = 25;
double price = 19.99;
boolean isJavaFun = true;
char grade = 'A';
String name = "Alice";

System.out.println(age + ", " + price + ", " + isJavaFun + ", " + grade + ", " + name);

2. Operators

Review arithmetic, assignment, and comparison operators by writing simple expressions.


int x = 10, y = 5;
System.out.println("Sum: " + (x + y));
System.out.println("Comparison: " + (x > y));

3. Conditional Statements

if-else and switch help in decision-making.


int score = 85;
if (score >= 90) {
    System.out.println("Grade A");
} else if (score >= 75) {
    System.out.println("Grade B");
} else {
    System.out.println("Grade C");
}

4. Loops

Loops repeat tasks. Practice for, while, and do-while.


for (int i = 1; i <= 5; i++) {
    System.out.println("Count: " + i);
}

5. Arrays

Arrays hold multiple values. Loop through arrays with for and for-each.


int[] numbers = {1, 2, 3, 4, 5};
for (int num : numbers) {
    System.out.println(num);
}

6. Methods

Methods make code reusable. Review void methods, parameters, and return values.


static int square(int n) {
    return n * n;
}

public static void main(String[] args) {
    System.out.println(square(4));
}

Mini Exercises

  • Write a program to check if a number is even or odd.
  • Print a multiplication table using a loop.
  • Store 5 names in an array and print them.
  • Create a method that returns the maximum of two numbers.

Summary

This review ties together all the core Java concepts you’ve learned so far. If you feel confident, you are ready to move on to Object-Oriented Programming (OOP), which is the foundation of modern Java development.

إرسال تعليق