Java for Beginners Course

Course Introduction

Welcome to the Java for Beginners course!

What do I need?

Before starting, please make sure you have Java installed and an IDE. If you don’t have these tools installed, feel free to check this tutorial for guidance. We’ll be using the 3 main tools mentioned in that tutorial for the rest of this beginners course.

Also, we recommend downloading the example project (see below for details) and importing it into your IDE.

How is the course organized?

The course is divided into separate chapters which you can find under the Contents section on the right hand side of this page (or at the bottom of the page if you’re accessing from a mobile device).

The first 3 chapters will introduce the basic building blocks you’ll need to know to start coding in Java and that will serve as a foundation for the rest of the courses.

If you are familiar with other programming languages then you might be familiar with either some of the concepts or even the syntax as Java shares a similar syntax with languages like C++. If that’s the case, feel free to skim/skip through the initial chapters.

  • Chapter 1: Introduces the concepts of variables, an initial look into classes, objects and packages and a first example on how to run a Java application.

  • Chapter 2: Covers the concepts of primitives and the basic operations in the Java language. NOTE: We omit Bitwise operations from this chapter, but will introduce them in a future course.

  • Chapter 3: Defines the difference between expressions and statements, and also introduces statements you can use to control the flow of the application.

  • Chapter 4: Our first example project. We introduce a small example project to put some of the topics in the first 3 chapters together.

  • Chapter 5: Covers Classes in more detail and introduces the concept of interfaces, inheritance and other OOP features available in Java.

  • Chapter 6: Introduces common object operations and base object behaviors.

  • Chapter 7: Defines arrays and provides an introduction to data structures.

  • Chapter 8: Provides an introduction to anonymous classes, lambdas and functional interfaces.

  • Chapter 9: Introduces the concept of streams and stream pipelines in Java.

In all of the chapters we’ll cover the concepts using an example-based approach, so you’ll find plenty of code examples that you can identify by this font when they are in-lined, or by blocks of code like the one below:

String sample = "This is an example";

Where is the example project?

For this course, as we do in other tutorials and articles in this website, you’ll find a "Code in GitHub" section in every page. If you are on a desktop/laptop, you’ll find this on the right-hand side of the page, or at the bottom of each page in mobile devices.

The "Code in GitHub" section highlights 2 or 3 links depending on the contents of the page:

  1. The first link, called Project Repo, will take you to the main page of the project in GitHub where you can navigate it in more detail, get the links to clone it, or fork the project if you want.

  2. The second link, called Download code for this step, is a direct link to a zip file with the code we are using for the section you’re currently reading. This is useful if you are not too familiar yet with GitHub but want to try the code in your computer.

  3. The third link, which only appears if necessary, called Main class for this step, will take you either to the main class that is being covered in the page, or to the main folder that contains the classes being discussed.

All the projects we publish use Gradle as the build system, so importing them to an IDE should be very simple. If in doubt, check this tutorial for details on how to import the project into an IDE.

For this beginners course, we’ll use the same project for all the chapters, so the "Project Repo" and the "Download code for this step" should always take you to the same place (no need to download different projects for different chapters).

The example project is a collection of examples used throughout the course put together in the same GitHub project for convenience of the reader. However, it shouldn’t be used as a reference project on how to design systems.

What this course is not?

The main purpose of this course is to provide you with an understanding of the syntax of the Java language and give a basic ground for a beginner Java developer to be able to read and write Java code.

However, this course won’t focus on software design. We’ll introduce some concepts relevant to this but it isn’t the intention of this course.

What version of Java?

As this is a beginners course, most of the concepts can be applied to versions of Java ranging from the very old to the most recent. However, we aim to cover most of the concepts available in Java 8.

For concepts that are only available in Java versions 9 and above, we’ll highlight them as such.

Code in GitHub

Get the code for this tutorial using the links below.

Project Repo
Download code for this step
Dependencies

This is a list of recommended tutorials or courses that might be useful before starting this one.

Contents
Welcome to the Course!
Course Introduction
Chapter 1 - Building Blocks
Quick introduction to Java Variables Classes And Objects Class Example - Defining a class Object Examples - Creating instances Java Application Example - Running our first app Accessing class members - The dot operator Packages - Organizing the code
Chapter 2 - Primitives and Operators
Primitives Arithmetic Operators Assignment Operator Unary Operators Equality and Relational Operators Conditional Operators
Chapter 3 - Statements and Control Flow
Expressions Statements If-Then Statement If-Then-Else Statement More If Statements Switch Statement While and Do-While Statements For Statement Branching Statements Exception Handling
Chapter 4 - Code Example
Example Project - A Simple Vending Machine Adding money Delivering Items Giving Change
Chapter 5 - Classes and Interfaces
Introduction Access Level Modifiers Class Declaration - Class, Methods and Fields Class Declaration - Constructors Inheritance Basics Inheritance - Constructors Inheritance - Methods and Fields Polymorphism Abstract Classes and Methods Interfaces Static Class Members Class Composition Final Classes and Class Members Generic Classes
Chapter 6 - Base Object Behaviors
Introduction Type Comparison Type Casting Object Equality - The Contract Object Equality - Common Pitfalls Object String Representation Garbage Collection Object Comparison Primitive Wrappers and Autoboxing
Chapter 7 - Data Structures
Introduction Arrays - Declaration and Creation Arrays - Basic Operations Core Collection Interfaces List and ArrayList - Basic Operations ArrayList Internals Introduction to Hash Tables Map and HashMap - Basic Operations Set and HashSet - Basic Operations
Chapter 8 - Anonymous classes and lambdas
Introduction Filtering a List Anonymous Classes Lambdas Built-in Functional Interfaces
Chapter 9 - Streams
Introduction Creating Streams Intermediate Operations Terminal Operations