Skip to content

Latest commit

 

History

History
596 lines (405 loc) · 8.41 KB

File metadata and controls

596 lines (405 loc) · 8.41 KB

Java Introduction — Teach Me 🎓

Let's learn Java from zero, step by step. Don't try to memorize everything at once. First understand the big picture, then the details will make sense.


1. First: What is Java?

Java is a programming language used to create software.

For example, we can use Java to build:

  • Web applications
  • Backend/API servers
  • Banking software
  • Enterprise applications
  • Desktop applications
  • Cloud services
  • Large-scale distributed systems

A simple Java program:

public class Hello {
    public static void main(String[] args) {
        System.out.println("Hello, World!");
    }
}

This program simply prints:

Hello, World!

2. Why was Java created?

Imagine you write a program for one computer.

Traditional compiled languages might work like:

Program
   ↓
Compiler
   ↓
Machine Code
   ↓
Specific Computer

The machine code is tied to a particular platform.

Java wanted to solve this problem.

Java uses:

Java Program
     ↓
Java Compiler
     ↓
Bytecode
     ↓
JVM
     ↓
Computer

The JVM acts as a layer between your Java program and the underlying machine.

That's why Java became famous for:

Write Once, Run Anywhere


3. Java is not the same as JVM

This is one of the first doubts beginners have.

Java

The programming language.

Example:

int age = 20;

JVM

The Java Virtual Machine that executes Java bytecode.

JDK

The Java Development Kit, which provides the tools needed to develop Java programs.

Think of it like this:

JDK
 ├── Compiler
 ├── Development tools
 ├── Libraries
 └── JVM/runtime

Easy memory trick

JDK → Develop

JVM → Run


4. How does Java code run?

Suppose you create:

Hello.java

You compile it:

javac Hello.java

The compiler produces:

Hello.class

That .class file contains bytecode.

Then:

java Hello

starts the JVM and executes the program.

So remember:

.java
 ↓
javac
 ↓
.class
 ↓
JVM
 ↓
Output

5. What is bytecode?

Bytecode is an intermediate representation.

It is neither normal Java source code nor ordinary CPU machine code.

Think of it as a common language understood by the JVM.

Java
 ↓
Bytecode
 ↓
JVM
 ↓
Windows / Linux / macOS

This is the foundation of Java's portability.


6. What does the JVM actually do?

The JVM is much more than a simple program runner.

It handles things such as:

  • loading classes
  • executing bytecode
  • memory management
  • garbage collection
  • exception handling
  • threads
  • runtime security checks
  • performance optimization

Modern JVMs can also use JIT compilation.

The JVM notices frequently executed code and can compile it into optimized native machine code.

Bytecode
   ↓
JVM observes execution
   ↓
Frequently used code
   ↓
JIT compiler
   ↓
Optimized machine code

This is one reason Java can achieve high performance.


7. What does "object-oriented" mean?

Java is primarily an object-oriented programming language.

The basic idea is to organize software around objects.

For example, imagine a student:

Student
 ├── name
 ├── age
 └── study()

In Java, we can represent that using a class:

class Student {
    String name;
    int age;

    void study() {
        System.out.println("Studying...");
    }
}

Then create an object:

Student s = new Student();

Here:

  • Student → class
  • s → reference to an object
  • name → data
  • study() → behavior

8. Four important OOP concepts

You will hear these constantly in Java.

1. Encapsulation

Keep data and related operations together and control access to the data.

2. Inheritance

A class can derive behavior from another class.

Animal
   ↓
 Dog

3. Polymorphism

The same interface/type can represent different implementations.

Animal
 ├── Dog
 └── Cat

4. Abstraction

Expose what something does while hiding unnecessary implementation details.

These four concepts form a major part of Java programming.


9. Is Java strongly typed?

Yes.

Consider:

int age = 25;

age is an integer.

This would be invalid:

age = "Hello";

because "Hello" is a String, not an int.

Java's type system allows the compiler to detect many errors before the program runs.


10. Java has primitive types

Some common Java primitive types are:

byte
short
int
long
float
double
char
boolean

For example:

int age = 25;
double salary = 50000.50;
boolean active = true;
char grade = 'A';

Java also has reference types:

String name = "John";
Student student = new Student();

11. What is main()?

You will often see:

public static void main(String[] args)

For a traditional standalone Java application, this is the entry point.

Let's break it down:

public
   ↓
accessible

static
   ↓
belongs to the class

void
   ↓
returns nothing

main
   ↓
entry-point name

String[] args
   ↓
command-line arguments

So:

public static void main(String[] args) {
    System.out.println("Hello");
}

means, roughly:

"Here is the method the Java runtime can use to start this application."


12. What is System.out.println()?

This:

System.out.println("Hello");

prints text to standard output.

Break it down conceptually:

System
  ↓
Java system class

out
  ↓
standard output stream

println()
  ↓
print a line

You will use this constantly while learning Java.


13. Why is Java popular?

Java became successful because several advantages came together.

Platform independence

Bytecode + JVM.

Automatic memory management

Garbage collection.

Strong typing

Many errors are caught by the compiler.

Huge ecosystem

Thousands of libraries and frameworks.

Performance

Modern JVMs use sophisticated runtime optimization.

Backward compatibility

Java places significant emphasis on keeping existing applications working.

Enterprise support

Java became deeply established in large organizations.


14. Java's history in one minute

You already learned the history, so connect it to the introduction:

1991
 ↓
Green Project
 ↓
Oak
 ↓
Consumer electronics
 ↓
Internet opportunity
 ↓
Java
 ↓
1995 public introduction
 ↓
Web applets
 ↓
Enterprise applications
 ↓
Modern backend/cloud systems

The original goal was not simply "make a web language."

The deeper goal was:

Create portable software that could work across different hardware.


15. Java today

Modern Java is very different from the Java of the 1990s.

Modern Java includes features such as:

Lambda expressions

x -> x * 2

Streams

numbers.stream()
       .filter(n -> n > 10)
       .forEach(System.out::println);

Records

record Person(String name, int age) {}

Virtual threads

Modern Java can support very large numbers of lightweight concurrent tasks.

So Java has evolved considerably while maintaining its core platform.


🧠 Your Java mental model

Remember this diagram:

                 JAVA
                   │
        ┌──────────┴──────────┐
        ↓                     ↓
   Java Language          Java Platform
        │                     │
        ↓                     ↓
   Source Code        JDK + JVM + APIs
        │
        ↓
      javac
        │
        ↓
     Bytecode
        │
        ↓
       JVM
        │
        ↓
   Operating System
        │
        ↓
      Hardware

🎯 Five things to remember

If you're just starting Java, remember these five facts:

1. Java is a programming language.

2. Java source code is compiled into bytecode.

3. The JVM executes the bytecode.

4. JDK provides tools for developing Java applications.

5. Java's major historical advantage is platform independence.

Quick test 🧪

Try answering these from memory:

  1. What is Java?
  2. What is the difference between JDK and JVM?
  3. What is bytecode?
  4. Why is Java called platform-independent?
  5. What are the four main OOP concepts?

If you can answer those five, you have the foundation of Java Introduction.