CSI21M1 Java Programming Notes, prepared by Mr. S. Nyika, Semester I, 2019
Lecture 1: Object Oriented Programming
Objectives:
At the end of this lecture, students will be able to:
• explain the important principles of Object Oriented Programming
• define the term class
• define the term object
• explain the relationship between a class and its objects
• understand that there are two kinds of programmers
• explain why class programmers need to hide data
• advantages of Object Oriented Programming as opposed to linear programming
• Write a class in java syntax
Notes:
A class in Java is the same as a class in C++. It has attributes and behaviour which are put together as
one unit. This unit is called a class. A class is therefore set of attributes put together in one container or
capsule. This process of putting together attributes and methods (behaviour) is called Encapsulation.
An example is the car. When this is taken as a class will therefore appear with attributes and methods or
functions. There are three principles which are used to make sure the class is well formed. These are
Encapsulation, Polymorphism and Inheritance. Encapsulation is the bundling together the attributes
and the methods as follows:
class Car
{
String carModel;
int engineNumber;
int yearManufatured;
void setCarModel(String model)
{
carModel=mode;
}
void setEngineNumber(int enumber)
{
engineNumber=enumber;
}
void setYearManufactured(int year)
{
yearManufatured=year;
}
String getCarModel()
{
return carModel;
}
int getEngineNumber()
{
return engineNumber;
}
int getYearManufactured()
{
return yearManufatured;
}
}
Page 1 of 4
Lecture 1: Object Oriented Programming
Objectives:
At the end of this lecture, students will be able to:
• explain the important principles of Object Oriented Programming
• define the term class
• define the term object
• explain the relationship between a class and its objects
• understand that there are two kinds of programmers
• explain why class programmers need to hide data
• advantages of Object Oriented Programming as opposed to linear programming
• Write a class in java syntax
Notes:
A class in Java is the same as a class in C++. It has attributes and behaviour which are put together as
one unit. This unit is called a class. A class is therefore set of attributes put together in one container or
capsule. This process of putting together attributes and methods (behaviour) is called Encapsulation.
An example is the car. When this is taken as a class will therefore appear with attributes and methods or
functions. There are three principles which are used to make sure the class is well formed. These are
Encapsulation, Polymorphism and Inheritance. Encapsulation is the bundling together the attributes
and the methods as follows:
class Car
{
String carModel;
int engineNumber;
int yearManufatured;
void setCarModel(String model)
{
carModel=mode;
}
void setEngineNumber(int enumber)
{
engineNumber=enumber;
}
void setYearManufactured(int year)
{
yearManufatured=year;
}
String getCarModel()
{
return carModel;
}
int getEngineNumber()
{
return engineNumber;
}
int getYearManufactured()
{
return yearManufatured;
}
}
Page 1 of 4