Java Tutorial

This Java tutorial helps you learn Java programming from zero to mastery and shows you how to apply Java knowledge to develop practical applications.

Getting Started

This section helps you get started with Java by answering the most important question “What is Java?”, then walks you through the steps of creating the Hello World program, and finally explains the basic Java syntax.

  • What is Java – Understand what Java is, how Java works, and more importantly what can you do with Java.
  • Java Hello World – Show you step by step how to create the first Java program that displays the Hello, World! message on the screen.
  • Java syntax – Introduce the basic Java syntax, including whitespace, statements, keywords, blocks, and comments.

Variables, Primitive data types, and Strings

This section discusses the variables, primitive types, and arithmetic operators.

  • Variables – Learns how to use variables to store and manage data in a program.
  • Primitive types – Introduce Java’s primitive data types, which include integer types, floating-point types, character type, and the boolean type.
  • Arithmetic operators – Show you how to use the arithmetic operator to perform mathematical operations.
  • Type conversion – Understand type conversion in Java, which includes implicit and explicit type conversions.
  • var keyword – Show you how to use the var keyword to declare implicit-typed variables.
  • String – Discuss Java string and its basic operations.

Conditional logic

In this section, you’ll learn about relational and logical operators to perform logical operations. You’ll also learn the if-else and switch statements to add logic to the programs.

  • Relational operators – Introduce relational operators (or comparison operators) that compare two values and return the relationship between them.
  • Logical operators – Learn how to use the logical operators to perform logical operations on boolean values.
  • if – Show you how to execute a block of code if a condition is true.
  • if-else – Learn how to execute a block of code if a condition is true and another block of code if the condition is false.
  • if-else-if – Guide you on how to check multiple conditions sequentially and execute a block of code if a condition is true.
  • Ternary operator (?:) – Learn how to use the ternary operator to express the If-else statement more concisely.
  • switch – Show you how to compare an expression with multiple values and execute different code blocks based on the matches.

Loops

In this section, you’ll learn how to create loops that execute a block of code repeatedly using various statements such as while, do while, and for. You’ll also learn how to control the loops using the break and continue statements.

  • while – Learn how to execute a code block repeatedly as long as a specified condition is true with the condition evaluated at the beginning of each iteration.
  • do while – Show how to execute a code block repeatedly as long as a specified condition remains true with the condition evaluated at the end of each iteration.
  • for loop – Learn how to create a loop that executes a code block a specified number of times.
  • break – Show how to terminate a loop prematurely such as while loop, do while loop, and for loop.
  • continue – Learn how to skip the remaining code of the current iteration and start a new iteration prematurely.

Arrays

This section walks you through how to use arrays to manage a collection of values effectively. It also introduces the enhanced for loop which is also known as foreach loop to iterate over elements of an array.

  • Array – Learn how to use an array to hold multiple values in a single variable.
  • Multidimensional arrays – Show you how to define multidimensional arrays, focusing on 2D arrays.
  • Foreach – Learn how to use enhanced for loop a.k.a foreach loop to iterate over elements of an array.

Classes

  • Class – Learn about the basic class in Java and how to define a custom class with property and methods.
  • this – Help you understand the Java keyword clearly and how to use it effectively in your classes.
  • Public and Private – Introduce the public and private keywords to control access to the properties and methods of a class.
  • Getter / Setter – Learn how to use Getter and Setter methods to encapsulate private fields.
  • Constructor – Show you how to define a class constructor that creates a new object and initializes the object’s initial state.

Static Members

  • Static variables – Explain static variables in Java and how to use them effectively.
  • Static methods – Learn more about static methods and how to use them to define a utility class.

Methods in depth

  • Methods – Show you how to use the methods to organize your code to make it more maintainable and reusable.
  • Passing parameters – Understand how Java pass-by-value works.
  • Varargs – Learn how to define methods with a variable number of parameters.
  • Method overloading – Introduce the method overloading and how to use it to define overloaded methods in the same class that share the same name but different numbers or types of parameters.

Inheritance

This section helps you understand Java inheritance, allowing you to create reusable code in Java applications.

  • Inheritance – Learn how to define a class that inherits fields and methods from an existing class using Java inheritance.
  • Final class – Show how to define final classes that cannot be extended.
  • Object – Understand the Object class and learn how to override the methods of the Object class to make your class more useful.
  • Casting – Learn how to convert an object of a class to another class, within the class hierarchy.
  • Abstract class – Learn how to define an abstract class that serves as a base class for other multiple related classes.

Interfaces

  • Interface – Introduce the concept of interface and how to use interfaces to make contracts between classes.
  • Extending interface – Learn how to define an interface that extends one or more interfaces.
  • Default methods – Show you how to add new methods to an existing interface without making breaking changes to the classes that already implement the interface by using default methods.

Exception handling

  • try catch – Understand exceptions and how to handle exceptions to make your application more robust.
  • try catch finally – Learn how to clean up resources properly when an exception occurs.
  • throw – Show you how to throw an exception.
  • Rethrow exceptions – Learn how to rethrow an exception.
  • throws – Show you how to use the throws clause to specify one or more exceptions thrown by a method and propagate the exceptions up to the call stack, allowing the caller of the method to handle it.
  • Checked and unchecked Exceptions – Introduce the checked and unchecked exceptions and explain the differences between them.
  • Custom exceptions – Show you how to define custom exceptions that are relevant to your application.

Generics

  • Generics – Learn how to use Java generics to define classes that are parametrized over types.

Advanced classes

  • Nested Classes – Show you how to define a class within another class, which is called a nested class.
  • Anonymous class – Learn about anonymous class.

Enum

This section shows you how to use Java enum type to represent a fixed set of related constants to make your code more robust.

  • Enum – Show you how to use enum to represent a fixed set of related constant values.
  • Enum methods – Learn how to encapsulate behaviors by defining methods for enum.
  • Enum constructor – Show you how to associate enum constants with data by defining fields and constructors.
  • Convert a string to an enum – Show you how to convert a string into an enum.