Java Basics

The core language features that every Java program uses, regardless of whether you're building a simple script or a Spring Boot microservice.

What "Java Basics" Actually Means

Different resources define "basics" differently. Some include object-oriented programming. Some include collections. On this site, Java Basics means the language features that exist before you define your first class:

Object-oriented programming (classes, inheritance) is built on top of these fundamentals — you still use variables, methods, and exceptions inside every class you write. The basics tutorials here are the foundation that everything else depends on.

Before You Start

You need two things before beginning these tutorials:

1. Java installed on your computer

Download the JDK (Java Development Kit) from Adoptium (formerly AdoptOpenJDK). Version 17 or later is recommended. After installation, open a terminal and verify:

Terminal
java -version
javac -version

If both commands print a version number, you're ready.

2. Ability to compile and run from the terminal

The basics tutorials use plain .java files with no build tool (no Maven, no Gradle). You compile with javac and run with java. An IDE like IntelliJ IDEA or VS Code makes this easier, but it's not required.

Compile and run a simple program
// Save as Hello.java
public class Hello {
    public static void main(String[] args) {
        System.out.println("Java is working.");
    }
}
Terminal
javac Hello.java
java Hello
Console Output
Java is working.

If you see that output, your environment is set up correctly and you can proceed.

0
Prior Java
knowledge needed
5
Tutorials in
this section
~2h
Total reading
time (approx.)

Tutorials — Study in This Order

Each tutorial builds on concepts introduced in the previous ones. The "why you need this" notes explain the dependency.

Tutorial 1 of 5 Beginner · ~15 min

Java Variables and Data Types

How to declare variables, what the eight primitive types are and when to use each one, how type casting works, the difference between primitive types and reference types, and why String behaves differently from other objects.

Why first: Every subsequent tutorial uses variables. You can't write a method, catch an exception, or read a file without them.

Start tutorial →
Tutorial 2 of 5 Beginner · ~15 min

Java Methods

How to define and call methods, pass parameters, return values, use method overloading to create multiple versions of the same operation, and understand static methods vs. instance methods.

Why second: Methods organize code into reusable blocks. The file handling and logging tutorials both require writing methods. Overloading also introduces the polymorphism concept that inheritance builds on.

Start tutorial →
Tutorial 3 of 5 Beginner · ~20 min

Exception Handling

How to handle errors with try-catch-finally, understand Java's exception class hierarchy, create your own custom exception types, and use try-with-resources to guarantee that files, connections, and other resources are properly closed.

Why third: Try-with-resources is used in both the file handling and JDBC tutorials. Understanding checked vs. unchecked exceptions is also essential before working with any library framework, including Spring Boot.

Start tutorial →
Tutorial 4 of 5 Beginner · ~25 min

File Handling

How to read and write text files using the modern java.nio.file API, work with CSV and properties files, create and traverse directories, and copy, move, and delete files. Covers character encoding (UTF-8), the difference between Path and File, and when to use each reading approach.

Why fourth: Applications need to read configuration files and write output. The logging tutorial shows how loggers write to files, but understanding file I/O independently means you're not dependent on a framework for basic persistence.

Start tutorial →
Tutorial 5 of 5 Beginner · ~20 min

Java Logging

How to use java.util.logging to replace System.out.println() with a proper logging system. Covers log levels (SEVERE through FINEST), handlers (console and file), formatters, the logger hierarchy, configuration via properties files, and parameterized logging for performance.

Why last: Logging is the "right way" to output diagnostic information. Placing it at the end of the basics means every subsequent tutorial (JDBC, Spring Boot) can use proper logging in its examples instead of printStackTrace(). This also naturally leads into the Spring Boot tutorial, which configures logging through application.properties.

Start tutorial →
Advertisement

After Completing These Tutorials

You will have the skills to build functional, standalone Java programs that:

Read and process text files

Parse CSV data, read configuration, analyze log files — all with proper encoding handling.

Write structured output

Generate reports, save results, write configuration files — with correct formatting and encoding.

Handle errors gracefully

Validate input, recover from file-not-found and permission errors, and never leave resources open.

Produce useful log output

Replace println debugging with level-filtered, properly formatted logs that work in production.

What's Not in "Basics" (and Why)

Control flow is covered implicitly within each tutorial — you'll see if, for, while, and switch used in context. A standalone "control flow" tutorial would consist almost entirely of examples you've already seen in math class, which isn't a good use of your time. If you can follow the code in these tutorials, you know enough control flow.

Arrays and Strings are introduced where they're needed — the Variables tutorial covers all primitive types and mentions String's special behavior. A deep dive into String internals (string pool, immutability) is better placed after OOP, when you understand what objects and references are. Arrays are largely superseded by ArrayList (covered in Collections), so a full arrays tutorial has diminishing returns.

Object-oriented programming is a distinct paradigm with its own set of concepts (encapsulation, inheritance, polymorphism, abstraction). It deserves its own focused section (Object-Oriented Programming) rather than being crammed into "basics." You can write real, useful programs with just variables, methods, and file I/O — you can't do anything in Java without them.

The public static void main(String[] args) signature is explained briefly in the first tutorial, but there's no standalone tutorial on it because there's very little to explain — it's the entry point that the JVM calls. The interesting questions (packages, access modifiers, the classpath) only make sense after you understand classes and OOP.

Where to Go After Basics

Object-Oriented Programming

The natural next step. Learn to design programs around classes and objects — the way real Java applications are structured. Covers encapsulation, inheritance, and how to think in terms of objects rather than procedures.

Collections

Move beyond fixed-size arrays to dynamic data structures. ArrayList and HashMap are the two you'll use most often — they appear in virtually every Java program.

Database (JDBC)

Connect to MySQL, PostgreSQL, or other relational databases. The JDBC tutorial shows the raw API (which Spring Boot builds on top of) — understanding it makes framework magic less mysterious.