Free Online Course · Self-paced · Hands-on

Java Tutorial for Beginners (with examples)

Free Java tutorial for beginners: 100+ lessons on OOP, collections, lambdas, file I/O, exceptions, and multithreading, with examples run on OpenJDK 17.

  • 13 chapters
  • 114 lessons
  • ~18h
  • Beginner to Intermediate
  • Tested with OpenJDK 17.0.x
  • Updated Sep 2026
Java Tutorial for Beginners (with examples)
By Last updated

About this course

This is a free, self-paced Java course that starts with installing a JDK and ends with threads, schedulers, and the data structure questions that come up in interviews. It sticks to the core language and the standard library, the part of Java every framework builds on. Java 25 is the current long-term support release on Oracle's Java SE support roadmap, and the lessons were run on OpenJDK 17.

Most lessons are a small, complete class you can compile with javac and run with java from a terminal, with the output shown underneath. You do not need a Maven or Gradle project for the core syllabus, so when something breaks you are looking at your own code and not at build configuration.

If Java is new to you, go through the chapters in order, since the collections and threading lessons assume you are comfortable with classes and generics. If you already write Java, jump to object-oriented programming, the arrays and collections chapter, or multithreading.

What you'll learn

  • Install a JDK, set up an editor, and compile and run a class with a main() method
  • Use primitive and reference types, operators, casting, and control flow without surprises
  • Work with strings, Math, and number formatting, and write methods with clear parameters and return values
  • Design classes with constructors, encapsulation, inheritance, polymorphism, interfaces, and generics
  • Pick the right collection for the job, from ArrayList and LinkedList to HashMap and HashSet
  • Write lambda expressions and Predicate filters, and handle dates, times, and regular expressions
  • Read and write files, take console input, and handle exceptions with try, catch, and finally
  • Run work on multiple threads, schedule background tasks, and implement classic interview data structures

Who this course is for

  • Students taking a first programming or object-oriented design course that is taught in Java
  • Developers coming from Python or JavaScript who need static types and classes for a backend or Android job
  • Backend engineers who use a framework every day and want the core language and collections underneath it to make sense
  • Candidates preparing for Java interviews that ask about collections, threads, and classic data structures

Prerequisites

  • Basic programming experience with variables, loops, and functions in any language
  • A JDK on Linux, macOS, or Windows; the lessons were run on OpenJDK 17, and any current LTS build works
  • A terminal for javac and java, or a free editor such as Eclipse or VS Code, both covered in the setup chapter
  • No paid tools or cloud accounts; the core examples use only the JDK and its standard library

Versions and testing environment

Every command in this course was run on this stack

ComponentVersionNotes
OpenJDK 17.0.x Program output in the refreshed lessons, such as the nested loops lesson, comes from OpenJDK 17.0.17 on Linux
Older lesson transcripts JDK 11 and 16 The install lesson and a few early articles show these builds; check java --version output against your own JDK
Editors Eclipse, VS Code, BlueJ Setup lessons cover each one; none of the examples depend on a particular IDE

Syllabus

