initial commit
This commit is contained in:
10
.classpath
Normal file
10
.classpath
Normal file
@@ -0,0 +1,10 @@
|
||||
<?xml version="1.0" encoding="UTF-8"?>
|
||||
<classpath>
|
||||
<classpathentry kind="con" path="org.eclipse.jdt.launching.JRE_CONTAINER/org.eclipse.jdt.internal.debug.ui.launcher.StandardVMType/JavaSE-1.8">
|
||||
<attributes>
|
||||
<attribute name="module" value="true"/>
|
||||
</attributes>
|
||||
</classpathentry>
|
||||
<classpathentry kind="src" path="src"/>
|
||||
<classpathentry kind="output" path="bin"/>
|
||||
</classpath>
|
||||
17
.project
Normal file
17
.project
Normal file
@@ -0,0 +1,17 @@
|
||||
<?xml version="1.0" encoding="UTF-8"?>
|
||||
<projectDescription>
|
||||
<name>OracleCertificationAssociateTest</name>
|
||||
<comment></comment>
|
||||
<projects>
|
||||
</projects>
|
||||
<buildSpec>
|
||||
<buildCommand>
|
||||
<name>org.eclipse.jdt.core.javabuilder</name>
|
||||
<arguments>
|
||||
</arguments>
|
||||
</buildCommand>
|
||||
</buildSpec>
|
||||
<natures>
|
||||
<nature>org.eclipse.jdt.core.javanature</nature>
|
||||
</natures>
|
||||
</projectDescription>
|
||||
11
.settings/org.eclipse.jdt.core.prefs
Normal file
11
.settings/org.eclipse.jdt.core.prefs
Normal file
@@ -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
|
||||
35
src/it/oracle/associate/java8/A.java
Normal file
35
src/it/oracle/associate/java8/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 it.oracle.associate.java8;
|
||||
|
||||
/**
|
||||
*
|
||||
* @author fscotto
|
||||
*/
|
||||
public class A {
|
||||
public int i1 = 1;
|
||||
protected int i2 = 2;
|
||||
}
|
||||
42
src/it/oracle/associate/java8/Animal.java
Normal file
42
src/it/oracle/associate/java8/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 it.oracle.associate.java8;
|
||||
|
||||
/**
|
||||
*
|
||||
* @author fscotto
|
||||
*/
|
||||
abstract class Animal {
|
||||
private String name;
|
||||
|
||||
Animal(String name) {
|
||||
this.name = name;
|
||||
}
|
||||
|
||||
public String getName() {
|
||||
return this.name;
|
||||
}
|
||||
}
|
||||
34
src/it/oracle/associate/java8/B.java
Normal file
34
src/it/oracle/associate/java8/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 it.oracle.associate.java8;
|
||||
|
||||
/**
|
||||
*
|
||||
* @author fscotto
|
||||
*/
|
||||
public class B extends A {
|
||||
|
||||
}
|
||||
43
src/it/oracle/associate/java8/Counter.java
Normal file
43
src/it/oracle/associate/java8/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 it.oracle.associate.java8;
|
||||
|
||||
/**
|
||||
*
|
||||
* @author fscotto
|
||||
*/
|
||||
class Counter {
|
||||
int counter;
|
||||
|
||||
Counter(int counter) {
|
||||
this.counter = counter;
|
||||
}
|
||||
|
||||
@Override
|
||||
public String toString() {
|
||||
return "Counter: " + this.counter;
|
||||
}
|
||||
}
|
||||
40
src/it/oracle/associate/java8/Dog.java
Normal file
40
src/it/oracle/associate/java8/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 it.oracle.associate.java8;
|
||||
|
||||
/**
|
||||
*
|
||||
* @author fscotto
|
||||
*/
|
||||
public class Dog extends Animal {
|
||||
|
||||
private String breed;
|
||||
|
||||
Dog(String name, String breed) {
|
||||
super(name);
|
||||
this.breed = breed;
|
||||
}
|
||||
}
|
||||
371
src/it/oracle/associate/java8/Exam1.java
Normal file
371
src/it/oracle/associate/java8/Exam1.java
Normal file
@@ -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<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();
|
||||
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/it/oracle/associate/java8/Exam2.java
Normal file
122
src/it/oracle/associate/java8/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 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);
|
||||
}
|
||||
|
||||
}
|
||||
38
src/it/oracle/associate/java8/Guest.java
Normal file
38
src/it/oracle/associate/java8/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 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);
|
||||
}
|
||||
}
|
||||
40
src/it/oracle/associate/java8/I1.java
Normal file
40
src/it/oracle/associate/java8/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 it.oracle.associate.java8;
|
||||
|
||||
/**
|
||||
*
|
||||
* @author fscotto
|
||||
*/
|
||||
public interface I1 {
|
||||
public void m1() throws java.io.IOException;
|
||||
}
|
||||
|
||||
|
||||
class C4 implements I1 {
|
||||
@Override
|
||||
public void m1() {}
|
||||
}
|
||||
45
src/it/oracle/associate/java8/Point.java
Normal file
45
src/it/oracle/associate/java8/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 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 + ")";
|
||||
}
|
||||
}
|
||||
45
src/it/oracle/associate/java8/Student.java
Normal file
45
src/it/oracle/associate/java8/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 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 + "]";
|
||||
}
|
||||
}
|
||||
20
src/it/oracle/associate/java8/test/Airplane.java
Normal file
20
src/it/oracle/associate/java8/test/Airplane.java
Normal file
@@ -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);
|
||||
}
|
||||
}
|
||||
119
src/it/oracle/associate/java8/test/ArrayTest.java
Normal file
119
src/it/oracle/associate/java8/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 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;
|
||||
}
|
||||
}
|
||||
44
src/it/oracle/associate/java8/test/B.java
Normal file
44
src/it/oracle/associate/java8/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 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);
|
||||
}
|
||||
|
||||
}
|
||||
14
src/it/oracle/associate/java8/test/BaseClass.java
Normal file
14
src/it/oracle/associate/java8/test/BaseClass.java
Normal file
@@ -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;
|
||||
}
|
||||
}
|
||||
57
src/it/oracle/associate/java8/test/DateTest.java
Normal file
57
src/it/oracle/associate/java8/test/DateTest.java
Normal file
@@ -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<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));
|
||||
|
||||
|
||||
}
|
||||
}
|
||||
9
src/it/oracle/associate/java8/test/DerivatedClass.java
Normal file
9
src/it/oracle/associate/java8/test/DerivatedClass.java
Normal file
@@ -0,0 +1,9 @@
|
||||
package it.oracle.associate.java8.test;
|
||||
|
||||
public class DerivatedClass extends BaseClass {
|
||||
|
||||
public DerivatedClass(String name) {
|
||||
super(name);
|
||||
}
|
||||
|
||||
}
|
||||
23
src/it/oracle/associate/java8/test/Greetings.java
Normal file
23
src/it/oracle/associate/java8/test/Greetings.java
Normal file
@@ -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();
|
||||
}
|
||||
}
|
||||
19
src/it/oracle/associate/java8/test/InitOrder.java
Normal file
19
src/it/oracle/associate/java8/test/InitOrder.java
Normal file
@@ -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();
|
||||
}
|
||||
}
|
||||
9
src/it/oracle/associate/java8/test/NewsPaper.java
Normal file
9
src/it/oracle/associate/java8/test/NewsPaper.java
Normal file
@@ -0,0 +1,9 @@
|
||||
package it.oracle.associate.java8.test;
|
||||
|
||||
abstract class NewsPaper extends Paper {
|
||||
|
||||
@Override
|
||||
public void getMargin() {
|
||||
}
|
||||
|
||||
}
|
||||
9
src/it/oracle/associate/java8/test/Paper.java
Normal file
9
src/it/oracle/associate/java8/test/Paper.java
Normal file
@@ -0,0 +1,9 @@
|
||||
package it.oracle.associate.java8.test;
|
||||
|
||||
abstract class Paper implements Printable {
|
||||
|
||||
@Override
|
||||
public void getMargin() {
|
||||
}
|
||||
|
||||
}
|
||||
9
src/it/oracle/associate/java8/test/Penguin.java
Normal file
9
src/it/oracle/associate/java8/test/Penguin.java
Normal file
@@ -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;
|
||||
}
|
||||
}
|
||||
9
src/it/oracle/associate/java8/test/Printable.java
Normal file
9
src/it/oracle/associate/java8/test/Printable.java
Normal file
@@ -0,0 +1,9 @@
|
||||
package it.oracle.associate.java8.test;
|
||||
|
||||
public interface Printable {
|
||||
|
||||
public void getMargin();
|
||||
|
||||
public void getOrientation();
|
||||
|
||||
}
|
||||
9
src/it/oracle/associate/java8/test/Test.java
Normal file
9
src/it/oracle/associate/java8/test/Test.java
Normal file
@@ -0,0 +1,9 @@
|
||||
package it.oracle.associate.java8.test;
|
||||
|
||||
public class Test {
|
||||
|
||||
public static void main(String[] args) {
|
||||
// TODO Auto-generated method stub
|
||||
}
|
||||
|
||||
}
|
||||
12
src/it/oracle/associate/java8/test/Toy.java
Normal file
12
src/it/oracle/associate/java8/test/Toy.java
Normal file
@@ -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-");
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user