Your Ad Here

Thursday, June 9, 2011

GSM, GPRS, EDGE, 3G, WCDMA and HSDPA

It's a very basic and non-technical comparison.
GSM

GSM, stands for Global Systems for Mobile Communications, is basic standard bearer of 2G technologies. It is mainly used in mobile communication. Short Messaging System (SMS) was introduced into GSM networks along with capability to download content from various service providers. The content could ring tone, logos and picture messages.

It can support Voice telephony and Data however the Data rate is only 9.6Kb/s, that is very low bit rate for date communication.
GPRS

GPRS, stands for General Packet Radio Service, is used to give higher data speed over GSM. It is not the replacement of GSM. It is just a extension to the older GSM technology to gain faster speed.

Multimedia Messaging System or MMS is the feature of GPRS. It allowed subscribers to send videos, pictures, or sound clips to each other just like text messages. GPRS also provided mobile handset the ability to surf the Internet at dial-up speeds through WAP enabled sites.

GPRS offered higer bit rate ( Up to 171kb/s) by usage of A packet-linked technology over GSM.

EDGE

  • EDGE stands for Enhanced Data Rates for GSM Evolution. This technology, also termed as Enhanced GPRS.
  • This is a technology that uses the same equipment as GSM with only a few minor modifications to provide faster data speeds and is often regarded as a stepping stone towards 3G thus it is called 2.5G.
  • EDGE gives the users the inimitable chance to increase the throughput capacity and the data speed at least 3 to 4 times higher to what GPRS offers.
  • EDGE is a digital mobile phone technology but GPRS is a mobile data service.
  • It is a 3G Radio technology and GPRS or General Packet Radio Service is essentially packet oriented.
3G
  • The introduction of 3G changed a lot of the accepted standards in the mobile phone industry. It allows the use of a greater bandwidth that allows more features to be implemented on it.
  • 3G gives many features like video calls and TV applications because of the speed of 3G which began at 384kbps; well within DSL speeds. Further development on 3G technologies have also created even faster data rate reaching 3.6 and even 7.2Mbps.
  • Existing GSM networks are not compatible with the 3G networks. To keep it, requires a new infrastructure.
  • According to popularity and demand Telecom Operators place 3G towers in those areas.They have to operate 2 radios in particular areas; one for GSM and one for 3G.
  • Mobile phone Users are also required to switch mobile phones in order to take advantage of the new features of 3G.
WCDMA

3G Networks are based on WCDMA i.e. Wideband Code Division Multiple Access, a mobile technology that improves upon the capabilities of current GSM networks.

HSDPA
HSDPA (High Speed Downlink Packet Access) is what is also known as 3.5G, as it offers no substantial upgrade to the feature set of WCDMA, but improves the speed of data transmission to enhance those services.
WCDMA networks provides max 384kbps speed whileHSDPA allowed speeds above 384kbps, the most notable of which is 3.6Mbps and 7.2Mbps.

HSDPA has lower latency times and Fast Packet Scheduling compared to WCDMA.

Wednesday, June 8, 2011

How to write Binary data in XML

Binary data in XML

Sometimes It is required that we need to send content / binary data in xml itself instead of urls / path along with the meta data of the content.

Here is the code to write an Image File in XML : (I used here Base64 encoding)

-----------------------------------------------------------------------------------
import java.awt.image.BufferedImage;
import java.io.ByteArrayOutputStream;
import java.io.File;
import java.io.FileInputStream;
import java.io.FileNotFoundException;
import java.io.IOException;

import javax.imageio.ImageIO;

import org.apache.commons.codec.binary.Base64;


public class WriteBinaryXML {

    /**
     * @param args
     */
    public static void main(String[] args) {
        // TODO Auto-generated method stub
        try {
            BufferedImage img = ImageIO.read(new File("/pathofsourceimage/image.jpg"));
            ByteArrayOutputStream baos = new ByteArrayOutputStream();
            ImageIO.write(img, "jpg", baos);
            baos.flush();
            String encodedImage = new Base64().encodeToString(baos.toByteArray());
            baos.close();
            System.out.println("encodedImage -----  " + encodedImage);
 
    // Write this String (encodedImage)  to the tag using any xml api.

          }
    }
}

Tuesday, June 7, 2011

Start working with hibernate

There are few steps to start working with hibernate

1) pre-requisite for hibernate
2) Creation of Database / tables
3) Creation of POJO for tables
4) Mapping POJO to Database table
5) Configuration
6) Log4j configurations
7) Execute the example

1) Pre-requisite for hibernate 

a) The jdk1.5.x/1.6.x should be installed, JAVA_HOME and PATH should be set correctly.
b) Download and extract/install zip/tar file of Eclipse IDE (I used Galileo).
c) Download the following jars files from http://hibernate.org

