forked from androdev-cft6/ThinkJavaCode2
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathObjects.java
More file actions
55 lines (39 loc) · 1.34 KB
/
Objects.java
File metadata and controls
55 lines (39 loc) · 1.34 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
import java.math.BigInteger;
/**
* Demonstates uses of objects and wrappers.
*/
public class Objects {
public static void main(String[] args) {
// primitives vs objects
int number = -2;
char symbol = '!';
char[] array = {'c', 'a', 't'};
String word = "dog";
// Strings are immutable
String name = "Alan Turing";
String upperName = name.toUpperCase();
String text = "Computer Science is fun!";
text = text.replace("Computer Science", "CS");
// Wrapper classes
Integer x = new Integer(123);
Integer y = new Integer(123);
if (x == y) { // false
System.out.println("x and y are the same object");
}
if (x.equals(y)) { // true
System.out.println("x and y have the same value");
}
String str = "12345";
int num = Integer.parseInt(str);
num = 12345;
str = Integer.toString(num);
// BigInteger arithmetic
long z = 17;
BigInteger big = BigInteger.valueOf(z);
String s = "12345678901234567890";
BigInteger bigger = new BigInteger(s);
BigInteger a = BigInteger.valueOf(17);
BigInteger b = BigInteger.valueOf(1700000000);
BigInteger c = a.add(b);
}
}