forked from Labore/PR2-L
initial example files regarding i/o
parent
24564e4e6f
commit
1bd9bb761a
Binary file not shown.
|
@ -0,0 +1,7 @@
|
||||||
|
{
|
||||||
|
"java.project.sourcePaths": ["src"],
|
||||||
|
"java.project.outputPath": "bin",
|
||||||
|
"java.project.referencedLibraries": [
|
||||||
|
"lib/**/*.jar"
|
||||||
|
]
|
||||||
|
}
|
|
@ -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).
|
Binary file not shown.
Binary file not shown.
|
@ -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);
|
||||||
|
}
|
|
@ -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);
|
||||||
|
}
|
||||||
|
});
|
||||||
|
}
|
||||||
|
}
|
|
@ -0,0 +1,7 @@
|
||||||
|
{
|
||||||
|
"java.project.sourcePaths": ["src"],
|
||||||
|
"java.project.outputPath": "bin",
|
||||||
|
"java.project.referencedLibraries": [
|
||||||
|
"lib/**/*.jar"
|
||||||
|
]
|
||||||
|
}
|
|
@ -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).
|
|
@ -0,0 +1,14 @@
|
||||||
|
<?xml version="1.0" encoding="UTF-8"?>
|
||||||
|
<java version="22" class="java.beans.XMLDecoder">
|
||||||
|
<object class="Person">
|
||||||
|
<void property="alter">
|
||||||
|
<int>38</int>
|
||||||
|
</void>
|
||||||
|
<void property="name">
|
||||||
|
<string>Mustermann</string>
|
||||||
|
</void>
|
||||||
|
<void property="vorname">
|
||||||
|
<string>Harald</string>
|
||||||
|
</void>
|
||||||
|
</object>
|
||||||
|
</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();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
|
@ -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;
|
||||||
|
}
|
||||||
|
}
|
|
@ -0,0 +1,7 @@
|
||||||
|
{
|
||||||
|
"java.project.sourcePaths": ["src"],
|
||||||
|
"java.project.outputPath": "bin",
|
||||||
|
"java.project.referencedLibraries": [
|
||||||
|
"lib/**/*.jar"
|
||||||
|
]
|
||||||
|
}
|
|
@ -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).
|
|
@ -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");
|
||||||
|
}
|
||||||
|
}
|
|
@ -0,0 +1,7 @@
|
||||||
|
{
|
||||||
|
"java.project.sourcePaths": ["src"],
|
||||||
|
"java.project.outputPath": "bin",
|
||||||
|
"java.project.referencedLibraries": [
|
||||||
|
"lib/**/*.jar"
|
||||||
|
]
|
||||||
|
}
|
|
@ -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).
|
|
@ -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();
|
||||||
|
}
|
||||||
|
}
|
|
@ -0,0 +1,7 @@
|
||||||
|
{
|
||||||
|
"java.project.sourcePaths": ["src"],
|
||||||
|
"java.project.outputPath": "bin",
|
||||||
|
"java.project.referencedLibraries": [
|
||||||
|
"lib/**/*.jar"
|
||||||
|
]
|
||||||
|
}
|
|
@ -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).
|
|
@ -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();
|
||||||
|
}
|
||||||
|
}
|
Binary file not shown.
|
@ -0,0 +1,7 @@
|
||||||
|
{
|
||||||
|
"java.project.sourcePaths": ["src"],
|
||||||
|
"java.project.outputPath": "bin",
|
||||||
|
"java.project.referencedLibraries": [
|
||||||
|
"lib/**/*.jar"
|
||||||
|
]
|
||||||
|
}
|
|
@ -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).
|
|
@ -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);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
|
@ -0,0 +1,7 @@
|
||||||
|
{
|
||||||
|
"java.project.sourcePaths": ["src"],
|
||||||
|
"java.project.outputPath": "bin",
|
||||||
|
"java.project.referencedLibraries": [
|
||||||
|
"lib/**/*.jar"
|
||||||
|
]
|
||||||
|
}
|
|
@ -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).
|
|
@ -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);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
|
@ -0,0 +1,7 @@
|
||||||
|
{
|
||||||
|
"java.project.sourcePaths": ["src"],
|
||||||
|
"java.project.outputPath": "bin",
|
||||||
|
"java.project.referencedLibraries": [
|
||||||
|
"lib/**/*.jar"
|
||||||
|
]
|
||||||
|
}
|
|
@ -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).
|
|
@ -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);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
|
@ -0,0 +1,7 @@
|
||||||
|
{
|
||||||
|
"java.project.sourcePaths": ["src"],
|
||||||
|
"java.project.outputPath": "bin",
|
||||||
|
"java.project.referencedLibraries": [
|
||||||
|
"lib/**/*.jar"
|
||||||
|
]
|
||||||
|
}
|
|
@ -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).
|
|
@ -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);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
|
@ -0,0 +1,7 @@
|
||||||
|
{
|
||||||
|
"java.project.sourcePaths": ["src"],
|
||||||
|
"java.project.outputPath": "bin",
|
||||||
|
"java.project.referencedLibraries": [
|
||||||
|
"lib/**/*.jar"
|
||||||
|
]
|
||||||
|
}
|
|
@ -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).
|
|
@ -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());
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
|
@ -0,0 +1,7 @@
|
||||||
|
{
|
||||||
|
"java.project.sourcePaths": ["src"],
|
||||||
|
"java.project.outputPath": "bin",
|
||||||
|
"java.project.referencedLibraries": [
|
||||||
|
"lib/**/*.jar"
|
||||||
|
]
|
||||||
|
}
|
|
@ -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).
|
|
@ -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);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
|
@ -0,0 +1,2 @@
|
||||||
|
Erste Zeile Text
|
||||||
|
Zweite Zeile Text
|
|
@ -0,0 +1,7 @@
|
||||||
|
{
|
||||||
|
"java.project.sourcePaths": ["src"],
|
||||||
|
"java.project.outputPath": "bin",
|
||||||
|
"java.project.referencedLibraries": [
|
||||||
|
"lib/**/*.jar"
|
||||||
|
]
|
||||||
|
}
|
|
@ -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).
|
|
@ -0,0 +1,2 @@
|
||||||
|
200.32
|
||||||
|
55.43
|
|
@ -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);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
Loading…
Reference in New Issue