

















Study with the several resources on Docsity
Earn points by helping other students or get them with a premium plan
This page cannot be seen from the preview
Don't miss anything!


















(^1) docsity.com
(^2) docsity.com
4
The pi data exists and we can access it
even
when no instance
of MyMathStuff is created. We can access the data directly using the nameof the class, as in:double x = 2.0 * MyMathStuff.pi;
docsity.com
5
public class MyMathStuff{ public static double pi = 3.14;public static double timesPI (double x){ return x * pi;} }
docsity.com
7
If a class property is also declaredclass MyMathStuff{ public final static double PI = 3.14;}
final^ it is referred to as a
constant^ since it cannot be altered:
docsity.com
^ An^ identifier
is^ a^ sequence
of^ characters
that^ consist
of
letters,^ digits,
underscores
(_),^ and^ dollar
signs^ ($).
^ An^ identifier
must^ start
with^ a^ letter,
an^ underscore
or^ a^ dollar
sign^ ($).^ It
cannot^ start
with^ a^ digit.
^ An^ identifier
cannot^ be^ a
reserved^ word. ^ An^ identifier
cannot^ be
true,^ false
,^ or
null. An^ identifier
can^ be^ of^
any^ length.
(^8) docsity.com
final^ datatype
CONSTANTNAME
=^ VALUE;
final^ double
PI^ =^ 3.14159; final^ int
SIZE^ =^
3;
(^10) docsity.com
11
Name^
Range^
Storage Size
byte^
(^7) –2(-128) to 2
7 –1 (127)^
8-bit signed
short^
(^15) –2(-32768) to 2
15 –1 (32767)^
16-bit signed
int^
(^31) –2(-2147483648) to 2
31 –1 (2147483647)
32-bit signed
long^
(^63 63) –2to 2–
64-bit signed
(i.e., -9223372036854775808to^ 9223372036854775807) float^
Negative range:
32-bit IEEE 754
-3.4028235E+38 to -1.4E-45Positive range:1.4E-45 to 3.4028235E+ double^
Negative range:
64-bit IEEE 754
-1.7976931348623157E+308 to-4.9E-324Positive range:4.9E-324 to 1.7976931348623157E+
docsity.com
(^13) docsity.com
(^14) docsity.com
16
Operator^ Name
Description
++var^ preincrement
The expression (++var) increments var by 1 and evaluatesto the
new^ value in var^
after^ the increment.
var++^ postincrement
The expression (var++) evaluates to the
original^ value in var and increments var by 1. --var^ predecrement
The expression (--var) decrements var by 1 and evaluatesto the^
new^ value in var^ after
the decrement.
var--^ postdecrement
The expression (var--) evaluates to the
original^ value in var and decrements var by 1.
docsity.com
17
int^ i^ =^ 10; int^ newNum^ =
10 *^ i++ ;^
int^ newNum^ =
10 ^ i Same effect asi^ =^ i^ +^ 1; int^ i^ =^ 10; int^ newNum^ =^10 _^ ( **++i_** );^
i^ =^ i^ +^ 1;int^ newNum^
;= 10 * i Same effect as
docsity.com
Implicit
castingdouble d^ =^ 3;^
(type^ widening) Explicit
castingint i =^ (int)3.0;
(type^ narrowing) int^ i^ =^
(int)3.9;
(Fraction
part^ is
truncated) What is wrong?
int x = 5 / 2.0;
19
byte, short, int, long, float, double
range increases
docsity.com
20
Four hexadecimal digits.
NOTE: The increment and decrement operators can also be usedon char variables to get the next or preceding Unicode character.For example, the following statements display character b.char ch = 'a';System.out.println(++ch);
docsity.com