By Tony Bevis on Thursday, 10 August 2023
Category: Java

Java programming course: 1.3 What is object oriented programming?

This is Lesson 1.3 of the Java programming course.

What is object-oriented programming?

Object-oriented programming is an attempt to model the real world more closely when developing software, compared to procedural languages. The two key terms you need to understand at this stage are class and object:

Simple object-oriented example

To give an example, suppose you want to model an animal. When naming a class, it is conventional to use a singular noun with its initial letter capitalised, so you might call the class Animal.

Now you have decided to create an Animal class, you need to think about two types of things that are common to all animals; its attributes (i.e., what it is composed of) and its behaviours (i.e., what it can do in response to a request):

  1. What attributes will it need? You might consider the following:
    > Each animal will have a name (e.g.,, Fido, Cuddles, etc.) 
    > Each animal will have a gender (male or female) 
    > Each animal will be a certain number of years old  

  2. What behaviours will it need? You might consider the following:
    > Another object might want to know a particular animal's name
    > Another object might want to know a particular animal's gender
    > Another object might want to know a particular animal's age
      

Java variables and methods

In Java, each attribute value is stored in an area of memory known as a variable and each aspect of its behaviour is defined in a method. Variables and methods are given unique names so that they can be identified.

The next lesson will discuss how Java programs are developed.

Lesson 1.4 How Java programs are developed

Related Posts

Leave Comments