Posts

Showing posts with the label Core Java

Jackson – Convert JSON Array of Objects to List

Hello everyone, Here we will show how to convert JSON array String to List The Jackson library is composed of three components: Jackson Databind, Core, and Annotation. Jackson Databind has internal dependencies on Jackson Core and Annotation. Therefore, adding Jackson Databind to your Maven POM dependency /Gradle list will include the other dependencies as well. Maven (pom.xml)   <dependency> <groupId> com.fasterxml.jackson.core </groupId> <artifactId> jackson-databind </artifactId> <version> 2.9.8 </version> </dependency> Gradle (build.gradle)   implementation group: 'com.fasterxml.jackson.core' , name: 'jackson-core' , version: '2.13.2' JSON Array of Objects [ { "name" : "knowledgefactory1" , "salaray" : 1000 }, { "name" : "knowledgefactory2" , "salaray" : 1200 } ] Create an object to m

Java - Builder Design Pattern - Example

Builder is a creational pattern that provides an efficient way to build objects. Compared with the traditional way of using multiple constructors, using the Builder pattern can ensure the readability and stability of the code. This mode is particularly useful when creating complex objects. Use Builder pattern in the following situations: When the algorithm for creating a complex object should be independent of the object's components and how they are assembled When the construction process must allow the constructed object to have different representation Advantages 1. It provides a clear disseverment between the construction and representation of an object. 2. It provides better control over the construction process. 3. It fortifies transmuting the internal representation of objects. Implementation   Let's see an example and learn how to implement a builder pattern. Consider a POJO of Employee below. public class Employee { // All final attributes private final S

Java - Blowfish Encryption and decryption Example

Image
Blowfish is an encryption method developed by Bruce Schneier in 1993 as an alternative to the DES encryption method. It is significantly faster than DES and provides good encryption speed, although no effective cryptanalysis technique has been found to date. It is one of the first secure block ciphers that is not protected by any patents and is therefore freely available for anyone to use. This is a symmetric block cipher algorithm. Block size: 64 bits Key size: variable size from 32 to 448 bits number of subsections: 18 [P-array] number of rounds: 16 number of substitution blocks: 4 [each with 512 records of 32 bits each] develop  Example 1: Encryption and decryption using Blowfish import java.io.UnsupportedEncodingException; import java.nio.charset.Charset; import java.security.InvalidKeyException; import java.security.NoSuchAlgorithmException; import java.util.Base64; import javax.crypto.BadPaddingException; import javax.crypto.Cipher; import javax.crypto.IllegalBlockSizeExc