Cover image for Java Fundamentals , My Day 1–4 Learning Journey

Hashim HB

🚀After deciding to strengthen my programming fundamentals as part of my DevOps learning journey, I started learning Java.

I know these are basic concepts, but every experienced developer once started here. Building strong fundamentals makes learning advanced topics much easier later.

"Starting from scratch is never a weakness. Whether the concepts are basic or advanced, every lesson learned today becomes the building block for tomorrow's expertise."

In this blog, I'll summarize everything I learned during my first four days of Java.


Day 1 – Introduction to Java

Java is a high-level, object-oriented programming language designed to be platform-independent.

The famous Java principle is:

Write Once, Run Anywhere (WORA)

This is possible because Java programs are first compiled into bytecode, which can run on any operating system that has a Java Virtual Machine (JVM).


How Java Works

Java Source Code (.java)
          │
          ▼
      Java Compiler
        (javac)
          │
          ▼
      Bytecode (.class)
          │
          ▼
Java Virtual Machine (JVM)
          │
          ▼
 Machine Code
          │
          ▼
 Operating System
(Windows/Linux/macOS)

Enter fullscreen mode Exit fullscreen mode

The JVM converts bytecode into machine code that the operating system understands.


JDK vs JRE vs JVM

JVM (Java Virtual Machine)

  • Executes Java bytecode
  • Converts bytecode into machine code
  • Makes Java platform independent

JRE (Java Runtime Environment)

The JRE contains:

  • JVM
  • Core Java Libraries
  • Runtime files

Its purpose is simply to run Java applications.


JDK (Java Development Kit)

The JDK contains:

  • JRE
  • Java Compiler (javac)
  • Debugger
  • Documentation
  • Development tools

The JDK is used to develop Java applications.


IDE

IDE stands for Integrated Development Environment.

Popular Java IDEs include:

  • IntelliJ IDEA
  • Eclipse
  • VS Code
  • NetBeans

An IDE provides:

  • Code completion
  • Debugging
  • Syntax highlighting
  • Project management

First Java Program

public class Hello {

    public static void main(String[] args) {

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

    }

}

Enter fullscreen mode Exit fullscreen mode

Understanding the code

public

Accessible from anywhere.

class

Defines a class.

Hello

Class name.

main()

Entry point of every Java application.

System.out.println()

Prints output to the console.


Java Keywords

Keywords are reserved words already defined by Java.

Examples:

class
public
private
static
void
if
else
switch
while
for
return

Enter fullscreen mode Exit fullscreen mode

Keywords cannot be used as variable names.


Variables

A variable stores data in memory.

Example:

int age = 22;

Enter fullscreen mode Exit fullscreen mode

Rules for naming variables:

  • Case-sensitive
  • Must begin with a letter, _, or $
  • Cannot begin with a number
  • Cannot be a Java keyword
  • Prefer camelCase naming

Example:

int employeeAge;
String firstName;
double accountBalance;

Enter fullscreen mode Exit fullscreen mode


Primitive Data Types

Java has eight primitive data types.

Data Type Size Example
byte 1 byte 100
short 2 bytes 2000
int 4 bytes 100000
long 8 bytes 100000000L
float 4 bytes 12.5f
double 8 bytes 12.56
char 2 bytes 'A'
boolean 1 bit (logical) true

Example:

int age = 22;

float cgpa = 8.75f;

double salary = 25000.55;

char grade = 'A';

boolean isPassed = true;

Enter fullscreen mode Exit fullscreen mode

Notice the f after float values.

Without it, Java treats decimal numbers as double.


Type Conversion

Implicit Conversion (Widening)

Smaller data types are automatically converted into larger data types.

int age = 25;

long number = age;

Enter fullscreen mode Exit fullscreen mode

No data loss occurs.


Explicit Conversion (Casting)

Large data types can be converted into smaller ones.

int age = 150;

byte newAge = (byte) age;

Enter fullscreen mode Exit fullscreen mode

Output:

-106

Enter fullscreen mode Exit fullscreen mode

Since byte ranges only from -128 to 127, overflow occurs.


Comments

Single-line comment

// This is a comment

Enter fullscreen mode Exit fullscreen mode

Multi-line comment

/********************
This is
a multi-line comment
********************/

Enter fullscreen mode Exit fullscreen mode


Day 2 – Binary Number System

Computers understand only:

0
1

Enter fullscreen mode Exit fullscreen mode

Every value stored in memory is represented in binary.

Example:

int age = 12;

Enter fullscreen mode Exit fullscreen mode

Internally:

00000000 00000000 00000000 00001100

Enter fullscreen mode Exit fullscreen mode


Bytes and Bits

1 Byte = 8 Bits

short = 16 bits

int = 32 bits

long = 64 bits

Enter fullscreen mode Exit fullscreen mode


MSB and LSB

MSB

Most Significant Bit

