ALLInterview.com :: Home Page KalAajKal.com
 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   To Refer this Site to Your Friends   Click Here
Google
 
Categories  >>  Software  >>  Core Java  >>  Java J2EE  >>  Java Related
 
 


 

 
 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
write a progam hashmap & hashtable?
 Question Submitted By :: Gopalraop
I also faced this Question!!     Rank Answer Posted By  
 
  Re: write a progam hashmap & hashtable?
Answer
# 1
import java.io.*;
class Hashtable
{
public static void main (String args[])
{
Hashtable h=new hahtable();
h.add("dil");
h.add("ppp");
h.add("kkk");
System.out.println("the value of h is "+h);
System.out.println("the value of size is"+h.size());
}
}
import java.io.*;
class Hashmap
{
public static void main(String args[])
{
h.put("1","kkk");
h.put("2","ppp");
System.out.println("the value of h is"+h);
}
}
suppose if we use the haahtable  then the we have to use 
Enumeration concept and suppose if we use the HashMap then 
we have to use Iterator concept.
 
Is This Answer Correct ?    3 Yes 1 No
Dileep
 
  Re: write a progam hashmap & hashtable?
Answer
# 2
** HASH MAP **
import java.util.*;
class myhashmap
{
public static void main(strings args[])
{
HashMap map=new HashMap();
map.put("fname","abc");
map.put("email","abc@yahoo.com");
map.put("age",21);
map.put("","");
System.out.println(map.get("fname"));
System.out.println(map.get("age"));
}
}

** Hash Table **

import java.util.*;
class testhashtable
{
public static void main(string args[])
{
Hashtable<String,Integer> num=new Hashtable<String.Integer>
();
num.put("one",new Integer(1));
num.put("two",new.Integer(2));
Integer n=(Integer) num.get("two");
if(n!=null)
{
System.out.println("two="+n);
}
}
}


Difference b/w two is...Hash Map allows NULL values whereas 
Hash table not.
 
Is This Answer Correct ?    0 Yes 0 No
Ajay Yadav
 
 
 

 
 
 
Other Core Java Interview Questions
 
  Question Asked @ Answers
 
Is ResultSet class? Bally-Technologies2
What is a class ?  8
In what types of operations an ArithmeticException will be thrown?  2
What is the preferred size of a component?  1
In Inheritence concept, i have a static method in super class and i am inheriting that class to one sub class.in that case the static method is inherited to sub class or not???? Accenture8
can anyone explain me the concept of autoboxing?  3
how can we synchronize Hash map? CTS3
Why are the methods of the Math class are static?  1
Explain the term serialization? Wipro6
How the elements are organized in CardLayout?  5
Does java support multi dimensional arrays ?  4
what is the difference between ArrayList and Vector Wipro12
how can i cal servlet from jsp page?how can i pass variablesfrom the jsp that servlet can access? Verizon1
What modifiers are used for interface declaration?  3
In what type of containers, Border layout is a default layout?  3
What is the difference between a Window and a Frame?  1
What is anonymous class?  2
can we create a instance for intwerface?  3
What is JIT ? Satyam4
what is polymorphism with example?types of polymorphism? HP6
 
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 © 2007  ALLInterview.com.  All Rights Reserved.

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