Preview

Narrative report in ojt

Satisfactory Essays
Open Document
Open Document
365 Words
Grammar
Grammar
Plagiarism
Plagiarism
Writing
Writing
Score
Score
Narrative report in ojt
HashMaps
And an Introduction to GUIs
Using Java's Swing Toolkit

Lecture Time!
• HashMap
• J/Frame
• Component classes
– J/Button
– J/TextField

The Java Collections Framework
• This is a set of classes you can use for containing arbitrarily large collections of objects.
• To use: import java.util.*;
• Some basic Collection classes:
– ArrayList
– Vector
– HashMap
– Hashtable (yes, that's a small t)

HashMap
• ArrayList is usually mentioned as ArrayList
– E is the object type that it will contain.
– ArrayList means that we want an

ArrayList that can contain BankAccounts.

• HashMap, however, is defined as HashMap
– K is the object type that will be used as a key.
• HashMaps do not use an index and must rely on a provided “key” data to fetch an object.

– V is the object type that the HashMap will contain.
• Similar to E in ArrayList.

Example import java.util.*; public class HashMapDemo
{
public static void main( String args[] )
{
HashMap accts = new HashMap(); accts.put( "Bob", new BankAccount( 2000 ) ); accts.put( "Alice", new BankAccount( 1000 ) ); accts.get( "Bob" ).deposit( 500 );
// how do you print Alice's and Bob's balances?
}
}

Other HashMap Methods
• void clear()

– Empties the HashMap of keys and values.
• boolean containsKey( Object key )

– True if the HashMap has a value mapped to this key.
• boolean containsValue( Object value )

– True if the HashMap has the specified value inside.
• Set keySet() // self-study

– Gives a Set of all of its keys for iteration purposes.
• Collection values() // self-study

– Gives a Collection of all its value contents for iteration purposes. Java Swing Toolkit
• import java.awt.*;
• import javax.swing.*;

• While JOptionPane is useful, programmers often want more control over their programs.
– I don't want to use System.out.println() for program output anymore!
– I want to be able to accept 3 different text inputs at the same time

You May Also Find These Documents Helpful

  • Good Essays

    Nt1420 Unit 6

    • 1145 Words
    • 5 Pages

    Question 6 A hash table is a data structure that uses an array as its internal storage container. Items are added to the array based on the integer generated by a hash function. A hash function produces an integer based on some properties of the object. In Java hash functions are encapsulated via the hashcode method in the Object class and that many classes override.…

    • 1145 Words
    • 5 Pages
    Good Essays
  • Good Essays

    Nt1330 Unit 1 Assignment 1

    • 4614 Words
    • 19 Pages

    A ______ is rectangular area that can contain a document, program, or message option1 A __________ contains icon buttons that access frequently used commands A __________ provides access to features of the program A built-in tool that performs calculations automatically is a(an) A collection of related data that has been entered into a computer is called a A collection of separate software applications that are sold as a group, like Microsoft Office, is called a(n) A database sort directs the software to find and display one or more records option2 option1 option3 option3 option4 option2…

    • 4614 Words
    • 19 Pages
    Good Essays
  • Powerful Essays

    Pt1420 Unit 1 Assignment 2

    • 1305 Words
    • 6 Pages

    Hosch, L., Liesandthem, G., Luebring, J.E., Pallardy, R., Young, G. (2014). Java. In Encyclopedia Britannica.…

    • 1305 Words
    • 6 Pages
    Powerful Essays
  • Satisfactory Essays

    Another example for use of this use of multiple parameters would be in a point of sale type environment where you need to enter multiple values for an item that a customer is purchasing from an online store. You may need to collect entries for the item description, sku, price and weight. This could be done with a method like:…

    • 326 Words
    • 2 Pages
    Satisfactory Essays
  • Powerful Essays

    Searching and Sorting Streams and Files Graphics GUI Components and Events Mouse, Keyboard, Sounds, and Images Big-O Analysis of Algorithms The Java Collections Framework Lists and Iterators Stacks and Queues Recursion Revisited Binary Trees Lookup Tables and Hashing Heaps and Priority Queues Design Patterns…

    • 3908 Words
    • 16 Pages
    Powerful Essays
  • Satisfactory Essays

    Unit 1 Assignment 1

    • 465 Words
    • 2 Pages

    Keyboard map= Information that matches the key (or key combination) that exists on a keyboard to some matching binary code so that the keyboard can tell the computer specifically what key(s) were just pressed.…

    • 465 Words
    • 2 Pages
    Satisfactory Essays
  • Good Essays

    6. Data hiding, which means that critical data stored inside the object is protected from code outside the object is accomplished in Java by _____.…

    • 1518 Words
    • 7 Pages
    Good Essays
  • Good Essays

    Chapter 8 Quiz

    • 469 Words
    • 2 Pages

    4. Which is the simplest search technique to use to find an item in an array? (Points : 7)…

    • 469 Words
    • 2 Pages
    Good Essays
  • Good Essays

    T F 3. Java's read messages can be passed text strings as a parameter, and the string will be used by…

    • 719 Words
    • 3 Pages
    Good Essays
  • Powerful Essays

    It 210

    • 2960 Words
    • 12 Pages

    If you write individual items on separate random pieces of paper, you might get them confused, and end up going to the grocery store for a saw. By presenting a convenient method of organizing and separating your data, a list prevents this from happening. Sometimes a single list…

    • 2960 Words
    • 12 Pages
    Powerful Essays
  • Good Essays

    Express the set using the roster method. To do that, first translate into English what this mathematical expression states. Then list the elements of this set in roster form. Explain how you arrived at your answer.…

    • 2403 Words
    • 10 Pages
    Good Essays
  • Good Essays

    To develop a date class in java similar to the one in java.util.package using java doc commands.…

    • 1459 Words
    • 6 Pages
    Good Essays
  • Powerful Essays

          Karsten builds elegant Swing apps works with Objects since 1990 helps others with UI and architectures provides libraries that complement Swing provides examples for Swing architectures writes about Java desktop issues…

    • 2893 Words
    • 12 Pages
    Powerful Essays
  • Good Essays

    Java Programming

    • 1974 Words
    • 8 Pages

    Let us begin with a simple Java program that displays the message "Welcome to Java!" on the console. The program is shown in Listing 1.1.…

    • 1974 Words
    • 8 Pages
    Good Essays
  • Powerful Essays

    Intro to Java Netbeans

    • 2703 Words
    • 11 Pages

    A computer is a machine. Humans need to provide instructions to computers to operate. Providing instructions to a computer is called “Programming”.…

    • 2703 Words
    • 11 Pages
    Powerful Essays