Professional Documents
Culture Documents
Unit 2
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.
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.
To add padding to the image from the left, right, top, or bottom of
android:padding the view
<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
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
}
Output:
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?
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.
Command
Form
Canvas
An instance of the Command class is a button that the user presses on the device to
enact a specific task.
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.
java.sun.com/products/j2mewtoolkit/download.html.
It is used to develop and test J2ME applications by selecting a few buttons from a
toolbar.
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- 5: go to the project (MIDlet suite) to which you added MIDlets and open the manifest file in the
bin folder.
MidletLifecycle
MIDlet-Name: TextBoxEx
MIDlet-Vendor: Unknown
MIDlet-Version: 1.0
MicroEdition-Configuration: CLDC-1.0
MicroEdition-Profile: MIDP-2.0
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 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.”
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.”
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.”
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.”
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.”
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
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.
. 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.
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.
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.
When MIDlet starts to run, it goes into three phases which are
controlled by the AMS.
1. pasueApp()
2. startApp()
3. destroyApp();
{
public void startApp()
{}
{}
{}}
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.