In signed integers, the MSB represents the sign bit.

  • 0 → Positive
  • 1 → Negative (using two's complement representation)

LSB

Least Significant Bit

Represents the smallest place value.


Two's Complement

Negative numbers are represented using Two's Complement.

Steps:

  1. Invert all bits
  2. Add 1

Example:

5

Binary

00000101

Invert

11111010

Add 1

11111011

= -5

Enter fullscreen mode Exit fullscreen mode


Java Operators

Arithmetic Operators

+

-

*

/

%

Enter fullscreen mode Exit fullscreen mode

Example:

int a = 10;
int b = 3;

System.out.println(a+b);

System.out.println(a-b);

System.out.println(a*b);

System.out.println(a/b);

System.out.println(a%b);

Enter fullscreen mode Exit fullscreen mode


Assignment Operators

=

+=

-=

*=

/=

%=

Enter fullscreen mode Exit fullscreen mode


Relational Operators

==

!=

>

<

>=

<=

Enter fullscreen mode Exit fullscreen mode

Example:

System.out.println(5>3);

System.out.println(5==5);

System.out.println(5!=3);

Enter fullscreen mode Exit fullscreen mode


Logical Operators

&&

||

!

Enter fullscreen mode Exit fullscreen mode

Example

boolean a = true;

boolean b = false;

System.out.println(a && b);

System.out.println(a || b);

System.out.println(!a);

Enter fullscreen mode Exit fullscreen mode


Bitwise Operators

&

|

^

~

<<

>>

>>>

Enter fullscreen mode Exit fullscreen mode


Increment and Decrement

i++;

i--;

Enter fullscreen mode Exit fullscreen mode


Ternary Operator

condition ? value1 : value2;

Enter fullscreen mode Exit fullscreen mode

Example

int age = 18;

String result = age >= 18 ? "Adult" : "Minor";

System.out.println(result);

Enter fullscreen mode Exit fullscreen mode


Taking Input from User

Java provides the Scanner class.

import java.util.Scanner;

public class Main {

    public static void main(String[] args) {

        Scanner sc = new Scanner(System.in);

        System.out.print("Enter your age: ");

        int age = sc.nextInt();

        System.out.println(age);

        sc.close();

    }

}

Enter fullscreen mode Exit fullscreen mode

Useful methods:

nextInt()

nextFloat()

nextDouble()

next()

nextLine()

nextBoolean()

Enter fullscreen mode Exit fullscreen mode

Calling close() releases the underlying input resource when you're done using the scanner.


Day 3 – Conditional Statements

Java executes code depending on conditions.


if Statement

int age = 20;

if(age >= 18){

    System.out.println("Eligible");

}

Enter fullscreen mode Exit fullscreen mode


if-else

if(age >=18){

    System.out.println("Adult");

}

else{

    System.out.println("Minor");

}

Enter fullscreen mode Exit fullscreen mode


if-else-if

int marks = 85;

if(marks >=90){

    System.out.println("A");

}

else if(marks>=75){

    System.out.println("B");

}

else{

    System.out.println("C");

}

Enter fullscreen mode Exit fullscreen mode


Nested if

if(age>=18){

    if(age<60){

        System.out.println("Working");

    }

}

Enter fullscreen mode Exit fullscreen mode


Switch Statement

int day = 3;

switch(day){

case 1:

    System.out.println("Monday");

    break;

case 2:

    System.out.println("Tuesday");

    break;

case 3:

    System.out.println("Wednesday");

    break;

default:

    System.out.println("Invalid");

}

Enter fullscreen mode Exit fullscreen mode

Switch statements improve readability when checking many fixed values.


Day 4 – Loops

Loops execute a block of code repeatedly.


for Loop

for(int i = 1; i <= 5; i++){

    System.out.println(i);

}

Enter fullscreen mode Exit fullscreen mode

Structure:

Initialization

Condition

Update

Loop Body

Enter fullscreen mode Exit fullscreen mode

Example:

Sum of first n numbers

int n = 10;

int sum = n * (n + 1) / 2;

System.out.println(sum);

Enter fullscreen mode Exit fullscreen mode


while Loop

Used when the number of iterations is unknown.

int i = 1;

while(i <= 5){

    System.out.println(i);

    i++;

}

Enter fullscreen mode Exit fullscreen mode


do-while Loop

Executes at least once.

int i = 1;

do{

    System.out.println(i);

    i++;

}while(i <= 5);

Enter fullscreen mode Exit fullscreen mode


break

Stops the loop immediately.

for(int i=1;i<=10;i++){

    if(i==5)

        break;

    System.out.println(i);

}

Enter fullscreen mode Exit fullscreen mode


continue

Skips the current iteration.

for(int i=1;i<=5;i++){

    if(i==3)

        continue;

    System.out.println(i);

}

Enter fullscreen mode Exit fullscreen mode


Nested Loops

for(int i=1;i<=3;i++){

    for(int j=1;j<=3;j++){

        System.out.print("* ");

    }

    System.out.println();

}

Enter fullscreen mode Exit fullscreen mode

Output

* * *
* * *
* * *

Enter fullscreen mode Exit fullscreen mode


Labeled Break

outer:

for(int i=1;i<=3;i++){

    for(int j=1;j<=3;j++){

        if(i==2)

            break outer;

    }

}

Enter fullscreen mode Exit fullscreen mode

A labeled break exits multiple nested loops at once.


What's Next?

The next topic in my learning journey is Arrays in Java, where I'll explore:

  • Creating arrays
  • Accessing elements
  • Iterating using loops
  • Array operations
  • Multidimensional arrays

Stay tuned!


Final Thoughts

These first four days reminded me that programming isn't about memorizing syntax—it's about understanding how the language works behind the scenes.

From learning how Java compiles code into bytecode, to understanding primitive data types, operators, conditions, and loops, every concept lays the groundwork for more advanced topics like Object-Oriented Programming, Collections, and Multithreading.

I'm documenting this journey publicly to reinforce my own understanding and hopefully help others who are just getting started.

If you're also learning Java, feel free to connect and share your learning journey. Happy coding! 🚀