From Java 9 onwards, we can declare private methods in interface. In this post I will show with an example of how to do it. Private methods in interface are useful if you have logic shared by more than one default interface methods. We can put the shared logic in the private method. Below is…… Continue reading Private Interface Methods
Tag: Java
BiFunction Example
In this post, I will show how to use BiFunction functional interface with an example. BiFunction functional interface is similar to Function functional interface. It takes an input and produces an output. The difference lies in the number of inputs taken by the BiFunction functional interface. Function functional interface takes one input and produced one…… Continue reading BiFunction Example
DigestInputStream Class Example
In this post under Java –> Security, I will explain with example the use of DigestInputStream class. When any stream class under java.io package is used, the data flows from source to destination in a stream. DigestInputStream class can be used to calculate a Message Digest when data is being read from a source using…… Continue reading DigestInputStream Class Example
DigestOutputStream Class Example
In this post under Java –> Security, I will explain with example the use of DigestOutputStream class. When any stream class under java.io package is used, the data flows from source to destination in a stream. DigestOutputStream class can be used to calculate a Message Digest when data is being written to the destination using…… Continue reading DigestOutputStream Class Example
Custom Error Handling when parsing xml through SAX api
In this post under JAXP, I will explain how to add custom error handler when parsing xml document through SAX api. To provie a custom error handler, we need to implement the interface org.xml.sax.ErrorHandler as shown below package sax; import org.xml.sax.ErrorHandler; import org.xml.sax.SAXException; import org.xml.sax.SAXParseException; public class CustomErrorHandler implements ErrorHandler { @Override public void error(SAXParseException…… Continue reading Custom Error Handling when parsing xml through SAX api
Rotating File Handler
In this post under logging, I will show how to create a rotating file handler. A rotating file handler create a set of files, with each file having a count in the file name indicating the total number of files created. Each file has a size limit, which when reached a new file is created…… Continue reading Rotating File Handler
Java Util Logging ErrorManager example
In this post under java logging, I will explain the purpose of ErrorManager and how we can use it. Whenever we write the below code logger.info(“Hello my name is Sumanth1”); We are requesting the Handler to log the message to a destination. What if an error happens at the Handler level when an attempt is…… Continue reading Java Util Logging ErrorManager example
Custom format for Property names using PropertyNamingStrategy Part 2
In this post under JSONB, I will continue explaining how to create custom format for property names using PropertyNamingStrategy interface. In the post, “Custom format for Property names using PropertyNamingStrategy Part 1”, I listed the different formats provided by the interface out of the box, which are 1) CASE_INSENSITIVE 2) IDENTITY 3) LOWER_CASE_WITH_DASHES 4) LOWER_CASE_WITH_UNDERSCORES…… Continue reading Custom format for Property names using PropertyNamingStrategy Part 2
Combining two or more Function functional interface
In this post, I will explain how to combine Function functional interfaces. They are two ways in which we can combine Function functional interface and it is achieved using two methods in Function interface as mentioned below 1) default Function andThen(Function after) 2) default Function compose(Function before) Both the methods accept an implementation of Function…… Continue reading Combining two or more Function functional interface
Unzipping a jar file programmatically
In this post, I will explain how to unzip a jar file. Below is the complete code to unzipping a jar file programmatically Main code 1 package jar; 2 3 import java.io.File; 4 import java.io.FileOutputStream; 5 import java.io.IOException; 6 import java.io.InputStream; 7 import java.util.Enumeration; 8 import java.util.jar.JarEntry; 9 import java.util.jar.JarFile; 10 11 public class JarDemo2…… Continue reading Unzipping a jar file programmatically