Download as docx, pdf, or txt
Download as docx, pdf, or txt
You are on page 1of 28

UNIT – 2

PART B
1) Give the list of attribute of manifest file and explain in detail?
Inside the Java Archive File:

 All the files necessary to implement a MIDlet suite must be contained within a
production package called a Java archive (JAR) file. These files include MIDlet classes,
graphic images (if required by a MIDlet), and the manifest file. The manifest file contains
a list of attributes and related definitions that are used by the application manager to
install the files contained in the JAR file onto the small computing device. Nine attributes
are defined in the manifest file; all but six of these attributes are optional.

 The manifest file’s extension is changed to .mf when the MIDlet is prepared for
deployment.
MIDlet-Name: Best MIDlet
MIDlet-Version: 2.0
MIDlet-Vendor: MyCompany
MIDlet-1: BestMIDlet, /images/BestMIDlet.png, Best.BestMIDlet
MicroEdition-Profile: MIDP-1.0
MicroEdition-Configuration: CLDC-1.0

 The MIDlet-n attribute can contain three values that describe the MIDlet. A comma
Separates each value. The first value is the name of the MIDlet, which is BestMIDlet.
Next is an optional value that specifies the icon that will be used with the MIDlet. In
this example, BestMIDlet.png is the icon. The icon must be in the PNG image format.
And the last value for the MIDlet-n attribute is the MIDlet class name, which is
Best.BestMIDlet. The application manager uses the class name to load the MIDlet.

2) Draw the J2ME architecture and explain each layer?


J2ME Architecture:

 The modular design of the J2ME architecture enables an application to be scaled based on constraints of a small
computing device. J2ME architecture consists of layers located above the native operating system, collectively
referred to as the Connected Limited Device Configuration (CLDC). The CLDC, which is installed on top of the
operating system, forms the run-time environment for small computing devices. The J2ME architecture comprises
three software layers (Figure 3-1). The first layer is the configuration layer that includes the Java Virtual Machine
(JVM), which directly interacts with the native operating system. The configuration layer also handles interactions
between the profile and the JVM. The second layer is the profile layer, which
consists of the minimum set of application programming interfaces (APIs) for the small computing device. The third
layer is the Mobile Information Device Profile (MIDP). The MIDP layer contains Java APIs for user network
connections, persistence storage, and the user interface. It also has access to CLDC libraries and MIDP libraries.

 A small computing device has two components supplied by the original equipment manufacturer (OEM). These
are classes and applications. OEM classes are used by the MIDP to access device-specific features such as sending
and receiving messages and accessing device-specific persistent data. OEM applications are programs provided by
the OEM, such as an address book.
Ø The design of j2me architecture provides the scalability to an application based on
the constraints of the small computing devices.
Ø J2me architecture does not replace the operating system of small computing devices
Ø
J2me architecture consists of layers located above the native operating system.

Three layers
1. Configuration layer- includes the jvm, which interacts the operating system. and also
interacts the profiles and jvm.
2. Profile layer- it provides the java API used to implement the applications for the
small computing devices.
3. MIDP- provides classes for the network connections, user interface and persistent
storage.
small computing devices has two components provided by the original equipment
manufacturers.
1. OEM classes- these are used by the MIDP to access the features of the specific
device such as sending and receiving messages and access persistent storage.
2. OEM applications- these can be accessed by the MIDP such as address book.
Note:- these components are not portable since all the small computing devices does
not use the same OEM classes and OEM applications.

3) Explain the process of Designing images viewer class?


ImageView in Android with Example
ImageView class is used to display any kind of image resource in the android application either it
can be android.graphics.Bitmap or android.graphics.drawable.Drawable (it is a general
abstraction for anything that can be drawn in Android). ImageView class
or android.widget.ImageView inherits the android.view.View class which is the subclass of
Kotlin. AnyClass.Application of ImageView is also in applying tints to an image in order to reuse
a drawable resource and create overlays on background images. Moreover, ImageView is also used
to control the size and movement of an image.

Adding an ImageView to an Activity

Whenever ImageView is added to an activity, it means there is a requirement for an image


