From 8445b7d11b29b870815c3cef137391faac9afca5 Mon Sep 17 00:00:00 2001 From: Stefan Suhren Date: Wed, 15 Oct 2014 15:02:26 +0200 Subject: First commit of my Java1 work. --- .classpath | 6 ++ .gitignore | 1 + .project | 23 ++++ .settings/org.eclipse.jdt.core.prefs | 11 ++ misc/Blatt2.txt | 73 +++++++++++++ misc/Blatt3.txt | 41 ++++++++ misc/Blatt4.txt | 9 ++ src/de/fhswf/in/inf/java1/aufgabe1/HelloWorld.java | 45 ++++++++ src/de/fhswf/in/inf/java1/aufgabe4/Fill.java | 117 +++++++++++++++++++++ src/de/fhswf/in/inf/java1/tests/Tests.java | 31 ++++++ 10 files changed, 357 insertions(+) create mode 100644 .classpath create mode 100644 .gitignore create mode 100644 .project create mode 100644 .settings/org.eclipse.jdt.core.prefs create mode 100644 misc/Blatt2.txt create mode 100644 misc/Blatt3.txt create mode 100644 misc/Blatt4.txt create mode 100644 src/de/fhswf/in/inf/java1/aufgabe1/HelloWorld.java create mode 100644 src/de/fhswf/in/inf/java1/aufgabe4/Fill.java create mode 100644 src/de/fhswf/in/inf/java1/tests/Tests.java diff --git a/.classpath b/.classpath new file mode 100644 index 0000000..63b7e89 --- /dev/null +++ b/.classpath @@ -0,0 +1,6 @@ + + + + + + diff --git a/.gitignore b/.gitignore new file mode 100644 index 0000000..ae3c172 --- /dev/null +++ b/.gitignore @@ -0,0 +1 @@ +/bin/ diff --git a/.project b/.project new file mode 100644 index 0000000..58ee56f --- /dev/null +++ b/.project @@ -0,0 +1,23 @@ + + + java1 + + + + + + org.eclipse.jdt.core.javabuilder + + + + + net.sf.eclipsecs.core.CheckstyleBuilder + + + + + + org.eclipse.jdt.core.javanature + net.sf.eclipsecs.core.CheckstyleNature + + diff --git a/.settings/org.eclipse.jdt.core.prefs b/.settings/org.eclipse.jdt.core.prefs new file mode 100644 index 0000000..bb35fa0 --- /dev/null +++ b/.settings/org.eclipse.jdt.core.prefs @@ -0,0 +1,11 @@ +eclipse.preferences.version=1 +org.eclipse.jdt.core.compiler.codegen.inlineJsrBytecode=enabled +org.eclipse.jdt.core.compiler.codegen.targetPlatform=1.8 +org.eclipse.jdt.core.compiler.codegen.unusedLocal=preserve +org.eclipse.jdt.core.compiler.compliance=1.8 +org.eclipse.jdt.core.compiler.debug.lineNumber=generate +org.eclipse.jdt.core.compiler.debug.localVariable=generate +org.eclipse.jdt.core.compiler.debug.sourceFile=generate +org.eclipse.jdt.core.compiler.problem.assertIdentifier=error +org.eclipse.jdt.core.compiler.problem.enumIdentifier=error +org.eclipse.jdt.core.compiler.source=1.8 diff --git a/misc/Blatt2.txt b/misc/Blatt2.txt new file mode 100644 index 0000000..533d4d2 --- /dev/null +++ b/misc/Blatt2.txt @@ -0,0 +1,73 @@ +// Aufgabe1 + +while(Bedingung1){ + if(!Bedingung2){ + Anweisung; + } +} + +// Aufgabe2 + +while(Bedingung){ + Anweisung1; + Anweisung2; +} + +// Aufgabe3 + + B1 B2 B3 +A1 1 1 1 + +A2 0 1 1 + +A3 0 1 0 + +if(Bedingung2){ + if(Bedingung3){ + if(Bedingung1){ + Anweisung1; + }else{ + Anweisung2; + } + } + else{ + if(!Bedingung1){ + Anweisung3; + } + } + +------------------------------------------------- + + if(Bedingung1){ + if(Bedingung3){ + Anweisung1; + } + } + else{ + if(Bedingung3){ + Anweisung2; + } + else{ + Anweisung3; + } + } +} + +// Aufgabe4 + +{ + if(Bedingung1){ + Anweisung1; + } + else if(Bedingung2){ + Anweisung2; + } + else if(Bedingung3){ + Anweisung3; + } + else{ + Anweisung1; + } + } + } +} \ No newline at end of file diff --git a/misc/Blatt3.txt b/misc/Blatt3.txt new file mode 100644 index 0000000..f40f5f9 --- /dev/null +++ b/misc/Blatt3.txt @@ -0,0 +1,41 @@ +//Aufgabe 1 + +a) true, Währungssymbol am Anfang, dann nur UTF-16 Buchstaben +b) true, Unterstriche am Anfang, Zahl nach Anfang erlaubt +c) false, Minus ist nicht erlaubtes Zeichen +d) false, Zahl nicht am Anfang +e) false, Reserviertes Schlüsselwort +f) true, da erster Buchstabe groß und Case-Sensitive + +//Aufgabe 2 + +d), 1.0/0.0 ist +infinity, in (int) konvertiert = INT_MAX + +//Aufgabe 3 + +a) true, -1 = 11111.. ~-1 = 0, 1111...^^11111... ist 0, 0=0 +b) true, deMorgansche Regel, doppelte Invertierung entfällt +c) false, da ! höherwertig als < ist, wird !int gemacht +d) false, da 11111... bitverschoben ohne Vorzeichen = 01111... und somit MAX_VALUE +e) + 1000 + &0011 + ----- + =0000 + + true, da 0 % nicht 0 = 0 +f) + 1000 + |0011 + ----- + =1011 + + false, da % 0 = Division durch Null ist + + +//Aufgabe 4 +a) true, da j Integer und j.toString() = 1 ist +b) false, Referenzen nicht gleich +c) true, Werte von Integer gleich +d) false, da Integer in int verwandelt wird +e) false, 1 String.equals(1 String) ist true \ No newline at end of file diff --git a/misc/Blatt4.txt b/misc/Blatt4.txt new file mode 100644 index 0000000..fa9aecf --- /dev/null +++ b/misc/Blatt4.txt @@ -0,0 +1,9 @@ +String ist am langsamsten, da bei jedem Schleifendurchlauf ein neuer String gebaut wird, +welche den vorherigen String und das neue Zeichen c aufnimmt. + +Stringbuilder ist am zweit schnellsten, da es nur einmal Initialisiert werden muss. +Am längsten dauert dann die Konvertierung vom StringBuilder zu String. + +Array ist am schnellsten, da es wie StringBuilder nicht neu instanziiert werden muss, +da wir aber auf eine Schleife verzichten, wird nur ein Funktionsaufruf erledigt, welcher noch +im Maschinen Code optimiert werden kann. \ No newline at end of file diff --git a/src/de/fhswf/in/inf/java1/aufgabe1/HelloWorld.java b/src/de/fhswf/in/inf/java1/aufgabe1/HelloWorld.java new file mode 100644 index 0000000..b80b714 --- /dev/null +++ b/src/de/fhswf/in/inf/java1/aufgabe1/HelloWorld.java @@ -0,0 +1,45 @@ +/** + * + */ +package de.fhswf.in.inf.java1.aufgabe1; + +/** + * Begrüßung der Sprache Java. Diese Klasse begrüßt die Sprache Java mit einem + * traditionellen "Hello World!". + * + * @author $Author: $ + * @version $Revision: $, $Date: $ UTC + */ +public final class HelloWorld +{ + private HelloWorld() + { + + } + + /** + * Hauptmethode der Application. Begrüßung der Sprache Java. Diese Klasse + * begrüßt die Sprache Java mit einem traditionellen "Hello World!". + * + * @param args + * Übergabeparameter des Programms. + */ + public static void main(String[] args) + { + System.out.println("Anzahl der Argumente: " + args.length); + if (args.length != 0) + { + System.out.print("Ihr Name ist:"); + for (int i = 0; i < args.length; i++) + { + System.out.print(" " + args[i]); + } + System.out.println("."); + } + else + { + System.out.print("Kein Name vorhanden."); + } + } + +} diff --git a/src/de/fhswf/in/inf/java1/aufgabe4/Fill.java b/src/de/fhswf/in/inf/java1/aufgabe4/Fill.java new file mode 100644 index 0000000..20fdd84 --- /dev/null +++ b/src/de/fhswf/in/inf/java1/aufgabe4/Fill.java @@ -0,0 +1,117 @@ +/** + * + */ +package de.fhswf.in.inf.java1.aufgabe4; + +import java.util.Arrays; + +/** + * Tests the different methods to created a prefilled String. + * + * @author $Author: $ + * @version $Revision: $, $Date: $ UTC + */ +public final class Fill +{ + private Fill() + { + } + + /** + * + * Creates a string of given length filled with the given char. + * + * @param length + * Length of the returned String. + * @param c + * Char the String is filled with. + * @return Returns the generated String. + */ + public static String createStringFilledWith(int length, char c) + { + // String that will be returned + String result = ""; + for (int i = 0; i < length; i++) + { + // Every iteration, a new string is created. + result += c; + } + // Return the build string + return result; + } + + /** + * + * Creates a string of given length filled with the given char. + * + * @param length + * Length of the returned String. + * @param c + * Char the String is filled with. + * @return Returns the generated String. + */ + public static String createStringFilledWith2(int length, char c) + { + // charArray that will be returned + char[] result = new char[length]; + + Arrays.fill(result, c); + + // Return the build string + return result.toString(); + } + + /** + * + * Creates a string of given length filled with the given char. + * + * @param length + * Length of the returned String. + * @param c + * Char the String is filled with. + * @return Returns the generated String. + */ + public static String createStringFilledWith3(int length, char c) + { + // String that will be returned + StringBuilder result = new StringBuilder(length); + for (int i = 0; i < length; i++) + { + // Every iteration, a new string is created. + result.append(c); + } + // Return the build string + return result.toString(); + } + + /** + * + * Calls the function createStringFilledWith() and measures its runtime. + * + * @param args + * Console line arguments. + */ + public static void main(String[] args) + { + final int anzDurchlaefe = 100000000; + + long start; + start = System.currentTimeMillis(); // Gets current time in µs + Fill.createStringFilledWith(anzDurchlaefe, 'x'); // Function call + // Calculates the time runtime of creatStringFilledWith() + System.out.println("Elapsed time: " + + (System.currentTimeMillis() - start) + " ms"); + + start = System.currentTimeMillis(); // Gets current time in µs + Fill.createStringFilledWith2(anzDurchlaefe, 'x'); // Function call + // Calculates the time runtime of creatStringFilledWith2() + System.out.println("Elapsed time: " + + (System.currentTimeMillis() - start) + " ms"); + + start = System.currentTimeMillis(); // Gets current time in µs + Fill.createStringFilledWith3(anzDurchlaefe, 'x'); // Function call + // Calculates the time runtime of creatStringFilledWith3() + System.out.println("Elapsed time: " + + (System.currentTimeMillis() - start) + " ms"); + } +} diff --git a/src/de/fhswf/in/inf/java1/tests/Tests.java b/src/de/fhswf/in/inf/java1/tests/Tests.java new file mode 100644 index 0000000..ddf711e --- /dev/null +++ b/src/de/fhswf/in/inf/java1/tests/Tests.java @@ -0,0 +1,31 @@ +package de.fhswf.in.inf.java1.tests; +/** + * + * Test-Klasse für kleine Java-Snippets. + * + * @author $Author: $ + * @version $Revision: $, $Date: $ UTC + */ +public final class Tests +{ + private Tests() + { + + } + + /** + * + * Haupt-Methode zum Testen von Java-Snippets. + * + * @param args + * Übergebene Argumente + */ + public static void main(String[] args) + { + int a = -1; + System.out.println(Integer.toBinaryString(a)); + System.out.println(Integer.toBinaryString(a >>> 1)); + + } + +} -- cgit v1.2.3-70-g09d2