Skip to content

Commit d32c194

Browse files
committed
jdk9 examples
1 parent fcadebe commit d32c194

File tree

7 files changed

+147
-6
lines changed

7 files changed

+147
-6
lines changed

.classpath

Lines changed: 15 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,20 @@
11
<?xml version="1.0" encoding="UTF-8"?>
22
<classpath>
33
<classpathentry kind="src" path="src/main/java"/>
4-
<classpathentry kind="con" path="org.eclipse.jdt.launching.JRE_CONTAINER/org.eclipse.jdt.internal.debug.ui.launcher.StandardVMType/jdk8"/>
5-
<classpathentry kind="con" path="org.eclipse.jdt.USER_LIBRARY/JAVA_SRC_LIBS"/>
4+
<classpathentry kind="con" path="org.eclipse.jdt.launching.JRE_CONTAINER/org.eclipse.jdt.internal.debug.ui.launcher.StandardVMType/jdk9-oracle">
5+
<attributes>
6+
<attribute name="module" value="true"/>
7+
</attributes>
8+
</classpathentry>
9+
<classpathentry kind="lib" path="lib/guava-14.0-rc1.jar"/>
10+
<classpathentry kind="lib" path="lib/hadoop-common-2.5.1.jar"/>
11+
<classpathentry kind="lib" path="lib/hadoop-mapreduce-client-core-2.5.1.jar"/>
12+
<classpathentry kind="lib" path="lib/javax.mail.jar"/>
13+
<classpathentry kind="lib" path="lib/jsch-0.1.53.jar"/>
14+
<classpathentry kind="lib" path="lib/log4j-1.2.17.jar"/>
15+
<classpathentry kind="lib" path="lib/object-explorer.jar"/>
16+
<classpathentry kind="lib" path="lib/scala-library.jar"/>
17+
<classpathentry kind="lib" path="lib/spark-core_2.10-1.5.2.jar"/>
18+
<classpathentry kind="lib" path="lib/spark-streaming_2.10-1.5.2.jar"/>
619
<classpathentry kind="output" path="bin"/>
720
</classpath>

.gitignore

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,8 @@
11
/bin/
22

33
inbravo.jar
4-
inbravo-inst.jar
4+
inbravo-inst.jar
5+
*.class
6+
*.class
7+
*.class
8+
*.class

.settings/org.eclipse.jdt.core.prefs

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,15 +1,15 @@
11
eclipse.preferences.version=1
22
org.eclipse.jdt.core.compiler.codegen.inlineJsrBytecode=enabled
33
org.eclipse.jdt.core.compiler.codegen.methodParameters=do not generate
4-
org.eclipse.jdt.core.compiler.codegen.targetPlatform=1.8
4+
org.eclipse.jdt.core.compiler.codegen.targetPlatform=9
55
org.eclipse.jdt.core.compiler.codegen.unusedLocal=preserve
6-
org.eclipse.jdt.core.compiler.compliance=1.8
6+
org.eclipse.jdt.core.compiler.compliance=9
77
org.eclipse.jdt.core.compiler.debug.lineNumber=generate
88
org.eclipse.jdt.core.compiler.debug.localVariable=generate
99
org.eclipse.jdt.core.compiler.debug.sourceFile=generate
1010
org.eclipse.jdt.core.compiler.problem.assertIdentifier=error
1111
org.eclipse.jdt.core.compiler.problem.enumIdentifier=error
12-
org.eclipse.jdt.core.compiler.source=1.8
12+
org.eclipse.jdt.core.compiler.source=9
1313
org.eclipse.jdt.core.formatter.align_type_members_on_columns=false
1414
org.eclipse.jdt.core.formatter.alignment_for_arguments_in_allocation_expression=16
1515
org.eclipse.jdt.core.formatter.alignment_for_arguments_in_annotation=16

README.md

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,9 @@
88
- [Simulator for 'OutOfMemoryError'][OutOfMemoryErrorSim.md]
99
- [Singleton using 'enum'][EnumSingletonTest.md]
1010
- [How Remote Method Invocation(RMI) works][PowerServiceImpl.md]
11+
- [How 'jshell' (Read-Eval-Print Loop : JEP-222) works][JShellTest.md]
12+
- [How 'VarHandle' class (JEP-193) works][VarHandleTest.md]
13+
- [Oracle has removed underscore ('_') identifier in JDK 9][UnderscoreAsIdentifierTest.md]
1114

