**1. What is Java?
**Definition
Java is a high-level, object-oriented, class-based programming language designed to be portable across different operating systems.
Java was originally developed at Sun Microsystems and is now maintained by Oracle and the broader Java community.
The famous idea associated with Java is:
Write Once, Run Anywhere.
For example, you can write:
System.out.println("Hello Java");
and compile it into Java bytecode.
That bytecode can run on different operating systems as long as the appropriate JVM is available.
*2. Why is Java called platform-independent?
*
Suppose you write a Java program on Windows:
Java Code
↓
Java Compiler
↓
Bytecode
↓
.class file
That .class file can then run through a JVM on:
Windows
Linux
macOS
The flow is:
Java Code
│
▼
Java Compiler
│
▼
Bytecode
│
┌─────────┼─────────┐
▼ ▼ ▼
Windows Linux macOS
JVM JVM JVM
That's the basic reason Java is considered platform-independent.
*3. JDK vs JRE vs JVM
*
This is one of the most important Java fundamentals.
People often confuse these three.
JVM
Definition
JVM (Java Virtual Machine) is the runtime environment that executes Java bytecode.
Think:
.class file
↓
JVM
↓
Program runs
The JVM is responsible for things such as:
executing bytecode
memory management
garbage collection
runtime checks
**4. JRE
**Definition
JRE (Java Runtime Environment) provides the environment required to run Java applications.
Conceptually:
JRE
│
├── JVM
└── Java runtime libraries
So:
JRE = JVM + libraries needed to run Java applications
**5. JDK
**Definition
JDK (Java Development Kit) provides the tools required to develop Java applications.
Conceptually:
JDK
│
├── JRE
│ └── JVM
│
└── Development tools
├── javac
├── java
├── javadoc
└── other tools
So the easy relationship is:
JDK
↓
JRE
↓
JVM
Easy memory trick
JDK → Develop
JRE → Run
JVM → Execute
- Your first Java program
Create:
HelloWorld.java
Write:
public class HelloWorld {
public static void main(String[] args) {
System.out.println("Hello Java");
}
}
Output:
Hello Java
Now let's understand every single part.
**7. public
**public class HelloWorld
public is an access modifier.
It means that the class can be accessed from outside its package.
Don't worry about packages yet. We'll cover them later.
For now remember:
public → accessible from other classes
**8. class
**class HelloWorld
A class is a blueprint/template for creating objects.
For example:
Car
could be a class.
It can describe:
Properties:
color
model
speed
Behavior:
start()
stop()
accelerate()
We'll go deeply into classes when we reach OOP.
**9. HelloWorld
**class HelloWorld
This is the class name.
Java convention:
ClassName
uses PascalCase.
Examples:
Student
Employee
BankAccount
PaymentService
UserController
*10. main()
*
This is extremely important.
public static void main(String[] args)
The main() method is the entry point of a traditional Java application.
When the JVM starts your application, it looks for the appropriate main method.
Think:
Program starts
↓
main()
↓
Rest of your code executes
**11. System.out.println()
**System.out.println("Hello Java");
This prints text to the console.
For example:
System.out.println("Hello");
System.out.println("Welcome");
System.out.println(100);
Output:
Hello
Welcome
100
*12. Java Variables
*
Now we get into actual programming.
Definition
A variable is a named memory location used to store a value.
Example:
int age = 25;
Think of it like a labelled box:
┌───────────────┐
│ age │
│ │
│ 25 │
└───────────────┘
Here:
int → data type
age → variable name
25 → value
*13. Data Types
*
Java has two broad categories:
Data Types
│
├── Primitive
│
└── Reference
*14. Primitive Data Types
*
Java has 8 primitive data types:
byte
short
int
long
float
double
char
boolean
These are fundamental built-in types.
int
Used for whole numbers.
int age = 25;
Examples:
int count = 100;
int salary = 50000;
int marks = 85;
double
Used for decimal numbers.
double price = 99.99;
Example:
double temperature = 36.5;
char
Stores a single character.
char grade = 'A';
Notice:
'A'
uses single quotes.
boolean
Stores:
true
false
Example:
boolean isLoggedIn = true;
This is extremely common in real applications.
For example:
boolean isAdmin = false;
*15. Reference Types
*
Reference types can refer to objects.
Examples:
String name = "Srivalli";
int[] numbers = {10, 20, 30};
Student student = new Student();
We'll learn objects and references properly when we reach OOP.
*16. Operators
*
Operators allow you to perform operations.
Arithmetic operators
+
*
/
%
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);
Output:
13
7
30
3
1
Notice:
10 / 3
with two integers gives:
3
not 3.333....
*17. Comparison Operators
*
Used to compare values.
<
<=
!=
Example:
int age = 25;
System.out.println(age >= 18);
Output:
true
*18. Logical Operators
*
The main ones are:
&& AND
|| OR
! NOT
Example:
int age = 25;
boolean hasId = true;
if (age >= 18 && hasId) {
System.out.println("Allowed");
}
Both conditions must be true.
*19. Conditional Statements
*
Now Java can make decisions.
if
int age = 20;
if (age >= 18) {
System.out.println("Adult");
}
Flow:
age >= 18?
│
┌──┴──┐
YES NO
│ │
▼ ▼
Adult Nothing
**20. if-else
**int age = 16;
if (age >= 18) {
System.out.println("Adult");
} else {
System.out.println("Minor");
}
Output:
Minor
*21. Real-world example
*
Imagine login:
boolean loggedIn = true;
if (loggedIn) {
System.out.println("Show dashboard");
} else {
System.out.println("Show login page");
}
This is exactly the type of logic you'll eventually use in backend development.
For example:
User request
↓
Is authenticated?
↓
YES ───→ Dashboard/API response
NO ───→ Unauthorized
*22. Loops
*
Loops repeat code.
Suppose you want:
Hello
Hello
Hello
Hello
Hello
Instead of:
System.out.println("Hello");
System.out.println("Hello");
System.out.println("Hello");
System.out.println("Hello");
System.out.println("Hello");
use a loop.
**23. for loop
**for (int i = 0; i < 5; i++) {
System.out.println("Hello");
}
Flow:
i = 0
↓
condition?
↓
true
↓
print
↓
i++
↓
condition?
↓
...
↓
i = 5
↓
false
↓
STOP
Output:
Hello
Hello
Hello
Hello
Hello
*24. Real-time example — Display users
*
Suppose:
String[] users = {
"Alice",
"Bob",
"Charlie"
};
You can loop:
for (int i = 0; i < users.length; i++) {
System.out.println(users[i]);
}
Output:
Alice
Bob
Charlie
This becomes very useful when working with collections and database results.
**25. Arrays
**Definition
An array is a fixed-size collection of elements of the same type.
Example:
int[] marks = {80, 90, 75, 88};
Visual:
Index: 0 1 2 3
↓ ↓ ↓ ↓
┌────┬────┬────┬────┐
marks = │ 80 │ 90 │ 75 │ 88 │
└────┴────┴────┴────┘
Important:
Java array indexes start at 0.
So:
marks[0] → 80
marks[1] → 90
marks[2] → 75
marks[3] → 88
- Methods Definition
A method is a block of code that performs a specific task and can be called when needed.
Example:
static void greet() {
System.out.println("Hello!");
}
Call it:
greet();
Output:
Hello!
- Methods with parameters static void greet(String name) { System.out.println("Hello " + name); }
Call:
greet("Srivalli");
Output:
Hello Srivalli
Here:
name
is the parameter.
**28. Methods with return values
**static int add(int a, int b) {
return a + b;
}
Use:
int result = add(10, 20);
System.out.println(result);
Output:
30
Flow:
10 + 20
↓
add()
↓
return 30
↓
result
*29. The foundation of Java OOP
*
Everything we've covered so far prepares you for the biggest part of Java:
Object-Oriented Programming
The four major OOP concepts are:
OOP
│
├── Encapsulation
├── Inheritance
├── Polymorphism
└── Abstraction
But before these four, you need to understand:
Class
Object
Constructor
For example:
class Car {
String color;
int speed;
void drive() {
System.out.println("Car is driving");
}
}
Create an object:
Car car = new Car();
Now:
Class
↓
Car
↓
Blueprint
Object
↓
car
↓
Actual instance
You can then do:
car.color = "Red";
car.speed = 100;
car.drive();
Top comments (1)
Nice introduction for beginners 👍
One small detail that might be worth mentioning in a future part: the classic
JDK → JRE → JVM
model is great for explaining the concepts, but modern Java distributions have changed this picture a little.
Since the Java 9 module system, and especially with modern JDK releases, applications can use jlink to build custom runtime images containing only the modules they actually need. Separate JRE distributions are also much less central than they were in older Java versions.
So I’d keep the JDK/JRE/JVM explanation because it’s excellent for learning the fundamentals, but perhaps add a small “modern Java note” so beginners don’t assume every current Java deployment literally follows the old JDK-contains-JRE packaging model.
Looking forward to the OOP part. 👍