Wednesday, 30 April 2025

Intro to Java Methods – Write Once, Use Many Times

 Tired of repeating the same code again and again? Methods to the rescue! They let you wrap code in a reusable block.


๐Ÿงฑ What is a Method?

A method is a mini-program inside your program. It does a specific task.

Example:

public static void sayHello() {

    System.out.println("Hello, world!");

}

▶️ Calling a Method

Once defined, you can use it like this:

sayHello();

// in your main method

Thursday, 24 April 2025

Math.random() in Java

 

Get Whole Numbers

You can use it to get random integers too:

int num = (int)(Math.random() * 10); // 0 to 9


Mini Challenge: Dice Game

Write a program that:

  • Rolls two dice

  • Adds them together

  • Prints “You rolled: X + Y = Z”

Tuesday, 22 April 2025

Introduction to Java Arrays

 

In Java, an array lets you store multiple values in a single variable. Super useful when you’re working with a list of items!

//Structure of arrays in java

int[] numbers = {10, 20, 30, 40};

//Accessing Elements

System.out.println(numbers[0]); // 10

System.out.println(numbers[2]); // 30


๐Ÿ’ฅ Array Properties

  • Fixed size (you can’t change its length)

  • Index starts at 0

  • numbers.length gives you the number of elements


๐Ÿงช Challenge

Create an array of your 5 favorite numbers and print them all using a loop.



Monday, 21 April 2025

Loops in Java: Meet the While Loop

 

Loops in Java: Meet the While Loop

In Java, loops are used to repeat a block of code as long as a certain condition is true. One of the simplest types of loops is the while loop.


The Syntax

while (condition) {

    // code to repeat

}

As long as the condition is true, the code inside the loop keeps running.

Sunday, 20 April 2025

If-Else Explained (JAVA)

 

What if your program needs to make choices? Like checking if someone is old enough to vote, or if a number is positive or negative?

That’s where if-else statements come in — they let your code decide what to do based on a condition.

//Basic If-Else Structure

if (condition) {

    // do this if condition is true

} else {

    // do this if condition is false

}



//Example 1 : Even or Odd

int number = 7;

if (number % 2 == 0) {
    System.out.println("The number is even.");
else {
    System.out.println("The number is odd.");
}

Saturday, 19 April 2025

Taking User Input in Java (with Scanner)

 

๐Ÿงช Step 1: Import the Scanner

Before using it, you need to import it at the top of your code:

import java.util.Scanner;


✏️ Example: Asking for a Name
import java.util.Scanner; public class InputExample { public static void main(String[] args) { Scanner input = new Scanner(System.in); // Create Scanner System.out.print("What's your name? "); String name = input.nextLine(); // Read a line of text System.out.println("Hello, " + name + "!"); } }




Friday, 18 April 2025

Understanding Variables and Data Types in Java

 

๐Ÿง  What Is a Variable?

Think of a variable as a container that stores data. It could be a number, a word, or even a true/false value.


Common Data Types In Java

Data Type            Example                    What it stores
int                        int age = 15;              Whole Numbers
double                 double d = 1.2;          Decimal Numbers
String                  String s = "TOM";     Text(Always in quotes)
boolean               boolean i = true;         True or False
char                     char grade = 'A';         A single character(in single quotes)

//Sample Code

public class VariableDemo {
    public static void main(String[] args) {
        int age = 15;
        double score = 95.5;
        String name = "Aarav";
        boolean isCool = true;
        char grade = 'A';

        System.out.println("Name: " + name);
        System.out.println("Age: " + age);
        System.out.println("Score: " + score);
        System.out.println("Cool? " + isCool);
        System.out.println("Grade: " + grade);
    }
}

//output
Name: Aarav  
Age: 15  
Score: 95.5  
Cool? true  
Grade: A  


Thursday, 17 April 2025

Getting Started with Java: First Program (Hello, World!)

 

๐Ÿง  What Is "Hello, World!"?

It's a basic program that does one thing: prints the message Hello, World! to the screen. But more importantly, it introduces you to the structure of a Java program.

//Code

public class HelloWorld

{

    public static void main(String[] args)

    {

          System.out.println("Hello World!");

     }

}


๐Ÿ›  How to Run It

  1. Open a code editor (like VS Code or just Notepad).

  2. Save the file as HelloWorld.java.

  3. Open Command Prompt (or Terminal).

Wednesday, 16 April 2025

Why I Started Learning CS?

My interest in CS started with curiosity. I always wondered how apps, websites, and games were made. Once I began learning Java in AP Computer Science A, I realized how powerful and creative coding really is. It’s like solving puzzles but with endless possibilities.

Through CS with Aarav, I’ll share what I learn, the projects I build, and the tips I wish I knew earlier. Whether you're just starting out or curious about CS, I hope this blog helps you in your journey too!

Let’s code something awesome.


๐Ÿš€ Top 3 Java Projects Every Beginner Should Build (With Code Ideas)

 Tired of just printing "Hello World"? It’s time to build something real. ๐Ÿ’ป If you're learning Java and want to stand out, ...