-
Notifications
You must be signed in to change notification settings - Fork 0
/
ObjectsPractice.java
65 lines (60 loc) · 1.94 KB
/
ObjectsPractice.java
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
56
57
58
59
60
61
62
63
64
65
/*
* Chapter 9.3
*
* Chapter 9 is also connected to the CommandLine folder!
*/
import java.math.BigInteger;
public class ObjectsPractice
{
public static void main(String[] args)
{
/*
* When you invoke a method on a String,
* you get a new String object as a result.
* (1)After the 1st two statements run,
* upperName 'refers' to the string "ALAN TURING".
* -toUpperCase() DOES NOT AFFECT THE O.G. STRING
* Ex)The 1st Paragraphs result.The value of name,
* which refers to the O.G. String object, never
* changes.(2)To save the result you need to assign
* the return value.
*/
String name = "Alan Turing";
//(1)String upperName = name.toUpperCase();
name.toUpperCase();
//(2)name = name.toUpperCase();
System.out.println(name);
String text = "Computer Science is fun?";
//text.replace("Computer Science", "CS");
text = text.replace("Computer Science", "CS");
System.out.println(text);
//parse => "read and translate"
String str = "12345";
double num = Double.parseDouble(str);
System.out.println(num);
int num2 = 12345;
String stri = Integer.toString(num2);
System.out.println(stri);
/*
* Objects from wrapper classes are also immutable.
* x and y refer to different objects.
*
* ?Should only display the 2nd if not the 1st????
*/
Integer x = Integer.valueOf(123);
Integer y = Integer.valueOf(123);
System.out.println(y);
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 are the same value!");
//BigInteger's have no upper bound they only depend on
//your memory size and processing speed.
long z = 17;
BigInteger big = BigInteger.valueOf(z);
System.out.println(big);
String s = "12345678901234567890";
BigInteger bigger = new BigInteger(s);
System.out.println(bigger);
}
}