Posts

encryption in java

Image
The SHA hash functions are a set of cryptographic hash functions designed by the National Security Agency (NSA) and published by the NIST as a U.S. Federal Information Processing Standard. SHA stands for Secure Hash Algorithm. The three SHA algorithms are structured differently and are distinguished as SHA-0 , SHA-1 , and SHA-2 . The SHA-2 family uses an identical algorithm with a variable digest size which is distinguished as SHA-224 , SHA-256 , SHA-384 , and SHA-512 .   SHA-1 : The Secure Hash Algorithm (SHA) was developed by NIST and is specified in the Secure Hash Standard (SHS, FIPS 180). SHA-1 is a revision to this version and was published in 1994. It is also described in the ANSI X9.30 (part 2) standard. SHA-1 produces a 160-bit (20 byte) message digest. Although slower than MD5, this larger digest size makes it stronger against brute force attacks. MD5 : MD5 was developed by Professor Ronald L. Rivest in 1994. Its 128 bit (16 byte) message digest makes it a fas...

How to get google to index images quickly

Pictures are a valuable way to attract visitors to your site, because visitors search for them using Google, Yahoo and Bing image search. When an image is placed on a page, there is a space for two tags called ALT and TITLE. These tags are displayed to the user when the mouse hovers over a picture. Both an ALT and a TITLE tag are needed.   Before going to indexing, you should confirm about your images that they are visible google crawler So how will you check it Go to: http://www.smart-it-consulting.com/internet/google/googlebot-spoofer/ Some Guideline are here:- Give proper alt, title to the image Define the size(width and height) of image Each image must have unique alt tag Don't use src="images/abc.jpg". Better one is to used src="htttp://www.domain.com/images/abc.jpg" So you have to use full image path to display image in google search.

sum of matrix in java

Image
In this program we are going to calculate the sum of two matrix. To make this program, we need to declare two dimensional array of type integer. Firstly it calculates the length of the both the arrays. Now we need to make a matrix out of it. To make the matrix we will use the for loop. By making use of the for loop the rows and column will get divide. This process will be performed again for creating the second matrix. After getting both the matrix with us, we need to sum both the matrix. The both matrix will be added by using the for loop with array[i][j]+array1[i][j]. The output will be displayed by using the println() method. class summatrix {     public static void main(String[] args)              {             int array[][]= {{4,5,6},{6,8,9}};             int array1[][]= {{5,4,6},{5,6,7}};  ...

file upload using servlet

Hi friends Here is the example to upload a file using java servlet technology. <table> <tbody> <tr> <form action="http://your_host/servlet/UploadServlet?your_config" enctype="multipart/form-data" method="post"> <td> <input name="fname" size="20" type="file" /> </td> <td> <input type="Submit" value="Upload" /> </td> </form> </tr> </tbody></table> import java.io.File; import java.io.IOException; import java.util.Iterator; import java.util.List; import javax.servlet.ServletException; import javax.servlet.http.HttpServlet; import javax.servlet.http.HttpServletRequest; import javax.servlet.http.HttpServletResponse; import org.apache.commons.fileupload.DiskFileUpload; import org.apache.commons.fileupload.FileItem; import org.apache.commons.fileupload.FileItemFactory; import org.apache.commons.fileuploa...

split string in java

Java equivalent of PHP explode function In PHP we can easily break a long string into smaller parts by using the   explode()   function of PHP. $longstring="I am a cool guy " ; $brokenstring=explode(" ", $longstring); After the execution of the second command the variable $brokenstring is an array such that, $brokenstring[0]="I" $brokenstring[1]="am" $brokenstring[2]="a" $brokenstring[3]="cool" $brokenstring[4]="guy" In java we use String.split() function that achieves the same objective. class splitString     {         public static void main(String[] args)             {             String s1 = " I am a cool guy ";             String[] array = s1.split(" ");                    for(int i=0; i    ...

binary search in java

Image
Binary Search is the fast way to search a sorted array. The idea is to look at the element in the middle. If the key is equal to that, the search is finished. If the key is less than the middle element, do a binary search on the first half. If it's greater, do a binary search of the second half. public class BinarySearch { private long[] a; private int nElems; public BinarySearch(int max) { a = new long[max]; // create array nElems = 0; } public int size() { return nElems; } public int find(long searchKey) { return recFind(searchKey, 0, nElems - 1); } private int recFind(long searchKey, int lowerBound, int upperBound) { int curIn; curIn = (lowerBound + upperBound) / 2; if (a[curIn] == searchKey) return curIn; // found it else if (lowerBound > upperBound) return nElems; // can't find it else // divide range { if (a[curIn] < searchKey) // in upper half return recFind(searchKey, curI...

sort an array of object in java

Image
The java.util.Arrays class has static methods for sorting arrays, both arrays of primitive types and object types. The sort method can be applied to entire arrays, or only a particular range. For object types you can supply a comparator to define how the sort should be performed. All object types that implement Comparable (ie, defines compareTo() method), can be sorted with using a comparator. import java.util.Arrays; public class sortobjects { public static void main(String[] args) { String names[] = { "Ankit", "OM", "Deepti", "Anu" }; Arrays.sort(names); for (int i = 0; i < names.length; i++) { String name = names[i]; System.out.print("name = " + name + "; "); } Person persons[] = new Person[4]; persons[0] = new Person("Ankit"); persons[1] = new Person("OM"); persons[2] = new Person("Deepti"); persons[3] = new Person("Anu"); ...