Skip to content

Commit ddc1500

Browse files
committed
update
1 parent f94ad3e commit ddc1500

9 files changed

Lines changed: 65 additions & 42 deletions

File tree

‎README.md‎

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -3,18 +3,18 @@
33
Java核心技术学习代码兼测试案例<br>
44
- test目录(测试包名与src目录保持一致)<br>
55
对应学习代码包的详细测试案例<br>
6-
6+
本人根据得到的启发给各个模块评级 * 一般 ** 有点意思 *** 棒
77
包目录:
88

99
- [ ] ├── org.rpc // 基于Java动态代理&Socket的简单RPC实现
1010
=================华丽的分割线=================
11-
- [ ] ├── org.javacore.base // Java基础必备
12-
- [ ] ├── org.javacore.collection // Java集合
13-
- [ ] ├── org.javacore.collection.list // Java集合List
14-
- [ ] ├── org.javacore.collection.map // Java集合Map
15-
- [ ] ├── org.javacore.collection.queue // Java集合Queue
16-
- [ ] ├── org.javacore.collection.set // Java集合Set
17-
- [ ] ├── org.javacore.collection.util // Java集合工具类
11+
- [x] ├── org.javacore.base // Java基础必备(**)
12+
- [x] ├── org.javacore.collection // Java集合(*)
13+
- [x] ├── org.javacore.collection.list // Java集合List(*)
14+
- [x] ├── org.javacore.collection.map // Java集合Map(*)
15+
- [x] ├── org.javacore.collection.queue // Java集合Queue(*)
16+
- [x] ├── org.javacore.collection.set // Java集合Set(*)
17+
- [x] ├── org.javacore.collection.util // Java集合工具类(**)
1818
- [ ] ├── org.javacore.initAndCleanup // Java初始化及清理
1919
- [ ] ├── org.javacore.io // Java IO
2020
- [ ] ├── org.javacore.io.byteoper // Java IO 字节操作

‎src/main/java/org/javacore/base/String/StringT2.java‎

Lines changed: 14 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -4,9 +4,9 @@
44
* Licensed under the Apache License, Version 2.0 (the "License");
55
* you may not use this file except in compliance with the License.
66
* You may obtain a copy of the License at
7-
*
7+
*
88
* http://www.apache.org/licenses/LICENSE-2.0
9-
*
9+
*
1010
* Unless required by applicable law or agreed to in writing, software
1111
* distributed under the License is distributed on an "AS IS" BASIS,
1212
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
@@ -24,13 +24,19 @@ public class StringT2 {
2424
public static void main(String[] args) {
2525
StringObject sb = new StringObject();
2626
sb.setName("123");
27-
change(sb);
28-
System.out.println(sb.getName());
27+
change(sb, sb);
28+
System.out.println(sb.getName()); //结果为 234
2929
}
3030

31-
public static void change(StringObject sb) {
32-
sb = new StringObject();
33-
sb.setName("456");
31+
public static void change(StringObject sb1, StringObject sb2) {
32+
/**
33+
* 在这里可以看出对象作为方法传递,只是传递该对象的一个引用,相当于指针
34+
* sb1指向了一个新申请的对象
35+
* sb2引用没有变,只是修改了对象的name属性
36+
*/
37+
sb1 = new StringObject();
38+
sb1.setName("456");
39+
sb2.setName("234");
3440
}
3541

3642
}
@@ -44,4 +50,4 @@ public String getName() {
4450
public void setName(String name) {
4551
this.name = name;
4652
}
47-
}
53+
}

