Tip Bank

DevX - Software Development Resource

If Your Compiler Doesn’t Support snprintf() Yet

Sometimes, sprintf() is unavoidable. For example, when compatibility with C is paramount, Sprintf() has a safer version called snprintf(), which doesn’t write past its buffer’s limits. However, because snprintf() was

DevX - Software Development Resource

Avoid This Common ASSERT(…) Mistake

ASSERT is a very helpful macro for debugging, because it helps root out false assumptions. However, many programmers make the mistake of putting actual assignments inside the macro. Consider the

DevX - Software Development Resource

Using const_cast

If you want to convert from a const to a nonconst or from a volatile to a nonvolatile, you can use const_cast. This is the only conversion allowed with const_cast.

DevX - Software Development Resource

Porting Code With Unix File I/O

In pre-standard C, I/O operations were based on the Unix APIs. Instead of FILE pointers and functions such as fopen(), fread(), and fclose() that are defined in the header, Unix

DevX - Software Development Resource

Rounding a Number

The Standard Library doesn’t have a function for rounding floating point variables. However, you can easily round numbers as follows: double d=42.666;int rounded=d+0.5; // rounded = 43d=rounded; // d is

DevX - Software Development Resource

JToolTip in a JTable Column

Tool tips are handy for providing explanations for buttons and other fixed components in a panel. Sometimes, it

DevX - Software Development Resource

Execute an External Program Without Using JNI

The secret lies in the Runtime class. Runtime contains the methodexec, which takes the basic form of: Process exec(String command) orProcess exec(String[] comdarray) orProcess exec(String[] cmdarray, String[] envp, File dir)