SlideShare a Scribd company logo
Object Oriented Programming
02b: Classes
Informatics Department –Parahyangan Catholic
University
Taken and adapted from Lionov’s Lecture Slide
AUGUST, 24, 2017
Class
o It’s time to code the object into a something that will be understood
by a computer (a software object)
o But, there is a problem: We may not want to describe each individual
object because there might be too many objects.
o Idea : Several objects may have many commonalities. Why don’t we
describe what is common just once?
Class
o We can group the objects that we
have identified based on their
properties & capabilities.
o Example: all books have the same
properties & capabilities although
they may have different values for
their properties. A book shelf have
different properties & capabilities
compared to the books.
Class (2)
Solution
Class (3)
o In OOP, a cookie cutter is something we called a Class
o Class is a blueprint for objects with similar properties & capabilities.
o Class can only define what properties & capabilities an object will
have. A class cannot store any values. Only object can store any
values.
o Therefore, we only need to define a single class to describe the
properties & capabilities of similar objects.
o Class also defines a template for making an actual object. A class also
defines the initial values for the objects’ properties.
Class in Java Programming
Language
Java Programming Language:
o History of Java Language
o Java API (Application Programming Interface) provides almost 4000
classes that we can use
o Cross platform is one of the main advantages of Java PL (achieved
using Java Virtual Machine)
o Philosophy : "Write once, run anywhere"
Class in Java Programming
Language (2)
The Philosophy : "Write once, run anywhere":
Class in Java Programming
Language (3)
The Implementation Phase, using Java Programming Language and Java
Virtual Machine:
Class in Java Programming
Language (4)
Let us see a demo example: Simple Calculator
Assume that you’ve done all the steps:
1. Solve the problem / build your algorithm
2. Write the source code: Write the class using
Java PL and store it on a text file (.java)
3. Compile the source code using JDK, we will
get the Java bytecode (.class)
4. We run the bytecode in Java Virtual
Machine (JVM will interpret the bytecode)
Class in Java Programming
Language (5)
BLUE J:
o BlueJ is an IDE (Integrated Development Environement) for Java
Programming Language
o Although it is designed for educational purpose, we can use it to
develop a small-scale software
o We will use more sophisticated IDE like Netbeans, once you already
have an adequate programming skill
o BlueJ is free, but we have to install Java SDK separately (which is also
free)
Class in Java Programming
Language (6)
The structure of a class in Java :
public class ClassName{
}
Class in Java Programming
Language (7)
o ClassName can be changed into any name we want.
o the Java code to complete the creation of a class must be inserted
between the curly brackets ({ and })
o An example in BlueJ . . .
o . . . and an example of syntax error
Class in Java Programming
Language (8)
Identifier:
is a name assigned for classes, methods or variable
o First character must be a letter or underscore, but the rest is free
(including number and dollar sign)
o Spaces or symbols (? / %) cannot be used
o Several words cannot be used because Java use it as reserved words.
Example: new, class, extends, etc
o Exercises . . .
Class in Java Programming
Language (9)
Rules of naming for classes:
o Class name should be a noun(s)
o The first letter and also the first letter of each internal word should
be capitalized
o Avoid acronyms and/or abbreviations that leads to confusion. Bottom
line: when somebody read it, he/she must instantly understand what
the class is.
o Please do not be lazy to put several character !!
o Example: Ball, TabletPC, DoubleBed
Class in Java Programming
Language (10)
It is important to include several information into the source code :
Example in BlueJ . . .
Software Objects
After we define the class, we can create the Software Objects.
Software Object is an instance of the class:
◦ Made from a class template
◦ We can have many objects as an instances of the same class
◦ All of them will have the same properties, but might have different
values
◦ Different instances might have different values for their
attributes/instance variable
◦ The process of creating an object is called instantiating an object
Example in BlueJ . . .
Software Objects (2)
We write a computer program by modeling problem as a set of
collaborating component/object:
◦ Similar to building with Lego, you should determine what the
building blocks are.
◦ Some of the components are pre-defined but some of them should
be designed by yourself.
◦ Later on, you should put them together so they can cooperate
properly
Attributes & Methods
In Object Oriented Programming, we create a class and
◦ implement properties as instance variable a.k.a. Attributes
◦ implement capabilities as methods
Attributes & Methods (2)
o Each software object must communicate with others to accomplish
tasks
o They send messages (or instruction) to one another to invoke others
capabilities or change properties.
o When a human object send a message to a mailbox object (e.g. To
know how many item inside it), we say a human object calls a
method on a mailbox object.
Attributes & Methods (3)
Suppose Joe (the book’s owner) wants to move to the next page from
the current page:
◦ The book has a capability to move to the next page.
◦ Joe has to initiate (told the book to do) that action
◦ To do that, Joe has to know the name of the capability. Example:
moveToNextPage
◦ After receive (and understand) the command, the book will move
to the next page
◦ Alternatively, Joe can also told the book to move multiple pages
forward. Example: moveForward + numberOfPage
Attributes & Methods (4)
From the previous scenario, we know the message’s call requires:
o sender: Joeobject initiating the action
o receiver: The Bookobject whose method is being called
o message name: moveToNextPagename of the method being called
o parameters (optional): number of page extra information needed
by the method to operate
o return value (optional):  receiver can reply an returning some
information to the sender

