Explicit Floating Point Literals

Classic programmed-learning exercises, refreshed for modern Java and presented in the current MrStyner.com portfolio style.

Modern Java noteThis archive has been refreshed for Java 25 LTS. Core language concepts remain useful, while outdated setup instructions and browser-era Java are labeled or replaced. Java 26 is the current feature release; Java 25 is used here as the stable teaching baseline.
go to previous page   go to home page   hear noise   go to next page

(Thought question: ) Do you think that using float instead of double saves a significant amount of computer memory?

Answer:

No. For most programs using variables of type double will cost only a few extra bytes in a program thousands of bytes long.

Explicit Floating Point Literals

Sometimes you need to explicily ask for a single-precision float literal. Do this by putting a lower case 'f' or upper case 'F' at the end, like this:

123.0f        -123.5F         -198234.234f       0.00000381F

Sometimes you need to explicily ask for a double-precision double literal. Do this by putting a lower case 'd' or upper case 'D' at the end, like this:

123.0d        -123.5D         -198234.234d       0.00000381D

Remember, that without any letter at the end, a floating point literal will automatically be of type double.

QUESTION 9:

Do you think that the following is legal?

double rats = 8912D ;