13 chapters · 114 lessons · ~18h of reading

  1. 1 Getting Started and IDE Setup 6 lessons · ~52 min
    1. Part 1 Install Java on Linux, Windows, macOS 9 min read
    2. Part 2 Set up Java with Eclipse IDE 4 min read
    3. Part 3 Set up Java with BlueJ 5 min read
    4. Part 4 Set up Java with VS Code 4 min read
    5. Part 5 The main() method explained 20 min read
    6. Part 6 Multi-line comments in Java 10 min read
  2. 2 Variables, Data Types and Operators 17 lessons · ~2h 23m
    1. Part 7 Variables and types 10 min read
    2. Part 8 Primitive and reference data types 11 min read
    3. Part 9 byte data type 8 min read
    4. Part 10 Booleans 10 min read
    5. Part 11 int vs Integer 15 min read
    6. Part 12 long - MAX_VALUE and MIN_VALUE 4 min read
    7. Part 13 Declare global variables (static fields) 6 min read
    8. Part 14 Escape sequences in strings 5 min read
    9. Part 15 Java operators overview 11 min read
    10. Part 16 Arithmetic operators 17 min read
    11. Part 17 Relational operators 6 min read
    12. Part 18 Logical operators 6 min read
    13. Part 19 Bitwise operators 5 min read
    14. Part 20 Unary operators 6 min read
    15. Part 21 Boolean operators 8 min read
    16. Part 22 XOR (^) operator 7 min read
    17. Part 23 Type casting in Java 8 min read
  3. 3 Control Flow 8 lessons · ~1h 20m
    1. Part 24 if / else 10 min read
    2. Part 25 switch statement 18 min read
    3. Part 26 for loop 11 min read
    4. Part 27 Enhanced for (for-each) loop 6 min read
    5. Part 28 Nested loops 8 min read
    6. Part 29 while loop 10 min read
    7. Part 30 while vs do-while 8 min read
    8. Part 31 break and continue 9 min read
  4. 4 Strings, Math and Numbers 15 lessons · ~1h 48m
    1. Part 32 String methods overview 10 min read
    2. Part 33 Concatenate strings 10 min read
    3. Part 34 String length 8 min read
    4. Part 35 String indexing 5 min read
    5. Part 36 indexOf() method 8 min read
    6. Part 37 Split a string into an array 6 min read
    7. Part 38 Reverse a string 8 min read
    8. Part 39 Compare characters 6 min read
    9. Part 40 Add quotation marks within a string 5 min read
    10. Part 41 String interpolation 7 min read
    11. Part 42 Math class methods 11 min read
    12. Part 43 NumberFormat class 6 min read
    13. Part 44 DecimalFormat 7 min read
    14. Part 45 Compute a square 7 min read
    15. Part 46 Add fractions 4 min read
  5. 5 Methods, Parameters and Return Values 6 lessons · ~54 min
    1. Part 47 Method arguments 8 min read
    2. Part 48 Arguments vs parameters 11 min read
    3. Part 49 Parameter examples 8 min read
    4. Part 50 Optional parameters in Java 14 min read
    5. Part 51 Return multiple values 7 min read
    6. Part 52 Function currying 6 min read
  6. 6 Object-Oriented Programming 12 lessons · ~1h 58m
    1. Part 53 Constructors 15 min read
    2. Part 54 Class constructor examples 9 min read
    3. Part 55 Getters and setters (accessors / mutators) 7 min read
    4. Part 56 Encapsulation 11 min read
    5. Part 57 Inheritance 8 min read
    6. Part 58 Polymorphism 9 min read
    7. Part 59 private vs protected 9 min read
    8. Part 60 Interface vs abstract class 6 min read
    9. Part 61 instanceof 5 min read
    10. Part 62 Generics in Java 10 min read
    11. Part 63 Design patterns in Java 18 min read
    12. Part 64 final vs finally vs finalize 11 min read
  7. 7 Arrays and Collections 18 lessons · ~2h 16m
    1. Part 65 Arrays in Java 10 min read
    2. Part 66 Return an array from a method 8 min read
    3. Part 67 Arrays.asList() explained 7 min read
    4. Part 68 Array vs ArrayList Coming soon
    5. Part 69 ArrayList vs LinkedList 6 min read
    6. Part 70 List vs LinkedList 6 min read
    7. Part 71 Arrays and Collections overview 12 min read
    8. Part 72 Initialize a list 7 min read
    9. Part 73 Reverse a list 6 min read
    10. Part 74 Get a sublist 7 min read
    11. Part 75 ListIterator 7 min read
    12. Part 76 Convert a List to a Map 14 min read
    13. Part 77 Convert a Set to a List 7 min read
    14. Part 78 Hashtable vs HashMap 6 min read
    15. Part 79 HashMap vs Hashtable vs HashSet 6 min read
    16. Part 80 HashSet examples 11 min read
    17. Part 81 CopyOnWriteArrayList 7 min read
    18. Part 82 Stack vs Queue 9 min read
  8. 8 Functional Java (lambda, streams) 2 lessons · ~16 min
    1. Part 83 Lambda expressions 9 min read
    2. Part 84 Predicate functional interface 7 min read
  9. 9 Date, Time and Regex 5 lessons · ~42 min
    1. Part 85 Get the current date 6 min read
    2. Part 86 Convert a string to a Date 6 min read
    3. Part 87 Format dates and times 9 min read
    4. Part 88 Regex basics 11 min read
    5. Part 89 Regex examples 10 min read
  10. 10 File I/O and User Input 10 lessons · ~1h 8m
    1. Part 90 Read a file 8 min read
    2. Part 91 Create and write to a file 10 min read
    3. Part 92 Check if a file exists 6 min read
    4. Part 93 Copy a file 6 min read
    5. Part 94 Read user input (Scanner) 11 min read
    6. Part 95 Skip a line in Scanner 6 min read
    7. Part 96 Mask password input 3 min read
    8. Part 97 Serialization and deserialization 11 min read
    9. Part 98 WatchService - watch a directory 7 min read
    10. Part 99 Hashing methods Coming soon
  11. 11 Exception Handling 3 lessons · ~25 min
    1. Part 100 try / catch / finally 14 min read
    2. Part 101 throw an exception 11 min read
    3. Part 102 Throw exceptions in practice Coming soon
  12. 12 Multithreading and Concurrency 6 lessons · ~1h 15m
    1. Part 103 Multithreading basics 21 min read
    2. Part 104 Thread class examples 8 min read
    3. Part 105 Multiprocessing in Java 16 min read
    4. Part 106 Thread.sleep() 7 min read
    5. Part 107 Scheduling tasks 13 min read
    6. Part 108 Java memory management 10 min read
  13. 13 Data Structures (interview prep) 6 lessons · ~38 min
    1. Part 109 Implement a linked list Coming soon
    2. Part 110 LinkedList class tutorial 12 min read
    3. Part 111 Detect a loop in a linked list 6 min read
    4. Part 112 Find the merge point of two lists 8 min read
    5. Part 113 Find the height of a tree 6 min read
    6. Part 114 Implement three stacks in one array 6 min read

