Sabado, Enero 26, 2013

Hello World in J2ME : From Development to Deployment


Scope of Article
This article is intended for J2ME beginners and steps through every process of developing a MIDP compatible MIDlet. It is assumed that the reader has sufficient knowledge of general Java development using J2SE.




Java’s Original Promise
In the beginning Java was intended as a programming language that would power devices ranging from toasters to servers. This did not happen at first, but nearly a decade later Java found its way onto the mobile phones of millions of people and proved for the most part its ability to allow developers to “Write Once Run Anywhere”.
With this solid footing Java continues attempting to make inroads into other problem domains.

Java Mobile Edition Training

Do you want to learn Java Programming and its technologies? Having problems with your Java Certification Exam? You want to enhance your skill in Java Programming so it will help boost your career in the Programming? Here’s the answer to all of your problems pertaining to Java. Avail of the comprehensive Java Training of Prof. Erwin M. Globio and it will surely help you a lot about Java Programming and Development and be the first to know the secrets of Java Programming and its technologies. 

For more free information about Java Programming visit the following sites:http://erwinglobio.sulit.com.phhttp://javatraining.multiply.com/;http://erwinglobio.wordpress.com/http://twitter.com/trainjava. To avail of the comprehensive Java Training of Prof. Erwin Globio, you can call the numbers: 09393741359 and 09323956678. Call now and learn the secrets of Java Programming at 09393741359 and 09323956678. Java Training Philippines

class IntClass


class IntClass

The class IntClass is similar to the class Integer, but is not immutable.  The class DoubleClass is identical to IntClass, except that it deals with double values instead of int values.




Java Workshop Manila

Primitive Data Types and the Wrapper Classes


Primitive Data Types and the Wrapper Classes

Java provides the classes Integer, Double, Character, Long, and Float so that values of primitive data types can be treated as objects. These classes are calledwrappers. They wrap primitive type values. However, these classes have limitations that have to be followed.  You can create objects of the type, Integer, to store int values, but you cannot change the value stored in the objects. Parameter passing is a fundamental concept in any programming language.  Therefore, we have created the classes IntClass and DoubleClass, which are similar to the classes Integer and Double, respectively. You can create objects of the type IntClass and/or DoubleClass, store, and/or change values of the objects. 


The data members and methods in this class are:

data member: int x;
public IntClass()
public IntClass(int num)
public void setNum(int num)
public int getNum()
public void addToNum(int num)
public void multiplyToNum(int num)
public int compareTo(int num)
public Boolean equals(int num)
public String toString()

As of J2SE 5.0, Java has simplified the wrapping and unwrapping of primitive type values, called the autoboxing and auto-unboxing of primitive types.  An example of autoboxing is as follows:

            int x;
            Integer num;
            num = 25;

The third statement is equivalent to the statement
           
            Num = new Integer( 25 );

This is an example of autoboxing.

An example of auto-unboxing is:

            x = num;

This is equivalent to the statement
           
            x = num.intValue();

Teaching Tip

More information on autoboxing can be found at:

Teaching Tip

A listing of all of the wrapper classes in the java.lang package can be found at:

A Simplified OOD Methodology


A Simplified OOD Methodology

A simplified OOD methodology can be expressed in the following steps:

1.      Write down a detailed description of the problem.

2.      Identify all (relevant) nouns and verbs.

3.      From the list of nouns, select objects. Identify data components of each object.

4.      From the list of verbs, select the operations.

In order to create objects you first need to create classes. To know what type of classes to create, you need to know what an object stores and what operations are needed to manipulate an object’s data.  Because an object consists of data and operations on data in a single unit, in Java we use the mechanism of classes to combine data and its operations in a single unit. In OOD methodology, classes, data members of classes (known as fields), and operations are identified.

Teaching Tip

More information on Object-Oriented Design can be found at:


Implementing Classes and Operations

Once the relevant classes, data members of each class, and relevant operations for each class are identified, the next step is to implement these things in Java. 

In Java, to implement operations we write algorithms. Since there is usually more than one operation on an object, each algorithm is implemented with the help of Java’s methods.  However, Java does not provide all the methods that you will ever need. Therefore, to learn how to design and implement classes, you first must learn how to construct and implement your own methods.

Object-Oriented Design (OOD)


Object-Oriented Design

The aim of OOD is to build software from components called classes so that if someone wants to use a class, all they need to know is the various methods provided by that class. 

An object combines data and operations on that data in a single unit, a feature called encapsulation.  In OOD, the object is identified first, then the relevant data is identified, and finally the operations needed to manipulate the object are identified.

The aim of OOD is to build software from components called classes so that if someone wants to use a class, all they need to know is the various methods provided by that class. 

An object combines data and operations on that data in a single unit, a feature called encapsulation.  In OOD, the object is identified first, then the relevant data is identified, and finally the operations needed to manipulate the object are identified.

JButton: Handling an Event


Handling an Event

When you click a JButton an event is created, known as an action event, which sends a message to another object, known as an action listener. When the listener receives the message, it performs some action. Sending a message or an event to a listener object simply means that some method in the listener object is invoked with the event as the argument. This invocation happens automatically; you will not see the code corresponding to the method invocation. However, you must specify two things:

  • For each JButton, you must specify the corresponding listener object. In Java, this is known as registering the listener.

  • You must define the methods that will be invoked when the event is sent to the listener. Normally, you will write these methods and you will never write the code for invocation.

Java provides various classes to handle different kinds of events. The action event is handled by the class ActionListener.  The class ActionListener contains the method actionPerformed, which includes the code the system is to execute when an action event is generated.

The class ActionListener that handles the action event is a special type of class called an interface.  An interface contains only the methods headings; each methods heading is terminated with a semicolon.

Because the method actionPerformed does not contain a body, you cannot instantiate an object of the type ActionListener.  One way to register an action listener with an object is to create a class on top of ActionListener so that the required object can be instantiated. The class created must provide the necessary code for the method actionPerformed.  The interface ActionListener is contained in the package java.awt.event.

Teaching Tip

Tutorials regarding how to write various types of listeners, including ActionListeners, can be found at: