Wednesday, August 18, 2010

UDH in Binary SMS / Multipart SMS messsages

Multipart SMS messaging

By design, SMS is developed to send up to 140 bytes of user data. All user data is send in the 'User Data' part of the SMS packet. Because SMS text messages are encoded using 7-bit characters you can send up to 160 characters in a single SMS message. When sending Unicode text, you can only send 70 characters per single SMS message.
It is however possible to split up text and data messages and send them using multiple SMS messages. The receiving party will be able to combine the messages to the original message. This is called Segmentation and Reassembly (SAR). When sending multipart SMS messages you will be charged for every single SMS message sent.

Sending Multipart Messages through a GSM phone or modem

To send enhanced content, a so called user data header (UDH) is added add the beginning of the user data block of the SMS. When using an UDH, there is less data left for user data in the User Data field (140 - length of UDH).
An UDH can be used to send multipart messages, smart messaging (ringtones, WAP push, pictures etc), voicemail indications and other services. In this article we will only discuss the use of UDH to send multipart text messages.
The UDH for message concatenation will only take 5 bytes, so there are 135 bytes left for the user data. When sending concatenated text messages, you can send 153 characters when using 7-bit text, when using Unicode 67 characters per part.

Byte Value Description
01 00 Information Element Identifier: Concatenated short message, 8bit reference number
02 03 Information Element Data Length (always 03 for this UDH)
03 A4 Information Element Data: Concatenated short message reference, should be same for all parts of a message
04 03 Information Element Data: Total number of parts
05 01 Information Element Data: Number of this part (1/3)
Example of a multipart message consisting of 3 parts containing 300 bytes:
SMS 1 User Data: 00 03 A4 03 01 [ 135 bytes of message data ]
SMS 2 User Data: 00 03 A4 03 02 [ 135 bytes of message data ]
SMS 3 User Data: 00 03 A4 03 03 [   30 bytes of message data ]
Source and Full Info

User Data Header (UDH)

The SMS that make up a concatenated SMS are related together by using the User Data Header (UDH) of an SMS. The UDH is a collection of bytes which can be put at the start of the SMS content. It can be used to control what happens to the rest of the content. For instance, it was used to send the older style of Nokia picture messages.
To indicate that the content contains a UDH, a flag on the SMS called the UDH Indicator (UDHI) must be turned on. This tells the phone that it must separate the UDH from the rest of the content.



Figure:Format of an SMS with a UDH
The phone separates the UDH by reading the first byte of the content. The number in this byte is the length of the rest of UDH and is called the User Data Header Length (UDHL). The phone then knows how many bytes make up the UDH and can separate it from the rest of the message.
As already stated, a UDH can control various things and so can contain various commands. These commands are called Information Elements (IE's). These IE's always take the following format: an Identity Element Identifier (IEI) followed by the Length of the IE Data (IEDL) followed by the IE Data (IED). A UDH can contain 1 or more of these IE's.

Resources
1)Parameters with Definitions for Sending SMS and MMS

2)Sending Binary Messages using NowSMS

Monday, July 12, 2010

JAVA Composition vs Aggregation

Association - it's a structural relationship between two classifiers i.e. classes or Use cases.
An Association specifies how objects are related to one another.
Aggegation & Composition are associations with following  qualities.

Aggegation is normally understood as a "has-a" relationship.
Here both the entities continue to have their own independent existence.
Aggregations are not allowed to be circular - that is, an object can not be "a part of itself".

