Social Icons

twitterfacebookgoogle pluslinkedinemail
Showing posts with label Java. Show all posts
Showing posts with label Java. Show all posts

Friday, 6 September 2013

Basic Concept of Interface in java

Interface is collection of abstract method.

Using the keyword interface,you can fully abstract a class interface from its implementation.

example of interface:

interface Callback
{
void callback(int p);
}


Wednesday, 4 September 2013

String handling class in java

In java,there are two String handling class available.That is the library class which is available is java.lang package.

String handling class
  1. String
  2. StringBuffer
Object of String class cannot change.we can change the value of StringBuffer class.

eg.      String  s = "Hello World";
           String  s = new String("Hello World");
               char a[] = {'a','b','c','d'};
              String s = new |String(a);
             
 here, s  is a object of String class.There are several in-built method for String handling class.

Thursday, 29 August 2013

what is thread in java...?

Thread is a light wait process.In java, Thread is class which are extends to the our program.

Thread class have a run method which will be executed the thread.start( ) method will be call the run method and execute whenever the program run Thread are executed in parallel so the which thread are first execute and which are second is not decided.

class Thread1 extends Thread
{
public void run()
{
for(int i=0;i<5;i++)
{
System.out.println("Thread 1: " + i);
}
}
}
class Thread2 extends Thread
{
public void run()
{
for(int i=0;i<5;i++)
{
System.out.println("Thread 2: " + i);
}
}
}
class Thread3 extends Thread
{
public void run()
{
for(int i=0;i<5;i++)
{
System.out.println("Thread 3: " + i);
}
}
}

class demo
{
public static void main(String args[])
{
Thread1 t1 = new Thread1();
Thread2 t2 = new Thread2();
Thread3 t3 = new Thread3();

t1.setPriority(Thread.MIN_PRIORITY);
t2.setPriority(Thread.NORM_PRIORITY);
t3.setPriority(Thread.MAX_PRIORITY);

t1.start();
t2.start();
t3.start();
}
}

Thread class has a setPriority() method which will be setting the priority and consider which thread are execute in first.

value of the setPriority() method:

MIN_PRIORITY     :1
NORM_PRIORITY :5
MAX_PRIORITY    :10

Default priority is NORM_PRIORITY.

Saturday, 17 August 2013

find the factorial of number in java

class demo
{
public static void main(String args[])
{
int a=5;
int ans=1;
for(int i=a;i>=1;i--)
{
ans= ans*i;
}
System.out.println(ans);
}
}

Thursday, 15 August 2013

method overriding in java

In the method overloading,there are the signature of the method are change and we are declare at the
compile time so its called method overloading.when the arguments are remain same in all method that is called method overriding.

whenever child class use the parent class method there are nature of the child class is different so the body of the method is change and child class is use for own environment.so the child class redefined the parent class method and after use it.

what is the upcasting

upcasting means that the hive reference of child class to parent class.

In the upcasting ,there are multiple child class for one parent class so the parent class can access the property of child class.

class A
{
void getA()
{
System.out.println("this is class getA metho for A class");
}
}

Wednesday, 14 August 2013

how to use abstract class in java

abstarct class means , we cannot create the instance of abstract class.
whenever we create the abstract class in java we cannot use the property of that class through the instance of that class.
so, how can we access the property of abstract class. we can access the property and method of abstract class using inheritance.
we can create the child class and inherit the abstract class and through the child class we can access the property of abstract class.

 

Free Advertisement

Free Advertisement

Free Advertisement

Free Advertisement