ant-1.6.2.jar
ant-antlr-1.6.2.jar
ant-junit-1.6.2.jar
ant-launcher-1.6.2.jar
antlr-2.7.4.jar
ant-swing-1.6.2.jar
asm-3.3.jar
c3p0-0.8.5.jar
cglib-2.2.jar
cleanimports.jar
commons-collections-2.1.1.jar
commons-logging-1.0.4.jar
concurrent-1.3.2.jar
connector.jar
dom4j-1.5.2.jar
ehcache-1.1.jar
ejb3-persistence-3.3.2.Beta1.jar
hibernate-3.2.6.ga.jar
hibernate3.jar
hibernate-annotations-3.4.0.GA.jar
hibernate-commons-annotations-3.1.0.GA.jar
hibernate-core-3.3.0.SP1.jar
hibernate-entitymanager-3.4.0.GA.jar
hibernate-search-3.0.1.GA.jar
hibernate-validator-3.0.0.ga.jar
jaas.jar
jacc-1_0-fr.jar
jaxen-1.1-beta-4.jar
jboss-cache.jar
jboss-common.jar
jboss-jmx.jar
jboss-remoting.jar
jboss-system.jar
jdbc2_0-stdext.jar
jgroups-2.2.7.jar
jta.jar
junit-3.8.1.jar
log4j-1.2.9.jar
mysql-connector-java-3.0.16-ga-bin.jar
mysql-connector-java-3.1.6-bin.jar
oscache-2.1.jar
postgresql-8.2-504.jdbc3.jar
proxool-0.8.3.jar
swarmcache-1.0rc2.jar
versioncheck.jar
xerces-2.6.2.jar
xml-apis.jar

*some are not required e.g. if you are using mysql as your database then postgresql-8.2-504.jdbc3.jar is not required.

2) Creation of Database / tables  (Postgres SQL) :

|--------------------------------------------------------------------|
CREATE TABLE "public"."emp" (
id SERIAL,
name text,
dob date
PRIMARY KEY(id)
);
|--------------------------------------------------------------------|

3) Creation of POJO for tables  (Employee )

package net.vs.example;
public class Employee {
private Integer id;
private String name;
private Date dob;
public Employee(){
}
public Integer getId() {
return id;
}
public void setId(Integer id) {
this.id = id;
}
public String getName() {
return name;
}
public void setName(String name) {
this.name = name;
}
public Date Dob() {
return dob;
}
public void Dob(Date dob) {
this.date = date;
}

4) Mapping POJO to Database table

You can use XML or annotations to define, how to map your class attributes to a database table.
Create the Employee.hbm.xml in the package net.vs.example and change it to the following

PostgreSQL Version:
xml version="1.0" encoding="UTF-8"?>
DOCTYPE hibernate-mapping PUBLIC "-//Hibernate/Hibernate Mapping DTD
3.0//EN" "http://hibernate.sourceforge.net/hibernate-mapping-3.0.dtd" >
<hibernate-mapping>
<class name=net.vs.example.Employee table=emp>
<id name="id" column="id">
<generator class="sequence">
<param name="sequence"> emp_id_seq param>
generator>
id>
<property name="name" column = "name"/>
<property name="dob" column="dob" />
class>
hibernate-mapping>

5) Configuration

Create a file named “hibernate.cfg.xml” in your root directory
Insert the following in your hibernate file.


PostgreSQL Version:
xml version='1.0' encoding='UTF-8'?>
DOCTYPE hibernate-configuration PUBLIC "-//Hibernate/Hibernate Configuration DTD 3.0//EN"
"http://hibernate.sourceforge.net/hibernate-configuration-3.0.dtd">
<hibernate-configuration>
<session-factory>
<property name="connection.url">
jdbc:postgresql://localhost:5432/myDB
property>
<property name="connection.username"> myuser property>
<property name="connection.driver_class">org.postgresql.Driverproperty>
<property name="dialect">org.hibernate.dialect.PostgreSQLDialectproperty>
<property name="connection.password">mypwdproperty>

<property name="hibernate.show_sql">trueproperty>
<mapping resource="employee.hbm.xmll" />
session-factory>
hibernate-configuration>

6) Log4j configurations

As you can see above we added the log4j library. This library does like a configuration file in thesource directory or it welcomes you with the following error.

log4j:WARN No appenders could be found for logger (TestClient).
log4j:WARN Please initialize the log4j system properly.


