Getting to know the World in "Hello World"

Nagraj MathNagraj Math
4 min read

It is 10 minutes to 11pm, dated 6th of May 2025.

It is time to learn the World of Java, led by our Bald Sensei - Navin Reddy and his Bald apprentice - me.

Why Java?

[Answers from Reddit]

Java is a mature, well developed, well maintained, high-level programming language that has plenty of useful tooling.

Java is vanilla. It's not shiny or new or trendy, but it works and it works in just about everywhere. It's not as low level as C but it's not as high level as python. As a result, Java can be a good fit anywhere.

[Sensei’s notes]

learning Java makes other languages easy to learn;

readable;

maintainable;

enterprise preferred;

WORA - Write Once, Read Anywhere, Platform - independent;

Multi-threading, API handling, Exception Handling

Where to write Java?

Option 1: Code Editors - Notepad++, VS Code

Option 2: IDEs (Integrated Development Environments) - IntelliJ IDEA, Eclipse

Difference: Code editors focus on editing code, while IDEs provide a broader suite of tools for the entire development process.

How Java runs?

How to write Java?

public class Hello {
    public static void main (String args[]) {
             System.out.println(“It’s just the beginning”);
    }
}

public: JVM needs to access the class

static: if not there, JVM will have to instantiate the class which isn’t possible at the starting point

void: main method is not expected to return anything to JVM

main: specifies that it is the entry point to our program

String args[]: can pass String data type arguments to our function

Bald Sensei says

“We write programs to solve real world problems through virtual word”

as such we need to represent real world like data through variables, entities through objects (OOPS concept) and their properties, methods etc.

Data types

Java is a strongly typed language - we need to specify the data type of our variable because each data type has its own “box”, associated with size (in bytes) and some methods accessible to specific data types.

2 types:

  1. Primitive

    1. Integer

      1. Byte - Size: 1 byte , Range: -128 to 127

      2. Short - Size: 2 bytes , Range: -32,768 to 32,767

      3. Int - Size: 4 bytes , Range: -2,147,483,648 to 2,147,483,647

      4. Long - Size: 8 bytes , Range: -9,223,372,036,854,775,808 to 9,223,372,036,854,775,807

    2. Float

      1. Double - Size: 4 bytes [ex - 3.45]

      2. Float - Size: 8 bytes [ex - 4.35f] , more precision

    3. Character - follows UNICODE , Size: 2 bytes

    4. Boolean - true or false

  2. Non - Primitive

    1. String - sequence of characters

    2. Array - fixed size container for same data type values

    3. Class - a user defined blueprint to create objects

    4. Collections - list, set, map etc.

PrimitiveNon-Primitive
Stores value directlyStores reference to the object
Fixed memory sizeMemory usage varies
FasterSlightly slower due to reference
Examples: int, char, booleanExamples: String, Array, List

Type Conversion and Casting

Implicit or Automatic Conversion occurs when we try to perform operations on different data types by “Type Promotion”.

        int a = 4;
        int b = 2;
        float c = (a + b);
        System.out.println(c); //Output is 6.0

Explicit Conversion called Casting is when we try to change the data type of the variable. Lossy conversions as some data might get lost.

        int a = 4;
        double b = 2.33;
        int c = (int)(a + b);
        System.out.println(c); //Ouput is 6 but actual sum is 6.33

*While casting modulus operation is performed on the variables*

Additional bits of Wisdom

  1. post increment - fetches value first and then increment

  2. pre increment - increments and then fetches the value

  3. Ternary Operator: condition ? expression_if_true : expression_if_false;

        boolean isLoggedIn = true; 
        String message = isLoggedIn ? "Welcome back!" : "Please log in";
  1. Looping Statements:

    For Loop: Known number of iterations, Loops with counter (for (i=0; i<n; i++))

    While Loop: Unknown iterations (condition-based), Waiting for event/user input

    Do while Loop: At least one-time execution, Menus, retries, validation

  2. Conditional Statements: IF, IF-ELSE, IF-ELSE IF-ELSE, SWITCH

Cool Tricks

        int c = 0b101; //byte representation
        System.out.println(c); //Output is 5

        c = 0xf1; //hexadecimal representation
        System.out.println(c); //Output is 241
        char c = 'a';
        c++;
        System.out.println(c); //Output is 'b'
        int c = 10_00_000; //for readability
        System.out.println(c); //Output is 1000000

With that our day 1 ends, thank you Bald Sensei!

It saddens me that I had been very formal with my notes but these were the basics - getting to know the World before we dive into adventures.

So stay with me!

0
Subscribe to my newsletter

Read articles from Nagraj Math directly inside your inbox. Subscribe to the newsletter, and don't miss out.

Written by

Nagraj Math
Nagraj Math