February 2014
Beginner
1248 pages
62h 25m
English
Method testPushDouble (lines 25–36) invokes method push (line 34) to place the double values 1.1, 2.2, 3.3, 4.4 and 5.5 from array doubleElements onto doubleStack. Autoboxing occurs in line 34 when the program tries to push a primitive double value onto the doubleStack, which stores only references to Double objects.
Method testPopDouble (lines 39–59) invokes Stack method pop (line 50) in an infinite loop (lines 48–52) to remove all the values from the stack. The output shows that the values indeed pop off in last-in, first-out order (the defining characteristic of stacks). When the loop attempts to pop a sixth value, the doubleStack is empty, so pop throws an EmptyStackException, which causes the program ...
Read now
Unlock full access