resource. Thus it is oblivious to provide an Image file to that ImageView class. It can be done by
adding an image file that is present in the Android Studio itself or we can add our own image file.
Android Studio owns a wide range of drawable resources which are very common in the android
application layout. The following are the steps to add a drawable resource to the ImageView class.
For adding an image from Android Studio, Drag the ImageView widget to the activity area of the
application, a pop-up dialogue box will open choose from the wide range of drawable resources and
click “OK“.
For Adding an Image File other than Android Studio Drawable Resources:
Click on the “Resource Manager” tab on the leftmost panel and select the “Import Drawables”
option. 
Select the path of the image file on your computer and click “OK“. After that set, the “Qualifier
type” and “value” of the image file according to your need and click “Next” then “Import“.
Drag the ImageView class in the activity area, a pop-up dialogue box will appear which contains
your imported image file. Choose your image file and click “OK“, your image will be added to the
activity. 
Note: After adding an image set its constraints layout both vertically and horizontally otherwise it
will show an error.
XML Attribute Description

android:id To uniquely identify an image view

android:src/app:srcCompat To add the file path of the inserted image

android:background To provide a background color to the inserted image

android:layout_width To set the width of the image

android:layout_height To set the height of the image


XML Attribute Description

To add padding to the image from the left, right, top, or bottom of
android:padding the view

android:scaleType To re-size the image or to move it in order to fix its size

Step by Step Implementation


Step 1: Create a New Project
To create a new project in Android Studio please refer to How to Create/Start a New Project in
Android Studio. The code has been given in both Java and Kotlin Programming Language for
Android.
Step 2: Working with the activity_main.xml FileWorking with the activity_main.xml File
Go to the activity_main.xml File and refer to the following code. Below is the code for
the activity_main.xml File.
Navigate to the app > res > layout > activity_main.xml and add the below code to that file.
Below is the code for the activity_main.xml file. 
 XML
<?xml version="1.0" encoding="utf-8"?>

<androidx.constraintlayout.widget.ConstraintLayout 

    xmlns:android="http://schemas.android.com/apk/res/android"

    xmlns:app="http://schemas.android.com/apk/res-auto"

    xmlns:tools="http://schemas.android.com/tools"

    android:layout_width="match_parent"

    android:layout_height="match_parent"

    tools:context=".MainActivity">

  

    <ImageView

        android:id="@+id/GfG_full_logo"

        android:layout_width="0dp"

        android:layout_height="wrap_content"

        app:layout_constraintBottom_toBottomOf="parent"
        app:layout_constraintEnd_toEndOf="parent"

        app:layout_constraintStart_toStartOf="parent"

        app:layout_constraintTop_toTopOf="parent"

        app:layout_constraintVertical_bias="0.078"

        app:srcCompat="@drawable/full_logo" />

  

    <ImageView

        android:id="@+id/GfG_logo"

        android:layout_width="wrap_content"

        android:layout_height="wrap_content"

        app:layout_constraintBottom_toBottomOf="parent"

        app:layout_constraintEnd_toEndOf="parent"

        app:layout_constraintStart_toStartOf="parent"

        app:layout_constraintTop_toBottomOf="@+id/
GfG_full_logo"

        app:srcCompat="@drawable/logo" />

</androidx.constraintlayout.widget.ConstraintLayout>

Note: All the attributes of the ImageView which are starting with app:layout_constraint are the
vertical and horizontal constraints to fix the image position in the activity. This is very necessary
to add the constraint to the ImageView otherwise, all the images will take the position (0, 0) of the
activity layout.  
Step 4: Working with the MainActivity File
Go to the MainActivity file and refer to the following code. Below is the code for
the MainActivity file. Since in the activity, only 2 images have been added and nothing else is
being done like touching a button, etc. So, the MainActivity file will simply look like the below
code i.e. no change. 
 Java
 Kotlin
import androidx.appcompat.app.AppCompatActivity;

import android.os.Bundle;

  
public class MainActivity extends AppCompatActivity {

    

    @Override

    protected void onCreate(Bundle savedInstanceState) {

        super.onCreate(savedInstanceState);

        setContentView(R.layout.activity_main);

    }

Output: 

4)Write about J2ME Software Development kits?


J2ME Software Development Kits:

