Getting to know the World in "Hello World"

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:
Primitive
Integer
Byte - Size: 1 byte , Range: -128 to 127
Short - Size: 2 bytes , Range: -32,768 to 32,767
Int - Size: 4 bytes , Range: -2,147,483,648 to 2,147,483,647
Long - Size: 8 bytes , Range: -9,223,372,036,854,775,808 to 9,223,372,036,854,775,807
Float
Double - Size: 4 bytes [ex - 3.45]
Float - Size: 8 bytes [ex - 4.35f] , more precision
Character - follows UNICODE , Size: 2 bytes
Boolean - true or false
Non - Primitive
String - sequence of characters
Array - fixed size container for same data type values
Class - a user defined blueprint to create objects
Collections - list, set, map etc.
Primitive | Non-Primitive |
Stores value directly | Stores reference to the object |
Fixed memory size | Memory usage varies |
Faster | Slightly slower due to reference |
Examples: int , char , boolean | Examples: 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
post increment - fetches value first and then increment
pre increment - increments and then fetches the value
Ternary Operator: condition ? expression_if_true : expression_if_false;
boolean isLoggedIn = true;
String message = isLoggedIn ? "Welcome back!" : "Please log in";
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
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!
Subscribe to my newsletter
Read articles from Nagraj Math directly inside your inbox. Subscribe to the newsletter, and don't miss out.
Written by
