Java for Beginners · Module 1: Getting Started
🎯 Why Start with Java?
Imagine writing one letter that every post office in the world can read, whatever language its staff speak. That is the dream Java was built for: write your program once, and run it on any computer that has Java installed.
Today Java is used by millions of developers. It runs banking systems, Android apps, large websites and the tools programmers use every day. It is also one of the best first languages, because it teaches you good habits: clear structure, strict types and object-oriented thinking.
1️⃣ A Short History
Java was announced in 1995 by Sun Microsystems. The team was led by James Gosling, and the language was first called Oak. Oracle bought Sun in 2010 and now looks after Java. New versions arrive every six months, and some are marked LTS (Long-Term Support). LTS versions get updates for many years, so companies prefer them.
Sun Microsystems announces Java
JDK 1.0, the first release
Oracle acquires Sun
Java 8 adds lambdas
Java 11 (LTS)
Java 17 (LTS)
Java 21 (LTS)
Java 25 (LTS)
Figure 1: Important moments in Java's history. LTS versions are shown in green.
2️⃣ Write Once, Run Anywhere
When you compile a C program, you get machine code for one kind of computer. A Windows program does not run on Linux. Java does something different: the compiler turns your code into bytecode, a neutral format. Each computer has its own JVM that understands bytecode, so the same file runs everywhere.
Hello.javasource code you write
Hello.classbytecode: one file for every computer
JVM for Windows
▶ runs
JVM for Linux
▶ runs
JVM for macOS
▶ runs
Figure 2: One source file, one bytecode file, and a JVM on each operating system.
This idea is called WORA, for “Write Once, Run Anywhere”. You will study it in detail in Lesson 3.
3️⃣ Key Features of Java
| Feature | What it means for you |
| Simple | no pointers or manual memory |
| Object-oriented | programs built from objects |
| Platform independent | bytecode runs on any JVM |
| Secure | runs inside a controlled JVM |
| Robust | strong type checking, exceptions, garbage collection |
| Multithreaded | many tasks at once |
Figure 3: The main features of Java.
- Simple: Java removed hard parts of C and C++, such as pointers and manual memory freeing.
- Object-oriented: you build programs from objects that combine data and actions. You will start this in Lesson 29.
- Platform independent: bytecode runs on any JVM.
- Secure: programs run inside the JVM, which controls what they can do.
- Robust: Java checks types strictly, reports errors as exceptions, and cleans up unused memory automatically (garbage collection).
- Multithreaded: a program can do several tasks at the same time.
4️⃣ Where Is Java Used?
Many Android apps are written in Java
Spring and other frameworks run websites and APIs
Banks use Java for secure, reliable systems
Tools such as Hadoop and Kafka are built on the JVM
IDEs like IntelliJ IDEA and Eclipse are Java programs
A standard first language in many universities
Figure 4: Some places where Java is used in the real world.
5️⃣ Java and C Side by Side
If you already know a little C, this table shows what changes in Java.
| C | Java | |
| Compiled to | machine code for one OS | bytecode for the JVM |
| Runs on | the OS directly | the JVM, on any OS |
| Memory | you allocate and free | garbage collector frees it |
| Pointers | yes | no (references instead) |
| Style | procedural | object-oriented |
| Portability | recompile for each OS | compile once, run anywhere |
Figure 5: C and Java compared.
6️⃣ Your First Look at Java Code
Do not worry about understanding every word yet. Lesson 5 explains each line. For now, just see that Java is readable.
Program 1: The smallest useful program
public class HelloJava {
public static void main(String[] args) {
System.out.println("Hello, Java!");
}
}
Hello, Java!
public class HelloJavacreates a class. In Java every program lives inside a class, and the file must be namedHelloJava.java.public static void main(String[] args)is where the JVM starts running.System.out.println(...)prints text and moves to the next line.
Program 2: print and println
public class AboutMe {
public static void main(String[] args) {
System.out.print("Language: ");
System.out.println("Java");
System.out.println("Created in: 1995");
System.out.println("Used for: apps, websites, servers");
}
}
Language: Java
Created in: 1995
Used for: apps, websites, servers
printstays on the same line, so “Language: ” and “Java” join.printlnends the line, so the next output starts below.
Program 3: Adding two numbers
public class SimpleAddition {
public static void main(String[] args) {
int a = 10;
int b = 20;
int sum = a + b;
System.out.println("Sum = " + sum);
}
}
Sum = 30
int a = 10;creates a whole-number variable namedaholding 10."Sum = " + sumjoins text with a number to build one message.
Program 4: Area of a circle
public class CircleArea {
public static void main(String[] args) {
double radius = 3.5;
double area = Math.PI * radius * radius;
System.out.println("Radius = " + radius);
System.out.println("Area = " + area);
System.out.printf("Area (2 decimals) = %.2f%n", area);
}
}
Radius = 3.5
Area = 38.48451000647496
Area (2 decimals) = 38.48
doubleholds numbers with decimals.Math.PIis a ready-made constant from Java’s standard library.%.2finprintfprints 2 digits after the decimal point, and%nstarts a new line.
Program 5: A method and a loop
public class TwoThings {
static int square(int n) {
return n * n;
}
public static void main(String[] args) {
for (int i = 1; i <= 5; i++) {
System.out.println(i + " squared is " + square(i));
}
}
}
1 squared is 1
2 squared is 4
3 squared is 9
4 squared is 16
5 squared is 25
squareis a small method (the Java word for a function) that returnsn * n.- The
forloop calls it five times. If you know C functions, this will feel familiar.
⚠️ Common Beginner Mistakes
| Mistake | Why it is wrong | Fix |
|---|---|---|
| Saying “Java and JavaScript are the same” | They are different languages with similar names | Java runs on the JVM; JavaScript runs in browsers |
| Expecting Java to be machine code | Java compiles to bytecode | Remember: source, then bytecode, then JVM |
| Naming the file differently from the public class | The compiler reports an error | Class HelloJava goes in HelloJava.java |
Writing system.out.println | Java is case-sensitive: System has a capital S | Write System.out.println |
| Forgetting the semicolon | Every statement ends with ; | Add ; at the end |
❓ Frequently Asked Questions
Q1. Is Java free?
Yes. OpenJDK is free and open source, and you can use it to learn and to build real projects.
Q2. Is Java hard to learn?
It is stricter than some languages, but that strictness catches mistakes early. If you know basic C, you will find many ideas familiar.
Q3. Is Java still relevant?
Yes. It is used widely in companies, in Android development and in backend systems, and new versions keep arriving.
Q4. Do I need to know C first?
No. This series starts from zero.
✅ Key Takeaways
- Java is a general-purpose, object-oriented language created at Sun Microsystems and now maintained by Oracle.
- Source code compiles to bytecode, which runs on the JVM of any operating system.
- Java’s main features are simple, object-oriented, platform independent, secure, robust and multithreaded.
- Java is used for Android apps, web servers, banking, big data and desktop tools.
- Choose a recent LTS version (17, 21 or 25) for learning.
🎓 Practice questions: (1) In your own words, what does “Write Once, Run Anywhere” mean? (2) What is bytecode, and who runs it? (3) Name three differences between C and Java from the table. (4) Change Program 2 to print your own name and college. (5) Change Program 4 to calculate the area for a radius of 10.
All 30 lessons in this series (open course page)
Module 1 · Getting Started
- Lesson 1: What is Java? Features and Uses
- Lesson 2: Installing the JDK and Running Your First Program
- Lesson 3: JDK, JRE, JVM and WORA Explained
- Lesson 4: JVM Architecture and JIT Compilation
- Lesson 5: Hello World Program Explained Line by Line
Module 2 · Building Blocks
- Lesson 6: Comments, Identifiers and Keywords
- Lesson 7: Variables and Literals
- Lesson 8: Primitive Data Types in Java
- Lesson 9: Type Conversion and Casting
- Lesson 10: Taking Input with the Scanner Class
- Lesson 11: Escape Characters and Variable Scope in Java
Module 3 · Operators
- Lesson 12: Arithmetic Operators and Increment/Decrement in Java
- Lesson 13: Relational and Logical Operators in Java
- Lesson 14: Bitwise and Shift Operators in Java
- Lesson 15: Assignment, Ternary Operator and Operator Precedence in Java
Module 4 · Control Flow
- Lesson 16: if, if-else and else-if Ladder in Java
- Lesson 17: switch Statement in Java (Classic and Modern)
- Lesson 18: while and do-while Loops in Java
- Lesson 19: for Loop and Nested Loops (Patterns) in Java
- Lesson 20: break, continue and Labelled Loops in Java
Module 5 · Data and Methods
- Lesson 21: Arrays in Java (One-Dimensional)
- Lesson 22: Multidimensional Arrays in Java
- Lesson 23: Strings and the String Pool in Java
- Lesson 24: String Methods and StringBuilder in Java
- Lesson 25: Methods and Method Overloading in Java
- Lesson 26: Recursion Basics in Java
- Lesson 27: ArrayList and Wrapper Classes in Java
- Lesson 28: Exception Handling Basics in Java