Exercise 1 : Using the ObjectTool to Create and Manipulate Objects
Objetives
The objective of this exercise is to become familiar with the
ObjectTool and to create instances of a class and manipulate these
instances in several ways. The ObjectTool is an educational tool for
simulating objects in memory. The ObjectTool allows you to type in
individual lines of the Java programming language syntax and to observe
the outcome without having to go through the compilation and
interpretation of a full Java technology environment.
Task - Instantiating Objects with the Object Tool
In this task, you launch the ObjectTool and create a Shirt object:
1.- At a command line, launch the ObjectTool and by typing the following:
java -cp ot021502c.jar OT
Two ObjectTool windows appear. The first window is called the ObjectTool interpreter. You type lines of code in this window.
The second window is called the Display Controller Window. Objects that you create appear in this window.
2.- In the Code Entry field within the ObjectTool interpreter, type the following:
int myVariable; <return>
After you press Return, the line of syntax appears in the Code Entry
History panel. The Code Entry History panel displays all of the syntax
lines you have typed along with any error messages.
If you made a mistake, you might also receive am error in the Code Entry History panel. Try typing the syntax in again.
Also, after you press return, an int variable called myVariable is
declared and placed in the Local Variables table. This table simulates
all of the variables you have created that would typically appear in
stack memory
3.- In the Code Entry Field, type the following:
myVariable = 10; <return>
After you press Return, the value of 10 is assigned to the myVariable variable.
4.- Click the Show Binary Value Using Int menu item in the View menu to display the value of myVariable as a binary integer.
Because integers occupy 32 bits in memory, you will see 32 bits representing the value 10 in binary.
5.- Click the Show Binary Value Using Int menu item again to turn the myVariable value back to an integer value.
6.- In the Display Controller Window, click the OTShirt0 pre-created object from the Show Precreated Objects menu.
The Display Controller Window simulates how and object might appear in
heap memory and how that object is an instance of a class.