From 2378d00b516fcdf0e3e73c5a5486f70bd62e1624 Mon Sep 17 00:00:00 2001 From: Guruprasad Kulkarni Date: Mon, 8 Jan 2018 18:19:07 +0100 Subject: [PATCH 1/5] removed other folders --- .../addition/CollectionOfMethods.java | 99 -------------- .../CompletableFutureAdditions.java | 41 ------ .../SimpleUserService.java | 32 ----- .../improvment/StreamsImprovements.java | 122 ------------------ .../trywithresources/TryWithResources.java | 47 ------- 5 files changed, 341 deletions(-) delete mode 100644 com/linux/java/se/nine/collection/addition/CollectionOfMethods.java delete mode 100644 com/linux/java/se/nine/completable/future/improvment/CompletableFutureAdditions.java delete mode 100644 com/linux/java/se/nine/privateinterfacemethods/SimpleUserService.java delete mode 100644 com/linux/java/se/nine/streams/improvment/StreamsImprovements.java delete mode 100644 com/linux/java/se/nine/trywithresources/TryWithResources.java diff --git a/com/linux/java/se/nine/collection/addition/CollectionOfMethods.java b/com/linux/java/se/nine/collection/addition/CollectionOfMethods.java deleted file mode 100644 index 204d606..0000000 --- a/com/linux/java/se/nine/collection/addition/CollectionOfMethods.java +++ /dev/null @@ -1,99 +0,0 @@ -package com.linux.java.se.nine.collection.addition; - -import java.util.Arrays; -import java.util.Collections; -import java.util.HashMap; -import java.util.HashSet; -import java.util.List; -import java.util.Map; -import java.util.Set; - -/** - * CollectionOfMethods - */ -public class CollectionOfMethods { - public static void main(String[] args) { - System.out.printf("%n%nPre Java 9 Vs Java 9 %s%n%n", "Lists"); - - // Old - List oldStyleList = Arrays.asList(1, 2, 3, 4, 5, 6, 7, 8, 9, 10); - print(oldStyleList, "oldStyleList"); - List oldStyleSingleElementList = Collections.singletonList(100); - print(oldStyleSingleElementList, "oldStyleSingleElementList"); - List oldStyleEmptyList = Collections.emptyList(); - print(oldStyleEmptyList, "oldStyleEmptyList"); - - System.out.printf("%n%n--%n%n"); - - // Java 9 - List newStyleList = List.of(1, 2, 3, 4, 5, 6, 7, 8, 9, 10); - print(newStyleList, "newStyleList"); - List newStyleSingleElementList = List.of(100); - print(newStyleSingleElementList, "newStyleSingleElementList"); - List newStyleEmptyList = List.of(); - print(newStyleEmptyList, "newStyleEmptyList"); - - System.out.printf("%n%nPre Java 9 Vs Java 9 %s%n%n", "Sets"); - // ---------- Sets ---------- - // Old - Set oldStyleSet = new HashSet<>(); - oldStyleSet.add("One"); - oldStyleSet.add("Two"); - oldStyleSet.add("Three"); - oldStyleSet.add("Four"); - oldStyleSet.add("Five"); - print(oldStyleSet, "oldStyleSet"); - - Set oldStyleSingleElementSet = Collections.singleton("Hundred!"); - print(oldStyleSingleElementSet, "oldStyleSingleElementSet"); - - Set oldStyleEmptySet = Collections.emptySet(); - print(oldStyleEmptySet, "oldStyleEmptySet"); - - System.out.printf("%n%n--%n%n"); - // Java 9 - Set newStyleSet = Set.of("One", "Two", "Three", "Four", "Five"); - print(newStyleSet, "newStyleSet"); - - Set newStyleSingleElementSet = Set.of("Hundred!"); - print(newStyleSingleElementSet, "newStyleSingleElementSet"); - - Set newStyleEmptySet = Set.of(); - print(newStyleEmptySet, "newStyleEmptySet"); - - System.out.printf("%n%nPre Java 9 Vs Java 9 %s%n%n", "Maps"); - Map oldStyleMap = new HashMap<>(); - oldStyleMap.put(1, "One"); - oldStyleMap.put(2, "Two"); - oldStyleMap.put(3, "Three"); - oldStyleMap.put(4, "Four"); - oldStyleMap.put(5, "Five"); - print(oldStyleMap, "oldStyleMap"); - - Map oldStyleBadMap = new HashMap<>(){{put(1, "One");put(2, "Two");put(3, "Three");put(4, "Four");put(5, "Five");}}; - print(oldStyleBadMap, "oldStyleBadMap"); - - Map oldStyleSingleElementMap = Collections.singletonMap(100, "Hundred!"); - print(oldStyleSingleElementMap, "oldStyleSingleElementMap"); - - Map oldStyleEmptyMap = Collections.emptyMap(); - print(oldStyleEmptyMap, "oldStyleEmptyMap"); - - System.out.printf("%n%n--%n%n"); - - Map newStyleMap = Map.of(1, "One", 2, "Two", 3, "Three", 4, "Four", 5, "Five"); - print(newStyleMap, "newStyleMap"); - - Map newStyleSingleElementMap = Map.of(1, "Hundred!"); - print(newStyleSingleElementMap, "newStyleSingleElementMap"); - - Map newStyleEmptyMap = Map.of(); - print(newStyleEmptyMap, "newStyleEmptyMap"); - } - - private static void print(Object c, String identifier) { - System.out.println(String.join("", Collections.nCopies(150, "-"))); - System.out.printf("%-30s :: Type : %-50s | Elements : %s%n",identifier, c.getClass(), c); - } - -} \ No newline at end of file diff --git a/com/linux/java/se/nine/completable/future/improvment/CompletableFutureAdditions.java b/com/linux/java/se/nine/completable/future/improvment/CompletableFutureAdditions.java deleted file mode 100644 index 459f601..0000000 --- a/com/linux/java/se/nine/completable/future/improvment/CompletableFutureAdditions.java +++ /dev/null @@ -1,41 +0,0 @@ -package com.linux.java.se.nine.completable.future.improvment; - -import java.util.concurrent.CompletableFuture; -import java.util.concurrent.TimeUnit; - -/** - * CompletableFutureAdditions - */ -public class CompletableFutureAdditions { - public static void main(String[] args) { - CompletableFutureAdditions additions = new CompletableFutureAdditions(); - CompletableFuture cf = CompletableFuture.supplyAsync(() -> additions.sleep(2)); - System.out.println(" Original Completable Future is done ?" + cf.isDone()); - - CompletableFuture newCopy = cf.copy(); - System.out.println(" Copy of Completable Future is done ?" + cf.isDone()); - newCopy.completeExceptionally(new InterruptedException("Some message")); - - CompletableFuture completeOnTimeOut = cf.copy().completeOnTimeout("Failed to complete", 1, TimeUnit.SECONDS); - System.out.println("Completable Future Complete on Timeout is done ?" + cf.isDone()); - - cf.thenAccept(System.out::println); - newCopy.thenAccept(System.out::println); - completeOnTimeOut.thenAccept(System.out::println); - - - additions.sleep(5); - - } - - - private String sleep(int sleepTimeSeconds) { - try { - Thread.sleep(TimeUnit.SECONDS.toMillis(sleepTimeSeconds)); - } catch (InterruptedException e) { - throw new RuntimeException(e); - } - return "Done : " + System.currentTimeMillis() + " By " + Thread.currentThread().getName(); - } - -} \ No newline at end of file diff --git a/com/linux/java/se/nine/privateinterfacemethods/SimpleUserService.java b/com/linux/java/se/nine/privateinterfacemethods/SimpleUserService.java deleted file mode 100644 index a782fab..0000000 --- a/com/linux/java/se/nine/privateinterfacemethods/SimpleUserService.java +++ /dev/null @@ -1,32 +0,0 @@ -package com.linux.java.se.nine.privateinterfacemethods; - -interface UserService{ - - default String getUser() { - return getUserFromEnv(); - } - - static String getSystemUser(){ - return getUserFromEnv(); - } - - private static String getUserFromEnv() { - return System.getenv("USER"); - } - -} - -public class SimpleUserService implements UserService{ - - @Override - public String getUser() { - return "john"; - } - - public static void main(String[] args) { - UserService s = new SimpleUserService(); - System.out.println("Current User :: " + s.getUser()); - System.out.println("Current System User :: " + UserService.getSystemUser()); - } - -} \ No newline at end of file diff --git a/com/linux/java/se/nine/streams/improvment/StreamsImprovements.java b/com/linux/java/se/nine/streams/improvment/StreamsImprovements.java deleted file mode 100644 index d3cbf0f..0000000 --- a/com/linux/java/se/nine/streams/improvment/StreamsImprovements.java +++ /dev/null @@ -1,122 +0,0 @@ -package com.linux.java.se.nine.streams.improvment; - -import java.time.LocalDate; -import java.time.Month; -import java.time.Period; -import java.util.Collections; -import java.util.Comparator; -import java.util.List; -import java.util.function.Predicate; -import java.util.stream.Stream; - -import static java.util.Comparator.comparing; -import static java.util.stream.Collectors.toList; - - -/** - * StreamsImprovements - */ - -public class StreamsImprovements { - private static final Book ej3e = new Book("Effective Java 3rd Edition", "Joshua Bloch", "978-0-13-468599-1", LocalDate.of(2017, Month.DECEMBER, 20)); - private static final Book cjs9fi = new Book("Core Java SE 9 for the Impatient, 2nd Edition", "Cay S. Horstmann", "978-0-13-469472-6", LocalDate.of(2017, Month.SEPTEMBER, 15)); - private static final Book j9fp = new Book("Java 9 for Programmers, 4th Edition", "Paul J. Deitel, Harvey Deitel", "978-0-13-477756-6", LocalDate.of(2017, Month.MAY, 11)); - private static final Book ej2e = new Book("Effective Java 2nd Edition", "Joshua Bloch", "978-0-321-35668-0", LocalDate.of(2008, Month.MAY, 8)); - private static final Book rwjeep = new Book("Real World Java EE Patterns", "Adam Bien", "978-1-300-14931-6", LocalDate.of(2012, Month.SEPTEMBER, 5)); - private static final Book rwjeenh = new Book("Real World Java EE Night Hacks", "Adam Bien", "978-0-557-07832-5", LocalDate.of(2008, Month.MAY, 8)); - - - public static void main(String[] args) { - Predicate publishDateGreaterThan2012 = b -> b.getPublishDate().getYear() > 2012; - - print(getBooks().collect(toList()), "***** Original List *****"); - - List booksWithSkip = getBooks() - .skip(3) - .collect(toList()); - print(booksWithSkip, "Java 8 ... skip 3"); - - List booksWithDropWhile = getBooks() - .dropWhile(publishDateGreaterThan2012) - .collect(toList()); - print(booksWithDropWhile, "Java 9 ... dropWhile publishDateGreaterThan2012"); - - List booksWithLimit = getBooks() - .limit(3) - .collect(toList()); - print(booksWithLimit, "Java 8 ... limit"); - - List booksWithTakeWhile = getBooks() - .takeWhile(publishDateGreaterThan2012) - .collect(toList()); - print(booksWithTakeWhile, "Java 9 ... takeWhile publishDateGreaterThan2012"); - - } - - - /** - * New recommendation from Joshua Bloch -- If you know that the callers of your method are happy using Stream as a return, use it!!!! - */ - private static Stream getBooks() { - return Stream.of(ej3e, cjs9fi, j9fp, ej2e, rwjeep, rwjeenh).sorted(comparing(Book::getPublishDate).reversed()); - } - - private static void print(List list, String identifier) { - System.out.println(identifier); - list.forEach(System.out::println); - System.out.println(String.join("", Collections.nCopies(150, "-"))); - } - - - static class Book { - private final String name; - private final String author; - private final String isbn; - private final LocalDate publishDate; - - Book(String name, String author, String isbn, LocalDate publishDate) { - this.name = name; - this.author = author; - this.isbn = isbn; - this.publishDate = publishDate; - } - - public Period getBookAgeinMonths() { - return Period.between(publishDate, LocalDate.now()); - } - - /** - * @return the name - */ - public String getName() { - return name; - } - - /** - * @return the isbn - */ - public String getIsbn() { - return isbn; - } - - /** - * @return the publishDate - */ - public LocalDate getPublishDate() { - return publishDate; - } - - /** - * @return the author - */ - public String getAuthor() { - return author; - } - - @Override - public String toString() { - return String.format("Book{name=%-50s\tauthor=%-30s\tisbn=%-20s\tpublishDate=%10s}", name, author, isbn, publishDate); - } - - } -} diff --git a/com/linux/java/se/nine/trywithresources/TryWithResources.java b/com/linux/java/se/nine/trywithresources/TryWithResources.java deleted file mode 100644 index 9edaefb..0000000 --- a/com/linux/java/se/nine/trywithresources/TryWithResources.java +++ /dev/null @@ -1,47 +0,0 @@ -package com.linux.java.se.nine.trywithresources; - -import java.util.concurrent.TimeUnit; - -class SimpleResource implements AutoCloseable{ - private final String name; - - SimpleResource(String name) { - this.name = name; - } - - public String doWork(String context) { - try{ - TimeUnit.SECONDS.sleep(2); - } catch(InterruptedException ie) { - throw new RuntimeException(ie); - } - return "Work Done for " + context; - } - - @Override - public void close() { - System.out.println("Resource " + name + " closed"); - } -} - -/** - * TryWithResources - */ -public class TryWithResources { - public static void main(String[] args) { - System.out.println("-- Before :: "); - try(SimpleResource res = new SimpleResource("insideTryWithResource")){ - String workResponse = res.doWork("old style try with resources"); - System.out.println(workResponse); - } - - - System.out.println("-- After :: "); - SimpleResource resource = new SimpleResource("OutsideTryWithResource"); - try(resource) { - String workResponse = resource.doWork("yay! java 9"); - System.out.println(workResponse); - } - - } -} \ No newline at end of file From 602079a6391029e5cc84c62a796c93bac04ec699 Mon Sep 17 00:00:00 2001 From: Guruprasad Kulkarni Date: Wed, 17 Jan 2018 16:08:25 +0100 Subject: [PATCH 2/5] Added command to run --- jpms/simple/com/linux/simple/SimpleUiApp.java | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) diff --git a/jpms/simple/com/linux/simple/SimpleUiApp.java b/jpms/simple/com/linux/simple/SimpleUiApp.java index d602bad..fc5d4c2 100644 --- a/jpms/simple/com/linux/simple/SimpleUiApp.java +++ b/jpms/simple/com/linux/simple/SimpleUiApp.java @@ -25,4 +25,7 @@ public void start(Stage primaryStage) { } } // export PATH=/usr/lib/jvm/java-9-oracle/bin:/usr/lib/jvm/java-9-oracle/db/bin:/usr/lib/jvm/java-9-oracle/jre/bin:$PATH -// find Java-9-Discovery -type f -name "*.class" -exec rm -v {} + -o -name "*.jar" -exec rm -v {} + \ No newline at end of file +// find Java-9-Discovery -type f -name "*.class" -exec rm -v {} + -o -name "*.jar" -exec rm -v {} + +// cd jpms +// javac simple/module-info.java simple/com/linux/simple/SimpleUiApp.java +// cd simple && java com.linux.simple.SimpleUiApp \ No newline at end of file From a253ceb24299a458789aa0754fd48c6a82debe37 Mon Sep 17 00:00:00 2001 From: Guruprasad Kulkarni Date: Thu, 18 Jan 2018 11:57:35 +0100 Subject: [PATCH 3/5] Updated readme --- README.md | 15 ++++++++++++++- 1 file changed, 14 insertions(+), 1 deletion(-) diff --git a/README.md b/README.md index 63bd836..de64bcd 100644 --- a/README.md +++ b/README.md @@ -1,4 +1,17 @@ # Java-9-Discovery Java 9 Meetup -For more details see https://github.com/gurukulkarni/Java-9-Discovery/wiki \ No newline at end of file +To run this program, you need to (of course install Java 9 and setup you PATH properly) +1. Change to the directory where this README.md is. +2. cd jpms +3. javac simple/module-info.java simple/com/linux/simple/SimpleUiApp.javasimple/com/linux/simple/generators/internal/DefaultContentsGenerator.java +4. cd simple && java com.linux.simple.SimpleUiApp + +Possibly more commands to run could be found : (at least better syntax highlighting) +https://github.com/gurukulkarni/Java-9-Discovery/blob/01-jpms/jpms/simple/com/linux/simple/SimpleUiApp.java + +For more details see https://github.com/gurukulkarni/Java-9-Discovery/wiki + +find . -type f -name "*.class" -exec rm -v {} + // linux (actually GNU) command to remove all .class files from the project. +This is needed so that when you switch with class files remaining and the directory structure changes, git cannot remove the directories as it is not empty. +And no too mention I am too lazy to figure out how to configure VS Code to sent proper command to force this. \ No newline at end of file From 8a0d40494fb58afb320900b1c164a3f534ca422e Mon Sep 17 00:00:00 2001 From: Guruprasad Kulkarni Date: Thu, 18 Jan 2018 12:08:30 +0100 Subject: [PATCH 4/5] Added blankspace --- README.md | 1 + 1 file changed, 1 insertion(+) diff --git a/README.md b/README.md index de64bcd..f479002 100644 --- a/README.md +++ b/README.md @@ -8,6 +8,7 @@ To run this program, you need to (of course install Java 9 and setup you PATH pr 4. cd simple && java com.linux.simple.SimpleUiApp Possibly more commands to run could be found : (at least better syntax highlighting) + https://github.com/gurukulkarni/Java-9-Discovery/blob/01-jpms/jpms/simple/com/linux/simple/SimpleUiApp.java For more details see https://github.com/gurukulkarni/Java-9-Discovery/wiki From 52746d6224ae4faac67b173ccc22537d6300d173 Mon Sep 17 00:00:00 2001 From: Guruprasad Kulkarni Date: Thu, 18 Jan 2018 12:18:02 +0100 Subject: [PATCH 5/5] Added whitespace --- README.md | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/README.md b/README.md index f479002..8dbd4e0 100644 --- a/README.md +++ b/README.md @@ -13,6 +13,8 @@ https://github.com/gurukulkarni/Java-9-Discovery/blob/01-jpms/jpms/simple/com/li For more details see https://github.com/gurukulkarni/Java-9-Discovery/wiki -find . -type f -name "*.class" -exec rm -v {} + // linux (actually GNU) command to remove all .class files from the project. +find . -type f -name "*.class" -exec rm -v {} + + +Linux (actually GNU) command to remove all .class files from the project. This is needed so that when you switch with class files remaining and the directory structure changes, git cannot remove the directories as it is not empty. And no too mention I am too lazy to figure out how to configure VS Code to sent proper command to force this. \ No newline at end of file