Drawbacks of javac -parameters flag

The addition of parameter names to the class file format is covered by JEP 118, which was delivered in Java 8. There was a little bit of discussion about why inclusion of parameter names was made optional in OpenJDK email threads here and here. Briefly, the stated reasons to make parameter names optional are concerns … Read more

When is a Java Class loaded?

There is no simple answer to this question. The specification leaves room for different implementation strategies and even within one implementation, it will depend on how the class is been used. Further, your question is more about “when can it fail” which depends on why it may fail, e.g. a class may be loaded at … Read more

Java 8 stream emitting a stream

In Java 9, you could use static final Pattern LINE_WITH_CONTINUATION = Pattern.compile(“(\\V|\\R\\+)+”); … try(Scanner s = new Scanner(file)) { s.findAll(LINE_WITH_CONTINUATION) .map(m -> m.group().replaceAll(“\\R\\+”, “”)) .forEach(System.out::println); } Since Java 8 lacks the Scanner.findAll(Pattern) method, you may add a custom implementation of the operation as a work-around public static Stream<MatchResult> findAll(Scanner s, Pattern pattern) { return StreamSupport.stream(new Spliterators.AbstractSpliterator<MatchResult>( 1000, … Read more

Do terminal operations close the stream?

No forEach does not close the stream (created by Files.list or Files.lines). It is documented in the javadoc, for example for Files.list: The returned stream encapsulates a Reader. If timely disposal of file system resources is required, the try-with-resources construct should be used to ensure that the stream’s close method is invoked after the stream … Read more

LocalDateTime to java.sql.Date in java 8?

There is no direct correlation between LocalDateTime and java.sql.Date, since former is-a timestamp, and latter is-a Date. There is, however, a relation between LocalDate and java.sql.Date, and conversion can be done like this: LocalDate date = //your local date java.sql.Date sqlDate = java.sql.Date.valueOf(date) Which for any given LocalDateTime gives you the following code: LocalDateTime dateTime … Read more