gk said:
i have 2 questions..
Q1:Why do you create interfaces, and when MUST you use one?
This one question alone is actually composed of two sub-questions. The
answer to the first sub-question is long and abstract. Read
http://java.sun.com/docs/books/tutorial/java/concepts/interface.html
For the second sub-question, it's never the case that you *MUST* use an
interface, in the Turing Complete sense; that is, for any Java program which
uses interfaces, it should always be possible to write a different program
which doesn't use interfaces, but which is indistinguishable from the first
according to the end-user.
That said, interfaces are useful in that you can implement multiple
interfaces, but only extend one class.
This next question is actually 5 questions combined together.
Q2: can a double value be casted into byte ?
Yes.
how ?
double foo = 1.0;
byte bar = (byte) foo;
wont there be loss
of precison ?
Most of the time, yes.
On most (all?) implementations, probably yes. However, IMHO it's better
to think of the range of values than the actual bit-width. Double ranges
between negative Double.MAX_VALUE and positive Double.MAX_VALUE.
Double.MAX_VALUE is 1.7976931348623157e+308. The actual bit-width isn't that
important. The JVM for a 128 bit processor might allocate 16 bytes for
double, for example, and just ignore the top 8 bytes.
That's not it. See above.
- Oliver