updating docs

This commit is contained in:
YamiDoesDev 2022-11-04 17:13:00 +01:00
parent 48765d2c69
commit 3774abd5aa
3 changed files with 99 additions and 74 deletions

View File

@ -3,10 +3,10 @@
## Table of Contents ## Table of Contents
1. [Nutzung der Konsole](#nutzung-der-konsole) 1. [Nutzung der Konsole](#nutzung-der-konsole)
2. [Primitive Datentypen](#primitive-datentypen) 2. [Primitive Datentypen](#primitive-datentypen)
3. [Nicht Primitive Datentypen](#) 3. [Nicht Primitive Datentypen](#nicht-primitive-datentypen)
4. [Operatoren](#) 4. [Operatoren](#operatoren)
5. [Bedingungen](#) 5. [Bedingungen](#bedingungen)
6. [Schleifen](#) 6. [Schleifen](#schleifen)
7. [Exceptions](#exceptions) 7. [Exceptions](#exceptions)
## Nutzung der Konsole ## Nutzung der Konsole
@ -108,17 +108,18 @@ System.out.println("concatString: " + concatString);
``` ```
Methoden der Standardbibliothek: Methoden der Standardbibliothek:
```java
myString.charAt(); // Returns the char value at the specified index. | Methode | Beschreibung |
myString.indexOf(); // Returns the index within this string of the first occurrence of the specified substring. |------------------------|-------------------------------------------------------------------------------------------------------------------------|
myString.substring(); // Returns a string that is a substring of this string. | myString.charAt() | Returns the char value at the specified index. |
myString.equals(); // Compares this string to the specified object. | myString.indexOf() | Returns the index within this string of the first occurrence of the specified substring. |
myString.toLowerCase(); // Converts all of the characters in this String to lower case. | myString.substring() | Returns a string that is a substring of this string. |
myString.toUpperCase(); // Converts all of the characters in this String to upper case. | myString.equals() | Compares this string to the specified object. |
myString.contains(); // Returns true if and only if this string contains the specified sequence of char values. | myString.toLowerCase() | Converts all of the characters in this String to lower case. |
myString.replaceAll(); // Replaces each substring of this string that matches the given regular expression with the given replacement. | myString.toUpperCase() | Converts all of the characters in this String to upper case. |
myString.compareTo(); // Compares two strings lexicographically. The comparison is based on the Unicode value of each character in the strings. | myString.contains() | Returns true if and only if this string contains the specified sequence of char values. |
``` | myString.replaceAll() | Replaces each substring of this string that matches the given regular expression with the given replacement. |
| myString.compareTo() | Compares two strings lexicographically. The comparison is based on the Unicode value of each character in the strings. |
### Numeric Datatypes ### Numeric Datatypes
@ -144,14 +145,16 @@ myFloat.isNaN(); // Returns true if this Float value is a Not-a-Number (NaN), fa
``` ```
Funktionen für alle Numerischen Datentypen (Nicht Primitiv): Funktionen für alle Numerischen Datentypen (Nicht Primitiv):
```java
myNumber.compareTo(); // Compares two Integer objects numerically. | Methode | Beschreibung |
myNumber.toString(); // Returns a String object representing this Integer's value. |------------------------|---------------------------------------------------------------------------------------|
myNumber.intValue(); // Returns the value of this Integer as an int. | myNumber.compareTo() | Compares two Integer objects numerically. |
myNumber.floatValue(); // Returns the value of this Integer as a float after a widening primitive conversion. | myNumber.toString() | Returns a String object representing this Integer's value. |
myNumber.doubleValue(); // Returns the value of this Integer as a double after a widening primitive conversion. | myNumber.intValue() | Returns the value of this Integer as an int. |
myNumber.shortValue(); // Returns the value of this Integer as a short after a narrowing primitive conversion. | myNumber.floatValue() | Returns the value of this Integer as a float after a widening primitive conversion. |
``` | myNumber.doubleValue() | Returns the value of this Integer as a double after a widening primitive conversion. |
| myNumber.shortValue() | Returns the value of this Integer as a short after a narrowing primitive conversion. |
### Arrays ### Arrays
Bei Arrays handelt es sich um Schleifen eines bestimmten Datentypen. Sie werden Bei Arrays handelt es sich um Schleifen eines bestimmten Datentypen. Sie werden
@ -194,14 +197,15 @@ for(int row = 0; row < my2DArray.length; row++) {
``` ```
Methoden: Methoden:
```java
Arrays.toString(myArray); // a string representation of the object. | Methode | Beschreibung |
Arrays.copyOf(myArray, 3); // Copies the specified array, truncating or padding with zeros (if necessary) so the copy has the specified length. |-----------------------------------|-------------------------------------------------------------------------------------------------------------------|
Arrays.compare(myArray, myArray); // Compares two int arrays lexicographically. | Arrays.toString(Array a) | a string representation of the object. |
Arrays.equals(myArray, myArray); // Returns true if the two specified arrays of ints are equal to one another. | Arrays.copyOf(Array a, int index) | Copies the specified array, truncating or padding with zeros (if necessary) so the copy has the specified length. |
Arrays.sort(myArray); // Sorts the specified array into ascending numerical order | Arrays.compare(Array a, Array b) | Compares two int arrays lexicographically. |
Arrays.fill(myArray, 0); // Assigns the specified int value to each element of the specified array of ints. | Arrays.equals(Array a, Array b) | Returns true if the two specified arrays of ints are equal to one another. |
``` | Arrays.sort(Array a) | Sorts the specified array into ascending numerical order |
| Arrays.fill(Array a, int number) | Assigns the specified int value to each element of the specified array of ints. |
## Operatoren ## Operatoren

View File

@ -27,6 +27,26 @@ int nbr = 5;
String name = new String("Thomas"); String name = new String("Thomas");
``` ```
## Modifier
Quelle: [w3schools.com](https://www.w3schools.com/java/java_modifiers.asp)
### Access-Modifier
| Modifier | Beschreibung |
|-----------|--------------------------------------------------------------------------------------------------|
| public | The code is accessible for all classes |
| private | The code is only accessible within the declared class |
| protected | The code is accessible in the same package and subclasses. |
| default | The code is only accessible in the same package. This is used when you don't specify a modifier. |
### Non-Access-Modifier
| Modifier | Beschreibung |
|----------|-------------------------------------------------------------------------------------------------------------------|
| final | The class cannot be inherited by other classes |
| abstract | The class cannot be used to create objects (To access an abstract class, it must be inherited from another class. |
## #1 Einfache Objekte und Veerbung ## #1 Einfache Objekte und Veerbung
**Lernziele:** **Lernziele:**

View File

@ -65,55 +65,15 @@ public class Main /*extends Language implements Regex*/ {
} }
``` ```
### Abstract and Interface
```java
// Regex.java
public interface Regex {
public String concatStrings(String left, String right);
}
```
```java
// Main.java
abstract class Language {
public void showLanguage() {
System.out.println("This text is presented to you by Java");
}
public abstract void sayHelloWorld();
}
// Main.java
public class Main extends Language implements Regex {
public static void main(String[] args) {
// Language myLanguage = new Language();
// 'Language' is abstract; cannot be instantiated
Main myObject = new Main();
myObject.sayHelloWorld();
String wortwitz = myObject.concatStrings("du", "schlampe");
System.out.println(wortwitz); // duschlampe
}
@Override
public void sayHelloWorld() {
System.out.println("I refuse to say that!");
}
@Override
public String concatStrings(String left, String right) {
return left + right;
}
}
```
```java ```java
// SaveState.java // SaveState.java
import java.security.InvalidParameterException; import java.security.InvalidParameterException;
public class SaveState<T> implements Comparable<SaveState> { public class SaveState<T> implements Comparable<SaveState> {
private T saveEntry; private T saveEntry;
private int saveID = 0; private int saveID = 0;
private static int staticSaveID; private static int staticSaveID;
// constructor // constructor
SaveState(T saveEntry) throws InvalidParameterException { SaveState(T saveEntry) throws InvalidParameterException {
@ -159,6 +119,47 @@ public class SaveState<T> implements Comparable<SaveState> {
} }
``` ```
### Abstract and Interface
```java
// Regex.java
public interface Regex {
public String concatStrings(String left, String right);
}
```
```java
// Main.java
abstract class Language {
public void showLanguage() {
System.out.println("This text is presented to you by Java");
}
public abstract void sayHelloWorld();
}
// Main.java
public class Main extends Language implements Regex {
public static void main(String[] args) {
// Language myLanguage = new Language();
// 'Language' is abstract; cannot be instantiated
Main myObject = new Main();
myObject.sayHelloWorld();
String wortwitz = myObject.concatStrings("du", "schlampe");
System.out.println(wortwitz); // duschlampe
}
@Override
public void sayHelloWorld() {
System.out.println("I refuse to say that!");
}
@Override
public String concatStrings(String left, String right) {
return left + right;
}
}
```
## Collections ## Collections
```java ```java