Download presentation
Presentation is loading. Please wait.
Published byCharleen Wilkins Modified over 9 years ago
2
Introducing Objects and stuff GABY and MATT
3
Definition: Object: “a class that is the root of the hierarchy tree for all classes in JAVA.” –An object is defined by a class or Primitive Data: Includes common values such as numbers and characters. Data Type: Defines a set of values and operations. Operators: A symbol that represents an operation in a programming language, such as the addition operator
4
Continued… Encapsulation: the characteristic of an object that limits access to its variables and methods. All interaction with the object occurs through an interface. Inheritance: The ability to create a new class from an existing one. Inherited variables and methods of the original class are available in the new class if they were declared locally.
5
Section 2.1: Using Objects Kevin Curtis Dennis Truong Period 2
6
The Basics Objects The basic software part in an object- orientated program. Represents output device or file (i.e. monitor)
7
The Basics For example System.out.println (“Whatever you are, be a good one.”); System.out represents the output device or file The object’s name is out and stored in the system class The println method will print a string of characters to the screen. The parameter is the piece of data sent to a method, or in this example, the string of characters printed to the screen.
8
Methods and Objects Receives information from the parameter: System.out.println (“test”); Determines how the object functions for example: print method: prints information and stays on the same line. println method: prints information and then skips to the next line.
9
Methods and Objects main CountdownSystem.out println
10
Abstraction An abstraction means that the details of how it works does not matter to the user. An object is an example of an abstraction. An abstraction hides or ignores certain details. With a good abstraction hiding the right details at the right time to manage the complexity. Level of abstraction: the amount of abstraction that is used to hide the details
11
2.6 Creating Objects
12
Introduction Variable can hold primitive value or reference to object The new operator returns a reference to a newly created object Creating object with new operator is called instantiation ex. String name = new String (“Mr. Jacobson”); An object is called instance of particular class After the new operator creates the object, a constructor is a string literal
13
Dot Operator When object is instantiated, we use the dot operator to get is methods Dot operator is added right after object reference and is followed by method being invoked ex. Count = name.length()
14
The String Class String in Java are object represented by the string class the type shown in front of method name is called return type of the method A return type void means that the method doesn’t return a value Object immutable when value can’t lengthened or short nor can any of its character change Index is a character’s position in string The first character is zero
15
Wrapper Class All primitive type in Java have wrapper class-- let you create objects representing primitive data Integer class represent int and double class represent a double ex. Integer number = new Integer (45); The Integer and Double objects are immutable
16
Chapter 4.0 Writing Classes By Dina Deng April Ochoa
17
Objects Revisited Example of an Object: A ball has: diameter, color and elasticity. The properties that describe an object are called attributes - defined as the object’s state of being. Behaviors: What it does-ex. the ball can be thrown, bounced, or rolled.
18
[[Each object has a state and a set of behaviors. The values of an object’s variables define its state and the methods define its behaviors.]] The action of an object will remain the same, but it depends on the object’s state. The class of an object may contain a method to add a new course. Software objects can often represent physical things, but they don’t have to. For example: an error message can be an object, with its state being the text of the message and behaviors, including printing the error message. There’s no limit for possibilities to just be physical things.
19
Classes An object is defined by a class A class can be described as a model, patter, or blueprint of the object that’s being created. It has no memory space for data. Each object has its own data space, thus its own state. Blueprint - defines the important characteristics. Ex. A house’s : walls, windows, doors, electrical outlets, and so on.
20
Chapter 4.1 Review Anatomy of a Class Darwin Arayata Stephen Le Jibram Martinez
21
Members of the class are classes containing the declarations if the data that will be stored in each instantiated object and the declarations of the methods that can be invoked using an object. Refer to the picture on pg. 193 listing 4.1
22
Instance Data In the coin class, the constants HEADS and TAILS, and the variable face are declared inside the class, but not inside any methods. Location at which variable declared defines its scope The coin object, for example, has its own face variable with its own data space. -Reference to Page 197 listing 4.3
23
Instance Data continued.. Attributes such as the variable face are also called instance data because memory space is created for each instance of the class that is created. Java automatically initializes any variable declared at the class level.
24
Encapsulations and Visibility Modifiers We can think about an object in one of two ways, depending on what we are trying to do. First when we are designing and implementing objects We have to define the variables that will be held in the object and write the methods that make the object useful Objects should be encapsulations lated. The rest of a program should work with an object only through a well defined interface
25
Encapsulations and Visibility modifiers continued…. When we are designing a solution we have to think about the objects in the program work with each other In java we create object encapsulations using Modifiers A modifier is a java reserved word that names special characteristics of a programming language
26
Continued Some Java Modifiers are called visibility modifiers They control whether client code can “see’ what’s “inside” an object
27
Anatomy Of A Method By: Jei Mercado, David Chap, and Kevin Lai
28
Anatomy Of a Method A method declaration defines the code that is executed when the method is invoked. When it is done, control return to the location where the call was made and execution continue. Define the same class Define Programs
29
Return Statement A return value must match the return type in the method header. Return type in the method header can be a primitive type class name Reserved word void Void is used as a return type Return is double
30
Parameter Pass through when invoked List in the header of this method list the type of value that are passed their name Formal parameter Actual value pass into actual parameter
31
Constructor Cannot have any Return type even void Is the same name as the class Each class have a different structure
32
Local Data A variable declared in a method is local to that method and cannot be used outside of it Instruct data
33
Lesson 4.3 Method Overloading
34
Uses Performing similar operations on different types of data. Using the same method name with different parameter lists for several different methods.
35
What is needed The compiler still needs to match up each invocation with a specific method declaration. It needs a “signature”, which is the methods name, number, type, and order of its parameters.
36
What happens First, the value in the variable is converted to a string representation. Next, the two strings are concatenated into one longer string. Last, the definition of println that accepts a single string is called.
37
Public class SnakeEyes { public static void main (String[] args) { final int ROLLS = 500; int snakeEyes = 0, num1, num2; Die die1 = new Die(); Die die2 = new Die(20); for (int roll = 1; roll <= ROLLS; roll++) { num1 = die1.roll(); num2 = die2.roll(); if (num1 == 1 && num2 == 1) snakeEyes++; } System.out.println (“Number of rolls: “ + ROLLS); System.out.println (“Number of snake eyes: “ + snakeEyes); System.out.println (“Ratio: “ + (double)snakeEyes/ROLLS); }
38
Output Number or rolls: 500 Number of snake eyes: 6 Ratio: 0.012
39
Chapter 4 - Section 4our Method Decomposition By Miguel, Marvin, and Eric
40
What is method decomposition???? -a complicated method can be broken into several simpler methods and helped by support methods. -in an object-oriented design, breaking up methods must happen after objects have been broken.
41
For example… -beginsWithVowel, beginsWithBlend, startsWith are simpler methods that help the translate method do its job. -PigLatinTranslator.java (pg. 216-218) -the translate method is broken up into simpler methods and uses several support methods. -translateWord is a support method.
42
THE END Or is it…?
43
Object Relationship By Dustin and Greg
44
Association Use Relationship- when two classes are aware of each other and may use each other. –Ex. An artist object draws a picture object
45
Association of objects of the same class A method invoked through one object may take as a parameter another object of the same class Woman object taking parameters from Man object
46
Aggregation An aggregate object is made up, in part, of other objects, forming a has-a relationship has a –Ex. A car has a tire
47
Great Job! I will send a copy to each computer This is a good summary of some of the object oriented programming ideas
Similar presentations
© 2025 SlidePlayer.com. Inc.
All rights reserved.