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.
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 ]
P.S. Irene, you can edit your posts if you'd like. Take a look at the various icons above each post. The one that looks like a piece of paper with the pencil pointing at it is the "Edit/Delete Post" icon. Thanks for all the nice posts. Hope to see you 'round the Ranch!
Joined: Apr 15, 2002
Thank you, Dirk. I learned something today! I was wondering how to do the edits but never actually had time to look around.