1215
#### JVM features
1316
- [How JVM method-inline optimization works][NoClassInstance.md]
@@ -98,6 +101,10 @@
98101
[LevenshteinDistanceTest.md]: https://github.com/inbravo/java-src/blob/master/src/main/java/com/inbravo/string/LevenshteinDistanceTest.java
99102
[NoClassInstance.md]: https://github.com/inbravo/java-src/blob/master/src/main/java/com/inbravo/puzzle/NoClassInstance.java
100103
[PowerServiceImpl.md]: https://github.com/inbravo/java-src/blob/master/src/main/java/com/inbravo/rmi/PowerServiceImpl.java
104+
[JShellTest.md]: https://github.com/inbravo/java-src/blob/master/src/main/java/com/inbravo/jdk9/JShellTest.java
105+
[VarHandleTest.md]: https://github.com/inbravo/java-src/blob/master/src/main/java/com/inbravo/jdk9/VarHandleTest.java
106+
[VarHandleTest.md]: https://github.com/inbravo/java-src/blob/master/src/main/java/com/inbravo/jdk9/VarHandleTest.java
107+
[UnderscoreAsIdentifierTest.md]: https://github.com/inbravo/java-src/blob/master/src/main/java/com/inbravo/jdk9/UnderscoreAsIdentifierTest.java
101108
[FailedHoistingTest.md]: https://github.com/inbravo/java-src/blob/master/src/main/java/com/inbravo/runtime/jit/FailedHoistingTest.java
102109
[SuccessfulHoistingTest.md]: https://github.com/inbravo/java-src/blob/master/src/main/java/com/inbravo/runtime/jit/SuccessfulHoistingTest.java
103110
[AnotherSuccessfullHoistingTest.md]: https://github.com/inbravo/java-src/blob/master/src/main/java/com/inbravo/runtime/jit/AnotherSuccessfullHoistingTest.java
Lines changed: 43 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,43 @@
1+
/*
2+
* MIT License
3+
*
4+
* The Java Shell (Read-Eval-Print Loop - jshell) on JEP-222
5+
*
6+
* Copyright (c) 2017 Onwards Amit Dixit (github.com/inbravo)
7+
*
8+
* Permission is hereby granted, free of charge, to any person obtaining a copy of this software and
9+
* associated documentation files (the "Software"), to deal in the Software without restriction,
10+
* including without limitation the rights to use, copy, modify, merge, publish, distribute,
11+
* sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is
12+
* furnished to do so, subject to the following conditions:
13+
*
14+
* The above copyright notice and this permission notice shall be included in all copies or
15+
* substantial portions of the Software.
16+
*
17+
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT
18+
* NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
19+
* NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM,
20+
* DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
21+
* OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
22+
*/
23+
package com.inbravo.jdk9;
24+
25+
import jdk.jshell.JShell;
26+
import static java.lang.System.out;
27+
28+
public final class JShellTest {
29+
30+
public static void main(final String... args) {
31+
32+
/* Create a new java shell instance */
33+
final JShell shell = JShell.builder().build();
34+
35+
/* Create a new method 'hello()' on java shell using method 'eval()' */
36+
shell.eval("void one() { System.out.println(\"one VJUG\"); }");
37+
shell.eval("void two() { System.out.println(\"two VJUG\"); }");
38+
shell.eval("void three() { System.out.println(\"three VJUG\"); }");
39+
40+
/* Print signature & name of all methods, created on java shell */
41+
shell.methods().forEach(v -> out.println("Method: " + v.signature() + " " + v.name()));
42+
}
43+
}
Lines changed: 42 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,42 @@
1+
/*
2+
* MIT License
3+
*
4+
* Underscore (_) as an Identifier Name based on JEP-213
5+
* Using underscore ("_") as an identifier, should be turned into an error in Java SE 9
6+
*
7+
* Copyright (c) 2017 Onwards Amit Dixit (github.com/inbravo)
8+
*
9+
* Permission is hereby granted, free of charge, to any person obtaining a copy of this software and
10+
* associated documentation files (the "Software"), to deal in the Software without restriction,
11+
* including without limitation the rights to use, copy, modify, merge, publish, distribute,
12+
* sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is
13+
* furnished to do so, subject to the following conditions:
14+
*
15+
* The above copyright notice and this permission notice shall be included in all copies or
16+
* substantial portions of the Software.
17+
*
18+
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT
19+
* NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
20+
* NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM,
21+
* DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
22+
* OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
23+
*/
24+
package com.inbravo.jdk9;
25+
26+
/**
27+
* Oracle has removed underscore (“_”) usage as identifier completely in Java SE 9 release
28+
*
29+
* @author amit.dixit
30+
*/
31+
public final class UnderscoreAsIdentifierTest {
32+
33+
public static void main(final String... args) {
34+
35+
final String stringWithoutUnderscore = "stringWithoutUnderscore";
36+
37+
/* Line below will give error */
38+
/* final String _ = "stringWithUnderscore"; */
39+
/* System.out.println("stringWithUnderscore : " + _); */
40+
System.out.println("stringWithoutUnderscore : " + stringWithoutUnderscore);
41+
}
42+
}
Lines changed: 32 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,32 @@
1+
/*
2+
* To change this license header, choose License Headers in Project Properties.
3+
* To change this template file, choose Tools | Templates
4+
* and open the template in the editor.
5+
*/
6+
package com.inbravo.jdk9;
7+
8+
import java.lang.invoke.VarHandle;
9+
import java.lang.invoke.MethodHandles;
10+
11+
/**
12+
* 'java.lang.invoke.VarHandle' class example based on JEP-193
13+
*
14+
* @author amit.dixit
15+
*/
16+
public class VarHandleTest {
17+
18+
public static void main(final String... args) {
19+
try {
20+
final MethodHandles.Lookup lookup = MethodHandles.lookup();
21+
final VarHandle varHandle = lookup.in(Foo.class).findVarHandle(Foo.class, "i", int.class);
22+
23+
System.out.println(varHandle);
24+
} catch (final ReflectiveOperationException e) {
25+
throw new Error(e);
26+
}
27+
}
28+
}
29+
30+
class Foo {
31+
public final int i = 10;
32+
}

0 commit comments

Comments
 (0)