Posted In: Database, MySQL

MySQL AUTO_INCREMENT column

In case you worked most of life on Oracle DB you must be wondering where is the SEQUENCE. AUTO_INCREMENT column in MySQL is used for primary key column. For each insert MySQL will automatically update the column to next max value. For each new row, MySQL increments the value automatically and persist it to table. […]

Read More

by , on August 24th, 2017

Posted In: IO, Java Core

How to create a temporary file/directory in Java

JDK 7 createTempDirectory and createTempFile method creates temp folder with given suffix. I have also added deleteOnExit to delete temp folder but dir.toFile().deleteOnExit() does not seem to be reliable on Windows. package com.example.java.core; import java.nio.file.Files; import java.nio.file.Path; import java.nio.file.Paths; import org.junit.Test; public class TempFile { @Test public void create() throws Exception { Path dir = […]

Read More

by , on August 24th, 2017

Posted In: Date, Java Core

Convert java.util.Date to java.time.LocalDate, LocalDateTime

Date date1 = new SimpleDateFormat(“yyyy-MM-dd HH:mm:ss”) .parse(“2017-08-13 12:10:30”); LocalDate localdate = date1.toInstant().atZone(ZoneId.systemDefault()) .toLocalDate(); LocalDateTime localdatetime = date1.toInstant().atZone(ZoneId.systemDefault()) .toLocalDateTime();

Read More

by , on August 24th, 2017

Posted In: Date, Java Core

Comparing two Dates without the time portion

Techniques used 1. JODA Time DateTimeComparator 2. Apache Commons DateUtils 3. JDK 8 LocalDate 4. Below JDK 8 DateFormat  

Read More

by , on August 24th, 2017

Posted In: Security

How to encrypt Password/String using Bouncy castle library

Bouncy castle library Maven bcprov-jdk16

Read More

by , on August 24th, 2017

Posted In: Apache, Commons, Security

How to encrypt Password/String using Apache Crypto

Apache Crypto library Maven commons-crypto Original Example

Read More

by , on August 24th, 2017

Posted In: Security

How to encrypt Password/String using Jasypt library

Jasypt library provide multiple methods to encrypt a password Maven jasypt

Read More

by , on August 24th, 2017

Posted In: Apache, Commons, Security

How to encrypt Password/String using Apache Codec

Apache codec provide multiple methods to encrypt a string Maven commons-codec

Read More

by , on August 24th, 2017

Posted In: Java Core

How to determine the size of an object in Java

JDK 5 provides Instrumentation interface which can be used find Object Size Instrumentation set up requires entry to manifest file Premain-Class: ObjectAgent and use public static void premain(String agentArgs, Istrumentation instrumentation). There is little easy way to do it. Use memory-measurer Run class with javaagent VM argument  

Read More

by , on August 24th, 2017

Posted In: Java Core, String

String vs StringBuilder vs StringBuffer Simple Benchmark test

Since String is immutable in java any changes to it creates a new object. StringBuffer and StringBuilder are mutable objects. They provide methods like append(), insert(), delete() and substring() to manipulate date.   This test clearly shows that always use StringBuilder. It will perform much better than String concatenation. Result

Read More

by , on August 24th, 2017

  • Categories