Red information was taken from the Redhill 2019 OOP theory test.
Blue information was taken from the Redhill 2022 OOP theory test
Green information was taken from the Redhill 2021 OOP theory test.
Light blue information is taken from the Redhill 2020 OOP theory test
Pink information is taken from the 2018 Redhill OOP theory test
Object-oriented programming refers to a type of computer programming in
which programs define the data structure but also the type of operations that can be
applied to the data structure. It is also a method of modelling real-world problems by
indicating the properties of the object as well as its behaviours.
Properties
● The ability to reuse code
● It makes the development and maintenance easier
● Oop allows for information hiding
● Ability to simulate real-world events more easily
● Additional functionality can be added to the class
● Many objects can be created from the same class definition
● Simplifies software development
TERMINOLOGY
A class is a blueprint for an object and defines how the objects created from it will
behave. A class can be used to instantiate multiple objects()
NB! An array of objects can be created and this creates more robust code because it
can be processed all at once within a program reducing the amount of objects that
need to be insatiated.
An array of object advantages-: code is more robust – no need to ensure that
separate array elements are aligned when searching, sorting etc.
A collection of objects can be processed together in a single loop.
An object-The instance of a class(state represents the value of an object
Behaviour represents the behaviour of an object such as a deposit
Identity object identity is typically implemented via a unique ID)
(In simple terms this means that the object associated with class has unique
methods that are what is referred to as behaviours and have different values for
each field )
Constructor-This is used to create an instance of a class and assign values to the
objects fields(not void or typed and shares the name of the class)
NB Constructor is used to initialize the fields of an object:
Default constructor-no parameters
Pramatirized constructor-used to provide different values to distinct objects
The method is a block of Java statements inside a class which has a name and
performs an action
Encapsulates-occurs when a class combines the fields and methods into one unit
This provides control over the data and you may make it read-only or write-only
Void-dose not return value(MUTATOR METHODS )
Typed-Returns a value(must be a part of a large statement)
MUTATOR ACCESSOR
typed VOID
HAS NO PARAMETRIZED DOES HAVE A PARAMTERISED
CONSTRUCTOR CONTRUCTOR.
RETURNS A VALUE DOES NOT RETURN A VALUE
ASSIGNMENT OR CONDITION EXAMPLE ACCESSOR METHODS )
Non-static- belongs to an object of a class(objects get their copy of everything
defined as non-static)
Static belongs to a class(all static methods or fields do not copy across because
they are shared amongst all objects the class creates)
NB! When a field is declared as static there would be only one copy of the field in
memory whereas if a field is declared as static every object has a copy of the field in
memory increasing data redundancy)
NB!-A static field must be accessed by a static method(That is proper programming
principles), however, it can be accessed by non-static methods(See page 94 of the
programming textbook)
The code to access the static field is Class. variable
Constant fields-Constant fields are fields that cannot be changed and are declared
as public.
Declaring constant fields in a UML class diagram
+CAT=” Hip HOP”: String
To String methods: Combines the fields of an object into a neatly formatted
string so that the object’s fields can be displayed in an output statement in the
application class.NB! Every time there is a to-string method there is overriding
taking placel
Helper methods
Helper methods are methods that assit another method achieve its desired task and
are usually called up inside another method
Sometimes, methods are declared private, and are only able to be
invoked by other methods that are also members of the class since the user of
the class does not need to be aware of the irrelevant implementation
Details of the helper method being used..
Static non-static
Ascocaiuted with class Associated with an object of a class
Does not instantiate an object of the Must instantiate an object of the class
class
Class name. method name Object name. method name
Using variables in class is useless Variables declared in the class do not
because they have to be sent as have to be sent to every method
parameters into every method
Method signatures: The signature is made up of the method name and its
parameters,
Any class that wants to run must have a main method that is used to instantiate an
object of the definition class
Public methods/variables that are shared by all other classes
protected -methods or variables being shared with classes in the same package or
classes with inheritance
Private-Variables that are only used in the class they were created in
Default access modifiers: accessible only within the package
Overload methods have methods with the same name in a class but different
parameters. increases the readability of the program.Allows the class to define
multiple methods that have the same name,but respond to correspondly to different
messages sent to the class.Provides the program with flexibility.It can be used to
create objects with different fields by passing different types of data.
Override methods: when a subclass implements a method inherited from the
superclass this method is said to be overwritten.
The subclass has the same method as declared in the parent class it is known as
overridingMethod overriding is used to provide the specific implementation of the
method that has been provided and runtime polymorphism. As part of polymorphism,
one task is performed in different ways. Another aspect of polymorphism is the ability
of an object to behave either as a superclass object or a subclass object,
polymorphism allows a more general parent class to contain a method. The ability of
an object to behave differently depending on whether it’s a parent or child object.
NB! For method overriding the method must differ in terms of the
data type of parameters or number of parameters present. This
does not include the return type of the method and the declaration
type of the method.
Api-the way in which one program uses another program
Instance variable-created inside a class but outside the methods
(does not get memory until compile time only gets memory when compiled )
Inheritance-when an object acquires all the properties and behaviours of the parent
object.When a class acquires all the properties of and behaviours of the parent class
providing code reusability.
Imfomation hiding -Keeping the implementation details
of a class hidden from the class user
.
Scope and lifetime variables
The scope is where a variable can be used in a program
Lifetime is from the start of the squiggly brackets to the end of the squiggly brackets
INFORMATION HIDING-Makingh fields and even some private methods effectively
hide the inner workings of a class from the class user. This is known as information
hiding where the inner workings of the class are hidden from the user's perspective
and the complexity is hidden. The implication details are hidden using encapsulation
or private fields. Classes are not allowed to know the implementation details of
others
Recursion-in which a method calls itself continuously
Super is used to refer to the parent's immediate parent class object
This-there can be a lot of usage of the java this keyword a reference variable that
refers to the current object
JVM-the Java virtual machine compiles source code and runs the programs
Method-Member of a class that does some processing(code of reusability and code
optimisation)
Package-a group of similar type classes
RefactorTo improve a program without changing the way it works (i.e., its API). Examples include
renaming�fields or variables, streamlining code, etc. Very important in agile development because of the
emphasis on self-documenting cod
Encapsulation vs information hiding
Encapsulation is a language construct that facilitates the bundling of data (�fields) with
the methods operating on that data into a single class. Information hiding is a design
principle that strives to shield client classes (that have the object of the class or extend
that class) from the internal workings of a class. I.e. making the �fields private and
accessing them via public/protected methods like constructor, accessor and mutator
methods. Encapsulation facilitates but does not guarantee, information hiding. Smearing
the two into one concept prevents a clear understanding of either.
Take note of: Non-static fields cannot be used in static methods however static fields
can be used in non-static methods.
A simpler way of referring to the difference
Encapsulation is a fundamental concept in programming where methods and
properties are combined into a single unit. It involves packaging information
within a component in a way that hides certain aspects while making others
visible, thus promoting information hiding. The principle of information hiding
emphasizes keeping properties and methods as private as possible from the
user, ensuring that they only have access to code essential for the
application's functionality, rather than exposing all internal code.
Inheritance:
Advantages:
Additional functionality can be added to the child class
Base classes would be tried and tested, thus allowing extended classes to be
created quickly and reliably. Can re-use code from the superclass, ie less
repeating of similar code
Data Structures-describes how data is stored and organised in a computer so that it
can be used efficiently.
Algorithms are used to manipulate these data structures in memory.
Primary memory: Variables arrays, user-defined objects and a combination of the
above.
A decomposition problem is divided into smaller parts when problems are designed.
The smaller parts are divided further and this process is called abstraction.. This
focuses on solving each part of the problem. The programmer focuses on the
method in a sense.
The arrays-static array is a data structure that stores a fixed collection of identical
type, these items are arranged sequentially in memory and number using an index
starting from 0
Advantage combines elements of the same data type so that elements can be
addressed using one identifier name with an index or subscript. A for loop can be
used to process code drastically increasing the efficiency when running.
Int arr[]=new int [];
Static Dynamic array is declared without the
Max amount in the array is set number of elements
You make this static array large to A dynamic array will expand and
accommodate all scenarios contract as needed
Acess using arra[num] avearrr.get3
array.lenth() array.size()
Can be of primitive data types Cannot be a primitive data type
Parallel Arrays-their are two arrays that store data and are lined by their subscripts to
each other
Disadvantages-If you wanted to sort the array you would have to ensure that all
elements of both arrays were aligned . You would have to ensure each related
element stayed in the same position in the array.
OOP-used when dealing with large problems, since sections can be subdivided into
independent objects which can be reused in other project
Don't use: the program is small and trivial, not reused, has no similar sections, and
code does not need to be adapted in the future.
Use when the program is large and needs to be well organised, programs need to be
flexible, and repetition and the program will be reused.
Inheritance and composition
Inheritance is when one class is derived from another class
composition is when a class is the field of another class.
Changes in the superclass may The internal workings may
affect the child's class change if the method signature
is kept the same
Specialized version of the When one object has another
superclass object as its field
Designed to use all methods of The object usually uses some
ethe superclass of the methods of the other
classes
A subclass can inherit from one An object can have many
super claas objects as fields
An object can be composed of another object
Secondary Storage: The place where data is permanently
stored-when data is changed while in RAM it is written to
secondary storage.
Text Files text file is a computer file that is structured as a
sequence of lines of electronic text. The end of the file is denoted
by placing a special character at the end of the text file, known as
an end file marker.
Advantages-they are ideal for storing small amounts of data, its
easy to transport textfiles and can be transferred. Most formats will
export it to comma separate value
They do not need any additional software installed
Disanavatages-no additional functionality can be added, all
manipulation of the file must be done via a program
They are not secure and data may be redundant;
Databases:A relational database provides and effectives manner
oforganising data logicvally so that it can be retrieved using sequel
statements.they are based on a structure of tables which are
logicvally connected to eachother in menagful ways.
Adavaantages-data is only stored once
● Queries can easily be carried out
● Better control and security-tables can be set to view only
● DBms-manages the security access and creation of data in
the database
● Data integrity-Dmbms provides validation rules to reject
incoreect dat such as invalid dates
● Refrential integrity-no record can refer to another record that
does not exist
● Concurrency control-If data is updated by multiple
applications it must be done in a controlled way
● Backup and recover_-subsystem that is responsible for
recovery
● DatabaseSciurity-authentication-validating credentials
● Authorization-detremines particular resources the user can
use
Disadvantages of a database
Cost-specialized hardware and software are require to access the
database
Complexity-if applications are used a join driver is required and
queries are required to access the database and tables need to be
normalized
Hardware Performance-large databases might require more servers
Most desktop computers can process smaller and less complex
databases large and extremely
Damage to the database-sine many programs will be using the
database, if the database is corrupted or damaged,all these
programs will affected
Poor database design that is not scalable
Data base and textfiles
Data base textFile
Data is well structured Data is not structured
Complex to set up the database Very easy to set up
server and additional software
Transferring data is a complex Data can be copied and pasted
process
Dnms provides additional A textfile has no built-in
security to the database security it is not designed to
support multiple users.
Software is expensive Textfiles are feely available as
Drivers are needed to access feature of the op system
database via programs Utilities provided to read and
write to text files