1. Intro new
1. Intro new
(OOP)
2
Course materials
Textbook
1. Object-Oriented Programming with Java, 2nd Edition, Barry J.
Holmes - Daniel T. Joyce
2. An Introduction to Object-Oriented Programming with Java Fifth
Edition, C. Thomas Wu
3. Lecture notes by the lecturer
Tools
1. Java 11 SDK
2. Eclipse IDE
3. NetBeans IDE
Introduction to OOP
Lecture Objectives
➢History
➢OOP Introduction
➢SDLC
➢Objects
l Programming Languages
Generations
•Generation 1—machine languages:
•Program data entered directly into RAM in form of 1s and 0s
•Generation 2—assembly languages:
•Mnemonic symbols represent instructions and data.
•Generation 3—high-level languages:
•Java, C#, python, C++, VisualBasic, …
•Designed to be easy to write, read, and manipulate.
•Requires translator component to translate to low level language
•Generation 4—high-level languages:
•Human terms
•SQL, python, MATLAB
l Programming Languages
l Programming Languages
l
l Programming Languages
Compiler
• Translates a program from a high-level to a low-
level language.
• Compile source program
• produces machine -or assembly- language
programs called object.
• Most high-level languages need a different
compiler for each type of computer and for
each operating system.
• Compilers are very large programs that are
expensive to produce.
Programming Languages
l
Java Byte-Code
• The Java compiler translate a Java program into intermediate
language (byte-code)
• An interpreter translates byte-code instruction to machine-
language
• the byte-code can be used on any computer with a byte-code
interpreter and without a need to recompile.
• Write once, run anywhere
Machine
language
00110101
java: Serves as a Java interpreter used to run Java
applications by reading and interpreting bytecode files
301: Database
101:Programming (Java)
l Effort of Software Phases
➢Procedure programming
• Where repeated part of code separated in a function e.g.,
factorial function
➢Modular programming
• No. of functions become huge
• functions Partition into logical parts according to
business/functionality e.g. all mathematical functions together
• can load modules that include functions we need only
Unstructured programming
❑ Example of Objects
John Mary 238-49-1357
Customer Dog Account Object name
Object ‘type’
OO PROGRAMMING
Object 2
Object 1
l
messages
Data
l Data
l
Function
l Function
l
Object 3
l
Data
l
Function
l
• To create sets of objects that work together
concurrently to produce a better SW that models
problem domain
• Promote greater design
• Easier to maintain
WHY OOP? • Adapts to changing requirements
• Code reusability & reliability
• Robust programming structure
• High level of abstraction
• Modeling reality
Modular programming
➢Classes are abstraction constructs, that define objects of the same type.
➢A class provides a special type of methods, known as constructors, which
are invoked to construct objects from the class.
➢A Java class uses variables to define data fields and methods to define
behaviors.
Class Objects
30
l
Class and Object
Class:
▪Category of things
▪Template to create objects
▪ A class name can be used in Java as the type
▪Defines the variables and methods common to objects of a same
type.
Object
▪a particular item that belongs to a class
▪Also called an “instance”
▪Example
String s1 = "Hello";
❑ Member variable
▪ Anywhere in the class
▪ Outside all methods
▪ Can be accessed
▪ internally with “this”
▪ externally with object reference
l
Instance method
import java.util.*;
Creating Package
❑ Default Package
• A class without any package defined is in a “default package”
• Classes in the default package cannot be referenced outside the
default package
Point class example
▪ Package definition
▪ Defining member variables
▪ Defining member methods
▪ Define methods with return data type
▪ Defining method with void return type
▪ Interaction with similar objects
▪ Using methods to update member variables
▪ Setter & Getters (aka accessors and mutators)
Constructor
/*It took three lines of code to make a properly constructed person. It would
be possible for a programmer to build a person and forget to assign a first or
last name.*/
}
}
User-Defined Constructor
public class Person { Person.java
public String firstName, lastName;
public Person(String initialFirstName, String initialLastName) {
firstName = initialFirstName;
lastName = initialLastName;
}
}
PersonTest.java
public class PersonTest {
public static void main(String[] args) {
Person p = new Person(“Hamza", “Ezz");
DateTest.java meeting
49
GARBAGE COLLECTION
50
ASSIGNMENT
▪ Tutorials point
▪ How to do in Java
▪ OOP course notes