FOUNDATIONS
OF
COMPUTATIONAL
THINKING AND PROGRAMMING
Object-oriented languages
Learning Objectives
This session will cover object-oriented programming
languages.
1. C++
2. Java
3. Python
Overview: Object-oriented
languages
Object-oriented languages (OOLs) are programming languages based
on the principles of object-oriented programming (OOP), which
organizes code into objects—self-contained units that bundle data
(attributes) and behavior (methods). Key features of OOLs include:
• Encapsulation: Data hiding and controlled access using classes and
objects.
• Inheritance: Creating new classes based on existing ones to
promote code reuse.
• Polymorphism: Enabling objects to take multiple forms, allowing
flexibility in function implementation.
• Abstraction: Hiding complex implementation details while exposing
essential features.
Popular OOLs include Java, Python, C++, C#, and Ruby
C++ Language
C++ incorporates the entire C
language, adding powerful
features, while retaining much of
C’s syntax, efficiency and utility.
It is used to write code at all
levels including applications,
operating systems and firmware.
C++ Language
C++ is an extension of the C
programming language. It was
developed by Bjarne Stroustrup in the
late 1970s.
It is a powerful, flexible and general-
purpose programming language that
supports a number of different
programming paradigms, such as Bjarne Stroustrup
object orientated, procedural,
functional and generic programming.
Simple C++ Code
#include <cstdio>
int main ( )
puts(“Hello World!”);
return 0;
}
Java
In 1991, a team of engineers at Sun
Microsystem started working on
developing Java. Among them was
James Gosling who is known as the
father Java.
The initial name used for Java was
Greentalk and later on it is changed to
Oak.
Due to trademark issues with Oak
Technologies, the name has finally James Gosling
changed to Java.
The first version of Java was released in
Java is a compiled
language
Java is a compiled language
because its code is first converted
into bytecode before execution.
When you run a Java program:
1.The Java compiler (javac)
converts source code (.java) into
bytecode (.class).
2.The Java Virtual Machine (JVM)
interprets and executes the
bytecode.
This makes Java platform-
independent (via the JVM) while
still benefiting from compilation for
Uses of Java
Java was originally designed for
interactive television, however, at Web
Applicatio
the time it was a very advanced ns
technology for the digital cable
Mobile
television industry. Banking
Software
Applicatio
ns
Java is a general-purpose Uses
programming language. of
It is one of the most widely used Embedde
Java Desktop
programming languages in the world, d
Systems
Applicatio
ns
powering billions of devices.
Web
On of the key reasons behind its huge Servers
popularity is its platform independent
Features of Java
Simple
High
Secure
performance
Robust Portable
Features
of Java
Object
Intermediate
orientated
Multi- Platform
threading independent
Java Components
There are two most important
components to execute any java
program:
Coding ---→ Compilation ( JDK ) ---→ Execution ( JRE)
1. Java Development Kit (JDK)
compiles java source code and
generates .class file, in the form of Java Code Compiler Java Code
byte code, which can be run on any
operating system. Code.java Code.class
2. Java Runtime Environment (JRE)
provides environment to
execute .class file. Java Virtual
Machine (JVM) is the most
Python
Python was invented by Guido van
Rossum in 1991 at CWI in the
Netherlands.
Python is a widely-used general
purpose (both industry and academia)
high-level Programming language.
It combines the power of systems
languages, such as C and Java, with
the ease and rapid development of
Guido van Rossum
scripting languages, such as Ruby.
Python is an interpreted
language
Python is an interpreted language
because its code is executed line by line
by an interpreter rather than being fully
compiled into machine code before
execution. When you run a Python script:
1.The Python interpreter reads the
source code (.py file).
2.It converts the code into bytecode (an
intermediate format).
3.The Python Virtual Machine (PVM)
executes the bytecode.
This allows for cross-platform
compatibility, easy debugging, and
dynamic execution, but it can be slower
than compiled languages like C or C++.
Simple Java Program
class HelloWorld {
public static void main (String
args[] ) {
System.out.println(“Hello World!”);
}
}
Python History
• Python reached version 1.0 in January 1994. The major new
features included in this release were the functional
programming tools.
• Python 2.0 was released in 2000, with many new features
added.
• Python 3.0, adjusting several aspects of the core
language, was released in 2008.
• Python 3.0 is backwards-incompatible.
• Codes written for Python 2.x may not work under
3.x!
Python Philosophies
• Beautiful is better than ugly
• Explicit is better than implicit
• Simple is better than complex
• Complex is better than complicated
• Flat is better than nested
• Sparse is better than dense
Python Features
• Simple and Minimalistic
• Easy to Learn
• High-level Language
• Portable
• Interpreted
• Embeddable
• Extensive Libraries
• Free, Open Source, … and
Fun!
Simple Python
Statements
Summary
• Object-oriented languages structure code into
objects, promoting reuse and scalability.
• There are many object-oriented languages out there,
such as C++, Java and Python.
• C++ was developed by Bjarne Stroustrup in late
1970s;
• Java was developed by James Gosling in 1996
• Python was developed by Guido van Rossum in
1991.
Further
reading
Goodrich, M. T. et al. (2022) Data Structures and
Algorithms in Java. Wiley
Liang, D. Y. (2021) Introduction to Java Programming and
Data Structures, Comprehensive Version. 12th edn.
Pearson
Hunt, A. et al. (2000) The Pragmatic Programmer: From
Journeyman to Master. 1st edn. Addison-Wesley