3.1 Lesson Outcomes
After completing this lesson, learners will be able to:
- Identify Java primitive data types.
- Use primitive data types in Java programs.
- Perform calculations using numeric data types.
- Apply modulus operations in Java.
- Convert words, numbers, and dates in Java applications.
3.2 Overview
Primitive data types are fundamental building blocks in Java programming. Java uses different data types to store numbers, characters, decimal values, and logical values.
This lesson introduces learners to practical applications of primitive data types through the creation of a simple calculator that handles:
- numbers,
- strings,
- dates,
- and mathematical operations.
Primitive data types are important in:
- calculations,
- user input,
- software logic,
- and data processing.
Understanding primitive data types is important because they are used throughout software development.
PA0301 — Demonstrate Understanding of Primitive Data Types
Java provides several primitive data types used in programming applications.
Common Primitive Data Types
|
ata Type |
Purpose |
|---|---|
|
int |
Whole numbers |
|
double |
Decimal numbers |
|
char |
Single character |
|
boolean |
True or False |
Reference Data Types
|
Data Type |
Purpose |
|---|---|
|
String |
Text |
|
LocalDate |
Date handling |
Example Primitive Variables
Java
int age = 20;
Java
double price = 19.99;
Java
boolean isStudent = true;
Using Modulus Operator
The modulus operator returns the remainder after division.
Example Modulus Operation
Java
int result = 10 % 3;
Expected Output
Plain text
1
Converting Words to Numbers
Programs can convert text input into numeric values.
Example
Java
String word = “one”;
Java
int number = 1;
Working with Dates
Java provides date handling functionality using:
Plain text
LocalDate
Example Date
Java
LocalDate date = LocalDate.parse(“2025-09-30”);
Example Calculator Program
Java
import java.time.LocalDate;
public class SimpleCalculator {
public static void main(String[] args) {
int a = 10;
int b = 3;
System.out.println(a % b);
String word = “one”;
int number = 1;
System.out.println(number);
LocalDate date = LocalDate.parse(“2025-09-30”);
System.out.println(date);
}
}
Importance of Primitive Data Types
Primitive data types support:
- calculations,
- logical operations,
- user input,
- and application processing.
3.5 Key Notes / Summary
- Primitive data types store basic values in Java.
- int stores whole numbers.
- double stores decimal numbers.
- boolean stores true or false values.
- The modulus operator returns division remainders.
- Java uses LocalDate for date handling.
- Primitive data types are important in software calculations and logic.