1162 Java Utilities Package and Bit Manipulation Chapter (Web hosting servers)

1162 Java Utilities Package and Bit Manipulation Chapter 20 Performance Tip 20.6 The load factor in a hash table is a classic example of a space time trade-off: By increasing the load factor, we get better memory utilization, but the program runs slower, due to increased hashing collisions. By decreasing the load factor, we get better program speed, because of reduced hashing collisions, but we get poorer memory utilization, because a larger portion of the hash table remains empty. The complexity of programming hash tables properly is too much for most casual programmers. Computer science students study hashing schemes thoroughly in courses called Data Structures or Algorithms. Recognizing the value of hashing to most programmers, Java provides class Hashtable and some related features to enable programmers to use hashing without having to implement the messy details. Actually, the preceding sentence is profoundly important in our study of object-oriented programming. As discussed in earlier chapters, classes encapsulate and hide complexity (i.e., implementation details) and offer user-friendly interfaces. Crafting classes to do this properly is one of the most valued skills in the field of object-oriented programming. Figure 20.3 provides a GUI that enables you to test several Hashtable methods. Line 25 creates an empty Hashtable with a default capacity of 101 elements and a default load factor of .75. When the number of occupied slots in the Hashtablebecomes more than the capacity times the load factor, the table grows larger. Class Hashtablealso provides a constructor that takes one argument specifying the capacity and a constructor that takes two arguments, specifying the capacity and load factor, respectively. 1 // Fig. 20.3: HashtableTest.java 2 // Demonstrates class Hashtable of the java.util package. 3 4 // Java core packages 5 import java.awt.*; 6 import java.awt.event.*; 7 import java.util.*; 8 9 // Java extensions packages 10 import javax.swing.*; 11 12 public class HashtableTest extends JFrame { 13 private JLabel statusLabel; 14 private Hashtable table; 15 private JTextArea displayArea; 16 private JTextField lastNameField; 17 private JTextField firstNameField; 18 19 // set up GUI to demonstrate Hashtable features 20 public HashtableTest() 21 { 22 super( “Hashtable Example” ); 23 24 statusLabel = new JLabel(); 25 table = new Hashtable(); 26 displayArea = new JTextArea( 4, 20 ); Fig. 20.3 Demonstrating class Hashtable(part 1 of 6).
Note: If you are looking for best quality webspace to host and run your tomcat application check Vision shared web hosting services

Leave a Reply