Designing state machines using State Map Compiler (SMC)

A state machine is an entity, which handles the states of an entity by taking it thru various states, handles states’ entry - exit actions, controls the state transitions & transition actions.
Using state map compiler:
State map compiler helps us to design state machines easily. SMC has a well-defined format to write states, transitions & actions. [...]

Better “SingleTon” handling

Singleton design pattern is a creational pattern, which restricts the instantiation of objects. The designers need to keep three things in their mind before setting a class to follow Singleton pattern. One: make the constructor invisible. Two:provide a static method that can create a new instance only if no instance is available. Three: override the [...]

Executing native commands from Java

package subin.rnd.nativity;
import java.io.IOException;
import java.io.InputStream;
public class NativityTest
{
    public static void main(String[] args)
    {
        String cmd = “cmd /c dir”;
        _runtime = Runtime.getRuntime();
        executeCommand(cmd);
    }
   
    private static Runtime _runtime;
    private static Process _process;
    private static InputStream _inStream;
   
    private static void executeCommand(String cmd)   
    {
        System.out.println(“Executing > “ + cmd);
       
        _inStream = null;
        _process = null;
        int ch;
       
        try
        [...]

PushRegistry SMS Listener

I have attached a small code snippet which implements an SMS listener. For more details on PushRegistry click here. This will invoke notifyIncomingMessage() of the MessageListener. This code will not create a permanent entry in the registry, but will listen to the specified port as long as the application is alive.
package subin.rnd.mobile.game;
import javax.microedition.io.Connector;
import javax.wireless.messaging.MessageConnection;
import javax.wireless.messaging.MessageListener;
import javax.wireless.messaging.TextMessage;
public [...]

Creating Pie Charts using JFreeChart with custom colors

I have attached a sample code snippet for creating a Pie Chart using JFreeChart with custom colors. There is a PieReneder (a static inner class) which can be used to achieve the same. The PieRenderer takes an array of java.awt.Color in its constructor.
package subin.rnd.chart;
import java.awt.Color;
import java.io.File;
import java.util.List;
import org.jfree.chart.ChartFactory;
import org.jfree.chart.ChartUtilities;
import org.jfree.chart.JFreeChart;
import org.jfree.chart.plot.PiePlot;
import org.jfree.data.general.DefaultPieDataset;
public class PieChartWithCustomColours
{
    public [...]