Allan Jacobs

+ Follow
since Aug 28, 2006
Cows and Likes
Total received
In last 30 days
Total given
Total received
Received in last 30 days
Total given
Given in last 30 days
Forums and Threads
Scavenger Hunt
expand Ranch Hand Scavenger Hunt
expand Greenhorn Scavenger Hunt

Recent posts by Allan Jacobs

I'm very close to submitting. In my UI, I tried to follow the Java Look and Feel guidelines as closely as possible. JL&F is neutral on row sorting, so I probably did some extra work. I think I'll live dangerously and submit with a modification of the tutorial's table sorter. In a few weeks, I'll update this thread with notification of success or failure.

The tutorial's sorter did have some bugs in it. So, I did make some changes. I think it's appropriate to include Sun's copyright. If this was real code, would I need a second copyright to cover my fixes?
There is a free J2EE class that I can recommend that is being taught by Sang Shin: . Check out the definition of 'J2EE application' in the first week's assignment. Verify that the characteristics of your work assignment allow for the use of a J2EE application. Also, talk to your users or customers and gather use cases -- they will help define your assignment and constrain the solution.
Generics are especially useful when using collections. When using collections, the use of generics serves as an assertion that all the members of a collection have the same or at least a compatible set of types.
Third argument.

Simple API questions are answerable using the Javadoc for the Java API at The signature for the binarySearch
that takes a comparator is:

static <T> int binarySearch(T[] a, T key, Comparator<? super T> c)
Hello Deepak,

It is possible to do better than find the class file for you. Assuming that your .java file compiles then it should be possible to train you to find it yourself.

If your program compiles then post the (1) package statement at the top of the file that contains the Item.class usage, (2) the import statements at the top of the same file, (3) your javac command line (especially any -classpath argument). If your javac command line contains no -classpath argument then post (3') the CLASSPATH setting for your environment.
The B&S project is a client/server system and we are give us the choice of RMI or sockets. Does anyone have any ideas on how to get or buy machine time to allow for testing on a real network? I was RIFed by my employer recently and can't just use the machines at work.
The compiler error on page 104 of K&B is for the line that reads The type of the variable 'a' is Animal. The method eat() in Animal declares an exception. To get the code to compile, the method call needs to be in a try-catch block.

Declarations with exceptions are a separate issue. Leave out unchecked exceptions for purposes of discussion. It is legal for an overriding method to declare fewer exceptions than the method it overrides because any code that uses the override would still work -- the worst that would happen is that it would contain a seemingly redundant try-catch block. In terms of K&B page 104:
Animal a = new Dog2();
try {;
catch (Exception ex) {
assert (false) : "I'll never get here";
I'm a day or two away from submitting; I wish I could say that I've
passed the test and knew what I was talking about.

One good interpretation of the word "indication" is the "alone" in
"java -jar runme.jar alone". I had to look up the meaning of fits
the B&S specification in a number of places.
Try starting over. All the printing examples I've ever done were much
simpler and used only three or four classes. The home page for the
printing APIs are at . There is a link on that page to printing
tutorials. The URL for these is
There is an entry on this page entitled "The Printable Interface". It
introduces a sample code "PrintText".
13 years ago
I'm working on the same problem. There is one interface
specified for use in the server and it's a "data access interface."
The interface mandates lock, unlock, and isLocked method calls.

About lock cookies, there was another post about the
the home improvement contractor assignment. It was
noted that the data access interface did not specify RemoteException.
For instance,
public void lock(int recNo) throws RecordNotFoundException;
The reply in that post hinted that it might be the case that the
"data access interface" is different from the interface that a
client sees. Solutions might be free to use more than one
interface as long as one of them is from the assignment.

The assignent says that "must provide locking functionality as
specified in the interface provided." If we interpret the words
"data access interface" from the assignment instructions as
applying to the server only some of the problems go away.

This leads to the next befuddlement. It's possible to solve the problem
by implementing but not actually using the lock/unlock/isLocked
interface -- synchronization statements alone are sufficient.

My take on this is that synchronization should be avoided. One
benefit of implementing and using the lock/unlock/isLocked system
is that you can build in timeouts. That would allow the application
to cope with client crashes.

Another problem: the application has to be able to lock records
before it deletes them. The assignment instructions also say
that unlock method call throws an exception when called upon to
remove the lock from a deleted record. The assignment instructions
do not say whether or not the lock is actually removed in this
case. This is probably yet another reason to hide the unlock
method from client programs. Yuck.
There was a good summary of string length concepts and utilities
in September 2006. It's URL is
13 years ago
There is no ClassLoader.getCallerClassLoader() method. In the
sample code,
will return the current loader for the class of object o.
13 years ago
95%. Sign me up with the Kathy Sierra fan club.
13 years ago
class BBB { }
class CCC extends BBB { }
The instanceof operator is useful when it is necessary to find the
runtime type of an object. The declared type might be a supertype.

class DDD extends BBB { }
public class X {
public static void main(String[] args) {
BBB c = new CCC();
BBB d = new DDD();
X.checkIt(c); // prints true
X.checkIt(d); // prints false
private static void checkIt(BBB b) {
System.out.println(b instanceof CCC);

The example Stack<T> will not compile when you use a Java 5 compiler.

First, there are some shallow problems in the pop and peek methods. Their return type is 'int' and it's not guaranteed that a 'T' will unwrap to an int. Only if T is a subtype of java.lang.Integer will this be true.

Second, the type parameter is used as if the compiler could use it as a parameterized constructor name. This is not the case. The type parameters are merely used to enable the compiler to do type checking and have no impact on the bytecode that is generated. The problem is in the line that reads 'array = new T[number]'.

The code that follows compiles, the class that it generates can be
instantiated, and it seems to execute correctly, too.

package scjp.generic;

class Stack <T>
public int count = 0, size = 0, top = -1;
public String result;
public Object[] array;

public enum errormsg{UNDERFLOW, OVERFLOW};
int front = 0;

public Stack(int number)
array = new Object [number];

public void push(T obj)
array[top] = obj;


public T pop()
if( isNotEmpty() )
return (T)array[top--];
{ stackError( errormsg.UNDERFLOW ); }
return null;

public T peek()
return (T)array[top];
return null;

public boolean isNotFull()
return top<array.length-1;

public boolean isNotEmpty()
return top >= 0;

public void dump()

System.out.print("\t\t\t top: " + top + " Contents: " );
front = top;

System.out.print(array[front--] + " ");



public int Size()
return top+1;

public void stackError(errormsg msg)
switch (msg)
System.out.println("stack is empty!");
System.out.println("stack is full!");

14 years ago