Create a file named log4j.properties in the root directory and insert the following:
### direct log messages to stdout ###
log4j.appender.stdout=org.apache.log4j.ConsoleAppender
log4j.appender.stdout.Target=System.out
log4j.appender.stdout.layout=org.apache.log4j.PatternLayout
log4j.appender.stdout.layout.ConversionPattern=%d{ABSOLUTE} %5p %c{1}:%L - %m%n
### set log levels - for more verbose logging change 'info' to 'debug' ###
log4j.rootLogger=debug, stdout
log4j.logger.org.hibernate=info
#log4j.logger.org.hibernate=debug
### log HQL query parser activity
#log4j.logger.org.hibernate.hql.ast.AST=debug
### log just the SQL
log4j.logger.org.hibernate.SQL=debug
### log JDBC bind parameters ###
log4j.logger.org.hibernate.type=info
### log schema export/update ###
log4j.logger.org.hibernate.tool.hbm2ddl=info
### log HQL parse trees
#log4j.logger.org.hibernate.hql=debug
### log cache activity ###
log4j.logger.org.hibernate.cache=info
### log transaction activity
#log4j.logger.org.hibernate.transaction=debug
### log JDBC resource acquisition
#log4j.logger.org.hibernate.jdbc=debug
### enable the following line if you want to track down connection ###
### leakages when using DriverManagerConnectionProvider ###
#log4j.logger.org.hibernate.connection.DriverManagerConnectionProvider=trace
7) Execute the example


TestHibernate.java

public class TestHibernate{

public static void main(String agrs[]) {

Session session = null;
try {

SessionFactory factory = new Configuration().configure().buildSessionFactory();
session = factory.openSession();

Employee emp = new Employee();
emp.setName("John");
emp.setDob(new Date());

session.save(emp);

} catch(Exception be){
be.printStackTrace();
}
finally {
// Actual contact insertion will happen at this step
if (null!=session){
session.flush();
session.close();
}

}

}
Cheers !




Thursday, June 2, 2011

Why Hibernate ?

Hibernate, is Open Source Persistence technology and an Object-Relational Mapping (ORM) solution for JAVA. It is powerful, high performance O/R persistence and query engine. Working with Relational Database is complicated task with JDBC because there is mismatch between how data is represented in objects versus relational
database. So with JDBC, developer has to write code to map an object model's data representation to a relational data model and its corresponding database schema. At the other end Hibernate is flexible and powerful ORM solution to map Java classes to database tables.

Hibernate key features:

1) Hibernate 3.0 provides three type of facilities to query in database, via Hibernate Query Language(HQL), via Criteria Query and native SQL.
2) It also provides full support for projection/aggregation and subselects.
3) Hibernate can be used to develop/package and distribute the applications for free as it is under LGPL(GNU Lesser General Public License).
4) Mapping of Java objects with database tables and vice versa is called Transparent Persistence. It provides transparent persistence and developer does not need to write code explicitly to map database tables rows to application objects during communicating with Relational Databases. Using JDBC this need to be write manually with some lines of code.
5) Using JDBC, if there is any table / column / datbase change then developer need to write / modify the code many places. As table changed or database changed then it’s essential to change object structure as well as to change code written to map table-to-object/object-to-table.
Hibernate provides this mapping itself. The actual mapping between tables and application objects is done in XML files. If there is change in Database or in any table then the only need to change XML file properties.
6) Hibernate supports Automatic Versioning and Time Stamping, By database versioning one can be assured that the changes done by one person is not being roll
backed by another one unintentionally. Hibernate enables developer to define version type field to application, due to this defined field Hibernate updates version field of database table every time relational tuple is updated in form of Java class object to that table. So if two users retrieve same tuple and then modify it and one user save this modified tuple to database, version is automatically updated for this tuple by Hibernate. When other user tries to save updated tuple to database then it does not allow to save it because this user does not has updated data. In JDBC there is no check that always every user has updated data. This check has to be added by the developer.
7) Maintenance Cost reduses with Hibernate, With JDBC, it is developer’s responsibility to handle JDBC result set and convert it to Java objects
through code to use this persistent data in application. So with JDBC, mapping between Java objects and database tables is done manually. Hibernate reduces lines of code by maintaining object-table mapping itself and returns result to application in form of Java objects. It relieves programmer from manual handling of persistent data, hence reducing the development time and maintenance cost.


Main Disadvantages of Hibernate:

1) There will be a learning curve.
2) Hibernate is not for Data centric applications. For Instance if there is an application which used to use DB procedures and business logic at DB level not at Java object level then Its better not to choose hibernate, use JDBC instead.

Friday, June 25, 2010

Difference between ResultSet TYPE_SCROLL_SENSITIVE and TYPE_SCROLL_INSENSITIVE

Difference between ResultSet TYPE_SCROLL_SENSITIVE and TYPE_SCROLL_INSENSITIVE

