Skip to content

Commit 31d47be

Browse files
committed
更新 Java 8 核心 相关的文章链接
1 parent 7a8bb26 commit 31d47be

29 files changed

Lines changed: 691 additions & 2 deletions
Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,25 @@
1+
*.class
2+
3+
0.*
4+
5+
#folders#
6+
/target
7+
/neoDb*
8+
/data
9+
/src/main/webapp/WEB-INF/classes
10+
*/META-INF/*
11+
.resourceCache
12+
13+
# Packaged files #
14+
*.jar
15+
*.war
16+
*.ear
17+
18+
# Files generated by integration tests
19+
backup-pom.xml
20+
/bin/
21+
/temp
22+
23+
#IntelliJ specific
24+
.idea/
25+
*.iml
Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,13 @@
1+
## Java 8 核心(第 2 部分)
2+
3+
本模块中包含有关 Java 8 核心新增功能特性的一些文章。
4+
5+
### 相关文章
6+
7+
- [Run a Java Application from the Command Line](https://www.baeldung.com/java-run-jar-with-arguments)
8+
- [Java 8 Stream skip() vs limit()](https://www.baeldung.com/java-stream-skip-vs-limit)
9+
- [Guide to Java BiFunction Interface](https://www.baeldung.com/java-bifunction-interface)
10+
- [Interface With Default Methods vs Abstract Class](https://www.baeldung.com/java-interface-default-method-vs-abstract-class)
11+
- [Convert Between Byte Array and UUID in Java](https://www.baeldung.com/java-byte-array-to-uuid)
12+
- [Create a Simple “Rock-Paper-Scissors” Game in Java](https://www.baeldung.com/java-rock-paper-scissors)
13+
- [[<-- Java 8 核心(第 1 部分)]](/core-java-modules/core-java-8)
Lines changed: 29 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,29 @@
1+
<?xml version="1.0" encoding="UTF-8"?>
2+
<project xmlns="http://maven.apache.org/POM/4.0.0"
3+
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
4+
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
5+
<modelVersion>4.0.0</modelVersion>
6+
<artifactId>core-java-8-2</artifactId>
7+
<version>0.1.0-SNAPSHOT</version>
8+
<name>core-java-8-2</name>
9+
<packaging>jar</packaging>
10+
11+
<parent>
12+
<groupId>com.ossez.core-java-modules</groupId>
13+
<artifactId>core-java-modules</artifactId>
14+
<version>0.0.2-SNAPSHOT</version>
15+
</parent>
16+
17+
<dependencies>
18+
<dependency>
19+
<groupId>com.ibm.icu</groupId>
20+
<artifactId>icu4j</artifactId>
21+
<version>${icu.version}</version>
22+
</dependency>
23+
</dependencies>
24+
25+
<properties>
26+
<icu.version>64.2</icu.version>
27+
</properties>
28+
29+
</project>
Lines changed: 73 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,73 @@
1+
package com.ossez.game;
2+
3+
import java.util.*;
4+
5+
class RockPaperScissorsGame {
6+
7+
enum Move {
8+
ROCK("rock"),
9+
PAPER("paper"),
10+
SCISSORS("scissors");
11+
12+
private String value;
13+
14+
Move(String value) {
15+
this.value = value;
16+
}
17+
18+
public String getValue() {
19+
return value;
20+
}
21+
}
22+
23+
public static void main(String[] args) {
24+
Scanner scanner = new Scanner(System.in);
25+
int wins = 0;
26+
int losses = 0;
27+
28+
System.out.println("Welcome to Rock-Paper-Scissors! Please enter \"rock\", \"paper\", \"scissors\", or \"quit\" to exit.");
29+
30+
while (true) {
31+
System.out.println("-------------------------");
32+
System.out.print("Enter your move: ");
33+
String playerMove = scanner.nextLine();
34+
35+
if (playerMove.equals("quit")) {
36+
System.out.println("You won " + wins + " times and lost " + losses + " times.");
37+
System.out.println("Thanks for playing! See you again.");
38+
break;
39+
}
40+
41+
if (Arrays.stream(Move.values()).noneMatch(x -> x.getValue().equals(playerMove))) {
42+
System.out.println("Your move isn't valid!");
43+
continue;
44+
}
45+
46+
String computerMove = getComputerMove();
47+
48+
if (playerMove.equals(computerMove)) {
49+
System.out.println("It's a tie!");
50+
} else if (isPlayerWin(playerMove, computerMove)) {
51+
System.out.println("You won!");
52+
wins++;
53+
} else {
54+
System.out.println("You lost!");
55+
losses++;
56+
}
57+
}
58+
}
59+
60+
private static boolean isPlayerWin(String playerMove, String computerMove) {
61+
return playerMove.equals(Move.ROCK.value) && computerMove.equals(Move.SCISSORS.value)
62+
|| (playerMove.equals(Move.SCISSORS.value) && computerMove.equals(Move.PAPER.value))
63+
|| (playerMove.equals(Move.PAPER.value) && computerMove.equals(Move.ROCK.value));
64+
}
65+
66+
private static String getComputerMove() {
67+
Random random = new Random();
68+
int randomNumber = random.nextInt(3);
69+
String computerMove = Move.values()[randomNumber].getValue();
70+
System.out.println("Computer move: " + computerMove);
71+
return computerMove;
72+
}
73+
}
Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,14 @@
1+
package com.ossez.interfaceVsAbstractClass;
2+
3+
public class ChidlCircleInterfaceImpl implements CircleInterface {
4+
private String color;
5+
6+
@Override
7+
public String getColor() {
8+
return color;
9+
}
10+
11+
public void setColor(String color) {
12+
this.color = color;
13+
}
14+
}
Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
package com.ossez.interfaceVsAbstractClass;
2+
3+
public class ChildCircleClass extends CircleClass {
4+
5+
}
Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,23 @@
1+
package com.ossez.interfaceVsAbstractClass;
2+
3+
import java.util.Arrays;
4+
import java.util.List;
5+
6+
public abstract class CircleClass {
7+
8+
private String color;
9+
private List<String> allowedColors = Arrays.asList("RED", "GREEN", "BLUE");
10+
11+
public boolean isValid() {
12+
return allowedColors.contains(getColor());
13+
}
14+
15+
public String getColor() {
16+
return color;
17+
}
18+
19+
public void setColor(String color) {
20+
this.color = color;
21+
}
22+
23+
}
Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,14 @@
1+
package com.ossez.interfaceVsAbstractClass;
2+
3+
import java.util.Arrays;
4+
import java.util.List;
5+
6+
public interface CircleInterface {
7+
List<String> allowedColors = Arrays.asList("RED", "GREEN", "BLUE");
8+
9+
String getColor();
10+
11+
public default boolean isValid() {
12+
return allowedColors.contains(getColor());
13+
}
14+
}
Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,18 @@
1+
package com.ossez.jarArguments;
2+
3+
public class JarExample {
4+
5+
public static void main(String[] args) {
6+
System.out.println("Hello Baeldung Reader in JarExample!");
7+
8+
if(args == null) {
9+
System.out.println("You have not provided any arguments!");
10+
}else {
11+
System.out.println("There are "+args.length+" argument(s)!");
12+
for(int i=0; i<args.length; i++) {
13+
System.out.println("Argument("+(i+1)+"):" + args[i]);
14+
}
15+
}
16+
}
17+
18+
}
Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,21 @@
1+
package com.ossez.localization;
2+
3+
import java.text.ParseException;
4+
import java.util.Arrays;
5+
import java.util.List;
6+
import java.util.Locale;
7+
8+
public class App {
9+
10+
/**
11+
* Runs all available formatter
12+
* @throws ParseException
13+
*/
14+
public static void main(String[] args) {
15+
List<Locale> locales = Arrays.asList(new Locale[] { Locale.UK, Locale.ITALY, Locale.FRANCE, Locale.forLanguageTag("pl-PL") });
16+
Localization.run(locales);
17+
JavaSEFormat.run(locales);
18+
ICUFormat.run(locales);
19+
}
20+
21+
}

0 commit comments

Comments
 (0)