- HackSaw
- InnovVal System Solutions' library of code for writing TCP/IP applications
including: FTP file uploading and downloading, SMTP and POP3 email, HTTP
file and header retrieval, USENET postings, file attachments using MIME
and UU encoding/decoding and proxy support. $230 US.
- handle
- To do whatever action is necessary to deal with an event. An event handler
decides what kind of event has come in, and calls the corresponding more
specific action routine to handle the event. MacIntosh programmers use
the term handle to mean a pointer to a pointer. This allows the thing pointed
to be moved, and all references are thereby automatically forwarded to
the new location. Java pointers (called references) are usually implemented
as handles. See reference, event.
- handle body
- See peer.
- hashCode
- If you want to file something away for later retrieval, it
can be faster if you file it numerically rather than by a long
alphabetic key. A hashCode is a way of computing a small digest
numeric key from a long String or even an arbitrary clump of
bytes. The numeric key itself is meaningless and the hashCode
functions for computing them can look a bit insane. However, when
you go to look for something, you can do the same digest
calculation on the long alphabetic key you are looking for, and
no matter how bizarre an algorithm you used, you will calculate
the same hashCode, and will be able to look up numerically with
it. Of course there is always the likelihood two different
Strings will have the same digest hashCode. However, even then,
it greatly narrows down the search, hence speeding it up. A
Hashtable goes a step further, scrunching down the hashCode even
further to an even smaller number that it can use to directly
index an array, usually by dividing it by some prime number and
taking the remainder.
In JDK 1.0.x and 1.1.x the hashCode function for long Strings
worked by sampling every nth character. This pretty well
guaranteed you would have many Strings hashing to the same value,
thus slowing down Hashtable lookup. In JDK 1.2 the function has
been improved to multiply the result so far by 31 then add the
next character in sequence. This is a little slower, but is much
better at avoiding collisions. See Hashtable.
- HashJava
- a source code shrouder. See shroud.
- Hashtable
- For Strings, Hashtables work pretty much as you would expect if you are
familiar with hashing. The only catch is remembering to import java.util.Hashtable
(with a small t in table). Here is how you use a Hashtable:
import java.util.Hashtable;
import java.util.Enumeration;
...
// create a new Hashtable
Hashtable h = new Hashtable(149 /* capacity */ , 0.75f /* loadfactor */ );
// add some key/value pairs to the Hashtable
h.put( "WA" , "Washington" );
h.put( "NY" , "New York" );
h.put( "RI" , "Rhode Island" );
h.put( "BC" , "British Columbia" );
// look up a key in the Hashtable
String key = "NY" ;
String stateName = (String) h.get(key);
System.out.println(stateName);
// prints "New York"
// enumerate all the contents of the hashtable
Enumeration keys = h.keys();
while( keys.hasMoreElements() )
{
key = (String)keys.nextElement();
stateName = (String)h.get(key);
System.out.println(key + "" + stateName);
// prints lines of the form NY New York
// in effectively random order.
}
// end while
Some fine points:
- Hashtables work fastest if the capacity is a prime number.
Round your capacity up to prime number. However, avoid 31 or
multiples of 31 since the new hashCode algorithm for Strings in
JDK 1.2 uses 31 as a magic number in the hashing formula. You are
only using 4 bytes per additional entry. Here are some primes
just larger than various powers of two that would be good
choices.
11 |
17 |
37 |
67 |
131 |
257 |
521 |
1031 |
2053 |
4099 |
8209 |
16411 |
32771 |
65537 |
131101 |
262147 |
524309 |
1048583 |
2097169 |
4194319 |
8388617 |
- You cannot have elements with duplicate keys. If you add a new
element that duplicates the key of an existing element, it will replace
it.
- If you specified a capacity of 101 and a load factor of .75f, then
the initial table could hold 75 elements.
- Hashtables will automatically grow when you add too many elements.
However, growing requires copying, rehashing and rechaining, quite an
involved process. That is why you want an accurate estimate for the
initial capacity.
- A load factor of .75f means that the table will be expanded when it
gets three quarters full. Hashing works faster when the table is not full.
A value of .25f would use more RAM but would work faster. A value of 1.0f
would use minimal RAM but would run slowly.
- HashCodes are usually not unique. If you think about it, how could
they be? Consider Strings of length 10 characters (20 bytes, 160 bits).
How many different possible strings are there? 2^160. HashCodes are 32
bits long. How many possible different hashCodes are there? 2^32. You can
see there are way more strings that HashCodes, so strings would have to
share HashCodes.
- If two key hash to the same hashCode, or to the same hashCode modulus
the size of the table, all still works. It just takes a little longer to
look up that key, since get() has to
chase a chain of clashing keys to find the match. Keys are matched with
the equals() method, not ==, or simply by comparing hashCodes.
- The source code for Hashtable is very short. It takes an order of
magnitude more English to describe how it works than does the Java code
itself. I suggest you peruse it if you are in the least curious how it
works inside. Hashing is something every programmer should
understand. You might also study String.hashCode().
- Hashtables use generic objects or both keys and values. You need to
cast these back to Strings, or whatever you are using.
- If you want to use something other than Strings as your keys, make
sure you implement an equals() and
hashCode() method for those key
objects to override the default Object equals() and hashCode() methods. The default equals() method just checks that the two
objects are one in the same (using ==), not that they consist of the same
bit patterns.
- There are two methods for enumerating the Hashtable,
keys() which gives you the
keys, and elements() which
gives you the values. You could step through both enumerations
simultaneously instead of using get() as I showed. JDK 1.2 Hashmap
(the replacement for Hashtable) lets you iterate over keys,
values or key-value pairs.
- The size method keeps
track of how many unique keys are in the Hashtable, not the size
of the table. Hastables never contain items with duplicate
keys.
See primes, hashCode.
- Hayes
- Hayes was one of the first companies to make modems for the
XT/AT. They are now bankrupt. Since there are no official
standards on how to make your modem dial a number, hang up, etc.
most modem manufacturers copy one of the Hayes models. The phrase
"Hayes compatible" is a give-away that the modem is NOT
compatible with any particular Hayes model. It means they
concocted a hodgepodge of commands from various Hayes models with
a dollop of extra features of their own. Hayes modems were high
quality, and by definition do not have compatibility problems.
The only thing the matter with them was their outrageous price.
Hayes patented the +++ method of getting a modem into command
state. Let's hope that patent died along with the company.
See AT command set.
- HeapSort
- Williams and Floyd's sorting algorithm that models employees jockeying
for position on the corporate ladder. Another analogy is a tennis tournament
where winners of low level contests (comparing bigness of key) compete
at the next higher level. In Java, HeapSort is faster than QuickSort but
slower than RadixSort. HeapSort is unstable in that it sometimes disturbs
the order of existing records with equal keys. You can turn it into a stable
sort by appending the existing order as a minor key. Free source code is
available from Roedy Green at Canadian Mind Products. To learn more about
HeapSort's behaviour see Eppstein's
paper. HeapSort is particularly fast if the data are already almost
sorted. The source code is available both in prettified
HTML or download. See Sort, RadixSort,
QuickSort.
- Heatherington
- Hayes patented method of putting a pause before and after the +++ string
used to gain a modem's attention. The required pause helps avoid inadvertently
attracting the modem's attention when you send files (such as this one)
containing the string +++.
- HelloWorld
- HelloWorld is usually the first Java program a novice writes.
public class HelloWorld
{
public static main(String[] args)
{
System.out.println( "Hello World" );
}
// end main
}
// end class HelloWorld
To compile it, type:
javac HelloWorld.java
and later run it with:
java HelloWorld
If this does not work, here are some likely problem areas:
- The name of the source file must be HelloWorld.java, precisely,
and the name of the public class in your source must be HelloWorld, precisely,
including case.
- You specify the .java extension to compile, but leave the .class extension
off to execute. How logical!
- You may not specify the fully qualified drive and path: e.g.
java C:\TEMP\HelloWorld
is not permitted.
- As a corollary, make sure the current directory is where the HelloWorld.class
file is.
- You have to get the case exactly correct. e.g.
java Helloworld
is not permitted.
- make sure your CLASSPATH looks something like this:
CLASSPATH=.;D:\Jdk1.1.5\lib\classes.zip
Note the . to include the current directory. See CLASSPATH for
more details.
- If your HelloWorld is an Applet rather than an application, you need some
HTML commands to invoke it. You don't just load it in your browser as if it
were a web page. See Applet for more details on composing that HTML.
If you have a more complex program, using a package, the name of the class
you put on the java command line would be myPackage.myClass. myClass.class
needs to live in a directory called C:\myPackage. The current directory
needs to be C:\ for Java to be able to find the class. The full truth is
a little more complex, e.g. you can have zip and JAR files too.
See java.exe for a detailed discussion of how Java.exe combines package
names, class names and the CLASSPATH to find the classes.
- help
- text the user can request to help her understand a program. Context sensitive
help tries to guess just what questions the user would be asking herself
at that particular stage of the program. Java documentation and help tends
to be based on HTML files.
- Hermit Crab
- A variable length record manager for Java, something not so ambitious
as SQL, but more efficient.
- hexadecimal
- or hex for short, base 16 numbers, e.g. 08Cf, made of the
digits 0..9 and a..f. This is the number system we would have
used had we sixteen fingers instead of ten. You can display in
hex using code like this:
String hex = Integer.toString(i, 16 /* radix */ );
You can convert a hex String to internal binary like this:
int i = Integer.parseInt(g.trim(), 16 /*
radix */ );
Since the computer uses binary internally, it makes no sense to
talk about converting an int from hex to decimal or back, only a
String.
In Java you can use hex literals like this
See Literals for more details. The computer chip works internally
in binary (base 2 numbers), with numbers made only of the digits
0 and 1, low voltage/high voltage. Binary numbers are somewhat
bulky to write out, so they are usually written in base 16, hex.
It is very easy to convert hex to binary and visa versa using the
following table. For example, the hex number 8cf is 100011001111
in binary. Converting between decimal and hex is more difficult.
You must do successive divisions and moduluses by 10 or 16.
Decimal | Hex | Binary |
0 | 0 | 0000 |
1 | 1 | 0001 |
2 | 2 | 0010 |
3 | 3 | 0001 |
4 | 4 | 0100 |
5 | 5 | 0101 |
6 | 6 | 0110 |
7 | 7 | 0111 |
8 | 8 | 1000 |
9 | 9 | 1001 |
10 | a | 1010 |
11 | b | 1011 |
12 | c | 1100 |
13 | d | 1101 |
14 | e | 1110 |
15 | f | 1111 |
See the
Learn To Count Applet to sharpen your intuition on how
binary, hex and octal work. See binary, octal, literal.
- hide
- make temporarily invisible. "hide" is deprecated. With JDK 1.1 you are
supposed to use setVisible(false); instead. hide is also used to
describe what one window does to another when it is painted over top of
it. See setVisible, show.
- hit counters
- One of the most commonly requested Applets is one that will
display the number of visitors to a page like this:
Unfortunately, it is not possible to write such a program in Java
without the co-operation of a server somewhere to centrally
record the current value of the counter.
Happily there are people who will provide you with free hit
counters and free use of their server, usually in exchange for
some advertising on the counter. One of the least objectionable
is:
makers of the excellent software I use dozens of times a day to
comb these web pages for HTML errors.
You can get a commercial, advertising-free hit counter, including
use of the counting server, for about $35 to $600 a year,
depending on number of hits. Try the WebCounter people.
Commercial hit counters generally give faster response than free
ones. Before you sign up see if you can find some of that
vendor's hit counters on other people's sites and see how
responsive they are. A sluggish hit counter can be very annoying
to your visitors.
Some hit counters let you substitute your own set of ten gifs for
the digits 0 to 9 to create the counter. With search engines, you
can find hundreds of sets of free gifs to use.
Clever hit counter software is not fooled by the same person
visiting the same page several times in succession.
There is not much point combing the web for hit counter software
to run on your server. Most ISPs won't let you run it. They may
have some software they have tested they will let you run,
usually for a fee. The hit counters on my pages are handled by
Novell's SSI and are sent as ASCII text. Every ISP will have his
own preferred way of doing them, usually with CGI.
In theory, you could create a Java Applet to display a hit
counter. The central site could send the value of the count over
in compact binary. However, this would be slower than using CGI
since tche browser would need to download the Java Applet
containing contain code and a complete set of GIFs for all the
digits. Further the browser user would need to load the Java
interpreter. This would take considerably more time than just
sending the count or the gifs needed to display the current
count. The other problem is the count would not work for people
who did not have Java installed or if their Java did not work, or
if the Java Plug-In 1.2 had sabotaged the 1.1 version. If there
were some way of caching Applets, this technique could be very
fast. Perhaps we will see them in future, using smoooth
animations or other gimickry. See CGI, SSI.
- hide
- HomeSite
- an HTML authoring tool for Windows-95 and NT bought out by Allaire.
See Cold Fusion.
- Hook
- In the old days, the telephone mouthpiece rested on hook-shaped cradle
when it was not in use. To use the phone, you lifted the mouthpiece "off-hook"
which gave you a dial tone. To stop using the phone, you placed it back
"on-hook". We still use these terms for the electrical modem equivalents.
-
HoseMocha
- uses a simple trick to confuse the Mocha reverse engineering tool by inserting
an unreachable bogus opcode. See shroud.
- Hot
Java
- a web browser from Sun, written in Java, that competes with Netscape. Its
main advantage is that it is the first out to support new features of Java.
- HotSpot
- Sun's JIT coming real soon now. Code runs first in interpreted mode and
is then analyzed and compiled optimized to target platform. It aggressively
inlines frequently used methods, then uses traditional optimisation techniques
on the larger code chunks.
The HotSpot compiler builds heavily on work done in a
PhD thesis by Henry Massalin.
The thesis is the mother of all self-modifying code. You not only
optimise, you continuously re-optimise. See JIT, optimiser.
- HSB
- Hue Saturation Brightness. Java's
alternative to RGB (Red Green Blue) for
specifying colour. Java defines HSB as three floating point
numbers between 0. and 1. Note that Java's definition does not
match Paint Shop Pro's definition, even if you scale HSB to
0..255. Roughly hue represents the position on the rainbow or
colour wheel, only loosely related to the frequency or wavelength
of the simulated colour.
Saturation is how white the colour is, how broad the spectrum.
Brightness is how much light shines out of that colour, the
amplitude of the light waves. See the Netscape Colour chart of the
Netscape/X11 133 standard colours in HSB form. You can view it
sorted by hue, saturation, brightness, alphabetically or hue,
brightness, saturation.
You can generate an RGB-HSB equivalence
table with the little application below.
// ColorspaceTest.class
// Demonstrates correspondence between RGB
and HSB
import java.awt.Color.*;
public class ColorspaceTest
{
/**
* The smaller the number the more table entries
it will generate.
*/
static
final int INTERVAL = 30;
/**
* displays a table of RBG vs HSB values
*/
public
static void main(String[] args)
{
float
hsb[]= new float[3];
int
hue, sat,
bri;
//
Display column headings
System.out.println( " red grn blu hue sat bri" );
//
show a set of sample RGB colours
for
(int red=0; red<256; red+=INTERVAL )
{
for
(int grn=0; grn<256; grn+=INTERVAL )
{
for
(int blu=0; blu<256; blu+=INTERVAL )
{
//
convert from RGB to HSB
Color.RGBtoHSB(red, grn,
blu, hsb);
//
scale 0 .. 255
hue =
(int)(hsb[0]* 255);
sat =
(int)(hsb[1]* 255);
bri =
(int)(hsb[2]* 255);
System.out.println
(
rightJust(red, 4) +
rightJust(grn, 4) +
rightJust(blu, 4) +
" " +
rightJust(hue, 5) +
rightJust(sat, 5) +
rightJust(bri, 5) );
}
}
}
}
// end
ColorspaceTest
/**
* convert
int to String fixed width, right justified.
* @param
i the integer to convert.
* @param
width the width of the result field in chars.
* Will
chop if too wide, pad on left with spaces if too narrow.
*/
static
String rightJust(int i, int width)
{
String
s = Integer.toString(i);
if
( s.length()< width )
{
return
"
".substring(0, width-s.length()) + s;
}
else if (
s.length() == width ) return s;
else
return s.substring(0, width);
}
// end rightJust
}
// end class Color spaceTest
You can play with Rich Franzen's colourwheel
Applet to sharpen your HSB intuition.
See wavelength, RGB, CYMK.
- HST
- Before the invention of the CCITT V.32 modem standards for 9600 BPS modems,
US Robotics invented a proprietary protocol that runs even faster at 14,400
BPS. It became popular on US bulletin board system, but never caught on
outside the USA. It is gradually being replaced by V.32
- HTML
- HyperText Markup Language. A platform independent technique of
distributing formatted documents via the web. The bold,
italic etc. in the document you are reading now (presumably on a
web browser), is encoded by embedding tags like <B> and <I>.
This markup scheme works on any brand of computer and allows web sites to
send all information in a standard way, without having to worry about what
brand of computer the recipient has, or what software she uses. I have
composed an ASCII format cheat sheet to help you
compose HTML. It shows you how to create all the special characters like:
< > & " ¡ ¢ £ ¤ ¥ ¦
§ ¨ © ª « ¬ ® ¯ ° ±
² ³ ´ µ ¶ · ¸ ¹ º
» ¼ ½ ¾ ¿ ÷ ×
and all the accented characters like:
À Á Â Ã Ä Å Æ Ç
È É Ê Ë Ì Í Î Ï Ð
Ñ Ò Ó Ô Õ Ö Ø Ù
Ú Û Ü Ý Þ ß
à á â ã ä å æ ç
è é ê ë ì í î ï ð
ñ ò ó ô õ ö ø ù
ú û ü ý þ ÿ.
The Quoter Amanuensis will
automatically convert HTML's reserved characters to their
& é © etc. form.
Unfortunately there is no symbol to get you a trademark TM. The
é style abbreviations are not kosher in HTML3.2. They
are not part of the HTML 3.2 spec, but Netscape and Internet
Explorer still support them. See the list of
special characters and the bare bones html guide.
There is the classic A
Beginner's Guide to HTML, and then move to the following tutorial
for FORMS.
You can see how well your browser supports various fonts by examining this
list:
Arial |
Courier New |
Impact |
Scribble |
Arial Black |
Courier-Bold |
Monaco |
Symbol (Symbol) |
AvantGarde-Book |
Courier-BoldOblique |
MS Sans Serif |
Tahoma |
AvantGarde-BookOblique |
Courier-Oblique |
MS Serif |
Terminal |
AvantGarde-Demi |
Garamond |
NewCenturySchlbk-Bold |
Times |
AvantGarde-DemiOblique |
Geneva |
NewCenturySchlbk-BoldItalic |
Times New Roman |
Bookman-Demi |
Helvetica |
NewCenturySchlbk-Italic |
Times-Bold |
Bookman-DemiItalic |
Helvetica-Bold |
NewCenturySchlbk-Roman |
Times-BoldItalic |
Bookman-Light |
Helvetica-BoldOblique |
New York |
Times-Italic |
Bookman-LightItalic |
Helvetica-Narrow |
Palatino |
Times-Roman |
Britannic Bold |
Helvetica-Narrow-Bold |
Palatino-Bold |
Verdana |
Comic Sans MS |
Helvetica-Narrow-BoldOblique |
Palatino-BoldItalic |
Webdings (Webdings) |
Comic Sans MS Bold |
Helvetica-Narrow-Oblique |
Palatino-Italic |
ZapfChancery-MediumItalic |
Courier |
Helvetica-Oblique |
Palatino-Roman |
ZapfDingbats (ZapfDingbats) |
When it comes to HTML4, and CSS style sheets, browser support is
shaky. You have to stick to a subset
of features that are commonly supported.
The W3 Consortium offers an
online validator for the
various HTML dialects. It is sort of a Lint for HTML. It can
ensure your HTML will work properly on browsers other than the
one you tested it on. The W3C consortium also controls the
various HTML standards.
For speed, and control, I use
CSE HTMLValidator 3.03 to
check my web pages offline.
If you writing Java source code for an Applet, you can persuade
the browser you are running under to display an HTML page with:
java.net.URL url = new java.net.URL(<fileName>);
getAppletContext().showDocument(url);
Unfortunately that does not allow you to take a hunk of HTML
you have in a String, perhaps as the result of a POST, and
display it. In that case you somehow have to persuade your server
to put that html in a file where you can find it via URL.
Alternatively you could use Sun's not-free HTML rendering
classes.
If you are writing an application you are SOL. For applications,
there is no standard HTML rendering class, though BISS-AWT has
some primitive HTML rendering code. Andrew Moulden
offshore@netcomuk.co.uk has also written Calpane
an HTML rendering class, based on Swing.
See DTD, css, SSI, Koala, WebTwin, W3C.
- HTTP
- Hypertext Transer Protocol. A protocol
used on the Internet by web browsers to transport text and graphics. It is
focusses on grabbing a page at a time, rather setting up a session.
- HTTPS
- Hypertext Transer Protocol Secure.
Used for encrypted communication between browsers and servers. All
transmission of HTTP data are made with the SSL protocol. See HTTP, SSL.
- HyperProf
- a profile viewer and class browser that uses a hyperbolic plane to place
the class tree.
- Hz
- Hertz, cycles per second. Modems sing to each other, so sometimes
you will see references to the frequencies of the tones they sing.