Model G20 2027 at FLAME University, registrations now open

Introduction to Object Oriented Programming Concepts | ICSE Class 9 Computer Applications Notes

27 min read

On this page

This note covers programming approaches, objects and classes, data abstraction, encapsulation, inheritance, polymorphism, Java features, open source software, development tools, software requirements, applets and applications, compilation, bytecode, the Java Virtual Machine and uses of Java.

What is object oriented programming?

A program is an ordered set of instructions that tells a computer how to perform a task. A programming language provides the words and rules used to express those instructions. The program text written in that language is its source code. Programming involves preparing and writing programs to solve problems.

Java is a high-level programming language. A high-level language expresses instructions in a form that is easier for people to understand than machine language, the instructions directly understood by a computer. Java supports the object oriented approach to organising programs.

Definition: Object oriented programming, abbreviated to OOP, organises a program around objects that bring together related data and behaviour.

What do objects contain?

An object represents an identifiable entity. Its attributes are the properties represented by its data. Its behaviour consists of the actions it can perform. A method is a function belonging to a class or object; a function is a named unit of instructions performing a task.

Consider a mobile phone. Its model, colour and price describe properties. Storing a number and displaying missed-call details describe actions. In an object oriented representation, the data and the methods that work with it belong together.

A class specifies the data and behaviour shared by a category of objects. It may be regarded as a blueprint to create objects. An instance is a particular object of a class. The class describes the category; an object represents a particular member.

Understanding this distinction helps explain the four central principles: data abstraction, selecting essential features while hiding internal details; encapsulation, grouping related data and methods; inheritance, forming a class from an existing class; and polymorphism, allowing a common operation to take different forms.

How do procedure oriented and object oriented programming differ?

Procedure oriented programming, abbreviated to POP, organises a solution mainly around procedures or functions. A procedure is a group of instructions for a task. The programmer considers the processing steps and the data those steps need.

Object oriented programming organises the solution around objects and their responsibilities. The programmer identifies what the objects represent, which data describes them and which methods act on that data. Objects interact by requesting actions through methods.

What changes in the organisation?

BasisProcedure oriented approachObject oriented approach
Main emphasisProcedures and the sequence of actions.Objects, their data and their behaviour.
Problem descriptionWhat processing steps are needed?Which objects are involved and what can they do?
Organisation of data and actionsFunctions perform operations on the data supplied to them.Classes bring related data and methods into a unit.
Data protectionData is often shared between functions and passed from one to another, so it is less protected.Data can be hidden inside a class and reached through its methods, which gives greater security.
ReuseExisting functions can be called again.Class definitions can be reused, and inheritance can extend existing classes.

The difference concerns the main way a program is organised. It does not mean that an object oriented program stops using instructions, calculations or functions. Methods still contain instructions; these instructions are organised within the object oriented design.

In the mobile-phone representation, an object oriented description connects the phone's properties with its actions. A procedure oriented description gives greater attention to the steps required to perform the actions. The same real-world task can therefore be approached through different forms of organisation.

Note: Do not describe POP as incapable of reusing code. Functions support reuse. Inheritance provides an additional form of reuse in an object oriented design.

When comparing the approaches, use matched points. Compare their emphasis, organisation and reuse mechanisms directly. A statement about the data in one approach should be paired with a statement about the data in the other.

How does data abstraction hide unnecessary detail?

Data abstraction identifies the essential features of an object and separates them from its internal working. The user is given the information needed to use an operation without having to understand every step that implements it.

The implementation is the internal arrangement of data and instructions that makes an operation work. An interface, in this general sense, is the visible means of using a system. It lets a user request actions while the internal details remain hidden.

How does a mobile phone illustrate abstraction?

A person can receive a call on a mobile phone without knowing how its internal circuits carry out the task. The useful action is visible to the person. The internal mechanism does not have to be understood before that action can be used.

This separates what an object does from how it does it. The phone's available operations matter to its user, while the detailed arrangement of its internal components is outside that immediate task. Abstraction presents the essential view.

In programming, a class can present methods that perform useful operations while concealing the details behind them. The person using the class needs to understand what the available methods do and what information they require.

A student representation gives another illustration. Essential information can include a student's name, date of birth and course. Internal work such as calculating grades can be separated from the view presented to the user.

