From 3774abd5aa83fb157ee5516d55865276fb6ff494 Mon Sep 17 00:00:00 2001 From: YamiDoesDev Date: Fri, 4 Nov 2022 17:13:00 +0100 Subject: [PATCH] updating docs --- docs/02_basics.md | 66 ++++++++++++----------- docs/04_introduction_to_objects.md | 20 +++++++ docs/05_types_of_objects.md | 87 +++++++++++++++--------------- 3 files changed, 99 insertions(+), 74 deletions(-) diff --git a/docs/02_basics.md b/docs/02_basics.md index 1d833ce..18611de 100644 --- a/docs/02_basics.md +++ b/docs/02_basics.md @@ -3,10 +3,10 @@ ## Table of Contents 1. [Nutzung der Konsole](#nutzung-der-konsole) 2. [Primitive Datentypen](#primitive-datentypen) -3. [Nicht Primitive Datentypen](#) -4. [Operatoren](#) -5. [Bedingungen](#) -6. [Schleifen](#) +3. [Nicht Primitive Datentypen](#nicht-primitive-datentypen) +4. [Operatoren](#operatoren) +5. [Bedingungen](#bedingungen) +6. [Schleifen](#schleifen) 7. [Exceptions](#exceptions) ## Nutzung der Konsole @@ -108,17 +108,18 @@ System.out.println("concatString: " + concatString); ``` Methoden der Standardbibliothek: -```java -myString.charAt(); // Returns the char value at the specified index. -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.equals(); // Compares this string to the specified object. -myString.toLowerCase(); // Converts all of the characters in this String to lower case. -myString.toUpperCase(); // Converts all of the characters in this String to upper case. -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. -``` + +| Methode | Beschreibung | +|------------------------|-------------------------------------------------------------------------------------------------------------------------| +| myString.charAt() | Returns the char value at the specified index. | +| 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.equals() | Compares this string to the specified object. | +| myString.toLowerCase() | Converts all of the characters in this String to lower case. | +| myString.toUpperCase() | Converts all of the characters in this String to upper case. | +| 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 @@ -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): -```java -myNumber.compareTo(); // Compares two Integer objects numerically. -myNumber.toString(); // Returns a String object representing this Integer's value. -myNumber.intValue(); // Returns the value of this Integer as an int. -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. -``` + +| Methode | Beschreibung | +|------------------------|---------------------------------------------------------------------------------------| +| myNumber.compareTo() | Compares two Integer objects numerically. | +| myNumber.toString() | Returns a String object representing this Integer's value. | +| myNumber.intValue() | Returns the value of this Integer as an int. | +| 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 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: -```java -Arrays.toString(myArray); // a string representation of the object. -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.equals(myArray, myArray); // Returns true if the two specified arrays of ints are equal to one another. -Arrays.sort(myArray); // Sorts the specified array into ascending numerical order -Arrays.fill(myArray, 0); // Assigns the specified int value to each element of the specified array of ints. -``` + +| Methode | Beschreibung | +|-----------------------------------|-------------------------------------------------------------------------------------------------------------------| +| Arrays.toString(Array a) | a string representation of the object. | +| 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.compare(Array a, Array b) | Compares two int arrays lexicographically. | +| 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 diff --git a/docs/04_introduction_to_objects.md b/docs/04_introduction_to_objects.md index 12a7fe8..046e9b6 100644 --- a/docs/04_introduction_to_objects.md +++ b/docs/04_introduction_to_objects.md @@ -27,6 +27,26 @@ int nbr = 5; 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 **Lernziele:** diff --git a/docs/05_types_of_objects.md b/docs/05_types_of_objects.md index 22e6896..a1567c6 100644 --- a/docs/05_types_of_objects.md +++ b/docs/05_types_of_objects.md @@ -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 // SaveState.java import java.security.InvalidParameterException; public class SaveState implements Comparable { - private T saveEntry; - private int saveID = 0; - private static int staticSaveID; +private T saveEntry; +private int saveID = 0; +private static int staticSaveID; // constructor SaveState(T saveEntry) throws InvalidParameterException { @@ -159,6 +119,47 @@ public class SaveState implements Comparable { } ``` +### 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 ```java