Skip to content

Commit 31a92d5

Browse files
committed
Java Core Exam
1 parent 8204801 commit 31a92d5

18 files changed

Lines changed: 695 additions & 0 deletions

File tree

06Collection/Collection.pptx

2.33 MB
Binary file not shown.
Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,17 @@
1+
# Editor configuration, see http://editorconfig.org
2+
root = true
3+
4+
[*]
5+
charset = utf-8
6+
indent_style = space
7+
indent_size = 2
8+
insert_final_newline = true
9+
trim_trailing_whitespace = true
10+
max_line_length = 80
11+
12+
[*.sh]
13+
end_of_line = lf
14+
15+
[*.java]
16+
indent_size = 4
17+
max_line_length = 120
Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,2 @@
1+
# When shell scripts end in CRLF, bash gives a cryptic error message
2+
*.sh text eol=lf
Lines changed: 28 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,28 @@
1+
#
2+
# Standard Maven .gitignore
3+
#
4+
target/
5+
pom.xml.tag
6+
pom.xml.releaseBackup
7+
pom.xml.versionsBackup
8+
pom.xml.next
9+
release.properties
10+
dependency-reduced-pom.xml
11+
buildNumber.properties
12+
.mvn/timing.properties
13+
14+
#
15+
# IntelliJ
16+
#
17+
*.iml
18+
.idea/*
19+
!.idea/runConfigurations/
20+
21+
#
22+
# Visual Studio Code
23+
#
24+
.settings/
25+
.classpath
26+
.factorypath
27+
.project
28+
.vscode/
Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,4 @@
1+
language: java
2+
jdk: openjdk8
3+
after_success:
4+
- mvn coveralls:report
Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
# Làm việc với Collection
Lines changed: 195 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,195 @@
1+
<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/maven-v4_0_0.xsd">
2+
<modelVersion>4.0.0</modelVersion>
3+
<groupId>vn.techmaster</groupId>
4+
<artifactId>democollection</artifactId>
5+
<version>1.0</version>
6+
<properties>
7+
<maven.compiler.source>1.8</maven.compiler.source>
8+
<maven.compiler.target>1.8</maven.compiler.target>
9+
<project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
10+
<junit.version>5.6.0</junit.version>
11+
<maven-enforcer-plugin.version>3.0.0-M3</maven-enforcer-plugin.version>
12+
<maven-checkstyle-plugin.version>3.1.0</maven-checkstyle-plugin.version>
13+
<checkstyle.version>8.29</checkstyle.version>
14+
<checkstyle-rules.version>4.0.1</checkstyle-rules.version>
15+
<maven-surefire-plugin.version>3.0.0-M4</maven-surefire-plugin.version>
16+
<jacoco-maven-plugin.version>0.8.4</jacoco-maven-plugin.version>
17+
<maven-javadoc-plugin.version>3.0.0</maven-javadoc-plugin.version>
18+
<coveralls-maven-plugin.version>4.3.0</coveralls-maven-plugin.version>
19+
<!-- JaCoCo thresholds. Increase gradually as you add tests. -->
20+
<jacoco.unit-tests.limit.instruction-ratio>0%</jacoco.unit-tests.limit.instruction-ratio>
21+
<jacoco.unit-tests.limit.branch-ratio>0%</jacoco.unit-tests.limit.branch-ratio>
22+
<jacoco.unit-tests.limit.class-complexity>20</jacoco.unit-tests.limit.class-complexity>
23+
<jacoco.unit-tests.limit.method-complexity>5</jacoco.unit-tests.limit.method-complexity>
24+
</properties>
25+
<dependencies>
26+
<dependency>
27+
<groupId>org.junit.jupiter</groupId>
28+
<artifactId>junit-jupiter-api</artifactId>
29+
<version>${junit.version}</version>
30+
<scope>test</scope>
31+
</dependency>
32+
<dependency>
33+
<groupId>org.junit.jupiter</groupId>
34+
<artifactId>junit-jupiter-engine</artifactId>
35+
<version>${junit.version}</version>
36+
<scope>test</scope>
37+
</dependency>
38+
</dependencies>
39+
<build>
40+
<plugins>
41+
<plugin>
42+
<groupId>org.apache.maven.plugins</groupId>
43+
<artifactId>maven-enforcer-plugin</artifactId>
44+
<version>${maven-enforcer-plugin.version}</version>
45+
<executions>
46+
<execution>
47+
<goals>
48+
<goal>enforce</goal>
49+
</goals>
50+
<configuration>
51+
<rules>
52+
<requireMavenVersion>
53+
<version>3.6.3</version>
54+
</requireMavenVersion>
55+
</rules>
56+
<fail>true</fail>
57+
</configuration>
58+
</execution>
59+
</executions>
60+
</plugin>
61+
<plugin>
62+
<groupId>org.apache.maven.plugins</groupId>
63+
<artifactId>maven-checkstyle-plugin</artifactId>
64+
<version>${maven-checkstyle-plugin.version}</version>
65+
<dependencies>
66+
<dependency>
67+
<groupId>com.puppycrawl.tools</groupId>
68+
<artifactId>checkstyle</artifactId>
69+
<version>${checkstyle.version}</version>
70+
</dependency>
71+
<dependency>
72+
<groupId>com.github.ngeor</groupId>
73+
<artifactId>checkstyle-rules</artifactId>
74+
<version>${checkstyle-rules.version}</version>
75+
</dependency>
76+
</dependencies>
77+
<configuration>
78+
<configLocation>com/github/ngeor/checkstyle.xml</configLocation>
79+
<includeTestSourceDirectory>true</includeTestSourceDirectory>
80+
<skip>${skipTests}</skip>
81+
</configuration>
82+
<executions>
83+
<execution>
84+
<id>checkstyle</id>
85+
<phase>validate</phase>
86+
<goals>
87+
<goal>check</goal>
88+
</goals>
89+
</execution>
90+
</executions>
91+
</plugin>
92+
<plugin>
93+
<groupId>org.apache.maven.plugins</groupId>
94+
<artifactId>maven-surefire-plugin</artifactId>
95+
<version>${maven-surefire-plugin.version}</version>
96+
</plugin>
97+
<plugin>
98+
<groupId>org.jacoco</groupId>
99+
<artifactId>jacoco-maven-plugin</artifactId>
100+
<version>${jacoco-maven-plugin.version}</version>
101+
<executions>
102+
<execution>
103+
<id>pre-unit-test</id>
104+
<goals>
105+
<goal>prepare-agent</goal>
106+
</goals>
107+
</execution>
108+
<execution>
109+
<id>post-unit-test</id>
110+
<phase>test</phase>
111+
<goals>
112+
<goal>report</goal>
113+
</goals>
114+
</execution>
115+
<execution>
116+
<id>check-unit-test</id>
117+
<phase>test</phase>
118+
<goals>
119+
<goal>check</goal>
120+
</goals>
121+
<configuration>
122+
<dataFile>${project.build.directory}/jacoco.exec</dataFile>
123+
<rules>
124+
<rule>
125+
<element>BUNDLE</element>
126+
<limits>
127+
<limit>
128+
<counter>INSTRUCTION</counter>
129+
<value>COVEREDRATIO</value>
130+
<minimum>${jacoco.unit-tests.limit.instruction-ratio}</minimum>
131+
</limit>
132+
<limit>
133+
<counter>BRANCH</counter>
134+
<value>COVEREDRATIO</value>
135+
<minimum>${jacoco.unit-tests.limit.branch-ratio}</minimum>
136+
</limit>
137+
</limits>
138+
</rule>
139+
<rule>
140+
<element>CLASS</element>
141+
<limits>
142+
<limit>
143+
<counter>COMPLEXITY</counter>
144+
<value>TOTALCOUNT</value>
145+
<maximum>${jacoco.unit-tests.limit.class-complexity}</maximum>
146+
</limit>
147+
</limits>
148+
</rule>
149+
<rule>
150+
<element>METHOD</element>
151+
<limits>
152+
<limit>
153+
<counter>COMPLEXITY</counter>
154+
<value>TOTALCOUNT</value>
155+
<maximum>${jacoco.unit-tests.limit.method-complexity}</maximum>
156+
</limit>
157+
</limits>
158+
</rule>
159+
</rules>
160+
</configuration>
161+
</execution>
162+
</executions>
163+
</plugin>
164+
</plugins>
165+
</build>
166+
<reporting>
167+
<plugins>
168+
<plugin>
169+
<groupId>org.apache.maven.plugins</groupId>
170+
<artifactId>maven-javadoc-plugin</artifactId>
171+
<version>${maven-javadoc-plugin.version}</version>
172+
</plugin>
173+
</plugins>
174+
</reporting>
175+
<profiles>
176+
<!-- Publish coverage report to Coveralls, only when running in Travis. -->
177+
<profile>
178+
<id>travis</id>
179+
<activation>
180+
<property>
181+
<name>env.TRAVIS</name>
182+
</property>
183+
</activation>
184+
<build>
185+
<plugins>
186+
<plugin>
187+
<groupId>org.eluder.coveralls</groupId>
188+
<artifactId>coveralls-maven-plugin</artifactId>
189+
<version>${coveralls-maven-plugin.version}</version>
190+
</plugin>
191+
</plugins>
192+
</build>
193+
</profile>
194+
</profiles>
195+
</project>
Lines changed: 36 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,36 @@
1+
package vn.techmaster;
2+
3+
import java.util.ArrayList;
4+
import java.util.List;
5+
class Student {
6+
String name;
7+
float averageScore;
8+
public Student(String name, float averageScore) {
9+
this.name = name;
10+
this.averageScore = averageScore;
11+
}
12+
13+
@Override
14+
public String toString() {
15+
return this.name + " : " + this.averageScore;
16+
}
17+
}
18+
public class AnyTypeList {
19+
private List<Object> anyTypedList = new ArrayList<>();
20+
21+
public AnyTypeList() {
22+
anyTypedList.add("Hello");
23+
anyTypedList.add(1);
24+
anyTypedList.add(1.6);
25+
anyTypedList.add(10L);
26+
anyTypedList.add(1==1);
27+
anyTypedList.add(new Student("Trịnh Minh Cường", 7.85f));
28+
29+
}
30+
31+
public void listItemAndType() {
32+
anyTypedList.forEach(item -> {
33+
System.out.println(item.getClass() + " " + item.toString());
34+
});
35+
}
36+
}
Lines changed: 72 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,72 @@
1+
package vn.techmaster;
2+
3+
public final class App {
4+
private App() {
5+
}
6+
7+
static void differentWaysToLoopAList() {
8+
DemoList demoList = new DemoList();
9+
demoList.simpleForLoop();
10+
11+
demoList.enhanceForLoop();
12+
13+
demoList.iteratorLoop();
14+
15+
demoList.listIteratorLoop();
16+
17+
demoList.listIteratorBackward();
18+
19+
demoList.whileLoop();
20+
21+
demoList.forEachLoopA();
22+
23+
demoList.forEachLoopB();
24+
25+
demoList.streamForEach();
26+
}
27+
28+
static void aListCanAcceptAnyType() {
29+
AnyTypeList anyTypeList = new AnyTypeList();
30+
anyTypeList.listItemAndType();
31+
}
32+
33+
static void removeItemFromList() {
34+
RemoveItemFromList rmItemFromLst = new RemoveItemFromList();
35+
//rmItemFromLst.removeOddNumbersBuggy();
36+
//rmItemFromLst.removeOddNumbers();
37+
//rmItemFromLst.removeIfOddNumbers();
38+
rmItemFromLst.removeOddNumbersIterator();
39+
rmItemFromLst.clearAllItems();
40+
41+
}
42+
43+
static void sortList() {
44+
SortList sList = new SortList();
45+
sList.sortListSimple();
46+
}
47+
48+
static void customSort() {
49+
CustomSort s = new CustomSort();
50+
s.sort();
51+
}
52+
53+
static void demoHashSet() {
54+
DemoHashSet hs = new DemoHashSet();
55+
}
56+
57+
public static void main(String[] args) {
58+
// differentWaysToLoopAList();
59+
60+
// aListCanAcceptAnyType();
61+
62+
// removeItemFromList();
63+
64+
// sortList();
65+
66+
// customSort();
67+
int i;
68+
System.out.println(i);
69+
70+
//demoHashSet();
71+
}
72+
}

0 commit comments

Comments
 (0)