Monday, 21 April 2014

collections---------------treeset----------------comparator

import java.util.*;
class MyComparator implements Comparator
{
    public int compare(Object obj1,Object obj2)
    {
        Integer i1=(Integer) obj1;
        Integer i2=(Integer) obj2;
        //return i1.compareTo(i2);//Ascending Order
        //return -i1.compareTo(i2);//Dscending Order
        //return +1;//INSERTION ORDER
        return -1;//REVERSE INSERTION ORDER
       
    }
}
class  CustomTreeSetDemo//follows dictionary order but we can customize using comparatot interface.
{
    public static void main(String[] args)
    {
        TreeSet ts=new TreeSet(new MyComparator());
        ts.add(10);//doesn't follwo insertion order
        ts.add(20);
        ts.add(50);
        ts.add(20);//don't allows duplicate values
        ts.add(40);
        ts.add(30);
        ts.add(70);
       
        ts.add(60);
       

        System.out.println(ts.add(20));//false
        //System.out.println(ts.add(null));//allow one time get R.E. i.e. Exception in thread "main" java.lang.NullPointerExceptio
       

        //ts.add("a");//hetero geneous objects are allowed.
        //R.E. i.e. Exception in thread "main" java.lang.ClassCastException: java.lang.Integer canno
        //t be cast to java.lang.String
        //at java.lang.String.compareTo(Unknown Source)
        //at java.util.TreeMap.put(Unknown Source)
        //at java.util.TreeSet.add(Unknown Source)
       //at TreeSetDemo.main(TreeSetDemo.java:20)
       
        System.out.println(ts);
    }
}

collections-------Set----------------TreeSet


import java.util.*;
class  TreeSetDemo
{
    public static void main(String[] args)
    {
        TreeSet ts=new TreeSet();
        ts.add(10);//doesn't follwo insertion order
        ts.add(20);
        ts.add(20);//don't allows duplicate values
        ts.add(30);
        ts.add(40);
        ts.add(50);
        ts.add(60);
        ts.add(70);

        System.out.println(ts.add(20));//false
        //System.out.println(ts.add(null));//allow one time get R.E. i.e. Exception in thread "main" java.lang.NullPointerExceptio
       

        //ts.add("a");//hetero geneous objects are allowed.
        //R.E. i.e. Exception in thread "main" java.lang.ClassCastException: java.lang.Integer canno
        //t be cast to java.lang.String
        //at java.lang.String.compareTo(Unknown Source)
        //at java.util.TreeMap.put(Unknown Source)
        //at java.util.TreeSet.add(Unknown Source)
       //at TreeSetDemo.main(TreeSetDemo.java:20)
       
        System.out.println(ts);
    }
}

Collection-----------Set----------HashSet

import java.util.*;
class  HashSetDemo
{
    public static void main(String[] args)
    {
        HashSet ts=new HashSet();
        ts.add(10);//doesn't follow insertion order
        ts.add(20);
        ts.add(20);//don't allows duplicate values

        System.out.println(ts.add(20));//false
        System.out.println(ts.add(null));//allow one time retuns true
        System.out.println(ts.add(null));//false

        ts.add("a");//hetero geneous objects are allowed.
        ts.add("b");
        ts.add("c");
        System.out.println(ts);
    }
}

Saturday, 19 April 2014

Collections----------->>>>>>>>>Stack

Stack:[LAST IN FIRST OUT]

import java.util.Stack;
class StackExamp
{
public static void main(String[] args)
{Stack s=new Stack();
s.push("a");
s.push("b");
s.push("c");
s.push("d");
s.push("e");
System.out.println(s);
s.pop();
System.out.println(s);
System.out.println(s.peek());
System.out.println(s.size());
System.out.println(s.search("b"));// returns the position of b i.e.3
System.out.println(s.search("z"));//-1
ArrayList al=new ArrayList(s);// convertion  object  stack to arraylist
System.out.println(al);



}
}


OUTPUT:
D:\anvesh_java>java StackExamp
[a, b, c, d, e]
[a, b, c, d]
d
4
3
-1

collections-------------->>>>>>>>>>>Linkedlist

LinkedList;   It is best for Insrtion and deletion operations

