Guest User

Untitled

a guest
May 21st, 2018
159
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 2.37 KB | None | 0 0
  1. 02.04 Primitive Data Types: doubles
  2.  
  3. Imagine that you have to give a poster presentation in computer class about two types of numbers: integers and decimals. (Hang in there, this gets better.) You happen to be at the local Math store and notice that they sell the numbers you need. The numbers are stored in individually labeled plastic drawers in two different cabinets (like the ones in a carpenter's shop filled with nails of different sizes). One cabinet contains only integers and the drawers are shorter. The other cabinet contains decimal numbers and the drawers are longer.
  4.  
  5. You only need two types of numbers for your poster: integers and decimals. You decide to use your three favorite integers: -3, 52, and 365. You pull open the drawer in the narrower cabinet labeled neg_three, take out a small card with a -3 on it, and close the drawer. You follow the same procedure to retrieve 52, and 365 from their drawers in the narrow cabinet. Then you turn to the wider cabinet that contains decimal numbers. One drawer is labeled pi, and as you open it you notice how much longer it is than the drawer that contained integers. You take a card from the drawer with the number 3.14159 printed on it and realize the drawer had to be longer because decimal numbers are more precise than integers. Next you choose a long drawer labeled phi (which you remember is the golden ratio) and one labeled abs_zero, retrieving cards printed with 1.6180339887 and -273.15, respectively.
  6.  
  7. Unfortunately you don't have enough money for all six numbers, so you decide to put phi back. Distracted by your cell phone ringing, you try to put phi back in a smaller drawer, but it won't fit. Obviously, you can't put a decimal number back in an integer drawer, there is not enough space in the shorter drawer to hold it. Then, having knocked off your glasses, you misread the labels and put phi in the pi drawer, where it fits fine because they are both numbers of the same type (i.e., decimal). In a hurry now to get home and start your poster project, you mistakenly put 52 in the drawer labeled abs_zero, and even though it is an integer, it fits snugly in the longer drawer. As you drive home you are rather proud that you promoted your favorite integer to the decimal storage compartment.
  8.  
  9. Believe it or not, this analogy will help you understand the different memory storage requirements of two of Java's primitive data types.
Add Comment
Please, Sign In to add comment