nuovi test
This commit is contained in:
35
src/com/oracle/java8/associate/A.java
Normal file
35
src/com/oracle/java8/associate/A.java
Normal file
@@ -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 com.oracle.java8.associate;
|
||||
|
||||
/**
|
||||
*
|
||||
* @author fscotto
|
||||
*/
|
||||
public class A {
|
||||
public int i1 = 1;
|
||||
protected int i2 = 2;
|
||||
}
|
||||
42
src/com/oracle/java8/associate/Animal.java
Normal file
42
src/com/oracle/java8/associate/Animal.java
Normal file
@@ -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 com.oracle.java8.associate;
|
||||
|
||||
/**
|
||||
*
|
||||
* @author fscotto
|
||||
*/
|
||||
abstract class Animal {
|
||||
private String name;
|
||||
|
||||
Animal(String name) {
|
||||
this.name = name;
|
||||
}
|
||||
|
||||
public String getName() {
|
||||
return this.name;
|
||||
}
|
||||
}
|
||||
34
src/com/oracle/java8/associate/B.java
Normal file
34
src/com/oracle/java8/associate/B.java
Normal file
@@ -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 com.oracle.java8.associate;
|
||||
|
||||
/**
|
||||
*
|
||||
* @author fscotto
|
||||
*/
|
||||
public class B extends A {
|
||||
|
||||
}
|
||||
43
src/com/oracle/java8/associate/Counter.java
Normal file
43
src/com/oracle/java8/associate/Counter.java
Normal file
@@ -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 com.oracle.java8.associate;
|
||||
|
||||
/**
|
||||
*
|
||||
* @author fscotto
|
||||
*/
|
||||
class Counter {
|
||||
int counter;
|
||||
|
||||
Counter(int counter) {
|
||||
this.counter = counter;
|
||||
}
|
||||
|
||||
@Override
|
||||
public String toString() {
|
||||
return "Counter: " + this.counter;
|
||||
}
|
||||
}
|
||||
40
src/com/oracle/java8/associate/Dog.java
Normal file
40
src/com/oracle/java8/associate/Dog.java
Normal file
@@ -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 com.oracle.java8.associate;
|
||||
|
||||
/**
|
||||
*
|
||||
* @author fscotto
|
||||
*/
|
||||
public class Dog extends Animal {
|
||||
|
||||
private String breed;
|
||||
|
||||
Dog(String name, String breed) {
|
||||
super(name);
|
||||
this.breed = breed;
|
||||
}
|
||||
}
|
||||
25
src/com/oracle/java8/associate/ElectricCar.java
Normal file
25
src/com/oracle/java8/associate/ElectricCar.java
Normal file
@@ -0,0 +1,25 @@
|
||||
package com.oracle.java8.associate;
|
||||
|
||||
class Automobile {
|
||||
private final String drive() {
|
||||
return "Driving vehicle";
|
||||
}
|
||||
}
|
||||
|
||||
class Car extends Automobile {
|
||||
protected String drive() {
|
||||
return "Driving car";
|
||||
}
|
||||
}
|
||||
|
||||
public class ElectricCar extends Car {
|
||||
@Override
|
||||
public final String drive() {
|
||||
return "Driving electric car";
|
||||
}
|
||||
|
||||
public static void main(String[] args) {
|
||||
final Car car = new ElectricCar();
|
||||
System.out.println(car.drive());
|
||||
}
|
||||
}
|
||||
372
src/com/oracle/java8/associate/Exam1.java
Normal file
372
src/com/oracle/java8/associate/Exam1.java
Normal file
@@ -0,0 +1,372 @@
|
||||
/*
|
||||
* 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 com.oracle.java8.associate;
|
||||
|
||||
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;
|
||||
|
||||
import com.oracle.java8.associate.test.B;
|
||||
|
||||
/**
|
||||
*
|
||||
* @author fscotto
|
||||
*/
|
||||
public class Exam1 {
|
||||
|
||||
public static void main(String[] args) {
|
||||
Exam1 e = new Exam1();
|
||||
e.question27();
|
||||
}
|
||||
|
||||
private void question1() {
|
||||
new com.oracle.java8.associate.test.B().print();
|
||||
}
|
||||
|
||||
private void question2() {
|
||||
LocalDateTime obj = LocalDateTime.now();
|
||||
System.out.println(obj.getSecond());
|
||||
}
|
||||
|
||||
private void question3() {
|
||||
ArrayList<Counter> original = new ArrayList<>();
|
||||
original.add(new Counter((10)));
|
||||
|
||||
ArrayList<Counter> cloned = (ArrayList<Counter>) original.clone();
|
||||
cloned.get(0).counter = 5;
|
||||
|
||||
System.out.println(original);
|
||||
}
|
||||
|
||||
private void question4() {
|
||||
List<String> l1 = new ArrayList<>();
|
||||
l1.add("A");
|
||||
l1.add("D");
|
||||
|
||||
List<String> 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<Integer> 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<LocalDate> 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<Student> 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<Integer> 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<Character> 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<String> 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();
|
||||
com.oracle.java8.associate.test.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();
|
||||
}
|
||||
}
|
||||
122
src/com/oracle/java8/associate/Exam2.java
Normal file
122
src/com/oracle/java8/associate/Exam2.java
Normal file
@@ -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 com.oracle.java8.associate;
|
||||
|
||||
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);
|
||||
}
|
||||
|
||||
}
|
||||
38
src/com/oracle/java8/associate/Guest.java
Normal file
38
src/com/oracle/java8/associate/Guest.java
Normal file
@@ -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 com.oracle.java8.associate;
|
||||
|
||||
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);
|
||||
}
|
||||
}
|
||||
40
src/com/oracle/java8/associate/I1.java
Normal file
40
src/com/oracle/java8/associate/I1.java
Normal file
@@ -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 com.oracle.java8.associate;
|
||||
|
||||
/**
|
||||
*
|
||||
* @author fscotto
|
||||
*/
|
||||
public interface I1 {
|
||||
public void m1() throws java.io.IOException;
|
||||
}
|
||||
|
||||
|
||||
class C4 implements I1 {
|
||||
@Override
|
||||
public void m1() {}
|
||||
}
|
||||
45
src/com/oracle/java8/associate/Point.java
Normal file
45
src/com/oracle/java8/associate/Point.java
Normal file
@@ -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 com.oracle.java8.associate;
|
||||
|
||||
/**
|
||||
*
|
||||
* @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 + ")";
|
||||
}
|
||||
}
|
||||
45
src/com/oracle/java8/associate/Student.java
Normal file
45
src/com/oracle/java8/associate/Student.java
Normal file
@@ -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 com.oracle.java8.associate;
|
||||
|
||||
/**
|
||||
*
|
||||
* @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 + "]";
|
||||
}
|
||||
}
|
||||
20
src/com/oracle/java8/associate/test/Airplane.java
Normal file
20
src/com/oracle/java8/associate/test/Airplane.java
Normal file
@@ -0,0 +1,20 @@
|
||||
package com.oracle.java8.associate.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);
|
||||
}
|
||||
}
|
||||
119
src/com/oracle/java8/associate/test/ArrayTest.java
Normal file
119
src/com/oracle/java8/associate/test/ArrayTest.java
Normal file
@@ -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 Alpha 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 com.oracle.java8.associate.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;
|
||||
}
|
||||
}
|
||||
29
src/com/oracle/java8/associate/test/Automobile.java
Normal file
29
src/com/oracle/java8/associate/test/Automobile.java
Normal file
@@ -0,0 +1,29 @@
|
||||
package com.oracle.java8.associate.test;
|
||||
|
||||
public class Automobile {
|
||||
private static int targaCorrente;
|
||||
private int targa;
|
||||
private int portiere;
|
||||
|
||||
//1
|
||||
static {
|
||||
targaCorrente = 0;
|
||||
System.out.println("Blocco statico");
|
||||
}
|
||||
|
||||
//2
|
||||
{
|
||||
this.targa = targaCorrente++;
|
||||
System.out.println("Blocco istanza");
|
||||
}
|
||||
|
||||
//3
|
||||
public Automobile(int portiere) {
|
||||
this.portiere = portiere;
|
||||
System.out.println("Costruttore");
|
||||
}
|
||||
|
||||
public static void main(String[] args) {
|
||||
new Automobile(5);
|
||||
}
|
||||
}
|
||||
44
src/com/oracle/java8/associate/test/B.java
Normal file
44
src/com/oracle/java8/associate/test/B.java
Normal file
@@ -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 Alpha 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 com.oracle.java8.associate.test;
|
||||
|
||||
import com.oracle.java8.associate.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);
|
||||
}
|
||||
|
||||
}
|
||||
18
src/com/oracle/java8/associate/test/Ballroom.java
Normal file
18
src/com/oracle/java8/associate/test/Ballroom.java
Normal file
@@ -0,0 +1,18 @@
|
||||
package com.oracle.java8.associate.test;
|
||||
|
||||
abstract class House {
|
||||
protected abstract Object getSpace();
|
||||
}
|
||||
|
||||
abstract class Room extends House {
|
||||
abstract Object getSpace(Object list);
|
||||
}
|
||||
|
||||
abstract public class Ballroom extends House {
|
||||
@Override
|
||||
protected abstract Object getSpace();
|
||||
public static void main(String[] squareFootage) {
|
||||
System.out.println("Let's start the party");
|
||||
}
|
||||
|
||||
}
|
||||
14
src/com/oracle/java8/associate/test/BaseClass.java
Normal file
14
src/com/oracle/java8/associate/test/BaseClass.java
Normal file
@@ -0,0 +1,14 @@
|
||||
package com.oracle.java8.associate.test;
|
||||
|
||||
public abstract class BaseClass {
|
||||
|
||||
private String name;
|
||||
|
||||
public BaseClass(String name) {
|
||||
this.name = name;
|
||||
}
|
||||
|
||||
public String getName() {
|
||||
return this.name;
|
||||
}
|
||||
}
|
||||
21
src/com/oracle/java8/associate/test/BlueCar.java
Normal file
21
src/com/oracle/java8/associate/test/BlueCar.java
Normal file
@@ -0,0 +1,21 @@
|
||||
package com.oracle.java8.associate.test;
|
||||
|
||||
abstract class Car {
|
||||
static { System.out.println("1"); }
|
||||
public Car(String name) {
|
||||
super();
|
||||
System.out.println("2");
|
||||
}
|
||||
{ System.out.println("3"); }
|
||||
}
|
||||
|
||||
public class BlueCar extends Car {
|
||||
{ System.out.println("4"); }
|
||||
public BlueCar() {
|
||||
super("blue");
|
||||
System.out.println("5");
|
||||
}
|
||||
public static void main(String[] gears) {
|
||||
new BlueCar();
|
||||
}
|
||||
}
|
||||
61
src/com/oracle/java8/associate/test/Calculations.java
Normal file
61
src/com/oracle/java8/associate/test/Calculations.java
Normal file
@@ -0,0 +1,61 @@
|
||||
package com.oracle.java8.associate.test;
|
||||
|
||||
public class Calculations {
|
||||
|
||||
private enum CardinalPoint {
|
||||
NORTH, SOUTH, WEST, EST
|
||||
}
|
||||
|
||||
public Boolean findAverage(boolean sum) {
|
||||
return sum;
|
||||
}
|
||||
|
||||
public Byte findAverage(byte sum) {
|
||||
return sum;
|
||||
}
|
||||
|
||||
public Character findAverage(char sum) {
|
||||
return sum;
|
||||
}
|
||||
|
||||
public Short findAverage(short sum) {
|
||||
return sum;
|
||||
}
|
||||
|
||||
public Integer findAverage(int sum) {
|
||||
return sum;
|
||||
}
|
||||
|
||||
public Long findAverage(long sum) {
|
||||
return sum;
|
||||
}
|
||||
|
||||
public Float findAverage(float sum) {
|
||||
return sum;
|
||||
}
|
||||
|
||||
public Double findAverage(double sum) {
|
||||
return sum;
|
||||
}
|
||||
|
||||
public static void main(String[] args) {
|
||||
Calculations c = new Calculations();
|
||||
System.out.println(c.findAverage((char) 36));
|
||||
|
||||
char ch = 0b0010_0100;
|
||||
System.out.println(ch);
|
||||
|
||||
ch = 0x24;
|
||||
System.out.println(ch);
|
||||
|
||||
byte b = 100;
|
||||
switch (b) {
|
||||
case 100:
|
||||
break;
|
||||
case 20:
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
11
src/com/oracle/java8/associate/test/ChooseWisely.java
Normal file
11
src/com/oracle/java8/associate/test/ChooseWisely.java
Normal file
@@ -0,0 +1,11 @@
|
||||
package com.oracle.java8.associate.test;
|
||||
|
||||
public class ChooseWisely {
|
||||
public ChooseWisely() { super(); }
|
||||
public int choose(int choise) { return 5; }
|
||||
public int choose(short choise) { return 2; }
|
||||
public int choose(long choise) { return 11; }
|
||||
public static void main(String[] path) {
|
||||
System.out.println(new ChooseWisely().choose((byte) 2+1));
|
||||
}
|
||||
}
|
||||
95
src/com/oracle/java8/associate/test/DateTest.java
Normal file
95
src/com/oracle/java8/associate/test/DateTest.java
Normal file
@@ -0,0 +1,95 @@
|
||||
/*
|
||||
* 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 Alpha 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 com.oracle.java8.associate.test;
|
||||
|
||||
import java.text.SimpleDateFormat;
|
||||
import java.time.*;
|
||||
import java.time.format.DateTimeFormatter;
|
||||
import java.time.temporal.ChronoField;
|
||||
import java.time.temporal.ChronoUnit;
|
||||
import java.time.temporal.TemporalAccessor;
|
||||
import java.time.temporal.TemporalAmount;
|
||||
import java.util.ArrayList;
|
||||
import java.util.Date;
|
||||
import java.util.List;
|
||||
import java.util.Optional;
|
||||
import java.util.function.*;
|
||||
import java.util.stream.Collectors;
|
||||
|
||||
/**
|
||||
*
|
||||
* @author fscotto
|
||||
*/
|
||||
public class DateTest {
|
||||
|
||||
public static void main(String[] args) {
|
||||
List<LocalDate> 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<LocalTime> times = new ArrayList<>();
|
||||
times.add(LocalTime.of(16, 40));
|
||||
|
||||
Date java7Date = new Date();
|
||||
|
||||
LocalDate localDate = java7Date.toInstant()
|
||||
.atZone(ZoneId.systemDefault())
|
||||
.toLocalDate();
|
||||
|
||||
LocalDate today = LocalDate.now();
|
||||
LocalDate yesterday = today.minusDays(1);
|
||||
ZonedDateTime zdt = yesterday.atStartOfDay(ZoneId.systemDefault());
|
||||
System.out.println(LocalDateTime.of(yesterday, LocalTime.MAX));
|
||||
|
||||
LocalDate ld = LocalDate.of(2018, Month.JULY, 1);
|
||||
LocalDateTime endDate = getEndDate(ld);
|
||||
System.out.println(endDate);
|
||||
|
||||
System.out.println(LocalDateTime.MAX);
|
||||
|
||||
LocalDateTime infinity = LocalDateTime.of(9999, Month.DECEMBER, 31, 23, 59, 59);
|
||||
System.out.println(infinity);
|
||||
|
||||
LocalDate myBirthday = LocalDate.of(1988, Month.FEBRUARY, 17);
|
||||
|
||||
System.out.println(myBirthday.get(ChronoField.YEAR));
|
||||
System.out.println(LocalDate.now());
|
||||
Period period = Period.between(myBirthday, LocalDate.now());
|
||||
System.out.println(period.getYears());
|
||||
}
|
||||
|
||||
public static LocalDateTime getEndDate(LocalDate date) {
|
||||
return LocalDateTime.of(date.minusDays(1), LocalTime.MAX);
|
||||
}
|
||||
}
|
||||
44
src/com/oracle/java8/associate/test/DefaultInterface.java
Normal file
44
src/com/oracle/java8/associate/test/DefaultInterface.java
Normal file
@@ -0,0 +1,44 @@
|
||||
package com.oracle.java8.associate.test;
|
||||
|
||||
public class DefaultInterface {
|
||||
|
||||
public static void main (String[] args) {
|
||||
Delta delta = new Delta();
|
||||
delta.print();
|
||||
|
||||
Alpha.staticMethod();
|
||||
}
|
||||
}
|
||||
|
||||
class Delta implements Alpha, Beta {
|
||||
|
||||
@Override
|
||||
public void print() {
|
||||
Alpha.super.print();
|
||||
}
|
||||
}
|
||||
|
||||
interface Alpha {
|
||||
|
||||
default void print() {
|
||||
System.out.println("print ALPHA");
|
||||
}
|
||||
|
||||
static void staticMethod() {
|
||||
System.out.println("static metodoConParametroPrimitivo");
|
||||
}
|
||||
}
|
||||
|
||||
interface Beta {
|
||||
|
||||
default void print() {
|
||||
System.out.println("print BETA");
|
||||
}
|
||||
}
|
||||
|
||||
interface Gamma extends Alpha {
|
||||
|
||||
default void print() {
|
||||
System.out.println("print GAMMA");
|
||||
}
|
||||
}
|
||||
9
src/com/oracle/java8/associate/test/DerivatedClass.java
Normal file
9
src/com/oracle/java8/associate/test/DerivatedClass.java
Normal file
@@ -0,0 +1,9 @@
|
||||
package com.oracle.java8.associate.test;
|
||||
|
||||
public class DerivatedClass extends BaseClass {
|
||||
|
||||
public DerivatedClass(String name) {
|
||||
super(name);
|
||||
}
|
||||
|
||||
}
|
||||
10
src/com/oracle/java8/associate/test/Drink.java
Normal file
10
src/com/oracle/java8/associate/test/Drink.java
Normal file
@@ -0,0 +1,10 @@
|
||||
package com.oracle.java8.associate.test;
|
||||
|
||||
public class Drink {
|
||||
|
||||
public static void water() {}
|
||||
|
||||
public void get() {
|
||||
Drink.water();
|
||||
}
|
||||
}
|
||||
16
src/com/oracle/java8/associate/test/Encyclopedia.java
Normal file
16
src/com/oracle/java8/associate/test/Encyclopedia.java
Normal file
@@ -0,0 +1,16 @@
|
||||
package com.oracle.java8.associate.test;
|
||||
|
||||
abstract class Book {
|
||||
protected static String material = "papyrus";
|
||||
public Book() {}
|
||||
public Book(String material) { this.material = material; }
|
||||
}
|
||||
|
||||
public class Encyclopedia extends Book {
|
||||
public static String material = "cellulose";
|
||||
public Encyclopedia() {super();}
|
||||
public String getMaterial() { return super.material; }
|
||||
public static void main(String[] pages) {
|
||||
System.out.println(new Encyclopedia().getMaterial());
|
||||
}
|
||||
}
|
||||
13
src/com/oracle/java8/associate/test/Football.java
Normal file
13
src/com/oracle/java8/associate/test/Football.java
Normal file
@@ -0,0 +1,13 @@
|
||||
package com.oracle.java8.associate.test;
|
||||
|
||||
public class Football {
|
||||
|
||||
public static Long getScore(Long timeRemaining) {
|
||||
return 2 * timeRemaining; // m1
|
||||
}
|
||||
|
||||
public static void main(String[] refs) {
|
||||
final int startTime = 4;
|
||||
//System.out.println(getScore(startTime)); // m2
|
||||
}
|
||||
}
|
||||
42
src/com/oracle/java8/associate/test/FunctionalTest.java
Normal file
42
src/com/oracle/java8/associate/test/FunctionalTest.java
Normal file
@@ -0,0 +1,42 @@
|
||||
package com.oracle.java8.associate.test;
|
||||
|
||||
import java.util.function.Consumer;
|
||||
|
||||
public class FunctionalTest {
|
||||
|
||||
public static void main (String[] args) {
|
||||
Consumer<String> c1 = s -> s.toLowerCase();
|
||||
Consumer<String> c2 = s -> s.trim();
|
||||
String var = " Hello WORLD!!!";
|
||||
c1.andThen(c2).accept(var);
|
||||
System.out.println(var);
|
||||
|
||||
EmployeeFactory factory = Employee::new;
|
||||
Employee employee = factory.getEmployee("John Hammond", 25);
|
||||
System.out.println(employee);
|
||||
}
|
||||
}
|
||||
|
||||
class Employee {
|
||||
String name;
|
||||
Integer age;
|
||||
|
||||
public Employee (String name) {
|
||||
this.name = name;
|
||||
}
|
||||
|
||||
public Employee (String name, Integer age) {
|
||||
this.name = name;
|
||||
this.age = age;
|
||||
}
|
||||
|
||||
@Override
|
||||
public String toString () {
|
||||
return "Employee{" + "name='" + name + '\'' + ", age=" + age + '}';
|
||||
}
|
||||
}
|
||||
|
||||
@FunctionalInterface
|
||||
interface EmployeeFactory {
|
||||
Employee getEmployee(String name, Integer age);
|
||||
}
|
||||
23
src/com/oracle/java8/associate/test/Greetings.java
Normal file
23
src/com/oracle/java8/associate/test/Greetings.java
Normal file
@@ -0,0 +1,23 @@
|
||||
package com.oracle.java8.associate.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();
|
||||
}
|
||||
}
|
||||
27
src/com/oracle/java8/associate/test/HighSchool.java
Normal file
27
src/com/oracle/java8/associate/test/HighSchool.java
Normal file
@@ -0,0 +1,27 @@
|
||||
package com.oracle.java8.associate.test;
|
||||
|
||||
import java.io.FileNotFoundException;
|
||||
import java.io.IOException;
|
||||
|
||||
class School {
|
||||
public int getNumberOfStudentsPerClassroom(String... students) throws IOException {
|
||||
return 3;
|
||||
}
|
||||
|
||||
public int getNumberOfStudentsPerClassroom() throws IOException {
|
||||
return 9;
|
||||
}
|
||||
}
|
||||
|
||||
public class HighSchool extends School {
|
||||
|
||||
@Override
|
||||
public int getNumberOfStudentsPerClassroom() throws FileNotFoundException {
|
||||
return 2;
|
||||
}
|
||||
|
||||
public static void main(String[] args) throws IOException {
|
||||
School school = new HighSchool();
|
||||
System.out.println(school.getNumberOfStudentsPerClassroom());
|
||||
}
|
||||
}
|
||||
28
src/com/oracle/java8/associate/test/InfiniteMath.java
Normal file
28
src/com/oracle/java8/associate/test/InfiniteMath.java
Normal file
@@ -0,0 +1,28 @@
|
||||
package com.oracle.java8.associate.test;
|
||||
|
||||
import java.io.FileNotFoundException;
|
||||
|
||||
class Math {
|
||||
public final double secret = 2;
|
||||
}
|
||||
|
||||
class ComplexMath extends Math {
|
||||
public final double secret = 4;
|
||||
|
||||
protected void dance() throws FileNotFoundException {
|
||||
return;
|
||||
}
|
||||
}
|
||||
|
||||
public class InfiniteMath extends ComplexMath {
|
||||
public final double secret = 8;
|
||||
public static void main(String[] args) {
|
||||
Math math = new InfiniteMath();
|
||||
System.out.println(math.secret);
|
||||
}
|
||||
|
||||
@Override
|
||||
public final void dance() {
|
||||
return;
|
||||
}
|
||||
}
|
||||
19
src/com/oracle/java8/associate/test/InitOrder.java
Normal file
19
src/com/oracle/java8/associate/test/InitOrder.java
Normal file
@@ -0,0 +1,19 @@
|
||||
package com.oracle.java8.associate.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();
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,21 @@
|
||||
package com.oracle.java8.associate.test;
|
||||
|
||||
abstract class Triangle {
|
||||
abstract String getDescription();
|
||||
}
|
||||
|
||||
class RightTriangle extends Triangle {
|
||||
@Override
|
||||
protected String getDescription() { return "rt"; } // g1
|
||||
}
|
||||
|
||||
public abstract class IsoscelesRightTriangle extends RightTriangle { // g2
|
||||
@Override
|
||||
public String getDescription() {
|
||||
return "irt";
|
||||
}
|
||||
|
||||
public static void main(String[] args) {
|
||||
//final Triangle shape = new IsoscelesRightTriangle(); // g3
|
||||
}
|
||||
}
|
||||
9
src/com/oracle/java8/associate/test/NewsPaper.java
Normal file
9
src/com/oracle/java8/associate/test/NewsPaper.java
Normal file
@@ -0,0 +1,9 @@
|
||||
package com.oracle.java8.associate.test;
|
||||
|
||||
abstract class NewsPaper extends Paper {
|
||||
|
||||
@Override
|
||||
public void getMargin() {
|
||||
}
|
||||
|
||||
}
|
||||
9
src/com/oracle/java8/associate/test/Paper.java
Normal file
9
src/com/oracle/java8/associate/test/Paper.java
Normal file
@@ -0,0 +1,9 @@
|
||||
package com.oracle.java8.associate.test;
|
||||
|
||||
abstract class Paper implements Printable {
|
||||
|
||||
@Override
|
||||
public void getMargin() {
|
||||
}
|
||||
|
||||
}
|
||||
9
src/com/oracle/java8/associate/test/Penguin.java
Normal file
9
src/com/oracle/java8/associate/test/Penguin.java
Normal file
@@ -0,0 +1,9 @@
|
||||
package com.oracle.java8.associate.test;
|
||||
|
||||
public class Penguin {
|
||||
private double beakLength;
|
||||
|
||||
public static void setBeakTLength(Penguin p, int b) {
|
||||
p.beakLength = b;
|
||||
}
|
||||
}
|
||||
21
src/com/oracle/java8/associate/test/Performance.java
Normal file
21
src/com/oracle/java8/associate/test/Performance.java
Normal file
@@ -0,0 +1,21 @@
|
||||
package com.oracle.java8.associate.test;
|
||||
|
||||
interface SpeakDialogue { default int talk() { return 7; } }
|
||||
interface SingMonologue { default int talk() { return 5; } }
|
||||
|
||||
public class Performance implements SpeakDialogue, SingMonologue {
|
||||
public int talk(String... x) {
|
||||
return x.length;
|
||||
}
|
||||
|
||||
// obbligato a fare l'override
|
||||
@Override
|
||||
public int talk() {
|
||||
// TODO Auto-generated metodoConParametroPrimitivo stub
|
||||
return SingMonologue.super.talk();
|
||||
}
|
||||
|
||||
public static void main(String[] notes) {
|
||||
System.out.println(new Performance().talk(notes));
|
||||
}
|
||||
}
|
||||
20
src/com/oracle/java8/associate/test/Phone.java
Normal file
20
src/com/oracle/java8/associate/test/Phone.java
Normal file
@@ -0,0 +1,20 @@
|
||||
package com.oracle.java8.associate.test;
|
||||
|
||||
public class Phone {
|
||||
private int size;
|
||||
|
||||
public Phone(int size) {
|
||||
this.size = size;
|
||||
}
|
||||
|
||||
public static void sendHome(Phone p, int newSize) {
|
||||
p = new Phone(newSize);
|
||||
p.size = 4;
|
||||
}
|
||||
|
||||
public static final void main(String... params) {
|
||||
final Phone phone = new Phone(3);
|
||||
sendHome(phone, 7);
|
||||
System.out.println(phone.size);
|
||||
}
|
||||
}
|
||||
9
src/com/oracle/java8/associate/test/Printable.java
Normal file
9
src/com/oracle/java8/associate/test/Printable.java
Normal file
@@ -0,0 +1,9 @@
|
||||
package com.oracle.java8.associate.test;
|
||||
|
||||
public interface Printable {
|
||||
|
||||
public void getMargin();
|
||||
|
||||
public void getOrientation();
|
||||
|
||||
}
|
||||
13
src/com/oracle/java8/associate/test/Puppy.java
Normal file
13
src/com/oracle/java8/associate/test/Puppy.java
Normal file
@@ -0,0 +1,13 @@
|
||||
package com.oracle.java8.associate.test;
|
||||
|
||||
public class Puppy {
|
||||
public static int wag = 5;
|
||||
|
||||
public void Puppy(int wag) {
|
||||
this.wag = wag;
|
||||
}
|
||||
|
||||
public static void main(String[] tail) {
|
||||
//System.out.println(new Puppy(2).wag); // q3
|
||||
}
|
||||
}
|
||||
17
src/com/oracle/java8/associate/test/RainForest.java
Normal file
17
src/com/oracle/java8/associate/test/RainForest.java
Normal file
@@ -0,0 +1,17 @@
|
||||
package com.oracle.java8.associate.test;
|
||||
|
||||
public class RainForest extends Forest {
|
||||
|
||||
public RainForest(long treeCount) {
|
||||
//this.treeCount = treeCount + 1;
|
||||
super(treeCount + 1);
|
||||
}
|
||||
}
|
||||
|
||||
class Forest {
|
||||
public long treeCount;
|
||||
|
||||
public Forest(long treeCount) {
|
||||
this.treeCount = treeCount + 2;
|
||||
}
|
||||
}
|
||||
16
src/com/oracle/java8/associate/test/Robot.java
Normal file
16
src/com/oracle/java8/associate/test/Robot.java
Normal file
@@ -0,0 +1,16 @@
|
||||
package com.oracle.java8.associate.test;
|
||||
|
||||
import java.io.EOFException;
|
||||
|
||||
class Machine {
|
||||
public boolean turnOn() throws EOFException { return true; }
|
||||
}
|
||||
|
||||
public class Robot extends Machine {
|
||||
@Override
|
||||
public boolean turnOn() { return false; }
|
||||
public static void main(String[] doesNotCompute) throws Exception {
|
||||
Machine m = new Robot();
|
||||
System.out.println(m.turnOn());
|
||||
}
|
||||
}
|
||||
21
src/com/oracle/java8/associate/test/SoccerBall.java
Normal file
21
src/com/oracle/java8/associate/test/SoccerBall.java
Normal file
@@ -0,0 +1,21 @@
|
||||
package com.oracle.java8.associate.test;
|
||||
|
||||
abstract class Ball {
|
||||
protected final int size;
|
||||
public Ball(int size) {
|
||||
this.size = size;
|
||||
}
|
||||
}
|
||||
|
||||
interface Equipment {}
|
||||
|
||||
public class SoccerBall extends Ball implements Equipment {
|
||||
public SoccerBall() {
|
||||
super(5);
|
||||
}
|
||||
public Ball get() { return this; }
|
||||
public static void main(String[] args) {
|
||||
Equipment equipment = (Equipment) (Ball) new SoccerBall().get();
|
||||
System.out.println(((SoccerBall) equipment).size);
|
||||
}
|
||||
}
|
||||
24
src/com/oracle/java8/associate/test/Sprint.java
Normal file
24
src/com/oracle/java8/associate/test/Sprint.java
Normal file
@@ -0,0 +1,24 @@
|
||||
package com.oracle.java8.associate.test;
|
||||
|
||||
interface Run {
|
||||
default void walk() {
|
||||
System.out.println("Walking and running!");
|
||||
}
|
||||
}
|
||||
|
||||
interface Jog {
|
||||
default void walk() {
|
||||
System.out.println("Walking and jogging!");
|
||||
}
|
||||
}
|
||||
|
||||
public class Sprint implements Run, Jog {
|
||||
@Override
|
||||
public void walk() {
|
||||
System.out.println("Sprinting!");
|
||||
}
|
||||
|
||||
public static void main(String[] args) {
|
||||
new Sprint().walk();
|
||||
}
|
||||
}
|
||||
17
src/com/oracle/java8/associate/test/Square.java
Normal file
17
src/com/oracle/java8/associate/test/Square.java
Normal file
@@ -0,0 +1,17 @@
|
||||
package com.oracle.java8.associate.test;
|
||||
|
||||
abstract class Parallelogram {
|
||||
private int getEqualSides() { return 0; }
|
||||
}
|
||||
|
||||
abstract class Rectangle extends Parallelogram {
|
||||
public static int getEqualSides() { return 2; } // x1
|
||||
}
|
||||
|
||||
public class Square extends Rectangle {
|
||||
//public int getEqualSides() { return 4; } //x2
|
||||
public static void main(String[] args) {
|
||||
final Square myFigure = new Square(); // x3
|
||||
System.out.print(myFigure.getEqualSides());
|
||||
}
|
||||
}
|
||||
24
src/com/oracle/java8/associate/test/StringTest.java
Normal file
24
src/com/oracle/java8/associate/test/StringTest.java
Normal file
@@ -0,0 +1,24 @@
|
||||
package com.oracle.java8.associate.test;
|
||||
|
||||
public class StringTest {
|
||||
|
||||
public static void main(String[] args) {
|
||||
String s = "anna";
|
||||
System.out.println(s.indexOf("g"));
|
||||
System.out.println((char) 99);
|
||||
System.out.println(s.replace('n', 'g'));
|
||||
System.out.println(s.concat("p"));
|
||||
|
||||
StringBuilder sb = new StringBuilder(8);
|
||||
System.out.println(sb.capacity());
|
||||
sb.append("Ciao");
|
||||
sb.insert(4, ", Mondo");
|
||||
sb.delete(4, 5);
|
||||
sb.replace(4, 5, ", ");
|
||||
sb.ensureCapacity(8);
|
||||
System.out.println(sb.length());
|
||||
System.out.println(sb.capacity());
|
||||
System.out.println(sb.toString());
|
||||
System.out.println(s.substring(0, 4));
|
||||
}
|
||||
}
|
||||
9
src/com/oracle/java8/associate/test/Test.java
Normal file
9
src/com/oracle/java8/associate/test/Test.java
Normal file
@@ -0,0 +1,9 @@
|
||||
package com.oracle.java8.associate.test;
|
||||
|
||||
public class Test {
|
||||
|
||||
public static void main(String[] args) {
|
||||
// TODO Auto-generated metodoConParametroPrimitivo stub
|
||||
}
|
||||
|
||||
}
|
||||
12
src/com/oracle/java8/associate/test/Toy.java
Normal file
12
src/com/oracle/java8/associate/test/Toy.java
Normal file
@@ -0,0 +1,12 @@
|
||||
package com.oracle.java8.associate.test;
|
||||
|
||||
public class Toy {
|
||||
|
||||
public void play() {
|
||||
System.out.println("play-");
|
||||
}
|
||||
|
||||
public void finalizer() {
|
||||
System.out.println("clean-");
|
||||
}
|
||||
}
|
||||
17
src/com/oracle/java8/associate/test/Tree.java
Normal file
17
src/com/oracle/java8/associate/test/Tree.java
Normal file
@@ -0,0 +1,17 @@
|
||||
package com.oracle.java8.associate.test;
|
||||
|
||||
public class Tree {
|
||||
public final static long numberOfTrees;
|
||||
public final double height;
|
||||
|
||||
static {}
|
||||
{
|
||||
final int initHeight = 2;
|
||||
height = initHeight;
|
||||
}
|
||||
|
||||
static {
|
||||
numberOfTrees = 100;
|
||||
//height = 4;
|
||||
}
|
||||
}
|
||||
10
src/com/oracle/java8/associate/test/Violin.java
Normal file
10
src/com/oracle/java8/associate/test/Violin.java
Normal file
@@ -0,0 +1,10 @@
|
||||
package com.oracle.java8.associate.test;
|
||||
|
||||
interface MusicCreator { public Number play(); }
|
||||
abstract class StringInstrument { public Long play() { return 3L; } }
|
||||
public class Violin extends StringInstrument implements MusicCreator {
|
||||
@Override
|
||||
public Long play() {
|
||||
return null;
|
||||
}
|
||||
}
|
||||
8
src/com/oracle/java8/associate/test/Week.java
Normal file
8
src/com/oracle/java8/associate/test/Week.java
Normal file
@@ -0,0 +1,8 @@
|
||||
package com.oracle.java8.associate.test;
|
||||
|
||||
public class Week {
|
||||
//private static final String monday;
|
||||
String tuesday;
|
||||
//final static wednesday = 3;
|
||||
final protected int thursday = 4;
|
||||
}
|
||||
21
src/com/oracle/java8/associate/test/WrapperTest.java
Normal file
21
src/com/oracle/java8/associate/test/WrapperTest.java
Normal file
@@ -0,0 +1,21 @@
|
||||
package com.oracle.java8.associate.test;
|
||||
|
||||
public class WrapperTest {
|
||||
|
||||
public static void main(String[] args) {
|
||||
Integer i = null;
|
||||
//metodoConParametroPrimitivo(i); /* Questa istruzione genere NullPointerException */
|
||||
i = new Integer(10);
|
||||
|
||||
System.out.println(i == 1);
|
||||
System.out.println(i.equals((int) 10L));
|
||||
System.out.println(i == 10L);
|
||||
|
||||
Byte b = new Byte(i.byteValue());
|
||||
System.out.println(b.equals((byte) 10));
|
||||
}
|
||||
|
||||
static void metodoConParametroPrimitivo(int i) {
|
||||
System.out.println(i);
|
||||
}
|
||||
}
|
||||
14
src/com/oracle/java8/associate/test/Zoologist.java
Normal file
14
src/com/oracle/java8/associate/test/Zoologist.java
Normal file
@@ -0,0 +1,14 @@
|
||||
package com.oracle.java8.associate.test;
|
||||
|
||||
class Canine {}
|
||||
class Dog extends Canine {}
|
||||
class Wolf extends Canine {}
|
||||
final class Husky extends Dog {}
|
||||
|
||||
public class Zoologist {
|
||||
Canine animal;
|
||||
public final void setAnimal(Dog animal) { this.animal = animal; }
|
||||
public static void main(String[] furryFriends) {
|
||||
new Zoologist().setAnimal(new Dog());
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user