A MIDlet is built using free software packages that are downloadable from the java.sun .com
web site, although you can purchase third-party development products such as Borland JBuilder
Mobile Set, Sun One Studio 4 (formerly Forte for Java), and WebGain VisualCafe Enterprise
Suite. Three software packages need to be downloaded from java.sun.com. These are the Java
Development Kit (1.3 or greater) (java.sun.com/ j2se/downloads.html), Connected Limited Device
Configuration (CLDC) (java.sun. com/products/cldc/), and the Mobile Information Device Profile
(MIDP) (java.sun.com/ products/midp/).First, install the Java development kit. The Java
development kit contains the Java compiler and the jar.exe, which is used to create Java archive
files. After downloading the Java development kit package, unzip the package and run the
installation program. It is best to accept the default directory, although you are free to choose a
different directory for the Java development kit. Once the Java development kit is installed, place
the c:\jdk\bin directory, or whatever directory you selected for the Java development kit, on the
PATH environment variable (see ―Setting the Path in Windows‖ sidebar). This enables you to
invoke the Java compiler from anywhere on your computer.

 Install the CLDC once the Java development kit is installed. Unzip the downloaded CLDC files from
the java.sun.com web site onto the d:\j2me directory (J2ME_HOME) on your computer.
Unzipping the CLDC package creates the j2me_cldc subdirectory below the j2me directory. The
j2me_cldc has a bin subdirectory that contains the K Virtual Machine and the preverifier
executable files for an assortment of platforms such as win32. Each platform is in its own
subdirectory under j2me_cldc. Add the j2me\j2me_cldc\bin\win32 subdirectory to the PATH environment
variable (see ―Setting the Path in Windows‖. Next, download and unzip the MIDP file. Be sure to use \j2me as the
directory for the MIDP file. Unzipping the MIDP file creates a midp directory. The name of this directory might
vary depending on the version that you download. Some versions create a midp-fcs directory, while the 1.0.3
version creates a %J2ME_HOME%\ midp1.0.3fcs directory. Next, create two environment variables. These are
CLASSPATH and MIDP_HOME. The CLASSPATH environment variable identifies the path to be searched whenever
a class is invoked. The MIDP_HOME environment variable identifies the location of the \lib directory that contains
the internal.config file and the system.config file. Set the CLASSPATH to d:\j2me\midp1.0.3fcs\classes;. Set the
MIDP_HOME environment variable to d:\j2me\midp1.0.3fcs.
5) Explain J2ME user interfaces?

MIDP User Interface APIs:


The MIDP user interface API is divided into a high-and low-level API. The high-level API provides input
elements such as text fields, choices, and gauges. In contrast to the Abstract Windows Toolkit (AWT),
the high-level components cannot be positioned or nested freely.

There are only two fixed levels: Screens and Items. The Items can be placed in a Form, which is a
specialized Screen. The high-level Screens and the low-level class Canvas have the common base
class Displayable. All subclasses of Displayable fill the whole screen of the device. Subclasses of
Displayable can be shown on the device using the setCurrent() method of the Display object. The
display hardware of a MIDlet can be accessed by calling the static method getDisplay(), where the
MIDlet itself is given as a parameter.
A user interface is a set of routines that displays information on the screen, prompts the user to
perform a task, and then processes the task.

Ex: J2ME email application: list of menu options, such as Inbox, Compose, and Exit, and then prompt
the user to make a selection by moving the cursor keys and pressing a key on the small computing
device.

Three kinds of User Interfaces

 Command

 Form

 Canvas

Command User interface


 A command-based user interface consists of instances of the Command class.

 An instance of the Command class is a button that the user presses on the device to
enact a specific task.

For example, Exit, Help etc

 Exit and Help are instances of the Command Class‘s associated with an Exit button
and Help button on the keypad to terminate the application and link the Help key
whenever the user requires assistance.

Form User Interface


 A form-based user interface consists of an instance of the Form class that contains
instances derived from the Item class such as text boxes, radio buttons, check boxes,
lists, and other conventions used to display information on the screen and to collect
input from the user.

 A form is similar to an HTML form.

Canvas User Interface


 A canvas-based user interface consists of instances of the Canvas class within
which the developer creates images such as those used in a game.

6) Write multiple MIDlet as distributed in a single MIDlet Suite. For


