diff --git a/.vscode/launch.json b/.vscode/launch.json index 2e5b59d..4eafca6 100644 --- a/.vscode/launch.json +++ b/.vscode/launch.json @@ -4,6 +4,27 @@ // Weitere Informationen finden Sie unter https://go.microsoft.com/fwlink/?linkid=830387 "version": "0.2.0", "configurations": [ + { + "type": "java", + "name": "TaschenrechnerInt2", + "request": "launch", + "mainClass": "TaschenrechnerInt2", + "projectName": "PR2-L_ada963eb" + }, + { + "type": "java", + "name": "TaschenrechnerInt", + "request": "launch", + "mainClass": "TaschenrechnerInt", + "projectName": "PR2-L_ada963eb" + }, + { + "type": "java", + "name": "DemoParallel", + "request": "launch", + "mainClass": "DemoParallel", + "projectName": "PR2-L_ada963eb" + }, { "type": "java", "name": "TaschenrechnerInt4", diff --git a/DemoLazy/src/DemoLazy.java b/DemoLazy/src/DemoLazy.java index 9cafa3b..61d67ad 100644 --- a/DemoLazy/src/DemoLazy.java +++ b/DemoLazy/src/DemoLazy.java @@ -1,4 +1,7 @@ -// Lazy Evaluation von Operationen +/**Copyright (c) Balzert, H: "Java: Objektorientiert Programmieren" + * W3L-Verlag Dortmund, 3. Auflage, 2014 + * Lazy Evaluation von Operationen, S. 345. +*/ import java.util.ArrayList; import java.util.stream.Stream; diff --git a/DemoParallel/src/DemoParallel.java b/DemoParallel/src/DemoParallel.java index 75a5ba4..43905a8 100644 --- a/DemoParallel/src/DemoParallel.java +++ b/DemoParallel/src/DemoParallel.java @@ -1,30 +1,32 @@ -// Sequenzielle vs. parallele Berechnung +/**Copyright (c) Balzert, H: "Java: Objektorientiert Programmieren" + * W3L-Verlag Dortmund, 3. Auflage, 2014 + * Sequenzielle vs. parallele Berechnung, S. 347 f. +*/ import java.util.stream.Stream; import java.util.List; import java.util.stream.Collectors; public class DemoParallel { + public static void main(String[] args) { + + double uGrenze = -30.0, oGrenze = +40.0; + // Bereiche der Zufallszahlen + // Liste mit 10 Mio. Daten erzeugen + List d = Stream.generate( + () -> (uGrenze + (Math.random() * (oGrenze - uGrenze + 1)))) + .limit(10_000_000).collect(Collectors.toList()); - public static void main(String[] args) { - long start = System.currentTimeMillis(); - - double uGrenze = -30.0, oGrenze = +40.0; - // Bereiche der Zufallszahlen - // Liste mit 10 Mio. Daten erzeugen - List d = Stream.generate( - () -> new Double(uGrenze+(Math.random() * - (oGrenze - uGrenze + 1)))) - .limit(10_000_000).collect(Collectors.toList()); - - List temp = - d.stream() - .sorted() - .filter(wert -> (Math.abs(wert) > 25.0)) - .parallel() - .collect(Collectors.toList()); - - long stop = System.currentTimeMillis(); - System.out.println("Verbrauchte Zeit in ms: " + (stop - start)); - } + long start = System.currentTimeMillis(); + + d.stream() + .parallel() + .sorted() + .filter(wert -> (Math.abs(wert) > 25.0)) + .collect(Collectors.toList()); + + long stop = System.currentTimeMillis(); + + System.out.println("Verbrauchte Zeit in ms: " + (stop - start)); + } } diff --git a/TaschenrechnerInt/.vscode/settings.json b/TaschenrechnerInt/.vscode/settings.json new file mode 100644 index 0000000..0ac215c --- /dev/null +++ b/TaschenrechnerInt/.vscode/settings.json @@ -0,0 +1,7 @@ +{ + "java.project.sourcePaths": ["src"], + "java.project.outputPath": "bin", + "java.project.referencedLibraries": [ + "lib/**/*.jar" + ] +} diff --git a/TaschenrechnerInt/README.md b/TaschenrechnerInt/README.md new file mode 100644 index 0000000..a43b9f6 --- /dev/null +++ b/TaschenrechnerInt/README.md @@ -0,0 +1,18 @@ +## Getting Started + +Welcome to the VS Code Java world. Here is a guideline to help you get started to write Java code in Visual Studio Code. + +## Folder Structure + +The workspace contains two folders by default, where: + +- `src`: the folder to maintain sources +- `lib`: the folder to maintain dependencies + +Meanwhile, the compiled output files will be generated in the `bin` folder by default. + +> If you want to customize the folder structure, open `.vscode/settings.json` and update the related settings there. + +## Dependency Management + +The `JAVA PROJECTS` view allows you to manage your dependencies. More details can be found [here](https://github.com/microsoft/vscode-java-dependency#manage-dependencies). diff --git a/TaschenrechnerInt/src/TaschenrechnerInt.java b/TaschenrechnerInt/src/TaschenrechnerInt.java new file mode 100644 index 0000000..610e620 --- /dev/null +++ b/TaschenrechnerInt/src/TaschenrechnerInt.java @@ -0,0 +1,22 @@ +/**Copyright (c) Balzert, H: "Java: Objektorientiert Programmieren" + * W3L-Verlag Dortmund, 3. Auflage, 2014 + * Funktionale Schnittstellen, S. 339 +*/ + +public class TaschenrechnerInt +{ + @FunctionalInterface + interface MathInteger + { + int berechne(int a, int b); + } + + public static void main(String args []) + { + MathInteger addiere = (c, d) -> c + d; + MathInteger multipliziere = (x, y) -> x * y; + + System.out.println(addiere.berechne(10, 20)); + System.out.println(multipliziere.berechne(10, 20)); + } +} \ No newline at end of file diff --git a/TaschenrechnerInt2/.vscode/settings.json b/TaschenrechnerInt2/.vscode/settings.json new file mode 100644 index 0000000..0ac215c --- /dev/null +++ b/TaschenrechnerInt2/.vscode/settings.json @@ -0,0 +1,7 @@ +{ + "java.project.sourcePaths": ["src"], + "java.project.outputPath": "bin", + "java.project.referencedLibraries": [ + "lib/**/*.jar" + ] +} diff --git a/TaschenrechnerInt2/README.md b/TaschenrechnerInt2/README.md new file mode 100644 index 0000000..a43b9f6 --- /dev/null +++ b/TaschenrechnerInt2/README.md @@ -0,0 +1,18 @@ +## Getting Started + +Welcome to the VS Code Java world. Here is a guideline to help you get started to write Java code in Visual Studio Code. + +## Folder Structure + +The workspace contains two folders by default, where: + +- `src`: the folder to maintain sources +- `lib`: the folder to maintain dependencies + +Meanwhile, the compiled output files will be generated in the `bin` folder by default. + +> If you want to customize the folder structure, open `.vscode/settings.json` and update the related settings there. + +## Dependency Management + +The `JAVA PROJECTS` view allows you to manage your dependencies. More details can be found [here](https://github.com/microsoft/vscode-java-dependency#manage-dependencies). diff --git a/TaschenrechnerInt2/src/TaschenrechnerInt2.java b/TaschenrechnerInt2/src/TaschenrechnerInt2.java new file mode 100644 index 0000000..1c4c063 --- /dev/null +++ b/TaschenrechnerInt2/src/TaschenrechnerInt2.java @@ -0,0 +1,25 @@ +/**Copyright (c) Balzert, H: "Java: Objektorientiert Programmieren" + * W3L-Verlag Dortmund, 3. Auflage, 2014 + * Funktionale Schnittstellen, S. 340 +*/ + +public class TaschenrechnerInt2 +{ + @FunctionalInterface + interface MathInteger + { + int berechne(int a, int b); + } + + public static int ergebnis(int x, int y, MathInteger op) + { + return op.berechne(x, y); + } + + public static void main(String args []) + { + int c = 10, d = 20; + System.out.println(ergebnis(c, d, (c1, d1) -> c1 - d1)); + System.out.println(ergebnis(c, d, (c1, d1) -> c1 / d1)); + } +} \ No newline at end of file diff --git a/TaschenrechnerInt3/src/MathInteger.java b/TaschenrechnerInt3/src/MathInteger.java index e33a606..8ff0243 100644 --- a/TaschenrechnerInt3/src/MathInteger.java +++ b/TaschenrechnerInt3/src/MathInteger.java @@ -1,3 +1,8 @@ +/**Copyright (c) Balzert, H: "Java: Objektorientiert Programmieren" + * W3L-Verlag Dortmund, 3. Auflage, 2014 + * Funktionale Schnittstellen, S. 341. +*/ + @FunctionalInterface interface MathInteger { diff --git a/TaschenrechnerInt4/src/TaschenrechnerInt4.java b/TaschenrechnerInt4/src/TaschenrechnerInt4.java index 54c90e2..4937ec0 100644 --- a/TaschenrechnerInt4/src/TaschenrechnerInt4.java +++ b/TaschenrechnerInt4/src/TaschenrechnerInt4.java @@ -1,3 +1,8 @@ +/**Copyright (c) Balzert, H: "Java: Objektorientiert Programmieren" + * W3L-Verlag Dortmund, 3. Auflage, 2014 + * Funktionale Schnittstellen, S. 343. +*/ + import java.util.function.IntFunction; import java.util.function.IntPredicate;