LL is Given by java.util.LinkedList Package.
programe;
import java.util.LinkedList;
class LnkdListExamp
{
public static void main(String[] args)
{LinkedList ll=new LinkedList();
ll.add("c");
ll.add("c");
ll.add("c");
ll.add("c");
ll.add("c");
System.out.println(ll);
ll.addFirst("f");
ll.addLast("l");
System.out.println(ll);

System.out.println(ll.getFirst());
System.out.println(ll.getLast());

}
}
output:
D:\anvesh_java>java LnkdListExamp
[c, c, c, c, c]
[f, c, c, c, c, c, l]
f
l





D:\anvesh_java>javap java.util.LinkedList
Compiled from "LinkedList.java"
public class java.util.LinkedList extends java.util.AbstractSequentialList imple
ments java.util.List,java.util.Deque,java.lang.Cloneable,java.io.Serializable{
    public java.util.LinkedList();
    public java.util.LinkedList(java.util.Collection);
    public java.lang.Object getFirst();
    public java.lang.Object getLast();
    public java.lang.Object removeFirst();
    public java.lang.Object removeLast();
    public void addFirst(java.lang.Object);
    public void addLast(java.lang.Object);
    public boolean contains(java.lang.Object);
    public int size();
    public boolean add(java.lang.Object);
    public boolean remove(java.lang.Object);
    public boolean addAll(java.util.Collection);
    public boolean addAll(int, java.util.Collection);
    public void clear();
    public java.lang.Object get(int);
    public java.lang.Object set(int, java.lang.Object);
    public void add(int, java.lang.Object);
    public java.lang.Object remove(int);
    public int indexOf(java.lang.Object);
    public int lastIndexOf(java.lang.Object);
    public java.lang.Object peek();
    public java.lang.Object element();
    public java.lang.Object poll();
    public java.lang.Object remove();
    public boolean offer(java.lang.Object);
    public boolean offerFirst(java.lang.Object);
    public boolean offerLast(java.lang.Object);
    public java.lang.Object peekFirst();
    public java.lang.Object peekLast();
    public java.lang.Object pollFirst();
    public java.lang.Object pollLast();
    public void push(java.lang.Object);
    public java.lang.Object pop();
    public boolean removeFirstOccurrence(java.lang.Object);
    public boolean removeLastOccurrence(java.lang.Object);
    public java.util.ListIterator listIterator(int);
    public java.util.Iterator descendingIterator();
    public java.lang.Object clone();
    public java.lang.Object[] toArray();
    public java.lang.Object[] toArray(java.lang.Object[]);
    static java.util.LinkedList$Entry access$000(java.util.LinkedList);
    static int access$100(java.util.LinkedList);
    static java.lang.Object access$200(java.util.LinkedList, java.util.LinkedLis
t$Entry);
    static java.util.LinkedList$Entry access$300(java.util.LinkedList, java.lang
.Object, java.util.LinkedList$Entry);
}


D:\anvesh_java>

Friday, 18 April 2014

collections---------->>>>>>>>>>>>Vectro Class----------------->>>>>>>>>>>Synchronized Methods


D:\anvesh_java>javap java.util.Vector
Compiled from "Vector.java"
public class java.util.Vector extends java.util.AbstractList implements java
l.List,java.util.RandomAccess,java.lang.Cloneable,java.io.Serializable{
    protected java.lang.Object[] elementData;
    protected int elementCount;
    protected int capacityIncrement;
    public java.util.Vector(int, int);
    public java.util.Vector(int);
    public java.util.Vector();
    public java.util.Vector(java.util.Collection);
    public synchronized void copyInto(java.lang.Object[]);
    public synchronized void trimToSize();
    public synchronized void ensureCapacity(int);
    public synchronized void setSize(int);
    public synchronized int capacity();
    public synchronized int size();
    public synchronized boolean isEmpty();
    public java.util.Enumeration elements();
    public boolean contains(java.lang.Object);
    public int indexOf(java.lang.Object);
    public synchronized int indexOf(java.lang.Object, int);
    public synchronized int lastIndexOf(java.lang.Object);
    public synchronized int lastIndexOf(java.lang.Object, int);
    public synchronized java.lang.Object elementAt(int);
    public synchronized java.lang.Object firstElement();
    public synchronized java.lang.Object lastElement();
    public synchronized void setElementAt(java.lang.Object, int);
    public synchronized void removeElementAt(int);
    public synchronized void insertElementAt(java.lang.Object, int);
    public synchronized void addElement(java.lang.Object);
    public synchronized boolean removeElement(java.lang.Object);
    public synchronized void removeAllElements();
    public synchronized java.lang.Object clone();
    public synchronized java.lang.Object[] toArray();
    public synchronized java.lang.Object[] toArray(java.lang.Object[]);
    public synchronized java.lang.Object get(int);
    public synchronized java.lang.Object set(int, java.lang.Object);
    public synchronized boolean add(java.lang.Object);
    public boolean remove(java.lang.Object);
    public void add(int, java.lang.Object);
    public synchronized java.lang.Object remove(int);
    public void clear();
    public synchronized boolean containsAll(java.util.Collection);
    public synchronized boolean addAll(java.util.Collection);
    public synchronized boolean removeAll(java.util.Collection);
    public synchronized boolean retainAll(java.util.Collection);
    public synchronized boolean addAll(int, java.util.Collection);
    public synchronized boolean equals(java.lang.Object);
    public synchronized int hashCode();
    public synchronized java.lang.String toString();
    public synchronized java.util.List subList(int, int);
    protected synchronized void removeRange(int, int);
}

Programme;
import java.util.Vector;
class VectorExamp
{
public static void main(String[] args)
{Vector v=new Vector();
v.addElement("a");
v.addElement("b");
v.addElement("c");
v.addElement("d");
v.addElement("d");
System.out.println(v);
v.removeElement("d");
System.out.println(v);System.out.println(v.size());
}
}

out put:

D:\anvesh_java>java VectorExamp
[a, b, c, d, d]
[a, b, c, d]
4

D:\anvesh_java>

Array List Method------------->>>>>>>>>>>clone()

import java.util.GregorianCalendar;

public class ObjectDemo {

   public static void main(String[] args) {

      GregorianCalendar calendar = new GregorianCalendar();

     
      GregorianCalendar  y = (GregorianCalendar) calendar.clone();

   
      System.out.println("" + calendar.getTime());
      System.out.println("" + y.getTime());


   }
}

Collections------------->>>>>>>>>>>List---------->>>>>ArrayList------------>>>>>>>>>>Array List Methods

Array List Methods:
SNMethods with Description
1void add(int index, Object element)
Inserts the specified element at the specified position index in this list. Throws IndexOutOfBoundsException if the specified index is is out of range (index < 0 || index > size()).
2boolean add(Object o) 
Appends the specified element to the end of this list.
3boolean addAll(Collection c)
Appends all of the elements in the specified collection to the end of this list, in the order that they are returned by the specified collection's iterator. Throws NullPointerException if the specified collection is null.
4boolean addAll(int index, Collection c) 
Inserts all of the elements in the specified collection into this list, starting at the specified position. Throws NullPointerException if the specified collection is null.
5void clear() 
Removes all of the elements from this list.
6Object clone() 
Returns a shallow copy of this ArrayList.
7boolean contains(Object o) 
Returns true if this list contains the specified element. More formally, returns true if and only if this list contains at least one element e such that (o==null ? e==null : o.equals(e)).
8void ensureCapacity(int minCapacity) 
Increases the capacity of this ArrayList instance, if necessary, to ensure that it can hold at least the number of elements specified by the minimum capacity argument.
9Object get(int index) 
Returns the element at the specified position in this list. Throws IndexOutOfBoundsException if the specified index is is out of range (index < 0 || index >= size()).
10int indexOf(Object o) 
Returns the index in this list of the first occurrence of the specified element, or -1 if the List does not contain this element.
11int lastIndexOf(Object o)
Returns the index in this list of the last occurrence of the specified element, or -1 if the list does not contain this element.
12Object remove(int index) 
Removes the element at the specified position in this list. Throws IndexOutOfBoundsException if index out of range (index < 0 || index >= size()).
13protected void removeRange(int fromIndex, int toIndex) 
Removes from this List all of the elements whose index is between fromIndex, inclusive and toIndex, exclusive.
14Object set(int index, Object element) 
Replaces the element at the specified position in this list with the specified element. Throws IndexOutOfBoundsException if the specified index is is out of range (index < 0 || index >= size()).
15int size() 
Returns the number of elements in this list.
16Object[] toArray() 
Returns an array containing all of the elements in this list in the correct order. Throws NullPointerException if the specified array is null.
17Object[] toArray(Object[] a) 
Returns an array containing all of the elements in this list in the correct order; the runtime type of the returned array is that of the specified array.
18void trimToSize() 
Trims the capacity of this ArrayList instance to be the list's current size.


import java.util.*;
public class ArrayListDemo1

{
public static void main(String[] args)
{
ArrayList al=new ArrayList();
al.add("hi");
al.add("you");
System.out.println(al);

System.out.println(al.contains("hi"));
System.out.println(al.size());
;


}
}
//adding  objects  to AL.

