Posts

Showing posts with the label Java 10

Java 10 Time Based Release Versioning

Java 10 has introduced time based release versioning. In this article, I will be explaining this feature in detail. Before Java 10 Before Java 10, Java did not have a time based release. Instead, Java release was driven by features. So, if there was some delay in developing the features, the Java release also would be delayed. Java 10 time based release versioning gets rid of this issue by guaranteeing a Java release every 6 months. There are two main aspects to time based release versioning as follows: Feature Release Feature releases occur every 6 months.  All those features that are ready will be part of the release. The features that are not ready will be part of the next release. Support for these releases last only for 6 months, that is until the next release. The current version of Java is Java 14. It was released in March 2020 and it is a feature release. Long Term Release (LTS) Long term releases occur once in every three years. Support for such release would be for 3 years. J...

Java 10 Unmodifiable Collections Changes

One of the new features added by Java 10 is some new methods for creating unmodifiable collections. In this article, I will be covering the Java 10 Unmodifiable Collections. What is an Unmodifiable Collection? As the name implies, an unmodifiable Collection is a Collection that cannot be modified. So if you create an unmodifiable collection and then try to add or remove a value from it, Java throws an Exception What is the use of an Unmodifiable Collection Sometimes, you may need to create a read only copy of a Collection. Unmodifiable collections are useful in such scenarios. How to create an Unmodifiable Collection using Java 10 Java 10 has added a copyOf method to all the Collection interfaces. You can use this to create an unmodifiable Collection. The following code demonstrates this: List<Integer> numberList = Arrays.asList(2,4,6,8,10);numberList.add(12); // Line 1 - no exception List<Integer> unmodifiableList = List.copyOf(numberList);unmodifiableList.add(14); //Li...

Java 10 Type Inference explained with Code Samples

A new feature added by Java 10 is the Local Variable Type Inference . In this article, I will be covering this feature in detail. Introduction Before Java 10, while declaring a variable, you explicitly had to specify its type, The following code demonstrates this: int i = 10;String s = "Hello"; So this code declares an int variable i and assigns it the value 10 . It also declares a String variable s and assigns it the value “ Hello “. Java 10 introduces the Local Variable Type Inference feature. This means that Java can determine the data type of a variable based on the value assigned to the variable. So you do not need to explicitly specify the data type . Java 10 introduces a new type var . You need to specify ‘ var ‘ instead of the data type. The following code demonstrates this: var i = 6;var s = "Hello"; So this code declares the variables i and s . No data type is specified, the compiler infers the data type based on the value assigned to the variab...