If you would like to have a scrollable ResultSet Object then you need to supply constant when you create an object of it. By default it is FORWARD_ONLY, you can traverse forward in order to fetch records from table.

e.g. Statement stmt = con.createStatement(ResultSet.TYPE_SCROLL_INSENSITIVE , ResultSet.CONCUR_READ_ONLY);
Or
Statement stmt = con.createStatement(ResultSet.TYPE_SCROLL_SENSITIVE , ResultSet.CONCUR_READ_ONLY);

Or
Statement stmt = this.con.createStatement(ResultSet.TYPE_SCROLL_INSENSITIVE, ResultSet.CONCUR_UPDATABLE);

Or
Statement stmt = this.con.createStatement(ResultSet.TYPE_SCROLL_SENSITIVE, ResultSet.CONCUR_UPDATABLE);


A result set that is TYPE_SCROLL_INSENSITIVE does not reflect changes made while it is still open and one that is TYPE_SCROLL_SENSITIVE does.
Changes will be visible if result set is closed and re-opened.

TYPE_SCROLL_SENSTIVE does not *guarantee* that all changes made to the result set by others will be visible.It depends on a number of factors including the driver implementation (whether it caches the rows or not), the transaction isolation level etc...

Wednesday, June 2, 2010

Why should use Stored Procedures

In software development its very common to interact with Database(s) and Application Layer used to fetch data from DB using any programming language like java, C# conjunction with SQL.
There are two kind of DB languages
1) SQL : Non procedural language, where you can not write your own logic / subroutines.
2) PL/SQL: Procedural language, where you can write business logic and subroutines.

Stored procedures used where we would require the following
* modular programming at DB level
* Faster execution.
* Reduce network traffic.
* Security mechanism.

Advantages:

->You can modify stored procedures independently of the program source code.The application doesn't have to be recompiled when/if the SQL is altered.
->Stored procedures abstract or separate server-side functions from the client-side.
->Stored procedures allow a lot more flexibility offering capabilities such as conditional logic.
->Stored procedures are stored within the databse and run directly in database engine, bandwidth and execution time are reduced. This is because a single stored procedure can execute a complex set of SQL statements.

Disadvantages:

->If we need to modify anything in stored procedure then its definition has to be replaced.
->Any changes in the stored procedure will impact all the places whereever this procedure is used.

How to create :
http://download.oracle.com/docs/html/B16022_01/ch3.htm
Examples in java:
http://www.oracle.com/technology/sample_code/tech/java/jsp/oracle9ijsp.html

Sunday, May 23, 2010

Best Strategy ? Abstract classess Or Interface

Few points before to proceed :

1) Abstract class can have one or more abstract methods as well as concrete methods.
2) An abstract class can't not be instantiated.
3) To use functionality of abstract class One can create a concrete class that has to instantiate the abstract class and must have implementation for each abstract method.
4) Abstract classes are usually declared where two or more subclasses are expected to fulfill a similar role in different ways through different implementations.
5) Interfaces defines the behavior of the classes. in another word Contract.
6) All methods declared in interface are abstract by default, no need to use abstract keyword.
7) Basic feature of OO is Encapsulation : Reveal an object's programming interface (functionality of the object) without revealing its implementation.
8) Interfaces have no direct inherited relationship with any particular class, they are defined independently. Interfaces themselves have inheritance relationship
among themselves.

When Should Interfaces or Abstract classes some point are below :
First and very important is "Choice of design".
Second there are some facts and features of each, according to design we should use them.

1) Using Interfaces, The implementation can change without affecting
the caller of the interface.
2) Using Interfaces, Unrelated (One class is not a sub-class of another class) classes can implement similar methods(behaviors).
3) An interface can only define constants while abstract class can have fields.
4) Use Abstract classes, where you want to provide common implementation code for all its sub classes. It reduces the duplication. However we should not forget that a concrete can extend only one super class whether that super class is in the form of concrete class or abstract class.

I would use interfaces when I think that something there are very frequent changes in my design. How??? Simple example :

Consider an interface that you have developed called "TaskHandler":

public interface TaskHandler{
void performSomething(int i, float x);
int performMore(String s);
}


Now after some time , you want to add a third method to "TaskHandler", so that the interface now becomes:

public interface TaskHandler{
void performSomething(int i, float x);
int performMore(String s);
boolean willYouPerform(int i, float x, String s);
}


Points to be noted:

If you make this change, all classes that implement the old TaskHandler
interface will break because they don't implement all methods of
the the interface now.

Solution :
Create one more interface OtherTaskHandler that extends TaskHandler interface

public interface OtherTaskHandler extends TaskHandler {
boolean willYouPerform(int i, float x, String s);
}


Now Its up to users, he/she can choose to continue to use the old interface or to upgrade to the new interface.