Sie sind auf Seite 1von 11

PMRC-Dec 2011

1 1-1 Ans. Give differences with respect to J2ME: [20 Marks] Interactive Gauge Vs non Interactive Gauge Interactive Gauge Non Interactive Gauge The user is allowed to modify the value. The user is prohibited from modifying the value. They are used as setting values. They are used as progress indicators The interactive argument of the The interactive argument of the constructor is set to true. constructor is set to false. The maxValue argument of the constructor The maxValue argument of the constructor must be greater than zero and finite. must be greater than zero and finite or it can have special value INDEFINITE. The initial value must be within the range If the maximum value is INDEFINITE, the zero to maxValue, inclusive. initial value must be one of CONTINUOUS_IDLE, INCREMENTAL_IDLE, CONTINUOUS_RUNNING, or INCREMENTAL_UPDATING. TextBox Vs TextField TextBox The TextBox class is a Screen. public class TextBox extends Screen It has a title and we can set ticker to the TextBox. TextBox is not placed into a Form. Only one TextBox can be displayed at a time.

1-2 Ans.

TextField A TextField is an Item. public class TextField extends Item It has a label and we cannot set ticker to TextField. TextField is placed into a Form which is Screen. More than one TextField can be placed into a Form and hence can be displayed at a time.

1-3 Ans.

ListBox Vs ChoiceGroup ListBox The List is a Screen. public class List extends Screen implements Choice It has a title and we can set ticker to the List. The listType can be one of IMPLICIT, EXCLUSIVE, or MULTIPLE List is not placed into a Form. Only one List can be displayed at a time.

ChoiceGroup A ChoiceGroup is an Item. public class ChoiceGroup extends Item implements Choice It has a label and we cannot set ticket to ChoiceGroup. The choiceType can be one of EXCLUSIVE, MULTIPLE, or POPUP ChoiceGroup is placed into a Form which is Screen. More than one ChoiceGroup can be placed into a Form and hence can be displayed at a time.

1-4

CommandListner Vs ItemStateListner CommandListner This interface is used by applications which need to receive high-level events from the implementation.

ItemStateListner This interface is used by applications which need to receive events that indicate changes in the internal state of the interactive items within a Form.

It defines single method: void commandAction(Command c, Displayable d) All Screen have setCommandListener() method to set the CommandListner. 1-5 Mutable Image Vs Immutable Image Mutable Image Mutable images are created as blank images containing only white pixels. Mutable Images can be modified by calling getGraphics() and using the returned Graphics object to draw on the image. There is no direct method to create a mutable image from immutable image.

It defines single method: void itemStateChanged(Item item) Only Form has setItemStateListener() method to set the ItemStateListener.

Immutable Image Immutable images are generally created by loading image data from resource bundles, from files, or from the network. Immutable images cannot be modified.

We can create immutable image from mutable image using createImage() methods.

2 2-1 Ans.

Explain following with respect to J2ME : [20 Marks] Explain in brief Screen and Canvas In J2ME MIDP (Mobile Information Device Profile) contains user interface classes in the: 1. javax.microedition.lcdui and 2. javax.microedition.lcdui.game packages. The devices display, as seen by the MIDlet, is represented by an instance of the Display class, accessed from a factory method, getDisplay(). Displays main purpose in life is to keep track of what is currently shown, which is an instance of Displayable. Displayable has a small family of subclasses that represent various types of user interfaces. As shown in the figure below:

Figure: Displayable subclasses Screen Screen is the base class for all classes that represent generalized user interfaces. This class has no methods of its own, but inherits all from Displayable. Screen has following direct subclasses: 1. Alert- Used to display timed and modal alerts 2. List- Used to display list of choices 3. Form- Used to display textbox, images, lists gauges etc. on a single form. 4. TextBox- allows to enter string Canvas Generalized user-interface APIs (subclasses of Screen) are unsuitable for game development and other specialized user interfaces.

