FREE COURSE | BEGINNER

Java Programming Fundamentals

Build reliable applications with Java, from basic logic to object-oriented programming.

Learning objectives

Compile and run Java programs, use variables and control flow, process arrays, and model student records with classes and objects.

Prerequisites: basic computer skills. Use a JDK 17 or newer for local practice.

01. Introduction to Java and JVM

Java source is compiled by javac into bytecode. The Java Virtual Machine (JVM) executes bytecode on supported platforms. Java is statically typed and supports object-oriented programming.

Java source code

Expected output (original example)

Hello, Java!

Editing code does not change this reference output. Save as Main.java and run locally to test changes.

Try it yourself

Change the greeting and predict the output.

02. JDK Installation and Program Structure

Install a JDK from a trusted provider. Check java -version and javac -version in a terminal. Save each example as Main.java, then run javac Main.java followed by java Main. The conventional main method is the entry point; braces delimit blocks and semicolons end most statements.

Java source code

Expected output (original example)

My first program

Editing code does not change this reference output. Save as Main.java and run locally to test changes.

Try it yourself

Compile and run the program locally. Remove a semicolon and observe the compiler error, then restore it.

03. Variables, Data Types and Input/Output

int stores whole numbers, double stores floating-point numbers, boolean stores true or false, and String stores text. Scanner reads input; nextInt reads an integer. This example uses a fixed sample input so it is reproducible.

Java source code

Expected output (original example)

Ana | 19 | 85

Editing code does not change this reference output. Save as Main.java and run locally to test changes.

Try it yourself

Replace the Scanner argument with System.in to read a score from your terminal.

04. Operators and Expressions

Arithmetic operators include +, -, *, / and %. Integer division truncates toward zero. Comparison operators produce booleans; && and || combine conditions.

Java source code

Expected output (original example)

3
3.5
true

Editing code does not change this reference output. Save as Main.java and run locally to test changes.

Try it yourself

Change b to 3 and predict all three outputs.

05. Conditional Statements

Use if, else if and else to select a branch. Conditions must be boolean expressions. Use equals for String content comparison rather than ==.

Java source code

Expected output (original example)

Passed

Editing code does not change this reference output. Save as Main.java and run locally to test changes.

Try it yourself

Test scores 90, 75 and 74 to examine boundary conditions.

06. Loops and Arrays

A for loop repeats statements; a while loop repeats while its condition is true. Arrays hold fixed-length sequences of one type and use zero-based indexing. The enhanced for loop visits each element.

Java source code

Expected output (original example)

85.0

Editing code does not change this reference output. Save as Main.java and run locally to test changes.

Try it yourself

Add a fourth score and calculate the new average.

07. Methods, Classes and Objects

Methods group reusable behavior. A class defines fields and methods; an object is an instance created with new. Constructors initialize objects. Private fields support encapsulation.

Java source code

Expected output (original example)

Ana: 85 - Passed

Editing code does not change this reference output. Save as Main.java and run locally to test changes.

Try it yourself

Create another Student object and print its description.

08. Interactive Java Practice Lab

Trace a for loop that adds integers to a running total. The interactive simulation below models the original loop; it does not execute edited Java code.

Java source code

Expected output (original example)

15

Editing code does not change this reference output. Save as Main.java and run locally to test changes.

Loop simulator

Sum: 15

JavaScript simulation, not a Java compiler or JVM.

Try it yourself

Predict the sum for 10 before running the simulation.

09. Mini Project: Student Record System

Combine classes, constructors, arrays, methods and conditional logic. This console prototype stores fictional records in memory, not a database. Each student has a name and score; the report displays a pass/fail result.

Java source code

Expected output (original example)

Ana: 85 - Passed
Ben: 70 - Failed

Editing code does not change this reference output. Save as Main.java and run locally to test changes.

Try it yourself

Add a third record, calculate the class average, and validate that scores are between 0 and 100.

10. Knowledge Check

Continue learning with C# Fundamentals.