More Related Content

DOCX
javaopps concepts
PDF
JAVA-PPT'S.pdf
PPTX
Java notes(OOP) jkuat IT esection
PPTX
Java notes jkuat it
PDF
Chapter2 bag2
PPTX
JAVA-PPT'S-complete-chrome.pptx
PPTX
JAVA-PPT'S.pptx
PPT
Md02 - Getting Started part-2
javaopps concepts
JAVA-PPT'S.pdf
Java notes(OOP) jkuat IT esection
Java notes jkuat it
Chapter2 bag2
JAVA-PPT'S-complete-chrome.pptx
JAVA-PPT'S.pptx
Md02 - Getting Started part-2

Similar to Object Oriented Programming 02b: Classes (20)

PPTX
UNIT I OOP AND JAVA FUNDAMENTALS CONSTRUCTOR
DOCX
Java notes
PPTX
Bab satu
PDF
babsatu-140703233001-phpapp666666601.pdf
PDF
Lecture2.pdf
PPT
Java_presesntation.ppt
PPT
Lecture 2 classes i
PDF
Complete Java Course
PPTX
ICOM4015 CIIC4010 Exam Review #1
PDF
JAVA Object Oriented Programming (OOP)
PPT
Core Java unit no. 1 object and class ppt
PPTX
Unit3 part1-class
PPT
9 cm604.14
PDF
2.oop concept
PPTX
Java Programming - UNIT - 1, Basics OOPS, Differences
PPTX
the Concept of Object-Oriented Programming
PDF
Class 1 blog
PPTX
The smartpath information systems java
UNIT I OOP AND JAVA FUNDAMENTALS CONSTRUCTOR
Java notes
Bab satu
babsatu-140703233001-phpapp666666601.pdf
Lecture2.pdf
Java_presesntation.ppt
Lecture 2 classes i
Complete Java Course
ICOM4015 CIIC4010 Exam Review #1
JAVA Object Oriented Programming (OOP)
Core Java unit no. 1 object and class ppt
Unit3 part1-class
9 cm604.14
2.oop concept
Java Programming - UNIT - 1, Basics OOPS, Differences
the Concept of Object-Oriented Programming
Class 1 blog
The smartpath information systems java
Ad

Recently uploaded (20)

