posted 21 years ago
Reading parts of the JLS (as Irene has suggested) from time to time is strongly recommended. That's where the rules of the the Java language are found.
Mike, the short answer to your query is, floating point literals in Java (numbers like 1.2 , 0.1 , 0.0001 , etc.) are by default of type double. If you don't want that much precision and want to use the data type float instead, then you must explicitly tell the compiler of your desired use. Otherwise, it's going to error at compile time, essentially asking you if you are certain that you will accept the possible loss of precision if you try to assign a floating point literal to an identifier of type float.
Integer literals are by default of type int. Sometimes, when you want an integer literal to actually be used as a byte or a char or a short or a long, then you must explicitly tell the compiler of your wishes.
Note that you don't have to explicitly tell the compiler to use a floating point literal as a double or an integral literal as an int because these are the default data types.
Making any sense?
[ June 05, 2002: Message edited by: Dirk Schreckmann ]