Rule: Identify the essential information or operation first, then distinguish it from the internal details hidden from the user.

Abstraction is not the removal of the machinery that makes a system work. Those details still exist. They are hidden from a particular view so that the system can be understood and used at an appropriate level.

How does encapsulation keep data and methods together?

Encapsulation combines related data and the methods that operate on that data into a single unit. In Java, a class provides such a unit. The data describes the objects of the class; the methods specify their behaviour.

The mobile-phone example groups model, colour and price with operations such as storing a number and obtaining missed-call details. This arrangement connects the description of the phone with the actions associated with it.

How is encapsulation related to data hiding?

Data hiding restricts direct access to internal data from outside the class. A member is a data item or method declared within a class. A private member is intended for use within its declaring class, rather than direct access by unrelated classes.

Encapsulation and data hiding are connected, but the words emphasise different ideas. Encapsulation concerns bringing data and operations together. Data hiding concerns controlling access. Merely placing data in a class does not explain how access to that data is controlled.

ConceptMain concernQuestion to ask
AbstractionPresenting essential features while hiding implementation detail.What does the user need to see?
EncapsulationGrouping related data and methods in one unit.What belongs together?
Data hidingRestricting direct access to internal data.How is access controlled?

Draw and label

Mobile-phone class

Draw a box divided into three parts. Put the class name at the top, model, colour and price in the data part, and storing a number and obtaining missed-call details in the methods part.

The boundary around the data and methods represents their grouping as a unit. It helps illustrate encapsulation. To explain data hiding as well, state that access to internal data is controlled; the box alone does not show the access rules.

How does inheritance support reuse?

Inheritance forms a new class from an existing class. The existing class is the base class, also called the superclass. The new class is the derived class, also called the subclass. These names describe the relationship between the classes.

The derived class can use inherited features and add features of its own. This supports code reuse, which means using existing program definitions again instead of independently rewriting the same common features.

How does the mobile-phone example work?

A general mobile-phone class describes features shared by mobile phones. An Android-phone class can be treated as a more specialised category within that general category. The relationship is that an Android phone is a kind of mobile phone.

The general category provides the base-class idea. The specialised category provides the derived-class idea. In a program model, the specialised class can build on the common description while including its own characteristics.

This is an is-a relationship: an object of the specialised category is also a member of the general category. It gives a useful way to recognise the intended relationship before considering any Java instructions.

Draw and label

Mobile-phone inheritance

Draw a box for the general mobile-phone class above boxes for the specialised phone classes. Use connecting lines to show that each specialised category derives from the general category. Label the general class base and the specialised classes derived.

Inheritance relates classes. Creating a particular object from a class is a different action. A new object is an instance of the existing class; a derived class is a new class related to another class.

Reuse does not mean every detail must be identical. The value of the derived class is that it can retain common features while providing a more specialised description. Access to inherited data and methods remains subject to the language's rules.

What does polymorphism mean?

Polymorphism means taking many forms. In programming, it describes situations in which a common operation or name is associated with different behaviour according to the relevant data or object. The operation retains a shared meaning while its particular form can vary.

How can one operation have different forms?

An operator is a symbol that specifies an operation. The plus sign, +, represents addition for numbers. For strings, which are sequences of characters used to represent text, the same sign can represent joining text. Joining strings is called concatenation.

This is a simple illustration of an operation taking different forms according to the kind of data involved. The symbol is the same, but the operation must be interpreted in the context of the data. Numerical addition and joining text are different actions.

In Java, method overloading is another way to express the many-forms idea. Methods share a name but have different parameter lists. A parameter is a named input in a method definition; an argument is a value supplied when the method is called.

A method call is a request to execute a method. Differences in the number or types of parameters allow suitable overloaded methods to be distinguished. The introductory idea is the shared name with different forms, rather than memorising complex program syntax.

What is the real-world connection?

Different kinds of mobile phone share recognisable operations, although their particular behaviour can differ. This provides an analogy for a common request being carried out in different ways. The analogy illustrates the idea; it does not establish how a particular phone's software is written.

Note: Encapsulation concerns grouping, inheritance concerns deriving classes, and polymorphism concerns different forms of an operation. Identify the relationship being described before choosing the principle.

Which features explain Java's usefulness?

