renamed package

This commit is contained in:
Fabio Scotto di Santolo
2018-08-10 11:45:21 +02:00
parent ad11fe5454
commit bd39872f60
48 changed files with 51 additions and 50 deletions

View File

@@ -0,0 +1,20 @@
package com.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);
}
}

View 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 com.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;
}
}

View 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 com.oracle.associate.java8.test;
import com.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);
}
}

View File

@@ -0,0 +1,18 @@
package com.oracle.associate.java8.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");
}
}

View File

@@ -0,0 +1,14 @@
package com.oracle.associate.java8.test;
public abstract class BaseClass {
private String name;
public BaseClass(String name) {
this.name = name;
}
public String getName() {
return this.name;
}
}

View File

@@ -0,0 +1,21 @@
package com.oracle.associate.java8.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();
}
}

View File

@@ -0,0 +1,61 @@
package com.oracle.associate.java8.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;
}
}
}

View File

@@ -0,0 +1,11 @@
package com.oracle.associate.java8.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));
}
}

View 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 com.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));
}
}

View File

@@ -0,0 +1,9 @@
package com.oracle.associate.java8.test;
public class DerivatedClass extends BaseClass {
public DerivatedClass(String name) {
super(name);
}
}

View File

@@ -0,0 +1,10 @@
package com.oracle.associate.java8.test;
public class Drink {
public static void water() {}
public void get() {
Drink.water();
}
}

View File

@@ -0,0 +1,16 @@
package com.oracle.associate.java8.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());
}
}

View File

@@ -0,0 +1,13 @@
package com.oracle.associate.java8.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
}
}

View File

@@ -0,0 +1,23 @@
package com.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();
}
}

View File

@@ -0,0 +1,27 @@
package com.oracle.associate.java8.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());
}
}

View File

@@ -0,0 +1,28 @@
package com.oracle.associate.java8.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;
}
}

View File

@@ -0,0 +1,19 @@
package com.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();
}
}

View File

@@ -0,0 +1,21 @@
package com.oracle.associate.java8.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
}
}

View File

@@ -0,0 +1,9 @@
package com.oracle.associate.java8.test;
abstract class NewsPaper extends Paper {
@Override
public void getMargin() {
}
}

View File

@@ -0,0 +1,9 @@
package com.oracle.associate.java8.test;
abstract class Paper implements Printable {
@Override
public void getMargin() {
}
}

View File

@@ -0,0 +1,9 @@
package com.oracle.associate.java8.test;
public class Penguin {
private double beakLength;
public static void setBeakTLength(Penguin p, int b) {
p.beakLength = b;
}
}

View File

@@ -0,0 +1,21 @@
package com.oracle.associate.java8.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 method stub
return SingMonologue.super.talk();
}
public static void main(String[] notes) {
System.out.println(new Performance().talk(notes));
}
}

View File

@@ -0,0 +1,20 @@
package com.oracle.associate.java8.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);
}
}

View File

@@ -0,0 +1,9 @@
package com.oracle.associate.java8.test;
public interface Printable {
public void getMargin();
public void getOrientation();
}

View File

@@ -0,0 +1,13 @@
package com.oracle.associate.java8.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
}
}

View File

@@ -0,0 +1,17 @@
package com.oracle.associate.java8.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;
}
}

View File

@@ -0,0 +1,16 @@
package com.oracle.associate.java8.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());
}
}

View File

@@ -0,0 +1,21 @@
package com.oracle.associate.java8.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);
}
}

View File

@@ -0,0 +1,24 @@
package com.oracle.associate.java8.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();
}
}

View File

@@ -0,0 +1,17 @@
package com.oracle.associate.java8.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());
}
}

View File

@@ -0,0 +1,9 @@
package com.oracle.associate.java8.test;
public class Test {
public static void main(String[] args) {
// TODO Auto-generated method stub
}
}

View File

@@ -0,0 +1,12 @@
package com.oracle.associate.java8.test;
public class Toy {
public void play() {
System.out.println("play-");
}
public void finalizer() {
System.out.println("clean-");
}
}

View File

@@ -0,0 +1,17 @@
package com.oracle.associate.java8.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;
}
}

View File

@@ -0,0 +1,10 @@
package com.oracle.associate.java8.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;
}
}

View File

@@ -0,0 +1,8 @@
package com.oracle.associate.java8.test;
public class Week {
//private static final String monday;
String tuesday;
//final static wednesday = 3;
final protected int thursday = 4;
}

View File

@@ -0,0 +1,14 @@
package com.oracle.associate.java8.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());
}
}