-
Notifications
You must be signed in to change notification settings - Fork 39
/
topics.txt
153 lines (110 loc) · 3.3 KB
/
topics.txt
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
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
Java Beans
either has a default constructor JavaBean() or Serializable
matching methods: getX() and setX() both public
public void setX(int x) { internalx = x; }
public int getX() { return internalx ; }
public int[] getY() { }
public void setY(int y[]) {}
you may have other methods, but the automated code does not know about that
**Reflection API
Comparison equals
Identity ==
2 ==2 that's different, 2 is not an object
Cloneable
String Optimization
StringBuffer
StringBuilder
Immutable objects: String, Integer, Float, Double
**ArrayList<T> shallowcopy
wrapper classes
Float f = new Float(5.2f);
Double d = new Double(2.5);
Integer i = new Integer(3);
f = new Float(f.floatValue() + 1);
f = f + 1;
ArrayList<Double> a = new ArrayList<>();
for (int i = 0; i < 1000; i++)
a.add(i); // autoboxing new Double(i)
a.set(50, 42.8); // set can only be used once the position exists.
//traversing the array list
for (int i = 0; i < a.length; i++)
System.out.print(a.get(i));
for (Iterator<Double> i = a.iterator(); i.hasNext(); ) {
Double d = i.next();
System.out.print(d);
}
for (Double d : a) {
System.out.print(d);
}
review problem:
1. Build an ArrayList of numbers from 1 to 10 1 2 3 4 5 6 7 8 9 10
2. Remove elements from the end until there are only 5 1 2 3 4 5
3. Now remove all odd numbers from the list 2 4
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16...
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16...
i
j
HashMap<String, Double> quotes = new HashMap<>();
quotes.put("AAPL", 204);
quotes.put("OIL", -35);
double p = quotes.get("AAPL");
You should be able to dump out the entire hashmap but I won't ask that for the test
*** not on final, but learn before interview!!!
for (Map.Entry<String,Double> entry : quotes.entrySet()) {
System.out.println(entry.getKey() + "==>" + entry.getValue());
}
test yourself (not so important for final, but VERY important for interview)
load symbols and price from disk, look up symbol.
*** LinkedList<Integer> a = new LinkedList();
a.insert(0, 5);
**Serializable
Write a method yourself to serialize to JSON.
class Quiz {
String name;
int points;
int numQuestions;
public void save(PrintWriter p) {
p.println("{");
p.println("\"" + 5); // "5
p.println('"' + 5); // will print whatever character is 5 more than "
}
}
/*
{
"name": "Java Objects",
"points": 10,
"numQuestions": 20
}
**Thread not on final! I forgot to do it before!
class MyThread extends Thread {
@Override
public void run() {
}
}
Thread t = new Thread(); // nothing happens
t.start(); // run is executed
class, abstract class, interface, anonymous inner class, inner class, static inner class
this
super(); // first line of constructor calls parent
super("title"); // calls parent's constructor with a String parameter.
public void paint(Graphics g) {
super.paint(g);
...
}
** not on final
try {
PrintWriter pw = new PrintWriter(new BufferedWriter(new FileWriter("test.dat")));
pw.println("hello");
pw.close(); // be sure to close the file!!!
} catch (IOException e) {
e.printStackTrace();
}
Scanner!
To add a listener to a JButton (or a JTextField)
JButton b = new JButton("ok");
JTextField tf = new JTextField();
tf.addActionListener( new ActionListener() {
public void actionPerformed(ActionEvent e) {
// do something!
}
});