Skip to main content
PProfileMatch

Java Tutorial

Learn Java from scratch: syntax, control flow, methods, OOP and collections

Beginner to Intermediate6 lessonsabout 29 min of reading

This Java tutorial is for people who have never written a line of Java, as well as self-taught developers and students who know a little syntax but want it to finally make sense. You do not need prior programming experience. You do need a computer where you can install the JDK and a text editor or IDE you are comfortable with.

By the end you will be able to compile and run Java programs from the command line, model real-world things such as bank accounts and employees with classes, control program flow with conditions and loops, and store data in an ArrayList or HashMap. Those are the building blocks behind most coding-interview questions and most everyday backend code.

The six lessons are ordered so that each one only uses ideas from the lessons before it: how Java runs, then variables and types, then decisions and repetition, then methods, then classes and objects, and finally the collections framework. Every code example is a complete program you can paste into a file, compile and run, and the output shown is what the program actually prints.

Java lessons

  1. 1Java Introduction: What It Is, How It Runs, Your First ProgramLearn what Java is, the difference between JDK, JRE and JVM, how to compile and run code, and write your first Hello World program step by step.5 min read
  2. 2Java Variables and Data TypesUnderstand Java variables and data types: int, double, boolean, char, String, var, type casting and final constants, with runnable examples and common errors.5 min read
  3. 3Java If-Else, Switch and LoopsLearn Java if-else, switch expressions, for, while and enhanced for loops, plus break and continue, with real examples and the mistakes beginners make.5 min read
  4. 4Java Methods: Parameters, Return Values and OverloadingLearn how Java methods work: parameters, return values, void, overloading, varargs, pass-by-value and recursion, with clear examples and common mistakes.4 min read
  5. 5Java Classes and Objects (OOP Basics)Learn Java classes and objects: fields, constructors, encapsulation, inheritance, interfaces and the this keyword, using bank account and employee examples.5 min read
  6. 6Java Collections: ArrayList and HashMapLearn Java collections with ArrayList and HashMap: generics, add, get, remove, iteration, when to use each, and interview-style examples like word count.5 min read

Preparing for an interview? Practise Java interview questions

Learning Java to land a job? Browse open roles or check which skills are trending.