new someObject ((someObject)null );
Using longs for unique identifiers
Use a
long
identifier instead of a
String
identifier for unique constants, such as GUIDs, hash table keys, and state or context
identifiers.
For identifiers to remain unique across a BlackBerry® Java Application, use keys that an application generates based on a hash
of a
String
. In the input
String
, include enough information to make the identifier unique. For example, use a fully qualified
package name such as
com.rim.samples.docs.helloworld
.
Exiting applications correctly
Before you invoke
System.exit(int status)
, perform any necessary cleanup, such as removing objects from the
runtime store that applications no longer require.
Printing the stack trace
When you debug your application, to view the stack trace, catch a
Throwable
instance.
Code sample
catch (Throwable t) {
t.printStackTrace();
}
Best practice: Using objects judiciously
To allow a BlackBerry® Java Application to efficiently use memory resources, consider the following questions:
•
Given the size of an application, are all of the objects necessary?
•
Can your application store any objects that represent primitives, such as
Long
,
Integer
, and
Boolean
, as primitives
instead of as objects?
•
Are all of the persisted objects necessary?
•
Do any instances of
Vector
and
Hashtable
exist? Are these instances necessary? If so, how many
Object
handles
are not used in the
Vector
or
Hashtable
because the initial size is greater than the needed size?
•
How many
Objects
does your application create and then throw away? In other words, how many scope-specific
Objects
does your application create?
Best practice: Reducing the size of compiled code
To reduce the size of compiled code, consider the following guidelines:
Fundamentals Guide
Best practices for writing an efficient BlackBerry Java Application
18