back to course
Lesson 01 / 801%· free preview
Getting Started1/4
Java Introduction
What Java is, why 'Write Once Run Anywhere' still matters, and how it differs from Python/C.
What is Java?
Java is a general-purpose, object-oriented, statically-typed, compiled-to-bytecode programming language created by James Gosling at Sun Microsystems in 1995 (now owned by Oracle). It runs on the JVM (Java Virtual Machine) — so the same compiled .class file runs on Windows, Linux, macOS, and Android.
In simple words:
- Java is C++ with a safety net — adds garbage collection, no raw pointers, and a huge standard library.
- It compiles to bytecode (not native code) and the JVM JIT-compiles it to machine code at runtime.
- Famous slogan: "Write Once, Run Anywhere" (WORA) — one binary, every platform with a JVM.
- Powers everything from Android apps and banking systems to Netflix, LinkedIn, Spotify, and Minecraft.
Why Learn Java?
- Job market — #1 enterprise language. Banks, fintech, telecom, and government all run on Java.
- Android — native Android apps are Java/Kotlin (Kotlin compiles to JVM bytecode too).
- Beginner-friendly — strong types catch bugs at compile time, not in production.
- Massive ecosystem — Spring, Hibernate, Maven, Gradle, JUnit, IntelliJ.
- Performance — JIT-compiled, often within 10% of C++ for server workloads.
- Career stability — Java skills are in demand for the next 20 years (banks won't rewrite COBOL/Java overnight).
What You Can Build with Java?
| Domain | Real-world Example |
|---|---|
| Mobile apps | Android (Java + Kotlin) |
| Web back-ends | Netflix, LinkedIn, Uber, Twitter (early years) |
| Banking / Fintech | Goldman Sachs, JPMorgan, ICICI core banking |
| Big Data | Hadoop, Spark, Kafka, Cassandra |
| Enterprise | SAP, Oracle ERP, Salesforce back-end |
| Games | Minecraft (Java Edition), RuneScape |
| IoT / Embedded | Java ME, smart-card chips, Blu-ray players |
Java vs C, C++, Python — Quick Compare
| Feature | C | C++ | Python | Java |
|---|---|---|---|---|
| Paradigm | Procedural | Multi-paradigm | Multi-paradigm | OOP-first |
| Compiled to | Native | Native | Bytecode (interpreted) | Bytecode (JIT) |
| Memory mgmt | Manual | Manual + smart ptrs | GC | GC (automatic) |
| Pointers | Yes | Yes | No | No (references only) |
| Static / Dynamic typing | Static | Static | Dynamic | Static |
| Speed | Fastest | Fastest | Slowest | Fast (close to C++) |
| Platform-independent binary | No | No | Source-only | Yes (.class runs anywhere) |
| File extension | .c | .cpp | .py | .java → .class |
Your First Java Program
javapublic class HelloWorld { public static void main(String[] args) { System.out.println("Hello, Codekilla!"); } }
Hello, Codekilla!
Line-by-Line Explanation
public class HelloWorld { ... }— every Java program lives inside a class. The file name must match the public class name (HelloWorld.java).public static void main(String[] args)— the entry point. The JVM looks for this exact signature.public— accessible from outside the class.static— belongs to the class, no instance needed.void— returns nothing.String[] args— command-line arguments as an array.
System.out.println("...");— prints a line (println= print + newline) to standard output.- Every statement ends with a semicolon
;— Java is strict about it.
Compile and Run
bashjavac HelloWorld.java # produces HelloWorld.class (bytecode) java HelloWorld # runs the class on the JVM (no .class extension!)
Common Mistakes
- File name mismatch —
public class HelloWorldmust live inHelloWorld.java. Capital matters. - Forgetting
;— every statement ends with a semicolon. The compiler points at the next line. - Wrong case —
PublicorStaticwon't compile. Java is case-sensitive. - Running
java HelloWorld.class— drop the.class. Pass the class name, not the file. - No
mainmethod —Error: Main method not found in class ....
Interview Questions
Practice Exercises
- Hello on three lines — Print your name, age, and city on three separate lines using three
printlncalls. Hint: three statements, each ending in;. - Filename check — Save a file as
Hello.javacontainingpublic class HelloWorld. Compile it — note the error. Hint: rename the file to match the class. - Compile + run — Use
javacandjavaon your machine and confirm output matches. Hint: install JDK 17+ first. - No
static— Removestaticfrommainand try to run. Read the error. Hint: JVM can't call non-staticmainwithout an instance.
💡 Think Like a Programmer: Compile errors are your friend. They catch typos and type mismatches before users do. Read them top-to-bottom — the first error often causes the rest.
AI-powered recap
Quick recap quiz?
We'll generate 5 MCQs from this lesson and check your understanding instantly. Takes ~30 seconds.
# program
Program
Java
public class Main {
public static void main(String[] args) {
System.out.println("Hello, Codekilla!");
}
}Ready to move on?
// example library
Want more hands-on snippets in Java?
Browse 100 runnable examples · across 10 chapters · short, copy-paste-friendly · grouped by topic
// side-by-side reference
See this in other languages
Compare the same concept across C, C++, Java, and Python — one table, zero tab-switching.
// feedback.matters()
Did this lesson help you?
100% found this helpful · 1 vote
