-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathjava_notes.txt
More file actions
131 lines (92 loc) · 2.17 KB
/
java_notes.txt
File metadata and controls
131 lines (92 loc) · 2.17 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
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
Java
----
public static void main(String[] args) {
}
// main: when Java runs program, the code inside the main function is executed
// void: no value returned by the method
data types: int, boolean, char
comments: //
arithmetic operators: +, -, *, /, %
relational operators: <, <=, >, >=
equality operators: ==, !=
boolean operators: &&, ||, !
statements: if, if/else, if/else if/else
ternary statements: variableName = (boolean) ? 'Y' : 'N';
switch (variableName) {
case 1: statements;
default: statements;
}
class: set of instructions, how a data structure should behave
---
class ClassName {
}
---
class constructor: allows to create class instances
---
class ClassName {
public Instance(parameter) {
}
}
---
instance variables: describe details to the class
---
class ClassName {
int inVarName;
public Instance(parameter) {
inVarName = parameter;
}
}
---
instance (of a class): an object in Java
---
class ClassName {
int inVarName;
public Instance(parameter) {
inVarName = parameter;
}
public static void main(String[] args) {
ClassName instanceName = new Instance(parameterValue);
}
---
method: pre-defined set of instructions
---
class ClassName {
public void methodName(parameters) {
}
}
--- // declare a method
---
public static void main(String[] args) {
instanceName.methodName(parameterValues);
}
--- // call a method on an object
inheritance: inherit behaviour from another class
---
class ClassName1 extends ClassName2 {
}
--- // ClassName1 inherits behaviour from ClassName2
for loop
---
for (variable initialization; test condition; increment) {
}
---
for each loop
---
for (Type element : DataName) {
}
--- // for each element in the data structure, do ...
ArrayList: predefined Java class, data structure, list of data of specified type
---
ArrayList<DataType> arrayName = new ArrayList<DataType>();
arrayName.add(value);
arrayName.add(index, value);
arrayName.get(index);
arrayName.size(); // number of elements in the array
---
HashMap: maps keys to values
---
HashMap<DataType1(key), DataType2(value)> hashName = new HashMap<DataType1(key), DataType2(value)>();
hashName.put(key, value);
hashName.get(key);
hashName.size();
---