import java.util.*;
public class Ald
{
public static void main(String[] args)
{

ArrayList al=new ArrayList();
al.add(10);
al.add(20);
al.add(30);
al.add(40);
al.add(50);
al.add(60);
al.add(70);

System.out.println(al);
al.set(0,"anvesh");
System.out.println(al);
al.remove(1);
System.out.println(al);

ArrayList bl=new ArrayList();
bl.add(1);
bl.add(2);
bl.add(3);
bl.add(4);
bl.add(5);
bl.add(6);
bl.add(7);
bl.addAll(al);
//bl.retainAll(collection("20","30"))
System.out.println(bl);
bl.clear();
System.out.println(al);

}
}

http://www.tutorialspoint.com/java/java_arraylist_class.htm

Tuesday, 15 April 2014

Setting Path in JDK

How to set path in Java


If you are saving the java source file inside the jdk/bin directory, path is not required to be set because all the tools will be available in the current directory.The path is required to be set for using tools such as javac, java etc.
But If you are having your java file outside the jdk/bin folder, it is necessary to set path of JDK.
There are 2 ways to set java path:
  1. temporary
  2. permanent

  1. temporary path setting

how to set path in java







2) How to set Permanent Path of JDK in Windows

For setting the permanent path of JDK, you need to follow these steps:
  • Go to MyComputer properties -> advanced tab -> environment variables -> new tab of user variable -> write path in variable name -> write path of bin folder in variable value -> ok -> ok -> ok

For Example:

1)Go to MyComputer properties
how to set path in java
2)click on advanced tab
how to set path in java
3)click on environment variables
how to set path in java
4)click on new tab of user variables
how to set path in java
5)write path in variable name
how to set path in java
6)Copy the path of bin folder
how to set path in java
7)paste path of bin folder in variable value
how to set path in java
8)click on ok button
how to set path in java
9)click on ok button
how to set path in java

java-tutorial

What is Java?

Java is a programming language and a platform.
Platform Any hardware or software environment in which a program runs, known as a platform. Since Java has its own Runtime Environment (JRE) and API, it is called platform.


Where it is used?

According to Sun, 3 billion devices run java. There are many devices where java is currently used. Some of them are as follows:
  1. Desktop Applications such as acrobat reader, media player, antivirus etc.
  2. Web Applications such as irctc.co.in etc.
  3. Enterprise Applications such as banking applications.
  4. Mobile
  5. Embedded System
  6. Smart Card
  7. Robotics
  8. Games etc.

Types of Java Applications

There are mainly 4 type of applications that can be created using java:

1) Standalone Application

It is also known as desktop application or window-based application. An application that we need to install on every machine such as media player, antivirus etc. AWT and Swing are used in java for creating standalone applications.

2) Web Application

An application that runs on the server side and creates dynamic page, is called web application. Currently, servlet, jsp, struts, jsf etc. technologies are used for creating web applications in java.

3) Enterprise Application

An application that is distributed in nature, such as banking applications etc. It has the advantage of high level security, load balancing and clustering. In java, EJB is used for creating enterprise applications.

4) Mobile Application

An application that is created for mobile devices. Currently Android and Java ME are used for creating mobile applications.

Sunday, 13 April 2014

CustomException Throws

class ThrowsDemo
{
public static void main(String[] args) throws InterruptedException
{
doStuff();

}
static void doStuff() throws InterruptedException
{
doMoreStuff();

}
static void doMoreStuff() throws InterruptedException
{
System.out.println("Hi!");
Thread.sleep(5000);
System.out.println("I am Fine!");
}

}

Custom Exception

Custom Exception User Defined Exception:
class TooYoungExceptionDemo extends RuntimeException
{
TooYoungExceptionDemo(String str)
{
super(str);

}

};
class CEDemo
{
public static void main(String[] args)
{
int age= Integer.parseInt(args[0]);
        if (age<18)
{throw new TooYoungExceptionDemo("sorry! wait 4 some time");
}

else if(age>50)
{
throw new TooYoungExceptionDemo("sorry! u r not elible");
}System.out.println("sorry! egt good match");


}
}

Saturday, 12 April 2014

Throwing Exceptions

Throwing Exceptions
There are two parts to exceptions in Java – reporting them and recovering from them.  Because the location of the error usually occurs at a point in the program beyond where something can be done, a flexible way of dealing with problems had to be created.  In Java, exception handling is such a mechanism.  The idea is that when an error is reported, it can be passed back to a location in the code that knows what to do with it.

