2.2 Data Types, Variables, and Constants
In Example 2.2, we used as data the value of PI and the radius, and we calculated the area of the circle. For each of these values, we assigned a name. We also used the Java keyword double, which defines the data type of the data. The keyword double means that the value will be a floating-point number.
Java allows us to refer to the data in a program by defining variables, which are named locations in memory where we can store values. A variable can store one data value at a time, but that value might change as the program executes, and it might change from one execution of the program to the next. The real advantage of using variables is that we can name a variable, assign it a value, and subsequently ...
Get Java Illuminated, 5th Edition now with the O’Reilly learning platform.
O’Reilly members experience books, live events, courses curated by job role, and more from O’Reilly and nearly 200 top publishers.