Draw a picture to illustrate the stack and heap


Assignment:

Discuss the following questions regarding stack and heap drawings. How are stack and heap drawings done? How would one go about these questions?

Stack and Heap Drawings:

1. String s;
Fraction f, g;
Point w, x;
JFrame j;
f = new Fraction(25, 35);
g = f;
w = new Point(5, 10);

Draw a picture to illustrate what the stack and heap will look like.

2. String title = "Push Me"
JButton one = new JButton(title);
JButton two;
two = one;

Draw a picture to illustrate what the stack and heap will look like.

3. String y, z;
y = new String("This is easier than I thought!");
z = y.substring(11, 13);

Draw a picture of the stack and heap.

4. Consider the following code:
//Case 1
String word1 = "Easy";
String word2 = word1;
if (word1 == word2)
System.out.println("The words are the same");
else
System.out.println("The words are different");

This code will display "The words are the same" on the screen. However, if the code is written as:

// Case 2

String word1 = new String("Easy");
String word2 = new String("Easy");
if (word1 == word2)
System.out.println("The words are the same");
else
System.out.println("The words are different");

Most surprising however is that if you try the following code:

//Case 3

String word1 = "Easy";
String word2 = "Easy";
if (word1 == word2)
System.out.println("The words are the same");
else
System.out.println("The words are different");

This code will display "The words are the same" on the screen.

Solution Preview :

Prepared by a verified Expert
JAVA Programming: Draw a picture to illustrate the stack and heap
Reference No:- TGS01934143

Now Priced at $25 (50% Discount)

Recommended (91%)

Rated (4.3/5)