Java combines a high-level language with an object oriented approach. A programmer can describe entities through classes and organise their actions through methods. This provides a way to connect the structure of a program with the objects represented in a problem.

What do simple, robust and secure mean?

Simple refers to features intended to make Java easier to learn and use. It does not mean that every Java program is short or that every problem is easy. A complex application still requires careful design and clear instructions.

Robust means designed to support reliable execution, meaning the carrying out of instructions, and the handling of errors. Java includes checks and facilities for responding to exceptional conditions. An exception is an event during execution that disrupts the normal flow of instructions.

Secure describes mechanisms intended to restrict unsafe operations and inappropriate access. A security feature reduces a category of risk; it does not establish that every application written in the language is free from defects or misuse.

What does platform independent mean?

A platform is the hardware and software environment in which a program runs. Platform independence means that Java's compiled, or translated, program can run on different compatible platforms without being rewritten specifically for each one.

Bytecode is the intermediate instruction form produced by the Java compiler. A compiler translates source instructions into another code form. The Java Virtual Machine, abbreviated to JVM, provides the execution environment for Java bytecode on the target platform.

FeatureMeaning to remember
SimpleDesigned to make programming more manageable.
RobustProvides mechanisms that support reliability and error handling.
SecureProvides mechanisms for restricting unsafe actions and access.
Object orientedSupports organising programs through classes and objects.
Platform independentBytecode can run through a compatible JVM on different platforms.

The condition of a compatible JVM matters. Platform independence does not mean that the same program executes directly on every processor without supporting software. The bytecode is portable, while the JVM must suit the environment in which it runs.

What are open source software and an IDE?

Source code is the program text written in a programming language. Open source software makes its source code available under terms that permit its study, modification and redistribution. Its licence states the conditions under which these activities are permitted.

A licence is a statement of permissions and conditions for using software. Access to source code and permission to use it are related but distinct issues. The terms determine what a person may do with the software.

How does open source differ from freeware?

Freeware is software available for use without payment, but its source code may not be supplied. The absence of a purchase price does not by itself make software open source. Availability of code and the permissions attached to it are central.

OpenJDK, the Open Java Development Kit, is an open source Java development project. A development kit provides tools for creating programs. For Java development, a compiler is needed to translate the source into bytecode.

How does an IDE help?

An Integrated Development Environment, abbreviated to IDE, brings programming tools together. An editor lets the programmer enter and change source text. Build tools prepare the program for execution. A debugger helps investigate and correct errors in the source code.

DrJava, NetBeans, MyEclipse and BlueJ are examples of tools used for Java work. These names identify development environments, not different programming languages. Java remains the language even when the tool used to edit and run a program changes.

Note: An IDE, a compiler and a JVM have different roles. The IDE brings tools together, the compiler translates Java source into bytecode, and the JVM supports the execution of that bytecode.

Using an IDE makes these activities accessible through a common working environment. It does not make translation unnecessary. Editing a program, compiling it and executing it remain distinct activities even when the tools present them together.

What hardware, software and version information are needed?

Hardware means the physical parts of a computer system. Software means the instructions and associated data that make the hardware perform useful work. A Java programming environment depends on both, so checking a program's language alone is insufficient.

Which parts of the computer matter?

The processor, also called the central processing unit or CPU, executes instructions. Memory holds instructions and data needed for processing. Storage keeps program files and other data for future use. Input and output devices allow information to enter and leave the computer.

Random Access Memory, abbreviated to RAM, holds data temporarily while the computer works. Storage keeps installed software and saved source files. These have different purposes, so the amount of storage available is not a substitute for sufficient working memory.

An operating system manages the computer's resources and supports other software. The chosen Java development tools must work with that operating system and the available hardware. The editor or IDE, compiler and execution environment must also work together.

Why does the Java version matter?

A version identifies a particular release of software. Java development tools and IDEs can have different versions. A compatible combination allows the selected tools to recognise the program and prepare it for the intended execution environment.

  1. Identify the operating system and the Java version used by the development environment.
  2. Check that the chosen IDE supports the selected Java development tools.
  3. Check the processor, working memory and storage against the requirements of that software release.
  4. Confirm that the environment can compile and run a simple Java application.