‎src/main/java/org/javacore/base/copy/CopyT.java‎

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -121,7 +121,8 @@ protected Object clone() throws CloneNotSupportedException {
121121
* java的引用类型都是存储在堆上的。
122122
* 然后开始说这份代码说的内容
123123
* 1. 浅拷贝: 只是将调用该方法的对象另复制一份,使用一段新的内存来存放,
124-
* 但是在这个类里面类级别的属性还是引用
124+
* 但是在这个对象里面类级别的属性还是引用
125+
* 2. 深拷贝: 克隆该对象后再克隆对象所引用的类级别的属性,重新引用这些属性
125126
*
126127
*/
127128
public class CopyT {

‎src/main/java/org/javacore/base/inter/ApplyClass.java‎

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -45,6 +45,9 @@ Object process(Object input) {
4545
}
4646
}
4747

48+
/**
49+
* 不使用接口的话,就要用子类继承父类的方法来实现
50+
*/
4851
public class ApplyClass {
4952
public static void process(Processor p , Object input){
5053
System.out.println("调用对象名:" + p.name());

‎src/main/java/org/javacore/base/inter/ApplyInter.java‎

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -53,6 +53,10 @@ public Object process(Object input) {
5353
}
5454
}
5555

56+
/**
57+
* 虽然代码看起来和不用接口实现的类似,
58+
* 但是一个Java类只能继承一个父类,但可以实现多个接口
59+
*/
5660
public class ApplyInter {
5761
public static void process(ProcessorInter p , Object input){
5862
System.out.println("调用对象名:" + p.name());

‎src/main/java/org/javacore/collection/PerBtwnAllCollectionsT.java‎

Lines changed: 20 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -15,9 +15,9 @@
1515
* Licensed under the Apache License, Version 2.0 (the "License");
1616
* you may not use this file except in compliance with the License.
1717
* You may obtain a copy of the License at
18-
*
18+
*
1919
* http://www.apache.org/licenses/LICENSE-2.0
20-
*
20+
*
2121
* Unless required by applicable law or agreed to in writing, software
2222
* distributed under the License is distributed on an "AS IS" BASIS,
2323
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
@@ -30,9 +30,20 @@
3030
* @since 2015-6-17 23:32:30
3131
* 各集合添加元素性能对比
3232
*/
33+
34+
/**
35+
* 1. 了解常见集合,多种遍历方法
36+
* 2. 了解性能和线程安全问题
37+
* 3. 实现compare函数来排序
38+
*
39+
* 查看util包下的
40+
* 排序${@link org.javacore.collection.util.CollectionsT}
41+
* Iterator与ListIterator的区别${@link org.javacore.collection.util.IterAndListIterT}
42+
* Mao性能对比${@link org.javacore.collection.util.PerBtwnEmptyMapAndHashMapT}
43+
*/
3344
@SuppressWarnings("unchecked")
3445
public class PerBtwnAllCollectionsT{
35-
46+
3647
public static void main(String[] args){
3748
// List Add对比
3849
printLists();
@@ -53,7 +64,7 @@ private static void printLists(){
5364
a1.add("Map");
5465
System.out.println("ArrayList Elements:");
5566
System.out.print("\t" + a1 + "\n");
56-
67+
5768
List<String> l1 = new LinkedList<String>();
5869
l1.add("List");
5970
l1.add("Set");
@@ -62,7 +73,7 @@ private static void printLists(){
6273
System.out.println("LinkedList Elements:");
6374
System.out.print("\t" + l1 + "\n");
6475
}
65-
76+
6677
/**
6778
* 比较Set的Add方法:注意元素的位置
6879
*/
@@ -75,7 +86,7 @@ private static void printSets() {
7586
h1.add("Map");
7687
System.out.println("HashSet Elements:");
7788
System.out.print("\t" + h1 + "\n");
78-
89+
7990
Set t1 = new TreeSet<String>();
8091
t1.add("List");
8192
t1.add("Set");
@@ -84,7 +95,7 @@ private static void printSets() {
8495
System.out.println("TreeSet Elements:");
8596
System.out.print("\t" + t1 + "\n");
8697
}
87-
98+
8899
/**
89100
* 比较Map的put方法:注意元素的位置
90101
*/
@@ -96,14 +107,14 @@ private static void printMaps() {
96107
h1.put("Map", "HashMap");
97108
System.out.println("HashMap Elements:");
98109
System.out.print("\t" + h1 + "\n");
99-
110+
100111
Map<String, String> t1 = new TreeMap<String,String>();
101112
t1.put("List", "ArrayList");
102113
t1.put("Set", "HashSet");
103114
t1.put("Queue", "PriorityQueue");
104115
t1.put("Map", "HashMap");
105116
System.out.println("TreeMap Elements:");
106117
System.out.print("\t" + t1 + "\n");
107-
118+
108119
}
109120
}

‎src/main/java/org/javacore/collection/hash/HashList.java‎

Lines changed: 0 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -28,8 +28,5 @@ public static void main(String[] args) {
2828
skuObj.setDesc("descexist" + i);
2929
existSkuObjList.add(skuObj);
3030
}
31-
32-
33-
3431
}
3532
}

‎src/main/java/org/javacore/collection/util/IterAndListIterT.java‎

Lines changed: 9 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -11,9 +11,9 @@
1111
* Licensed under the Apache License, Version 2.0 (the "License");
1212
* you may not use this file except in compliance with the License.
1313
* You may obtain a copy of the License at
14-
*
14+
*
1515
* http://www.apache.org/licenses/LICENSE-2.0
16-
*
16+
*
1717
* Unless required by applicable law or agreed to in writing, software
1818
* distributed under the License is distributed on an "AS IS" BASIS,
1919
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
@@ -27,12 +27,12 @@
2727
* Iterator与ListIterator的区别
2828
*/
2929
public class IterAndListIterT {
30-
30+
3131
public static void main(String[] args) {
32-
//iterator();
32+
// iterator();
3333
listIterator();
3434
}
35-
35+
3636
/**
3737
* 并发修改异常产生。
3838
* 原因:Iterator(Object obj = it.next()) 会检查HashMap的size,
@@ -45,17 +45,17 @@ public static void iterator(){
4545
a1.add("List02");
4646
a1.add("List04");
4747
a1.add("List05");
48-
48+
4949
Iterator i1 = a1.iterator();
5050
while (i1.hasNext()){
5151
Object obj = i1.next();
5252
if (obj.equals("List02"))
5353
a1.add("List03");
5454
}
55-
55+
5656
System.out.print("集合:\n\t"+a1+"\n");
5757
}
58-
58+
5959
/**
6060
* ListIterator可以实现对象的修改。
6161
*/
@@ -66,7 +66,7 @@ public static void listIterator(){
6666
a1.add("List");
6767
a1.add("List03");
6868
a1.add("List04");
69-
69+
7070
ListIterator l1 = a1.listIterator();
7171
while (l1.hasNext()){
7272
Object obj = l1.next();

‎src/main/java/org/javacore/collection/util/PerBtwnEmptyMapAndHashMapT.java‎

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -9,9 +9,9 @@
99
* Licensed under the Apache License, Version 2.0 (the "License");
1010
* you may not use this file except in compliance with the License.
1111
* You may obtain a copy of the License at
12-
*
12+
*
1313
* http://www.apache.org/licenses/LICENSE-2.0
14-
*
14+
*
1515
* Unless required by applicable law or agreed to in writing, software
1616
* distributed under the License is distributed on an "AS IS" BASIS,
1717
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
@@ -28,16 +28,17 @@
2828
public class PerBtwnEmptyMapAndHashMapT {
2929
@SuppressWarnings({"unused", "rawtypes"})
3030
public static void main(String[] args) {
31+
// nanoTime() 输出的精度是纳秒ns级别
3132
long startTime = System.nanoTime();
3233
long endTime;
33-
long duration;
34+
long duration;
3435
for (int i = 0; i < 100000000; i++) {
3536
Map map = Collections.EMPTY_MAP;
3637
}
3738
endTime = System.nanoTime();
3839
duration = endTime - startTime;
3940
System.out.println("Collections.EMPTY_MAP: " + duration);
40-
41+
4142
startTime = System.nanoTime();
4243
for (int i = 0; i < 100000000; i++) {
4344
Map map = new HashMap<>();

0 commit comments

Comments
 (0)