diff --git a/DemoAnonymeKlasse/.DS_Store b/DemoAnonymeKlasse/.DS_Store new file mode 100644 index 0000000..0635bac Binary files /dev/null and b/DemoAnonymeKlasse/.DS_Store differ diff --git a/DemoAnonymeKlasse/.vscode/settings.json b/DemoAnonymeKlasse/.vscode/settings.json new file mode 100644 index 0000000..0ac215c --- /dev/null +++ b/DemoAnonymeKlasse/.vscode/settings.json @@ -0,0 +1,7 @@ +{ + "java.project.sourcePaths": ["src"], + "java.project.outputPath": "bin", + "java.project.referencedLibraries": [ + "lib/**/*.jar" + ] +} diff --git a/DemoAnonymeKlasse/README.md b/DemoAnonymeKlasse/README.md new file mode 100644 index 0000000..a43b9f6 --- /dev/null +++ b/DemoAnonymeKlasse/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/DemoAnonymeKlasse/bin/.DS_Store b/DemoAnonymeKlasse/bin/.DS_Store new file mode 100644 index 0000000..9e263d7 Binary files /dev/null and b/DemoAnonymeKlasse/bin/.DS_Store differ diff --git a/DemoAnonymeKlasse/src/.DS_Store b/DemoAnonymeKlasse/src/.DS_Store new file mode 100644 index 0000000..9e263d7 Binary files /dev/null and b/DemoAnonymeKlasse/src/.DS_Store differ diff --git a/DemoAnonymeKlasse/src/BerechnungDouble.java b/DemoAnonymeKlasse/src/BerechnungDouble.java new file mode 100644 index 0000000..138520f --- /dev/null +++ b/DemoAnonymeKlasse/src/BerechnungDouble.java @@ -0,0 +1,8 @@ +/**Copyright (c) Balzert, H: "Java: Objektorientiert Programmieren" + * W3L-Verlag Dortmund, 3. Auflage, 2014 + * Demonstration einer anonymen Klasse, S. 236 +*/ + +public interface BerechnungDouble { + public double berechne(double wert); +} diff --git a/DemoAnonymeKlasse/src/DemoAnonymeKlasse.java b/DemoAnonymeKlasse/src/DemoAnonymeKlasse.java new file mode 100644 index 0000000..3364840 --- /dev/null +++ b/DemoAnonymeKlasse/src/DemoAnonymeKlasse.java @@ -0,0 +1,23 @@ +/**Copyright (c) Balzert, H: "Java: Objektorientiert Programmieren" + * W3L-Verlag Dortmund, 3. Auflage, 2014 + * Demonstration einer anonymen Klasse, S. 236 +*/ + +public class DemoAnonymeKlasse { + public static void druckeTabelle(BerechnungDouble methode) { + System.out.println("Wertetabelle"); + for(int x = 0; x <= 5; x++) + { + System.out.println(x + " - > " + methode.berechne(x)); + } + } + + public static void main(String[] args) { + druckeTabelle( + new BerechnungDouble() { + public double berechne(double wert) { + return Math.sqrt(wert); + } + }); + } +} diff --git a/DemoXMLSerialisierung/.vscode/settings.json b/DemoXMLSerialisierung/.vscode/settings.json new file mode 100644 index 0000000..0ac215c --- /dev/null +++ b/DemoXMLSerialisierung/.vscode/settings.json @@ -0,0 +1,7 @@ +{ + "java.project.sourcePaths": ["src"], + "java.project.outputPath": "bin", + "java.project.referencedLibraries": [ + "lib/**/*.jar" + ] +} diff --git a/DemoXMLSerialisierung/README.md b/DemoXMLSerialisierung/README.md new file mode 100644 index 0000000..a43b9f6 --- /dev/null +++ b/DemoXMLSerialisierung/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/DemoXMLSerialisierung/src/Beispiel.xml b/DemoXMLSerialisierung/src/Beispiel.xml new file mode 100644 index 0000000..c77f389 --- /dev/null +++ b/DemoXMLSerialisierung/src/Beispiel.xml @@ -0,0 +1,14 @@ + + + + + 38 + + + Mustermann + + + Harald + + + diff --git a/DemoXMLSerialisierung/src/DemoXMLSerialisierung.java b/DemoXMLSerialisierung/src/DemoXMLSerialisierung.java new file mode 100644 index 0000000..f0ab169 --- /dev/null +++ b/DemoXMLSerialisierung/src/DemoXMLSerialisierung.java @@ -0,0 +1,46 @@ +/**Copyright (c) Balzert, H: "Java: Objektorientiert Programmieren" + * W3L-Verlag Dortmund, 3. Auflage, 2014 + * XML-Serialisierung von Objekten, S. 273 f. +*/ + +import java.io.*; +import java.beans.*; + +public class DemoXMLSerialisierung { + + public static void main(String[] args) { + Person einePerson = + new Person("Mustermann", + "Harald", 38); + String filename = "DemoXMLSerialisierung/src/Beispiel.xml"; + + // Serialisieren + + try(XMLEncoder enc = + new XMLEncoder( + new FileOutputStream(filename))) + { + enc.writeObject(einePerson); + } + catch(IOException e) + { + e.printStackTrace(); + } + + // Deserialisieren + try(XMLDecoder dec = + new XMLDecoder( + new FileInputStream(filename))) + { + Person wiedereinePerson = + (Person) dec.readObject(); + System.out.println(wiedereinePerson.getName() + ", " + + wiedereinePerson.getVorname() + ", Alter: " + + wiedereinePerson.getAlter()); + } + catch(IOException e) + { + e.printStackTrace(); + } + } +} \ No newline at end of file diff --git a/DemoXMLSerialisierung/src/Person.java b/DemoXMLSerialisierung/src/Person.java new file mode 100644 index 0000000..510064d --- /dev/null +++ b/DemoXMLSerialisierung/src/Person.java @@ -0,0 +1,50 @@ +/**Copyright (c) Balzert, H: "Java: Objektorientiert Programmieren" + * W3L-Verlag Dortmund, 3. Auflage, 2014 + * XML-Serialisierung von Objekten, S. 272 f. +*/ + +public class Person { + private String name; + private String vorname; + private int alter; + + public Person() {} + + public Person(String name, + String vorname, int alter) + { + this.name = name; + this.vorname = vorname; + this.alter = alter; + } + + public String getName() + { + return name; + } + + public void setName(String name) + { + this.name = name; + } + + public String getVorname() + { + return vorname; + } + + public void setVorname(String vorname) + { + this.vorname = vorname; + } + + public int getAlter() + { + return alter; + } + + public void setAlter(int alter) + { + this.alter = alter; + } +} \ No newline at end of file diff --git a/Eingabe/.vscode/settings.json b/Eingabe/.vscode/settings.json new file mode 100644 index 0000000..0ac215c --- /dev/null +++ b/Eingabe/.vscode/settings.json @@ -0,0 +1,7 @@ +{ + "java.project.sourcePaths": ["src"], + "java.project.outputPath": "bin", + "java.project.referencedLibraries": [ + "lib/**/*.jar" + ] +} diff --git a/Eingabe/README.md b/Eingabe/README.md new file mode 100644 index 0000000..a43b9f6 --- /dev/null +++ b/Eingabe/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/Eingabe/src/Eingabe.java b/Eingabe/src/Eingabe.java new file mode 100644 index 0000000..323299a --- /dev/null +++ b/Eingabe/src/Eingabe.java @@ -0,0 +1,30 @@ +/**Copyright (c) Balzert, H: "Java: Objektorientiert Programmieren" + * W3L-Verlag Dortmund, 3. Auflage, 2014 + * Liest einen Text aus einer Textdatei, S. 251 f. +*/ + +import java.io.*; + +public class Eingabe { + public static void main(String [] args) { + String name; + int geburtsjahr; + + // Objekt für Konsole beschaffen + Console cons = System.console(); + + // Daten ausgaben und einlesen + cons.printf("\n"); + cons.printf(" Geben Sie Ihren vollständigen Namen ein: "); + name = cons.readLine(); + + cons.printf(" Geben Sie Ihr Geburtstagsjahr ein: "); + String eingabe = cons.readLine(); + geburtsjahr = Integer.parseInt(eingabe); + cons.printf("\n"); + + cons.printf(" %1$s, %2$d war ein sehr guter Jahrgang!", + name, geburtsjahr); + cons.printf("\n"); + } +} \ No newline at end of file diff --git a/Eingabe_BufferedReader/.vscode/settings.json b/Eingabe_BufferedReader/.vscode/settings.json new file mode 100644 index 0000000..0ac215c --- /dev/null +++ b/Eingabe_BufferedReader/.vscode/settings.json @@ -0,0 +1,7 @@ +{ + "java.project.sourcePaths": ["src"], + "java.project.outputPath": "bin", + "java.project.referencedLibraries": [ + "lib/**/*.jar" + ] +} diff --git a/Eingabe_BufferedReader/README.md b/Eingabe_BufferedReader/README.md new file mode 100644 index 0000000..a43b9f6 --- /dev/null +++ b/Eingabe_BufferedReader/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/Eingabe_BufferedReader/src/Eingabe_BufferedReader.java b/Eingabe_BufferedReader/src/Eingabe_BufferedReader.java new file mode 100644 index 0000000..27db70e --- /dev/null +++ b/Eingabe_BufferedReader/src/Eingabe_BufferedReader.java @@ -0,0 +1,17 @@ +import java.io.*; + +public class Eingabe_BufferedReader { + public static void main(String [] args) throws IOException { + int zahl; + + System.out.println(); + System.out.print(" Geben Sie einen Integer-Wert ein: "); + BufferedReader tastatur = + new BufferedReader(new InputStreamReader(System.in)); + String eingabe = tastatur.readLine(); + + zahl = Integer.parseInt(eingabe); + System.out.println(" " + zahl); + System.out.println(); + } +} \ No newline at end of file diff --git a/Eingabe_Scanner/.vscode/settings.json b/Eingabe_Scanner/.vscode/settings.json new file mode 100644 index 0000000..0ac215c --- /dev/null +++ b/Eingabe_Scanner/.vscode/settings.json @@ -0,0 +1,7 @@ +{ + "java.project.sourcePaths": ["src"], + "java.project.outputPath": "bin", + "java.project.referencedLibraries": [ + "lib/**/*.jar" + ] +} diff --git a/Eingabe_Scanner/README.md b/Eingabe_Scanner/README.md new file mode 100644 index 0000000..a43b9f6 --- /dev/null +++ b/Eingabe_Scanner/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/Eingabe_Scanner/src/Eingabe_Scanner.java b/Eingabe_Scanner/src/Eingabe_Scanner.java new file mode 100644 index 0000000..b493c17 --- /dev/null +++ b/Eingabe_Scanner/src/Eingabe_Scanner.java @@ -0,0 +1,17 @@ +import java.util.Scanner; + +public class Eingabe_Scanner { + public static void main(String [] args) { + + System.out.println(); + System.out.print(" Geben Sie einen Integer-Wert ein: "); + + Scanner sc = new Scanner(System.in); + int zahl = sc.nextInt(); + + sc.close(); + + System.out.println(" Sie haben " + zahl + " eingegeben"); + System.out.println(); + } +} \ No newline at end of file diff --git a/LeseDatei/.DS_Store b/LeseDatei/.DS_Store new file mode 100644 index 0000000..d4f135c Binary files /dev/null and b/LeseDatei/.DS_Store differ diff --git a/LeseDatei/.vscode/settings.json b/LeseDatei/.vscode/settings.json new file mode 100644 index 0000000..0ac215c --- /dev/null +++ b/LeseDatei/.vscode/settings.json @@ -0,0 +1,7 @@ +{ + "java.project.sourcePaths": ["src"], + "java.project.outputPath": "bin", + "java.project.referencedLibraries": [ + "lib/**/*.jar" + ] +} diff --git a/LeseDatei/README.md b/LeseDatei/README.md new file mode 100644 index 0000000..a43b9f6 --- /dev/null +++ b/LeseDatei/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/LeseDatei/src/LeseDatei.java b/LeseDatei/src/LeseDatei.java new file mode 100644 index 0000000..cd55ded --- /dev/null +++ b/LeseDatei/src/LeseDatei.java @@ -0,0 +1,40 @@ +/**Copyright (c) Balzert, H: "Java: Objektorientiert Programmieren" + * W3L-Verlag Dortmund, 3. Auflage, 2014 + * Liest einen Text aus einer Textdatei, S. 251 f. +*/ + +import java.io.*; + +class LeseDatei +{ + public static void main(String [] args) + { + FileReader eineEingabeDatei = null; + try { + eineEingabeDatei = + new FileReader("LeseDatei/src/LeseDatei.java"); + int c; + while((c = eineEingabeDatei.read()) + != -1) + System.out.print((char) c); + } + catch(IOException eineAusnahme) + { + System.out.println( + "Fehlermeldung: " + eineAusnahme); + } + finally // Schliessen der Datei + { + if(eineEingabeDatei != null) + try + { + eineEingabeDatei.close(); + } + catch(IOException eineAusnahme) + { + System.out.println("Fehlermeldung: " + + eineAusnahme); + } + } + } + } \ No newline at end of file diff --git a/LeseDatei2/.vscode/settings.json b/LeseDatei2/.vscode/settings.json new file mode 100644 index 0000000..0ac215c --- /dev/null +++ b/LeseDatei2/.vscode/settings.json @@ -0,0 +1,7 @@ +{ + "java.project.sourcePaths": ["src"], + "java.project.outputPath": "bin", + "java.project.referencedLibraries": [ + "lib/**/*.jar" + ] +} diff --git a/LeseDatei2/README.md b/LeseDatei2/README.md new file mode 100644 index 0000000..a43b9f6 --- /dev/null +++ b/LeseDatei2/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/LeseDatei2/src/LeseDatei2.java b/LeseDatei2/src/LeseDatei2.java new file mode 100644 index 0000000..35f131e --- /dev/null +++ b/LeseDatei2/src/LeseDatei2.java @@ -0,0 +1,26 @@ +/**Copyright (c) Balzert, H: "Java: Objektorientiert Programmieren" + * W3L-Verlag Dortmund, 3. Auflage, 2014 + * Liest einen Text aus einer Textdatei, S. 252 f. +*/ + +import java.io.FileReader; +import java.io.IOException; + +class LeseDatei2 +{ + public static void main(String args []) + { + try(FileReader eineEingabeDatei = + new FileReader("LeseDatei2/src/LeseDatei2.java")) + { + int c; + while((c = eineEingabeDatei.read()) != -1) + System.out.print((char) c); + } + catch(IOException eineAusnahme) + { + System.out.println("Fehlermeldung: " + + eineAusnahme); + } + } +} diff --git a/LeseDateiGepuffert/.vscode/settings.json b/LeseDateiGepuffert/.vscode/settings.json new file mode 100644 index 0000000..0ac215c --- /dev/null +++ b/LeseDateiGepuffert/.vscode/settings.json @@ -0,0 +1,7 @@ +{ + "java.project.sourcePaths": ["src"], + "java.project.outputPath": "bin", + "java.project.referencedLibraries": [ + "lib/**/*.jar" + ] +} diff --git a/LeseDateiGepuffert/README.md b/LeseDateiGepuffert/README.md new file mode 100644 index 0000000..a43b9f6 --- /dev/null +++ b/LeseDateiGepuffert/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/LeseDateiGepuffert/src/LeseDateiGepuffert.java b/LeseDateiGepuffert/src/LeseDateiGepuffert.java new file mode 100644 index 0000000..cf590e9 --- /dev/null +++ b/LeseDateiGepuffert/src/LeseDateiGepuffert.java @@ -0,0 +1,29 @@ +/**Copyright (c) Balzert, H: "Java: Objektorientiert Programmieren" + * W3L-Verlag Dortmund, 3. Auflage, 2014 + * Liest einen Text aus einer Textdatei gepuffert, S. 253 f. +*/ + +import java.io.*; + +class LeseDateiGepuffert +{ + public static void main(String [] args) + { + try (BufferedReader eineEingabeDatei = + new BufferedReader(new FileReader( + "LeseDateiGepuffert/src/LeseDateiGepuffert.java"))){ + + String zeile = eineEingabeDatei.readLine(); + + while(zeile != null) { + System.out.println(zeile); + zeile = eineEingabeDatei.readLine(); + } + } + catch(IOException eineAusnahme) + { + System.out.println("Fehlermeldung: " + + eineAusnahme); + } + } +} \ No newline at end of file diff --git a/LeseDateiMitZeilennr/.vscode/settings.json b/LeseDateiMitZeilennr/.vscode/settings.json new file mode 100644 index 0000000..0ac215c --- /dev/null +++ b/LeseDateiMitZeilennr/.vscode/settings.json @@ -0,0 +1,7 @@ +{ + "java.project.sourcePaths": ["src"], + "java.project.outputPath": "bin", + "java.project.referencedLibraries": [ + "lib/**/*.jar" + ] +} diff --git a/LeseDateiMitZeilennr/README.md b/LeseDateiMitZeilennr/README.md new file mode 100644 index 0000000..a43b9f6 --- /dev/null +++ b/LeseDateiMitZeilennr/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/LeseDateiMitZeilennr/src/LeseDateiMitZeilennr.java b/LeseDateiMitZeilennr/src/LeseDateiMitZeilennr.java new file mode 100644 index 0000000..1e063f9 --- /dev/null +++ b/LeseDateiMitZeilennr/src/LeseDateiMitZeilennr.java @@ -0,0 +1,26 @@ +/**Copyright (c) Balzert, H: "Java: Objektorientiert Programmieren" + * W3L-Verlag Dortmund, 3. Auflage, 2014 + * Beispiel für eine Dateiausgabe mit Zeilennummern ab 100, S. 255 +*/ + +import java.io.*; + +class LeseDateiMitZeilennr +{ + public static void main(String [] args) + { + try (LineNumberReader eineEingabeDatei = new LineNumberReader(new FileReader("LeseDateiMitZeilennr/src/LeseDateiMitZeilennr.java"))){ + String zeile = eineEingabeDatei.readLine(); + eineEingabeDatei.setLineNumber(100); + + while(zeile != null) { + System.out.println(eineEingabeDatei.getLineNumber() + ": " + zeile); + zeile = eineEingabeDatei.readLine(); + } + } + catch(IOException eineAusnahme) + { + System.out.println("Fehlermeldung: " + eineAusnahme); + } + } +} \ No newline at end of file diff --git a/Roemisch/.vscode/settings.json b/Roemisch/.vscode/settings.json new file mode 100644 index 0000000..0ac215c --- /dev/null +++ b/Roemisch/.vscode/settings.json @@ -0,0 +1,7 @@ +{ + "java.project.sourcePaths": ["src"], + "java.project.outputPath": "bin", + "java.project.referencedLibraries": [ + "lib/**/*.jar" + ] +} diff --git a/Roemisch/README.md b/Roemisch/README.md new file mode 100644 index 0000000..a43b9f6 --- /dev/null +++ b/Roemisch/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/Roemisch/src/Roemisch.java b/Roemisch/src/Roemisch.java new file mode 100644 index 0000000..3f8ce1d --- /dev/null +++ b/Roemisch/src/Roemisch.java @@ -0,0 +1,24 @@ +/**Copyright (c) Balzert, H: "Java: Objektorientiert Programmieren" + * W3L-Verlag Dortmund, 3. Auflage, 2014 + * Beispiel für Aufzählungen mit Attributen, S. 238 +*/ + +public class Roemisch { + public enum Roman { + I(1), V(5), X(20), L(50), C(100), + D(500), M(1000); + private final int wert; + + Roman(int wert) { + this.wert = wert; } + + public int getWert() { + return wert; } + } + public static void main(String [] args) { + for(Roman r : Roman.values()) { + System.out.println(r.getWert() + + "\t" + r.ordinal()); + } + } +} diff --git a/SchreibeDatei/.vscode/settings.json b/SchreibeDatei/.vscode/settings.json new file mode 100644 index 0000000..0ac215c --- /dev/null +++ b/SchreibeDatei/.vscode/settings.json @@ -0,0 +1,7 @@ +{ + "java.project.sourcePaths": ["src"], + "java.project.outputPath": "bin", + "java.project.referencedLibraries": [ + "lib/**/*.jar" + ] +} diff --git a/SchreibeDatei/README.md b/SchreibeDatei/README.md new file mode 100644 index 0000000..a43b9f6 --- /dev/null +++ b/SchreibeDatei/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/SchreibeDatei/src/SchreibeDatei.java b/SchreibeDatei/src/SchreibeDatei.java new file mode 100644 index 0000000..5de4cff --- /dev/null +++ b/SchreibeDatei/src/SchreibeDatei.java @@ -0,0 +1,26 @@ +/**Copyright (c) Balzert, H: "Java: Objektorientiert Programmieren" + * W3L-Verlag Dortmund, 3. Auflage, 2014 + * Schreibt einen Text in eine Textdatei, S. 256 f. +*/ + +import java.io.*; + +class SchreibeDatei +{ + public static void main(String [] args) + { + try (FileWriter eineAusgabeDatei = + new FileWriter("SchreibeDatei/src/Schreibedatei.txt")){ + + eineAusgabeDatei + .write("Erste Zeile Text\n"); + eineAusgabeDatei + .write("Zweite Zeile Text\n"); + } + catch(IOException eineAusnahme) + { + System.out.println("Fehlermeldung: " + + eineAusnahme); + } + } +} \ No newline at end of file diff --git a/SchreibeDatei/src/Schreibedatei.txt b/SchreibeDatei/src/Schreibedatei.txt new file mode 100644 index 0000000..0114fed --- /dev/null +++ b/SchreibeDatei/src/Schreibedatei.txt @@ -0,0 +1,2 @@ +Erste Zeile Text +Zweite Zeile Text diff --git a/SchreibeDateiMitPrintWriter/.vscode/settings.json b/SchreibeDateiMitPrintWriter/.vscode/settings.json new file mode 100644 index 0000000..0ac215c --- /dev/null +++ b/SchreibeDateiMitPrintWriter/.vscode/settings.json @@ -0,0 +1,7 @@ +{ + "java.project.sourcePaths": ["src"], + "java.project.outputPath": "bin", + "java.project.referencedLibraries": [ + "lib/**/*.jar" + ] +} diff --git a/SchreibeDateiMitPrintWriter/README.md b/SchreibeDateiMitPrintWriter/README.md new file mode 100644 index 0000000..a43b9f6 --- /dev/null +++ b/SchreibeDateiMitPrintWriter/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/SchreibeDateiMitPrintWriter/src/MesswerteDatei.txt b/SchreibeDateiMitPrintWriter/src/MesswerteDatei.txt new file mode 100644 index 0000000..9f9b02c --- /dev/null +++ b/SchreibeDateiMitPrintWriter/src/MesswerteDatei.txt @@ -0,0 +1,2 @@ +200.32 +55.43 diff --git a/SchreibeDateiMitPrintWriter/src/SchreibeDateiMitPrintWriter.java b/SchreibeDateiMitPrintWriter/src/SchreibeDateiMitPrintWriter.java new file mode 100644 index 0000000..4f98674 --- /dev/null +++ b/SchreibeDateiMitPrintWriter/src/SchreibeDateiMitPrintWriter.java @@ -0,0 +1,23 @@ +/**Copyright (c) Balzert, H: "Java: Objektorientiert Programmieren" + * W3L-Verlag Dortmund, 3. Auflage, 2014 + * Schreibt double-Literale in eine Textdatei, S. 257 f. +*/ + +import java.io.*; + +class SchreibeDateiMitPrintWriter +{ + public static void main(String [] args) + { + try (PrintWriter eineAusgabeDatei = + new PrintWriter("SchreibeDateiMitPrintWriter/src/MesswerteDatei.txt")){ + eineAusgabeDatei.println(200.32); + eineAusgabeDatei.println(55.43); + } + catch(IOException eineAusnahme) + { + System.out.println("Fehlermeldung: " + + eineAusnahme); + } + } +} \ No newline at end of file