Compatibility means that the parts can work together as required. For the school programming laboratory, provide at least 2 GB RAM and a P-V or equivalent processor. The software baseline for Classes IX and X is a suitable operating system and BlueJ 5.4.2 or higher, or another suitable editor or IDE, with JDK 11 or higher. Choose mutually compatible releases and check their actual hardware requirements; these school-laboratory baselines are not universal requirements for every Java environment.

How do Java applets and applications differ?

A Java application is a program that can be launched as an independent application in a suitable Java execution environment. An applet, in the historical Java model, is a program hosted by a Java-enabled browser or an applet viewer.

An applet viewer is a tool that provides an environment for running applets. The distinction concerns the way the program is hosted and started. Both types involve Java, but they do not have the same launching arrangement.

How should the two types be compared?

BasisAppletApplication
Execution settingRuns within a suitable host, historically a Java-enabled browser or applet viewer.Is launched as an independent program in a suitable Java environment.
Dependence on a hostDepends on the applet host to manage its execution.Does not require an applet host.
Starting pointDoes not start from a main method; the host calls the applet's own methods.Starts execution from its main method.
Main distinctionHosted Java program.Independently launched Java program.

The term standalone means independently launched in this comparison. It does not mean that an application can operate without an operating system or the supporting software it requires. Independence from an applet host is the relevant point.

An educational online quiz is a possible use for a hosted Java program in the historical applet model. A student grading system is an example of an application task. The task name alone does not establish the program type; its actual execution arrangement determines the classification.

Note: A web-based application is not automatically an applet. Web-based describes access through the web, while applet describes a particular Java hosting model.

When identifying an applet, look for the specified host. When identifying an application, look for independent launching. Do not use the program's size or the fact that it displays a graphical screen as the deciding test.

How does Java source code become an executing program?

Compilation translates a program from its source form into another code form. In Java, the compiler produces bytecode. Execution is the carrying out of program instructions. Keeping these terms separate explains why compiling a program and running it are different actions.

Which forms of code must be distinguished?

TermMeaningRole in Java
Source codeThe program text prepared by the programmer.Input to the Java compiler.
BytecodeIntermediate instructions intended for a virtual machine.Output of Java compilation and input to the JVM.
Object codeThe machine code, made of processor-level instructions, produced when source code is translated.Not the same as portable Java bytecode: the Java compiler produces bytecode, and the JVM turns it into machine code for the platform.
Machine codeInstructions understood by the target processor.The processor-specific form used in carrying out the program.

Native code is machine code for a particular target platform. Object code is the same kind of machine-level code. The important Java distinction is between portable bytecode and processor-specific machine instructions.

What is the sequence?

  1. Write and save: use an editor or IDE to prepare Java source code.
  2. Compile: the Java compiler checks the source and translates valid code into bytecode.
  3. Provide the execution environment: a compatible JVM handles the compiled bytecode on the chosen platform.
  4. Execute: the JVM translates the bytecode into machine code for the platform and then executes it.

A syntax error is a violation of the language's writing rules. If compilation reports such errors, the source must be corrected and compiled again. A successful compilation does not by itself prove that the program produces the intended result.

A logical error is a mistake in the reasoning or instructions that causes an incorrect result. The program may still compile. Testing the behaviour is therefore a separate part of checking the program.

Draw and label

Java translation and execution

Draw a source-code box connected to a compiler box, then a bytecode box and a compatible-JVM box. Add a final box for execution on the target computer. Label each connecting arrow with the stage it represents.

Platform independence follows from the intermediate bytecode stage. Different platforms can provide their own compatible JVMs. The same bytecode can then be used without treating it as the native instructions of every different processor.

Object code must also be distinguished from an object in OOP. The first term concerns translated instructions. The second concerns an instance of a class. The shared word does not make the two concepts interchangeable.

Where can Java be used?

Java can be used in different application areas. An application area describes the kind of task a program serves. It does not mean that every product in that area uses Java, or that a product must use Java for all its parts.

Which application areas should be recognised?

  • Mobile applications: programs intended for mobile devices.
  • Desktop graphical applications: programs with a graphical user interface, abbreviated to GUI, through which a person interacts using visible controls, for example Acrobat Reader.
  • Web-based applications: systems accessed through the web, including banking systems and e-commerce, which means conducting commercial activities electronically.
  • Gaming applications: programs that provide games and their interactive behaviour.
  • Robotic applications: software associated with robots, including applications in health care.
  • Educational applications: online quizzes and student grading systems.
  • Chatbots: programs that interact conversationally, including customer-service and messaging uses.
  • Virtual assistants: software that helps users carry out tasks through a user-facing interaction.

