Under OTP, I showed with example how to generate an totp. By default the length of the totp generated will be 6. We can change that to any number between 6 and 8. In this post under OTP, I will show with example how to change totp length to 8. Below is the complete main…… Continue reading Changing the totp length
Month: January 2024
Verifying the TOTP
In this post, I will show with example how to verify TOTP. In my previous posts, under OTP I showed with example how to generate TOTP. To verify an TOTP we can use non-static overloaded “verify” methods in “TOTP” class. Below is the complete code for your reference. Main Class 1 package defaultPackage;2 3 import…… Continue reading Verifying the TOTP
@Cleanup calling custom method
In the previous post under Lombok, I explained with purpose of “@Cleanup” annotation. “@Cleanup” annotation applied to any field assumes it as a resource and closes it just before the program ends. By default it assumes that the annotated field or resource or the instance has a method named “close” and when the time comes…… Continue reading @Cleanup calling custom method
Merging two character arrays
In this post under Java. I will show with example how to merge two character arrays into one. Below is the complete code for your reference. Main Class 1 package core.string; 2 3 public class Example1 { 4 public static void main(String[] args) { 5 char[] inputArray1 = {‘a’, ‘b’, ‘c’}; 6 char[] inputArray2 =…… Continue reading Merging two character arrays
Changing the algorithm when generating totp
In previous post, I showed with example how to generate an TOTP. I also mentioned in my previous post, how the framework by default using SHA-1 algorithm to generate the totp. In this post under OTP, I will show with example how to change the default algorithm. Below is the code for your reference. 1…… Continue reading Changing the algorithm when generating totp
@Cleanup annotation example
In this post under Lombok, I will explain with example the purpose of “@Cleanup” annotation. In Java whenever we open a resource, we have to close it after we are done with the resource. Usually all resource will have “close” method. We call that “close” method to close the resource. To do this in Java,…… Continue reading @Cleanup annotation example
assertArraysEquals example
In this post under Junit 5, I will explain with example the purpose of “assertArraysEquals” method. We can use the “assertArraysEquals” method to assert whether two arrays are equal or not. Below is the complete main code for your reference. Main Class package package15;import static org.junit.jupiter.api.Assertions.assertAll;import static org.junit.jupiter.api.Assertions.assertArrayEquals;import org.junit.jupiter.api.Test;public class Example15 { @Test public void…… Continue reading assertArraysEquals example
InstanceCreator example
In this post under Gson, I will show with example the purpose of “InstanceCreator” interface provided by Gson framework. Whenever we define a Pojo class, we don’t add constructor of our own, as we use Java provided default no argument constructor to create an object of the class. But sometimes we end up adding constructors…… Continue reading InstanceCreator example
Merging text files
In this post under Java I will with example how to merge two or more text files. Below is the complete code for your reference Main class 1 package io;2 3 import java.io.*;4 5 public class IOExample3 {6 private static int BYTES_TO_BE_READ = 1000;7 private char buffer[] = new char[BYTES_TO_BE_READ];8 9 public static void main(String[]…… Continue reading Merging text files
Creating text file of user specified size with random data
In this post under Java, I will show with example how to create a text file of user specified size with random data. Below is the complete code for you example Main class 1 package io;2 3 import java.io.BufferedWriter;4 import java.io.File;5 import java.io.FileWriter;6 import java.io.IOException;7 import java.util.Random;8 9 public class IOExample1 {10 private Random random;11…… Continue reading Creating text file of user specified size with random data