PDF
Chapter 5_Foreign Exchange Market in .pdf
PPTX
Principles of Marketing, Industrial, Consumers,
DOCX
unit 1 COST ACCOUNTING AND COST SHEET
PDF
WRN_Investor_Presentation_August 2025.pdf
DOCX
unit 2 cost accounting- Tender and Quotation & Reconciliation Statement
PDF
BsN 7th Sem Course GridNNNNNNNN CCN.pdf
PDF
Reconciliation AND MEMORANDUM RECONCILATION
PPTX
Dragon_Fruit_Cultivation_in Nepal ppt.pptx
PPT
Chapter four Project-Preparation material
PPT
Data mining for business intelligence ch04 sharda
PDF
Training And Development of Employee .pdf
PDF
kom-180-proposal-for-a-directive-amending-directive-2014-45-eu-and-directive-...
PDF
COST SHEET- Tender and Quotation unit 2.pdf
PPTX
5 Stages of group development guide.pptx
PDF
Elevate Cleaning Efficiency Using Tallfly Hair Remover Roller Factory Expertise
PDF
Types of control:Qualitative vs Quantitative
PDF
Unit 1 Cost Accounting - Cost sheet
DOCX
Euro SEO Services 1st 3 General Updates.docx
PPTX
The Marketing Journey - Tracey Phillips - Marketing Matters 7-2025.pptx
PDF
Power and position in leadershipDOC-20250808-WA0011..pdf
Chapter 5_Foreign Exchange Market in .pdf
Principles of Marketing, Industrial, Consumers,
unit 1 COST ACCOUNTING AND COST SHEET
WRN_Investor_Presentation_August 2025.pdf
unit 2 cost accounting- Tender and Quotation & Reconciliation Statement
BsN 7th Sem Course GridNNNNNNNN CCN.pdf
Reconciliation AND MEMORANDUM RECONCILATION
Dragon_Fruit_Cultivation_in Nepal ppt.pptx
Chapter four Project-Preparation material
Data mining for business intelligence ch04 sharda
Training And Development of Employee .pdf
kom-180-proposal-for-a-directive-amending-directive-2014-45-eu-and-directive-...
COST SHEET- Tender and Quotation unit 2.pdf
5 Stages of group development guide.pptx
Elevate Cleaning Efficiency Using Tallfly Hair Remover Roller Factory Expertise
Types of control:Qualitative vs Quantitative
Unit 1 Cost Accounting - Cost sheet
Euro SEO Services 1st 3 General Updates.docx
The Marketing Journey - Tracey Phillips - Marketing Matters 7-2025.pptx
Power and position in leadershipDOC-20250808-WA0011..pdf
Ad