These are examples of uses, rather than descriptions of how every system in a category is built. A banking system and an online quiz serve different purposes, although Java can be used in developing either kind of application.

How do these uses connect with the rest of the topic?

OOP principles concern how a program is organised. Development tools concern how it is written and prepared. Compilation and the JVM concern how it reaches execution. Application areas concern the tasks for which that programming work is used.

Keep these levels separate when explaining an example. Naming an educational application answers a question about use. Explaining that related data and methods are grouped together answers a question about encapsulation. Describing portable bytecode answers a question about execution across platforms.

Glossary

  • Object — An identifiable entity represented through its data and the behaviour associated with that data.
  • Class — A specification of the data and behaviour shared by objects belonging to a category.
  • Method — A function associated with a class or object that performs a defined operation.
  • Data abstraction — Presenting essential features while hiding internal details that the user does not need.
  • Encapsulation — Combining related data and the methods that operate on it within a single unit.
  • Inheritance — Forming a derived class from an existing base class to reuse and extend features.
  • Polymorphism — Allowing a common operation or name to have different forms according to context.
  • Open source software — Software with source code available under terms permitting study, modification and redistribution.
  • Integrated Development Environment — Software that brings editing, building and debugging tools together for program development.
  • Source code — The program text written by a programmer in a programming language before translation.
  • Bytecode — Intermediate instructions produced by the Java compiler for execution through a compatible virtual machine.
  • Object code — The machine code (processor-level instructions) produced when source code is translated; in Java it is formed from bytecode by the JVM and is not the same as bytecode.
  • Java Virtual Machine — The execution environment that translates Java bytecode into machine code for a particular platform and executes it.
  • Applet — A hosted Java program historically run through a Java-enabled browser or an applet viewer.
  • Java application — A Java program launched independently in a suitable environment without requiring an applet host.

Common errors and misconceptions

  • Misconception: A class and an object are the same thing. Correct: A class specifies a category of objects; an object is a particular instance of that class.
  • Misconception: Abstraction and encapsulation are interchangeable words. Correct: Abstraction presents essential features while hiding detail. Encapsulation groups related data and methods into a unit.
  • Misconception: Creating an object demonstrates inheritance. Correct: Object creation produces an instance. Inheritance forms a derived class from an existing base class.
  • Misconception: Procedure oriented programs cannot reuse code. Correct: Functions can be reused. Inheritance supplies an additional reuse mechanism in object oriented programming.
  • Misconception: Java bytecode is native machine code for every processor. Correct: Bytecode is an intermediate form that needs a compatible JVM on the target platform.
  • Misconception: An IDE and a JVM perform the same task. Correct: An IDE combines development tools, while a JVM supports bytecode execution.
  • Misconception: Freeware is necessarily open source. Correct: Freeware can be available without payment while its source code remains unavailable.
  • Misconception: Every web-based Java program is an applet. Correct: An applet uses a particular hosting model; web-based applications are a broader category.

Exam-style questions with model answers

Q1. Distinguish a class from an object in two points. [2 marks]
  1. A class is a blueprint specifying shared data and behaviour, whereas an object is a particular instance of that class.
  2. One class definition can be used to create many objects, whereas each object represents an individual instance with its own identity and instance-data values.
Q2. A mobile-phone model groups colour and price with methods for storing numbers. Its user can receive a call without knowing the internal circuitry. Identify and explain the OOP principle illustrated by each statement. [4 marks]
  1. The grouping of the phone's data and its associated methods illustrates encapsulation, because related components are brought into a single unit.
  2. Colour and price represent data, while storing numbers represents behaviour associated with the phone.
  3. Receiving a call without knowing the internal circuitry illustrates abstraction, which presents an essential operation while hiding implementation details.
  4. The user needs to know how to use the call operation, without understanding the internal mechanism that carries it out.