Example manager then displays each MIDlet as a menu option,
enabling the user to run one of the MIDlet.Also create another
MIDlet to illustrate how to deploy a multiple MIDlet Suite?
7) Explain about the J2ME Wireless toolkit?

J2ME Wireless Toolkit


 J2ME Wireless Toolkit that is downloadable from

java.sun.com/products/j2mewtoolkit/download.html.

 It is used to develop and test J2ME applications by selecting a few buttons from a
toolbar.

 J2ME Wireless Toolkit is a stripped-down integrated development environment in


that it does not include an editor, a full debugger, and other amenities found in a third-
party integrated development environment.

 Building and Running a Project.

 Ktoolbar is the executable within the directory that launches the Toolkit. The main
window is displayed when you run ktoolbar
Step – 1:create a new project or open existing project.
Step -2 : Enter the project name and class name of the first MIDLET to begin the project.
Step- 3: click the ok button on entering MIDlet Details

Step -4: Click ok

Step- 5: go to the project (MIDlet suite) to which you added MIDlets and open the manifest file in the
bin folder.

MIDlet-1: ExampleTb, ExampleTb.png, ExampleTb

MIDlet-2: MidletLifecycle, MidletLifecycle.png,

MidletLifecycle

MIDlet-Name: TextBoxEx

MIDlet-Vendor: Unknown

MIDlet-Version: 1.0

MicroEdition-Configuration: CLDC-1.0

MicroEdition-Profile: MIDP-2.0

Step- 6 : place MIDlets in the src folder of the MIDlet Suite

step – 7: build the project


step- 8: run project
Features of the Wireless Toolkit
The KToolbar, included with the J2ME Wireless Toolkit, is a minimal development environment with a Graphical User Interface
(GUI) for compiling, packaging, and executing MIDP applications. The only other tools you need are a third-party editor for your
Java source files and a debugger.

An IDE compatible with the J2ME Wireless Toolkit, such as the Sun™ Open Net Environment (Sun ONE) Studio IDE, provides
even more convenience. For example, when you use the Wireless Toolkit within an IDE, you can edit, compile, package, and
execute or debug MIDP applications, all within the same environment. For a list of IDEs that are compatible with the Wireless
Toolkit, see the Java™ 2 Platform, Micro Edition, Wireless Toolkit web page at http://java.sun.com/products/j2mewtoolkit/.

When working with the J2ME Wireless Toolkit in standalone mode, you work mainly through the KToolbar. The features available
to help you create, modify, and test your MIDlet suite are described briefly in the following sections.
Compiling, Preverifying, and Debugging

When you compile MIDlets through the KToolbar (or an IDE compatible with the toolkit), your source files are compiled using the
Java™ 2 Platform, Standard Edition (J2SE™) SDK compiler. Preverification of the compiled files is done with the Preverifier that
prepares class and JAR files and class directories. Preverification takes place automatically for you immediately after compilation.
You can debug applications within the environment using the Emulator, which simulates the execution of the application on
various devices. For more information on how to compile, preverify, and debug files using KToolbar, see Chapter 3, “Operating
with KToolbar.”

Packaging

You can package your MIDlet suite from the KToolbar or with a compatible IDE. The KToolbar gives you the choice of creating a
standard package or creating an obfuscated package that produces a smaller JAR file by reducing the size of the classes in the
suite through the obfuscation process.

For more information on packaging and obfuscated packaging, see Chapter 2, “Developing and Running Applications.” For
information on how to package applications using the KToolbar, see Chapter 3, “Operating with KToolbar.”

Running MIDlet Suites

Running a MIDlet suite on the emulator can be done either locally (running directly from the classpath without packaging) to see
the application perform immediately after a build or remotely through Over-The-Air (OTA) provisioning (emulation of the
application provisioning and installation from the server to the device).

For a description on different ways to run your application, see Chapter 2, “Developing and Running Applications.” For information
on testing your applications with OTA provisioning or remotely from a web server, see Chapter 8, “Testing Application
Provisioning.”

Authenticating and Authorizing MIDlets

You can create trusted applications that have permission to use protected APIs. You can request permission to access network
protocol APIs through the Project Settings dialog box from the KToolbar. You can sign your MIDlet suite and assign a security
domain that defines the suite’s authorization level with the Sign MIDlet Suite window.