Object Oriented Programming 02b: Classes

  • 1. Object Oriented Programming 02b: Classes Informatics Department –Parahyangan Catholic University Taken and adapted from Lionov’s Lecture Slide AUGUST, 24, 2017
  • 2. Class o It’s time to code the object into a something that will be understood by a computer (a software object) o But, there is a problem: We may not want to describe each individual object because there might be too many objects. o Idea : Several objects may have many commonalities. Why don’t we describe what is common just once?
  • 3. Class o We can group the objects that we have identified based on their properties & capabilities. o Example: all books have the same properties & capabilities although they may have different values for their properties. A book shelf have different properties & capabilities compared to the books.
  • 5. Class (3) o In OOP, a cookie cutter is something we called a Class o Class is a blueprint for objects with similar properties & capabilities. o Class can only define what properties & capabilities an object will have. A class cannot store any values. Only object can store any values. o Therefore, we only need to define a single class to describe the properties & capabilities of similar objects. o Class also defines a template for making an actual object. A class also defines the initial values for the objects’ properties.
  • 6. Class in Java Programming Language Java Programming Language: o History of Java Language o Java API (Application Programming Interface) provides almost 4000 classes that we can use o Cross platform is one of the main advantages of Java PL (achieved using Java Virtual Machine) o Philosophy : "Write once, run anywhere"
  • 7. Class in Java Programming Language (2) The Philosophy : "Write once, run anywhere":
  • 8. Class in Java Programming Language (3) The Implementation Phase, using Java Programming Language and Java Virtual Machine:
  • 9. Class in Java Programming Language (4) Let us see a demo example: Simple Calculator Assume that you’ve done all the steps: 1. Solve the problem / build your algorithm 2. Write the source code: Write the class using Java PL and store it on a text file (.java) 3. Compile the source code using JDK, we will get the Java bytecode (.class) 4. We run the bytecode in Java Virtual Machine (JVM will interpret the bytecode)
  • 10. Class in Java Programming Language (5) BLUE J: o BlueJ is an IDE (Integrated Development Environement) for Java Programming Language o Although it is designed for educational purpose, we can use it to develop a small-scale software o We will use more sophisticated IDE like Netbeans, once you already have an adequate programming skill o BlueJ is free, but we have to install Java SDK separately (which is also free)
  • 11. Class in Java Programming Language (6) The structure of a class in Java : public class ClassName{ }
  • 12. Class in Java Programming Language (7) o ClassName can be changed into any name we want. o the Java code to complete the creation of a class must be inserted between the curly brackets ({ and }) o An example in BlueJ . . . o . . . and an example of syntax error
  • 13. Class in Java Programming Language (8) Identifier: is a name assigned for classes, methods or variable o First character must be a letter or underscore, but the rest is free (including number and dollar sign) o Spaces or symbols (? / %) cannot be used o Several words cannot be used because Java use it as reserved words. Example: new, class, extends, etc o Exercises . . .
  • 14. Class in Java Programming Language (9) Rules of naming for classes: o Class name should be a noun(s) o The first letter and also the first letter of each internal word should be capitalized o Avoid acronyms and/or abbreviations that leads to confusion. Bottom line: when somebody read it, he/she must instantly understand what the class is. o Please do not be lazy to put several character !! o Example: Ball, TabletPC, DoubleBed
  • 15. Class in Java Programming Language (10) It is important to include several information into the source code : Example in BlueJ . . .
  • 16. Software Objects After we define the class, we can create the Software Objects. Software Object is an instance of the class: ◦ Made from a class template ◦ We can have many objects as an instances of the same class ◦ All of them will have the same properties, but might have different values ◦ Different instances might have different values for their attributes/instance variable ◦ The process of creating an object is called instantiating an object Example in BlueJ . . .
  • 17. Software Objects (2) We write a computer program by modeling problem as a set of collaborating component/object: ◦ Similar to building with Lego, you should determine what the building blocks are. ◦ Some of the components are pre-defined but some of them should be designed by yourself. ◦ Later on, you should put them together so they can cooperate properly
  • 18. Attributes & Methods In Object Oriented Programming, we create a class and ◦ implement properties as instance variable a.k.a. Attributes ◦ implement capabilities as methods
  • 19. Attributes & Methods (2) o Each software object must communicate with others to accomplish tasks o They send messages (or instruction) to one another to invoke others capabilities or change properties. o When a human object send a message to a mailbox object (e.g. To know how many item inside it), we say a human object calls a method on a mailbox object.
  • 20. Attributes & Methods (3) Suppose Joe (the book’s owner) wants to move to the next page from the current page: ◦ The book has a capability to move to the next page. ◦ Joe has to initiate (told the book to do) that action ◦ To do that, Joe has to know the name of the capability. Example: moveToNextPage ◦ After receive (and understand) the command, the book will move to the next page ◦ Alternatively, Joe can also told the book to move multiple pages forward. Example: moveForward + numberOfPage
  • 21. Attributes & Methods (4) From the previous scenario, we know the message’s call requires: o sender: Joeobject initiating the action o receiver: The Bookobject whose method is being called o message name: moveToNextPagename of the method being called o parameters (optional): number of page extra information needed by the method to operate o return value (optional):  receiver can reply an returning some information to the sender