├── .gitignore ├── LICENSE ├── src └── main │ └── java │ └── me │ └── sumithpuri │ └── github │ └── singapore │ ├── jdk8 │ └── defaultinterface │ │ ├── jdk8_PreJava9BusinessService.java │ │ ├── jdk8_Java9BusinessService.java │ │ └── jdk8_PreJava9BusinessInterface.java │ ├── safevarargs │ └── jdk9_SafeVarargsOnPrivateMethod.java │ ├── enhanceddeprecation │ └── jdk9_EnhancedDeprecation.java │ ├── illegalunderscore │ └── jdk9_VariableNaming.java │ ├── conveniencecollections │ └── jdk9_ConvenienceCollections.java │ ├── privatedefaultinterface │ └── jdk9_PrivateMethodInterface.java │ ├── diamondanyonymous │ └── jdk9_DiamondOperatorOnAnonymous.java │ ├── tryresources │ └── jdk9_EffectivelyFinalTryResources.java │ ├── processapi │ └── jdk9_ProcessAPIChanges.java │ └── main │ └── jdk9_Singapore.java ├── pom.xml └── README.md /.gitignore: -------------------------------------------------------------------------------- 1 | /target/ 2 | -------------------------------------------------------------------------------- /LICENSE: -------------------------------------------------------------------------------- 1 | MIT License 2 | 3 | Copyright (c) 2018 Sumith Kumar Puri 4 | 5 | [Refer Each Code File for the Actual Licence Statement] 6 | -------------------------------------------------------------------------------- /src/main/java/me/sumithpuri/github/singapore/jdk8/defaultinterface/jdk8_PreJava9BusinessService.java: -------------------------------------------------------------------------------- 1 | package me.sumithpuri.github.singapore.jdk8.defaultinterface; 2 | 3 | /** 4 | * MIT License 5 | * 6 | * Copyright (c) 2018-19, Sumith Kumar Puri 7 | 8 | * GitHub URL https://github.com/sumithpuri 9 | * Blog Post URL http://www.techilashots.com/2018/09/java-se-9-whats-new-code-samples-0102.html 10 | * Blog Short URL https://goo.gl/dpxjEU 11 | * Package Prefix me.sumithpuri.github.singapore 12 | * Project Codename singapore 13 | * Contact E-Mail code@sumithpuri.me 14 | * Contact WhatsApp +91 9591497974 15 | * 16 | * 17 | * Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated 18 | * documentation files (the "Software"), to deal in the Software without restriction, including without limitation the 19 | * rights to use, copy, modify, merge, publish, distribute, sub-license and/or sell copies of the Software and to permit 20 | * persons to whom the Software is furnished to do so, subject to the following conditions: 21 | * 22 | * The above copyright notice and this permission notice shall be included in all copies or substantial portions of the 23 | * Software. 24 | * 25 | * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE 26 | * WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR 27 | * COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR 28 | * OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. 29 | */ 30 | public class jdk8_PreJava9BusinessService implements jdk8_PreJava9BusinessInterface { 31 | 32 | @Override 33 | public void doLegacyBusinessMethodOne() { 34 | 35 | System.out.println("Core Business Method One"); 36 | } 37 | 38 | @Override 39 | public void doLegacyBusinessMethodTwo() { 40 | 41 | System.out.println("Core Business Method Two"); 42 | } 43 | } 44 | -------------------------------------------------------------------------------- /src/main/java/me/sumithpuri/github/singapore/safevarargs/jdk9_SafeVarargsOnPrivateMethod.java: -------------------------------------------------------------------------------- 1 | package me.sumithpuri.github.singapore.safevarargs; 2 | 3 | /** 4 | * MIT License 5 | * 6 | * Copyright (c) 2018-19, Sumith Kumar Puri 7 | 8 | * GitHub URL https://github.com/sumithpuri 9 | * Blog Post URL http://www.techilashots.com/2018/09/java-se-9-whats-new-code-samples-0102.html 10 | * Blog Short URL https://goo.gl/dpxjEU 11 | * Package Prefix me.sumithpuri.github.singapore 12 | * Project Codename singapore 13 | * Contact E-Mail code@sumithpuri.me 14 | * Contact WhatsApp +91 9591497974 15 | * 16 | * 17 | * Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated 18 | * documentation files (the "Software"), to deal in the Software without restriction, including without limitation the 19 | * rights to use, copy, modify, merge, publish, distribute, sub-license and/or sell copies of the Software and to permit 20 | * persons to whom the Software is furnished to do so, subject to the following conditions: 21 | * 22 | * The above copyright notice and this permission notice shall be included in all copies or substantial portions of the 23 | * Software. 24 | * 25 | * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE 26 | * WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR 27 | * COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR 28 | * OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. 29 | */ 30 | public class jdk9_SafeVarargsOnPrivateMethod { 31 | 32 | public void demoSafeVarargsInJava9() { 33 | 34 | safeVarargsInJava9(24.00f, 03, 19, 82); 35 | } 36 | 37 | @SafeVarargs 38 | private void safeVarargsInJava9 (Float a, Integer... b) { 39 | 40 | System.out.println("Invoked a Private Instance Method with " + a + ", " + b[0] + ", " + b[1] + ", " + b[2]); 41 | System.out.println("With Java 9, @SafeVarargs is Allowed on Private Instance Methods!"); 42 | } 43 | } 44 | -------------------------------------------------------------------------------- /src/main/java/me/sumithpuri/github/singapore/enhanceddeprecation/jdk9_EnhancedDeprecation.java: -------------------------------------------------------------------------------- 1 | package me.sumithpuri.github.singapore.enhanceddeprecation; 2 | 3 | /** 4 | * MIT License 5 | * 6 | * Copyright (c) 2018-19, Sumith Kumar Puri 7 | 8 | * GitHub URL https://github.com/sumithpuri 9 | * Blog Post URL http://www.techilashots.com/2018/09/java-se-9-whats-new-code-samples-0102.html 10 | * Blog Short URL https://goo.gl/dpxjEU 11 | * Package Prefix me.sumithpuri.github.singapore 12 | * Project Codename singapore 13 | * Contact E-Mail code@sumithpuri.me 14 | * Contact WhatsApp +91 9591497974 15 | * 16 | * 17 | * Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated 18 | * documentation files (the "Software"), to deal in the Software without restriction, including without limitation the 19 | * rights to use, copy, modify, merge, publish, distribute, sub-license and/or sell copies of the Software and to permit 20 | * persons to whom the Software is furnished to do so, subject to the following conditions: 21 | * 22 | * The above copyright notice and this permission notice shall be included in all copies or substantial portions of the 23 | * Software. 24 | * 25 | * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE 26 | * WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR 27 | * COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR 28 | * OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. 29 | */ 30 | public class jdk9_EnhancedDeprecation { 31 | 32 | @Deprecated(forRemoval=true) 33 | public void methodMarkedForRemoval() { 34 | 35 | System.out.println("Java 9 Allows Enhanced Method Deprecation"); 36 | System.out.println("Invoked Method is Deprecated and Marked [For Removal]"); 37 | this.methodDeprecatedSince(); 38 | } 39 | 40 | @Deprecated(since="12.2") 41 | public void methodDeprecatedSince() { 42 | System.out.println("Invoked Method is Deprecated and Marked [Since]"); 43 | } 44 | } 45 | -------------------------------------------------------------------------------- /src/main/java/me/sumithpuri/github/singapore/illegalunderscore/jdk9_VariableNaming.java: -------------------------------------------------------------------------------- 1 | package me.sumithpuri.github.singapore.illegalunderscore; 2 | 3 | /** 4 | * MIT License 5 | * 6 | * Copyright (c) 2018-19, Sumith Kumar Puri 7 | 8 | * GitHub URL https://github.com/sumithpuri 9 | * Blog Post URL http://www.techilashots.com/2018/09/java-se-9-whats-new-code-samples-0102.html 10 | * Blog Short URL https://goo.gl/dpxjEU 11 | * Package Prefix me.sumithpuri.github.singapore 12 | * Project Codename singapore 13 | * Contact E-Mail code@sumithpuri.me 14 | * Contact WhatsApp +91 9591497974 15 | * 16 | * 17 | * Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated 18 | * documentation files (the "Software"), to deal in the Software without restriction, including without limitation the 19 | * rights to use, copy, modify, merge, publish, distribute, sub-license and/or sell copies of the Software and to permit 20 | * persons to whom the Software is furnished to do so, subject to the following conditions: 21 | * 22 | * The above copyright notice and this permission notice shall be included in all copies or substantial portions of the 23 | * Software. 24 | * 25 | * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE 26 | * WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR 27 | * COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR 28 | * OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. 29 | */ 30 | public class jdk9_VariableNaming { 31 | 32 | // pre-java 9, this was a valid variable name 33 | // from java 8, _ was marked as a reserved keyword 34 | // from java 9, the following line of code will cause compilation failure 35 | // private String _; 36 | private String _socket = null; 37 | 38 | /** 39 | * @param args 40 | */ 41 | public void notForDemoMethod() { 42 | 43 | _socket = new String("Network Socket"); 44 | System.out.println("_ is no Longer a Valid Variable Name!, [Variable Value: " + _socket + "]"); 45 | } 46 | } 47 | -------------------------------------------------------------------------------- /src/main/java/me/sumithpuri/github/singapore/conveniencecollections/jdk9_ConvenienceCollections.java: -------------------------------------------------------------------------------- 1 | package me.sumithpuri.github.singapore.conveniencecollections; 2 | 3 | import java.util.Set; 4 | 5 | /** 6 | * MIT License 7 | * 8 | * Copyright (c) 2018-19, Sumith Kumar Puri 9 | 10 | * GitHub URL https://github.com/sumithpuri 11 | * Blog Post URL http://www.techilashots.com/2018/09/java-se-9-whats-new-code-samples-0102.html 12 | * Blog Short URL https://goo.gl/dpxjEU 13 | * Package Prefix me.sumithpuri.github.singapore 14 | * Project Codename singapore 15 | * Contact E-Mail code@sumithpuri.me 16 | * Contact WhatsApp +91 9591497974 17 | * 18 | * 19 | * Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated 20 | * documentation files (the "Software"), to deal in the Software without restriction, including without limitation the 21 | * rights to use, copy, modify, merge, publish, distribute, sub-license and/or sell copies of the Software and to permit 22 | * persons to whom the Software is furnished to do so, subject to the following conditions: 23 | * 24 | * The above copyright notice and this permission notice shall be included in all copies or substantial portions of the 25 | * Software. 26 | * 27 | * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE 28 | * WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR 29 | * COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR 30 | * OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. 31 | */ 32 | public class jdk9_ConvenienceCollections { 33 | 34 | public void checkItOut() { 35 | 36 | System.out.println("Java 9 Introduced a Static [of()] Factory Method"); 37 | System.out.println("This allows Creation of Immutable Collections"); 38 | 39 | Set immutableCountrySet = Set.of("America", "Russia", "China", "India"); 40 | 41 | try { 42 | 43 | immutableCountrySet.add("England"); 44 | } catch (Exception e) { 45 | 46 | System.out.println("Caught Exception, Adding Entry to Immutable Collection!"); 47 | } 48 | } 49 | } -------------------------------------------------------------------------------- /src/main/java/me/sumithpuri/github/singapore/privatedefaultinterface/jdk9_PrivateMethodInterface.java: -------------------------------------------------------------------------------- 1 | package me.sumithpuri.github.singapore.privatedefaultinterface; 2 | 3 | /** 4 | * MIT License 5 | * 6 | * Copyright (c) 2018-19, Sumith Kumar Puri 7 | 8 | * GitHub URL https://github.com/sumithpuri 9 | * Blog Post URL http://www.techilashots.com/2018/09/java-se-9-whats-new-code-samples-0102.html 10 | * Blog Short URL https://goo.gl/dpxjEU 11 | * Package Prefix me.sumithpuri.github.singapore 12 | * Project Codename singapore 13 | * Contact E-Mail code@sumithpuri.me 14 | * Contact WhatsApp +91 9591497974 15 | * 16 | * 17 | * Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated 18 | * documentation files (the "Software"), to deal in the Software without restriction, including without limitation the 19 | * rights to use, copy, modify, merge, publish, distribute, sub-license and/or sell copies of the Software and to permit 20 | * persons to whom the Software is furnished to do so, subject to the following conditions: 21 | * 22 | * The above copyright notice and this permission notice shall be included in all copies or substantial portions of the 23 | * Software. 24 | * 25 | * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE 26 | * WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR 27 | * COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR 28 | * OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. 29 | */ 30 | public interface jdk9_PrivateMethodInterface { 31 | 32 | public void preJava9BusinessMethodOne(); 33 | 34 | public void preJava9BusinessMethodTwo(); 35 | 36 | public default void newJava9BusinessMethodThree() { 37 | 38 | System.out.println("Interface Methods can call Private Interface Methods!"); 39 | System.out.println(""); 40 | java9BusinessMethodThreeHelper(); 41 | } 42 | 43 | private void java9BusinessMethodThreeHelper() { 44 | 45 | System.out.println("Default Methods... Now Private Methods!"); 46 | System.out.println("Once Upon a Time, I was a Java Developer!"); 47 | } 48 | } 49 | -------------------------------------------------------------------------------- /pom.xml: -------------------------------------------------------------------------------- 1 | 4 | 4.0.0 5 | 6 | me.sumithpuri.github 7 | skp-code-marathon-singapore 8 | 0.0.1-SNAPSHOT 9 | jar 10 | 11 | Singapore : Java SE 9 Code Samples (01/02) 12 | http://maven.apache.org 13 | 14 | 15 | 16 | UTF-8 17 | 9 18 | 9 19 | false 20 | 21 | 22 | 23 | 24 | junit 25 | junit 26 | 3.8.1 27 | test 28 | 29 | 30 | 31 | 32 | 33 | 34 | org.apache.maven.plugins 35 | maven-compiler-plugin 36 | 3.6.1 37 | 38 | 39 | org.codehaus.mojo 40 | exec-maven-plugin 41 | 1.6.0 42 | 43 | 44 | test 45 | 46 | java 47 | 48 | 49 | me.sumithpuri.github.singapore.main.jdk9_Singapore 50 | true 51 | 52 | 53 | 54 | 55 | 56 | org.apache.maven.plugins 57 | maven-jar-plugin 58 | 3.1.0 59 | 60 | 61 | 62 | true 63 | me.sumithpuri.github.singapore.main.jdk9_Singapore 64 | 65 | 66 | 67 | 68 | 69 | 70 | Code Samples for the Blog Article [Java SE 9... What's New? (01/02)] 71 | 72 | -------------------------------------------------------------------------------- /src/main/java/me/sumithpuri/github/singapore/diamondanyonymous/jdk9_DiamondOperatorOnAnonymous.java: -------------------------------------------------------------------------------- 1 | package me.sumithpuri.github.singapore.diamondanyonymous; 2 | 3 | import java.io.Serializable; 4 | 5 | /** 6 | * MIT License 7 | * 8 | * Copyright (c) 2018-19, Sumith Kumar Puri 9 | 10 | * GitHub URL https://github.com/sumithpuri 11 | * Blog Post URL http://www.techilashots.com/2018/09/java-se-9-whats-new-code-samples-0102.html 12 | * Blog Short URL https://goo.gl/dpxjEU 13 | * Package Prefix me.sumithpuri.github.singapore 14 | * Project Codename singapore 15 | * Contact E-Mail code@sumithpuri.me 16 | * Contact WhatsApp +91 9591497974 17 | * 18 | * 19 | * Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated 20 | * documentation files (the "Software"), to deal in the Software without restriction, including without limitation the 21 | * rights to use, copy, modify, merge, publish, distribute, sub-license and/or sell copies of the Software and to permit 22 | * persons to whom the Software is furnished to do so, subject to the following conditions: 23 | * 24 | * The above copyright notice and this permission notice shall be included in all copies or substantial portions of the 25 | * Software. 26 | * 27 | * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE 28 | * WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR 29 | * COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR 30 | * OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. 31 | */ 32 | public class jdk9_DiamondOperatorOnAnonymous { 33 | 34 | public void diamondForInferredDenotable() { 35 | 36 | //prior to java 9, anonymous inner classes were not allowed to use diamond operator 37 | Java5ToJava8Coder java9SyntaxGuru = new Java5ToJava8Coder<>() { 38 | 39 | @Override 40 | public void java9SyntaxMagic() { 41 | 42 | System.out.println("Introduced in Java 5, Generics was Intriguing and Complex!"); 43 | System.out.println("With Java 9, Diamond Operator On Anonymous Classes is Allowed..."); 44 | System.out.println("As Long as Java 9 Infers the Type (Inferred) to be Denotable."); 45 | } 46 | }; 47 | 48 | java9SyntaxGuru.java9SyntaxMagic(); 49 | } 50 | } 51 | 52 | abstract class Java5ToJava8Coder { 53 | 54 | public abstract void java9SyntaxMagic(); 55 | } 56 | 57 | 58 | 59 | -------------------------------------------------------------------------------- /src/main/java/me/sumithpuri/github/singapore/tryresources/jdk9_EffectivelyFinalTryResources.java: -------------------------------------------------------------------------------- 1 | package me.sumithpuri.github.singapore.tryresources; 2 | 3 | import java.io.BufferedReader; 4 | import java.io.File; 5 | import java.io.FileReader; 6 | import java.io.IOException; 7 | 8 | /** 9 | * MIT License 10 | * 11 | * Copyright (c) 2018-19, Sumith Kumar Puri 12 | 13 | * GitHub URL https://github.com/sumithpuri 14 | * Blog Post URL http://www.techilashots.com/2018/09/java-se-9-whats-new-code-samples-0102.html 15 | * Blog Short URL https://goo.gl/dpxjEU 16 | * Package Prefix me.sumithpuri.github.singapore 17 | * Project Codename singapore 18 | * Contact E-Mail code@sumithpuri.me 19 | * Contact WhatsApp +91 9591497974 20 | * 21 | * 22 | * Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated 23 | * documentation files (the "Software"), to deal in the Software without restriction, including without limitation the 24 | * rights to use, copy, modify, merge, publish, distribute, sub-license and/or sell copies of the Software and to permit 25 | * persons to whom the Software is furnished to do so, subject to the following conditions: 26 | * 27 | * The above copyright notice and this permission notice shall be included in all copies or substantial portions of the 28 | * Software. 29 | * 30 | * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE 31 | * WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR 32 | * COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR 33 | * OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. 34 | */ 35 | public class jdk9_EffectivelyFinalTryResources { 36 | 37 | private static File file = new File("try_resources.j9"); 38 | 39 | //with java 9, you need to use either explicitly final or effectively final variables in try/resources 40 | 41 | public void methodWithAnomaly() throws IOException { 42 | 43 | file.createNewFile(); 44 | BufferedReader bufferedReader = new BufferedReader(new FileReader(file)); 45 | 46 | //prior to java 9, the usage would look like this 47 | //try (final BufferedReader bufferedReader = new BufferedReader(new FileReader(file))) { 48 | 49 | //this code will not compile before java 9 50 | try (bufferedReader) { 51 | 52 | System.out.println("Can Use Final or Effectively Final in Try with Resources!"); 53 | } finally { 54 | 55 | System.out.println("Java 9 Gives More Flexibility to Developers."); 56 | } 57 | } 58 | } 59 | -------------------------------------------------------------------------------- /src/main/java/me/sumithpuri/github/singapore/jdk8/defaultinterface/jdk8_Java9BusinessService.java: -------------------------------------------------------------------------------- 1 | package me.sumithpuri.github.singapore.jdk8.defaultinterface; 2 | 3 | /** 4 | * MIT License 5 | * 6 | * Copyright (c) 2018-19, Sumith Kumar Puri 7 | 8 | * GitHub URL https://github.com/sumithpuri 9 | * Blog Post URL http://www.techilashots.com/2018/09/java-se-9-whats-new-code-samples-0102.html 10 | * Blog Short URL https://goo.gl/dpxjEU 11 | * Package Prefix me.sumithpuri.github.singapore 12 | * Project Codename singapore 13 | * Contact E-Mail code@sumithpuri.me 14 | * Contact WhatsApp +91 9591497974 15 | * 16 | * 17 | * Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated 18 | * documentation files (the "Software"), to deal in the Software without restriction, including without limitation the 19 | * rights to use, copy, modify, merge, publish, distribute, sub-license and/or sell copies of the Software and to permit 20 | * persons to whom the Software is furnished to do so, subject to the following conditions: 21 | * 22 | * The above copyright notice and this permission notice shall be included in all copies or substantial portions of the 23 | * Software. 24 | * 25 | * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE 26 | * WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR 27 | * COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR 28 | * OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. 29 | */ 30 | public class jdk8_Java9BusinessService implements jdk8_PreJava9BusinessInterface { 31 | 32 | /* 33 | * [the requirement now changes to add a new business method [doLegacyBusinessMethodThree()] 34 | * - 35 | * [with this, disruption will be caused to internal and externally packaged implementations 36 | * [before java 8, external systems integrating with the api have to re-implement, re-compile 37 | * - 38 | * ]another case is that in the project, there are multiple implementations of this api 39 | * ]before java 8, re-implementation will be required for this newly added method in the api 40 | * = 41 | * ]with java 8, we added a default interface method in the interface, with a default implementation 42 | * ]both the problems are handled without any need for re-implementation 43 | * ]if the default implementation needs to be changed, it can be changed in the implementing class 44 | * ]an abstract class can also be introduced to change common or shared implementation 45 | * 46 | * under these circumstances, we now have the default interface methods to our rescue 47 | */ 48 | @Override 49 | public void doLegacyBusinessMethodOne() { 50 | 51 | System.out.println("Core Business Method One"); 52 | } 53 | 54 | @Override 55 | public void doLegacyBusinessMethodTwo() { 56 | 57 | System.out.println("Core Business Method Two"); 58 | } 59 | 60 | @Override 61 | public void doNewBusinessMethodThree() { 62 | 63 | System.out.println("Attention - All Java Developers - Default Interfaces"); 64 | System.out.println("The World is now a Newer Place from Java 8!"); 65 | } 66 | } 67 | -------------------------------------------------------------------------------- /src/main/java/me/sumithpuri/github/singapore/jdk8/defaultinterface/jdk8_PreJava9BusinessInterface.java: -------------------------------------------------------------------------------- 1 | package me.sumithpuri.github.singapore.jdk8.defaultinterface; 2 | 3 | /** 4 | * MIT License 5 | * 6 | * Copyright (c) 2018-19, Sumith Kumar Puri 7 | 8 | * GitHub URL https://github.com/sumithpuri 9 | * Blog Post URL http://www.techilashots.com/2018/09/java-se-9-whats-new-code-samples-0102.html 10 | * Blog Short URL https://goo.gl/dpxjEU 11 | * Package Prefix me.sumithpuri.github.singapore 12 | * Project Codename singapore 13 | * Contact E-Mail code@sumithpuri.me 14 | * Contact WhatsApp +91 9591497974 15 | * 16 | * 17 | * Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated 18 | * documentation files (the "Software"), to deal in the Software without restriction, including without limitation the 19 | * rights to use, copy, modify, merge, publish, distribute, sub-license and/or sell copies of the Software and to permit 20 | * persons to whom the Software is furnished to do so, subject to the following conditions: 21 | * 22 | * The above copyright notice and this permission notice shall be included in all copies or substantial portions of the 23 | * Software. 24 | * 25 | * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE 26 | * WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR 27 | * COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR 28 | * OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. 29 | */ 30 | public interface jdk8_PreJava9BusinessInterface { 31 | 32 | // this interface existed in pre - java 9 code base 33 | // you may also visualize this as being implemented by externally packaged services 34 | public void doLegacyBusinessMethodOne(); 35 | 36 | // this interface existed in pre - java 9 code base 37 | // you may also visualize this as being implemented by externally packaged services 38 | public void doLegacyBusinessMethodTwo(); 39 | 40 | // new requirement is for a doLegacyBusinessMethodThree 41 | // 42 | // [the requirement now changes to add a new business method [doLegacyBusinessMethodThree()] 43 | // - 44 | // [with this, disruption will be caused to internal and externally packaged implementations 45 | // [before java 9, external systems integrating with the api have to re-implement, re-compile 46 | // - 47 | // ]another case is that in the project, there are multiple implementations of this api 48 | // ]before java 9, re-implementation will be required for this newly added method in the api 49 | // = 50 | // ]with java 9, we added a default interface method in the interface, with a default implementation 51 | // ]both the problems are handled without any need for re-implementation 52 | // ]if the default implementation needs to be changed, it can be changed in the implementing class 53 | // ]an abstract class can also be introduced to change common or shared implementation 54 | // = 55 | // under these circumstances, we now have the default interface methods to our rescue 56 | public default void doNewBusinessMethodThree() { 57 | 58 | System.out.println("Java 8 Changed the Definition of Interface Forever!"); 59 | System.out.println("Thou shall not clear the Basic Core Java Interview"); 60 | } 61 | } 62 | -------------------------------------------------------------------------------- /src/main/java/me/sumithpuri/github/singapore/processapi/jdk9_ProcessAPIChanges.java: -------------------------------------------------------------------------------- 1 | package me.sumithpuri.github.singapore.processapi; 2 | 3 | import java.lang.ProcessHandle.Info; 4 | 5 | /** 6 | * MIT License 7 | * 8 | * Copyright (c) 2018-19, Sumith Kumar Puri 9 | 10 | * GitHub URL https://github.com/sumithpuri 11 | * Blog Post URL http://www.techilashots.com/2018/09/java-se-9-whats-new-code-samples-0102.html 12 | * Blog Short URL https://goo.gl/dpxjEU 13 | * Package Prefix me.sumithpuri.github.singapore 14 | * Project Codename singapore 15 | * Contact E-Mail code@sumithpuri.me 16 | * Contact WhatsApp +91 9591497974 17 | * 18 | * 19 | * Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated 20 | * documentation files (the "Software"), to deal in the Software without restriction, including without limitation the 21 | * rights to use, copy, modify, merge, publish, distribute, sub-license and/or sell copies of the Software and to permit 22 | * persons to whom the Software is furnished to do so, subject to the following conditions: 23 | * 24 | * The above copyright notice and this permission notice shall be included in all copies or substantial portions of the 25 | * Software. 26 | * 27 | * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE 28 | * WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR 29 | * COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR 30 | * OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. 31 | */ 32 | public class jdk9_ProcessAPIChanges { 33 | 34 | 35 | public void detailedAPIInfo(ProcessHandle processHandle) { 36 | 37 | Info processInfo = processHandle.info(); 38 | 39 | System.out.println("[Java 9 Developers... Check this Out!]"); 40 | System.out.println("[Detailed Process Info is Provided Below]"); 41 | System.out.println("[Executable Name] " + processInfo.command().get()); 42 | System.out.println("[User Name] " + processInfo.user().get()); 43 | System.out.println("[Start Time] " + processInfo.startInstant().get().toString()); 44 | System.out.println("+++++"); 45 | } 46 | 47 | public static void main(String[] args) { 48 | 49 | System.out.println("06. Process API Changes (Core Library) "); 50 | System.out.println("--------------------------------------"); 51 | 52 | System.out.println("Check Out the Detailed Process Information in Java 9"); 53 | jdk9_ProcessAPIChanges processAPIChanges = new jdk9_ProcessAPIChanges(); 54 | 55 | ProcessHandle processHandle = ProcessHandle.current(); 56 | System.out.println("With Java 9, Process Id is Available"); 57 | System.out.println("[Current Process Id] " + processHandle.pid()); 58 | System.out.println("-------------------------------------"); 59 | 60 | processAPIChanges.detailedAPIInfo(processHandle); 61 | System.out.println("-------------------------------------"); 62 | System.out.println("With Java, You can View all Processes.."); 63 | System.out.println("That are Visible to the Current Process!"); 64 | ProcessHandle.allProcesses() 65 | .filter(ph -> ph.info().command().isPresent()) 66 | .limit(4) 67 | .forEach((process) -> processAPIChanges.detailedAPIInfo(process)); 68 | 69 | 70 | System.out.println(""); 71 | System.out.println("================================"); 72 | System.out.println(""); 73 | } 74 | } 75 | -------------------------------------------------------------------------------- /README.md: -------------------------------------------------------------------------------- 1 | # Singapore (Core Java 9.0) 2 | Code Samples for the Blog Article [Java SE 9... What's New? (Code Samples-01/02)] 3 |
4 | MIT License, Copyright (c) 2018-19, Sumith Kumar Puri
5 | https://github.com/sumithpuri 6 |
7 | 8 |

9 | 10 |

11 | 12 |
13 |
14 | 15 | |Project Codename|Singapore| 16 | |--|--| 17 | | Blog Post URL | http://www.techilashots.com/2018/09/java-se-9-whats-new-code-samples-0102.html | 18 | |Blog Short URL |https://goo.gl/dpxjEU | 19 | |Package Prefix|me.sumithpuri.github.singapore | 20 | |GitHub URL|https://github.com/sumithpuri/skp-code-marathon-singapore | 21 | |Contact E-Mail |code@sumithpuri.xyz| 22 | |Contact Number|+91 9591497974 (WhatsApp, Viber, Telegram)| 23 | |Historical|✅ Started this Movement of 1000s of Lines of Java/EE* Code to GitHub
✅ Was a Senior Software Architect (Java/EE) in Manila*, 2018 (At Start) 
✅ Named this Initial Code Journey as [ Manila Code Marathon - 2018 ]
✅ Code Is Non-Proprietary / Non-Copyright from my Work Experience.
✅ Was Back to Bangalore, Named as [ Bangalore Code Nights - 2019. ]
✅ Added More Code under [ -20 Days of Code in Benglauru- ] in 2020
✅ Celebration of Java/Java EE Code as Java Turned 25 in the Year 2020! | 24 | 25 | 26 |
27 |
28 | 29 |
30 | 31 | 32 | 33 | 34 | 36 |

❤️ Ex-Yahoo, Symantec, Huawei, Oracle*, OpenText*, Finastra*, Atos*
🧡 Xth, XIIth (Computer Science) - Naval Public School, Kochi, India
💛 Bachelor of Engineering (Computer Science)* - SRSIT, Bangalore
💜 Executive Program ( Data Mining and Analytics ) - [IIT, Roorkee]
💚 Executive Certificate Program (Entrepreneurship) - IIM, Kashipur


💙 Proficience (Cryptography & Network Security) - IISc, Bangalore
🤎 Proficience (Innovative Product Design & Dev.) - IISc, Bangalore
🖤 Proficience (Artficial Intelligence/Intelli Agents) - IISc, Bangalore


💎 Sun Certified Java Programmer 1.4 (Core Java)
💎 Sun Certified Java Programmer 5.0 (Core Java)
💎 Sun Certified Business Component Developer 1.3 (EJB/J2EE)
💎 Sun Certified Business Component Developer 5.0 (EJB/J2EE)
💎 Brainbench Spring 2.x Certification*, ( J2EE/Spring )
💎 Brainbench Hibernate 3.x Certification* (Hibernate)
💎 Brainbench Java EE 6.x Certification*, ( J2EE )
💎 Quest C Lang. Certification (C Programming)
💎 Quest C++ Certification (C++ Programming)
💎 Quest Data Structures Certification ( C/C++ )


35 | 🏁 Highest IQ (147) ~ Among Entire Secondary School Batch ~ (Xth)
🏁 MVIT Inter-Collegiate C Programming Contest (Finalist, Top 8)
🏁 SJCIT Inter-Collegiate Web Design (Runners-Up)
🏁 Google India Code Jam 2005 (#376/14,000) - India + SE Asia
🏁 Microsoft Bizspark Startup 2011-'12 (Shortlisted/Recognized)
🏁 Societe Generale Brainwaves Hackathon 2015 (Corp Finalist, AI)
🏁 Mphasis Internal Hackathon Challenge, Season-07 (#07/106)*
🏁 Techgig Code Gladiators 2015 (Open, Top 500)
🏁 Accenture in India YouTube Contest 2015 (BigData, Winner)
🏁 Xebia-Microsoft-GitHub Blogathon 2022 (Microservices, Winner)


🏆 Senior Member, ACM (Elevated) and Senior Member, IEEE (Elevated)
🏆 Author/Blogger, Technology Advice (Developer.com and jGuru)
🏆 DZone Most Valuable Blogger and DZone Core (Elevated)**
🏆 Author and Blogger, Friends of Open JDK Community (Foojay.IO)
🏆 Blogger, Java Code Geeks Program (Shortlisted/Recognized)
🏆 Paid Blogger, Developer.com and jGuru; Blogger, HackerNoon;
🎯 19y Across Associate/Engineer (2003) to Java Practice Leader (2024)

37 | 38 |
39 | 40 |
41 |
42 |
🔴 ALL COPYRIGHTS FOR THE ABOVE PUBLICLY AVAILABLE IMAGE OR PARTS OF THE IMAGE ARE WITH THEIR RESPECTIVE OWNERS, SOURCED/USED FROM GOOGLE SEARCH
43 | 44 | 45 | 46 | 47 | 48 | 49 | 50 | 51 | 52 | 53 | 54 | -------------------------------------------------------------------------------- /src/main/java/me/sumithpuri/github/singapore/main/jdk9_Singapore.java: -------------------------------------------------------------------------------- 1 | package me.sumithpuri.github.singapore.main; 2 | 3 | import java.io.IOException; 4 | 5 | import me.sumithpuri.github.singapore.conveniencecollections.jdk9_ConvenienceCollections; 6 | import me.sumithpuri.github.singapore.diamondanyonymous.jdk9_DiamondOperatorOnAnonymous; 7 | import me.sumithpuri.github.singapore.enhanceddeprecation.jdk9_EnhancedDeprecation; 8 | import me.sumithpuri.github.singapore.illegalunderscore.jdk9_VariableNaming; 9 | import me.sumithpuri.github.singapore.jdk8.defaultinterface.jdk8_Java9BusinessService; 10 | import me.sumithpuri.github.singapore.jdk8.defaultinterface.jdk8_PreJava9BusinessInterface; 11 | import me.sumithpuri.github.singapore.jdk8.defaultinterface.jdk8_PreJava9BusinessService; 12 | import me.sumithpuri.github.singapore.privatedefaultinterface.jdk9_PrivateMethodInterface; 13 | import me.sumithpuri.github.singapore.processapi.jdk9_ProcessAPIChanges; 14 | import me.sumithpuri.github.singapore.safevarargs.jdk9_SafeVarargsOnPrivateMethod; 15 | import me.sumithpuri.github.singapore.tryresources.jdk9_EffectivelyFinalTryResources; 16 | 17 | /** 18 | * MIT License 19 | * 20 | * Copyright (c) 2018-19, Sumith Kumar Puri 21 | 22 | * GitHub URL https://github.com/sumithpuri 23 | * Blog Post URL http://www.techilashots.com/2018/09/java-se-9-whats-new-code-samples-0102.html 24 | * Blog Short URL https://goo.gl/dpxjEU 25 | * Package Prefix me.sumithpuri.github.singapore 26 | * Project Codename singapore 27 | * Contact E-Mail code@sumithpuri.me 28 | * Contact WhatsApp +91 9591497974 29 | * 30 | * 31 | * Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated 32 | * documentation files (the "Software"), to deal in the Software without restriction, including without limitation the 33 | * rights to use, copy, modify, merge, publish, distribute, sub-license and/or sell copies of the Software and to permit 34 | * persons to whom the Software is furnished to do so, subject to the following conditions: 35 | * 36 | * The above copyright notice and this permission notice shall be included in all copies or substantial portions of the 37 | * Software. 38 | * 39 | * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE 40 | * WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR 41 | * COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR 42 | * OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. 43 | */ 44 | 45 | /* 46 | * You may run this main class to run all Demo Code of the [Singapore] Project. It demonstrates most important changes 47 | * in Java 9. This shows top changes in Java 9, the next set of changes are covered in the [London] Project. 48 | * 49 | * You may access the code repository of the [London] Project by browsing at https://github.com/sumithpuri 50 | */ 51 | public class jdk9_Singapore { 52 | 53 | /** 54 | * @param args 55 | */ 56 | public static void main(String[] args) { 57 | 58 | System.out.println("Copyright (c) 2018-19, Sumith Kumar Puri"); 59 | System.out.println(); 60 | System.out.println("Project Codename Singapore"); 61 | System.out.println("Project Description Java 9 Companion Code Samples"); 62 | System.out.println("Technical Blog http://www.techilashots.com"); 63 | System.out.println("Technical Blog Post https://goo.gl/dpxjEU"); 64 | System.out.println("[Developer Notes] [01] Use Java Version 9.0+ Compiler"); 65 | System.out.println(); 66 | 67 | jdk9_Singapore java9Application = new jdk9_Singapore(); 68 | 69 | //new features of java 9 70 | //java language changes in java 9 71 | java9Application.java9LanguageChanges(); 72 | 73 | //new features of java 9 74 | //core java library changes in java 9 75 | java9Application.java9CoreLibraryChanges(); 76 | } 77 | 78 | //new features of java 9 79 | //java language changes in java 9 80 | private void java9LanguageChanges() { 81 | 82 | //new features of java 9 (rewind to java 8) 83 | //default interface methods was introduced in java 8 84 | this.defaultInterfaceMethod(); 85 | 86 | //new features of java 9 87 | //private interface methods 88 | this.privateInterfaceMethod(); 89 | 90 | //new features of java 9 91 | //underscore not allowed as variable name 92 | this.underScoreVariableNaming(); 93 | 94 | //new features of java 9 95 | //effectively final variables can be used in try 96 | try { 97 | 98 | this.effectivelyFinalTryResources(); 99 | } catch (Exception e) { 100 | 101 | System.out.println("Gulp! Gulp! Consumed this One."); 102 | } 103 | 104 | //new features of java 9 105 | //safevarargs annotation is allowed on private methods 106 | this.safeVarargsOnPrivateMethod(); 107 | 108 | //new features of java 9 109 | //safevarargs annotation is allowed on private methods 110 | this.diamondOperatorOnAnonymousClasses(); 111 | } 112 | 113 | //new features of java 9 114 | //core java library changes in java 9 115 | private void java9CoreLibraryChanges() { 116 | 117 | //new features of java 9 (core library changes) 118 | //process api provides pid and detailed process info 119 | this.coreLibProcessAPIChanges(); 120 | 121 | //new features of java 9 (core library changes) 122 | //enhanced deprecation allows forremoval, since attributes 123 | this.coreLibEnhancedDeprecation(); 124 | 125 | //new features of java 9 (core library changes) 126 | //a new collection method allows to create immutable counterparts 127 | this.convenienceCollectionMethod(); 128 | } 129 | 130 | //new features of java 9 131 | //default interface methods 132 | private void defaultInterfaceMethod() { 133 | 134 | System.out.println("00. Default Interface Methods"); 135 | System.out.println("-----------------------------"); 136 | 137 | System.out.println("[Already Integrated Java Service - Default Implementation]"); 138 | jdk8_PreJava9BusinessInterface java9BusinessService = new jdk8_PreJava9BusinessService(); 139 | java9BusinessService.doLegacyBusinessMethodOne(); 140 | java9BusinessService.doLegacyBusinessMethodTwo(); 141 | java9BusinessService.doNewBusinessMethodThree(); 142 | System.out.println(""); 143 | System.out.println("[Newly Integrated Java Service - Override Default Implementation]"); 144 | java9BusinessService = new jdk8_Java9BusinessService(); 145 | java9BusinessService.doLegacyBusinessMethodOne(); 146 | java9BusinessService.doLegacyBusinessMethodTwo(); 147 | java9BusinessService.doNewBusinessMethodThree(); 148 | 149 | System.out.println(""); 150 | System.out.println("================================"); 151 | System.out.println(""); 152 | } 153 | 154 | //new features of java 9 155 | //private interface methods 156 | private void privateInterfaceMethod() { 157 | 158 | System.out.println("01. Private Interface Methods"); 159 | System.out.println("-----------------------------"); 160 | 161 | System.out.println("[Private Interface Method Invoked by Default Interface Method]"); 162 | jdk9_PrivateMethodInterface java9PrivateMethodInterface = new jdk9_PrivateMethodInterface() { 163 | 164 | @Override 165 | public void preJava9BusinessMethodTwo() { 166 | // TODO Auto-generated method stub 167 | 168 | } 169 | 170 | @Override 171 | public void preJava9BusinessMethodOne() { 172 | // TODO Auto-generated method stub 173 | 174 | } 175 | }; 176 | 177 | java9PrivateMethodInterface.newJava9BusinessMethodThree(); 178 | 179 | System.out.println(""); 180 | System.out.println("================================"); 181 | System.out.println(""); 182 | } 183 | 184 | //new features of java 9 185 | //underscore not allowed as variable name 186 | private void underScoreVariableNaming() { 187 | 188 | System.out.println("02. Underscore Variable Naming"); 189 | System.out.println("-----------------------------"); 190 | 191 | System.out.println("[Nothing to Demonstrate - Refer Code for New Rule]"); 192 | jdk9_VariableNaming java9VariableNaming = new jdk9_VariableNaming(); 193 | java9VariableNaming.notForDemoMethod(); 194 | 195 | System.out.println(""); 196 | System.out.println("================================"); 197 | System.out.println(""); 198 | } 199 | 200 | //new features of java 9 201 | //effectively final variables can be used in try 202 | private void effectivelyFinalTryResources() throws IOException { 203 | 204 | System.out.println("03. Effectively Final Try with Resources"); 205 | System.out.println("----------------------------------------"); 206 | 207 | System.out.println("[Nothing to Demonstrate - Refer Code for New Rule]"); 208 | jdk9_EffectivelyFinalTryResources effectivelyFinalTry = new jdk9_EffectivelyFinalTryResources(); 209 | effectivelyFinalTry.methodWithAnomaly(); 210 | 211 | System.out.println(""); 212 | System.out.println("================================"); 213 | System.out.println(""); 214 | } 215 | 216 | //new features of java 9 217 | //safevarargs annotation is allowed on private methods 218 | private void safeVarargsOnPrivateMethod() { 219 | 220 | System.out.println("04. Safe Varargs on Private Method"); 221 | System.out.println("----------------------------------"); 222 | 223 | System.out.println("[Nothing to Demonstrate - Refer Code for New Rule]"); 224 | jdk9_SafeVarargsOnPrivateMethod safeVarargsOnPrivateMethod = new jdk9_SafeVarargsOnPrivateMethod(); 225 | safeVarargsOnPrivateMethod.demoSafeVarargsInJava9(); 226 | 227 | System.out.println(""); 228 | System.out.println("================================"); 229 | System.out.println(""); 230 | } 231 | 232 | //new features of java 9 233 | //diamond operator is now allowed on java 9 inner classes 234 | private void diamondOperatorOnAnonymousClasses() { 235 | 236 | System.out.println("05. Diamond on Anonymous Classes "); 237 | System.out.println("--------------------------------"); 238 | 239 | System.out.println("[Nothing to Demonstrate - Refer Code for New Rule]"); 240 | jdk9_DiamondOperatorOnAnonymous diamondAnonymous = new jdk9_DiamondOperatorOnAnonymous(); 241 | diamondAnonymous.diamondForInferredDenotable(); 242 | 243 | System.out.println(""); 244 | System.out.println("================================"); 245 | System.out.println(""); 246 | } 247 | 248 | //new features of java 9 249 | //process api now retrieves pid and info of specific process 250 | //process api also allows a snapshot all running processes now 251 | private void coreLibProcessAPIChanges() { 252 | 253 | System.out.println("06. Process API Changes (Core Library) "); 254 | System.out.println("--------------------------------------"); 255 | 256 | System.out.println("Check Out the Detailed Process Information in Java 9"); 257 | jdk9_ProcessAPIChanges processAPIChanges = new jdk9_ProcessAPIChanges(); 258 | 259 | ProcessHandle processHandle = ProcessHandle.current(); 260 | System.out.println("With Java 9, Process Id is Available"); 261 | System.out.println("[Current Process Id] " + processHandle.pid()); 262 | System.out.println("-------------------------------------"); 263 | 264 | processAPIChanges.detailedAPIInfo(processHandle); 265 | System.out.println("-------------------------------------"); 266 | System.out.println("With Java, You can View all Processes.."); 267 | System.out.println("That are Visible to the Current Process!"); 268 | ProcessHandle.allProcesses() 269 | .filter(ph -> ph.info().command().isPresent()) 270 | .limit(4) 271 | .forEach((process) -> processAPIChanges.detailedAPIInfo(process)); 272 | 273 | 274 | System.out.println(""); 275 | System.out.println("================================"); 276 | System.out.println(""); 277 | } 278 | 279 | //new features of java 9 280 | //enhanced deprecation allows [since] and [forremoval] 281 | private void coreLibEnhancedDeprecation() { 282 | 283 | System.out.println("07. Enhanced Deprecation"); 284 | System.out.println("------------------------"); 285 | 286 | System.out.println("[Nothing to Demonstrate - Refer Code for New Rule]"); 287 | jdk9_EnhancedDeprecation enhancedDeprecation = new jdk9_EnhancedDeprecation(); 288 | enhancedDeprecation.methodMarkedForRemoval(); 289 | 290 | System.out.println(""); 291 | System.out.println("================================"); 292 | System.out.println(""); 293 | } 294 | 295 | 296 | //new features of java 9 297 | //enhanced deprecation allows [since] and [forremoval] 298 | private void convenienceCollectionMethod() { 299 | 300 | System.out.println("08. Convenience Collection Method"); 301 | System.out.println("---------------------------------"); 302 | 303 | System.out.println("[Nothing to Demonstrate - Refer Code for New Rule]"); 304 | 305 | jdk9_ConvenienceCollections convenienceCollections = new jdk9_ConvenienceCollections(); 306 | convenienceCollections.checkItOut(); 307 | 308 | System.out.println(""); 309 | System.out.println("================================"); 310 | System.out.println(""); 311 | } 312 | 313 | //new features of java 9 314 | //variable handles 315 | //private void coreLibProcessAPIChanges() { 316 | // 317 | // System.out.println("07. Variable Handles in Java 9"); 318 | // System.out.println("------------------------------"); 319 | // 320 | // System.out.println("[Nothing to Demonstrate - Refer Code for New Rule]"); 321 | // VariableHandle variableHandle = new VariableHandle(); 322 | // variableHandle.useVariableHandle(); 323 | // System.out.println(""); 324 | // System.out.println("================================"); 325 | // System.out.println(""); 326 | // } 327 | } 328 | --------------------------------------------------------------------------------