The first job is fairly simple – you have to report the error.  You do this with the “throws” clause and an appropriate exception object.  There are several different types:

hierarchy

Class StringIndexOutOfBoundsException

  • java.lang.Object
    • java.lang.Throwable
      • java.lang.Exception
        • java.lang.RuntimeException
          • java.lang.IndexOutOfBoundsException
            • java.lang.StringIndexOutOfBoundsException
              • if index in the string is passing greater then the string size 
                or negative value of index in string.

                        class Example {

                                public static void main(String[] args) {        
                                    
                                  
                        String str = "hello my friends";
                                    
                                    String str1 = str.substring(20);
                                    
                                }

                        }





                    out put:
                    Exception in thread "main" java.lang.StringIndexOutOfBoundsException: String ind
                    ex out of range: -4
                            at java.lang.String.substring(String.java:1937)
                            at java.lang.String.substring(String.java:1904)
                            at Example.main(Example.java:9)

Class ArrayIndexOutOfBoundsException

Class Cast Exception


class Animal {
    public void eat(String str) {
        System.out.println("Eating for grass");
    }
}

class Goat extends Animal {
    public void eat(String str) {
        System.out.println("blank");
    }
}

class Another extends Goat{
  public void eat(String str) {
        System.out.println("another");
  }
}

public class InheritanceSample {
    public static void main(String[] args) {
        Animal a = new Animal();
        Another t5 = (Another) new Goat();
    }
}



o/p:
D:\anvesh>java InheritanceSample
Exception in thread "main" java.lang.ClassCastException: Goat cannot be cast to
Another
        at InheritanceSample.main(InheritanceSample.java:22)

NumberformatExceptionDemo

class NumberformatExceptionDemo
{

public static void main(String args[])
  {
    String str1= "10";
    int x = Integer.parseInt(str1);
    System.out.println(x*x);    // prints 100

    try
    {
      String str2= "ten";
      int y = Integer.parseInt(str2);
    }
    catch(NumberFormatException e)
    {
      System.err.println("Unable to format. " + e);
    }

}
}

Exception Handling Multiple catch Blocks

java.lang.Exception----->java.lang.RunTimeExceptions


public class EXCEPTIONDemo 
{
public void show(int a)
{
try
{
System.out.println(5.5);
}
catch(ArithmeticException e)
{
System.out.println("ArtmeticException"+e.getMessage());
}
catch(NumberFormatException e)
{
System.out.println("NumberFormatException"+e.getMessage());
}
catch(ClassCastException e)
{
System.out.println("ccException"+e.getMessage());
}
catch(NullPointerException e)
{
System.out.println("NpException"+e.getMessage());
}
catch(ArrayIndexOutOfBoundsException e)
{
System.out.println("aiotofbdsException"+e.getMessage());
}
catch(StringIndexOutOfBoundsException e)
{
System.out.println("NumberFormatException"+e.getMessage());
}
catch(IllegalArgumentException e)
{
System.out.println("NumberFormatException"+e.getMessage());
}
finally
{
System.out.println("final alweays executes");
}
}
public static  void main(String[] args) 
EXCEPTIONDemo eXCEPTIONDemo=new EXCEPTIONDemo();
eXCEPTIONDemo.show(5);
}

 

}

Errors

java.lang.throwable--->java.lang.error:



public class EXCEPTIONDemo
{
public void m1()
{
System.out.println(8);
m2();
}
public void m2()
{
System.out.println(8);
m1();
}
 






public static  void main(String[] args)
{

EXCEPTIONDemo eXCEPTIONDemo=new EXCEPTIONDemo();
eXCEPTIONDemo.m1();


}



}

Thursday, 10 April 2014

CODING STANDARDS?

package com.codingdemo;//package

public class CodingDemo {//demo class
   
//VARIABLES
private String accountNumber="ABN012345";
public static final double MIN_BAL=500.00;
//constructor
CodingDemo()
{
System.out.println("constructor");

}
//inner class
   class Enquiry
{
  Enquiry()
  {
 
  }
//System.out.println("constructor");
}
//methods
public void show(){
System.out.println("methods");

}
//main



public static void main(String[] args)
{
CodingDemo codingDemo=new CodingDemo();


System.out.println("hi");

}

}

Wednesday, 9 April 2014

Difference between StringBuffer && StringBuilder class?

1.Difference between StringBuffer && StringBuilder class?
StringBuffer class:
all methods are synchronised methods.

