>

Friday, December 14, 2012

Threads Question And Answers

What is thread?
It is the unit of execution which doesn't have any existence.

What is Synchronization?
It is the controlling mechanism when multiple threads are trying to access same resource.

How can be a thread Created?
By extending thread class and implementing runnable interface.

What is the use of sleep method?
Sleep method is used to stop the execution of a thread temporarily for a user defined milliseconds.

What is Preemptive Scheduling?
When an lower priority thread is already running  that thread will be suspended and higher priority thread will get executed.

What is Time slicing?
It is the process where the time is sliced between equal priority threads.

What are the methods available in threads?
Thread t=new Thread();
t.getName()-To get the name of thread.
t.setName()-To set the name for thread.
t.getPriority()- To get the priority
t.setPriority()-To set the priority

constant properties of thread
MAX_PRIORITY=10
MIN_PRIORITY=1
NORM_PRIORITY=5

What are the states of an thread?
newborn()->runnable->running>dead.

What is Daemon Thread?

It is a thread which will be invoked by automatically without intervention of user. Garbage collector is example for Daemon Thread.

What is run Method?
Whether we use implement runnable or extending thread the public void run() method should be override. And using start() method we start running a thread.

Saturday, December 8, 2012

Java Find maximum value in an array

import java.util.Scanner;
public class ArrayMaximum {
 public static void main(String args[])
 {
     System.out.println("Enter the limit for array :");
     Scanner in=new Scanner(System.in);
     int limit=in.nextInt();
     int array[]=new int[limit];
     System.out.println("enter the values for array :");
     for(int i=0;i<array.length;i++)
     {
         array[i]=in.nextInt();
     }
         System.out.println("Values of array");
             for(int m:array)
             {
                 System.out.print(" "+m);
             }
             System.out.println();
             int max=array[0];
             for(int j=1;j<array.length;j++){
                 if((array[j])>max)
                  max=array[j];
                  else
                      max=array[0];
                
             }
             System.out.println("biggest Number in this array "+ max);
 }
}


OUTPUT
Enter the limit for array :
5
enter the values for array :
4
5
6
7
8
Values of array
 4 5 6 7 8
biggest Number in this array 8

Friday, December 7, 2012

String Replace in Java

Most of us know that replace function in  String is only works with characters. As work within single quotes.. But String replace function also works fine with double quotes.

public class StringManipulation {

    public static void main(String args[]){

        String name="commission";
        name=name.replace("i","j");
        System.out.println(name);
    }
}


OUTPUT

commjssjon

Sequence Labelling a New Technology

SEQUENCE LABELING:

Sequence labeling is a technology where appliances in our home will interactive with us. Means they will listen our commands and take action based on commands. In addition with predefined algorithms. And  reduce the workload for housewives, senior citizens, disabled persons. But in out of box it will be increase our laziness. Because now a days people are forgot to walk. Most people will not walk even 30 minutes per day.

Smart homes, or homes wherein appliances are turned on or off with direction from us — either pre-loaded cues, or through speech recognition — already exist. Apparently, these technologies are based on a process called sequence labelling, which classifies how tasks occur in a consequential sequence.

For more details visit the
http://www.thehindu.com/sci-tech/technology/towards-a-smart-home/article4156967.ece

An article from Hindu.,.. 

 

Friday, November 9, 2012

Java Program without Semicolon

 class Program
{
public static void main( String[] args )
{
 if( System.out.printf( "India not poor country%n" )== null ){
 }
}}

OUTPUT:
India not poor country

Factorial Using While loop in java

import java.util.Scanner;

class FactorialWhile{

 public static void main(String args[]){

    int fact=1,num,i=1;

    System.out.println("Enter the number:");

   Scanner in=new Scanner(System.in);

   num=in.nextInt();

  while(i<=num){

    fact=fact*i;

    i++;
}

  System.out.println("factorial of given number is "+fact);
}  }


OUTPUT:

Enter the number:
4
factorial of given number is 24

String Reverse Program in Java Wihtout Reverse Function

import java.util.Scanner;

public class StringReverse {
public static void stringReverse(String name)
{
    String str=name;
    char c[]=str.toCharArray();
        System.out.println("Reversed String : ");
    for(int i=str.length();i>0;i--)
    {
        System.out.print(c[i-1]);

    }
       

       
        }
    public static void main(String[] args) {
        // TODO Auto-generated method stub
        Scanner in=new Scanner(System.in);
        System.out.println("enter your string:");
        String input=in.nextLine();
        System.out.println("Given String Value :"+ input);
        stringReverse(input);
    }

}


OUTPUT:
enter your string:
Kanimozhi
Given String Value :Kanimozhi
Reversed String :
ihzominaK