In this post, I am giving an example about implementing Bubble Sort in Java using characters as data types.
import java.io.* ;
public class BubbleSort {
public static void main (String args[]) {
String stringarray = "fgjhsflsdlkfghdksdkjdgskakdkfkjggkdkgjg";
int i, j;
i = j = 0 ;
char temp ;
int arrsize = 0 ;
int strsize = stringarray.length() ;
char strarray[] = new char[50] ;
System.out.println("Str array length: " + strsize) ;
System.out.println("Str array: " + stringarray) ;
for (int a = 0 ; a < strsize ; a++) {
strarray[a] = stringarray.charAt(a) ;
arrsize++ ;
}
System.out.println("char array length: " + arrsize) ;
//Bubble Sort code
for(i=0; i< (arrsize - 1); ++i) {
for(j = i + 1; j > 0; --j) {
if(strarray[j] < strarray[j-1]) {
//Swaps the values
temp = strarray[j];
strarray[j] = strarray[j - 1];
strarray[j - 1] = temp;
}
}
}
System.out.print("Values: " ) ;
for (int b = 0 ; b < strsize ; b++) {
System.out.print(strarray[b]) ;
}
}
}
Output:
Sunday, October 17, 2010
Bubble Sort Example using Char (Java)
Example for Capturing Transaction Time using currentTimeMillis() method (Java)
In this post, I am giving an example for Capturing Transaction Time using currentTimeMillis() method using Java.
import java.io.* ;
public class CalculateSystemTxTime {
public static void main (String args[]) {
// Calculate Start time
double startTime = System.currentTimeMillis();
System.out.println("Timer is Started") ;
// Performing somekind of transaction.
// Here, 1000 iterations are used as transaction.
int i = 500;
for (int j = 1 ; j <= 1000 ; j++) {
if (j == i)
System.out.println("The number is incremented upto the random number generated.") ;
}
// Calculate Stop Time
double stopTime = System.currentTimeMillis();
System.out.println("Timer is Stopped. Total time for incrementing is: " + (stopTime - startTime) + " sec." );
// Calculating average time
System.out.println("The average time for each increment is: " + (stopTime - startTime)/1000 + " sec.") ;
}
}
Output:
import java.io.* ;
public class CalculateSystemTxTime {
public static void main (String args[]) {
// Calculate Start time
double startTime = System.currentTimeMillis();
System.out.println("Timer is Started") ;
// Performing somekind of transaction.
// Here, 1000 iterations are used as transaction.
int i = 500;
for (int j = 1 ; j <= 1000 ; j++) {
if (j == i)
System.out.println("The number is incremented upto the random number generated.") ;
}
// Calculate Stop Time
double stopTime = System.currentTimeMillis();
System.out.println("Timer is Stopped. Total time for incrementing is: " + (stopTime - startTime) + " sec." );
// Calculating average time
System.out.println("The average time for each increment is: " + (stopTime - startTime)/1000 + " sec.") ;
}
}
Output:
Steps in Installing Android SDK within Eclipse
In this post, I am giving the steps to easily install Android in Windows 7 and hooking it up with Eclipse.
Installing in Windows XP and Vista is more or less the same.
Installing in Windows XP and Vista is more or less the same.
- Download Android SDK from here
- Extract the files and store them at any location.
- Go to start. Right click on My Computer and go to "properties"
- go to "advanced" --> "environment variables" and then to "system variables"
- now open "PATH" variable in system environment variables.
- Copy the path where Android is stored from "My Computer".
- In "Variable Value" at the end of the existing link, put a semicolon ';' and then paste the path of Android here.
- Press "OK" thrice to Come out of "System Properties"
- Start Eclipse
- Go to "Windows" --> "Android SDK and AVD Manager".
- If you are getting any error stating that Preferences is not set, then go to "Windows" --> "Preferences" --> "Android" and at SDK Location give the path to the location of Android in your system and press "Ok" .
- In "Android SDK and AVD Manager" go to "Available Packages in the left pane.
- There will be a root link in the right pane referring it to Google Android.
- Click the root link and make sure all the Child links are the child links are ticked.
- Then click "Install Selected" and then a pane named "Choose Packages to Install" appears.
- Click "Accept All" and then "Install" and a menu titled "Installing Archives" appears where all the packages get downloaded and installed.
- Sometimes, it takes a while to download and install all the Packages.
- Then, it asks permission to to restart ADB. Press "Yes" and after a while press "Ok".
- Press "Close".
- Close the "Android SDK and AVD Manager".
- Sometimes, it may ask to restart Eclipse. That should be "Ok".
Now, Android is installed in your system. To test if Android is successfully installed, go to "File" --> "New"
--> "Project". In the "New Project" menu, you will find "Android" and in it you will find "Android Project" and "Android Test Project". This ensures that Android is successfully installed.
Welcome to Android! Have Fun!
Cheers!
These following books can be referred for Android all though Google Support is better.
Subscribe to:
Posts (Atom)

