page4
calculated (based on number of bits)?
A short is a two-byte signed integer value which means that the first bit defines
the sign and the following 15 bits define the value. This means that the maximum
value would be represented by the following equation:
8/30/2023
4
c)
What are the contents of the Stack memory? What are the contents of the Heap
memory?
The stack memory contains the function calls for main(), method2(), and method3()
along with locally declared primitives such as sh and n2 and pointers to variables in
the heap. The heap memory contains the objects a3 and args (passed to main).
d)
(i) Can you write an equation showing how the required value of ‘sh’ can be
(ii) show how ‘n2’ can be calculated?
(iii) Explain how the 2 values printed out in method3 were obtained.
In hex, A→C is equivalent to 10→12. When represented as the hexidecimal “ABC”:
ABC = 10(16
2
) + 11(16
1
) + 12(16
0
) = 2748
Those values are the ASCII representation of the char values ‘a’ and ‘z’, the first
letter a is 97, and 25 letters later is 122 which is ‘z’