diff --git a/annotations/AtUnitExample2.java b/annotations/AtUnitExample2.java index 44cf7552..a72282fa 100644 --- a/annotations/AtUnitExample2.java +++ b/annotations/AtUnitExample2.java @@ -28,7 +28,8 @@ public class AtUnitExample2 { } @Test void exceptionExample() throws IOException { - new FileInputStream("nofile.txt"); // Throws + try(FileInputStream fis = + new FileInputStream("nofile.txt")) {} // Throws } @Test boolean assertAndReturn() { diff --git a/annotations/UseCaseTracker.java b/annotations/UseCaseTracker.java index 4f60f30e..c6188e9f 100644 --- a/annotations/UseCaseTracker.java +++ b/annotations/UseCaseTracker.java @@ -14,7 +14,7 @@ public class UseCaseTracker { if(uc != null) { System.out.println("Found Use Case " + uc.id() + "\n " + uc.description()); - useCases.remove(new Integer(uc.id())); + useCases.remove(Integer.valueOf(uc.id())); } } useCases.forEach(i -> diff --git a/arrays/SimpleSetAll.java b/arrays/SimpleSetAll.java index ce281c97..1234eb59 100644 --- a/arrays/SimpleSetAll.java +++ b/arrays/SimpleSetAll.java @@ -14,7 +14,7 @@ class Bob { public class SimpleSetAll { public static final int SZ = 8; - public static int val = 1; + static int val = 1; static char[] chars = "abcdefghijklmnopqrstuvwxyz" .toCharArray(); static char getChar(int n) { return chars[n]; } diff --git a/collections/MapOfList.java b/collections/MapOfList.java index 151d4e1e..877ebd37 100644 --- a/collections/MapOfList.java +++ b/collections/MapOfList.java @@ -8,7 +8,7 @@ import typeinfo.pets.*; import java.util.*; public class MapOfList { - public static Map> + public static final Map> petPeople = new HashMap<>(); static { petPeople.put(new Person("Dawn"), diff --git a/collectiontopics/CanonicalMapping.java b/collectiontopics/CanonicalMapping.java index f3bbdae2..fecd6d3c 100644 --- a/collectiontopics/CanonicalMapping.java +++ b/collectiontopics/CanonicalMapping.java @@ -39,7 +39,7 @@ public class CanonicalMapping { int size = 1000; // Or, choose size via the command line: if(args.length > 0) - size = new Integer(args[0]); + size = Integer.valueOf(args[0]); Key[] keys = new Key[size]; WeakHashMap map = new WeakHashMap<>(); diff --git a/collectiontopics/References.java b/collectiontopics/References.java index ea99741f..30dfd45d 100644 --- a/collectiontopics/References.java +++ b/collectiontopics/References.java @@ -31,7 +31,7 @@ public class References { int size = 10; // Or, choose size via the command line: if(args.length > 0) - size = new Integer(args[0]); + size = Integer.valueOf(args[0]); LinkedList> sa = new LinkedList<>(); for(int i = 0; i < size; i++) { diff --git a/concurrent/CompletableOperations.java b/concurrent/CompletableOperations.java index 3d3e3f48..ffa06612 100644 --- a/concurrent/CompletableOperations.java +++ b/concurrent/CompletableOperations.java @@ -9,7 +9,7 @@ public class CompletableOperations { static CompletableFuture cfi(int i) { return CompletableFuture.completedFuture( - new Integer(i)); + Integer.valueOf(i)); } public static void main(String[] args) { showr(cfi(1)); // Basic test diff --git a/concurrent/CountingTask.java b/concurrent/CountingTask.java index ddcbacf1..1f3bbc2f 100644 --- a/concurrent/CountingTask.java +++ b/concurrent/CountingTask.java @@ -9,7 +9,7 @@ public class CountingTask implements Callable { public CountingTask(int id) { this.id = id; } @Override public Integer call() { - Integer val = new Integer(0); + Integer val = 0; for(int i = 0; i < 100; i++) val++; System.out.println(id + " " + diff --git a/concurrent/DiningPhilosophers.java b/concurrent/DiningPhilosophers.java index 13d08aca..2fc2e798 100644 --- a/concurrent/DiningPhilosophers.java +++ b/concurrent/DiningPhilosophers.java @@ -3,6 +3,7 @@ // We make no guarantees that this code is fit for any purpose. // Visit http://OnJava8.com for more book information. // Hidden deadlock +// {ValidateByHand} Gradle has trouble import java.util.*; import java.util.concurrent.*; import onjava.Nap; diff --git a/concurrent/InterferingTask.java b/concurrent/InterferingTask.java index 9ed9632b..4c564acc 100644 --- a/concurrent/InterferingTask.java +++ b/concurrent/InterferingTask.java @@ -5,7 +5,7 @@ public class InterferingTask implements Runnable { final int id; - private static Integer val = new Integer(0); + private static Integer val = 0; public InterferingTask(int id) { this.id = id; } @Override public void run() { diff --git a/concurrent/ParallelStreamPuzzle2.java b/concurrent/ParallelStreamPuzzle2.java index 881e0032..8f72fd76 100644 --- a/concurrent/ParallelStreamPuzzle2.java +++ b/concurrent/ParallelStreamPuzzle2.java @@ -10,7 +10,7 @@ import java.util.concurrent.atomic.*; import java.nio.file.*; public class ParallelStreamPuzzle2 { - public static Deque trace = + public static final Deque trace = new ConcurrentLinkedDeque<>(); static class IntGenerator implements Supplier { diff --git a/equalshashcode/Equality.java b/equalshashcode/Equality.java index 4fd0e36a..07e37a41 100644 --- a/equalshashcode/Equality.java +++ b/equalshashcode/Equality.java @@ -46,7 +46,7 @@ public class Equality { neq = eqf.make(99, "Bob", 1.618); e.test("null", "false", null); e.test("same object", "true", e); - e.test("different type", "false", new Integer(99)); + e.test("different type", "false", Integer.valueOf(99)); e.test("same values", "true", eq); e.test("different values", "false", neq); } diff --git a/functional/Closure7.java b/functional/Closure7.java index f67a6b58..bb7f54ea 100644 --- a/functional/Closure7.java +++ b/functional/Closure7.java @@ -7,7 +7,7 @@ import java.util.function.*; public class Closure7 { IntSupplier makeFun(int x) { - Integer i = new Integer(0); + Integer i = Integer.valueOf(0); i = i + 1; return () -> x + i; } diff --git a/innerclasses/GreenhouseController.java b/innerclasses/GreenhouseController.java index e39a470f..6e85f483 100644 --- a/innerclasses/GreenhouseController.java +++ b/innerclasses/GreenhouseController.java @@ -24,7 +24,7 @@ public class GreenhouseController { if(args.length == 1) gc.addEvent( new GreenhouseControls.Terminate( - new Integer(args[0]))); + Integer.valueOf(args[0]))); gc.run(); } } diff --git a/operators/EqualsMethod.java b/operators/EqualsMethod.java index baa3877d..50c5a8ff 100644 --- a/operators/EqualsMethod.java +++ b/operators/EqualsMethod.java @@ -5,8 +5,8 @@ public class EqualsMethod { public static void main(String[] args) { - Integer n1 = new Integer(47); - Integer n2 = new Integer(47); + Integer n1 = 47; + Integer n2 = 47; System.out.println(n1.equals(n2)); } } diff --git a/operators/Equivalence.java b/operators/Equivalence.java index a3d26fd1..26a89490 100644 --- a/operators/Equivalence.java +++ b/operators/Equivalence.java @@ -5,8 +5,8 @@ public class Equivalence { public static void main(String[] args) { - Integer n1 = new Integer(47); - Integer n2 = new Integer(47); + Integer n1 = 47; + Integer n2 = 47; System.out.println(n1 == n2); System.out.println(n1 != n2); } diff --git a/serialization/Blips.java b/serialization/Blips.java index 345752da..4a98f123 100644 --- a/serialization/Blips.java +++ b/serialization/Blips.java @@ -6,7 +6,7 @@ import java.io.*; class Blip1 implements Externalizable { - Blip1() { + public Blip1() { System.out.println("Blip1 Constructor"); } @Override diff --git a/serialization/FreezeAlien.java b/serialization/FreezeAlien.java index 701b6987..ec046d8b 100644 --- a/serialization/FreezeAlien.java +++ b/serialization/FreezeAlien.java @@ -8,9 +8,12 @@ import java.io.*; public class FreezeAlien { public static void main(String[] args) throws Exception { - ObjectOutput out = new ObjectOutputStream( - new FileOutputStream("X.file")); - Alien quellek = new Alien(); - out.writeObject(quellek); + try( + ObjectOutputStream out = new ObjectOutputStream( + new FileOutputStream("X.file")); + ) { + Alien quellek = new Alien(); + out.writeObject(quellek); + } } }