Q3. Explain the four OOP principles: data abstraction, encapsulation, inheritance and polymorphism. Give one separate point for each. [4 marks]
  1. Data abstraction presents the essential features needed by a user while hiding internal implementation details.
  2. Encapsulation combines related data and the methods that operate on that data into a single unit, such as a class.
  3. Inheritance forms a derived class from an existing base class, allowing common features to be reused and extended.
  4. Polymorphism allows a common operation or name to take different forms according to the relevant data or object.
Q4. A Java program is to be prepared from source text and run on different compatible platforms. Explain source code, compilation, bytecode, the JVM and platform independence in five connected points. [5 marks]
  1. Source code is the program text written by the programmer in Java. It expresses the instructions that the program is intended to carry out.
  2. Compilation translates that source text into bytecode. The Java compiler checks the source against language rules and reports compilation errors where it detects them.
  3. Bytecode is an intermediate instruction form intended for a virtual machine. It is distinct from the native machine instructions of a particular processor.
  4. The Java Virtual Machine provides the environment for executing the bytecode on a target platform. That JVM must be compatible with the compiled program.
  5. Platform independence follows because different platforms can provide compatible JVMs for the same bytecode, allowing the compiled program to run across those environments.
Q5. Distinguish freeware from open source software. [2 marks]
  1. Freeware is available for use without payment, but its source code may not be available.
  2. Open source software makes source code available under terms permitting study, modification and redistribution.
Q6. State three differences between procedure oriented and object oriented programming, covering emphasis, organisation and reuse. [3 marks]
  1. Procedure oriented programming emphasises procedures and processing steps, whereas object oriented programming emphasises objects, their data and their behaviour.
  2. In the procedure oriented approach, functions operate on supplied data. In the object oriented approach, classes bring related data and methods into units.
  3. Procedure oriented programs reuse functions through calls. Object oriented designs can reuse class definitions and use inheritance to extend existing classes.
Q7. Explain the difference between an IDE, a Java compiler and a JVM, giving one point for each. [3 marks]
  1. An Integrated Development Environment brings programming tools together, including facilities for editing source code, preparing programs and investigating errors.
  2. A Java compiler translates source code into bytecode and reports compilation errors. Its purpose is translation rather than providing the entire editing environment.
  3. A Java Virtual Machine supplies the environment for executing bytecode on a compatible platform. It has a different role from the source editor and compiler.
Q8. A Java program is hosted by a Java-enabled browser in the historical applet model. Another is launched independently in a suitable Java environment. Identify the two program types. [2 marks]
  1. The browser-hosted program is an applet because it depends on a suitable applet host for execution.
  2. The independently launched program is a Java application because it does not require an applet host.

Key takeaways

  • Object oriented programming connects the data describing an entity with the methods that represent its behaviour.
  • A class specifies a category of objects; a particular instance of that class is an object.
  • Abstraction hides implementation detail, while encapsulation groups related data and methods into one unit.
  • Inheritance supports reuse by forming derived classes from existing base classes; polymorphism allows different forms of a common operation.
  • An IDE combines development tools, while the Java compiler and JVM perform distinct translation and execution roles.
  • Java compilation produces bytecode, which can run on different platforms when compatible JVMs are available.
  • Open source concerns source availability and permissions; software being free of charge does not establish that it is open source.
  • Java applications are independently launched, while historical applets depend on a suitable host to manage their execution.

Test yourself

What do the letters OOP stand for?

OOP stands for object oriented programming, an approach that organises programs around objects with related data and behaviour.

Which principle lets a mobile-phone user make use of an operation without understanding its internal circuitry?

Data abstraction presents the essential operation while hiding internal implementation details from the user.

What is the difference between a base class and a derived class?

The base class is the existing class. The derived class is formed from it, reusing inherited features and potentially adding its own.

What does encapsulation combine?

Encapsulation combines related data and the methods that operate on that data within a single unit.

What is the output form produced by the Java compiler?

The Java compiler produces bytecode, an intermediate instruction form intended for execution through a compatible JVM.

Why must a platform provide a compatible JVM?

The JVM provides the execution environment for Java bytecode, allowing it to be carried out on that platform.

Is freeware necessarily open source?

No. Freeware can be available without payment while its source code is not made available.

Does successful compilation prove that a program produces the intended result?

No. A program can compile successfully while containing a logical error, so its behaviour still needs testing.