Would

final String charData = 3.14159265;

work?

A good answer might be:

No. charData is an object of type String and 3.14159265 (without the quotes around it) is a literal of primitive type double. These data types use bit patterns in completely different ways. A simple statement assigning one type to the other won't work.


How the Program Works

In the program, the characters "3.14159265" are contained inside the String charData.

final String charData = "3.14159265";
double value;

Now look at the statement that converts the characters to a double data type and puts the results in value:

value  = Double.parseDouble( charData  ) ;

The assignment statement works in two steps:

  1. The expression on the right of the equal sign is evaluated.
    • The parseDouble() method from the class Double examines the characters and creates a double value.
  2. That double value is copied to the variable value.

Usually this is called converting from character data to double precision floating point data. However, the character data is not changed. A floating point value is calculated from it and that value is copied to another location.

QUESTION 3:

Would the program work if the declaration of charData were changed to:

final String charData = "0.314159265E+1";