forked from Labore/PR2-L
1
0
Fork 0

added more demos

main
Gerd Marmitt 2024-04-25 12:27:26 +02:00
parent 2cc61992d1
commit c024ef0a4f
32 changed files with 439 additions and 0 deletions

View File

@ -0,0 +1,7 @@
{
"java.project.sourcePaths": ["src"],
"java.project.outputPath": "bin",
"java.project.referencedLibraries": [
"lib/**/*.jar"
]
}

View File

@ -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).

View File

@ -0,0 +1,21 @@
public class DatenspeicherMinMax<T> {
private T min, max;
public void setMax(T neuerWert) {
if (neuerWert > max)
max = neuerWert;
}
public void setMin(T neuerWert) {
if (neuerWert < min)
min = neuerWert;
}
public T getMax() {
return max;
}
public T getMin() {
return min;
}
}

View File

@ -0,0 +1,8 @@
public class Test {
public static void main(String[] args) throws Exception {
DatenspeicherMinMax<Float> dF =
new DatenspeicherMinMax<>();
dF.setMin(3.75f); // Geht das???
}
}

View File

@ -0,0 +1,7 @@
{
"java.project.sourcePaths": ["src"],
"java.project.outputPath": "bin",
"java.project.referencedLibraries": [
"lib/**/*.jar"
]
}

View File

@ -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).

View File

@ -0,0 +1,20 @@
public class DatenspeicherMinMax2<T extends Comparable<T>> {
private T min, max;
public void pruefeMax(T neuerWert)
{
if(neuerWert.compareTo(max) > 0)
max = neuerWert;
}
public void pruefeMin(T neuerWert)
{
if(neuerWert.compareTo(min) < 0)
min = neuerWert;
}
public void setMax(T neuerWert) { max = neuerWert; }
public void setMin(T neuerWert) { min = neuerWert; }
public T getMax() { return max; }
public T getMin() { return min; }
}

View File

@ -0,0 +1,8 @@
public class Test {
public static void main(String[] args) throws Exception {
DatenspeicherMinMax2<Float> dF =
new DatenspeicherMinMax2<>();
dF.setMin(3.75f); // Geht das???
}
}

View File

@ -0,0 +1,7 @@
{
"java.project.sourcePaths": ["src"],
"java.project.outputPath": "bin",
"java.project.referencedLibraries": [
"lib/**/*.jar"
]
}

View File

@ -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).

View File

@ -0,0 +1,18 @@
public class DatenspeicherPaar<T1, T2> {
private T1 wert1;
private T2 wert2;
public void setPaar(T1 nW1, T2 nW2) {
wert1 = nW1;
wert2 = nW2;
}
public T1 getWert1() {
return wert1;
}
public T2 getWert2() {
return wert2;
}
}

View File

@ -0,0 +1,9 @@
public class TestPaar {
public static void main(String[] args) throws Exception {
DatenspeicherPaar<String, Integer> dsP = new DatenspeicherPaar<>();
dsP.setPaar("Java-Version", 19);
System.out.println(dsP.getWert1() + " " + dsP.getWert2());
}
}

View File

@ -0,0 +1,7 @@
{
"java.project.sourcePaths": ["src"],
"java.project.outputPath": "bin",
"java.project.referencedLibraries": [
"lib/**/*.jar"
]
}

View File

@ -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).

View File

@ -0,0 +1,17 @@
public class Dreieckstausch {
public static <E> void tausche(E [] f)
{
E s = f[0]; f[0] = f[1]; f[1] = s;
}
public static void main(String args [])
{
Double v[] = {1.0, 2.0};
System.out.println(v[0] + " " + v[1]);
Dreieckstausch.tausche(v);
System.out.println(v[0] + " " + v[1]);
}
}

View File

@ -0,0 +1,7 @@
{
"java.project.sourcePaths": ["src"],
"java.project.outputPath": "bin",
"java.project.referencedLibraries": [
"lib/**/*.jar"
]
}

View File

@ -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).

View File

