Posts

Kotlin - How to ping multiple HTTP endpoints by run Multiple Threads Concurrently?

Hello everyone, today we are going to learn how to ping multiple HTTP endpoints by running multiple threads concurrently in Kotlin. I am using ExecutorService Approach to achieve the goal. What is the ExecutorService?   The ExecutorService is the interface that sanctions us to execute tasks on threads asynchronously.  The ExecutorService avails in maintaining a pool of threads and assigns them tasks. It withal provides the facility to queue up tasks until there is a free thread available if the number of tasks is more than the threads available. Example: import kotlin. Throws import kotlin.jvm. JvmStatic import java.util.concurrent. ExecutorService import java.util.concurrent. Executors import java.lang. Runnable import KnfPingStatusWithExecutorService . MyRunnable import java.lang. Exception import java.net. HttpURLConnection import java.net. URL /** * @author knf */ object KnfPingStatusWithExecutorService { private const val MYTHREADS = 10 @ Throws ( Exception :: class )

Kotlin - Random and Secure Random with Example - Generate random number in kotlin

Random The classes defined in Random are not cryptographically vigorous, and the numbers culled are not consummately random because a definite mathematical algorithm is utilized to cull them. Ergo, it is not safe to utilize this class for tasks that require a high calibre of security, like engendering an arbitrary password, etc. The class utilizes a 48-bit seed Instances of java.util.Random are threadsafe. However, the concurrent utilization of the same java.util.Random instances across threads may encounter contention and consequent poor performance. Consider instead utilizing ThreadLocalRandom in multithreaded designs. Instances of java.util.Random is not cryptographically secure. Consider instead utilizing SecureRandom to get a cryptographically secure pseudo-desultory number engenderer for use by security-sensitive applications.  Random Example: package com.knowledgefactory import java.util.* /* * A Kotlin program to demonstrate random number generation using java.util

Kotlin - Blowfish Encryption and decryption Example

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: import java.io.UnsupportedEncodingException import java.nio.charset.Charset import java.security.InvalidKeyException import java.security.NoSuchAlgorithmException import java.util.* import javax.crypto.BadPaddingException import javax.crypto.Cipher import javax.crypto.IllegalBlockSizeException import javax.crypto.NoSuchPaddingException impo

Quarkus - Interview questions and answers

Image
  1. What is Quarkus Framework?  The Quarkus is a full-stack, Kubernetes-native Java framework made for Java virtual machines and native compilation, optimizing Java categorically for containers and enabling it to become an efficacious platform for serverless, cloud, and Kubernetes environments. The goal of Quarkus is to make Java a leading platform in Kubernetes and serverless environments while offering developers an amalgamated reactive and imperative programming model to optimally address a wider range of distributed application architectures.     2. Why do we use Quarkus? The Quarkus optimizes Java and makes it efficient for containers, cloud, and serverless environments with memory consumption optimization and an expeditious first replication time. Quarkus optimizes Java and makes it efficient for containers, cloud, and serverless environments with memory consumption optimization and a fast first response time. The Quarkus has a low learning curve for Java developers. 3. What se