>

Friday, February 22, 2013

Sort Letters in a String Object

public void doSorting(String str)
    {
     char array[]=str.toCharArray();
     char temp;
     System.out.print("Given name :");
     for(int i=0;i<array.length;i++)
     {
         System.out.print(array[i]);
     }
     System.out.println();
     for(int i=0;i<array.length;i++)
     {
         for(int j=0;j<i;j++)
         {
             if(array[i]<array[j])
             {
                temp=array[j];
                array[j]=array[i];
                array[i]=temp;
             }
         }
   
     }

CONTENT WARNING:This is my own program.. It is for Educational purposes only. Please do not republish or reproduce with another name in online.
   

Reverse String in JAVA


This is the method which will reverse the given STRING :


public void myOwnstringReversing(String str)
{
    for(int i=str.length()-1;i>=0;i--)
    {
        System.out.print(str.charAt(i));
    }
}




CONTENT WARNING:
This is my own program.. It is for Educational purposes only. Anyone do not republish in your website will be punished offensively.

Wednesday, December 19, 2012

Thread Program four in Java


public class Thread_Demo extends Thread{

public void run(){
System.out.println("Some text");
}
public static void main(String[] args) throws InterruptedException{


Thread_Demo t=new Thread_Demo();
Thread_Demo td1=new Thread_Demo();

t.start();

System.out.println("ISALIVE :"+t.isAlive());
t.sleep(500);
System.out.println("ISALIVE :"+t.isAlive());
//t.destroy();
t.resume();
System.out.println("ISALIVE :"+t.isAlive());
}

}

Thread Program three in Java


What is out put?

public class Thread_Demo extends Thread{

public void run(){
System.out.println("Some text");
}

public static void main(String[] args) throws InterruptedException {

Thread_Demo t=new Thread_Demo();
Thread_Demo td1=new Thread_Demo();
t.run();
System.out.println("ISALIVE :"+t.isAlive());
t.sleep(500);
System.out.println("ISALIVE :"+t.isAlive());
t.destroy();
System.out.println("ISALIVE :"+t.isAlive());
}

}

Thread Program Two in Java

What is output?


public class Thread_Demo extends Thread{

public void run(){
System.out.println("Some text");
}

public static void main(String[] args) throws InterruptedException {


Thread_Demo t=new Thread_Demo();
Thread_Demo td1=new Thread_Demo();

t.start();

System.out.println("ISALIVE :"+t.isAlive());
t.sleep(500);
System.out.println("ISALIVE :"+t.isAlive());
t.destroy();
System.out.println("ISALIVE :"+t.isAlive());
}

}

Thread Program in Java

What is out put?


public class Thread_Demo extends Thread{

public void run(){
System.out.println("Some text");
}

public static void main(String[] args) throws InterruptedException {


Thread_Demo td=new Thread_Demo();
Thread_Demo td1=new Thread_Demo();
/*Thread t=new Thread(td);*/
td.start();
td.setPriority(10);
System.out.println(td.getName()+td.getPriority());
td1.run();
System.out.println(td1.getName()+td1.getPriority());
}
}

Sunday, December 16, 2012

File Creation in java

import java.io.File;
import java.io.IOException;

public class FileCreatin {

    public static void main(String args[]) throws IOException
    {
        File f=new File("F:/java.txt");
        if(!f.exists())
        {
            f.createNewFile();
            System.out.println("file created successfully");
        }
        else
            System.out.println("File already exists");
       
    }
}