Monday, 19 March 2018

AES Encryption in Javascript and Decryption in Java

AES stands for Advanced Encryption System and it’s a symmetric encryption algorithm.Many times we require to encrypt some plain-text such as password at the client side and send it to server and then server decrypts it to process further.AES encryption and decryption is easier to implement in the same platform such as Android client and Java server but sometimes it becomes challenging to decrypt an AES encrypted password in cross platform environment such as Javascript client and Java Server such as in spring mvc framework because if any system defaults do not match then the decryption will fail.

Friday, 16 March 2018

SMPP Java Example(Client)

This post provides SMPP java example by creating a simple SMPP client that sends short messages to mobile subscriber.Using this client either we can make simple submit to send message to a single mobile subscriber or can broadcast a message to multiple mobile subscribers in one shot.Also, we will verify the delivery receipt. For the client purpose we will be using existing java SMPP client library – jSMPP

Wednesday, 14 March 2018

AES Encryption and Decryption in Java(CBC Mode)

Transmitting confidential data such as plain text password through wire is always vulnerable to security.It is always recommended to encrypt such information and use SSL to transmit those confidential data.Java provides multiple encryption algorithm for this.In this post, we will be discussing about AES(Advanced Encryption Standard) symmetric encryption algorithm in java with CBC mode which is faster and more secure than 3DES.

Monday, 12 March 2018

JDBC - Difference between PreparedStatement and Statement in Java

JDBC API provides three types of Statement for wrapping an SQL query and sending for execution to the database, they are aptly named as Statement, PreparedStatement, and CallableStatement. First one, Statement is used to execute normal SQL queries e.g. select count(*) from Courses. You can also use it to execute DDL, DML and DCL SQL statements. The second one, PreparedStatement is specialized to execute parameterized queries e.g. select * from Courses where courseId=?, you can execute this SQL multiple times by just changing the course parameters. They are compiled and cached at database end, hence quite fast for repeated execution. The third member of this family is CallableStatement, which is there to execute or call stored procedures stored in the database.

Friday, 9 March 2018

A Simple Example to Check if File is Empty in Java

One of the readers of my blog Javarevisited emailed me yesterday about how to check if a file is empty in Java and that's why I am writing this post to show that using an example. The common approach for checking if a file is empty or not is to first check if the file exists or not and then check if it contains any content, but Java has done that hard work for you. Well, it's pretty easy to check emptiness for a file in Java by using length() method of the class. This method returns zero if the file is empty, but the good thing is it also returns zero if the file doesn't exist. Which means you don't need to check if the file exists or not.

Wednesday, 7 March 2018

How to implement Radix Sort in Java - Algorithm Example

The radix sort, like counting sort and bucket sort, is an integer based algorithm (i.e. the values of the input array are assumed to be integers). Hence radix sort is among the fastest sorting algorithms around, in theory. It is also one of the few O(n) sorting algorithm along with a bucket and counting sort. The particular distinction for radix sort is that it creates a bucket for each cipher (i.e. digit); as such, similar to bucket sort, each bucket in radix sort must be a growable list that may admit different keys.

Sunday, 4 March 2018

Mergesort in Java - Algorithm Example

The Merge sort algorithm is a divide and conquers algorithm. In the divide and conquer paradigm, a problem is broken into small problems where each small problem still retains all the properties of the larger problem -- except its size. To solve the original problem, each piece is solved individually; then the pieces are merged back together. For example, imagine you have to sort an array of 200 elements using the selection sort algorithm. Since selection sort takes O(n^2) time, it would take about 40,000-time units to sort the array. Now imagine splitting the array into ten equal pieces and sorting each piece individually still using selection sort. Now it would take 400-time units to sort each piece; for a grand total of 10*400 = 4000.