For information on signing a MIDlet suite, see Chapter 6, “Using Security Features in the Wireless Toolkit.”

Performance Tuning

The Wireless Toolkit’s Profiler enables you to optimize the performance of your MIDlet suite by determining where bottlenecks
might be occurring during runtime. You can improve the execution time of your MIDlet suite by examining the time spent in
method calls, the number of times a method is called during runtime, and the amount of time a method runs compared to the
overall runtime of the application.

You can also adjust the performance speed of your application in the Performance panel of the Project Settings dialog box.
Setting the speed features does not demonstrate how your application would run on an actual device; however, by adjusting the
speed emulation parameters, you can achieve a better representational performance of your application on a device.

For information on how to use the Profiler and how to manage device speed, see Chapter 4, “Performance Tuning and Monitoring
Applications.”

Memory and Network Monitoring

The Wireless Toolkit provides you with tools to examine and analyze memory usage by your application and network
transmissions between your device and the network. You can get an overall view of memory usage during runtime of your
application and get a breakdown of memory usage per object to see where in the application you can optimize memory usage.
With the Network Monitor, you can examine network transmissions for several types of network protocols.

For information on how to use the Memory and Network Monitors, see Chapter 4, “Performance Tuning and Monitoring
Applications.”

Working With the Emulator

The J2ME Wireless Toolkit comes with a selection of emulated devices for you to run and test your applications on.
Representations of mobile devices are available from the Device list on the KToolbar. Java Technology for the Wireless Industry
defines the technologies to be included in compliant phones. These technologies include CLDC, MIDP, MMAPI, and WMA.

You can set the functionality for an emulated device through the Preferences window. You can also start various emulator utilities
such as the Profiler, the Network Monitor, the Memory Monitor, and the Certificate Manager from the Utilities window. For more
information on the Emulator, see Chapter 5, “Working With the Emulator.”

For information on examining applications that you develop that use network protocols or wireless messaging, see Chapter 4,
“Performance Tuning and Monitoring Applications.”

To test applications that use wireless messaging, the Wireless Toolkit provides the WMA console, which you can use to send and
receive binary and text SMS messages. You can also use the console to broadcast CBS messages to devices. For more
information about the WMA console, see Chapter 7, “Wireless Messaging with the Wireless Toolkit.”

Internationalization Features of the


Wireless Toolkit

You can run the Wireless Toolkit and display your application in your desired language by setting the locale properties of the
Wireless Toolkit and the Emulator. You can also change the character encoding setting for the device MIDP environment and for
the Java compiler. For more information on internationalization, see Appendix C, “Internationalization.”

Providing Access to J2ME Web Services

You can generate a stub connector to access J2ME Web Services from the KToolbar. The Emulator is compliant with the J2ME
Web Services specification. The Stub Generator is created using a Web Service Descriptor Language file (WDSL), provided by
the user. You can launch the stub generator from the KToolbar using the File menu’s Utilities option, from the Project menu, or
you can run it from the command line. See Appendix D, “Command Line Utilities” for more information

Operating From the Command-Line

Many of the basic development operations available from the KToolbar can also be performed at the command line such as
compiling and preverifying, creating manifest files, JAR and JAD files, running emulators, tracing and debugging, invoking the
Stub Generator, and using the Application Management System. You can also sign MIDlet suites and manage certificates from
the command line. See Appendix D, “Command Line Utilities” for more information.

8) Discuss about how multiple MIDlets are handled using MIDlet


suite with general scenario?
Multiple MIDlets in a MIDlet Suite
 add multiple MIDlets to the MIDlet Suite
 AMS displays the MIDlets in the menu option and enables the user to run one MIDlet
at a time.

 How to create MIDlet Suite


step-1: open sun_java_wireless toolkit and click on settings

Step-2: Click on MIDlets and click the add button

MIDlets and MIDlet Suites


