This week's book giveaway is in the OO, Patterns, UML and Refactoring forum. We're giving away four copies of Refactoring for Software Design Smells: Managing Technical Debt and have Girish Suryanarayana, Ganesh Samarthyam & Tushar Sharma on-line! See this thread for details.
Q2-5. Which of the following options contain correct code to declare and initialize
variables to store whole numbers?
a bit a = 0;
b integer a2 = 7;
c long a3 = 0x10C;
d short a4 = 0512;
e double a5 = 10;
f byte a7 = -0;
g long a8 = 123456789;
Answer: c, d, f, g
why e is not correct? I tried it on my jdeveloper and it compiled and run well.
The question clearly states a whole number (integer). double is not used to store whole numbers (integers), but for decimal values (floating points). So this question is not only about knowing which code fragments will compile and which don't, but also about picking the correct data type for the job
Exactly! double is a primitive data type that's used to store floating-point (decimal) values, not whole numbers (integers). To store whole numbers (integers) you need to use byte, short, int or long. Of course you can store the literal 10 in a double, but then it's not a whole number anymore, but a decimal value.
Really obvious when you execute the following snippet:
I’ve looked at a lot of different solutions, and in my humble opinion Aspose is the way to go. Here’s the link: http://aspose.com