March 28, 2001

Object.hashCode() and Object.equals()

The Object.hashCode() method returns a number that is effectively random. This number is also implementation- and instance-dependent. This has a couple consequences: 1 – The order of iteration for elements in a Hashtable will be unpredictable, and will generally differ from one program invocation to the next.2 – A class

Setting the SQL Plus Environment With login.SQL File

The environment of a SQL plus session, like linesize, pagesize, etc., can be permanently set according to one’s own needs with the help of login.sql file. The settings can be set by a SET statement on each line. For Example: SET linesize 100SET pagesize 100 The above settings can be

Making a Collection Read-Only

The Collections class provides static APIs to generate a read-only or unmodifiable collection, list, set, or map from the specified entity. For instance, if you are sure that the ArrayList you’ve made should not be modified, you can generate a read-only list from it by using the following code: ArrayList

Making a Thread-Safe or Synchronized Collection

As you know by now, the commonly used collection classes, such as java.util.ArrayList, are not synchronized. However, if there’s a chance that two threads could be altering a collection concurrently, you can generate a synchronized collection from it using the synchronizedCollection() method. Similar to the read-only methods, the thread-safe APIs

Conditional Compilation in Java

The C preprocessor provides for conditional compilation in instances where large areas of text are ignored and stripped out, regardless of whether a given preprocessor constant was defined. For example: #if defined(XYZ) //code part 1#else //code part 2#endif Although this functionality is not directly available in Java, we can achieve

Determining the Size of an Oracle Database

The size of the database is the total size of the datafiles that make up the tablespaces of the database. These details are found in the dba_extents view. Type the following lines at the SQL-PLUS prompt: select sum(bytes/1048576)from dba_extents; This will give the total number of Mb used by your

Allocating Memory Before Calling a Function

Suppose you want to pass an object to a method and also want to allocate the object into that method. If you pass the object as it is, it will not work because the memory that the object points to changes. To get around this, wrap this object into another