Chapter 2 — Java Fundamentals

📚 Chapter Overview

Data is the core of any program. In this chapter, you will learn how to store, categorize, and manipulate data using Java's strict typing system and operators.

Learning Objectives:

2.1 Variables and Primitive Types

Part 1 — Definition

A variable is a container that holds data while the Java program is executed. Java is Statically Typed, meaning every variable must be declared with a specific type (e.g., int, float, char) before it can be used. Primitive types are the basic building blocks of data in Java.

Part 2 — Syntax

Main.java
int age = 25;
double price = 99.99;
char grade = 'A';
boolean isJavaFun = true;

Part 3 — Example

Problem: Calculate the total price of items in a cart.

Cart.java
int quantity = 5;
double unitPrice = 20.5;
double total = quantity * unitPrice;
System.out.println("Total Price: " + total);

Output: Total Price: 102.5

Part 4 — Video

Video: Coming Soon


2.2 Java Operators

Part 1 — Definition

Operators are symbols used to perform operations on variables and values. Java provides Arithmetic (+, -, *, /), Relational (==, !=, <, >), and Logical (&&, ||, !) operators.

Part 2 — Syntax

Main.java
int sum = a + b;
boolean check = (age >= 18) && (hasID == true);

Part 3 — Example

Problem: Check if a student passed based on their marks.

Grader.java
int marks = 75;
boolean isPass = marks >= 40;
System.out.println("Passed: " + isPass);

Output: Passed: true

Part 4 — Video

Video: Coming Soon


🏆 Chapter Challenge

Challenge Objective

Build a "Student Result Calculator" that uses various data types and operators.

Requirements

Step-by-Step Process

  1. Declare variables for name and subject marks.
  2. Sum the marks and divide by 3 to get the average.
  3. Use System.out.println to print the final result card.

Expected Deliverables

Solve in Compiler