Logout

OOP Objects

Objects

One of the important ideas with object oriented programming is that certain instances of a particular class can be made based on the "model" of that class, or looked at another way, based on a "template" for that class. So an object is a "copy" of a particular class. Different copies can have different values for the various attributes. And at any given time there can be one, several, or many different instances "alive".

Recall that with the principle of encapsulation, each object not only has its own copy of the attributes of the class, but also its own copy of the various methods.

new

new is the operator which is used to reserve new memory for objects. In the process of the instantiation of an object, the constructor is called, and it is this which will help the new operator determine how much memory will need to be located.


Using Object Instances

Objects are used all the time when we take advantage of the classes others (or we) have made. Here are a couple of examples:

 BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
String s = br.readLine();

Here we make a new BufferedReader object, and in the process we make a new InputStreamReader, which is used as the parameter. ReadLine() is a method which can read in a stream of text.

 

DecimalFormat formatter = new DecimalFormat("#00000000000.0 \u20Ab");
System.out.println(formatter.format(23423));

DecimalFormat is a class which specializes in the output of numbers



Other Examples of Using Additional Libraries

A library is any collection of related classes, so with Java, think in terms of packages. So when thinking about the use of additional libraries, think about situations where you import packages or specific classes of packages in the import lines at the top of your programs.

So for the dossier Mastery Aspect in which use additional libraries, either of the ones above examples could count, but note that the more non-standard the usage, the better. And the more full usage the better too. So just using one method of a certain class, as in the two examples above, wouldn't be as good as using several methods of a given class.