java.base
모듈에 Java SE 플랫폼의 기본 API들이 정의되어 있음 (최상위 모듈)java.base
모듈 구성요소// module-info.java 파일
module samplemodule {
// requires : 의존하고 있는 모듈 명시
requires othermodule;
// exports : 다른 모듈의 코드에서 접근할 수 있는 public 패키지 지정
exports packagename;
// exprots to : 정확히 어떤 모듈이 접근 가능한지 명시
exports packagename to module1, module2;
// uses : 해당 모듈에서 사용하는 서비스 지정
uses classpath.interfacename;
// provides-with : 제공하는 서비스의 구현체 지정
provides classpath.interfacename with implementation;
// opens : 런타임 시에만 접근할 수 있는 패키지 지정 (reflection 시)
opens packagename;
// opens-to : 패키지에 접근할 수 있는 특정 모듈 명시
opens packagename to module1, module2;
/* 만약 모듈의 모든 패키지들을 접근할 수 있도록 지정하고 싶으면 모듈 선언 시 open 예약어 사용
* ex] open module modulename { ... }
*/
}
jshell
또는 jshell -v
입력 (-v : verbose 모드)// current Process
ProcessHandle processHandle = ProcessHandle.current();
processHandle.getPid();
processHandle.isAlive();
processHandle.children().count();
processHandle.supportsNormalTermination();
ProcessHandle.InfoprocessInfo = processHandle.info();
processInfo.arguments();
processInfo.command();
processInfo.totalCpuDuration();
processInfo.user();
// all Processes
Stream<ProcessHandle> processStream = ProcessHandle.allProcesses();
// destroy Process
processHandle.destroy();
Process (Java Platform SE 9 )try-with-resource
문에서 해당 변수를 사용할 수 있도록 개선before
final Resource resource1 = new Resource("resource1");
Resource resource2 = new Resource("resource2");
try (Resource r1 = resource1;
Resource r2 = resource2) {
...
}
after
try(resource1; resource1) {
...
}
IntStream.iterate(1, i -> i<20, i -> i*2).foreach(System.out::println);
Stream.of(1,2,3,4,5,6).dropWhile(i -> i<=3).foreach(System.out::print);
//result: 456
Stream.of(1,6,5,2,3,4).dropWhile(i -> i<=3).foreach(System.out::print);
//result: 65234
Stream.of(1,2,3,4,5,6).takeWhile(i -> i<=3).foreach(System.out::print);
//result: 123
Stream.of(1,6,5,2,3,4).takeWhile(i -> i<=3).foreach(System.out::print);
//result: 1
```java
// numbers [1,2,3,null]
// mapNumber [1 - one, 2 - two, 3 - three, null - null]
List<String> newstringNumbers = numbers.stream()
.flatMap(s -> Stream.ofNullable(mapNumber.get(s)))
.collect(Collectors.toList());
//result: [one, two, three]
```
FooClass<Integer> fc = new FooClass<>(1) {
// anonymous inner class
};
FooClass<? extends Integer> fc0 = new FooClass<>(1) {
// anonymous inner class
};
FooClass<?> fc1 = new FooClass<>(1) {
// anonymous inner class
};
List list = List.of("one", "two", "three");
Map map = Map.of(1, "one", 2, "two", 3, "three");
Set set = Set.of(1, 2, 3);
public interface Card {
private Long createCardId() { ... }
private static void displayCardDetails() { ... }
}
Oracle Java9 변경사항 보러가기
What's New in Oracle JDK 9
Java 9 Features with Examples - DigitalOcean
[Java] JPMS와 Module - Hello My World!