Posts

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...

Python Dictionary

In my  earlier article, I had covered Python Tuples.  In this article, I will be covering Python dictionary.   What is a Python dictionary? A Python dictionary stores a List of key-value pairs. Creating a Python dictionary You can create a dictionary by specifying key-value pairs in curly brackets separated by commas. The following code demonstrates this: employeeDict = {'name':'John Doe','salary':5000.00,'department':'HR'} This code creates a dictionary employeeDict with some key value pairs. The key and value need to be separated by a colon symbol(:) Accessing values in a Python dictionary You can access a value from a dictionary by specifying the key in square brackets. The following code demonstrates this: employeeDict = {'name':'John Doe','salary':5000.00,'department':'HR'}print(employeeDict['name']) Updating a Python dictionary You can update the value for an existing key, add a new key-valu...

ToIntFunction in Java 8 With Code Sample

Functional interfaces and lambda expressions are one of the major features in Java 8. Java provides a lot of in-built functioal interfaces in the java.util.function package. One of these is the ToIntFunction. In this blog post, I will be explaining how thisfunctional interface works. To know more about functional interfaces, you can refer to this  blog post. Edit What is ToIntFunction ToIntFunction is an in-built functional interface in the java.util.Function package. It accepts an argument of any data type but returns a result of type int . It is a primitive specialization of the Function interface that always returns a result of int type. So IntFunction<T> is similar to Function<T,Integer> It has an applyAsInt  method. It then applies the logic in this method on the argument passed in to produce the int result. ToIntFunction Sample Code The following code snippet demonstrates this interface: ToIntFunction<String> strLengthProducer = str -> str.length()...

Spring Bean Scopes Explained With Code Samples

Image
The Spring Framework allows defining scopes for a Spring Bean. Spring Bean scopes define the lifetime of a Spring bean. In this article, we will take a look at bean scopes. What is Spring Bean Scope? A Spring Bean scope specifies the lifetime of a Spring bean. So it specifies when the bean will be created and how long it will exist in the system. Edit What are the different bean scopes? Spring supports the following bean scopes:   Singleton This is the default bean scope. As per this scope, only one instance of a bean is created. Each time the bean is requested, the same instance is returned. Prototype As per this scope, a new instance of a bean is created each time the bean is requested. Request This bean scope is valid only for a web application. As per this bean scope, a new instance of the bean is created for each HTTP request. The bean stays alive until the HTTP request completes.  If you use this bean scope for a standalone application, your code will result in an...

What is the difference between Iterator and SplitIterator

In this post, I will be explaining the difference between a Iterator and SplitIterator. Edit Iterator SplitIterator Present in Java right from the start Added by Java 8 Allows iterating over the elements of a collection individually Allows iterating over the elements of a collection individually as well as in bulk Can be used only for iterating over a Collection Can be used to iterate over a Stream as well as a Collection Only allows sequential processing Allows both sequential as well as parallel processing  

Java 9 New Features Explained in Detail

In this article, I will be summing up all the new features introduced by Java 9. Modules Modules are basically  groups of packages . Just like you put a set of related classes into a package, you can put a set of related packages into a module. This helps to organize code better and to follow the Single Responsibility Principle (SRP).  You can deploy a module by itself. So modules help to reduce the size of an application. In order to read more about modules, you can refer to this article. You can also see some of my other articles about module internals and how to create modules . Stream Improvements Java 9 has made several improvements on the Stream interface. These are as follows (You can click the article link for an in-depth explanation of each feature): Stream.ofNullable – Helps to create a Stream with a null value. Stream.iterate   – Helps to create a new finite Stream. The Stream is terminated when the specified condition is true Stream.dropWhile – Helps t...

Java Queue Interface Methods Explained With Code Samples

One of the lesser known Collection interfaces in the java.util.Queue interface. In this article, I will be covering this interface in detail. What is the Java Queue interface? The java.util.Queue interface extends the java.util.Collection interface. It provides a First In First Out (FIFO) behavior and you can use it to represent a Queue data structure.  It has several implementations in the Collection API. The java.util.LinkedList and java.util.PriorityQueue are the most common implementations Java Queue Interface Operations There are several methods available on the queue interface that help to perform various queue operations. add The add method supports adding an element to the Queue. if for some reason the add method is unable to add the element, it throws an  Exception. Sample Code (Without Exception) Queue<String> daysOfTheWeek = new LinkedList<String>();daysOfTheWeek.add("Monday");daysOfTheWeek.add("Tuesday");daysOfTheWeek.add("Wednesda...