Hands-on labs

6 guided builds you run yourself

  1. Watch a directory for file changes

    Register a WatchService on a path and react as files are created, modified, or deleted.

  2. Schedule recurring background jobs

    Run tasks after a delay and at a fixed rate with Timer and ScheduledExecutorService, and see when Quartz or Spring scheduling is worth adding.

  3. Save and restore objects with serialization

    Write an object to a file, read it back, and keep sensitive fields out of the stream with transient.

  4. Run work in parallel with threads

    Start several threads, share data between them, and use synchronized to stop them corrupting it.

  5. Build a console prompt with a masked password

    Read a password from the terminal and print asterisks in place of the characters the user types.

  6. Implement common design patterns

    Write singleton, factory, and observer implementations in plain Java and see where each one fits.

Where to go after this course

  • Official Java learning siteOracle's own tutorials for newer language features such as records, sealed classes, and pattern matching.
  • Keytool and Java Keystore courseManage the certificates and keystores Java applications use for TLS once you start deploying them.
  • SQL courseMost Java backends sit on a relational database, and JDBC or JPA code is easier to follow when you know the SQL underneath.
  • Java interview questionsPractise explaining collections, concurrency, and JVM behaviour the way interviewers ask about them.

Frequently Asked Questions

Which Java version should I learn in 2026?

Learn on a long-term support (LTS) release. Java 25 is the newest LTS, released in September 2025, and Java 21 and 17 are older LTS releases still common in production. Oracle plans the next LTS, Java 29, for September 2027. The lessons here use core language and standard library features that all three releases share, so install whichever one your course or employer uses. Oracle's support roadmap has the current dates.

Should I install OpenJDK or Oracle JDK?

For learning, either works, because both are built from the same OpenJDK source. OpenJDK builds from your Linux distribution, jdk.java.net, or vendors such as Eclipse Temurin are open source. Oracle JDK 25 is free for all users under Oracle's no-fee terms, while Oracle JDK updates for 8, 11, and 17 are free only for personal and development use. If you are not sure, install the OpenJDK package from your operating system's package manager.

Is Java the same as JavaScript?

No. They are separate languages that share part of a name. Java is statically typed and compiles to bytecode that runs on the Java Virtual Machine. JavaScript is dynamically typed and runs in web browsers and in Node.js. If you want the browser side, see the JavaScript course.

Do I need an IDE to learn Java?

No. A text editor and a terminal are enough for everything in this course. Since Java 11 you can even skip the separate compile step for a single file:

bash
java HelloWorld.java

An IDE starts to pay off once a project has many classes, because it adds code completion, refactoring, and a debugger. The setup chapter covers Eclipse, VS Code, and BlueJ.

Should I learn Java or Python first?

Python gets you to a working script faster because it has less syntax and no compile step. Java makes you declare types and organize code into classes from the first program, which is the style Android and most large enterprise backends expect. If the job or course you are aiming at uses Java, start here. Otherwise the Python course is the gentler first language.

Deepak Prasad

R&D Engineer

Founder of GoLinuxCloud with 15+ years of expertise in Linux, Python, Go, Laravel, DevOps, Kubernetes, Git, Shell scripting, OpenShift, AWS, Networking, and Security. With extensive experience, he excels across development, DevOps, networking, and security, delivering robust and efficient solutions for diverse projects.

  • Go (programming language)
  • Python (programming language)
  • DevOps
  • Computer Security
  • Cloud Computing
  • Kubernetes
  • Linux
  • Ansible (software)