File tree Expand file tree Collapse file tree
Expand file tree Collapse file tree Original file line number Diff line number Diff line change @@ -87,7 +87,7 @@ These are numbers with a radix of 10 which we use most commonly. They do not nee
8787as below:
8888
8989{% highlight java %}
90- int length = 343;
90+ int length = 343; // 343 is the literal
9191{% endhighlight %}
9292
9393** Binary Literals**
@@ -143,16 +143,41 @@ long so = 0xFFFFl; // Note the lowercase 'l'
143143
144144#### Floating-point Literals
145145
146+ Floating-point numbers are defined as a number, a decimal symbol, and more numbers representing the fraction. For
147+ example,
146148
149+ {% highlight java %}
150+ double d = 11301874.9881024;
151+ {% endhighlight %}
147152
153+ By default, floating-point literals are defined as ` double ` (64 bits) so if you want to assign a floating-point literal
154+ to a variable of type ` float ` (32 bits), you must attach the suffix ` F ` or ` f ` to the number. So, the below code
155+ generates a compiler error:
148156
157+ {% highlight java %}
158+ float f = 23.467890; // Compiler error, possible loss
159+ // of precision
160+ {% endhighlight %}
149161
162+ This happens because we're trying to fit a larger number (64 bits) into a (potentially) less precise "container"
163+ (32 bits).
150164
165+ Now as by default floating-point literals are of type ` double ` , it is optional to attach a suffix of ` D ` or ` d ` when you
166+ want to assign it to a variable of type ` double ` . For example,
167+
168+ {% highlight java %}
169+ double d = 110599.995011D; // Optional, not required
170+ double g = 987.897; // No 'D' suffix, but OK because the
171+ // literal is a double by default
172+ {% endhighlight %}
151173
174+ #### Boolean Literals
152175
153176
154177
178+ #### Character Literals
155179
156180
157181
182+ #### String Literals
158183
You can’t perform that action at this time.
0 commit comments