Purchase Solution

java stack and heap

Not what you're looking for?

Ask Custom Question

I was given the following questions regarding stack and heap drawings. How are stack and heap drawings done? How would one go about these questions? I am posting the questions as reference, but I am requesting information about how to do these types of questions generally, not to have them done for me.

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.

Purchase this Solution

Solution Summary

The expert examines a stack and heap drawings. How stack and heap drawings are done are given.

Purchase this Solution


Free BrainMass Quizzes
Basic Computer Terms

We use many basic terms like bit, pixel in our usual conversations about computers. Are we aware of what these mean? This little quiz is an attempt towards discovering that.

Excel Introductory Quiz

This quiz tests your knowledge of basics of MS-Excel.

Java loops

This quiz checks your knowledge of for and while loops in Java. For and while loops are essential building blocks for all Java programs. Having a solid understanding of these constructs is critical for success in programming Java.

C++ Operators

This quiz tests a student's knowledge about C++ operators.

Basic Networking Questions

This quiz consists of some basic networking questions.