From f36f1ec8c277ad09571cc9ac46b3820b7156209f Mon Sep 17 00:00:00 2001 From: Fabio Scotto di Santolo Date: Wed, 31 Jan 2018 11:46:59 +0100 Subject: [PATCH] initial commit --- .classpath | 10 + .project | 17 + .settings/org.eclipse.jdt.core.prefs | 11 + src/it/oracle/associate/java8/A.java | 35 ++ src/it/oracle/associate/java8/Animal.java | 42 ++ src/it/oracle/associate/java8/B.java | 34 ++ src/it/oracle/associate/java8/Counter.java | 43 ++ src/it/oracle/associate/java8/Dog.java | 40 ++ src/it/oracle/associate/java8/Exam1.java | 371 ++++++++++++++++++ src/it/oracle/associate/java8/Exam2.java | 122 ++++++ src/it/oracle/associate/java8/Guest.java | 38 ++ src/it/oracle/associate/java8/I1.java | 40 ++ src/it/oracle/associate/java8/Point.java | 45 +++ src/it/oracle/associate/java8/Student.java | 45 +++ .../oracle/associate/java8/test/Airplane.java | 20 + .../associate/java8/test/ArrayTest.java | 119 ++++++ src/it/oracle/associate/java8/test/B.java | 44 +++ .../associate/java8/test/BaseClass.java | 14 + .../oracle/associate/java8/test/DateTest.java | 57 +++ .../associate/java8/test/DerivatedClass.java | 9 + .../associate/java8/test/Greetings.java | 23 ++ .../associate/java8/test/InitOrder.java | 19 + .../associate/java8/test/NewsPaper.java | 9 + src/it/oracle/associate/java8/test/Paper.java | 9 + .../oracle/associate/java8/test/Penguin.java | 9 + .../associate/java8/test/Printable.java | 9 + src/it/oracle/associate/java8/test/Test.java | 9 + src/it/oracle/associate/java8/test/Toy.java | 12 + 28 files changed, 1255 insertions(+) create mode 100644 .classpath create mode 100644 .project create mode 100644 .settings/org.eclipse.jdt.core.prefs create mode 100644 src/it/oracle/associate/java8/A.java create mode 100644 src/it/oracle/associate/java8/Animal.java create mode 100644 src/it/oracle/associate/java8/B.java create mode 100644 src/it/oracle/associate/java8/Counter.java create mode 100644 src/it/oracle/associate/java8/Dog.java create mode 100644 src/it/oracle/associate/java8/Exam1.java create mode 100644 src/it/oracle/associate/java8/Exam2.java create mode 100644 src/it/oracle/associate/java8/Guest.java create mode 100644 src/it/oracle/associate/java8/I1.java create mode 100644 src/it/oracle/associate/java8/Point.java create mode 100644 src/it/oracle/associate/java8/Student.java create mode 100644 src/it/oracle/associate/java8/test/Airplane.java create mode 100644 src/it/oracle/associate/java8/test/ArrayTest.java create mode 100644 src/it/oracle/associate/java8/test/B.java create mode 100644 src/it/oracle/associate/java8/test/BaseClass.java create mode 100644 src/it/oracle/associate/java8/test/DateTest.java create mode 100644 src/it/oracle/associate/java8/test/DerivatedClass.java create mode 100644 src/it/oracle/associate/java8/test/Greetings.java create mode 100644 src/it/oracle/associate/java8/test/InitOrder.java create mode 100644 src/it/oracle/associate/java8/test/NewsPaper.java create mode 100644 src/it/oracle/associate/java8/test/Paper.java create mode 100644 src/it/oracle/associate/java8/test/Penguin.java create mode 100644 src/it/oracle/associate/java8/test/Printable.java create mode 100644 src/it/oracle/associate/java8/test/Test.java create mode 100644 src/it/oracle/associate/java8/test/Toy.java diff --git a/.classpath b/.classpath new file mode 100644 index 0000000..4f2c72b --- /dev/null +++ b/.classpath @@ -0,0 +1,10 @@ + + + + + + + + + + diff --git a/.project b/.project new file mode 100644 index 0000000..56c5fbc --- /dev/null +++ b/.project @@ -0,0 +1,17 @@ + + + OracleCertificationAssociateTest + + + + + + org.eclipse.jdt.core.javabuilder + + + + + + org.eclipse.jdt.core.javanature + + diff --git a/.settings/org.eclipse.jdt.core.prefs b/.settings/org.eclipse.jdt.core.prefs new file mode 100644 index 0000000..3a21537 --- /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/src/it/oracle/associate/java8/A.java b/src/it/oracle/associate/java8/A.java new file mode 100644 index 0000000..9436c22 --- /dev/null +++ b/src/it/oracle/associate/java8/A.java @@ -0,0 +1,35 @@ +/* + * Copyright (c) 2018, fscotto + * All rights reserved. + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions are met: + * + * * Redistributions of source code must retain the above copyright notice, this + * list of conditions and the following disclaimer. + * * Redistributions in binary form must reproduce the above copyright notice, + * this list of conditions and the following disclaimer in the documentation + * and/or other materials provided with the distribution. + * + * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" + * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE + * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE + * ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE + * LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR + * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF + * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS + * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN + * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) + * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE + * POSSIBILITY OF SUCH DAMAGE. + */ +package it.oracle.associate.java8; + +/** + * + * @author fscotto + */ +public class A { + public int i1 = 1; + protected int i2 = 2; +} diff --git a/src/it/oracle/associate/java8/Animal.java b/src/it/oracle/associate/java8/Animal.java new file mode 100644 index 0000000..b1a1fb1 --- /dev/null +++ b/src/it/oracle/associate/java8/Animal.java @@ -0,0 +1,42 @@ +/* + * Copyright (c) 2018, fscotto + * All rights reserved. + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions are met: + * + * * Redistributions of source code must retain the above copyright notice, this + * list of conditions and the following disclaimer. + * * Redistributions in binary form must reproduce the above copyright notice, + * this list of conditions and the following disclaimer in the documentation + * and/or other materials provided with the distribution. + * + * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" + * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE + * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE + * ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE + * LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR + * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF + * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS + * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN + * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) + * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE + * POSSIBILITY OF SUCH DAMAGE. + */ +package it.oracle.associate.java8; + +/** + * + * @author fscotto + */ +abstract class Animal { + private String name; + + Animal(String name) { + this.name = name; + } + + public String getName() { + return this.name; + } +} diff --git a/src/it/oracle/associate/java8/B.java b/src/it/oracle/associate/java8/B.java new file mode 100644 index 0000000..3612a1d --- /dev/null +++ b/src/it/oracle/associate/java8/B.java @@ -0,0 +1,34 @@ +/* + * Copyright (c) 2018, fscotto + * All rights reserved. + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions are met: + * + * * Redistributions of source code must retain the above copyright notice, this + * list of conditions and the following disclaimer. + * * Redistributions in binary form must reproduce the above copyright notice, + * this list of conditions and the following disclaimer in the documentation + * and/or other materials provided with the distribution. + * + * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" + * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE + * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE + * ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE + * LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR + * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF + * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS + * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN + * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) + * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE + * POSSIBILITY OF SUCH DAMAGE. + */ +package it.oracle.associate.java8; + +/** + * + * @author fscotto + */ +public class B extends A { + +} diff --git a/src/it/oracle/associate/java8/Counter.java b/src/it/oracle/associate/java8/Counter.java new file mode 100644 index 0000000..ea25845 --- /dev/null +++ b/src/it/oracle/associate/java8/Counter.java @@ -0,0 +1,43 @@ +/* + * Copyright (c) 2018, fscotto + * All rights reserved. + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions are met: + * + * * Redistributions of source code must retain the above copyright notice, this + * list of conditions and the following disclaimer. + * * Redistributions in binary form must reproduce the above copyright notice, + * this list of conditions and the following disclaimer in the documentation + * and/or other materials provided with the distribution. + * + * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" + * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE + * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE + * ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE + * LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR + * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF + * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS + * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN + * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) + * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE + * POSSIBILITY OF SUCH DAMAGE. + */ +package it.oracle.associate.java8; + +/** + * + * @author fscotto + */ +class Counter { + int counter; + + Counter(int counter) { + this.counter = counter; + } + + @Override + public String toString() { + return "Counter: " + this.counter; + } +} diff --git a/src/it/oracle/associate/java8/Dog.java b/src/it/oracle/associate/java8/Dog.java new file mode 100644 index 0000000..3125df8 --- /dev/null +++ b/src/it/oracle/associate/java8/Dog.java @@ -0,0 +1,40 @@ +/* + * Copyright (c) 2018, fscotto + * All rights reserved. + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions are met: + * + * * Redistributions of source code must retain the above copyright notice, this + * list of conditions and the following disclaimer. + * * Redistributions in binary form must reproduce the above copyright notice, + * this list of conditions and the following disclaimer in the documentation + * and/or other materials provided with the distribution. + * + * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" + * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE + * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE + * ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE + * LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR + * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF + * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS + * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN + * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) + * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE + * POSSIBILITY OF SUCH DAMAGE. + */ +package it.oracle.associate.java8; + +/** + * + * @author fscotto + */ +public class Dog extends Animal { + + private String breed; + + Dog(String name, String breed) { + super(name); + this.breed = breed; + } +} diff --git a/src/it/oracle/associate/java8/Exam1.java b/src/it/oracle/associate/java8/Exam1.java new file mode 100644 index 0000000..b56f151 --- /dev/null +++ b/src/it/oracle/associate/java8/Exam1.java @@ -0,0 +1,371 @@ +/* + * Copyright (c) 2018, fscotto + * All rights reserved. + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions are met: + * + * * Redistributions of source code must retain the above copyright notice, this + * list of conditions and the following disclaimer. + * * Redistributions in binary form must reproduce the above copyright notice, + * this list of conditions and the following disclaimer in the documentation + * and/or other materials provided with the distribution. + * + * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" + * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE + * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE + * ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE + * LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR + * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF + * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS + * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN + * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) + * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE + * POSSIBILITY OF SUCH DAMAGE. + */ +package it.oracle.associate.java8; + +import it.oracle.associate.java8.test.B; +import java.io.FileNotFoundException; +import java.io.IOException; +import java.time.LocalDate; +import java.time.LocalDateTime; +import java.time.LocalTime; +import java.time.Month; +import java.time.Period; +import java.time.format.DateTimeFormatter; +import java.util.ArrayList; +import java.util.List; + +/** + * + * @author fscotto + */ +public class Exam1 { + + public static void main(String[] args) { + Exam1 e = new Exam1(); + e.question27(); + } + + private void question1() { + new B().print(); + } + + private void question2() { + LocalDateTime obj = LocalDateTime.now(); + System.out.println(obj.getSecond()); + } + + private void question3() { + ArrayList original = new ArrayList<>(); + original.add(new Counter((10))); + + ArrayList cloned = (ArrayList) original.clone(); + cloned.get(0).counter = 5; + + System.out.println(original); + } + + private void question4() { + List l1 = new ArrayList<>(); + l1.add("A"); + l1.add("D"); + + List l2 = new ArrayList<>(); + l2.add("B"); + l2.add("C"); + + l1.addAll(1, l2); + + System.out.println(l1); + } + + public void question5() { + do { + System.out.println(100); + } while (false); + System.out.println("Bye"); + } + + public void question10() { + List l = new ArrayList<>(); + l.add(new Integer(2)); + l.add(new Integer(1)); + l.add(new Integer(0)); + + l.remove(l.indexOf(0)); + System.out.println(l); + } + + public void question11() { + int a = 100; + System.out.println(-a++); + } + + public void question14() { + LocalDate date = LocalDate.of(2012, 1, 11); + Period period = Period.ofMonths(2); + DateTimeFormatter formatter = DateTimeFormatter.ofPattern("MM-dd-yy"); + System.out.print(formatter.format(date.minus(period))); + } + + public void question15() { + List dates = new ArrayList<>(); + dates.add(LocalDate.parse("2018-07-11")); + dates.add(LocalDate.parse("1919-02-25")); + dates.add(LocalDate.of(2020, 4, 8)); + dates.add(LocalDate.of(1980, Month.DECEMBER, 31)); + + dates.removeIf(x -> x.getYear() < 2000); + + System.out.println(dates); + } + + public void question16() { + Point p1 = new Point(); + p1.x = 10; + p1.y = 20; + Point p2 = new Point(); + p2.assign(p1.x, p1.y); + System.out.println(p1.toString() + ";" + p2.toString()); + } + + public void question17() { + String str = "java"; + StringBuilder sb = new StringBuilder("java"); + + System.out.println(str.equals(sb) + ":" + sb.equals(str)); + } + + public void question18() { + List students = new ArrayList<>(); + students.add(new Student("James", 25)); + students.add(new Student("James", 27)); + students.add(new Student("James", 25)); + students.add(new Student("James", 25)); + + students.remove(new Student("James", 25)); + + for (Student stud : students) { + System.out.println(stud); + } + } + + public void question19() { + String swiftCode = "ICICINBBRT4"; + System.out.println(swiftCode.substring(4, 6)); + } + + public void question22() { + LocalDate date = LocalDate.of(2020, 9, 31); + System.out.println(date); + } + + public void question23() { + StringBuilder sb = new StringBuilder("Java"); + String s1 = sb.toString(); + String s2 = sb.toString(); + + System.out.println(s1 == s2); + } + + private void question26() { + String fruit = "mango"; + switch (fruit) { + default: + System.out.println("ANY FRUIT WILL DO"); + case "Apple": + System.out.println("APPLE"); + case "Mango": + System.out.println("MANGO"); + case "Banana": + System.out.println("BANANA"); + break; + } + } + + private void m(int x) { + System.out.println("int version"); + } + + private void m(char x) { + System.out.println("char version"); + } + + private void question27() { + int i = '5'; + m(i); + m('5'); + } + + private void question28() { + LocalDate date = LocalDate.parse("1947-08-14"); + LocalTime time = LocalTime.MAX; + System.out.println(date.atTime(time)); + } + + private void question33() { + List list = new ArrayList<>(); + list.add(100); + list.add(200); + list.add(100); + list.add(200); + + list.remove(100); + + System.out.println(list); + } + + public void question35() { +// Super s = new Sub(); +// try { +// s.m1(); +// } catch (FileNotFoundException e) { +// System.out.print("M"); +// } finally { +// System.out.print("N"); +// } + } + + private void question39() { + String str1 = new String("Core"); + String str2 = new String("CoRe"); + System.out.println(str1 = str2); + } + + private void question42() { + List list = new ArrayList<>(); + list.add(0, 'V'); + list.add('T'); + list.add(1, 'E'); + list.add(3, 'O'); + + if (list.contains('O')) { + list.remove('O'); + } + + for (char ch : list) { + System.out.print(ch); + } + } + + private void question43() { + System.out.println(new String("Java")); + System.out.println(new StringBuilder("Java")); + System.out.println(new SpecialString("Java")); + } + + private void question45() { +// double price = 90000; +// String model; +// if (price > 100000) { +// model = "Tesla Model X"; +// } else if (price <= 100000) { +// model = "Tesla Model S"; +// } +// System.out.println(model); + } + + private void question47() { + char var = 7; + switch (var) { + case 7: + System.out.println("Lucky no. 7"); + break; + default: + System.out.println("DEFAULT"); + } + } + + private void question48() { + String s = new String("Hello"); + List list = new ArrayList<>(); + list.add(s); + list.add(new String("Hello")); + list.add(s); + s.replace("l", "L"); + + System.out.println(list); + } + + private void question50() { + short[] arr; + arr = new short[2]; + arr[0] = 5; + arr[1] = 10; + System.out.println("[" + arr[0] + ", " + arr[1] + "]"); + } + + private void question52() { +// double [] arr = new int[2]; //Line 3 + } + + private void question53() { + LocalDate newYear = LocalDate.of(2018, 1, 1); + LocalDate christmas = LocalDate.of(2018, 12, 25); + boolean flag1 = newYear.isAfter(christmas); + boolean flag2 = newYear.isBefore(christmas); + System.out.println(flag1 + ":" + flag2); + } + + private void question54() { + //m1(); + } + + private static void m1() throws Exception { //Line 6 + System.out.println("NOT THROWING ANY EXCEPTION"); //Line 7 + } + + private void question55() { + A obj1 = new A(); + B obj2 = (B) obj1; + //obj2.print(); + } + + private void question57() { + Period period = Period.of(0, 0, 0); + System.out.println(period); + } + + private void question59() { + Double[] arr = new Double[2]; + System.out.println(arr[0] + arr[1]); + } + + private void question61() { +// byte var = 100; +// switch (var) { +// case 100: +// System.out.println("var is 100"); +// break; +// case 200: +// System.out.println("var is 200"); +// break; +// default: +// System.out.println("In default"); +// } + } +} + +class SpecialString { + + String str; + + SpecialString(String str) { + this.str = str; + } +} + +abstract class Super { + + public abstract void m1() throws IOException; +} + +class Sub extends Super { + + @Override + public void m1() throws IOException { + throw new FileNotFoundException(); + } +} diff --git a/src/it/oracle/associate/java8/Exam2.java b/src/it/oracle/associate/java8/Exam2.java new file mode 100644 index 0000000..270fcc1 --- /dev/null +++ b/src/it/oracle/associate/java8/Exam2.java @@ -0,0 +1,122 @@ +/* + * Copyright (c) 2018, fscotto + * All rights reserved. + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions are met: + * + * * Redistributions of source code must retain the above copyright notice, this + * list of conditions and the following disclaimer. + * * Redistributions in binary form must reproduce the above copyright notice, + * this list of conditions and the following disclaimer in the documentation + * and/or other materials provided with the distribution. + * + * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" + * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE + * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE + * ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE + * LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR + * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF + * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS + * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN + * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) + * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE + * POSSIBILITY OF SUCH DAMAGE. + */ +package it.oracle.associate.java8; + +import java.time.LocalDate; +import java.time.Period; +import java.time.format.DateTimeFormatter; + +/** + * + * @author fscotto + */ +public class Exam2 { + + public static void main(String[] args) { + Exam2 e = new Exam2(); + e.question65(); + } + + private void question8() { + Boolean b1 = new Boolean("tRuE"); + Boolean b2 = new Boolean("fAlSe"); + Boolean b3 = new Boolean("abc"); + Boolean b4 = null; + System.out.println(b1 + ":" + b2 + ":" + b3 + ":" + b4); + } + + private void question13() { + LocalDate date = LocalDate.of(2012, 1, 11); + Period period = Period.ofMonths(2); + DateTimeFormatter formatter = DateTimeFormatter.ofPattern("mm-dd-yy"); + System.out.print(formatter.format(date.minus(period))); + } + + private void question33() { + LocalDate date = LocalDate.parse("2000-01-01"); + Period period = Period.ofYears(-3000); + System.out.println(date.plus(period)); + } + + private void question35() { + LocalDate date = LocalDate.parse("1980-03-16"); + System.out.println(date.minusYears(-5)); + } + + private void question39() { + int a = 2; + boolean res = false; + res = a++ == 2 || --a == 2 && --a == 2; + System.out.println(a); + } + + private static void add(double d1, double d2) { + System.out.println("double version: " + (d1 + d2)); + } + + private static void add(Double d1, Double d2) { + System.out.println("Double version: " + (d1 + d2)); + } + + private void question63() { + Period period = Period.of(2, 1, 0).ofYears(10).ofMonths(5).ofDays(2); + System.out.println(period); + } + + private void question65() { + LocalDate d1 = LocalDate.parse("1999-09-09"); + LocalDate d2 = LocalDate.parse("1999-09-09"); + LocalDate d3 = LocalDate.of(1999, 9, 9); + LocalDate d4 = LocalDate.of(1999, 9, 9); + System.out.println((d1 == d2) + ":" + (d2 == d3) + ":" + (d3 == d4)); + } +} + +class Parent { + + int i = 10; + + Parent(int i) { + super(); + this.i = i; + } +} + +class Child extends Parent { + + int j = 20; + + Child(int j) { + super(0); + this.j = j; + } + + Child(int i, int j) { + super(i); +// this(j); + } + +} diff --git a/src/it/oracle/associate/java8/Guest.java b/src/it/oracle/associate/java8/Guest.java new file mode 100644 index 0000000..8f96485 --- /dev/null +++ b/src/it/oracle/associate/java8/Guest.java @@ -0,0 +1,38 @@ +/* + * Copyright (c) 2018, fscotto + * All rights reserved. + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions are met: + * + * * Redistributions of source code must retain the above copyright notice, this + * list of conditions and the following disclaimer. + * * Redistributions in binary form must reproduce the above copyright notice, + * this list of conditions and the following disclaimer in the documentation + * and/or other materials provided with the distribution. + * + * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" + * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE + * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE + * ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE + * LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR + * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF + * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS + * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN + * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) + * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE + * POSSIBILITY OF SUCH DAMAGE. + */ +package it.oracle.associate.java8; + +class Message { + static void main(String [] args) { + System.out.println("Welcome! " + args[1]); + } +} + +public class Guest { + public static void main(String [] args) { + Message.main(args); + } +} diff --git a/src/it/oracle/associate/java8/I1.java b/src/it/oracle/associate/java8/I1.java new file mode 100644 index 0000000..d86928d --- /dev/null +++ b/src/it/oracle/associate/java8/I1.java @@ -0,0 +1,40 @@ +/* + * Copyright (c) 2018, fscotto + * All rights reserved. + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions are met: + * + * * Redistributions of source code must retain the above copyright notice, this + * list of conditions and the following disclaimer. + * * Redistributions in binary form must reproduce the above copyright notice, + * this list of conditions and the following disclaimer in the documentation + * and/or other materials provided with the distribution. + * + * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" + * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE + * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE + * ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE + * LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR + * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF + * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS + * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN + * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) + * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE + * POSSIBILITY OF SUCH DAMAGE. + */ +package it.oracle.associate.java8; + +/** + * + * @author fscotto + */ +public interface I1 { + public void m1() throws java.io.IOException; +} + + +class C4 implements I1 { + @Override + public void m1() {} +} \ No newline at end of file diff --git a/src/it/oracle/associate/java8/Point.java b/src/it/oracle/associate/java8/Point.java new file mode 100644 index 0000000..b373330 --- /dev/null +++ b/src/it/oracle/associate/java8/Point.java @@ -0,0 +1,45 @@ +/* + * Copyright (c) 2018, fscotto + * All rights reserved. + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions are met: + * + * * Redistributions of source code must retain the above copyright notice, this + * list of conditions and the following disclaimer. + * * Redistributions in binary form must reproduce the above copyright notice, + * this list of conditions and the following disclaimer in the documentation + * and/or other materials provided with the distribution. + * + * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" + * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE + * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE + * ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE + * LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR + * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF + * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS + * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN + * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) + * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE + * POSSIBILITY OF SUCH DAMAGE. + */ +package it.oracle.associate.java8; + +/** + * + * @author fscotto + */ +class Point { + + int x; + int y; + + public void assign(int x, int y) { + x = this.x; + this.y = y; + } + + public String toString() { + return "Point(" + x + ", " + y + ")"; + } +} diff --git a/src/it/oracle/associate/java8/Student.java b/src/it/oracle/associate/java8/Student.java new file mode 100644 index 0000000..0035e19 --- /dev/null +++ b/src/it/oracle/associate/java8/Student.java @@ -0,0 +1,45 @@ +/* + * Copyright (c) 2018, fscotto + * All rights reserved. + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions are met: + * + * * Redistributions of source code must retain the above copyright notice, this + * list of conditions and the following disclaimer. + * * Redistributions in binary form must reproduce the above copyright notice, + * this list of conditions and the following disclaimer in the documentation + * and/or other materials provided with the distribution. + * + * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" + * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE + * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE + * ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE + * LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR + * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF + * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS + * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN + * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) + * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE + * POSSIBILITY OF SUCH DAMAGE. + */ +package it.oracle.associate.java8; + +/** + * + * @author fscotto + */ +class Student { + + String name; + int age; + + Student(String name, int age) { + this.name = name; + this.age = age; + } + + public String toString() { + return "Student[" + name + ", " + age + "]"; + } +} diff --git a/src/it/oracle/associate/java8/test/Airplane.java b/src/it/oracle/associate/java8/test/Airplane.java new file mode 100644 index 0000000..5c1377f --- /dev/null +++ b/src/it/oracle/associate/java8/test/Airplane.java @@ -0,0 +1,20 @@ +package it.oracle.associate.java8.test; + +public class Airplane { + static int start = 2; + final int end; + + public Airplane(int x) { + x = 4; + end = x; + } + + public void fly(int distance) { + System.out.println(end-start+" "); + System.out.println(distance); + } + + public static void main(String... start) { + new Airplane(10).fly(5); + } +} diff --git a/src/it/oracle/associate/java8/test/ArrayTest.java b/src/it/oracle/associate/java8/test/ArrayTest.java new file mode 100644 index 0000000..5437676 --- /dev/null +++ b/src/it/oracle/associate/java8/test/ArrayTest.java @@ -0,0 +1,119 @@ +/* + * Copyright (c) 2018, fscotto + * All rights reserved. + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions are met: + * + * * Redistributions of source code must retain the above copyright notice, this + * list of conditions and the following disclaimer. + * * Redistributions in binary form must reproduce the above copyright notice, + * this list of conditions and the following disclaimer in the documentation + * and/or other materials provided with the distribution. + * + * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" + * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE + * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE + * ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE + * LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR + * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF + * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS + * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN + * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) + * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE + * POSSIBILITY OF SUCH DAMAGE. + */ +package it.oracle.associate.java8.test; + +import java.util.Arrays; + +/** + * + * @author fscotto + */ +public class ArrayTest { + + public static void main(String[] args) { + int[] a0 = new int[10]; + System.out.println("a0 length: " + a0.length); + + int a1[] = new int[10]; + System.out.println("a1 length: " + a1.length); + + int[] a2 = new int[]{0}; + System.out.println("a2 length: " + a2.length); + + int a3[]; + a3 = new int[10]; + System.out.println("a3 length: " + a3.length); + System.out.println(Arrays.toString(a3)); + + MyClass[] a4 = new MyClass[]{new MyClass("classe1"), new MyClass("classe2")}; + System.out.println("a4 length: " + a4.length); + System.out.println(Arrays.toString(a4)); + a4 = add(a4, new MyClass(("classe3"))); + System.out.println("a4 length: " + a4.length); + System.out.println(Arrays.toString(a4)); + + char index = 5; + int[] a5 = new int[index]; + + String[] a6 = {"Corey", "Ozzy", "Zakk"}; + + f(new String[0]); + + //String s = a6[-1]; ArrayIndexOutOfBoundsException + + //Field f = new int[0].getClass().getField("length"); java.lang.NoSuchFieldException: length + + // non funziona + int[] a7 = unmodifieble(new int[]{1, 2, 3, 4, 5}); + System.out.println(Arrays.toString(a7)); + a7[0] = 0; + System.out.println(Arrays.toString(a7)); + + int[][] a8 = new int[3][3]; + + int a[][] = {{}, {}}; + } + + private static int[] unmodifieble(int[] arr) { + final int[] ret = Arrays.copyOf(arr, arr.length); + return ret; + } + + private static void f(String[] array) { + // non fa nulla + } + + private static MyClass[] add(MyClass[] arr, MyClass obj) { + MyClass[] copy = arr.clone(); + System.out.println(Arrays.toString(copy)); + MyClass[] newArray = Arrays.copyOf(arr, arr.length + 10); + System.out.println(Arrays.toString(newArray)); + for (int i = 0; i < newArray.length; i++) { + MyClass o = newArray[i]; + if (o == null) { + newArray[i] = obj; + break; + } + } + System.out.println(Arrays.toString(newArray)); + return newArray; + } + +} + +class MyClass { + + final String name; + + MyClass(String name) { + this.name = name; + } + + @Override + public String toString() { + return this.name; + } +} diff --git a/src/it/oracle/associate/java8/test/B.java b/src/it/oracle/associate/java8/test/B.java new file mode 100644 index 0000000..9a2e4bb --- /dev/null +++ b/src/it/oracle/associate/java8/test/B.java @@ -0,0 +1,44 @@ +/* + * Copyright (c) 2018, fscotto + * All rights reserved. + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions are met: + * + * * Redistributions of source code must retain the above copyright notice, this + * list of conditions and the following disclaimer. + * * Redistributions in binary form must reproduce the above copyright notice, + * this list of conditions and the following disclaimer in the documentation + * and/or other materials provided with the distribution. + * + * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" + * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE + * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE + * ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE + * LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR + * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF + * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS + * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN + * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) + * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE + * POSSIBILITY OF SUCH DAMAGE. + */ +package it.oracle.associate.java8.test; + +import it.oracle.associate.java8.A; + +/** + * + * @author fscotto + */ +public class B extends A { + + public void print() { + A obj = new A(); + System.out.println(obj.i1); +// System.out.println(obj.i2); + System.out.println(this.i2); + System.out.println(super.i2); + } + +} diff --git a/src/it/oracle/associate/java8/test/BaseClass.java b/src/it/oracle/associate/java8/test/BaseClass.java new file mode 100644 index 0000000..995c7f9 --- /dev/null +++ b/src/it/oracle/associate/java8/test/BaseClass.java @@ -0,0 +1,14 @@ +package it.oracle.associate.java8.test; + +public abstract class BaseClass { + + private String name; + + public BaseClass(String name) { + this.name = name; + } + + public String getName() { + return this.name; + } +} diff --git a/src/it/oracle/associate/java8/test/DateTest.java b/src/it/oracle/associate/java8/test/DateTest.java new file mode 100644 index 0000000..4a0a2c0 --- /dev/null +++ b/src/it/oracle/associate/java8/test/DateTest.java @@ -0,0 +1,57 @@ +/* + * Copyright (c) 2018, fscotto + * All rights reserved. + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions are met: + * + * * Redistributions of source code must retain the above copyright notice, this + * list of conditions and the following disclaimer. + * * Redistributions in binary form must reproduce the above copyright notice, + * this list of conditions and the following disclaimer in the documentation + * and/or other materials provided with the distribution. + * + * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" + * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE + * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE + * ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE + * LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR + * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF + * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS + * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN + * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) + * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE + * POSSIBILITY OF SUCH DAMAGE. + */ +package it.oracle.associate.java8.test; + +import java.time.LocalDate; +import java.time.LocalTime; +import java.util.ArrayList; +import java.util.List; + +/** + * + * @author fscotto + */ +public class DateTest { + + public static void main(String[] args) { + List dates = new ArrayList<>(); + dates.add(LocalDate.parse("2018-02-12")); + dates.add(LocalDate.of(2014, 4, 10)); + + dates.removeIf(d -> d.getYear() < 2000); + + System.out.println(dates); + + //LocalDate.of(2001, Month.FEBRUARY, 29); + + //LocalDate.parse("2018-09-31"); + + List times = new ArrayList<>(); + times.add(LocalTime.of(16, 40)); + + + } +} diff --git a/src/it/oracle/associate/java8/test/DerivatedClass.java b/src/it/oracle/associate/java8/test/DerivatedClass.java new file mode 100644 index 0000000..c616e1d --- /dev/null +++ b/src/it/oracle/associate/java8/test/DerivatedClass.java @@ -0,0 +1,9 @@ +package it.oracle.associate.java8.test; + +public class DerivatedClass extends BaseClass { + + public DerivatedClass(String name) { + super(name); + } + +} diff --git a/src/it/oracle/associate/java8/test/Greetings.java b/src/it/oracle/associate/java8/test/Greetings.java new file mode 100644 index 0000000..441f695 --- /dev/null +++ b/src/it/oracle/associate/java8/test/Greetings.java @@ -0,0 +1,23 @@ +package it.oracle.associate.java8.test; + +public class Greetings { + String msg = null; + + public Greetings() { + } + + public Greetings(String str) { + msg = str; + } + + public void displayMsg() { + System.out.println(msg); + } + + public static void main(String[] args) { + Greetings g1 = new Greetings(); + Greetings g2 = new Greetings("Good Evening!"); + g1.displayMsg(); + g1.displayMsg(); + } +} diff --git a/src/it/oracle/associate/java8/test/InitOrder.java b/src/it/oracle/associate/java8/test/InitOrder.java new file mode 100644 index 0000000..7e1d2d9 --- /dev/null +++ b/src/it/oracle/associate/java8/test/InitOrder.java @@ -0,0 +1,19 @@ +package it.oracle.associate.java8.test; + +public class InitOrder { + public String first = "instance"; + + public InitOrder() { + first = "costructor"; + } + + {first = "block";} + + public void print() { + System.out.println(first); + } + + public static void main(String... args) { + new InitOrder().print(); + } +} diff --git a/src/it/oracle/associate/java8/test/NewsPaper.java b/src/it/oracle/associate/java8/test/NewsPaper.java new file mode 100644 index 0000000..cbb92bd --- /dev/null +++ b/src/it/oracle/associate/java8/test/NewsPaper.java @@ -0,0 +1,9 @@ +package it.oracle.associate.java8.test; + +abstract class NewsPaper extends Paper { + + @Override + public void getMargin() { + } + +} diff --git a/src/it/oracle/associate/java8/test/Paper.java b/src/it/oracle/associate/java8/test/Paper.java new file mode 100644 index 0000000..b7b299c --- /dev/null +++ b/src/it/oracle/associate/java8/test/Paper.java @@ -0,0 +1,9 @@ +package it.oracle.associate.java8.test; + +abstract class Paper implements Printable { + + @Override + public void getMargin() { + } + +} diff --git a/src/it/oracle/associate/java8/test/Penguin.java b/src/it/oracle/associate/java8/test/Penguin.java new file mode 100644 index 0000000..08b7458 --- /dev/null +++ b/src/it/oracle/associate/java8/test/Penguin.java @@ -0,0 +1,9 @@ +package it.oracle.associate.java8.test; + +public class Penguin { + private double beakLength; + + public static void setBeakTLength(Penguin p, int b) { + p.beakLength = b; + } +} diff --git a/src/it/oracle/associate/java8/test/Printable.java b/src/it/oracle/associate/java8/test/Printable.java new file mode 100644 index 0000000..6468263 --- /dev/null +++ b/src/it/oracle/associate/java8/test/Printable.java @@ -0,0 +1,9 @@ +package it.oracle.associate.java8.test; + +public interface Printable { + + public void getMargin(); + + public void getOrientation(); + +} diff --git a/src/it/oracle/associate/java8/test/Test.java b/src/it/oracle/associate/java8/test/Test.java new file mode 100644 index 0000000..0b373b2 --- /dev/null +++ b/src/it/oracle/associate/java8/test/Test.java @@ -0,0 +1,9 @@ +package it.oracle.associate.java8.test; + +public class Test { + + public static void main(String[] args) { + // TODO Auto-generated method stub + } + +} diff --git a/src/it/oracle/associate/java8/test/Toy.java b/src/it/oracle/associate/java8/test/Toy.java new file mode 100644 index 0000000..c54bb67 --- /dev/null +++ b/src/it/oracle/associate/java8/test/Toy.java @@ -0,0 +1,12 @@ +package it.oracle.associate.java8.test; + +public class Toy { + + public void play() { + System.out.println("play-"); + } + + public void finalizer() { + System.out.println("clean-"); + } +}