Chapter Three, Sethi

Structured programming

No Preprocessor:

Unlike C++, which has a preprocessor and can compile separate debug and release versions of code, Java does not have a preprocessor or its equivalent and cannot compile conditional code. This is not as big a loss as it seems since conditional code is often used for platform specific features and Java is platform independent.

The Java 1.4 release introduced an assert() capability which can be used to enforce pre/post conditions in PRIVATE methods. The assert statements are left in the code and must be activated with a command line argument. (Array bounds are automatically checked in Java and an ArrayIndexOutOfBounds exceptions is thrown when necessary).

Java provides some support for synchronization in multithreaded environments. The synchronize key word can be used in sections of code or for a method to ensure an exclusive lock on a data object.

For example,

Synchronize (data)

{

//manipulate the data here

}