Java applications that run on MIDP devices are known as MIDlets. A MIDlet consists
of at least one Java class that must be derived from the MIDP-defined abstract
class javax.microedition.midlet.MIDlet. MIDlets run in an execution environment
within the Java VM that provides a well-defined lifecycle controlled via methods of
the MIDlet class that each MIDlet must implement. A MIDlet can also use methods in
the MIDlet class to obtain services from its environment, and it must use only the
APIs defined in the MIDP specification if it is to be device-portable.
A group of related MIDlets may be collected into a MIDlet suite. All of the MIDlets
in a suite are packaged and installed onto a device as a single entity, and they can be
uninstalled and removed only as a group. The MIDlets in a suite share both static and
runtime resources of their host environment, as follows:
 At runtime, if the device supports concurrent running of more than one MIDlet,
all active MIDlets from a MIDlet suite run in the same Java VM. All MIDlets in the
same suite therefore share the same instances of all Java classes and other resources
loaded into the Java VM. Among other things, this means that data can be shared
between MIDlets, and the usual Java synchronization primitives can be used to
protect against concurrent access not only within a single MIDlet, but also between
concurrently executing MIDlets from the same suite.
 Persistent storage on the device is managed at the MIDlet ...

9) Discuss about J2ME best practices?


Best Practices:

 . Best practices are proven design and programming techniques used to build J2ME systems.
Patterns are routines that solve common programming problems that occur in such systems.
 Keep Applications Simple:
1. u must adapt to a new mind-set when creating applications for small computing devices because
of limited resources available and the inability to easily expand resources to meet application
requirements
 Keep Applications Small:
2. The size of your J2ME application is critical to deploying the application efficiently. The best
practice is to remove unnecessary components of your application in order to reduce the size of
the overall application.
 Limit the Use of Memory:
3. There are two types of memory management that should be used in the J2ME application. These
are overall memory management and peak time memory management. Overall memory
management is designed to reduce the total memory requirements of an application. Peak
memory management focuses on minimizing the amount of memory the application uses at times
of increased memory usage on the device. A primary way to reduce total memory requirements
of your application is to avoid using object types. Instead, use scalar types, which use less memory
than object types. Likewise, always use the minimum data type suited for storing data. A boolean
value requires less memory and therefore should be used in place of an int. This and similar data
management subtleties usually have little or no noticeable impact on a non-J2ME application. Peak
time memory management requires you to manage garbage collection. J2ME does have a garbage
collector, but as with J2SE, you don’t know when the garbage collector will collect your garbage.
 Off-Load Computations to the Server:
4. Small computing devices are designed to run applications that do not require intensive processing
because processing power common to desktop computers is not available on these devices. The
alternative is to build a client-service J2ME application or web services J2ME application. There are
two levels of operation in a client-service application. These are the client level and the server
level. The small computing device runs the client level that provides user interface and
presentation functionality to the application. The server-side level processes client requests and
returns the result to the small computing device for presentation to the user. There are three tiers
in web services. The first layer is the client tier, sometimes referred to as the presentation tier. This
is where a person interacts with an application. The second layer contains the business logic that is
used to fulfill requests from a client by calling appropriate software on the processing tier.
Processing software returns results to the business logic layer, and in turn, those results are
returned to the client for presentation to the user.

 Manage Your Application’s Use of a Network Connection:


5. Besides lightening the processing load on the small computing device, you must
also be concerned about the availability of a network connection. Some small
computing devices are mobile, wireless devices where a network connection is
not always available, and even when available, the connection might be broken
during transmission due to the positioning of the transmitter and
receiverCellular telephone networks use technology that attempts to maintain
connection as the mobile device moves from one cell to another cell.
 Simplify the User Interface:
6. Most desktop applications have a standard set of graphical user interface objects
such as text boxes, combo boxes, radio buttons, check boxes, and push buttons.
There is a standard display and input for desktop computers, but you cannot say
the same about small computing devices. The variety of shapes and hardware
configurations found in devices classified as small computing devices makes it
nearly impossible to standardize on a set of user interface objects for these
devices.
 Use Local Variables:
7. Limited resource is the theme that echoes through design considerations for
applications that run on small computing devices. Failure to seriously recognize
this theme will result in your application being unable to run on many small
computing devices. Therefore, it is critical to evaluate processing requirements
of each routine within your application. Data storage is a key area within an
application for reducing excessive processing. In many applications, developers
assign values to data members of a class rather than using a local variable.
Assigning data to a class member adheres to object-oriented design philosophy,
which is prevalent in application design.
 Don’t Concatenate Strings:
8. Concatenating strings is another processing drain that can be avoided by
designing an application to eliminate concatenations or at least reduce the
number of concatenations to the minimum necessary to achieve the objective of
the application. A string is an array of characters terminated by a NULL and
stored sequentially in memory. The application instructs the small computing
device to copy the first character of each string into the CPU for comparison. This
process continues until either the null character is reached or a letter pair is
different. The entire process might require ten reading instructions and five
comparison instructions, depending on when a mismatch is discovered.
 Avoid Synchronization:
9. It is very common for developers to invoke one or multiple threads within an
operation. Invoking a thread is a way of sharing a routine among other
operations. Each operation invokes the sort routine independent of other
operations, although the same code is being executed for all operations.
Deadlocks and other conflicts might arise when multiple operations use the
same routine.

Another way to increase performance is to avoid using synchronization where


possible. Synchronization requires additional processing steps that are not
necessary when synchronization is deactivated.
 Thread Group Class Workaround:
10. A common way of reducing the overhead of starting a new thread is to create a
group of thread objects that are assigned threads as needed by operations
within
an application. Grouping thread objects is made possible by the ThreadGroup
class, but J2ME does not support this class.
 Upload Code from the Web Server:
11. Version management is always a concern of application developers, especially
when applications are invoked from within a small computing device. It can be a
nightmare keeping track of various versions of an application once an application
is distributed.
 Reading Settings from JAD Files:
12. A good practice is to create a user-defined value within the JAD file rather than
within the manifest file because the JAD file can be modified without having to
repackage your application. A manifest file is a component of a package
 Populating Drop-down Boxes:
13. A drop-down box is a convenient way for users to choose an item from a list of
possible items, such as an abbreviation for a state. Traditionally, content of a
drop-down box is loaded from the data source once when the application is
invoked and remains in memory until the application terminates.
 Minimize Network Traffic:
14. A good practice is to off-load as much processing as is reasonable to a server and
minimize the number of processes that need to be invoked by the J2ME
application in order to reduce network transmissions. Collect all the information
from the user that is required by the process at one time, and then forward the
information to the server when invoking the process.
 Dealing with Time:
15. Desktop computers and servers are stationary, and therefore current time
reflects the time zone where these devices are located. The problem of time-
sensitive data is further compounded by the fact that the date/ time setting is
device dependent. The best practice is to always store time based on Greenwich
Mean Time (GMT) by using the getTime() method of the Date class.
 Automatic Data Synchronization:
16. Storage of data in a small computing device is temporary because the device
usually doesn’t have secondary storage. All data is stored in primary storage
(memory) and can be lost whenever the device loses power. Data is permanently
stored in secondary storage on a traditional computing device such as a desktop
computer or server. A good practice is to build into your J2ME application a
routine that automatically uploads the latest data when the J2ME application is
invoked.
 Updating Data that Has Changed:
Data can become outdated in two ways: when data changes on the small computing device and
when data changes on the secondary storage device, which is usually the server. A good practice is
to offer the user of your application three options for updating data: incremental updates, batch
updates, and full updates. Incremental updates require an exchange of data to occur whenever data
changes, either on the small computing device or on the secondary storage device. And only the
changed data is exchanged between devices. Performance decreases as the number of incremental
data changes occur because the changed data is transmitted following the modification of the data.
The batch update option eliminates the need for incremental updates by updating a batch of data
either periodically or on demand, controlled by the user of the application. A batch update only
transmits data that is changed by either the small computing device or the secondary storage
device.
 Be Careful of the Content of the startApp() Method:
