Posts

Showing posts from 2009

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 faster

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}};             System.out.println("Number of Row= " + array.length);             System.out.println("Number of Column= " + array[1].length);             int l= array.length;

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                 {                 System.out.println(array[i]);                 }             }     }  /* array[0] ="I" array[1] ="am" array[2] ="a&q

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");

Quick sort in java

Image
Quick sort algorithm is developed by C. A. R. Hoare. Quick sort is a comparison sort. The working of quick sort algorithm is depending on a divide-and-conquer strategy. A divide and conquer strategy is dividing an array into two sub-arrays. Quick sort is one of the fastest and simplest sorting algorithm. The complexity of quick sort in the average case is Θ(n log(n)) and in the worst case is Θ(n2). Working of quick sort algorithm: Input:12 9 4 99 120 1 3 10 13 Output:1 3 4 10 12 13 99 120 The code of the program : public class QuickSort{ public static void main(String a[]){ int i; int array[] = {12,9,4,99,120,1,3,10,13}; System.out.println(" Quick Sort\n\n"); System.out.println("Values Before the sort:\n"); for(i = 0; i < array.length; i++) System.out.print( array[i]+" "); System.out.println(); quick_srt(array,0,array.length-1); System.out.print("\nValues after the sort:\n\n

Sorting an array of integers in java

In computer science and mathematics, a sorting algorithm is an algorithm that puts elements of a list in a certain order. Summaries of popular sorting algorithms Bubble sort Insertion sort Shell sort Merge sort Heap sort Quick sort Bucket sort Radix sort Distribution sort Shuffle sort Make a class named whatever you want like as public class SortNumbers { public static void sort(int[] nums) { for (int i = 0; i < nums.length; i++) { int min = i; for (int j = i; j < nums.length; j++) { if (nums[j] < nums[min]) min = j; } int tmp; tmp = nums[i]; nums[i] = nums[min]; nums[min] = tmp; } } public static void main(String[] args) { int[] nums = new int[args.length]; // Create an array to hold numbers for (int i = 0; i < nums.length; i++) nums[i] = Integer.parseInt(args[i]); sort(nums); // Sort them for (int i = 0; i < nums.length; i++) // Pr

How to get values from command line in java

Hi friends A Java application can accept any number of arguments from the command line. This allows the user to specify configuration information when the application is launched. The user enters command-line arguments when invoking the application and specifies them after the name of the class to be run. When an application is launched, the runtime system passes the command-line arguments to the application's main method via an array of   String s.   This example is for all type data types, because from command line all the arguments are of string type. class getcommandtext {     public static void main(String[] args)     {         for (String s: args)             {             System.out.println(s);             }     } } For Numeric Command line Argument:- If an application needs to support a numeric command-line argument, it must convert a   String   argument that represents a number, such as "12", to a numeric value. class numericargument {     p

How to Try the New Google Search

Hi Firends Go to Google.com  Once it loads, enter this code into your web browser's URL address field: javascript:void(document.cookie="PREF=ID=0b6e4c2f44943bb:U=4bf292d46faad806:TM=1249677602:LM=1257919388:S=odm0Ys-53ZueXfZG;path=/;domain=.google.com"); 3. Hit the enter  4. Reload or open a new Google.com page and you will have access to the new user interface

How to write a java program

Dear friends,                  Java technology allows you to work and play in a secure computing environment.  Java allows you to play online games, chat with people around the world, calculate your mortgage interest, and view images in 3D, just to name a few.  Now to write a program java first Class test         {         public static void main(String[] args)             {              System.out.println("Hello! this is my first java program.");             }         } Save this as test.java open your command prompt type javac test.java A class test.class will be created in corresponding directory type java test It will print Hello! this is my first java program

How to make suggetion box using ajax in php from database onchange event

Image
Hell Friends Here is the example to get data from database using ajax in php (autocomplete) This is the front page viewable to the user. Here is the input box that get input by the user and showData function take the request and send it to the getdata.php file via ajax and send response to the user. index.php <html> <head> <title>autocomplete | Home</title> <script type="text/javascript"> var xmlhttp; function showData(str) { xmlhttp=GetXmlHttpObject(); if (xmlhttp==null) { alert ("Browser does not support HTTP Request"); return; } var url="getdata.php"; url=url+"?q="+str; url=url+"&sid="+Math.random(); xmlhttp.onreadystatechange=stateChanged; xmlhttp.open("GET",url,true); xmlhttp.send(nodata); } function stateChanged() { if (xmlhttp.readyState == 4) { document.getElementById("txtHint").innerHTML=xmlhttp.resp

Check username availability from database in php using jQuery

Hell Friends here is an example to Check username availability from database in php using jQuery. This will be done with three steps. First create a file " index.php " or whatever you want. Create a " user_availability.php ". Create database named "test" and table named "login". What is jquery? JQuery is a fast and concise JavaScript Library that simplifies HTML document traversing, event handling, animating, and Ajax interactions for rapid web development. jQuery is designed to change the way that you write JavaScript. index.php( This is the file from where you will input username ) <!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd"> <html> <head> <title>Username availability Checking using jQuery</title> <meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1"> <script src="jquery-1.