JAVA exam 6.1
When working with an object, you are typically using two things.
The object itself, which must be created in memory. A reference variable that refers to [points to]1 the object.
reference variable
The object that is created in memory holds data of some sort and performs operations of some sort. §In order to work with the object in code, you need some way to refer to the object [and its code] That's where the reference variable comes in.[It]3 doesn't hold an actual piece of data ..., [but]4 instead holds the object's memory address [to where its code can be accessed]5.
sharing code
Those objects are then used to call the other Java programs' methods. This results in one Java program sharing code with another Java program.
Wine bestWine = new Wine(); The ________ object is in memory and referenced by ___________.
Wine; bestWine
A variable of reference type stores the _____ of an object.
address
System.in is
an argument sent to the Scanner() constructor that allows for keyboard entries.
When the object is instantiated, what happens?
an instance (copy) of the class is loaded into memory.That instance is referred to by a reference variable.
For a Java program to use the code in another Java program
an object of the 2nd program has to be created.
Relationships between classes are called _______.
associations
Size, shape, and color are examples of a car's _______.
attributes
The fields of a Java program are the
attributes.
A ball rolls, bounces, inflates and deflates. These are examples of a ball's _______.
behaviors
Primitive variables
, such as ints, doubles, and so forth, are simply storage locations in the computer's memory. It has no built-in capabilities other than storing a value. The compiler sets aside, or allocates, a chunk of memory that is big enough for that variable. The memory is the actual location that will hold any variable [of the given type]1.
22 System.out.println();
//Outputs a blank line.
Basketball myBall = new Basketball(); Basketball yourBall = new Basketball(); 1.How many objects are there? 2.What is each object? 3.What are the variables (reference variables)? 4.What is in each variable? 5.Does each object have the same features and functions?
1.2 2.Basketball 3.myBall, yourBall 4.the memory address of each Basketball object 5.Yes
Programmers use existing classes as the _________ _________for constructing ________ classes.
1.building blocks; new
Objects from a ________ class are used to ________ a server class's ________.
1.client; call; methods
Each class contains fields and the set of methods that manipulate the fields and provide services to _______.
1.clients
Code reuse occurs when one Java program _________ an _________ of another Java program.
1.creates; object
An object is a copy or _______ of a class.
1.instance
Outside code can manipulate a class' fields and _______ through an object of the class. This indirect access is known as a programming _______.
1.methods 2. interface
Objects allow one Java class to ________ _______ with another Java class.
1.share code
parent or superclass.
A Java class can inherit code from its parent or superclass.
The Relationship Between Classes and Objects
A class allows other programs to use its code through objects. To do this an object of a class is created in the client program. the object is given a name called a reference variable. the reference variable points to an instance of the class now in memory.the object is used to call the class's methods (code). A relationship or association is established between the client class and the server class. There is, therefore, a web of relationships extended across additional server classes, that themselves are client classes and their objects, in a powerful and dynamic chain of code sharing and reuse.
where do objects come from?
classes
An object of a class is created in the _________ class.
client
The power of object-orientation is ________ ________.
code reuse
The power of object-orientation is
code reuse through methods. Code once, use over and over. Code reuse happens when Java programs create objects of other Java programs.
class
code that describes a particular type of object. It specifies the data that an object can hold (the object's fields), and the actions that an object can perform (the object's methods). "blueprint" to create a particular type of object When a program is running, it can use the class to create, in memory, as many objects of a specific type as needed.
Object instantiation
creates a client and server relationship between classes.
Use private when
declaring objects at the class level.
Object instantiation is a powerful and dynamic chain of code sharing and reuse that has a ____________ _________.
domino effect
object
exists in memory, and performs a specific task.
There is no reason for a Java class to know
how another Java class's code functions.
A Java class has a relationship or is associated with another Java class through
inheritance or through objects.
The reference variable and the object are used
interchangeably to mean the same thing when in reality one points/refers to the other.
In object-oriented design, objects may know how to communicate with one another across well-defined _______, but normally they are not allowed to know how other objects are implemented. This is known as information _______.
interfaces; hiding
The client class
is the one that instantiates the object which, in turn, is used to call the methods from the server class.
The name input is known as a reference variable because
it refers (points) to the Scanner class in memory.
OOP endeavors to
model task-oriented components through methods, that when combined with other methods operate as a whole to form a purposeful program, such as an accounting package, a word-processor, a human resource package, and so forth.
All _____ types are reference types.
nonprimitive
A(n) _______ of a class is used to call the class's methods, or its _______.
object; code
Instantiating a class means the same thing as creating a(n) (new class/object) or creating a(n) (instance/member) of the class.
object; instance
Classes are to _______ as blueprints are to houses.
objects
In object-oriented design, software components that model real world items are called _______.
objects
Object-oriented design encapsulates attributes and operations (behaviors) into
objects. Attributes = Fields Operations = Methods
When a client class creates an object of a server class a _________________ is established between them.
relationship
Packaging software as classes facilitates _______.
reuse
A class for which an object is created is the _________ class.
server
When a program needs the services of a particular type of object, it creates
that object in memory, and then calls that object's methods as necessary.
An object of a class is needed...
to use its code.
relationship between object and reference variable
used interchangeably
In calling the methods, you need to know whether they are
value-receiving and/or value-returning so you can code properly the method call.
Associations
—relationships between classes
The focus of OOL.
◦The focus is on creating classes. §Each contains fields and the set of methods that manipulate the fields and provide services to clients (i.e., other classes that use the class). §Programmers use existing classes as the building blocks for constructing new classes. §Classes are to objects as blueprints are to houses.
instance
Each object that is created from a class is called an instance of the class.
instantiation of an object called myHouse of type House. (and explain)
House myHouse = new House(); myHouse is actually the reference to the House program that is now in memory. The House program that is now in memory is the actual object. To reference the House object, myHouse has the memory address of the object's location in memory.
what has a lot of classes?
JAVA API examples: scanner PrintWriter
Object-oriented design models communication
Object-oriented design models communication between objects (via messages). These messages are method calls.1
Object-oriented design (OOD)
Object-oriented design models software in terms similar to those that people use to describe real-world objects. Class relationships Inheritance relationships
Object-Oriented Languages (OOL)
Object-oriented programming (OOP) in an OOL allows you to implement an object-oriented design as a working system. Java is object-oriented.
Objects
Objects are reusable software components that model real world items. Humans think in terms of objects, e.g., people, animals, plants, cars, etc. Objects have attributes, e.g., size, shape, color, weight, etc. Objects exhibit behaviors, e.g., a ball rolls, bounces, inflates and deflates; a baby cries
Objects have two general capabilities:
Objects can store data. The pieces of data stored in an object are known as fields. Objects can perform operations. The operations that an object can perform are known as methods.
Information hiding
Objects may know how to communicate with one another across well-defined interfaces, but normally, they are not allowed to know how other objects are implemented.
