CS 4773 Object Oriented Systems
Hash Tables, Definite Assignment, and other Miscellaneous Topics


Announcement:

External reviewers for the College of Sciences and Engineering undergraduate self evaluation will be on campus Monday, March 30, 1998, through Wednesday, April 1, 1998.

Students are invited to meet with the reviewers on Monday, March 30, 1998, from 9:00 - 9:45 am in the Dean's Conference Room, 4.01.10 SB


This contains a few short unrelated topics.
Previous Topic: Vectors and Synchronization

Dictionaries
Hash Tables
Definite Assignment
Miscellaneous Topics
Java News

Next Topic: Java Beans



Dictionaries

A dictionary is used for looking up words. In Java, Dictionary is an abstract class used for maintaining a dictionary of key-element pairs. The keys and elements may be arbitrary objects.

Abstract methods are available to put items into the dictionary, retrieve them by key, and delete them.

Here is the documentation.


Hash Tables

The Java class Hashtable extends Dictionary and also provide some additional functionality such as the clone() method and methods to tell whether a key or object is in the table.

Here is the documentation.


Definite Assignment

From the Java Language Specification:

It then goes on to describe what is meant by "definitely assigned value" in the next 16 pages.


This is OK:
Example 1:
   int k;
   int n;
   k = 3;
   n = k;

This is not:
Example 2:
   int k;
   int n;
   n = k;
This produces a compile-time error.


Example 3:
   int k;
   int n=5;
   if (n > 2)
      k = 3;
   System.out.println(k);
The compiler cannot tell that n > 2 is always true.
However, the following is OK:
Example 4:
   int k;
   int n=5;
   if (n > 2)
      k = 3;
   else
      k = 5;
   System.out.println(k);
The compiler knows about if-else.
The compiler has some cleverness. The following is OK:
Example 5:
   int k;
   int n = 1;
   while(true) {
      k = n;
      if (k >= 5) break;
      n = 6;
   }
   System.out.println(k);

The following is also OK:
Example 6:
   void flow(boolean flag) {
      int k;
      if (flag)
         k = 3;
      else
         k = 4;
      System.out.println(k);
   }

But the following is not:
Example 7:
   void flow(boolean flag) { 
      int k; 
      if (flag) 
         k = 3; 
      if (!flag) 
         k = 4; 
      System.out.println(k); 
   } 

The following is also OK:
Example 8:
   int k;
   if (v > 0 && (k = System.in.read()) > 0)
      System.out.println(k);
because the compiler knows that for the boolean expression to be true, the second operand of && must be evaluated.


However, the following will produce a compile error:
Example 9:
   int k;
   if (v > 0 || (k = System.in.read()) > 0)
      System.out.println(k);

Miscellaneous Topics

What is a char?

What is the value of

"foo"+'s';
The answer depends on the version of JDK you are using.
JDK10 gives "foos" and JDK11 gives "foo115"

The above results were stated somewhere on the web but not tested by me. Here is my definitive answer to this.

The Java Language Specification says "foo" + 'c' is equivalent to "foo" + (new Character('c')).toString() and that the toString method of class Character produces a string of length 1 whose sole member is the character 'c'.

My testing revealed the following results using jdk1.0.2, jdk1.1.5, jdk1.2.beta2 and jdk1.2.beta3 under Sparc Solaris:

When compiled under jdk1.0.2, jdk1.1.5, or jdk1.2beta3, and run under any of the four JVMs, the result was "foos", which agrees with the specification.

When compiled under jdk1.2beta2 and run under any of the four JVMs, the result was "foo115" which is a bug.


Beeps

There is no standard way to produce a beep.
Under Java 1.0 you could do

System.out.print("\007");
System.out.flush();

In Java 1.1 you can use

java.awt.Toolkit.beep();

But the only portable way is to make a .au file and use

AudioClip.play()


java.util.Date


drawRect(int x, int y, int width, int height)

Draws a rectangle one pixel bigger than the specified width and height.
Think of it as drawing lines infinitely thin and then adding thickness one pixel down and to the right.



Java News

New releases of JDK

JDK 1.1.6 and JDK 1.2beta3 are now available for download from Sun at http://java.sun.com/products/jdk/.

Actually, as of 3 AM on March 26, the JDK 1.1.6 link on this page still pointed to JDK 1.1.5 and by 4 AM the above link no longer had any mention of JDK 1.1.6.


Java JumpStart 1.1

Sun has announced the early access availability of software code-names 'Java activator' which is included in their Java JumpStart product.

From the Sun press release at http://www.sun.com/smi/Press/sunflash/9803/sunflash.980324.12.html


Proposed changes to the Java Virtual Machine floating point specification.

The full press release is at http://www.sun.com/smi/Press/sunflash/9803/sunflash.980324.17.html.

Summary:

Currently the JVM specification states that results of floating point calculations must be rounded to IEEE 754 single precision (32-bit) or double precision (64-bit) values. Performance would improve on some platforms (specifically Power PC and Intel) if the specification allowed intermediate calculations to be done using IEEE 754 extended formats.

From the Java Language Specification and the Java Virtual Machine Specification:


Java makes coffee

The full press release is at http://www.sun.com/smi/Press/sunflash/9803/sunflash.980324.8.html.

Summary:

Users can order custom ground coffee from the net. The machine grinds the appropriate selection of beans and brews the coffee which the user can pick up in a few minutes.

They are working on a method to directly deliver the coffee to the cup holder found on most modern PCs.



Next topic: Java Beans