@ -0,0 +1,18 @@
public class EigeneException {
public static double division(double zaehler, double nenner) throws NullDivisionException {
if(nenner == 0.0)
throw new NullDivisionException("Nulldivision", zaehler);
else
return zaehler / nenner;
}
public static void main(String [] args) {
try {
double zaehler = 21.3;
double nenner = 0.0;
double bruch = division(zaehler, nenner);
System.out.printf("\n\t %f : %f = %f\n", zaehler, nenner, bruch);
} catch (NullDivisionException e) {
System.err.println(e.getMessage() + " mit Zaehler: " + e.getZaehler());
}
}
}

View File

@ -0,0 +1,14 @@
class NullDivisionException extends Exception {
private double zaehler;
public NullDivisionException() { }
public NullDivisionException(String meldung) {
super(meldung);
}
public NullDivisionException(String meldung, double zaehler) {
super(meldung);
this.zaehler = zaehler;
}
public double getZaehler() { return zaehler; }
}

View File

@ -0,0 +1,7 @@
{
"java.project.sourcePaths": ["src"],
"java.project.outputPath": "bin",
"java.project.referencedLibraries": [
"lib/**/*.jar"
]
}

View File

@ -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).

View File

@ -0,0 +1,18 @@
import java.util.HashMap;
import java.util.Map;
import java.time.LocalDate;
public class Geburtstagsverzeichnis {
public static void main(String[] args) {
Map<String, LocalDate> gv = new HashMap<>();
gv.put("Klaus",
LocalDate.of(1994, 12, 23));
gv.put("Erika",
LocalDate.of(1992, 5, 3));
System.out.println("Klaus' Geburtstag: " +
gv.get("Klaus").toString());
}
}

7
Maximum/.vscode/settings.json vendored 100644
View File

@ -0,0 +1,7 @@
{
"java.project.sourcePaths": ["src"],
"java.project.outputPath": "bin",
"java.project.referencedLibraries": [
"lib/**/*.jar"
]
}

18
Maximum/README.md 100644
View File

@ -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).

View File

@ -0,0 +1,15 @@
public class Maximum {
public static
<T extends Comparable<T>>
T max(T w1, T w2) {
if(w1.compareTo(w2) > 0)
return w1;
else
return w2;
}
public static void main(String args []) {
System.out.println("Max: " +
max(1.0, 2.0));
}
}

View File

@ -0,0 +1,7 @@
{
"java.project.sourcePaths": ["src"],
"java.project.outputPath": "bin",
"java.project.referencedLibraries": [
"lib/**/*.jar"
]
}

View File

@ -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).

View File

@ -0,0 +1,16 @@
class SwingException extends Exception {}
class CloseException extends Exception {}
class Door implements AutoCloseable {
public void swing() throws Exception {
System.out.println("The door is becoming unhinged!");
close();
throw new SwingException();
}
public void close() throws Exception {
System.out.println("The door is now closed.");
throw new CloseException();
}
}

View File

@ -0,0 +1,13 @@
public class SuppressedExceptionExample {
public static void main(String[] args) throws Exception {
try (Door door = new Door()) {
door.swing(); /* Throws the SwingException */
} catch (Exception e) {
System.out.println("Primary Exception: " + e.getClass());
if (e.getSuppressed().length > 0) {
System.out.print("Suppressed Exception: " + e.getSuppressed()[0]);
}
}
}
}

View File

@ -0,0 +1,7 @@
{
"java.project.sourcePaths": ["src"],
"java.project.outputPath": "bin",
"java.project.referencedLibraries": [
"lib/**/*.jar"
]
}

View File

@ -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).

View File

@ -0,0 +1,19 @@
public class VerketteteExceptions {
public static void eineMethode() {
try {
throw new Exception("Originale Exception");
}
catch(Exception ex) {
throw new RuntimeException(ex); // Exception verketten
}
}
public static void main(String [] args) {
try {
eineMethode();
} catch(Exception ex) {
System.console().printf(" %s\n", ex.getCause().toString());
}
}
}