17. Tips for Developing J2ME Applications
■ Applications are typically single-threaded.
■ One application runs at a time.
■ Applications are event driven.
■ Users change from one application to another rather than terminating an
application.
■ Mobile small computing devices are used intermittently.
■ Applications use multiple subscreens, each displaying only
relevant information.
■ Mobile small computing devices are typically used in two-minute sessions 30
times a day.
■ Applications must accomplish a task within two minutes; otherwise the user is
likely to turn off the mobile small computing device.
■ Limit user input to a few keystrokes. Develop a PC-based component of your
application that is used for data input.
■ Users want an instant response from an application.
■ Off-load processing to a server or desktop computer.
■ Avoid power-consuming tasks such as communications, animation, and sound.
■ Reduce data communication to the bare minimum because users pay for
transmission by byte, usually in the range of 50,000 to 300,000 bytes per month.
■ Preload as many files as possible into a mobile small computing device in order
to reduce data transmissions.
10) What is Midlet Suite and explain the life cycle of Midlet in detail.
MIDlet
What Does MIDlet Mean?
A MIDlet is an application that uses the mobile information device profile (MIDP) for
the Java Platform, Micro Edition (Java ME) environment. When Java was the most
widely used mobile platform, the MIDlet became the most ubiquitous of mobile
applications. In fac

t, MIDlets still exist in a majority of low-end feature phones.


Techopedia Explains MIDlet
A MIDlet is built for resource limited devices, such as pagers, personal digital assistants
(PDA) and phones. As cell phones outpaced other devices, and games made up the majority
of these applications, MIDlets became associated with Java games on cell phones.

Java’s main challenge was to facilitate the use of applications on devices with constrained
resources. Cell phones that support MIDlets have small displays, slow central processing
units (CPU), small memory, ordinary keypads and minimal connectivity features.

A MIDlet is normally deployed as a suite composed of a Java Archive (.jar) file and a Java
Application Descriptor (.jad) file. For security reasons, a MIDlet cannot modify itself or the
runtime environment and cannot escape the runtime environment.

There are various MIDlet installation methods, as follows:

 Direct method: Entails the use of a connection between the development computer
and device. Although the most commonly used connection medium is data cable,
employing wireless connections, like Bluetooth and infrared (IR), is also possible.
 Over-the-air (OTA) provisioning: The MIDlet is uploaded to a Web server and
accessed via the target device’s built-in browser. Because anyone can access the
MIDlet at any time, this method is ideal for large scale deployments.

MIDlet Programming
• Programming a MIDlet is similar to creating a J2SE application in that define a
class and related methods
• Less Robust

• A MIDlet is a class that extends the MIDlet class and is the interface
between application statements and the run-time environment, which is
controlled by the application manager.

MIDP Applications (MIDlets) and MIDlet Lifecycle


When j2me application (MIDlet) is created it must extended from the
MIDlet class in javax.microedition.midlet.MIDlet

MIDlet class as three abstract methods that are called by the


Application manager software (AMS).

When MIDlet starts to run, it goes into three phases which are
controlled by the AMS.
1. pasueApp()
2. startApp()
3. destroyApp();

Stages of MIDlet's lifecycle


1. When the MIDlet is about to be run, an instance

of javax.microedition.midlet.MIDlet class is created. The MIDlet's class


constructor with 0 arguments is run, and the MIDlet is in the Paused
state.

2. Next, MIDlet move into Active state after application manager

calling startApp() method which implement with extend MIDlet class.

3. While the MIDlet is Active state, the application manager can


suspend its execution by calling pauseApp() method
4. After application manager execute startApp() method, can
terminate the execution by calling destroyApp() method.
5. A MIDlet can destroy itself by calling notifyDestroyed() method.

 public class BasicMIDletShell extends MIDlet

 {
 public void startApp()

 {}

 public void pauseApp()

 {}

 public void destroyApp( boolean unconditional)

 {}}

CCCC

• Both the startApp() and pauseApp() methods are public and have no return value
nor parameter list.
• The destroyApp() method is also a public method without a return value.
• However, the destroyApp() method has a boolean parameter that is set to true if
the termination of the MIDlet is unconditional and false if the MIDlet can throw a
MIDletStateChangeException telling the application manager that the MIDlet does
not want to be destroyed just yet.
• At the center of every MIDlet are the MIDP API classes used by the MIDlet to
interact with the user and handle data management.
• User interactions are managed by user interface MIDP API classes.
• These APIs enable a developer to display screens of data and prompt the user to
respond with an appropriate command. The command causes the MIDlet to
execute oneof three routines: perform a computation, make a network request, or
display another screen.
• The data-handling MIDP API classes enable the developer to perform four kinds of
data routines:
• write and read persistent data, store data in data types, receive data from
and send data to a network, and interact with the small computing device’s
input/output features.

You might also like