Java Tutorial
Java is one of the most widely used programming languages in the world. It runs Android apps, bank and government systems, enterprise software and the popular game Minecraft. In the Philippines, it's taught in many senior high school TVL-ICT Computer Programming classes and college IT courses.
This free course has 21 lessons. Every example is a complete program shown together with its exact output, so you can study even without a computer. Each lesson ends with a Taglish summary and a quick quiz.
How to run the examples
- On a computer: install the free JDK (Java Development Kit) and an editor like VS Code, NetBeans or IntelliJ IDEA Community. Lesson 2 shows how.
- On a phone: search for an "online Java compiler" and paste the code, or use an Android app that compiles Java.
Before you start
No experience is needed, but Java is stricter than Python or JavaScript: every variable has a fixed type, and every statement ends with a semicolon. If you'd like an easier warm-up, try a few lessons of our Python course first.
What you'll be able to do
- Write, compile and run complete Java programs
- Read keyboard input with
Scannerand make decisions - Repeat tasks with loops and store data in arrays and ArrayLists
- Organize code into methods and classes
- Use the four pillars of object-oriented programming
- Build a complete console grading system
All lessons
Getting Started
- Introduction to JavaWhat Java is, where it's used, how "write once, run anywhere" works with the JVM, and what a first Java program looks like.
- Getting Started with Java — Install the JDK and Run a ProgramInstall the Java Development Kit, write a program in a text editor, compile it with javac, run it with java, and choose an IDE such as VS Code, NetBeans or IntelliJ.
- Java Output and Comments — println, print and printfPrint text and numbers with System.out.println, print and printf, use escape characters, format decimals, and write single-line, multi-line and Javadoc comments.
Basics
- Java VariablesDeclare and initialize variables with a type, change their values, use final for constants, follow naming conventions, and use var for local type inference.
- Java Data Types and Type CastingJava's eight primitive types (byte, short, int, long, float, double, char, boolean), the String reference type, and converting between types with casting and parsing.
- Java OperatorsArithmetic, assignment, increment, comparison and logical operators in Java, with operator precedence and the difference between x++ and ++x.
- Java Strings and String MethodsWork with text in Java — length, charAt, substring, indexOf, toUpperCase, trim, replace, split, contains, comparing with equals and equalsIgnoreCase, and StringBuilder.
- Java Math Class and Random NumbersUse Java's Math class — max, min, abs, sqrt, pow, round, ceil, floor — and generate random numbers with Math.random and the Random class.
- Java User Input with ScannerRead keyboard input with java.util.Scanner — nextInt, nextDouble, next and nextLine — avoid the nextLine skipping bug, and build interactive console programs.
Control Flow
- Java if, else if and elseMake decisions in Java with if, else if and else, nest conditions, combine them with && and ||, and use the ternary operator. Includes a DepEd grade descriptor program.
- Java switch Statement and Switch ExpressionsChoose between exact values with switch, case, break and default, group cases, switch on Strings, and use modern arrow-style switch expressions.
- Java while and do-while LoopsRepeat code with while and do-while loops — counters, savings goals, input validation, menus — and avoid infinite loops.
- Java for Loops and Nested LoopsCount with for loops, step by different amounts, compute sums and factorials, build multiplication tables and star patterns with nested loops.
Arrays & Methods
- Java Arrays and 2D ArraysStore many values of the same type in an array — create, read, change and loop through arrays, use the for-each loop, Arrays.sort and Arrays.toString, and work with 2D arrays like a seating chart.
- Java Methods — Parameters, Return Values and OverloadingOrganize code into reusable methods — define static methods, pass parameters, return values, overload methods, and understand pass-by-value and recursion.
Object-Oriented Programming
- Java Classes and ObjectsObject-oriented programming in Java — define a class with fields and methods, create objects with new, use this, write toString, and keep classes in separate files.
- Java Constructors and EncapsulationInitialize objects with constructors, overload them, protect data with private fields, and control access with getters, setters and validation. Includes a BankAccount class.
- Java Inheritance, Polymorphism and AbstractionBuild classes on top of others with extends and super, override methods, treat different objects the same way with polymorphism, and use abstract classes and interfaces.
- Java ArrayList and HashMapUse ArrayList for lists that grow and shrink — add, get, set, remove, contains, sort — and HashMap for key–value lookups such as a price list or vote counter.
Going Further
- Java Exceptions — try, catch, finally and throwHandle runtime errors with try, catch and finally, know common exceptions like NumberFormatException and ArithmeticException, throw your own, and read and write files safely.
- Java Final Project — Class Record and Grading SystemBuild a complete console grading system in Java with a Student class, an ArrayList, a menu, input validation, DepEd-style computation, rankings and a saved report.