StringBuilder class:
All methods are Non-Synchronized methods.


2.Difference between String &&  StringBuilder class?



String class:
all methods are synchronised methods.

StringBuilder class:
All methods are Non-Synchronized methods.

Note: remaining diferences are same as String && StringBuffer class.

difference between equals&& = = operator ?



//StringMethodsDemo for equals() && = =
class  StringMethodsDemo
{
};
//StringMethodsDemoImpl
class  StringMethodsDemoImpl
{//main()
public static void main(String[] args)
{
StringMethodsDemo  stringMethodsDemo=new StringMethodsDemo();
String string1=new String("hello");//String class object
String string2=string1;
String string3=new String("hello");//String class object

System.out.println(string1==string2);
System.out.println(string1.equals(string2));
}
}

out put:

D:\anvesh_java>java StringMethodsDemoImpl
true
true

Difference between Concat And Append methods

class StringMethods
{
public static void main(String[] args)
{//immutable
String s1=new String("hello");
String s2=new String("java");
System.out.println(s1.concat(s2));
       System.out.println(s1.length());
  System.out.println(s2.length());
//mutable
StringBuffer sb1=new StringBuffer("hello");
StringBuffer sb2=new StringBuffer(" core");
System.out.println(sb1.append(sb2));
System.out.println(sb1.length());
System.out.println(sb2.length());
System.out.println("sb1 object capacity"+sb1.capacity());
System.out.println("sb2 object capacity"+sb2.capacity());
//sb.append("java");
//sb.insert(5,"---new---");
//sb.delete(2,3);
//System.out.println(sb.capacity());
//System.out.println(sb.reverse());
//System.out.println(sb.length());
}
}

D:\anvesh_java>javac StringMethods.java

D:\anvesh_java>java StringMethods
hellojava
5
4
hello core
10
5
sb1 object capacity21
sb2 object capacity21

Difference between String class StringBuffer class

class StringSBdiff // difference between String class StringBuffer class

{
public static void main(String[] args)
{
//String class
String s1=new String("hello");
String s2=new String("hello");
String s3=s1;
System.out.println(s1.equals(s2));
System.out.println(s1.equals(s3));

//StringBuffer class

StringBuffer sb1=new StringBuffer("hello");
StringBuffer sb2=new StringBuffer("hello");
StringBuffer sb3=sb1;
System.out.println(sb1.equals(sb2));
System.out.println(sb1.equals(sb3));


}

StringBuffer Methods

class SbDemo
{

public static void main(String[] args)
{
StringBuffer sb1=new  StringBuffer("hello how are");
StringBuffer sb2=new  StringBuffer(4);
System.out.println(sb1);
sb2.append("hey");
System.out.println(sb2);
System.out.println("Hello World!");
}
}

StringBufferMethods




class StringMethods
{
public static void main(String[] args)
{
StringBuffer sb=new StringBuffer("hello");
sb.append("java");
sb.insert(5,"---new---");

System.out.println(sb);
System.out.println(sb);
System.out.println(sb.length());
}
}

Thursday, 3 April 2014

Final Method


Final Method:
class Parent {
  public  void show()
{
System.out.println("parent ");

}


}

class Child extends Parent {
public final void show()
{
System.out.println("child ");

}
public static void main(String[] args)
{
Child c=new Child();
c.show();
Parent pc=new Child();
pc.show();



}

}


method overridding:

final-----------final   not possible
final-----------non final not possible
non final-------final possible


final methods are object type but not reference type.



Best Tutorial  :
click here:

Javatpoint - A Solution of all Technology


Static method concept breaks overridding cocept

 class Parent {
  public static void show()
{
System.out.println("parent ");

}


}

class Child extends Parent {
public static void show()
{
System.out.println("child ");

}
public static void main(String[] args)
{
Child c=new Child();
c.show();
Parent pc=new Child();
pc.show();
}
}


static-----static   possible
static-----nonstatic not possible
nonstatic--------static  not possible



so it is not method overridding it is method hiding






Wednesday, 2 April 2014

OverriddingDemo

public class Parent {
public void show(int a)
{
System.out.println("parent class method no return type"+a);
}
public int disp()
{
System.out.println("parent class disp method type");
return 0;
}

}

class Child extends Parent {
public void show(int a)
{
System.out.println("child no return type"+a);
}
public static void main(String[] args)
{
Child c=new Child();
c.show(2);
Parent pc=new Child();
pc.show(3);
Parent p=new Parent();
p.disp();


}

}