What is HashMap & Map ?
Map is an Interface and HashMap is class Implements MapMap<K,V>
is an interface, HashMap<K,V>
is a class that implements Map
.
you can do
Map<Key,Value> map = new HashMap<Key,Value>();
What are pass by reference and pass by value ?
Pass by reference means the passing the address itself rather than value, Pass by value means passing the copy of value to be passedDifference between HashMap and HashTable ?
- HashMap class roughly equivalent to HashTable except that it is unsynchronised and permits null.
- (HashMap allows null to store as key,Value wheres as HashTable doesn't allows)
- HashMap doesn't guarantees that order of the map remains constant over time
- HashMap is unsynchronised where as HashTable is synchronised
Hashtable<String,String> hashtableobj = new Hashtable<String, String>(); hashtableobj.put("Maga", "available"); hashtableobj.put("Machi", "available"); System.out.println("obj output :"+ hastable_obje);
HashMaphashmapobj = new HashMap (); hashmapobj.put("test ", "awesome"); hashmapobj.put("internal", "sake of marks"); System.out.println("HashMap object output :"+hashmap_obj);
Difference between Vector and Arraylist ?
Vector is synchronised and arraylist is not
Difference between Overloading and Overriding ?
1)
Method overloading is used to increase the readability of the program.
Method overriding is used to provide the specific implementation of the method that is already provided by its super class.
2)
Method overloading is performed within class.
Method overriding occurs in two classes that have IS-A (inheritance) relationship.
3)
In case of method overloading, parameter must be different.
In case of method overriding, parameter must be same.
4)
Method overloading is the example of compile time polymorphism.
Method overriding is the example of run time polymorphism.
5)
In java, method overloading can't be performed by changing return type of the method only. Return type can be same or different in method overloading. But you must have to change the parameter.
Return type must be same or covariant in method overriding.
Java Method Overloading example
- class OverloadingExample{
- static int add(int a,int b){return a+b;}
- static int add(int a,int b,int c){return a+b+c;}
- }
Java Method Overriding example
- class Animal{
- void eat(){System.out.println("eating...");}
- }
- class Dog extends Animal{
- void eat(){System.out.println("eating bread...");}
- }
1)
Method overloading is used to increase the readability of the program.
Method overriding is used to provide the specific implementation of the method that is already provided by its super class.
Method overloading is used to increase the readability of the program.
Method overriding is used to provide the specific implementation of the method that is already provided by its super class.
2)
Method overloading is performed within class.
Method overriding occurs in two classes that have IS-A (inheritance) relationship.
Method overloading is performed within class.
Method overriding occurs in two classes that have IS-A (inheritance) relationship.
3)
In case of method overloading, parameter must be different.
In case of method overriding, parameter must be same.
In case of method overloading, parameter must be different.
In case of method overriding, parameter must be same.
4)
Method overloading is the example of compile time polymorphism.
Method overriding is the example of run time polymorphism.
Method overloading is the example of compile time polymorphism.
Method overriding is the example of run time polymorphism.
5)
In java, method overloading can't be performed by changing return type of the method only. Return type can be same or different in method overloading. But you must have to change the parameter.
Return type must be same or covariant in method overriding.
In java, method overloading can't be performed by changing return type of the method only. Return type can be same or different in method overloading. But you must have to change the parameter.
Return type must be same or covariant in method overriding.
Java Method Overloading example
- class OverloadingExample{
- static int add(int a,int b){return a+b;}
- static int add(int a,int b,int c){return a+b+c;}
- }
Java Method Overriding example
- class Animal{
- void eat(){System.out.println("eating...");}
- }
- class Dog extends Animal{
- void eat(){System.out.println("eating bread...");}
- }
0 comments:
Post a Comment