:: 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                      
Categories >> Software >> Java Related >> Java J2EE >> Core Java


 Core Java interview questions  Core Java Interview Questions (1728)
 Advanced Java interview questions  Advanced Java Interview Questions (332)
 Swing interview questions  Swing Interview Questions (44)
 EJB interview questions  EJB Interview Questions (134)
 Servlets interview questions  Servlets Interview Questions (255)
 Struts interview questions  Struts Interview Questions (196)
 JDBC interview questions  JDBC Interview Questions (187)
 JMS interview questions  JMS Interview Questions (9)
 SunOne interview questions  SunOne Interview Questions (3)
 J2EE interview questions  J2EE Interview Questions (71)
 Weblogic interview questions  Weblogic Interview Questions (147)
 Websphere interview questions  Websphere Interview Questions (14)
 Java Networking interview questions  Java Networking Interview Questions (20)
 Java J2EE AllOther interview questions  Java J2EE AllOther Interview Questions (87)
why HashTable not allow null key and value
 Question Submitted By :: Core-Java
I also faced this Question!!     Answer Posted By  
# 1
To successfully store and retrieve objects from a hashtable,
the objects used
as keys must implement the hashCode method and the equals

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 ?    4 Yes 0 No
# 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 ?    4 Yes 0 No

Other Core Java Interview Questions
  Question Asked @ Answers
How can two threads be made to communicate with each other? HCL 3
Explain final, finalize() and finally? Accenture 11
what is the use of private constructor in core java? Satyam 3
How will you convert an ArrayList to Arrays? KPIT 4
How to Sort list of Strings in ascending order without using java api. Hcl 1
How Applets & Servlets will communicate with each other?   2
Difference between Applet & Application?   6
how can u handle run time exception in java? explain with brief explanation with examples? CTS 2
When does Exception occurs?   3
please send code example of inner classes?   2
what is Hashmap & Hashtable wirh example? Saksoft 5
For more Core Java Interview Questions Click Here 

Copyright Policy  |  Terms of Service  |  Articles  |  Site Map  |  RSS Site Map  |  Contact Us
Copyright 2013  All Rights Reserved.   ::