Home » Java » Core Java » Page 40

Core Java

Thread Methods destroy() and stop(Throwable) Removed in JDK 11

The message “RFR(s): 8204243: remove Thread.destroy() and Thread.stop(Throwable)” by @DrDeprecator (Stuart Marks) on the core-libs-dev OpenJDK mailing list is a request for review (RFR) of a change set associated with JDK-8204243 [“remove Thread.destroy() and Thread.stop(Throwable)”]. Both the bug report and the mailing list message describe the history of these two referenced Thread methods and explain that neither method really does ...

Read More »

[JDK 11] Class Loader Hierarchy Details Coming to jcmd

I’ve been a fan of the diagnostic command-line tool jcmd since hearing about jcmd at JavaOne 2012. I’ve used this tool extensively since then and have blogged multiple times about this tool: jcmd: One JDK Command-Line Tool to Rule Them All Determining the Active HotSpot Garbage Collector Programmatic jcmd Access JavaOne 2012: Diagnosing Your Application on the VM After numerous ...

Read More »

JDK 9/10/11: Side Effects from += on Java String

The question “Why does `array[i++%n] += i+” “` give different results in Java 8 and Java 10?” was posted earlier this week on StackOverflow.com. It points to a bug in the Java compiler that is present in JDK9 and later, but is not present in JDK8. As explained on the StackOverflow thread, Didier L provided a simple example of Java ...

Read More »

API Updates in Java SE 11 (18.9)

Java SE 11, which is also named as 18.9 (based on the new naming scheme which uses the year and month of release), is slated to be GA during the last week of September. The new approach for releasing new JDK version frequently is allowing the language creators to introduce new features, API updates more quickly to the developer community. ...

Read More »

Binary Search in Java without Recursion – Iterative algorithm

This week’s task is to implement binary search in Java, you need to write both iterative and recursive binary search algorithm. In computer science, a binary search or half-interval search is a divide and conquer algorithm which locates the position of an item in a sorted array. Binary search works by comparing an input value to the middle element of ...

Read More »

Java 10: Collecting a Stream into an Unmodifiable Collection

Java 10 introduces several new methods to facilitate the creation of unmodifiable collections. The List.copyOf, Set.copyOf, and Map.copyOf methods create new collection instances from existing instances. For example: List<String> modifiable = Arrays.asList("foo", "bar"); List<String> unmodifiableCopy = List.copyOf(list); // Note that since Java 9, you can also use "of" to create // unmodifiable collections List<String> unmodifiable = List.of("foo", "bar"); There are ...

Read More »

Void methods as behavior black holes

This post could have been titled ‘Void methods considered harmful’, if ‘considered harmful’ essays weren’t considered harmful themselves. Oh welp. Void methods are ubiquitous in most Object Oriented codebases. A direct consequence of mutable state or I/O somewhere in your runtime, you can wrap any behavior that functional programming zealots would call impure, which in principle has no meaningful return ...

Read More »

Shebang Coming to Java?

Although it was never a central goal of JEP 330 [“Launch Single-File Source-Code Programs”] to add support for the Unix-style shebang (#!), issues surrounding the potential ability of JEP 330 “single file source programs” to support a Unix-style shebang have generated significant discussion on the OpenJDK jdk-dev mailing list. This “vigorous discussion” has led to Mark Reinhold adding a week ...

Read More »

Java’s String.format Can Be Statically Imported

JDK-8203630 [“Add instance method equivalents for String::format”] postulates that “the argument for implementing String::format as static appears to be that the format methods could be imported statically and thus conduct themselves comparably to C‘s sprintf.” On a StackOverflow.com thread on the subject, Brandon Yarbrough writes, “by making the method static you can use format in a way that’s very familiar ...

Read More »