Thursday, 15 November 2012

Java Blackberry database management

Blackberry java development allows to create a database on the device. There are many possible ways to create database. I have recently used Sqlite database for my application. Following is what I have done to use that with my application.

1) Create a database through through blackberry emulator. Following is the code to do that. 

 URI uri = URI.create("file:///SDCard/Databases/employee.db");
 Database sqliteDB = DatabaseFactory.create(uri);
 Statement st = sqliteDB.createStatement("CREATE TABLE Employee ("
 +"ID       INTEGER PRIMARY KEY,"
 +"name     TEXT,"
 +"number   TEXT,"
 );");
 st.prepare();
 st.execute();
 

2) A db file will be created in the file system. Open that db file. Insert as many data as you need. I have been required to insert data like this. As I had a large number of records that i needed in db on start up time only. I have tried to insert data through java program only. But i was facing issue about memory consumption. If you don't have too many data you can insert run time. 

3) Following is the code to retrieve data from database. 

 Statement st1 = sqliteDB.createStatement("select * from Employee;");
 st1.prepare();
 Cursor c = st1.getCursor();
 Row r;
 int count=0;
 while (c.next()) {
 r = c.getRow();
 String name = r.getString(1);
 }
 

If you have close database connection. You need to open the connection again before you go to retrieve data from the database. 

 sqliteDB = DatabaseFactory.open(uri);
 

This is just an example. Your implementation can be differ as per your requirement. 

Saturday, 18 August 2012

Java Design Patterns : Behavioral Patterns

Behavioral patterns are concerned with the flow of control through a system. Some ways of organizing control within a system can yield great benefits in both efficiency and maintainability of that system. Behavioral patterns distill the essence of proven practices into readily understood, well known, and easy-to-apply heuristics.

Following is the list of all Behavioral patterns:

  • Chain of Responsibility
  • Command
  • Interpreter
  • Iterator
  • Mediator
  • Memento
  • Observer
  • State
  • Strategy
  • Visitor
  • Template Method

Tuesday, 14 August 2012

Java Design Patterns : Structural Patterns

Structural patterns describe effective ways both to partition and to combine the elements of an application. The ways structural patterns affect applications varies widely: for instance, the Adapter pattern can let two incompatible systems communicate, while Facade lets you present a simplified interface to a user without removing all the options available in the system.

Following is the list of structural patterns :

  • Adapter
  • Bridge
  • Composite
  • Decorator
  • Facade
  • Flyweight
  • Proxy

Thursday, 9 August 2012

Four level accordion menu using jQuery

Here is a demo to use jQuery for left hand side menu.

Attaching code for the same also.

Tuesday, 7 August 2012

Java Design Patterns : Creational Patterns

These patterns support one of the most common tasks in object-oriented programming—the creation of objects in a system. Most OO systems of any complexity require many objects to be instantiated over time, and these patterns support the creation process by helping to provide the following capabilities:

Generic instantiation – This allows objects to be created in a system without having to identify a specific class type in code.

Simplicity – Some of the patterns make object creation easier, so callers will not have to write large, complex code to instantiate an object.

Creation constraints – Some patterns enforce constraints on the type or number of objects that can be created within a system.

The following is the list of creational design patterns:

  • Abstract Factory
  • Builder
  • Factory Method
  • Prototype
  • Singleton

Saturday, 4 August 2012

Java Design Patterns : Classification

The 23 design patterns covered in the original Design Patterns book had several known applications and were on a middle level of generality, where they could easily cross application areas and encompass several objects.

The authors divided these patterns into three types: creational, structural, and behavioral.

  • Creational patterns create objects for you rather than having you instantiate objects directly. This gives your program more flexibility in deciding which objects need to be created for a given case.

  • Structural patterns help you compose groups of objects into larger structures, such as complex user interfaces or accounting data.

  • Behavioral patterns help you define the communication between objects in your system and how the flow is controlled in a complex program.

Java Design Patterns : Learning Process

We have found that, regardless of the language, learning design patterns is a three-step process.

  1. Acceptance

  2. Recognition

  3. Internalization

First, you accept the premise that design patterns are important in your work. Then, you recognize that you need to read about design patterns so you will know when you need them. Finally, you internalize the patterns in sufficient detail that you know which ones might help you solve a given design problem.

For some lucky people, design patterns are obvious tools, and these people can grasp their essential utility just by reading summaries of the patterns. For many of the rest of us, there is a slow induction period after we've read about a pattern followed by the proverbial "Aha!" when we see how we can apply them in our work. This book takes you to that final stage of internalization by providing complete, working programs that you can try out yourself.

The examples in Design Patterns are brief and are in C++ or, in some cases, Smalltalk. If you are working in another language, it is helpful to have the pattern examples in your language of choice. This book attempts to fill that need for C# programmers.