e.g. to compute the expected check digit 7 for: 706-511-227 7 0 6 5 1 1 2 2 7 * 2 * 2 * 2 * 2 --------------------------------- 7 + 0 + 6 +1+0+ 1 + 2 + 2 + 4 = 23 23 MOD 10 = 3 10 - 3 = 7 -- the check digitNote that the digits of the multiplication results must be added before doing the sum. Here is method more amenable to computer calculation:
e.g. to compute see if the check digit is as expected: 706-511-227 7 0 6 5 1 1 2 2 7 z z z z --------------------------------- 7 + 0 + 6 + 1 + 1 + 2 + 2 + 4 + 7 = 30 30 MOD 10 had better = 0 where int z (int digit) { // 0->0 1->2 2->4 3->6 4->8 5->1 6->3 7->5 8->7 9->9 if (digit == 0) return 0; else return (digit*2-1) % 9 + 1; }
Symantec Visual Cafe hides its CLASSPATH in C:\VCP\BIN\SC.ini. Internet Explorer hides its CLASSPATH in the registry under HKEY_LOCAL_MACHINE/SOFTWARE/Microsoft/Java VM. Netscape uses the CLASSPATH in the standard SET environment. Windows 95 controls the environment with SET CLASSPATH= in autoexec.bat. Linux controls the environment with export CLASSPATH= in your .bashrc file. NT controls the environment with the Control Panel / System / Environment settings. One would think a platform independent language would have a platform independent way of controlling the CLASSPATH, but it doesn't. Symantec's is closest.
In Linux and NT under bash, the elements of the classpath are separated by colons. In Win95 and standard NT, they are separated by semicolons. Somebody deserves a major raspberry.
Beware of inserting extra semicolons in your classpath. Everything to the right will be ignored!, leading you to pull out your remaining hair in frustration wondering why java can't find the classes. You must have exactly one semicolon between elements, no lead/trail/extras.
Just to keep you on your toes, in JDK 1.1 putting classes.zip on the CLASSPATH is optional. In 1.2 it is an error.
See java.exe for a detailed discussion of how Java.exe combines package names, class names and the classpath to find the classes.
You can then use it like this:
Rabbit r1 = new Rabbit();
Rabbit r2 = (Rabbit) r1.clone();
Note: To comply with Cloneable, clone() must return an Object not a Rabbit.
Instead of using super.clone(), you could use new Rabbit() and copy the fields one by one to the new object and return the new object. Then you don't have to mess with CloneNotSupportedException.
platform | problems |
---|---|
JavaSoft JDK 1.1.5 | ok |
JavaSoft JDK 1.1.6 | load problems with the JIT in Win95/NT. Problems with reading serialised files. |
Jbuilder 2.0 | ok |
Microsoft Internet Explorer 4.01 | Not only does IE 4 leave out the RMI classes, its security manager prevents you from using Sun's. It complains that you are trying to access "localhost" which it considers to be a different host from the nameless one it loaded the applets from. Problems loading jar files. Microsoft wants you to use proprietary cab files instead. |
Microsoft Internet Explorer 4.01
with the Activator Java Plug-in |
ok |
Netscape Communicator 4.05 | ok. In earlier versions the JIT fails. You can turn it off by deleting the jit3240.dll file. |
Netscape Communicator 4.05 with the Activator Java Plug-in | ok |
Supercede 2.01 | Needs registry entries like this HKEY_LOCAL_MACHINE\SOFTWARE\JavaSoft\Java Runtime Environment\1.1\JavaHome "C:\Program Files\Supercede\Jre" HKEY_LOCAL_MACHINE\SOFTWARE\JavaSoft\Java Runtime Environment\1.1\MicroVersion "4" HKEY_LOCAL_MACHINE\SOFTWARE\JavaSoft\Java Runtime Environment\1.1\RuntimeLib "C:\WINNT\System32\sc30rtl.dll" |
Symantec 2.5 Visual Cafe JIT activated |
ignores standard classpath, uses SC.INI. |
Symantec 2.5 Visual Cafe JIT disabled SET JAVA_COMPCMD=DIS |
ignores standard classpath, uses SC.INI. |
Suppose further that a class Animal_printer implements the method:
void print(Animal a);
Can I say that Animal_printer implements Dog_printer? Logically, I should be able to. Anywhere that a Dog_printer is expected, I can supply an Animal_printer, and the dog will get printed. (Because all dogs are animals.) So, logically, there is the relation:
Animal_printer is a subtype of Dog_printer.
Although logically correct, this is weird looking. Then again, something that can print any animal "extends" something that can print any dog, so maybe it isn't so weird. Anyway, to determine whether Animal_printer is a subtype of Dog_printer, we have used the "contravariant argument rule". Similarly, there is a "covariant return value rule" that would state that:
Dog_creator is a subtype of Animal_creator.
See contravariance.
More generally CRCs are a technique for creating a signature from a string of bytes. If any of the bytes changes, then most likely the calculated signature would change too. CRC's are used to verify a message has been sent unmolested and for hashCodes. JDK 1.1 offers the java.util.zip.Checksum interface and CRC32 and Adler32 classes that implement it. CRC32 produces a classic 32 bit result using native code for speed. The CRC calculation can be thought of as polynomial division, with the individual bits as coefficients, or as XOR division that ignores carries. It works much like treating the message as a giant binary number and dividing it by some prime number and taking the remainder as the signature, except the calculation is easier for computers. Adler32 uses a even more simplified and speedy algorithm that produces almost as satisfactorily "random" a result. Here is how to use the undocumented 16-bit CRC built into Java 1.0.2.
import sun.misc.*; ... byte[] b = new byte[200]; ... // create a new CRC-calculating object CRC16 crc = new CRC16(); // loop, calculating CRC for each byte of the string for (int i=0; i<b.length; i++) { crc.update(b[i]); } short result = (short) crc.value;The innermost loop of a 16-bit CRC calculation looks something like this:
for (int i = 0; i<256; i++) { int crc = i; crc = (crc >> 1) ^ ((crc & 1) ? poly : 0); crc = (crc >> 1) ^ ((crc & 1) ? poly : 0); crc = (crc >> 1) ^ ((crc & 1) ? poly : 0); crc = (crc >> 1) ^ ((crc & 1) ? poly : 0); crc = (crc >> 1) ^ ((crc & 1) ? poly : 0); crc = (crc >> 1) ^ ((crc & 1) ? poly : 0); crc = (crc >> 1) ^ ((crc & 1) ? poly : 0); crc = (crc >> 1) ^ ((crc & 1) ? poly : 0); CRCTable[i] = crc; }
![]() |
![]() |
![]() |
|
Canadian Mind Products | The Mining Company's Focus on Java Best of the Net Award |
You can get an updated copy of this page from http://mindprod.com/jglossc.html |