Composition is normally understood as a "contains-a" relations.
It depicts a Whole-part relationship and the 'part' entity doesn't have its own independent existence.
Adds a lifetime responsibility to Aggregation.

  • In case of Aggregation, both the entities will continue to have their independent existence whereas in case of Composition the lifetime of the entity representing 'part' of the "whole-part" is governed by the entity representing 'whole'.

  • Aggregation represents a loose form of relationship as compared to that represented by Composition which depicts a stronger relationship.

  • Example:
    An Employ can have Cabin(seating arrangement) and Food preferences.
    Cabin can exist without employ ie Aggegation
    Food Preferences of employ  cannot exist without employ as they are specific to that employ object -- Composition

    Sources

    Composition vs Aggregation. How is Association related to them?

    Association Vs Aggregation Vs Composition   


    Lables: JAVA FAQ,Aggregation,Composition,
    Association

    Tuesday, June 15, 2010

    Why we need MVC framework?


    Why we need MVC framework?

    Web applications differ from conventional websites in that web applications can create a dynamic response. Many websites deliver only static pages. A web application can interact with databases and business logic engines to customize a response.

    Web applications based on JavaServer Pages sometimes commingle database code, page design code, and control flow code. In practice, we find that unless these concerns are separated, larger applications become difficult to maintain.

    One way to separate concerns in a software application is to use a Model-View-Controller (MVC) architecture. The Model represents the business or database code, the View represents the page design code, and the Controller represents the navigational code.

    The Struts framework is designed to help developers create web applications that utilize a MVC architecture.
    In Struts 2, MVC are implemented by the action, result, and FilterDispatcher.

    Resources for  Struts MVC

    Spring's Web MVC framework is designed around a DispatcherServlet  that dispatches requests to handlers, with configurable handler mappings, view resolution, locale and theme resolution as well as support for upload files.

    Resources for  Spring MVC

    Tuesday, April 13, 2010

    Formatting(Precision) Java Double /Float Decimal Digits

    Formatting( Precision ) Java Double Decimal Digits

    Formatters converts a floating point/double value  to a string  with a specified number  of decimals.

    For formatting the decimal part of double/Float we can use NumberFormat or DecimalFormat .

    The difference between them is that
            NumberFormat is an abstract class.
            DecimalFormat is a concrete implementation of NumberFormat.

    Using NumberFormat:

    NumberFormat is the abstract base class for all number formats. This class provides the interface for formatting and parsing numbers. NumberFormat also provides methods for determining which locales have number formats, and what their names are.
    Number formats are generally not synchronized. It is recommended to create separate format instances for each thread. If multiple threads access a format concurrently, it must be synchronized externally. 

        NumberFormat nfrmtr = NumberFormat.getNumberInstance();
        nfrmtr.setGroupingUsed(false);
        nfrmtr.setMaximumFractionDigits(2);
        nfrmtr.setMinimumFractionDigits(2);
        double dval = 0.0;
        System.out.println(nfrmtr.format(dval));

    Using DecimalFormat:

    DecimalFormat is a concrete subclass of NumberFormat that formats decimal numbers. It has a variety of features designed to make it possible to parse and format numbers in any locale, including support for Western, Arabic, and Indic digits. It also supports different kinds of numbers, including integers (123), fixed-point numbers (123.4), scientific notation (1.23E4), percentages (12%), and currency amounts ($123). All of these can be localized. 

    As DecimalFormat is implementing NumberFormat Class we can use the functions available in NumberFormat.

        DecimalFormat dfrmtr = new DecimalFormat("###.##");
        double dval = 0.0;
        System.out.println(dfrmtr.format(dval));     

    Sample Program :

    import java.text.DecimalFormat;
    import java.text.NumberFormat;

    public class DecimalFormatter {
        public static void main(String srgs[]){
       
            DecimalFormat dfrmtr = new DecimalFormat("###.##");

            NumberFormat nfrmtr = NumberFormat.getNumberInstance();
            nfrmtr.setGroupingUsed(false);
            nfrmtr.setMaximumFractionDigits(2);
            dfrmtr.setMinimumFractionDigits(2);
           
            double dval = 0.0;
            for (int i = 0; i < 10; i++)
            {
                dval += 0.111;
                System.out.println(dval+" "+dfrmtr.format(dval)+"  "+nfrmtr.format(dval));           
            }
        }
    }

    Source NumberFormat
    Source DecimalFormat

    Thursday, February 18, 2010

    Parameter retrieval from JSP with multipart/form-data

    javax.servlet.HttpServletRequest.getParameter(String) returns null
    when the ContentType is multipart/form-data


    Solution A:


    invoke getParameters() on com.oreilly.servlet.MultipartRequest
    You can get files from here

    Solution B:

    1. download Jar file from here
    2. invoke readHeaders() in org.apache.commons.fileupload.MultipartStream
    JSP Example program  here

    Solution C:


    invoke getParameter on com.bigfoot.bugar.servlet.http.MultipartFormData

    Solution D:

    Use Struts. Struts 1.1 handles this automatically.

    Reference: jGuru 

    Friday, January 29, 2010

    Comparison of Java ==, .equals(), compareTo(), and compare()

    Source & Full Article


    When you really need to know if two references are identical, use ==. But when you need to know if the objects themselves (not the references) are equal, use the  equals() method.


    If you don't override a class's equals() method, you won't be able to use those objects as a key in a hashtable and you probably won't get accurate Sets, such that there are no conceptual duplicates.


    Equality comparison: One way for primitives, Four ways for objects



    Comparison Objects
    a == b, a != b
    Compares references, not values. The use of == with object references is generally limited to the following:
    • Comparing to see if a reference is null.
    • Comparing two enum values. This works because there is only one object for each enum constant.
    • You want to know if two references are to the same object
    a.equals(b)
    Compares values for equality. Because this method is defined in the Object class, from which all other classes are derived, it's automatically defined for every class. However, it doesn't perform an intelligent comparison for most classes unless the class overrides it. It has been defined in a meaningful way for most Java core classes. If it's not defined for a (user) class, it behaves the same as ==.
    It turns out that defining equals() isn't trivial; in fact it's moderately hard to get it right, especially in the case of subclasses. The best treatment of the issues is in Horstmann's Core Java Vol 1. [TODO: Add explanation and example]
    a.compareTo(b)
    Comparable interface. Compares values and returns an int which tells if the values compare less than, equal, or greater than. If your class objects have a natural order, implement the Comparable<T> interface and define this method. All Java classes that have a natural ordering implement this (String, Double, BigInteger, ...).
    compare(a, b)
    Comparator interface. Compares values of two objects. This is implemented as part of the Comparator<T>sort() or for use by sorting data structures such as TreeMap and TreeSet. You might want to create a Comparator object for the following. interface, and the typical use is to define one or more small utility classes that implement this, to pass to methods such as
    • Multiple comparisons. To provide several different ways to sort something. For example, you might want to sort a Person class by name, ID, age, height, ... You would define a Comparator for each of these to pass to the sort() method.
    • System class. To provide comparison methods for classes that you have no control over. For example, you could define a Comparator for Strings that compared them by length.
    • Strategy pattern. To implement a strategy pattern, which is a situation where you want to represent an algorithm as an object that you can pass as a parameter, save in a data structure, etc.
    If your class objects have one natural sorting order, you may not need this.

    Thursday, January 21, 2010

    Java 2 Platform, Enterprise Edition (J2EE) FAQ

    What is the Java 2 Platform, Enterprise Edition (J2EE)?
    The Java 2 Platform, Enterprise Edition (J2EE) is a set of coordinated specifications and practices that together enable solutions for developing, deploying, and managing multi-tier server-centric applications. Building on the Java 2 Platform, Standard Edition (J2SE), the J2EE platform adds the capabilities necessary to provide a complete, stable, secure, and fast Java platform to the enterprise level. It provides value by significantly reducing the cost and complexity of developing and deploying multi-tier solutions, resulting in services that can be rapidly deployed and easily enhanced.
    What are the main benefits of the J2EE platform?
    The J2EE platform provides the following:
    • Complete Web services support. The J2EE platform provides a framework for developing and deploying web services on the Java platform. The Java API for XML-based RPC (JAX-RPC) enables Java technology developers to develop SOAP based interoperable and portable web services. Developers use the standard JAX-RPC programming model to develop SOAP based web service clients and endpoints. A web service endpoint is described using a Web Services Description Language (WSDL) document. JAX-RPC enables JAX-RPC clients to invoke web services developed across heterogeneous platforms. In a similar manner, JAX-RPC web service endpoints can be invoked by heterogeneous clients. For more info, see http://java.sun.com/webservices/.
    • Faster solutions delivery time to market. The J2EE platform uses "containers" to simplify development. J2EE containers provide for the separation of business logic from resource and lifecycle management, which means that developers can focus on writing business logic -- their value add -- rather than writing enterprise infrastructure. For example, the Enterprise JavaBeans (EJB) container (implemented by J2EE technology vendors) handles distributed communication, threading, scaling, transaction management, etc. Similarly, Java Servlets simplify web development by providing infrastructure for component, communication, and session management in a web container that is integrated with a web server.
    • Freedom of choice. J2EE technology is a set of standards that many vendors can implement. The vendors are free to compete on implementations but not on standards or APIs. Sun supplies a comprehensive J2EE Compatibility Test Suite (CTS) to J2EE licensees. The J2EE CTS helps ensure compatibility among the application vendors which helps ensure portability for the applications and components written for the J2EE platform. The J2EE platform brings Write Once, Run Anywhere (WORA) to the server.
    • Simplified connectivity. J2EE technology makes it easier to connect the applications and systems you already have and bring those capabilities to the web, to cell phones, and to devices. J2EE offers Java Message Service for integrating diverse applications in a loosely coupled, asynchronous way. The J2EE platform also offers CORBA support for tightly linking systems through remote method calls. In addition, the J2EE platform has J2EE Connectors for linking to enterprise information systems such as ERP systems, packaged financial applications, and CRM applications.
    • By offering one platform with faster solution delivery time to market, freedom of choice, and simplified connectivity, the J2EE platform helps IT by reducing TCO and simultaneously avoiding single-source for their enterprise software needs.
    What technologies are included in the J2EE platform?
    The primary technologies in the J2EE platform are: Java API for XML-Based RPC (JAX-RPC), JavaServer Pages, Java Servlets, Enterprise JavaBeans components, J2EE Connector Architecture, J2EE Management Model, J2EE Deployment API, Java Management Extensions (JMX), J2EE Authorization Contract for Containers, Java API for XML Registries (JAXR), Java Message Service (JMS), Java Naming and Directory Interface (JNDI), Java Transaction API (JTA), CORBA, and JDBC data access API.


    For Source & more FAQs  sun.com