:: 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 (1722)
 Advanced Java interview questions  Advanced Java Interview Questions (331)
 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 we can write the string concatenation program in java.   3
What modifiers are used with a top level class?   3
Is it possible to write JAVA program without including any of the packages,such as "import*"; bcoz I instantly wrote a code without "import..." statement and runned the program on command Line & it worked. the code is: class Person { String name; int age; Person(String s,int a) { name = s; age = a; } accept() { System.out.println(name+"Hi!!!!!"); System.out.println(age); } } class Demo { public static void main(Strings args[])throws IOException { String name = args[0]; int age = Integer.parseInt(args[1]); Person p = new Person(name,age); p.accept(); } }   3
explain the classification of exception and hoew to handle the exceptions   2
Can you explain the difference b/n abtract and interface with a good example,?In what cases we have use abtract and what case interface? Satyam 4
Suppose there is an array list [10,5,20,19,15,24].Print them in ascending & descending order in collection framework concept ??? Cognizent 2
How 'java' got its name and what it stands for? Wipro 10
Different types of modifiers? RoboCom 8
If I have 1000 objects and my requirement is to sort them quickly, then which collection would you recommend and why? KPIT 5
what is Thread?   6
When does Exception occurs?   3
what is the Arraylist limit (maximum) by default ? Fidelity 11
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.   ::