SIS2024Y Object-Oriented Programming: Introduction To Object Orientation
SIS2024Y Object-Oriented Programming: Introduction To Object Orientation
SIS2024Y Object-Oriented Programming: Introduction To Object Orientation
Object-Oriented Programming
Lecture 1
Introduction to Object Orientation
1
Agenda
• Object-Orientation
• Object-Oriented Programming (OOP)
• Objects and Classes
• Object-Oriented Concepts
– Abstraction
– Encapsulation
– Hierarchy
• Getting started with Java
• My first java programme
2
Object-Orientation
• Object-Oriented is about trying to represent the ‘objects’
that we find in the real world in software.
3
Object-Oriented Programming
• OOP is a method of implementation in which
programs are organized as cooperative collection
of objects, each of which represent an instance of
some class, and whose classes are all members of
a hierarchy of classes united via inheritance
relationships. [Booch]
4
What is an object?
• Objects are the elements through which we
perceive the world around us.
6
Object Example 2 – Bank Account
• A Bank Account can also be considered as an object.
7
Activity 1
• List out the State and Behaviour of a Student
object?
8
What is a Class?
• The Object-Oriented approach invites us to understand the
world, the problems around us in terms of objects and
classes.
9
Class Structure
• A class consists of 3 parts:
– Name (or identity): identifies the class
– Variables (or attribute, state, field): contains the static
attributes of the class
– Methods (or behaviors, function, operation): contains the
dynamic behaviors of the class
10
Classes and Abstraction
• Abstraction is the concept of exposing only
the required essential characteristics and
behavior with respect to a context.
11
Encapsulation
(Information Hiding)
• Encapsulation separates the external aspects of an
object, which are accessible to other objects, from the
internal implementation details, which are hidden from
other objects.
12
Abstraction v/s Encapsulation
http://stackoverflow.com/questions/16014290/simple-way-to-understand-encapsulation-and-abstraction
13
Hierarchy
• Abstraction is a useful concept that allows us to
understand complex problems by defining
specific views.
15
Hierarchy Examples
Inheritance
http://faculty.ycp.edu/~dhovemey/f
all2005/cs102/lecture/9-8-2005.html
Composition / Aggregation
http://gateoverflow.in/54244/isro2014-11
16
Getting started with Java
• Java is an object-oriented programming language originally
developed by Sun Microsystems and released in 1995.
1. Java Platform, Standard Edition (Java SE) – To develop and deploy Java
applications on desktops and servers, as well as embedded environments.
2. Java Platform, Enterprise Edition (Java EE) - is the enterprise standard to build
scalable business services that feed dynamic web and mobile applications.
3. Java Platform, Micro Edition (Java ME) - is a Java platform designed for
embedded systems (mobile devices are one kind of such systems). Target devices
range from industrial controls to mobile phones and set-top boxes. Java ME was
formerly known as Java 2 Platform, Micro Edition (J2ME)
20
Java Program Structure
• Example:
21
Java Program Structure
22
Java Program Structure
• public class Hello
– This creates a class called Hello.
– All class names required to start with a capital letter.
– The word public means that it is accessible by any
other classes.
• {…}
– The 2 curly brackets are used to group all the
commands together so it is known that the commands
belong to that class.
23
Java Program Structure
• public static void main
– The word public means that it is accessible by any other classes.
– The word static means that it is unique.
– The word void means this main method has no return value.
– main is a method where the program starts.
• System.out.println();
– System is a utility class and provides functionalities like facilities
provided functionalities like standard input, standard output,
and error output streams; access to externally defined
properties and environment variables; loading files and libraries;
– println method prints text on the screen with newline.
24
My first Java program
• Write a simple program to display the following
string on console: “My first Java program!”
• Steps:
1. Create a new Java project, Ex1
2. Create a new package, LectureOne (if asked)
3. Create new class, FirstProgram
4. Write main method
25
FirstProgram.java
• Class FirstProgram
• Output on Console
26
References
• http://docs.oracle.com/javase/tutorial/java/ja
vaOO/accesscontrol.html
• http://www.w3schools.in/java-tutorial/intro/
27