Java 9 new features (#660)
* initial push for core-java-9 tutorials * Fixed Maven build with experimental java 9 Maven compiler plug-in. Minor code changes * Running maven build and changes to some of tests. * Fixed maven build and modifications ot some tests * Removing unnecessary files
This commit is contained in:
committed by
Grzegorz Piwowarek
parent
98ffbc1f37
commit
c68e1bfbc8
13
core-java-9/src/main/java/.gitignore
vendored
Normal file
13
core-java-9/src/main/java/.gitignore
vendored
Normal file
@@ -0,0 +1,13 @@
|
||||
*.class
|
||||
|
||||
#folders#
|
||||
/target
|
||||
/neoDb*
|
||||
/data
|
||||
/src/main/webapp/WEB-INF/classes
|
||||
*/META-INF/*
|
||||
|
||||
# Packaged files #
|
||||
*.jar
|
||||
*.war
|
||||
*.ear
|
||||
@@ -0,0 +1,23 @@
|
||||
package com.baeldung.java9.language;
|
||||
|
||||
public interface PrivateInterface {
|
||||
|
||||
private static String staticPrivate() {
|
||||
return "static private";
|
||||
}
|
||||
|
||||
private String instancePrivate() {
|
||||
return "instance private";
|
||||
}
|
||||
|
||||
public default void check(){
|
||||
String result = staticPrivate();
|
||||
if (!result.equals("static private"))
|
||||
throw new AssertionError("Incorrect result for static private interface method");
|
||||
PrivateInterface pvt = new PrivateInterface() {
|
||||
};
|
||||
result = pvt.instancePrivate();
|
||||
if (!result.equals("instance private"))
|
||||
throw new AssertionError("Incorrect result for instance private interface method");
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,44 @@
|
||||
package com.baeldung.java9.process;
|
||||
|
||||
import java.io.File;
|
||||
import java.io.IOException;
|
||||
import java.security.NoSuchAlgorithmException;
|
||||
import java.security.SecureRandom;
|
||||
import java.time.Duration;
|
||||
import java.time.Instant;
|
||||
import java.util.stream.Stream;
|
||||
|
||||
|
||||
public class ProcessUtils {
|
||||
|
||||
public static String getClassPath(){
|
||||
String cp = System.getProperty("java.class.path");
|
||||
System.out.println("ClassPath is "+cp);
|
||||
return cp;
|
||||
}
|
||||
|
||||
public static File getJavaCmd() throws IOException{
|
||||
String javaHome = System.getProperty("java.home");
|
||||
File javaCmd;
|
||||
if(System.getProperty("os.name").startsWith("Win")){
|
||||
javaCmd = new File(javaHome, "bin/java.exe");
|
||||
}else{
|
||||
javaCmd = new File(javaHome, "bin/java");
|
||||
}
|
||||
if(javaCmd.canExecute()){
|
||||
return javaCmd;
|
||||
}else{
|
||||
throw new UnsupportedOperationException(javaCmd.getCanonicalPath() + " is not executable");
|
||||
}
|
||||
}
|
||||
|
||||
public static String getMainClass(){
|
||||
return System.getProperty("sun.java.command");
|
||||
}
|
||||
|
||||
public static String getSystemProperties(){
|
||||
StringBuilder sb = new StringBuilder();
|
||||
System.getProperties().forEach((s1, s2) -> sb.append(s1 +" - "+ s2) );
|
||||
return sb.toString();
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,22 @@
|
||||
package com.baeldung.java9.process;
|
||||
|
||||
import java.util.Optional;
|
||||
|
||||
public class ServiceMain {
|
||||
|
||||
public static void main(String[] args) throws InterruptedException {
|
||||
ProcessHandle thisProcess = ProcessHandle.current();
|
||||
long pid = thisProcess.getPid();
|
||||
|
||||
|
||||
Optional<String[]> opArgs = Optional.ofNullable(args);
|
||||
String procName = opArgs.map(str -> str.length > 0 ? str[0] : null).orElse(System.getProperty("sun.java.command"));
|
||||
|
||||
for (int i = 0; i < 10000; i++) {
|
||||
System.out.println("Process " + procName + " with ID " + pid + " is running!");
|
||||
Thread.sleep(10000);
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
}
|
||||
Reference in New Issue
Block a user