General Java Questions II
Narrowing conversions almost always require an explicit cast.
char to double is one of the widening primitive conversions, so the compiler
automatically treated it as though you had written "if ( r >(double)s)"
by Patricia Shanahan
Answer2: Yes, char is indeed a 16 bit value. However, the actual answer is in the
Java
Language Specification, section 5.6.2, which is at the following URL:
http://java.sun.com/docs/books/jls/second_edition/html/conversions.doc.html#170983
In summary, the char is automagically promoted to a double. No explicit cast is
necessary since the language rules say that it gets "promoted" to a double
by John O Conner
Is there any performance or other benefit from importing only the classes you
need in a file using something like...
Is there any performance or other benefit from importing only the classes you need in
a file using something like:
import java.util.HashMap;
instead of using ,
import java.util.*;
to import all the classes in a package.
Answer: Strictly speaking, "import java.util.*;" does not import the whole of java.util. It
is an "import on demand" which imports any class or interface in java.util that is
needed. If the first import statement would have done the job, then HashMap is the
only class the second one would import.
No measurable differences in compile time performance. You can do the test, but I
suspect you would get identical byte code, so no difference in run time performance.
There is a practical difference when two packages contain classes with the same
name. Suppose you also imported java.awt.* and tried to declare a List. It would be
ambiguous. If you use the second form you would either import java.util.List or
java.awt.List.
There is also a documentation difference. The first one makes it clear exactly what
imported classes are being used.
by Patricia Shanahan
Q: == and equals ()... These two still make me confuse a lot of time.
Can somebody give me some thumb rule or explain it to me?
Answer: When you use == with a primitive int, double, char, ... you are checking that
the values are identical. But if you use == with an object, you are checking that the 2
objects are stored at the same address. In other words the references pointing to the
same object...
Method equals () is different.
file:///F|/a_jsite/350_tips/general_java II.htm (8 of 14) [2001 07 08 11:24:53]
footer
Visionwebhosting.net Business web hosting division of Web
Design Plus. All rights reserved