Chapter2 bag2

384 views

Published on

0 Comments
0 Likes
Statistics
Notes
  • Be the first to comment

  • Be the first to like this

No Downloads
Views
Total views
384
On SlideShare
0
From Embeds
0
Number of Embeds
62
Actions
Shares
0
Downloads
2
Comments
0
Likes
0
Embeds 0
No embeds

No notes for slide

Chapter2 bag2

  1. 1. 2.1 Introduction to Object- Oriented Programming
  2. 2. 2.1.1 Procedural versus OOP languages • Procedural programming involves creating a sequence of instructions • OOP uses a collection of interacting objects • Functions are logically grouped, making enhancements easy • OOP can model human problem- solving
  3. 3. 2.1.2 Basic Java terminology Object. contains data and instructions Class. blueprint for an object Attribute. describe the state of objects Data Type. describes what kind of information a certain attribute is Behavior. describe what objects can do Method. a set of instructions Inheritance. Some objects derive attributes and behaviors from other objects Encapsulation. Combining data and methods together
  4. 4. 2.2 What are Objects? 2.2.1 Introduction to objects • Anything tangible or abstract that is relevent • Objects can have attributes and behaviors • Attributes describe the object • Behaviors describe what the object can do
  5. 5. 2.2.2 Classification of objects • User Interface objects – Objects that the user interacts directly with • Operating environment objects – Provide services to other components • Task Related objects – Documents, multimedia, problem domain
  6. 6. 2.2.3 Objects - identifying, defining, creating and operating on • Identifying – Requires needs assessment • Defining – Classification, relationships, operations. The class keyword • Creating – The constructor and the new keyword • Operating – Using an object’s methods
  7. 7. 2.2.7 Encapsulation • To hide the details, package together • Access modifiers – public, private and protected
  8. 8. 2.2.8 Object relationships • Association – Objects know about each other • Whole-part – Existance of an object relies on another • Inheritance – Attributes & behaviors can be inherited
  9. 9. 2.2.9 Inheritance
  10. 10. 2.2.10 Object mutability and destruction • Some object attributes should be immutable, or unchangable • To make an item immutable, use the final keyword • The JVM automatically releases memory when objects are no longer required • The garbage collector will reclaim memory by objects that are no longer referenced • Garage collection is not controllable
  11. 11. 2.3.1 Modeling languages and symbols • Unified Modeling Language (UML) standardizes symbols & terminology for diagramming objects
  12. 12. 2.3.2 Basic Class symbol • Rectangle represents a class of objects • 3 compartments: Name, attributes , and operations or methods • Symbols indicate accessibility
  13. 13. 2.4.1 Class definition •Defined by using public class Person { private String name; the class keyword public Person(String theName) { •Public classes name = theName; defined in separate } } files •Filename must be the same as the class name
  14. 14. 2.4.2 Creating objects • Constructor methods are called when an object is created • All object data is stored in memory • Variables are a reference to the memory location
  15. 15. 2.4.3 Object methods • Mutator – Changes object data • Accessor – Retrieves object data • Methods with no arguments • Methods that require arguments • Method return values – Provide a result to the caller
  16. 16. 2.5.1 System class • Data stored by an object is member data • Data present in an object’s methods is called local or temporary data • Java.lang.System is a pre-defined object that can be used to perform system tasks System.out.println(“Hello World!”);

×