ALLInterview.com :: Home Page            
 Advertise your Business Here     
Browse  |   Placement Papers  |   Company  |   Code Snippets  |   Certifications  |   Visa Questions
Post Question  |   Post Answer  |   My Panel  |   Search  |   Articles  |   Topics  |   ERRORS new
   Refer this Site  Refer This Site to Your Friends  Site Map  Bookmark this Site  Set it as your HomePage  Contact Us     Login  |  Sign Up                      
tip       Ask Questions on ANYTHING, that arise in your Daily Life at     FORUM9.COM
Google
   
 
Categories  >>  Software  >>  Java Related  >>  Java J2EE  >>  Core Java
 
 


 

 
 Core Java interview questions  Core Java Interview Questions
 Advanced Java interview questions  Advanced Java Interview Questions
 Swing interview questions  Swing Interview Questions
 EJB interview questions  EJB Interview Questions
 Servlets interview questions  Servlets Interview Questions
 Struts interview questions  Struts Interview Questions
 JDBC interview questions  JDBC Interview Questions
 JMS interview questions  JMS Interview Questions
 SunOne interview questions  SunOne Interview Questions
 J2EE interview questions  J2EE Interview Questions
 Weblogic interview questions  Weblogic Interview Questions
 Websphere interview questions  Websphere Interview Questions
 Java Networking interview questions  Java Networking Interview Questions
 Java J2EE AllOther interview questions  Java J2EE AllOther Interview Questions
Question
why HashTable not allow null key and value
 Question Submitted By :: Kundan Ranjan
I also faced this Question!!     Rank Answer Posted By  
 
  Re: why HashTable not allow null key and value
Answer
# 1
To successfully store and retrieve objects from a hashtable,
the objects used
as keys must implement the hashCode method and the equals
method.

In a nutshell, since null isn't an object, you can't call
.equals() or .hashCode() on it, so the Hashtable can't
compute a hash to use it as a key.

HashMap is newer, and has more advanced capabilities, which
are basically just an improvement on the Hashtable
functionality. As such, when HashMap was created, it was
specifically designed to handle null values as keys and
handles them as a special case.

Specifically, the use of null as a key is handled like this
when issuing a .get(key):

(key==null ? k==null : key.equals(k))
 
Is This Answer Correct ?    0 Yes 0 No
Eknath
 
  Re: why HashTable not allow null key and value
Answer
# 2
There is null check in the put method implementation of
hashtable, so it does not support null values and null keys.


public Object put(Object key, Object value) {
// Make sure the value is not null
if (value == null) throw new NullPointerException();
}

above is HashTable put method logic implemented by Sun.
 
Is This Answer Correct ?    2 Yes 0 No
Naveen
 
 
 

 
 
 
Other Core Java Interview Questions
 
  Question Asked @ Answers
 
What is run time polymorphism? Elementus-Technologies6
Can we declare static variables in JSP page. TCS3
Hi Friends, Can u give few interview questions which relates ArrayList and Hashmap. I mean how to link ArrayList and HashMap.I know this is not good way of asking questions like this , but i need Microsoft1
when we create singleton design then we create private constructtor..so how JVM take private constructor to make object..but it's private.. Ness-Technologies1
Catch(Exception e){ } in that what is Exception and purpose of that in that place exactly?  3
How 'java' got its name and what it stands for? Wipro10
when asub class inherits a super class and overrides a public method of super class in sub class(public method in super class). why these methods needs to be public in sub class. (otherwise compile time error).  3
If there is no implementation of MARKER INTERFACE in java. Then how compiler come to know about specification.  2
In real time project which driver did u use? What is the main functionality of the Prepared Statement? Photon3
how can we synchronize Hash map? CTS3
printstream class method println() is calling using System class and its static object out .how it is explain any one in detail with example ? TCS1
how copy the hashmap object into arraylist at java program? HCL4
 
For more Core Java Interview Questions Click Here 
 
 
 
 
 


   
Copyright Policy  |  Terms of Service  |  Help  |  Site Map 1  |  Articles  |  Site Map  |   Site Map  |  Contact Us interview questions urls   External Links 
   
Copyright © 2012  ALLInterview.com.  All Rights Reserved.

ALLInterview.com   ::  Forum9.com   ::  KalAajKal.com