Learn Java Programming
Master Java from basics to advanced topics with concise lessons and practical examples. Follow a structured path inspired by reputable learning resources.
Reference guide: Programiz — Getting Started with Java [0]
Java Data Types
Java has two categories of types: primitive types (8 built-in value types) and reference types (objects, arrays, interfaces). Understanding the difference is fundamental to writing correct Java code.
Primitive Types
// Integer types
byte smallNum = 127; // -128 to 127
short mediumNum = 32000; // -32,768 to 32,767
int normalNum = 2_000_000; // underscores for readability (Java 7+)
long bigNum = 9_876_543_210L; // suffix L for long literals
// Floating point
float price = 19.99f; // suffix f required
double precise = 3.141592653589; // default decimal type
// Character and boolean
char letter = 'A'; // single character in single quotes
char unicode = '\u0041'; // Unicode A
boolean isActive = true; // only true or false
// Number bases
int hex = 0xFF; // hexadecimal (255)
int binary = 0b1010; // binary (10)
int octal = 0755; // octal (493)
Reference Types
// String — most common reference type
String greeting = "Hello, World!";
String empty = "";
String nullStr = null; // reference types can be null
// Arrays
int[] numbers = {1, 2, 3, 4, 5};
String[] names = new String[3];
// Objects
Object obj = new Object();
List<String> list = new ArrayList<>();
// Key difference: primitives store VALUES, references store ADDRESSES
int a = 5;
int b = a; // b gets a COPY of the value
b = 10; // a is still 5
String s1 = "Hello";
String s2 = s1; // s2 points to the SAME object
// But Strings are immutable, so this is safe
Wrapper Classes and Autoboxing
// Wrapper classes: object versions of primitives
Integer boxedInt = 42; // autoboxing: int -> Integer
int unboxed = boxedInt; // auto-unboxing: Integer -> int
// Useful for collections (cannot store primitives directly)
List<Integer> numbers = new ArrayList<>();
numbers.add(10); // autoboxed to Integer
int first = numbers.get(0); // auto-unboxed to int
// Utility methods on wrapper classes
int parsed = Integer.parseInt("42");
String str = Integer.toString(42);
int max = Integer.MAX_VALUE; // 2,147,483,647
double infinity = Double.POSITIVE_INFINITY;
// Null danger with unboxing
Integer maybeNull = null;
// int crash = maybeNull; // NullPointerException!
Type Comparison Table
| Primitive | Wrapper | Default | Size |
|---|---|---|---|
byte | Byte | 0 | 1 byte |
short | Short | 0 | 2 bytes |
int | Integer | 0 | 4 bytes |
long | Long | 0L | 8 bytes |
float | Float | 0.0f | 4 bytes |
double | Double | 0.0 | 8 bytes |
char | Character | '\u0000' | 2 bytes |
boolean | Boolean | false | 1 bit* |
Key Takeaways
- Primitives store values directly on the stack; reference types store addresses pointing to heap objects.
- Wrapper classes (
Integer,Double) are needed for collections and nullable values. - Autoboxing converts automatically, but beware of
NullPointerExceptionwhen unboxing null. - Use
long(withLsuffix) for values exceeding int range;doubleis the default decimal type. - Use
var(Java 10+) for local type inference when the type is obvious from the right side.
Java Tutorial FAQs
How do I run Java online?
How do I install Java on Windows?
JAVA_HOME and update the Path variable to include the JDK bin directory. Verify with java --version. [0]How do I install Java on macOS?
export JAVA_HOME=$(/usr/libexec/java_home) and update PATH to include $JAVA_HOME/bin. Verify with java --version. [0]Do I need the JDK to compile Java?
javac) and tools needed to build Java applications. For quick tests, the online compiler is a convenient alternative.What is Java used for?
Learn Java the Practical Way
Whether you’re new to programming or expanding your skills, this Java tutorial focuses on hands-on learning. Each topic pairs clear explanations with short, working examples that you can run online. Move from fundamentals—variables, data types, and control flow—to core OOP concepts like classes, inheritance, and interfaces. Along the way, you’ll see idiomatic Java patterns and simple best practices that build confidence.
Why this guide? It’s designed for real-world use: fast to read, easy to try, and friendly on mobile. Bookmark it and return whenever you need a refresher or a quick example.
Java Programming Tutorial — Learn Java Step by Step
Java is one of the most widely-used programming languages in the world, powering Android apps, enterprise backends, cloud services, and scientific computing. This tutorial teaches Java from the ground up with practical, runnable examples you can try in our free Java Compiler or any local IDE.
Each topic includes multiple code examples with explanations, expected output, and best practices. Whether you are a complete beginner or refreshing your knowledge of a specific feature, every page gives you immediately usable code.
What This Tutorial Covers
- Basics: Hello World, variables, data types, operators
- Control Flow: if/else, switch, for, while, break/continue
- Methods: Parameters, return types, overloading, recursion
- Arrays & Strings: Declaration, manipulation, StringBuilder
- OOP: Classes, objects, constructors, encapsulation
- Inheritance: extends, super, abstract classes, final
- Interfaces: Abstraction, default methods, functional interfaces
- Collections: ArrayList, HashMap, HashSet, LinkedList
- Exceptions: try/catch/finally, custom exceptions
- Generics: Type parameters, bounded types, wildcards
- Streams (Java 8+): filter, map, reduce, collect
- File I/O: BufferedReader, Files API, serialisation
Why Learn Java in 2026?
- Enterprise dominance: Java powers most Fortune 500 backends via Spring Boot and Jakarta EE
- Android development: Java + Kotlin build apps for 3+ billion active Android devices
- Job market: Top 3 most-demanded language on LinkedIn, Indeed, and Stack Overflow survey
- Platform independence: Write once, run anywhere — bytecode runs on any JVM
- Modern evolution: Java 17/21 LTS added records, sealed classes, virtual threads, pattern matching
- Ecosystem: Maven/Gradle, IntelliJ IDEA, 100,000+ libraries, massive community
How to Get Started
- Run code online: Use our Java Compiler — no installation needed
- Install JDK locally: Download OpenJDK 17+ from adoptium.net
- Choose an IDE: IntelliJ IDEA Community (free), Eclipse, or VS Code with Java Extension Pack
- Follow topics in order: Start from Hello World and progress sequentially
- Build a project: After OOP, build a small CRUD app to solidify your knowledge
Frequently Asked Questions
No. This tutorial starts from absolute basics (Hello World, variables) and progresses to advanced topics. Each concept builds on the previous one.
Java 17 (LTS) is recommended. All examples in this tutorial work on Java 17+. Our online compiler uses the latest stable release.
Basics take 4–6 weeks of daily practice. Intermediate topics (collections, generics) add 4–6 more weeks. Job-readiness typically requires 3–6 months total.
Yes, completely free. No account, no sign-up. All topics and examples are available without any restriction.
Who Is This For?
Complete beginners choosing Java as their first language. CS students preparing for university courses and exams. Self-taught developers building a strong OOP foundation. Python/JS developers learning Java for backend or Android work. Interview candidates practising Java data structures. Professional developers needing a quick reference for specific Java features.