DEV Community

Cover image for Day 1 of My DSA Journey: From Flowcharts to My First Java Code (And an Elegant Math Trick!)
Mibhur Mahajan
Mibhur Mahajan

Posted on • Originally published at Medium

Day 1 of My DSA Journey: From Flowcharts to My First Java Code (And an Elegant Math Trick!)

The journey of a thousand miles begins with a single step — or in the case of a Computer Science student, a single line of code.

I’ve officially kicked off my Data Structures and Algorithms (DSA) public learning journey by diving into Kunal Kushwaha’s famous Java playlist. Going into Lecture 1, I thought I’d be immediately overwhelmed by complex Java syntax. Instead, I spent the first half of my day drawing shapes and the second half uncovering why Java is such a powerhouse language.

Here is everything I learned on Day 1, including a brilliant prime-number optimization trick that absolutely blew my mind.

Part 1: Thinking in Pictures (Flowcharts & Pseudocode)
Before you write code for a computer, you have to clear up the logic in your own head. That’s where Flowcharts (visual maps) and Pseudocode (writing logic in plain English) come in.

I started by learning the core toolkit of flowchart building blocks:

🛑 Oval: Start / Stop
📥 Parallelogram: Input / Output (getting data or displaying it)
⚙️ Rectangle: Processing (doing calculations like math operations)
💎 Diamond: Conditions (asking True/False questions to split the logic path)
Warming Up with Simple Logic
To get comfortable, I mapped out a few fundamental problems:

The Hello Name Flowchart: A simple flow that takes a name as an input and outputs "Hello {Name}".
The Salary Bonus Problem: A slightly more advanced flow with a condition. If a user inputs a salary greater than 10,000, they get a 2,000 bonus. Otherwise, they only get a 1,000 bonus.
Visualizing the path of execution using these arrows makes it incredibly obvious how data moves through a program.

🛑 The “Aha!” Moment: Optimizing the Prime Number Problem
Things got real when I tried to design a flowchart and pseudocode to check if a number is Prime or not.

The standard approach is straightforward: you start a counter at $c = 2$ and check if the number can be divided perfectly (num % c == 0). If it can, it's not prime. If it can't, you increment $c$ by 1 (c = c + 1) and loop back, checking every single number all the way up to num - 1.

The Problem? It’s slow. Very slow for large numbers.
But then came the optimization insight that made everything click. Let’s look at the factors of the number 36:

1 * 36 = 36
2 * 18 = 36
3 * 12 = 36
4 * 9 = 36
6 * 6 = 36
— — — — — — — — — (The Mirror Line)
9 * 4 = 36 (Ignore! We already checked 4 x 9)
12 * 3 = 36 (Ignore!)
18 * 2 = 36 (Ignore!)
Notice how past 6 times 6(the square root of 36), the factors just repeat themselves in reverse order? This means we don’t have to check all the way to the end!
By changing our loop condition from while c < num to while c * c <= num (checking only up to the square root of the number), we drastically reduce the work the computer has to do. For a number like 17, instead of checking up to 16, we only check 2, 3, and 4. That is pure efficiency!

Part 2: What Happens Under the Hood of Java?
After conquering the logic, it was time to understand how Java actually talks to our computers. I mapped out the entire execution pipeline in my notes:

SOURCE CODE — —COMPILER — → BYTE CODE(.CLASS FILE) — — INTERPRETER— → MACHINE CODE (0 & 1)

The Secret to Java’s Superpower: Platform Independence
If you write code in C or C++, the compiler converts it into an .exe file tailored specifically to your computer's architecture. That makes C/C++ platform-dependent.

Java does things differently. The Java compiler converts your code into Bytecode (a .class file). This bytecode doesn't care what operating system you are using. Any computer with a Java Virtual Machine (JVM) can read it.

💡 Key Takeaway: Java as a language is platform-independent because its bytecode can run anywhere, but the JVM itself is platform-dependent because it must be custom-built for Windows, Mac, or Linux to translate that bytecode into native machine code.

Part 3: Writing My First Java Program!
To wrap up Day 1, I finally opened the IDE and wrote the classic starter code:

Java

public class Main {
public static void main(String[] args) {
System.out.println("Hello World!");
}
}
A Quick Trick I Learned About Strings
While learning about data inputs, I noted two crucial details that often trip up beginners:

Strings are not primitive data types. Unlike integers or characters, a String can be broken down into smaller individual data types (a sequence of char types).
input.next() vs input.nextLine(): If you use next(), Java will only read the first word you type before a space. If you want to grab the entire sentence, you have to use nextLine().
Wrapping Up Day 1
Day 1 taught me that coding is 80% problem-solving logic and only 20% syntax. Taking the time to optimize a prime number loop on paper before writing a single line of Java showed me exactly why studying DSA is so important.

What’s coming next: Tomorrow, I will be moving past the setup phase and diving deeper into Java variables, primitive data types, and taking clean user inputs.

Are you studying DSA right now or thinking about starting? Let’s keep each other accountable! Leave a comment below with your favorite coding shortcut or what language you’re learning.

CONTACT ME :

Email : mhjnmibhur23@gmail.com

LinkedIn : https://www.linkedin.com/in/mibhurmahajan

Twitter : https://x.com/mhjnmibhur05

Top comments (0)