General Java Questions I
concurrently, and at least one of the threads modifies the map structurally, it must be
synchronized externally.
Most people asked why there is an error, but my question is why this is NOT an
error
Please take a look:
r is a number and s is a character, why can I put them together to make a comparison
without compilation error? Could somebody tell me... thank you
double r = 34.5;
char s =  c ;
if (r > s) {
   System.out.println("r > s");
} else {
   System.out.println("r < s");
}
Answer1: char is considered to be an arithmetic type, acting as a 16 bit unsigned
integer.
Conversions among the primitive types are divided into three categories:
identity, widening, and narrowing. The identity conversions are the trivial ones like
char to char. The widening conversions all have the effect of preserving the
approximate magnitude of the result, even if it cannot be represented exactly in the
new type. The narrowing conversions are the remaining conversions that may
destroy the magnitude information.
Identity and widening conversions can be inserted automatically by the compiler.
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.*;
file:///F|/a_jsite/350_tips/general_java I.htm (10 of 33) [2001 07 08 11:24:51]






footer




 

 

 

 

 Home | About Us | Network | Services | Support | FAQ | Control Panel | Order Online | Sitemap | Contact

java web hosting

 

Visionwebhosting.net Business web hosting division of Web Design Plus. All rights reserved