Professional Documents
Culture Documents
White Paper Best Practices
White Paper Best Practices
WHITE PAPER
BEST PRACTICES
http://www.siemens.com.br/wm
____________________________
04-07-2007 pág. 1/15
____________________________S
BEST PRACTICES A&D SC WM
Summary
Preface/Facts pag.3
Benchmarking/Monitoring pag.5
AT Command pag.9
Memory pag.12
Performance pag.13
____________________________
04-07-2007 pág. 2/15
____________________________S
BEST PRACTICES A&D SC WM
Preface/Facts
J2ME is intended for devices with limited memory resources and processor power, such as cell
phones and Personal Data Assistants (PDAs).
The configuration is a specification, which relies on features and facts of the device:
- types and amount of memory
- processor type and speed
- type of network connection available to the device
Glossary
____________________________
04-07-2007 pág. 3/15
____________________________S
BEST PRACTICES A&D SC WM
Necessities of CLDC:
- save memory
- structure the code to get it as small as it can be
____________________________
04-07-2007 pág. 4/15
____________________________S
BEST PRACTICES A&D SC WM
Benchmarking/Monitoring
Memory
Available methods in the Runtime class
- freeMemory()
- totalMemory()
Performance/Execution Time
§ System time
- currentTimeMillis()
____________________________
04-07-2007 pág. 5/15
____________________________S
BEST PRACTICES A&D SC WM
Code Style
General instructions
§ Try to reduce the count of objects (potentially stored in arrays or vectors) and use one class
working on data directly
instead implement
arrayObject[num].do(<args>);
use
singletonObject.do(num, <args>);
____________________________
04-07-2007 pág. 6/15
____________________________S
BEST PRACTICES A&D SC WM
Bad style:
Better style:
Cleaning UP
Bad style:
____________________________
04-07-2007 pág. 7/15
____________________________S
BEST PRACTICES A&D SC WM
Better style:
____________________________
04-07-2007 pág. 8/15
____________________________S
BEST PRACTICES A&D SC WM
ATCommand
Attention
It is extremely important to create only one AT command instance for the entire application
See below an example for the execution of one AT command trough Java:
In case of use various AT commands, the example below is a better style of code:
____________________________
04-07-2007 pág. 9/15
____________________________S
BEST PRACTICES A&D SC WM
Another important recommendation is to insert a delay after ATs command to prevent errors.
____________________________
04-07-2007 pág. 10/15
____________________________S
BEST PRACTICES A&D SC WM
Using the “SyncATConmmand” Siemens class (see below), which synchronizes the AT commands,
avoids the execution of 2 or more AT commands at the same time.
Tip: Take the maximum advantage of the modules using the java in order to organize your projects
in an object-oriented way.
Avoid put all your application logic into Execution class (startApp ()). Program in a modular way
facilitates an overview of the project, without counting that in this direction, the possibilities of reuse
the code are much bigger.
____________________________
04-07-2007 pág. 11/15
____________________________S
BEST PRACTICES A&D SC WM
Memory
Strings
§ Strings are the only objects where the "+" operator is overloaded.
§ It is not complete clear when the runtime environment creates new objects and how much of
them.
§ Remember String and StringBuffer both work on character arrays in the background.
So if you want full control on your instances just use character or byte arrays
§ With these objects it is easy to handle a vary number of objects or data. Remember that these
structures grow larger when needed and this is expensive. New objects are created and a lot
of copy work must be done
§ If you use them try to initialize the size of the instance as correct as possible. Both classes
have constructors where you can set the initial value.
If you do so no resizing or rehashing must be done and you save performance.
____________________________
04-07-2007 pág. 12/15
____________________________S
BEST PRACTICES A&D SC WM
Performance
Reading/writing on streams
Bad style:
Solution:
- a couple of bytes read
- in best case only one loop is done (data < buffer)
____________________________
04-07-2007 pág. 13/15
____________________________S
BEST PRACTICES A&D SC WM
Use an Obfuscator
- Reduce the size of the class files
- Keeps your application slim
- Makes the execution faster
Generate a JavaDoc
____________________________
04-07-2007 pág. 14/15
____________________________S
BEST PRACTICES A&D SC WM
Recommended bibliography
http://java.sun.com/
http://proguard.sourceforge.net/
____________________________
04-07-2007 pág. 15/15