General Java Questions I
the design of your application. You should fix this instead of using dirty tricks like the
above.
Carl Rosenberger
db4o database for objects
http://www.db4o.com
Q: If anybody can provide some tips on how to design this smartly...
Q: I am facing a problem that might sound common to you all. I have to write a
switch statement with 40 case statement. I am wondering if there can be some way to
reduce this. If anybody can provide some tips on how to design this smartly. ;)
Answer: The alternatives are:
an array you index into to get values or delegates.
an array you binary search.
Roedy Green
Q: I want to use some java variables , across multiple java files. Is there some
thing like a "extern in C" in java ??
Answer: If you want to share constants, the usual way is to create a class like this:
public class My_Constants {
public static final int ID_OK = 1;
public static final int ID_CANCEL = 2;
public static final String MSG_OK = "Okay.";
public static final String MSG_ERROR = "An error occurred.";
}
If you want to share a single object instance across your application, use the
Singleton pattern.
Actually, the more common way is to create an interface, like this:
public interface MyConstants{ // Note naming conventions
int ID_OK=1; // public static final is implicit in interfaces
// etc
}
Then anyone who wishes to use the constants without putting MyConstants before
each reference can simply implement the interface.
by Gerhard Haring, Jon Skeet
Q: Does anyone know what the character limit for a class name would be?
I have my class name in a variable ft and I am doing a Class.forName(ft);
My class name with qualifiers is 44 characters long, I can only imagine that there
must be a limit ....
Answer: From the JVM Spec 2 4.2
Class and interface names...fully qualified name...as
CONSTANT_Utf8_info.
file:///F|/a_jsite/350_tips/general_java I.htm (32 of 33) [2001 07 08 11:24:51]
footer
Visionwebhosting.net Business web hosting division of Web
Design Plus. All rights reserved