diff --git a/src/Employee.java b/src/Employee.java new file mode 100644 index 0000000..8163bde --- /dev/null +++ b/src/Employee.java @@ -0,0 +1,21 @@ +/** + * Created by bbn on 4/18/16. + */ +public class Employee { + public int employeeId; + public String firstName, lastName; + public int yearStarted; + @Override public int hashCode() { + return employeeId; + } + public boolean equals(Employee e) { + return this.employeeId == e.employeeId; + } + public static void main(String[] args) { + Employee one = new Employee(); + one.employeeId = 101; + Employee two = new Employee(); + two.employeeId = 101; + if (one.equals(two)) System.out.println("Success"); + else System.out.println("Failure"); + } } \ No newline at end of file diff --git a/src/Sorted.java b/src/Sorted.java new file mode 100644 index 0000000..a4ed128 --- /dev/null +++ b/src/Sorted.java @@ -0,0 +1,26 @@ +/** + * + */ +import java.util.*; + +public class Sorted implements Comparable, Comparator { + private int num; + private String text; + Sorted(int n, String t) { + this.num = n; + this.text = t; + } + public String toString() { return "" + num; } + public int compareTo(Sorted s) { return text.compareTo(s.text); } + public int compare(Sorted s1, Sorted s2) { return s1.num - s2.num; } + public static void main(String[] args) { + Sorted s1 = new Sorted(88, "a"); + Sorted s2 = new Sorted(55, "b"); + TreeSet t1 = new TreeSet<>(); + t1.add(s1); + t1.add(s2); + TreeSet t2 = new TreeSet<>(s1); + t2.add(s1); + t2.add(s2); + System.out.println(t1 + " " + t2); + } } \ No newline at end of file diff --git a/src/Test.java b/src/Test.java new file mode 100644 index 0000000..ddb2244 --- /dev/null +++ b/src/Test.java @@ -0,0 +1,109 @@ +import enums.Season; + +import java.util.ArrayList; +import java.util.List; + +/** + * + */ +public class Test { + public static void main(Object[] args) { + System.out.println("Objects"); + } + + public static void main(Integer[] args) { + System.out.println("Integers"); + } + + public static void main(int[] args) { + System.out.println("int"); + } + + public static void main(String[] args) { + // Multiple variable of same type can be declared in one line + String a ="a", b ="b", c="c"; + int i=0, j=1; + + // Null can be concatenated + String s = null; +// s = s + 1; +// System.out.println(s); +// String x; +// String q[] = new String[5]; +// for (String å : q) +// System.out.println(å.concat(å + 111)); + + // ArrayList constructor, subList, addAll() + List s1 = new ArrayList<>(); + s1.add("a"); + s1.add("b"); + s1.add(1, "c"); + List s2 = new ArrayList<>(s1.subList(1, 1)); + s1.addAll(s2); + System.out.println(s1); + + // Lambda parameter must be unique in whole containing block + + // If condition requires boolean expression + + // No non-argument constructor in wrapper class + Integer it = new Integer(4); + + + int ad = 3; + boolean ttt = false; + while(ttt){ + ad = 4; + } + System.out.println(3.5 % 3); + + System.out.println(Integer.MIN_VALUE); + System.out.println(-Integer.MIN_VALUE); + System.out.println(Integer.MAX_VALUE); + System.out.println(-Integer.MAX_VALUE); + + // Wrapper class + System.out.println(Integer.valueOf(5)); + System.out.println(Integer.valueOf("5")); + System.out.println(Integer.parseInt("5")); + System.out.println(new Integer(5).intValue()); + System.out.println(new Integer(5).longValue()); // returns long + System.out.println(new Long("5").intValue()); // returns int + + System.out.println(Boolean.parseBoolean("")); + + + // Every wrapper classes has only 2 constructor + // 1. takes string in argument + // 2. takes their primitive value in argument + // No non-argument or no Wrapper object argumented contstructor + Short short1 = new Short((short)5); + Short short2 = new Short("5"); + + Boolean bool1 = new Boolean(true); + Boolean bool2 = new Boolean("false"); + + Byte byte1 = new Byte((byte)5); + Byte byte2 = new Byte("5"); + + short k = 97; + int o = 98; + float t = o; + o = (int)t; + System.out.println((char)k + ", " + (char)o); + System.out.println((char)k + ", " + (char)t); + + int ik = Integer.MAX_VALUE; + float f = ik; + System.out.println(ik); + System.out.println(f); + ik = (int)f; // Int to float requires explicit cast, but precision will be lost + System.out.println(ik == Integer.MAX_VALUE); + + Byte aaa = new Byte((byte)1); + Byte aab = new Byte(1); + Float aac = new Float(1.0); + + + } +} diff --git a/src/lambdas/NOTE.md b/src/lambdas/NOTE.md new file mode 100644 index 0000000..f28c71c --- /dev/null +++ b/src/lambdas/NOTE.md @@ -0,0 +1,16 @@ + + + + +There is one more issue you might see with lambdas. We’ve been defining an argument +list in our lambda expressions. Since Java doesn’t allow us to re‐declare a local variable, the +following is an issue: +(a, b) -> { int a = 0; return 5;} // DOES NOT COMPILE +(a, b) -> { int c = 0; return 5;} // COMPILES + + + + +ceilling(Object o) on Collections + + diff --git a/src/strings/Car.java b/src/strings/Car.java new file mode 100644 index 0000000..a5dcd35 --- /dev/null +++ b/src/strings/Car.java @@ -0,0 +1,33 @@ +package strings; + +/** + * Created by bbn on 4/8/16. + */ +public class Car { + String type = "Hatchbag"; + int speed = 100; + + Car() { + } + + Car(int speed, String type) { + this.speed = speed; + this.type = type; + } +} + +class Prosche extends Car { + String name; + + Prosche(String name) { + super(); + this.name = name; + } + + Prosche(int speed, String type, String name) { + super(speed, type); + this.name = name; + } + +} + diff --git a/src/strings/Frog.java b/src/strings/Frog.java new file mode 100644 index 0000000..8bae376 --- /dev/null +++ b/src/strings/Frog.java @@ -0,0 +1,13 @@ +package strings; + +/** + */ +public class Frog extends Cell { + private int i = 0; + protected void a() { } + void b() {} +} + +class Cell { + public int i = 0; +} \ No newline at end of file diff --git a/src/varargs/Tadpole.java b/src/varargs/Tadpole.java new file mode 100644 index 0000000..339dabe --- /dev/null +++ b/src/varargs/Tadpole.java @@ -0,0 +1,17 @@ +package varargs; + +import strings.*; +/** + */ +public class Tadpole extends Frog { + public static void main(String[] args) { + Tadpole t = new Tadpole(); + System.out.println(t.i); + t.a(); + t.b(); + Frog f = new Tadpole(); + f.a(); // DOES NOT COMPILE + ((Tadpole)f).a(); + f.b(); + } +}