📘LESSON 7
3.1 Lesson Outcomes
After completing this lesson, learners will be able to:
- Define variables in Java.
- Perform operations using Java operators.
- Explain classes and objects in Java.
- Define fields, constructors, and methods.
- Explain interfaces in Java.
- Explain the purpose of packages in Java.
3.2 Overview
Java programming is built around core programming concepts that support software development and object-oriented programming. These concepts help developers organize code, create reusable components, and build structured applications.
This lesson introduces learners to Java core concepts and explains how variables, operations, classes, objects, interfaces, and packages are used in Java applications.
Java core concepts are widely used in:
- enterprise applications,
- banking systems,
- Android applications,
- web development,
- and software engineering.
Understanding Java core concepts is important because they form the foundation of Java programming and object-oriented software development.
KT0701 — Variables
A variable is a named memory location used to store data values in a Java program.
Variables allow programs to:
- store information,
- process data,
- and perform calculations.
Variable Declaration
int age = 25;
Components of a Variable
| Component | Purpose |
|---|---|
| int | Data type |
| age | Variable name |
| 25 | Stored value |
Types of Variables
| Type | Example |
|---|---|
| Integer | int |
| Decimal | double |
| Character | char |
| Boolean | boolean |
Importance of Variables
Variables support:
- data storage,
- calculations,
- and program processing.
KT0702 — Operations
Operations are actions performed on data values using operators.
Java supports:
- arithmetic operations,
- comparison operations,
- and logical operations.
Arithmetic Operators
| Operator | Purpose |
|---|---|
| + | Addition |
| – | Subtraction |
| * | Multiplication |
| / | Division |
| % | Modulus |
Example
int total = 10 + 5;
Comparison Operators
| Operator | Purpose |
|---|---|
| == | Equal to |
| != | Not equal to |
| > | Greater than |
| < | Less than |
Importance of Operations
Operations support:
- calculations,
- comparisons,
- and logical processing.
KT0703 — Classes + Objects
A class is a blueprint used to create objects.
An object is an instance of a class.
Class Example
public class Student {
String name;
int age;
}
Object Example
Student student1 = new Student();
Fields
Fields are variables declared inside a class.
Example of Fields
String name;
int age;
Constructors
Constructors are special methods used to initialize objects.
Constructor Example
public Student() {
System.out.println("Object Created");
}
Methods
Methods are blocks of code used to perform tasks.
Method Example
public void display() {
System.out.println("Hello");
}
Importance of Classes and Objects
Classes and objects support:
- object-oriented programming,
- reusable code,
- and software organization.
KT0704 — Interfaces
An interface is a structure that contains method declarations without full implementation.
Interfaces define behaviors that classes must implement.
Interface Example
interface Animal {
void sound();
}
Implementing an Interface
class Dog implements Animal {
public void sound() {
System.out.println("Bark");
}
}
Importance of Interfaces
Interfaces support:
- abstraction,
- flexible design,
- and code standardization.
KT0705 — Packages
A package is a collection of related classes and interfaces.
Packages help organize Java programs.
Package Example
package school;
Benefits of Packages
| Benefit | Purpose |
|---|---|
| Organization | Groups related classes |
| Reusability | Reuses components |
| Access Control | Controls visibility |
Importance of Packages
Packages improve:
- software organization,
- maintainability,
- and project structure.
3.5 Key Notes / Summary
- Variables store data values in Java programs.
- Operations perform calculations and comparisons.
- Classes are blueprints for objects.
- Objects are instances of classes.
- Fields store object data.
- Constructors initialize objects.
- Methods perform tasks.
- Interfaces define behaviors.
- Packages organize Java applications.