devxlogo

Tip Bank

Default Arguments in a Template Instantiation

Templates can have default type parameters. The compiler uses these default types when you don’t provide them explicitly in a template instantiation. For example: template < class T1=char, class T2=char

Avoid Hardcoded Literal Strings

Hardcoded literal strings can become a serious maintenance problem. Suppose you have numerous message boxes in your application that display a hardcoded text message and you want to change that

Package Protected Constructor

Question: I need to extend class A which resides in a different package, butclass A has only one constructor which is package protected. I get a compile error in class

Vectors vs. Hashtables

Question: Is there a significant speed advantage to using Hashtables over Vectors? Answer: The answer depends on how you are using those containers classes. Ifyou are only using them for

Stopping Threads

Question: How do you stop a Thread without using the stop() method? Answer: The recommended method for stopping threads in Java is for each thread topoll a boolean value or

A HashMap of HashMaps

Question: I have been looking everywhere for information on HashMaps,particularly how to put one hash map into another HashMap. Answer: This is where the expression RTFM (Read That Fine Manual)

Multiple Drawing Threads

Question: I have written an applet which uses a Graphics object to draw movingcircles. However, when multiple threads accesses the same Graphics object,the circles disappear after being on screen for

Determining Stack Content Type

Question: Only Objects can be popped from, or push onto, a stack. That means Ihave to wrap a primitive data type, such as int, with something akin toInteger before pushing

Switching Between Frames

Question: I’m building an application that has several different frames. Eachhas a button that when pressed should bring up a new frame and closethe calling frame. How can I display