UOB - Using Objects Overview
Using Objects
Introduction
You sit down to do your math homework and realize you need a sheet of paper. What do you do? Go to the back yard, chop down a tree, grind it into pulp and make your own paper? NO! You probably have a pack of paper or a notebook in your bag right now. Somebody else has already mastered the creation of paper and all you must do is use it. Concepts in computer science work the same way. Some objects or concepts are so frequently used that programmers can draw upon existing code that has already been written and tested. This makes writing solutions move along more quickly and with more confidence. It’s like using a calculator on that math homework. You could go ahead and do a lot of work by hand, but using that calculator will not only save you time it will also help you eliminate errors. If you could use code that has already been tested, then you know it works and can focus your attention on other aspects of your program.
Module Lessons Preview
In this module, we will study the following topics:
Objects: Instances of Class: Now that you have learned about variables, how to write basic programs, and how to calculate simple mathematical problems, in this module you will gain an understanding of what an object is in Java and how it is used for programming.
Creating and Storing Objects (Instantiation): Like primitive data, variables are used to reference objects. Unlike primitive data, objects are created using constructors from the class. Creating an object is called instantiation or creating an instance of a class.
Calling a Method: Methods represent what an object can do or can have done to it. They are the actions. Methods contain code that complete certain tasks. Here we will look at method signatures and how to write code in order to invoke methods on objects.
String Objects: The String class is a very special class. It acts like primitive data, but it is so much more. Strings are objects but are unique in that they can be created like primitive data or like objects.
String Methods: The String class contains many methods (actions). We will learn the ones that will be tested on the AP Exam and explore other methods that will make our programs more interesting.
Using the Math Class: The Math class allows us to use static methods which do not require an object. The Math class has many methods that can be used for mathematical calculations. We will learn the methods that will be tested on the AP exam and explore other methods that will make our programs more interesting.
Key Terms
class – the blueprint of the attributes and behaviors of an object
concatenation – placing a String after another to form a new String
constructor – a special method which creates an instance of a class
methods – actions/behaviors of an object
null - value of an object that has not yet been initialized
object – a specific instance of a class
object reference – a value that denotes the location of an object in memory
overloaded – methods that have the same name but different parameter list
parameters – an item of information that is specified to a method when the method is called
signature – method declaration or heading
static methods – methods which can be accessed without having to create an object
String – an object which stores characters in double quotations
void – a value is not returned from this method
wrapper classes – classes that convert primitives to objects
IMAGES CREATED BY GAVS