MIDP offers a class, javax.microedition.lcdui.Canvas, that provides low-level access to a devices screen and input facilities and allows creating a custom user interface. You can find out exactly which keys a user is pressing and draw whatever you want on the screen. Canvas supplies methods that allow your MIDlet to learn about its environmentthe size of the display, for example, and which kinds of events are supported by the device. To use Canvas, you must create a subclass of Canvas. This differs from the Screen subclasses, which are ready to use out of the box. The MIDP implementation calls a Canvass paint() method when the contents of the Canvas need to be shown. The MIDP implementation passes a Graphics object to your paint() method. Graphics has methods for drawing shapes, text, and images on a Canvas. A typical Canvas implementation, then, looks something like this: import javax.microedition.lcdui.*; public class MyCanvas extends Canvas { public void paint(Graphics g) { // Draw stuff using g. } } 2-2 Ans. 2-3 Ans. Explain Image class See Jun 2010 paper solution Q3-b. Explain Date and Ticker class Date class The class Date represents a specific instant in time, with millisecond precision. Constructors: public Date() Allocates a Date object and initializes it to represent the current time specified number of milliseconds since the standard base time known as "the epoch", namely January 1, 1970, 00:00:00 GMT. public Date(long date) Allocates a Date object and initializes it to represent the specified number of milliseconds since the standard base time known as "the epoch", namely January 1, 1970, 00:00:00 GMT. Methods: public long getTime() Returns the number of milliseconds since January 1, 1970, 00:00:00 GMT represented by this Date object. public void setTime(long time) Sets this Date object to represent a point in time that is time milliseconds after January 1, 1970 00:00:00 GMT. Ticker Class A ticker is simply a bit of text that scrolls across the top of a Displayable. The Ticker class is a simple wrapper for a string. To add a ticker to a screen, you would do something like this: // Displayable d = ... Ticker ticker = new Ticker("This is the ticker message!"); d.setTicker(ticker); Constructor:

public Ticker(String str) Constructs a new Ticker object, given its initial contents string. Methods: public String getString() Gets the string currently being scrolled by the ticker. public void setString(String str) Sets the string to be displayed by this ticker. If this ticker is active and is on the display, it immediately begins showing the new string. Note: Date class is misspelled it should be DateField. DateField DateField is an extremely handy mechanism by which users can enter dates, times, or both. DateField is an Item which can be included on the Form. To create a DateField, specify a label and a type. Three constants in the DateField class describe the different types: 1. DATE displays an editable date. 2. TIME displays an editable time. 3. DATE_TIME displays both a date and a time. DateField provides two constructors. The first uses the default time zone, while the second allows you to specify a TimeZone explicitly: 1. public DateField(String label, int mode) 2. public DateField(String label, int mode, TimeZone timeZone) A DateField is an editor for a java.util.Date. You can set or get the Date represented by the DateField using the following methods: public Date getDate() public void setDate(Date date) If you do not supply a Date to setDate() before showing the DateField, it will appear uninitialized. 2-4 Ans. Explain Graphics class Graphics class provides simple 2D geometric rendering capability. Graphics has methods for drawing shapes, text, and images on a Canvas. It also maintains some state, like the current pen color and line style. Methods for drawing shapes: Shape Outline drawLine(int x1, int y1, int x2, int y2) drawRect(int x, int y, int width, int height)
drawRoundRect(int x, int y, int width, int height, int arcWidth, int arcHeight)

Filled Shape

fillTriangle(int x1, int y1, int x2, int y2, int x3, int y3) fillRect(int x, int y, int width, int height)
fillRoundRect(int x, int y, int width, int height, int arcWidth, int arcHeight)

drawArc(int x, int y, int width, int height, int startAngle, int arcAngle) Methods for drawing texts
public public public public void void void void

fillArc(int x, int y, int width, int height, int startAngle, int arcAngle)

drawChar(char character, int x, int y, int anchor) drawChars(char[] data, int offset, int length, int x, int y, int anchor) drawString(String str, int x, int y, int anchor) drawSubstring(String str, int offset, int len, int x, int y, int anchor)

Methods for drawing image public void drawImage(Image img, int x, int y, int anchor) Anchor points: The drawing of text is based on "anchor points". The anchor point determines exactly where the text will be drawn. Anchor points are described with a horizontal and vertical component. The Graphics class defines the horizontal and vertical anchor points as constants. Figure illustrates the various anchor points for a string of text. Each anchor point is described as a combination of a horizontal and vertical anchor point.

Figure: Anchor Points 2-5 Ans. Explain Alert and StringItem Alert See Dec 2010 paper solution Q4-d. StringItem An item that can contain a string. A StringItem is display-only; the user cannot edit the contents. Both the label and the textual content of a StringItem may be modified by the application. StringItem represents a simple text label. Constructors: public StringItem(String label, String text) Creates a new StringItem object. public StringItem(String label, String text, int appearanceMode) Creates a new StringItem object with the given label, textual content, and appearance mode. Either label or text may be present or null. Appearance Mode The appearance mode allows the item to look like a URL link or a button. The three appearance modes (which are defined in the Item class) are as follows: PLAIN shows the item in its normal state. HYPERLINK shows the item as a URL. BUTTON shows the item as a button. Methods: 1 2 3 4 int Font String void getAppearanceMode() getFont() getText() setFont(Font font) Returns the appearance mode of the StringItem. Gets the application's preferred font for rendering this StringItem. Gets the text contents of the StringItem, or null if the StringItem is empty. Sets the application's preferred font for rendering this StringItem.

5 6

void void

setPreferredSize(int width, int height) setText(String text)

Sets the preferred width and height for this Item. Sets the text contents of the StringItem.

3-a Ans.

What is record management in J2ME? How do you handle records in J2ME? [5 Marks] In MIDP, persistent storage is centered around record stores. A record store is a small database that contains pieces of data called records. Record stores are represented by instances of javax.microedition.rms.RecordStore. The scope of a record store can either be limited to a single MIDlet suite or be shared between MIDlet suites. Record stores are identified by a name. Within a MIDlet suites record stores, the names must be unique. The RecordStore class serves two purposes. 1. First, it defines an API for manipulating individual records. 2. Second, it defines an API (mostly static methods) for managing record stores. To open a record store, you simply need to name it. public static RecordStore openRecordStore(String recordStoreName, boolean createIfNecessary) throws RecordStoreException, RecordStoreFullException, RecordStoreNotFoundException If the record store does not exist, the createIfNecessary parameter determines whether a new record store will be created or not. If the record store does not exist, and the createIfNecessary parameter is false, then a RecordStoreNotFoundException will be thrown. An open record store can be closed by calling the closeRecordStore() method. To find out all the record stores available to a particular MIDlet suite, call the listRecordStores() method: public static String[] listRecordStores() Finally, to remove a record store, call the static deleteRecordStore() method. The record store and its contained records will be deleted.

3-b Ans.

How do you program for multimedia in J2ME. [5 Marks] To program for multimedia J2ME provides Mobile Media API (MMAPI). The subset of the MMAPI that is included is called the Audio Building Block (ABB). It includes the capability to play simple tones and sampled audio. The ABB is implemented in the 1. javax.microedition.media and 2. javax.microedition.media.control packages. To play a tone: javax.microedition.media.Manager Class provides a following static method to play tones public static void playTone(int note, int duration, int volume) throws MediaException Parameters: note - Defines the tone of the note. A note is given in the range of 0 to 127 inclusive. duration - The duration of the tone in milliseconds. Duration must be positive. volume - Audio volume range from 0 to 100 (Maximum). To play sampled audio files To play sampled audio, you just need to get a Player for the data you wish to hear, and then start the Player running. Example: URL url = "http://localhost:8080/test.wav"; Player p = Manager.createPlayer(url); p.start();

In this approach, the web server provides the content type of the data. Another approach is to obtain an InputStream to the audio data, and then create a Player by telling Manager the content type of the data. This is handy for reading audio files that are stored as resources in the MIDlet suite JAR. Example: InputStream in = getClass().getResourceAsStream("/test.wav"); Player player = Manager.createPlayer(in, "audio/x-wav"); player.start(); Playing MP3 Music: InputStream in = getClass().getResourceAsStream("/mytrack.mp3"); Player player = Manager.createPlayer(in, "audio/mpeg"); player.start(); Playing video: InputStream in = getClass().getResourceAsStream("/test.mpg"); Player player = Manager.createPlayer(in, "video/mpeg"); player.start(); 3-c Ans. What is CLDC? How do you program for CLDC? [5 Marks] CLDC (Connected, Limited Device Configuration) is a J2ME configuration specification which defines Java platform for small, resource-constrained, connected devices. It specifies Processor (16/32 bit), Memory (160-512 KB), JVM (called KVM), Core APIs (subset of J2SE). CLDC Specification does not address the following features: Application life-cycle management (application installation, launching, deletion) User interface functionality Event handling High-level application model (the interaction between the user and the application) Therefore to program for CLDC we must use profiles based on CLDC i.e. Mobile Information Device Profile (MIDP) or Personal Digital Assistant Profile (PDAP). These profiles provide APIs for user interface and whatever necessary to develop and run the applications. To program mobile devices use CLDC/MIDP APIs. CLDC Packages (API) java.io java.lang java.lang.ref java.security java.util javax.microedition.io

Provides classes for input and output through data streams. Provides classes that are fundamental to the Java programming language. Provides support for weak references. Provides the classes and interfaces for the security framework. Contains the collection classes, and the date and time facilities. Classes for the Generic Connection framework.

3-d Ans.

What is J2ME MIDP? [5 Marks] The Mobile Information Device Profile (MIDP) is a key element of the Java 2 Platform, Mobile Edition (J2ME). When combined with the Connected Limited Device Configuration (CLDC), MIDP provides a standard Java runtime environment for today's most popular mobile information devices, such as cell phones and mainstream personal digital assistants (PDAs). CLDC and MIDP provide the core application functionality required by mobile applications, in the form of a standardized Java runtime environment and a rich set of Java APIs. Developers using MIDP can write applications once, then deploy them quickly to a wide variety of mobile

information devices. Characteristics: A minimum of 256KB of ROM for the MIDP implementation (this is in addition to the requirements of the CLDC) A minimum of 128KB of RAM for the Java runtime heap A minimum of 8KB of nonvolatile writable memory for persistent data A screen of at least 9654 pixels Some capacity for input, either by keypad, keyboard, or touch screen Two-way network connection, possibly intermittent Example product scenarios: Cellular phones Two-way pagers Wireless-enabled personal digital assistants (PDAs) Version: MIDP 1.0 (JSR 37) MIDP 2.0 (JSR 118) 4-a Ans. 4-b Ans. 4-c Ans. Explain MIDlet lifecycle. [10 Marks] See Jun 2010 paper solution Q1-b. What are different security considerations in J2ME? [10 Marks] See Jun 2011 paper solution Q6-a. What are the differences between J2ME and other flavors of Java for example J2SE or J2EE. [5 Marks] J2ME J2SE (Java 2 Platform Micro Edition) (Java 2 Platform Standard Edition) Provides a robust, flexible environment Lets you develop and deploy Java applications on for applications running on mobile and desktops and servers. other embedded devices (mobile phones, personal digital assistants (PDAs), TV set-top boxes, and printers). J2ME is divided into: J2SE consists of: A configuration provides the most Java Virtual Machine (JVM) to run Java basic set of libraries and virtual bycodes and machine capabilities for a broad Java Application Programming Interface range of devices, (API) is a large collection of ready-made A profile is a set of APIs that support software components that provide many a narrower range of devices, and useful capabilities. An optional package is a set of technology-specific APIs. J2ME provides a subset of the It contains all of the libraries and APIs that any functionality of J2SE, but also introduces Java programmer should learn (java.lang, libraries specific to mobile devices. java.io, java.math, java.net, java.util, etc). The applications developed for With J2SE we can develop stand alone Java CLDC/MIDP are called midlets. application and applet. Application development steps: Application development steps: Code Code Compile Compile Preverify Run Package Test or Deploy

5-a Ans. 5-b Ans. 6-a Ans. 6-b Ans. 7-a Ans.

Write note on MVC architecture. [10 Marks] See Dec 2010 paper solution Q1-b. What are JDBC drivers, state its types and elaborate each of them? [10 Marks] See Dec 2010 paper solution Q3-a. Explain lifecycle of servlet. [10 Marks] See Jun 2010 paper solution Q2-a. Write a note on web centric approach and EJB centric approach of creating web applications. [10 Marks] See Jun 2010 paper solution Q6-b. Explain various classes in Games API. [10 Marks] The Game API builds on the Canvas and Graphics classes. The entire game API is composed of five classes in the javax.microedition.lcdui.game package. 1. GameCanvas 2. Layer 3. LayerManager 4. Sprite 5. TiledLayer One class, GameCanvas, provides methods for animation and key polling. The other four classes deal with layers, which can be used to compose scenes from several different elements. GameCanvas class GameCanvas extends javax.microedition.lcdui.Canvas with methods for animation and key state polling. To use GameCanvas, you subclass it. To draw on the screen, you use the Graphics returned from getGraphics(). When you want updates to appear on the screen, call flushGraphics(), which does not return until the screen is updated. For more specific updates, use the method flushGraphics(int x, int y, int width, int height), which only updates a region of the screen. The rest of the Game API is devoted to layers. Layers are graphic elements that can be combined to create a complete scene. You might, for example, have a background of mountains, another background of city buildings, and several smaller items in the foreground: people, spaceships, cars, whatever. Layer class Layer class represents a layer. Layer is abstract, with two concrete subclasses: 1. Sprite 2. TiledLayer Layer has a location, a size, and can be visible or invisible. The location and size are accessed and modified with the following methods: public final int getX() public final int getY() public final int getWidth() public final int getHeight() public void setPosition(int x, int y) Layer also offers a handy method for moving relative to the current position. Pass pixel offsets to the following method to adjust the position of the layer: public void move(int dx, int dy) The layers visibility is accessed using getVisible() and setVisible(). The last method in Layer is paint(), which is declared abstract. Subclasses override this method to define their

appearance. LayerManager Class LayerManagers job is keeping an ordered list of layers. To create a LayerManager, just call its no-argument constructor. Layers have an index, which indicates their position front to back. A position of 0 is on top, closest to the user, while larger indices are farther away, towards the bottom. Layers may be added to the bottom of the list using this method: public void append(Layer l) You can add a layer at a specific location using insert(): public void insert(Layer l, int index) You can find the number of layers in the LayerManager by calling getSize(). If youd like to retrieve the layer at a certain position, pass the index to the getLayerAt() method. Finally, you can remove a layer by passing the Layer object to the remove() method. LayerManager includes the concept of a view window, which is the rectangular portion of the scene that will be drawn. You can set the view window using the following method, where the x and y coordinates are relative to the origin of the LayerManager. public void setViewWindow(int x, int y, int width, int height) To actually draw the scene represented by the LayerManagers layers, call the paint() method: public void paint(Graphics g, int x, int y) TiledLayer Class A tiled layer is made from a palette of tiles. The tiles come from a single image that is divided into equal-sized pieces. Tiles are numbered starting at one. The tiled layer itself is a grid of cells, where each cell is occupied by one tile. To create a TiledLayer, supply the number of columns and rows, the source image, and the tile dimensions to the constructor: public TiledLayer(int columns, int rows, Image image, int tileWidth, int tileHeight) The number of columns and rows in a TiledLayer can be retrieved with getColumns() and getRows(). To retrieve the tile dimensions, use getCellWidth() and getCellHeight(). A TiledLayer is empty when you first create it. To assign a tile to a cell, use this method: public void setCell(int col, int row, int tileIndex) All the cells in the TiledLayer are initially filled with tile index 0, which indicates a blank tile. You can retrieve the tile index of a particular cell by passing its column and row number to getCell(). If you would like to assign the same tile to a range of cells, use the fillCells() method: public void fillCells(int col, int row, int numCols, int numRows, int tileIndex) Sprite Class While a TiledLayer uses a palette of tiles to fill a large area, a Sprite uses a palette of tiles to animate a layer that is the same size as a single tile. In Sprite, tiles are called frames instead. As with a TiledLayer, a Sprite is created from a source image that is divided into equally sized frames. public Sprite(Image image, int frameWidth, int frameHeight) Theres also a special caseif the image contains just one frame, it will not be animated: public Sprite(Image image) Sprite cannot be created from separate frame images; the frames must be packed into a single source image. If you want to change the source image after the Sprite is created, use setImage(): public void setImage(Image img, int frameWidth, int frameHeight) The total number of frames contained in the Sprite is returned from getRawFrameCount().

Like any other Layer, Sprites are rendered when the paint() method is called. Usually the Sprite will belong to a LayerManager, in which case it is rendered automatically when the LayerManager is rendered. Sprite animation is all about frame sequences. When a Sprite is created, it has a default frame sequence that includes every frame in the source image. The following method changes the current frame sequence: public void setFrameSequence(int[] sequence) To move forward and backward in the sequence, use nextFrame() and prevFrame(). Sprite includes support for transformations so that you can use the API to generate additional frames that are simple transformations of existing frames. The following method applies a transformation to a Sprite: public void setTransform(int transform) The transform argument can be any of the constant values defined in the Sprite class: TRANS_NONE TRANS_ROT90 TRANS_ROT180 TRANS_ROT270 TRANS_MIRROR TRANS_MIRROR_ROT90 TRANS_MIRROR_ROT180 TRANS_MIRROR_ROT270 7-b Ans. Write a note on 1. Obfuscator See Jun 2010 paper solution Q5-a. 2. Bluetooth architecture. See Jun 2010 paper solution Q5-d.

Ans.

Das könnte Ihnen auch gefallen