Showing posts with label General QA. Show all posts
Showing posts with label General QA. Show all posts

Monday, January 4, 2010

Export config Data Using Preferences Class

We can Export User/System configuration data using Preferences API to a persistent file. The exported file would be XML formated.
Example:


The content of the XML file would be:

Java Properties Class Vs Preferences Class

Whenever we needed to store user specific configuration, we could use the Properties class. One issue using Properties class is where to store those files, here simple file system or network files would be used to store those informations, but what happens if user does not have write permission on those file systems.

Here the Preferences API comes into the existence, this API is available since Java 1.4, this API resolves these problems. The purpose of the API is to allow for the easy storage of user preferences without the developer having to worry about where this information will be stored. The API determines the appropriate place.
For example, when running an application in Windows, the preferences will be stored in the Windows registry.

This API is found in java.util.prefs package. All preferences are stored like tree-structure with the data itself stored in nodes of the tree.

This API provides two types of Preferences data:
   1. User Preferences
   2. System Preferences

1. User Preferences are only visible to the user, for which it is created.
2. System Preferences are shared among all the users.

The Preferences class has several methods used to get and put primitive data in the Preferences data store. We can use only the following types of data:
   * String
   * boolean
   * double
   * float
   * int
   * long
   * byte array

Example:


Output:


If we use Preferences API in Windows platform, then Preference data will be stored in Windows Registry.

Tuesday, December 29, 2009

Java Keyword Ordering

Keyword Ordering
The Java language specification makes recommendations about the order of modifiers:

For Fields:
public -> protected -> private -> static -> final -> transient -> volatile.

For Methods:
public -> protected -> private -> abstract -> static -> final -> synchronized -> native -> strictfp.

For Classes:
public -> protected -> private -> abstract -> static -> final -> strictfp.

Saturday, November 14, 2009

What does Bytecode Verifier

1. Checks a classfile for validity:
    a. Code only has valid instructions & register use
    b. Code does not overflow/underflow stack
    c. Does not convert data types illegally or forge pointers
    d. Accesses objects as correct type
    e. Method calls use correct number & types of arguments
    f. References to other classes use legal names

2. Goal is to prevent access to underlying machine