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
<span style="display:inline-block;padding:.16em .6em;border:1.5px solid currentColor;border-radius:999px;font-size:.68em;font-weight:700;letter-spacing:.06em;text-transform:uppercase;opacity:.75">Not asked since 2022</span>
Definition. <mark>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.</mark>
Diagram.
<figure class="ds-fig" style="margin:1.4rem 0;overflow-x:auto"><svg xmlns="http://www.w3.org/2000/svg" id="dsfig-u5-01" viewBox="0 0 87 424" width="87" height="424" role="img" aria-label="J2ME layers, top to bottom - MIDlet application, profile (MIDP), configuration (CLDC), KVM virtual machine, device operating system"><style>#dsfig-u5-01 .e{stroke:#454C5A;stroke-width:1.4;fill:none}#dsfig-u5-01 .e.hi{stroke:#2340B8;stroke-width:2.6}#dsfig-u5-01 .n{fill:#FFFFFF;stroke:#16181D;stroke-width:1.4}#dsfig-u5-01 .n.hi{fill:#E3E9FC;stroke:#2340B8;stroke-width:2.2}#dsfig-u5-01 .n.rb-b{fill:#16181D;stroke:#16181D}#dsfig-u5-01 .n.rb-r{fill:#BD3227;stroke:#BD3227}#dsfig-u5-01 text{font-family:"JetBrains Mono",ui-monospace,Menlo,Consolas,monospace;font-size:13px}#dsfig-u5-01 .t{fill:#16181D;font-weight:500}#dsfig-u5-01 .t.inv{fill:#FFFFFF;font-weight:700}#dsfig-u5-01 .kd{stroke:#16181D;stroke-width:1.2}#dsfig-u5-01 .dot{fill:#16181D}#dsfig-u5-01 .ann{fill:#2340B8;font-size:11px;font-weight:700}#dsfig-u5-01 .lbl{fill:#6F7787;font-family:system-ui,-apple-system,sans-serif;font-size:12px;font-weight:700}#dsfig-u5-01 .ptr{fill:#2340B8;font-size:12px;font-weight:700}#dsfig-u5-01 .ah{fill:#454C5A}#dsfig-u5-01 .ah.hi{fill:#2340B8}#dsfig-u5-01 .wl rect{fill:#FFFFFF;stroke:#DCE0E7}#dsfig-u5-01 .wl .t{font-size:12px;font-weight:700}#dsfig-u5-01 .wl.hi rect{fill:#2340B8;stroke:#2340B8}#dsfig-u5-01 .wl.hi .t{fill:#FFFFFF}html.dark #dsfig-u5-01 .e{stroke:#B1B7C3}html.dark #dsfig-u5-01 .e.hi{stroke:#8FA3FF}html.dark #dsfig-u5-01 .n{fill:#161920;stroke:#E6E8ED}html.dark #dsfig-u5-01 .n.hi{fill:#1E2748;stroke:#8FA3FF}html.dark #dsfig-u5-01 .n.rb-b{fill:#E6E8ED;stroke:#E6E8ED}html.dark #dsfig-u5-01 .n.rb-r{fill:#FF7E71;stroke:#FF7E71}html.dark #dsfig-u5-01 .t{fill:#E6E8ED}html.dark #dsfig-u5-01 .t.inv{fill:#0F1115}html.dark #dsfig-u5-01 .kd{stroke:#E6E8ED}html.dark #dsfig-u5-01 .dot{fill:#E6E8ED}html.dark #dsfig-u5-01 .ann{fill:#8FA3FF}html.dark #dsfig-u5-01 .lbl{fill:#858D9C}html.dark #dsfig-u5-01 .ptr{fill:#8FA3FF}html.dark #dsfig-u5-01 .ah{fill:#B1B7C3}html.dark #dsfig-u5-01 .ah.hi{fill:#8FA3FF}html.dark #dsfig-u5-01 .wl rect{fill:#161920;stroke:#2A2E37}html.dark #dsfig-u5-01 .wl.hi rect{fill:#8FA3FF;stroke:#8FA3FF}html.dark #dsfig-u5-01 .wl.hi .t{fill:#0F1115}</style><defs><marker id="ah2" viewBox="0 0 10 10" refX="9" refY="5" markerWidth="7" markerHeight="7" orient="auto-start-reverse"><path class="ah" d="M0,1 L9,5 L0,9 z"/></marker><marker id="ahh2" viewBox="0 0 10 10" refX="9" refY="5" markerWidth="7" markerHeight="7" orient="auto-start-reverse"><path class="ah hi" d="M0,1 L9,5 L0,9 z"/></marker></defs><path class="e" d="M40,59 L40,98" marker-end="url(#ah2)"/><path class="e" d="M40,152 L40,184" marker-end="url(#ah2)"/><path class="e" d="M40,238 L40,277" marker-end="url(#ah2)"/><path class="e" d="M40,317 L40,363" marker-end="url(#ah2)"/><circle class="n" cx="40" cy="40" r="18"/><text class="t" x="40" y="40" dy=".35em" text-anchor="middle">App</text><rect class="n" x="15" y="111" width="50" height="30" rx="15"/><text class="t" x="40" y="126" dy=".35em" text-anchor="middle">Prof</text><rect class="n" x="15" y="197" width="50" height="30" rx="15"/><text class="t" x="40" y="212" dy=".35em" text-anchor="middle">Conf</text><circle class="n" cx="40" cy="298" r="18"/><text class="t" x="40" y="298" dy=".35em" text-anchor="middle">JVM</text><circle class="n" cx="40" cy="384" r="18"/><text class="t" x="40" y="384" dy=".35em" text-anchor="middle">OS</text></svg><figcaption style="font-size:.82em;opacity:.72;margin-top:.45rem">J2ME layers, top to bottom - MIDlet application, profile (MIDP), configuration (CLDC), KVM virtual machine, device operating system</figcaption></figure>
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
<span style="display:inline-block;padding:.16em .6em;border:1.5px solid currentColor;border-radius:999px;font-size:.68em;font-weight:700;letter-spacing:.06em;text-transform:uppercase;opacity:.75">Not asked since 2022</span>
Definition. <mark>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.</mark>
Diagram.
<figure class="ds-fig" style="margin:1.4rem 0;overflow-x:auto"><svg xmlns="http://www.w3.org/2000/svg" id="dsfig-u5-02" viewBox="0 0 467 80" width="467" height="80" role="img" aria-label="J2EE tiers - Client (browser), Web tier (Servlet, JSP), Business tier (EJB), database (EIS)"><style>#dsfig-u5-02 .e{stroke:#454C5A;stroke-width:1.4;fill:none}#dsfig-u5-02 .e.hi{stroke:#2340B8;stroke-width:2.6}#dsfig-u5-02 .n{fill:#FFFFFF;stroke:#16181D;stroke-width:1.4}#dsfig-u5-02 .n.hi{fill:#E3E9FC;stroke:#2340B8;stroke-width:2.2}#dsfig-u5-02 .n.rb-b{fill:#16181D;stroke:#16181D}#dsfig-u5-02 .n.rb-r{fill:#BD3227;stroke:#BD3227}#dsfig-u5-02 text{font-family:"JetBrains Mono",ui-monospace,Menlo,Consolas,monospace;font-size:13px}#dsfig-u5-02 .t{fill:#16181D;font-weight:500}#dsfig-u5-02 .t.inv{fill:#FFFFFF;font-weight:700}#dsfig-u5-02 .kd{stroke:#16181D;stroke-width:1.2}#dsfig-u5-02 .dot{fill:#16181D}#dsfig-u5-02 .ann{fill:#2340B8;font-size:11px;font-weight:700}#dsfig-u5-02 .lbl{fill:#6F7787;font-family:system-ui,-apple-system,sans-serif;font-size:12px;font-weight:700}#dsfig-u5-02 .ptr{fill:#2340B8;font-size:12px;font-weight:700}#dsfig-u5-02 .ah{fill:#454C5A}#dsfig-u5-02 .ah.hi{fill:#2340B8}#dsfig-u5-02 .wl rect{fill:#FFFFFF;stroke:#DCE0E7}#dsfig-u5-02 .wl .t{font-size:12px;font-weight:700}#dsfig-u5-02 .wl.hi rect{fill:#2340B8;stroke:#2340B8}#dsfig-u5-02 .wl.hi .t{fill:#FFFFFF}html.dark #dsfig-u5-02 .e{stroke:#B1B7C3}html.dark #dsfig-u5-02 .e.hi{stroke:#8FA3FF}html.dark #dsfig-u5-02 .n{fill:#161920;stroke:#E6E8ED}html.dark #dsfig-u5-02 .n.hi{fill:#1E2748;stroke:#8FA3FF}html.dark #dsfig-u5-02 .n.rb-b{fill:#E6E8ED;stroke:#E6E8ED}html.dark #dsfig-u5-02 .n.rb-r{fill:#FF7E71;stroke:#FF7E71}html.dark #dsfig-u5-02 .t{fill:#E6E8ED}html.dark #dsfig-u5-02 .t.inv{fill:#0F1115}html.dark #dsfig-u5-02 .kd{stroke:#E6E8ED}html.dark #dsfig-u5-02 .dot{fill:#E6E8ED}html.dark #dsfig-u5-02 .ann{fill:#8FA3FF}html.dark #dsfig-u5-02 .lbl{fill:#858D9C}html.dark #dsfig-u5-02 .ptr{fill:#8FA3FF}html.dark #dsfig-u5-02 .ah{fill:#B1B7C3}html.dark #dsfig-u5-02 .ah.hi{fill:#8FA3FF}html.dark #dsfig-u5-02 .wl rect{fill:#161920;stroke:#2A2E37}html.dark #dsfig-u5-02 .wl.hi rect{fill:#8FA3FF;stroke:#8FA3FF}html.dark #dsfig-u5-02 .wl.hi .t{fill:#0F1115}</style><defs><marker id="ah3" viewBox="0 0 10 10" refX="9" refY="5" markerWidth="7" markerHeight="7" orient="auto-start-reverse"><path class="ah" d="M0,1 L9,5 L0,9 z"/></marker><marker id="ahh3" viewBox="0 0 10 10" refX="9" refY="5" markerWidth="7" markerHeight="7" orient="auto-start-reverse"><path class="ah hi" d="M0,1 L9,5 L0,9 z"/></marker></defs><path class="e" d="M61,40 L148,40" marker-end="url(#ah3)" marker-start="url(#ah3)"/><path class="e" d="M190,40 L277,40" marker-end="url(#ah3)" marker-start="url(#ah3)"/><path class="e" d="M319,40 L406,40" marker-end="url(#ah3)" marker-start="url(#ah3)"/><circle class="n" cx="40" cy="40" r="18"/><text class="t" x="40" y="40" dy=".35em" text-anchor="middle">Cl</text><circle class="n" cx="169" cy="40" r="18"/><text class="t" x="169" y="40" dy=".35em" text-anchor="middle">Web</text><circle class="n" cx="298" cy="40" r="18"/><text class="t" x="298" y="40" dy=".35em" text-anchor="middle">Biz</text><circle class="n" cx="427" cy="40" r="18"/><text class="t" x="427" y="40" dy=".35em" text-anchor="middle">DB</text></svg><figcaption style="font-size:.82em;opacity:.72;margin-top:.45rem">J2EE tiers - Client (browser), Web tier (Servlet, JSP), Business tier (EJB), database (EIS)</figcaption></figure>
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
<span style="display:inline-block;padding:.16em .6em;border:1.5px solid currentColor;border-radius:999px;font-size:.68em;font-weight:700;letter-spacing:.06em;text-transform:uppercase;opacity:.75">Not asked since 2022</span>
Definition. <mark>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.</mark>
Diagram.
<figure class="ds-fig" style="margin:1.4rem 0;overflow-x:auto"><svg xmlns="http://www.w3.org/2000/svg" id="dsfig-u5-03" viewBox="0 0 431 80" width="431" height="80" role="img" aria-label="EJB call path - the client calls the bean through the EJB container, which adds transaction, security and pooling"><style>#dsfig-u5-03 .e{stroke:#454C5A;stroke-width:1.4;fill:none}#dsfig-u5-03 .e.hi{stroke:#2340B8;stroke-width:2.6}#dsfig-u5-03 .n{fill:#FFFFFF;stroke:#16181D;stroke-width:1.4}#dsfig-u5-03 .n.hi{fill:#E3E9FC;stroke:#2340B8;stroke-width:2.2}#dsfig-u5-03 .n.rb-b{fill:#16181D;stroke:#16181D}#dsfig-u5-03 .n.rb-r{fill:#BD3227;stroke:#BD3227}#dsfig-u5-03 text{font-family:"JetBrains Mono",ui-monospace,Menlo,Consolas,monospace;font-size:13px}#dsfig-u5-03 .t{fill:#16181D;font-weight:500}#dsfig-u5-03 .t.inv{fill:#FFFFFF;font-weight:700}#dsfig-u5-03 .kd{stroke:#16181D;stroke-width:1.2}#dsfig-u5-03 .dot{fill:#16181D}#dsfig-u5-03 .ann{fill:#2340B8;font-size:11px;font-weight:700}#dsfig-u5-03 .lbl{fill:#6F7787;font-family:system-ui,-apple-system,sans-serif;font-size:12px;font-weight:700}#dsfig-u5-03 .ptr{fill:#2340B8;font-size:12px;font-weight:700}#dsfig-u5-03 .ah{fill:#454C5A}#dsfig-u5-03 .ah.hi{fill:#2340B8}#dsfig-u5-03 .wl rect{fill:#FFFFFF;stroke:#DCE0E7}#dsfig-u5-03 .wl .t{font-size:12px;font-weight:700}#dsfig-u5-03 .wl.hi rect{fill:#2340B8;stroke:#2340B8}#dsfig-u5-03 .wl.hi .t{fill:#FFFFFF}html.dark #dsfig-u5-03 .e{stroke:#B1B7C3}html.dark #dsfig-u5-03 .e.hi{stroke:#8FA3FF}html.dark #dsfig-u5-03 .n{fill:#161920;stroke:#E6E8ED}html.dark #dsfig-u5-03 .n.hi{fill:#1E2748;stroke:#8FA3FF}html.dark #dsfig-u5-03 .n.rb-b{fill:#E6E8ED;stroke:#E6E8ED}html.dark #dsfig-u5-03 .n.rb-r{fill:#FF7E71;stroke:#FF7E71}html.dark #dsfig-u5-03 .t{fill:#E6E8ED}html.dark #dsfig-u5-03 .t.inv{fill:#0F1115}html.dark #dsfig-u5-03 .kd{stroke:#E6E8ED}html.dark #dsfig-u5-03 .dot{fill:#E6E8ED}html.dark #dsfig-u5-03 .ann{fill:#8FA3FF}html.dark #dsfig-u5-03 .lbl{fill:#858D9C}html.dark #dsfig-u5-03 .ptr{fill:#8FA3FF}html.dark #dsfig-u5-03 .ah{fill:#B1B7C3}html.dark #dsfig-u5-03 .ah.hi{fill:#8FA3FF}html.dark #dsfig-u5-03 .wl rect{fill:#161920;stroke:#2A2E37}html.dark #dsfig-u5-03 .wl.hi rect{fill:#8FA3FF;stroke:#8FA3FF}html.dark #dsfig-u5-03 .wl.hi .t{fill:#0F1115}</style><defs><marker id="ah4" viewBox="0 0 10 10" refX="9" refY="5" markerWidth="7" markerHeight="7" orient="auto-start-reverse"><path class="ah" d="M0,1 L9,5 L0,9 z"/></marker><marker id="ahh4" viewBox="0 0 10 10" refX="9" refY="5" markerWidth="7" markerHeight="7" orient="auto-start-reverse"><path class="ah hi" d="M0,1 L9,5 L0,9 z"/></marker></defs><path class="e" d="M59,40 L191,40" marker-end="url(#ah4)"/><path class="e" d="M231,40 L356,40" marker-end="url(#ah4)"/><circle class="n" cx="40" cy="40" r="18"/><text class="t" x="40" y="40" dy=".35em" text-anchor="middle">Cli</text><circle class="n" cx="212" cy="40" r="18"/><text class="t" x="212" y="40" dy=".35em" text-anchor="middle">Ctr</text><rect class="n" x="359" y="25" width="50" height="30" rx="15"/><text class="t" x="384" y="40" dy=".35em" text-anchor="middle">Bean</text></svg><figcaption style="font-size:.82em;opacity:.72;margin-top:.45rem">EJB call path - the client calls the bean through the EJB container, which adds transaction, security and pooling</figcaption></figure>
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
<span style="display:inline-block;padding:.16em .6em;border:1.5px solid currentColor;border-radius:999px;font-size:.68em;font-weight:700;letter-spacing:.06em;text-transform:uppercase;opacity:.75">Not asked since 2022</span>
Definition. <mark>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.</mark>
Diagram.
<figure class="ds-fig" style="margin:1.4rem 0;overflow-x:auto"><svg xmlns="http://www.w3.org/2000/svg" id="dsfig-u5-04" viewBox="0 0 255 130" width="255" height="130" role="img" aria-label="tree diagram"><style>#dsfig-u5-04 .e{stroke:#454C5A;stroke-width:1.4;fill:none}#dsfig-u5-04 .e.hi{stroke:#2340B8;stroke-width:2.6}#dsfig-u5-04 .n{fill:#FFFFFF;stroke:#16181D;stroke-width:1.4}#dsfig-u5-04 .n.hi{fill:#E3E9FC;stroke:#2340B8;stroke-width:2.2}#dsfig-u5-04 .n.rb-b{fill:#16181D;stroke:#16181D}#dsfig-u5-04 .n.rb-r{fill:#BD3227;stroke:#BD3227}#dsfig-u5-04 text{font-family:"JetBrains Mono",ui-monospace,Menlo,Consolas,monospace;font-size:13px}#dsfig-u5-04 .t{fill:#16181D;font-weight:500}#dsfig-u5-04 .t.inv{fill:#FFFFFF;font-weight:700}#dsfig-u5-04 .kd{stroke:#16181D;stroke-width:1.2}#dsfig-u5-04 .dot{fill:#16181D}#dsfig-u5-04 .ann{fill:#2340B8;font-size:11px;font-weight:700}#dsfig-u5-04 .lbl{fill:#6F7787;font-family:system-ui,-apple-system,sans-serif;font-size:12px;font-weight:700}#dsfig-u5-04 .ptr{fill:#2340B8;font-size:12px;font-weight:700}#dsfig-u5-04 .ah{fill:#454C5A}#dsfig-u5-04 .ah.hi{fill:#2340B8}#dsfig-u5-04 .wl rect{fill:#FFFFFF;stroke:#DCE0E7}#dsfig-u5-04 .wl .t{font-size:12px;font-weight:700}#dsfig-u5-04 .wl.hi rect{fill:#2340B8;stroke:#2340B8}#dsfig-u5-04 .wl.hi .t{fill:#FFFFFF}html.dark #dsfig-u5-04 .e{stroke:#B1B7C3}html.dark #dsfig-u5-04 .e.hi{stroke:#8FA3FF}html.dark #dsfig-u5-04 .n{fill:#161920;stroke:#E6E8ED}html.dark #dsfig-u5-04 .n.hi{fill:#1E2748;stroke:#8FA3FF}html.dark #dsfig-u5-04 .n.rb-b{fill:#E6E8ED;stroke:#E6E8ED}html.dark #dsfig-u5-04 .n.rb-r{fill:#FF7E71;stroke:#FF7E71}html.dark #dsfig-u5-04 .t{fill:#E6E8ED}html.dark #dsfig-u5-04 .t.inv{fill:#0F1115}html.dark #dsfig-u5-04 .kd{stroke:#E6E8ED}html.dark #dsfig-u5-04 .dot{fill:#E6E8ED}html.dark #dsfig-u5-04 .ann{fill:#8FA3FF}html.dark #dsfig-u5-04 .lbl{fill:#858D9C}html.dark #dsfig-u5-04 .ptr{fill:#8FA3FF}html.dark #dsfig-u5-04 .ah{fill:#B1B7C3}html.dark #dsfig-u5-04 .ah.hi{fill:#8FA3FF}html.dark #dsfig-u5-04 .wl rect{fill:#161920;stroke:#2A2E37}html.dark #dsfig-u5-04 .wl.hi rect{fill:#8FA3FF;stroke:#8FA3FF}html.dark #dsfig-u5-04 .wl.hi .t{fill:#0F1115}</style><defs><marker id="ah5" viewBox="0 0 10 10" refX="9" refY="5" markerWidth="7" markerHeight="7" orient="auto-start-reverse"><path class="ah" d="M0,1 L9,5 L0,9 z"/></marker><marker id="ahh5" viewBox="0 0 10 10" refX="9" refY="5" markerWidth="7" markerHeight="7" orient="auto-start-reverse"><path class="ah hi" d="M0,1 L9,5 L0,9 z"/></marker></defs><line class="e" x1="111.8" y1="37" x2="40" y2="101"/><line class="e" x1="111.8" y1="37" x2="108" y2="101"/><line class="e" x1="111.8" y1="37" x2="183.5" y2="101"/><rect class="n" x="74.3" y="22" width="75" height="30" rx="8"/><text class="t" x="111.8" y="37" dy=".35em" text-anchor="middle">student</text><rect class="n" x="14" y="86" width="52" height="30" rx="8"/><text class="t" x="40" y="101" dy=".35em" text-anchor="middle">name</text><rect class="n" x="82" y="86" width="52" height="30" rx="8"/><text class="t" x="108" y="101" dy=".35em" text-anchor="middle">roll</text><rect class="n" x="150" y="86" width="67" height="30" rx="8"/><text class="t" x="183.5" y="101" dy=".35em" text-anchor="middle">branch</text></svg></figure>
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).