How unit 5 is examined
This unit is an overview of four technologies (J2ME, J2EE, EJB, XML); none has been asked in the supplied papers, so each is taught as a short answer-ready section, and the likeliest exam forms are "explain", "differentiate" and "write short notes".
J2ME
Not asked since 2022
Definition. J2ME (Java 2 Platform, Micro Edition, now Java ME) is the Java platform for small, resource-limited devices such as mobile phones, PDAs, set-top boxes, smart cards and embedded controllers.
Diagram.
Key points.
- J2ME uses a small-footprint virtual machine (the KVM, "kilobyte" VM) and a trimmed set of libraries, because these devices have little memory, a slow processor, a small screen and limited battery.
- A configuration defines the basic virtual machine and core libraries for a family of devices: CLDC (Connected Limited Device Configuration) is for phones and pagers, and CDC (Connected Device Configuration) is for more capable devices such as set-top boxes.
- A profile sits on a configuration and adds APIs for the user interface, storage and networking; MIDP (Mobile Information Device Profile) is the profile used with CLDC on mobile phones.
- Applications are called MIDlets; they extend the class
MIDlet, are downloaded over the air to the phone, and are started, paused and destroyed by the device's application manager. - A MIDlet has three states, paused, active and destroyed, controlled by the methods
startApp(),pauseApp()anddestroyApp(). - J2ME keeps the write-once-run-anywhere idea, but only a subset of the standard J2SE classes is present, and features such as floating point and reflection are limited in CLDC.
public class Hello extends MIDlet {
public void startApp() { /* build the screen and show it */ }
public void pauseApp() { }
public void destroyApp(boolean unconditional) { }
}
Answer frame. Open with the definition; draw the layer figure; develop configuration, profile, MIDlet and its three life-cycle methods in that order; close with one line that J2ME is J2SE cut down for mobile devices.
J2EE
Not asked since 2022
Definition. J2EE (Java 2 Platform, Enterprise Edition, now Java EE) is a standard platform of APIs and a runtime environment for developing and deploying large, distributed, multi-tier, server-side enterprise applications.
Diagram.
Key points.
- J2EE builds on J2SE and adds enterprise APIs: Servlets, JSP, EJB, JDBC, JNDI (naming), JMS (messaging), JTA (transactions), JavaMail and RMI.
- Applications follow a multi-tier model: the client tier is a browser or standalone program, the web tier runs Servlets and JSP, the business tier runs EJB components, and the enterprise information system (EIS) tier holds the database and legacy systems.
- Each component runs inside a container provided by the application server, and the container supplies services such as transaction management, security, connection pooling, threading and life-cycle management, so the programmer writes only business logic.
- The web container hosts Servlets and JSP, and the EJB container hosts enterprise beans; both are part of the application server (for example GlassFish, JBoss or WebLogic).
- Applications are packaged as archives: JAR for EJB modules, WAR for web modules and EAR for the complete application, with deployment descriptors (
web.xml,ejb-jar.xml) written in XML. - J2EE gives scalable, portable, vendor-independent and secure applications, because the same code runs on any compliant server.
| Aspect | J2SE | J2EE |
|---|---|---|
| Purpose | Desktop and standalone programs | Distributed enterprise applications |
| Contents | Core language and libraries | J2SE plus Servlet, JSP, EJB, JMS, JTA |
| Runs on | JVM | Application server with containers |
| Typical use | Utilities, GUI, applets | Banking, reservation, e-commerce systems |
Answer frame. Open with the definition; draw the tier figure; develop the APIs, tiers, containers and packaging in that order; close with portability and scalability.
EJB
Not asked since 2022
Definition. Enterprise JavaBeans (EJB) is the J2EE server-side component architecture in which the business logic of an enterprise application is written as reusable components called beans, managed by an EJB container.
Diagram.
Key points.
- A session bean performs business logic for one client; it is stateless if it keeps no client data between calls (and can be shared through a pool) and stateful if it remembers the conversation with one client.
- An entity bean represents persistent data, usually one row of a database table, and is identified by a primary key; in later versions it was replaced by JPA entities.
- A message-driven bean is invoked by the arrival of a JMS message, so it handles asynchronous requests and has no client-visible interface.
- The EJB container provides transaction management, security, persistence, concurrency, remote access and instance pooling, so the bean developer does not code these services.
- A client reaches a bean through its home interface (to create or find the bean) and its remote interface (the business methods), locating them with a JNDI lookup and calling them over RMI.
- The bean class, its interfaces and the deployment descriptor
ejb-jar.xmlare packaged into a JAR and deployed on the application server.
| Bean type | Holds | State | Invoked by |
|---|---|---|---|
| Stateless session | Business logic | None between calls | Client call |
| Stateful session | Business logic | Per-client conversation | Client call |
| Entity | Persistent data | Stored in database | Client or session bean |
| Message-driven | Logic for messages | None | JMS message |
Answer frame. Open with the definition; draw the call-path figure; develop the three bean types, then the container services, then the interfaces; close with the benefit that the container removes plumbing code.
XML
Not asked since 2022
Definition. XML (Extensible Markup Language) is a W3C text-based markup language in which the user defines their own tags to describe and carry data in a platform-independent, self-describing form.
Diagram.
Key points.
- XML describes what the data is, not how it looks, unlike HTML, which has fixed tags and describes display; its tags are user-defined and it is case-sensitive.
- A document must be well-formed: it has exactly one root element, tags are properly nested, every start tag has an end tag, and attribute values are quoted.
- A DTD or an XML Schema defines the allowed elements and their order, and a well-formed document that follows it is called valid.
- XML parsing means reading a document into a program: a parser checks well-formedness and gives the program access to the elements.
- A DOM parser loads the whole document as a tree in memory, so it allows random access and modification but uses more memory.
- A SAX parser is event-driven and reads the document sequentially, raising events such as start element and end element, so it is fast and uses little memory but cannot go backwards.
- Java supports both through JAXP (
DocumentBuilderfor DOM,SAXParserfor SAX), and XML is used for data exchange, configuration files such asweb.xml, and web services.
<?xml version="1.0"?>
<student>
<name>Amit</name>
<roll>101</roll>
<branch>CSE</branch>
</student>
| Feature | DOM parser | SAX parser |
|---|---|---|
| Model | Tree in memory | Stream of events |
| Memory | High | Low |
| Access | Random, can edit | Forward only, read only |
| Speed | Slower for big files | Faster |
Answer frame. Open with the definition; write a small XML document and draw its tree; develop well-formed versus valid, then DOM and SAX with the table; close with XML's use in data exchange.
Pitfall: Writing an unclosed tag, two root elements or mismatched case in an example makes the document not well-formed and loses the marks.
Last-minute revision
- J2ME is the Java platform for small devices; its programs are MIDlets running on the KVM.
- J2ME structure: configuration (CLDC or CDC) plus profile (MIDP).
- MIDlet life-cycle methods:
startApp(),pauseApp(),destroyApp(). - J2EE is the Java platform for distributed multi-tier enterprise applications.
- J2EE tiers: client, web (Servlet and JSP), business (EJB), EIS (database).
- The J2EE container supplies transactions, security and pooling; packaging is JAR, WAR and EAR.
- EJB is the server-side component model for business logic, managed by the EJB container.
- EJB types: session (stateful or stateless), entity, message-driven.
- XML lets users define their own tags; it is self-describing and platform independent.
- Well-formed means correct syntax; valid means it also follows a DTD or Schema.
- DOM loads a tree in memory (random access); SAX is event-based and light (forward only).
Memory hooks
- Micro means Mobile: J2ME, MIDlet, KVM, CLDC plus MIDP.
- Enterprise means Every tier: J2EE is client, web, business, database.
- Beans come in three flavours: Session, Entity, Message.
- DOM is a Document tree in memory; SAX is a Stream of events.
- Well-formed is grammar, valid is grammar plus the DTD rulebook.
Coverage checklist
- J2ME: definition, configuration and profile, MIDlet life cycle (no past questions).
- J2EE: definition, tiers, containers, packaging, comparison with J2SE (no past questions).
- EJB: definition, bean types, container services, interfaces (no past questions).
- XML: definition, well-formed and valid, DOM and SAX parsing (no past questions).