SlideShare une entreprise Scribd logo
1  sur  44
Télécharger pour lire hors ligne
Use of Java™ Technology-Based Class Loaders
to Design and Implement a Java Platform,
Micro Edition (JavaME™ Platform) Container
  Christian Kurzke, Developer Platforms Architect, Motorola Inc.
  Gustavo de Paula, Senior Consultant for Wireless
  Technologies, C.E.S.A.R
  TS-7575, JavaSE™ and Cool Stuff
Learn the characteristics of an application
container and understand how to design a
JavaTM Platform, Micro Edition (Java ME)
container using Java Platform, Standard Edition
(Java SE) Class Loaders




                                  2008 JavaOneSM Conference | java.sun.com/javaone |   2
Motivation

 Today most of the hand-held devices in the world include a
 Java virtual machine...
 But the Java platform defines different application models,
 such as MIDlet, Applet, etc.
      Applet       MIDlet             Xlet    ...         etc.


                            Java VM


                        Hand-held OS


 Challenge: How to design a solution that enables different
 Application Models on top of the same Java virtual
 machine base?
                                             2008 JavaOneSM Conference | java.sun.com/javaone |   3
Agenda

 Application Model
 Application Container
 Java Class Loaders
 Motorola Java ME Platform Emulator Scenario
 Main Issues in Java ME Container Design
 Conclusions




                                        2008 JavaOneSM Conference | java.sun.com/javaone |   4
Application Model


           main()               Running                   finished


Usual Java Application Execution model is very simple:
  • Run a Java Class
  • There is a single “Running” State
      • Entered when public static void       main(String[]args) is called
      • Exits when the method finishes
   • All JRE is available to the Java class

The Application Model defines
   • The main execution entity
   • The life cycle of this execution entity (states, events and transitions)
   • The runtime environment
                                                        2008 JavaOneSM Conference | java.sun.com/javaone |   5
Application Model
Java ME Platform Architecture




                                                                  Figure 2 in REF [1]


 Java ME platform defines two configurations and a set of
 different profiles
 Four different application models are supported
                                          2008 JavaOneSM Conference | java.sun.com/javaone |   6
Application Model
Mobile Information Device Profile Application Model
 MIDP is one of the Java ME
 platform Profiles
  • Defines a “new” Application
    model called MIDlet
 Runs on top of CLDC/KVM
 Defines the concept of optional
 package
  • Different devices might have a
    different set of JSRs
  • But: All devices support the
    same MIDlet Application model


                                                                              See REF [2]




                                       2008 JavaOneSM Conference | java.sun.com/javaone |   7
Application Model
MIDlet Application Model
 Execution entity is a MIDlet
  • extends the class
    javax.microedition.midlet.MIDl
    et
 Life cycle defines 3 states
  • Paused
  • Active
  • Destroyed
 The runtime platform is
  • MIDP/CLDC/KVM
  • Optional packages
                                                                            See REF [3]




                                     2008 JavaOneSM Conference | java.sun.com/javaone |   8
Application Model
MIDP/CLDC/KVM vs. Java SE Platform
MIDP/CLDC/KVM                    Java SE platform

 Limited VM (limited error         Full Java SE technology-based API
 handling, threadgroups, etc.)     support
 No JNI support                    Simplified Application model (not
 No user defined class loaders     managed)
 No reflection                     All features that are not supported
 No Object.finalize()              on Java ME platform
 Managed Application model
 (MIDlet)




                                             2008 JavaOneSM Conference | java.sun.com/javaone |   9
Agenda

 Application Model
 Application Container
 Java Class Loaders
 Motorola Java ME Platform Emulator Scenario
 Main Issues in Java ME Container Design
 Conclusions




                                        2008 JavaOneSM Conference | java.sun.com/javaone |   10
Application Container
       App 1        App 2          App 3          App X

                      Application Container


                              Java VM


                            Hand-held OS
 The container is directly associated to a specific life cycle
 It is responsible to
  • Implements the Application model specification
  • Manage the application life cycle
  • Interact with “external components”
  • Provide the runtime environment
 Each application model, Xlet, MIDlet, etc., has a different
 container
                                              2008 JavaOneSM Conference | java.sun.com/javaone |   11
Application Container

 In order to design and implement a container, it is necessary
 to have
  • A mechanism to isolate the application runtime environment from the
    host runtime environment
  • A mechanism to load the application classes different from the
    container execution classes
                                                         Application
                                 App 1                   Classes

                                                                         Application
                         Runtime environment                             Runtime
                                                                               Container
                            Application Container                              Classes

                                                                              Host
                           JRE                                                Runtime
                                                    2008 JavaOneSM Conference | java.sun.com/javaone |   12
Application Container


 Java SE platform provides the a mechanism to implement
 those requirements
  • Java Class Loaders
 Java Class Loaders are part of the core Java SE platform
 Specification
  • Available since Java 1.0 platform




                                         2008 JavaOneSM Conference | java.sun.com/javaone |   13
Agenda

 Application Model
 Application Container
 Java Class Loaders
 Motorola Java ME Platform Emulator Scenario
 Main Issues in Java ME Container Design
 Conclusions




                                        2008 JavaOneSM Conference | java.sun.com/javaone |   14
Java Class Loaders

 A class loader is the VM component that has 3 main services
  • Know where to find the class files, optionally packaged as JAR files
  • Find one specific class inside the JARs
  • Load this class or resource inside the VM execution environment

 Class loader is deeply related to Java virtual machine
  • Inheritance hierarchies resolved and class definitions are located by VM
  • Classes are interpreted byte code

 Class loading mechanism is similar to the operating system
 dynamic library loading mechanism



                                                  2008 JavaOneSM Conference | java.sun.com/javaone |   15
Java Class Loaders

                    File system
                                  4 different types of class
Resolution
Priority
                                    loaders
                                    Boot class loader is the initial
     Bootstrap                      class loader
                    Core APIs
    Class loader
                                     • Implemented in native code
    Extensions
                    Extensions       • Loads all “Core” APIs
    Class loader
                                    User defined class loader
      System        Classpath       extend the system class
    Class loader     classes        loader
     User-defined                    • Application classes customized
                      Other            loading mechanism
     Class loader
                                    Core APIs and extensions are
                                    “protected” inside the VM
                                     • Those classes cannot be loaded
                                       by other class loaders
                                            2008 JavaOneSM Conference | java.sun.com/javaone |   16
Java Class Loaders
Code Sample - loadClass
  // verify if it was already loaded
  clazz = findLoadedClass(name);          Check if the class
  if (clazz != null) {                    is already loaded
         return clazz;
  }
  try {                                   Find the Class
         clazz = findClass(name);
  } catch (ClassNotFoundException e) {                    If can't find,
         clazz = findSystemClass(name);                   check on system
  }                                                       classpath
  if (resolve) {
         resolveClass(clazz);
  }
  return clazz;




                                          2008 JavaOneSM Conference | java.sun.com/javaone |   17
Java Class Loaders
Code Sample - findClass
 String path = classname.replace('.', '/') + ".class";
 byte[] raw = null;
 for (int i = 0; i < CLASSPATH.length; i++) {
   JarEntry classFile=                         Get one entry on
       CLASSPATH[i].getJarEntry(path);         the class path and
   if (classFile != null){                     search file
     try {
       raw = readFromJAR(CLASSPATH[i],             Read the Class
           classFile);                             bytes
       break;
     } catch (IOException e) {
       throw new ClassNotFoundException("", e);
     }
   }
 }
 if (raw == null) {
        throw new ClassNotFoundException("" + name);
 }
 return defineClass(name, raw, 0,         Define the class
       raw.length);
                                           2008 JavaOneSM Conference | java.sun.com/javaone |   18
Java Class Loaders
Class Loader on Java ME platform (CLDC)
 CLDC does not allow user-defined class loaders
 When a MIDlet is running, the only class loader is the main
 KVM loader
  • Similar to the bootstrap class loader

 KVM Class loader only load
  • Core KVM classes (CLDC, MIDP)
  • Optional packages
  • MIDlet JAR




                                          2008 JavaOneSM Conference | java.sun.com/javaone |   19
Agenda

 Application Model
 Application Container
 Java Class Loaders
 Motorola Java ME Platform Emulator Scenario
 Main Issues in Java ME Container Design
 Conclusions




                                        2008 JavaOneSM Conference | java.sun.com/javaone |   20
Motorola Java ME Platform Emulator Scenario

 Motorola supports different device platforms according to the
 target market
  • Low tier: Motorola OS
  • High tier: MOTOMAGX (Linux)
  • Multi-media device: UIQ (Symbian)
  • Productivity Device: Windows Mobile

 MIDlet Application Model is supported on ALL platforms

 But each platform has a different set of supported JSRs and
 hardware capabilities



                                          2008 JavaOneSM Conference | java.sun.com/javaone |   21
Motorola Java ME Platform Emulator Scenario

                                              Motorola OS
    Linux OS
                                              Crypto API
    Media Streaming
                                              Bluetooth API
    WMA 2.0



                       Windows Mobile OS
                       Bluetooth API
                       Location API


 A Motorola Java ME platform Emulator needs to address
 those different kinds of devices
  • Same Application model, but with different runtime platform
 An application model container is the best solution for that

                                            2008 JavaOneSM Conference | java.sun.com/javaone |   22
Motorola Java ME Platform Emulator
MoJa Container Requirements
    UEI Compliant IDE
                         Motorola Java ME Container

                         Single Application Model, MIDlet, but
                         different platforms and devices
                         Host runtime platform is the Java SE
                         platform
     MoJa Container
                         Allow that each device can define its
                         own set of supported APIs
                         Integrated on any UEI Compliant IDE
                         Loads the MIDlet and the JSRs
                         classes

          JRE


                                        2008 JavaOneSM Conference | java.sun.com/javaone |   23
Agenda

 Application Model
 Application Container
 Java Class Loaders
 Motorola Java ME Platform Emulator Scenario
 Main Issues in Java ME Container Design
 Conclusions




                                        2008 JavaOneSM Conference | java.sun.com/javaone |   24
Main Issues in Java ME Platform Container Design
High Level View

        MIDlet JAR
                              MoJa Container can access ALL
                              Java SE APIs
                              MIDP and JSRs implementation
 MIDP & JSRs Implementation   can
                               • Access each other
                               • Access the container internal classes
                               • Access all Java SE APIs
             MoJa Container   MIDlet JAR can
                               • Access its own classes
                               • Access the MIDP & JSRs Interfaces

  Java VM & JavaSE APIs


                                             2008 JavaOneSM Conference | java.sun.com/javaone |   25
Main Issues in Java ME Platform Container Design
Four Issues
  How to represent each specific JSR?
  How to represent each Device?
  How to handle the MIDlet suite under execution?
  How to separate the Java ME platform from the Java SE
  platform?




                                          2008 JavaOneSM Conference | java.sun.com/javaone |   26
Issue 1: How to represent each specific JSR?

 CLDC/MIDP Architecture Define the Concept of Optional
 Packages (JSR)
  • Depends on CLDC and/or MIDP and there is no dependency between
    each other

 Solution
  • Define a common platform (supported by ALL devices)
  • Design each JSR as a separated JAR that depends only on the common
    platform




                                                2008 JavaOneSM Conference | java.sun.com/javaone |   27
How to represent each specific JSR?
JSRs Logical View

    JSRWWW    JSRXXX    JSRYYY      JSRZZZ                   etc...


                    Common MIDP Platform



  MoJa Common platform is CLDC, MIDP, JSR 75 (File System)
  and JSR 135
   • Common platform can be organized in a single JAR file
  Each other JSR can have its own JAR
  MoJa Container will have a base of JSRs that it supports



                                             2008 JavaOneSM Conference | java.sun.com/javaone |   28
Issue 2: How to represent each Device?
 Each device must indicate the set of JSRs that it supports from
 the JSRs Base
 MoJa Container has two main components that handles the
 device representation
  • DeviceHandler                                     JSRs Base
  • JMELoader
                                                                       JSRWWW

                 JSRWWW                                                  JSRXXX
  Device A       JSRYYY          DeviceHandler
                 JSRZZZ
                                                                         JSRYYY


                                                                         JSRZZZ
                                  JMELoader


                                              2008 JavaOneSM Conference | java.sun.com/javaone |   29
How to represent each Device?

 Each device is represented by a property/XML file
  • List all the JSRs supported by that device

 DeviceHandler is responsible to
  • Parser the device property file that list all supported JSRs
  • Go to the JSRs base
  • Locate JSR JARs
  • Start the JMELoader pointing to ALL Device JSRs

 JMELoader is responsible to
  • Find classes inside the JSRs JARs
  • Load classes inside the JSRs JARs


                                                     2008 JavaOneSM Conference | java.sun.com/javaone |   30
Issue 3: How to handle the MIDlet suite under
execution?
  A MIDlet suite is represented by its
   • Java Application Descriptor (JAD File)
   • JAR File
  The Suite JAR has all classes and resources that are necessary
  to execute the MIDlet
  MoJa Container has two main components that handles the
  device representation
   • DeviceHandler
   • MIDletLoader
MIDlet                        DeviceHandler                MIDletLoader
Suite            JAD File




                 JAR File
                                              2008 JavaOneSM Conference | java.sun.com/javaone |   31
How to handle the MIDlet suite under execution?

 When the MIDlet is executed, the DeviceHandler is
 responsible to
  • Read / Parse the Suite JAD file
  • Locate the Suite JAR File
  • Start the MIDletLoader pointing to the MIDlet JAR File
  • Create the MIDlet it self and manage its state transitions

 MIDletLoader is responsible to
  • Find classes inside the MIDlet JAR
  • Load classes inside the MIDlet JAR

 MIDletLoader the only responsible to load MIDlet classes
 / resources

                                               2008 JavaOneSM Conference | java.sun.com/javaone |   32
Issue 4: How to separate the Java ME
platform from the Java SE platform?
MIDlet Tries to Load a Class
  MIDletLoader and JMELoader Class Loaders both avoid
  the MIDlet from accessing any non Java ME class
  JMELoader class loader allow access to all Java SE classes
   • But MIDletLoader doesn't
                                    MIDletLoader
                 MIDlet JAR         works here

                                             JMELoader
         JSRs and Common Platform            works here

                MoJa Container

                   JRE

                                            2008 JavaOneSM Conference | java.sun.com/javaone |   33
How to separate the Java ME platform
from the Java SE platform?
MIDlet Tries to Load a Class

  MIDletLoader execute the following steps to load a class
  1. Check if the class is inside the MIDlet JAR
  2. If it is not, ask JMELoader to load the class (JSRs JARs)
  3. If the class is not found until step 2, a ClassNotFoundException
     is returned

  JMELoader execute the following steps
  1. Check if the class is inside the JSRs JARs;
  2. If it is not, check if the class is inside the Common Platform;
  3. If it is not, ask the system class loader to load the class;
  4. If the class is not found until step 3, a ClassNotFoundException
     is returned.


                                               2008 JavaOneSM Conference | java.sun.com/javaone |   34
Main Issues in Java ME Platform Container Design
Summarized Answers
 How to represent each specific JSR?
  • MoJa has a common platform
  • Each JSR has it own JAR that depends on the common platform
 How to represent each Device?
  • Device property represents a device
  • DeviceHandler understands the device property file
  • JMELoader loads all JSRs JARs
 How to handle the MIDlet suite under execution?
  • DeviceHandler manage the MIDlet execution
  • MIDletLoader loads the MIDlet JAR
 How to separate the Java ME platform from the Java SE
 platform?
  • MIDletLoader only allow access to MIDlet and JSR classes
  • JMELoader allow access to JSRs and JRE classes
                                               2008 JavaOneSM Conference | java.sun.com/javaone |   35
MoJa Container Architecture
High Level Logical View
                                 3 levels of class loaders
 MoJa Container




                  MIDletLoader
                                 MIDletLoader
                                  • Knows how to load all MIDlet suite
                                    specific classes and resources
                  JMELoader

                                 JMELoader
                                  • Knows how to load all JSR specific
                                    classes and resources
 Java VM




                    JavaSE
                  Class loader
                                 Java SE System Class Loader
                                  • Knows how to load all Java SE
                                    classes and resources


                                                2008 JavaOneSM Conference | java.sun.com/javaone |   36
MoJa Container Architecture
Load Class Sequence Diagram
Load MIDlet
   Class
Load JSR
  Class




                              2008 JavaOneSM Conference | java.sun.com/javaone |   37
MoJa Container Architecture
JMELoader Entry Points
 While the MIDlet is under execution, there are two main
 entry points on the JMELoader
  • loadClass(): usual load class method. Used by all classes that were
    loaded by JMELoader
  • loadMEClass(): specific load class method that only check for
    classes inside the OPs & Platform.

 loadMEClass() method guarantees that only Java ME
 classes are accessed by the MIDlet

       JSR JAR                                          MIDlet JAR



             loadClass       JMELoader       loadMEClass

                                               2008 JavaOneSM Conference | java.sun.com/javaone |   38
MoJa Container Architecture
MIDletLoader.loadClass() Code Sample
  // verify if it was already loaded
  clazz = findLoadedClass(name);
  if (clazz != null) return clazz;

  try {
    // try to find the class on MIDlet JAR classpath
    clazz = findClass(name);
  } catch (ClassNotFoundException e) {        Check MIDlet JAR
    try {
      // try to find the class on Java ME library
      clazz = getJMELoader().loadMEClass(name, resolve);
    } catch (Exception exc) {                  Check JSRs &
      throw new ClassNotFoundException();      Platform
    }
    if (clazz == null) throw new ClassNotFoundException("”);
  }
  return clazz;

                                         2008 JavaOneSM Conference | java.sun.com/javaone |   39
MoJa Container Architecture
JMELoader.loadClass() Code Sample
  // verify if it was already loaded
  clazz = findLoadedClass(name);
  if (clazz != null) return clazz;

  // try to find the class on java me library
  try {
    clazz = findClass(name);                  Check JSRs & Platform
  } catch (ClassNotFoundException e) {
    //try to find the class from the system
    clazz = findSystemClass(name);             Check JRE
  }
  return clazz;




                                           2008 JavaOneSM Conference | java.sun.com/javaone |   40
Agenda

 Application Model
 Application Container
 Java Class Loaders
 Motorola Java ME Platform Emulator Scenario
 Main Issues in Java ME Container Design
 Conclusions




                                        2008 JavaOneSM Conference | java.sun.com/javaone |   41
Conclusions

 Java platform allows many different application models
 Each application model has its own particularities
 An application model container provides the necessary
 concepts to isolate each model particularities from the
 underlaying platform
 Java ME platform defines the MIDlet application models that
 can be implemented on top of a Java SE platform
 Java SE classes loader is a powerful mechanism that can be
 used to implement a Java ME container




                                         2008 JavaOneSM Conference | java.sun.com/javaone |   42
For More Information

(1)A Survey of Java ME Today (Update)
  http://developers.sun.com/mobility/getstart/articles/survey/
(2)Sun Mobile Device Technology - Introduction to Mobility Java
  Technology http://developers.sun.com/mobility/getstart/
(3)MIDP Javadocs
  http://java.sun.com/javame/reference/apis/jsr118/




                                          2008 JavaOneSM Conference | java.sun.com/javaone |   43
Christian Kurzke, Developer Platforms Architect, Motorola
Inc.
Gustavo de Paula, Senior Consultant for Wireless
Technologies, C.E.S.A.R

TS-7575, JavaSE and Cool Stuff




                                       2008 JavaOneSM Conference | java.sun.com/javaone |   44

Contenu connexe

Tendances

Introduction to java
Introduction to javaIntroduction to java
Introduction to javaAjay Sharma
 
Introduction to java (revised)
Introduction to java (revised)Introduction to java (revised)
Introduction to java (revised)Sujit Majety
 
1 java programming- introduction
1  java programming- introduction1  java programming- introduction
1 java programming- introductionjyoti_lakhani
 
Introduction to Java Programming
Introduction to Java Programming Introduction to Java Programming
Introduction to Java Programming Saravanakumar R
 
Introduction to java
Introduction to java Introduction to java
Introduction to java Sandeep Rawat
 
Basics of java programming language
Basics of java programming languageBasics of java programming language
Basics of java programming languagemasud33bd
 
Java Tutorial For Beginners - Step By Step | Java Basics | Java Certification...
Java Tutorial For Beginners - Step By Step | Java Basics | Java Certification...Java Tutorial For Beginners - Step By Step | Java Basics | Java Certification...
Java Tutorial For Beginners - Step By Step | Java Basics | Java Certification...Edureka!
 
Modules all the way down: OSGi and the Java Platform Module System
Modules all the way down: OSGi and the Java Platform Module SystemModules all the way down: OSGi and the Java Platform Module System
Modules all the way down: OSGi and the Java Platform Module SystemTim Ellison
 
Introduction to java
Introduction to java Introduction to java
Introduction to java Java Lover
 
Java Threads Tutorial | Multithreading In Java Tutorial | Java Tutorial For B...
Java Threads Tutorial | Multithreading In Java Tutorial | Java Tutorial For B...Java Threads Tutorial | Multithreading In Java Tutorial | Java Tutorial For B...
Java Threads Tutorial | Multithreading In Java Tutorial | Java Tutorial For B...Edureka!
 
java tutorial for beginner - Free Download
java tutorial for beginner - Free Downloadjava tutorial for beginner - Free Download
java tutorial for beginner - Free DownloadTIB Academy
 
Introduction to java
Introduction to javaIntroduction to java
Introduction to javajayc8586
 
Chapter 1 introduction to java technology
Chapter 1 introduction to java technologyChapter 1 introduction to java technology
Chapter 1 introduction to java technologysshhzap
 
Skillwise Elementary Java Programming
Skillwise Elementary Java ProgrammingSkillwise Elementary Java Programming
Skillwise Elementary Java ProgrammingSkillwise Group
 
Learn Java with Dr. Rifat Shahriyar
Learn Java with Dr. Rifat ShahriyarLearn Java with Dr. Rifat Shahriyar
Learn Java with Dr. Rifat ShahriyarAbir Mohammad
 

Tendances (20)

Introduction to java
Introduction to javaIntroduction to java
Introduction to java
 
Introduction to java (revised)
Introduction to java (revised)Introduction to java (revised)
Introduction to java (revised)
 
1 java programming- introduction
1  java programming- introduction1  java programming- introduction
1 java programming- introduction
 
Java9
Java9Java9
Java9
 
Introduction to Java Programming
Introduction to Java Programming Introduction to Java Programming
Introduction to Java Programming
 
Introduction to java
Introduction to java Introduction to java
Introduction to java
 
Learn Java Part 1
Learn Java Part 1Learn Java Part 1
Learn Java Part 1
 
perl-java
perl-javaperl-java
perl-java
 
Basics of java programming language
Basics of java programming languageBasics of java programming language
Basics of java programming language
 
Java Tutorial For Beginners - Step By Step | Java Basics | Java Certification...
Java Tutorial For Beginners - Step By Step | Java Basics | Java Certification...Java Tutorial For Beginners - Step By Step | Java Basics | Java Certification...
Java Tutorial For Beginners - Step By Step | Java Basics | Java Certification...
 
Java basics notes
Java basics notesJava basics notes
Java basics notes
 
Modules all the way down: OSGi and the Java Platform Module System
Modules all the way down: OSGi and the Java Platform Module SystemModules all the way down: OSGi and the Java Platform Module System
Modules all the way down: OSGi and the Java Platform Module System
 
Introduction to java
Introduction to java Introduction to java
Introduction to java
 
Java Threads Tutorial | Multithreading In Java Tutorial | Java Tutorial For B...
Java Threads Tutorial | Multithreading In Java Tutorial | Java Tutorial For B...Java Threads Tutorial | Multithreading In Java Tutorial | Java Tutorial For B...
Java Threads Tutorial | Multithreading In Java Tutorial | Java Tutorial For B...
 
Java modules
Java modulesJava modules
Java modules
 
java tutorial for beginner - Free Download
java tutorial for beginner - Free Downloadjava tutorial for beginner - Free Download
java tutorial for beginner - Free Download
 
Introduction to java
Introduction to javaIntroduction to java
Introduction to java
 
Chapter 1 introduction to java technology
Chapter 1 introduction to java technologyChapter 1 introduction to java technology
Chapter 1 introduction to java technology
 
Skillwise Elementary Java Programming
Skillwise Elementary Java ProgrammingSkillwise Elementary Java Programming
Skillwise Elementary Java Programming
 
Learn Java with Dr. Rifat Shahriyar
Learn Java with Dr. Rifat ShahriyarLearn Java with Dr. Rifat Shahriyar
Learn Java with Dr. Rifat Shahriyar
 

Similaire à Use of Java™ Technology-Based Class Loaders to Design and Implement a Java Platform, Micro Edition (JavaME™ Platform) Container

OOP with Java
OOP with JavaOOP with Java
OOP with JavaOmegaHub
 
Java Interview Questions Answers Guide
Java Interview Questions Answers GuideJava Interview Questions Answers Guide
Java Interview Questions Answers GuideDaisyWatson5
 
Java Programming and J2ME: The Basics
Java Programming and J2ME: The BasicsJava Programming and J2ME: The Basics
Java Programming and J2ME: The Basicstosine
 
JAVA_Day1_BasicIntroduction.pptx
JAVA_Day1_BasicIntroduction.pptxJAVA_Day1_BasicIntroduction.pptx
JAVA_Day1_BasicIntroduction.pptxMurugesh33
 
JAVAPart1_BasicIntroduction.pptx
JAVAPart1_BasicIntroduction.pptxJAVAPart1_BasicIntroduction.pptx
JAVAPart1_BasicIntroduction.pptxMurugesh33
 
Java programming basics
Java programming basicsJava programming basics
Java programming basicsHamid Ghorbani
 
A begineers guide of JAVA - Getting Started
 A begineers guide of JAVA - Getting Started A begineers guide of JAVA - Getting Started
A begineers guide of JAVA - Getting StartedRakesh Madugula
 
Java Virtual Machine - Internal Architecture
Java Virtual Machine - Internal ArchitectureJava Virtual Machine - Internal Architecture
Java Virtual Machine - Internal Architecturesubnesh
 
A Brief study on JVM A Brief study on JVM
A Brief study on JVM A Brief study on JVMA Brief study on JVM A Brief study on JVM
A Brief study on JVM A Brief study on JVMBRNSSPublicationHubI
 
Java For beginners and CSIT and IT students
Java  For beginners and CSIT and IT studentsJava  For beginners and CSIT and IT students
Java For beginners and CSIT and IT studentsPartnered Health
 
Development of Java tools using SWT and WALA af Hans Søndergaard, ViaUC
Development of Java tools using SWT and WALA af Hans Søndergaard, ViaUCDevelopment of Java tools using SWT and WALA af Hans Søndergaard, ViaUC
Development of Java tools using SWT and WALA af Hans Søndergaard, ViaUCInfinIT - Innovationsnetværket for it
 
Apache DeltaSpike
Apache DeltaSpikeApache DeltaSpike
Apache DeltaSpikeos890
 
Java questions and answers jan bask.net
Java questions and answers jan bask.netJava questions and answers jan bask.net
Java questions and answers jan bask.netJanbask ItTraining
 
Using the OSGi Application Model on Mobile Devices with CLDC JVM - Dimitar Va...
Using the OSGi Application Model on Mobile Devices with CLDC JVM - Dimitar Va...Using the OSGi Application Model on Mobile Devices with CLDC JVM - Dimitar Va...
Using the OSGi Application Model on Mobile Devices with CLDC JVM - Dimitar Va...mfrancis
 

Similaire à Use of Java™ Technology-Based Class Loaders to Design and Implement a Java Platform, Micro Edition (JavaME™ Platform) Container (20)

OOP with Java
OOP with JavaOOP with Java
OOP with Java
 
Java Interview Questions Answers Guide
Java Interview Questions Answers GuideJava Interview Questions Answers Guide
Java Interview Questions Answers Guide
 
oop unit1.pptx
oop unit1.pptxoop unit1.pptx
oop unit1.pptx
 
Java Programming and J2ME: The Basics
Java Programming and J2ME: The BasicsJava Programming and J2ME: The Basics
Java Programming and J2ME: The Basics
 
JAVA_Day1_BasicIntroduction.pptx
JAVA_Day1_BasicIntroduction.pptxJAVA_Day1_BasicIntroduction.pptx
JAVA_Day1_BasicIntroduction.pptx
 
JAVAPart1_BasicIntroduction.pptx
JAVAPart1_BasicIntroduction.pptxJAVAPart1_BasicIntroduction.pptx
JAVAPart1_BasicIntroduction.pptx
 
CS8392 OOP
CS8392 OOPCS8392 OOP
CS8392 OOP
 
Java programming basics
Java programming basicsJava programming basics
Java programming basics
 
A begineers guide of JAVA - Getting Started
 A begineers guide of JAVA - Getting Started A begineers guide of JAVA - Getting Started
A begineers guide of JAVA - Getting Started
 
Java Virtual Machine - Internal Architecture
Java Virtual Machine - Internal ArchitectureJava Virtual Machine - Internal Architecture
Java Virtual Machine - Internal Architecture
 
A Brief study on JVM A Brief study on JVM
A Brief study on JVM A Brief study on JVMA Brief study on JVM A Brief study on JVM
A Brief study on JVM A Brief study on JVM
 
Java For beginners and CSIT and IT students
Java  For beginners and CSIT and IT studentsJava  For beginners and CSIT and IT students
Java For beginners and CSIT and IT students
 
Java Class Loader
Java Class LoaderJava Class Loader
Java Class Loader
 
Development of Java tools using SWT and WALA af Hans Søndergaard, ViaUC
Development of Java tools using SWT and WALA af Hans Søndergaard, ViaUCDevelopment of Java tools using SWT and WALA af Hans Søndergaard, ViaUC
Development of Java tools using SWT and WALA af Hans Søndergaard, ViaUC
 
Java Tutorial 1
Java Tutorial 1Java Tutorial 1
Java Tutorial 1
 
Apache DeltaSpike
Apache DeltaSpikeApache DeltaSpike
Apache DeltaSpike
 
Introduction java programming
Introduction java programmingIntroduction java programming
Introduction java programming
 
Introduction to java
Introduction to javaIntroduction to java
Introduction to java
 
Java questions and answers jan bask.net
Java questions and answers jan bask.netJava questions and answers jan bask.net
Java questions and answers jan bask.net
 
Using the OSGi Application Model on Mobile Devices with CLDC JVM - Dimitar Va...
Using the OSGi Application Model on Mobile Devices with CLDC JVM - Dimitar Va...Using the OSGi Application Model on Mobile Devices with CLDC JVM - Dimitar Va...
Using the OSGi Application Model on Mobile Devices with CLDC JVM - Dimitar Va...
 

Plus de gustavoeliano

Introduction to Trusted Virtual Client
Introduction to Trusted Virtual ClientIntroduction to Trusted Virtual Client
Introduction to Trusted Virtual Clientgustavoeliano
 
Modelo de Negociação Bilateral para Comércio Eletrônico
Modelo de Negociação Bilateral para Comércio EletrônicoModelo de Negociação Bilateral para Comércio Eletrônico
Modelo de Negociação Bilateral para Comércio Eletrônicogustavoeliano
 
Bilateral Negotiation Model for Agent Mediated Electronic Commerce
Bilateral Negotiation Model for Agent Mediated Electronic CommerceBilateral Negotiation Model for Agent Mediated Electronic Commerce
Bilateral Negotiation Model for Agent Mediated Electronic Commercegustavoeliano
 
Uma Arquitetura para Agentes Negociadores Baseada em Teoria dos Jogos
Uma Arquitetura para Agentes Negociadores Baseada em Teoria dos JogosUma Arquitetura para Agentes Negociadores Baseada em Teoria dos Jogos
Uma Arquitetura para Agentes Negociadores Baseada em Teoria dos Jogosgustavoeliano
 
Client Server Development – Problems in Supporting Different Wireless Platform
Client Server Development – Problems in Supporting Different Wireless PlatformClient Server Development – Problems in Supporting Different Wireless Platform
Client Server Development – Problems in Supporting Different Wireless Platformgustavoeliano
 
DSDP Mobile Tools for Java Webinar
DSDP Mobile Tools for Java WebinarDSDP Mobile Tools for Java Webinar
DSDP Mobile Tools for Java Webinargustavoeliano
 
Restructuring a Web Application, Using Spring and Hibernate
Restructuring a Web Application, Using Spring and HibernateRestructuring a Web Application, Using Spring and Hibernate
Restructuring a Web Application, Using Spring and Hibernategustavoeliano
 
DSDP Mobile Tools for Java Project
DSDP Mobile Tools for Java ProjectDSDP Mobile Tools for Java Project
DSDP Mobile Tools for Java Projectgustavoeliano
 
MOTODEV Studio for Testing A platform testing based on Eclipse
MOTODEV Studio for Testing A platform testing based on EclipseMOTODEV Studio for Testing A platform testing based on Eclipse
MOTODEV Studio for Testing A platform testing based on Eclipsegustavoeliano
 
MTJ Taking Mobile Java Developers to the Next Level
MTJ Taking Mobile Java Developers to the Next LevelMTJ Taking Mobile Java Developers to the Next Level
MTJ Taking Mobile Java Developers to the Next Levelgustavoeliano
 
Multi-Configuration support in MTJ
Multi-Configuration support in MTJMulti-Configuration support in MTJ
Multi-Configuration support in MTJgustavoeliano
 
469-Porting the build system of a commercial RCP Application from Europa to G...
469-Porting the build system of a commercial RCP Application from Europa to G...469-Porting the build system of a commercial RCP Application from Europa to G...
469-Porting the build system of a commercial RCP Application from Europa to G...gustavoeliano
 
DSDP Mobile Tools for Java New and Noteworthy
DSDP Mobile Tools for Java New and NoteworthyDSDP Mobile Tools for Java New and Noteworthy
DSDP Mobile Tools for Java New and Noteworthygustavoeliano
 
The Build System of Commercial RCP Application A Case Study
The Build System of Commercial RCP Application A Case StudyThe Build System of Commercial RCP Application A Case Study
The Build System of Commercial RCP Application A Case Studygustavoeliano
 
Re-structuring of a swing-based application into an Eclipse RCP
Re-structuring of a swing-based application into an Eclipse RCPRe-structuring of a swing-based application into an Eclipse RCP
Re-structuring of a swing-based application into an Eclipse RCPgustavoeliano
 
Mobile Tools for Java - Current Project Status
Mobile Tools for Java - Current Project StatusMobile Tools for Java - Current Project Status
Mobile Tools for Java - Current Project Statusgustavoeliano
 
Building XML-based content for Eclipse Help a real experience
Building XML-based content for Eclipse Help a real experienceBuilding XML-based content for Eclipse Help a real experience
Building XML-based content for Eclipse Help a real experiencegustavoeliano
 

Plus de gustavoeliano (17)

Introduction to Trusted Virtual Client
Introduction to Trusted Virtual ClientIntroduction to Trusted Virtual Client
Introduction to Trusted Virtual Client
 
Modelo de Negociação Bilateral para Comércio Eletrônico
Modelo de Negociação Bilateral para Comércio EletrônicoModelo de Negociação Bilateral para Comércio Eletrônico
Modelo de Negociação Bilateral para Comércio Eletrônico
 
Bilateral Negotiation Model for Agent Mediated Electronic Commerce
Bilateral Negotiation Model for Agent Mediated Electronic CommerceBilateral Negotiation Model for Agent Mediated Electronic Commerce
Bilateral Negotiation Model for Agent Mediated Electronic Commerce
 
Uma Arquitetura para Agentes Negociadores Baseada em Teoria dos Jogos
Uma Arquitetura para Agentes Negociadores Baseada em Teoria dos JogosUma Arquitetura para Agentes Negociadores Baseada em Teoria dos Jogos
Uma Arquitetura para Agentes Negociadores Baseada em Teoria dos Jogos
 
Client Server Development – Problems in Supporting Different Wireless Platform
Client Server Development – Problems in Supporting Different Wireless PlatformClient Server Development – Problems in Supporting Different Wireless Platform
Client Server Development – Problems in Supporting Different Wireless Platform
 
DSDP Mobile Tools for Java Webinar
DSDP Mobile Tools for Java WebinarDSDP Mobile Tools for Java Webinar
DSDP Mobile Tools for Java Webinar
 
Restructuring a Web Application, Using Spring and Hibernate
Restructuring a Web Application, Using Spring and HibernateRestructuring a Web Application, Using Spring and Hibernate
Restructuring a Web Application, Using Spring and Hibernate
 
DSDP Mobile Tools for Java Project
DSDP Mobile Tools for Java ProjectDSDP Mobile Tools for Java Project
DSDP Mobile Tools for Java Project
 
MOTODEV Studio for Testing A platform testing based on Eclipse
MOTODEV Studio for Testing A platform testing based on EclipseMOTODEV Studio for Testing A platform testing based on Eclipse
MOTODEV Studio for Testing A platform testing based on Eclipse
 
MTJ Taking Mobile Java Developers to the Next Level
MTJ Taking Mobile Java Developers to the Next LevelMTJ Taking Mobile Java Developers to the Next Level
MTJ Taking Mobile Java Developers to the Next Level
 
Multi-Configuration support in MTJ
Multi-Configuration support in MTJMulti-Configuration support in MTJ
Multi-Configuration support in MTJ
 
469-Porting the build system of a commercial RCP Application from Europa to G...
469-Porting the build system of a commercial RCP Application from Europa to G...469-Porting the build system of a commercial RCP Application from Europa to G...
469-Porting the build system of a commercial RCP Application from Europa to G...
 
DSDP Mobile Tools for Java New and Noteworthy
DSDP Mobile Tools for Java New and NoteworthyDSDP Mobile Tools for Java New and Noteworthy
DSDP Mobile Tools for Java New and Noteworthy
 
The Build System of Commercial RCP Application A Case Study
The Build System of Commercial RCP Application A Case StudyThe Build System of Commercial RCP Application A Case Study
The Build System of Commercial RCP Application A Case Study
 
Re-structuring of a swing-based application into an Eclipse RCP
Re-structuring of a swing-based application into an Eclipse RCPRe-structuring of a swing-based application into an Eclipse RCP
Re-structuring of a swing-based application into an Eclipse RCP
 
Mobile Tools for Java - Current Project Status
Mobile Tools for Java - Current Project StatusMobile Tools for Java - Current Project Status
Mobile Tools for Java - Current Project Status
 
Building XML-based content for Eclipse Help a real experience
Building XML-based content for Eclipse Help a real experienceBuilding XML-based content for Eclipse Help a real experience
Building XML-based content for Eclipse Help a real experience
 

Use of Java™ Technology-Based Class Loaders to Design and Implement a Java Platform, Micro Edition (JavaME™ Platform) Container

  • 1. Use of Java™ Technology-Based Class Loaders to Design and Implement a Java Platform, Micro Edition (JavaME™ Platform) Container Christian Kurzke, Developer Platforms Architect, Motorola Inc. Gustavo de Paula, Senior Consultant for Wireless Technologies, C.E.S.A.R TS-7575, JavaSE™ and Cool Stuff
  • 2. Learn the characteristics of an application container and understand how to design a JavaTM Platform, Micro Edition (Java ME) container using Java Platform, Standard Edition (Java SE) Class Loaders 2008 JavaOneSM Conference | java.sun.com/javaone | 2
  • 3. Motivation Today most of the hand-held devices in the world include a Java virtual machine... But the Java platform defines different application models, such as MIDlet, Applet, etc. Applet MIDlet Xlet ... etc. Java VM Hand-held OS Challenge: How to design a solution that enables different Application Models on top of the same Java virtual machine base? 2008 JavaOneSM Conference | java.sun.com/javaone | 3
  • 4. Agenda Application Model Application Container Java Class Loaders Motorola Java ME Platform Emulator Scenario Main Issues in Java ME Container Design Conclusions 2008 JavaOneSM Conference | java.sun.com/javaone | 4
  • 5. Application Model main() Running finished Usual Java Application Execution model is very simple: • Run a Java Class • There is a single “Running” State • Entered when public static void main(String[]args) is called • Exits when the method finishes • All JRE is available to the Java class The Application Model defines • The main execution entity • The life cycle of this execution entity (states, events and transitions) • The runtime environment 2008 JavaOneSM Conference | java.sun.com/javaone | 5
  • 6. Application Model Java ME Platform Architecture Figure 2 in REF [1] Java ME platform defines two configurations and a set of different profiles Four different application models are supported 2008 JavaOneSM Conference | java.sun.com/javaone | 6
  • 7. Application Model Mobile Information Device Profile Application Model MIDP is one of the Java ME platform Profiles • Defines a “new” Application model called MIDlet Runs on top of CLDC/KVM Defines the concept of optional package • Different devices might have a different set of JSRs • But: All devices support the same MIDlet Application model See REF [2] 2008 JavaOneSM Conference | java.sun.com/javaone | 7
  • 8. Application Model MIDlet Application Model Execution entity is a MIDlet • extends the class javax.microedition.midlet.MIDl et Life cycle defines 3 states • Paused • Active • Destroyed The runtime platform is • MIDP/CLDC/KVM • Optional packages See REF [3] 2008 JavaOneSM Conference | java.sun.com/javaone | 8
  • 9. Application Model MIDP/CLDC/KVM vs. Java SE Platform MIDP/CLDC/KVM Java SE platform Limited VM (limited error Full Java SE technology-based API handling, threadgroups, etc.) support No JNI support Simplified Application model (not No user defined class loaders managed) No reflection All features that are not supported No Object.finalize() on Java ME platform Managed Application model (MIDlet) 2008 JavaOneSM Conference | java.sun.com/javaone | 9
  • 10. Agenda Application Model Application Container Java Class Loaders Motorola Java ME Platform Emulator Scenario Main Issues in Java ME Container Design Conclusions 2008 JavaOneSM Conference | java.sun.com/javaone | 10
  • 11. Application Container App 1 App 2 App 3 App X Application Container Java VM Hand-held OS The container is directly associated to a specific life cycle It is responsible to • Implements the Application model specification • Manage the application life cycle • Interact with “external components” • Provide the runtime environment Each application model, Xlet, MIDlet, etc., has a different container 2008 JavaOneSM Conference | java.sun.com/javaone | 11
  • 12. Application Container In order to design and implement a container, it is necessary to have • A mechanism to isolate the application runtime environment from the host runtime environment • A mechanism to load the application classes different from the container execution classes Application App 1 Classes Application Runtime environment Runtime Container Application Container Classes Host JRE Runtime 2008 JavaOneSM Conference | java.sun.com/javaone | 12
  • 13. Application Container Java SE platform provides the a mechanism to implement those requirements • Java Class Loaders Java Class Loaders are part of the core Java SE platform Specification • Available since Java 1.0 platform 2008 JavaOneSM Conference | java.sun.com/javaone | 13
  • 14. Agenda Application Model Application Container Java Class Loaders Motorola Java ME Platform Emulator Scenario Main Issues in Java ME Container Design Conclusions 2008 JavaOneSM Conference | java.sun.com/javaone | 14
  • 15. Java Class Loaders A class loader is the VM component that has 3 main services • Know where to find the class files, optionally packaged as JAR files • Find one specific class inside the JARs • Load this class or resource inside the VM execution environment Class loader is deeply related to Java virtual machine • Inheritance hierarchies resolved and class definitions are located by VM • Classes are interpreted byte code Class loading mechanism is similar to the operating system dynamic library loading mechanism 2008 JavaOneSM Conference | java.sun.com/javaone | 15
  • 16. Java Class Loaders File system 4 different types of class Resolution Priority loaders Boot class loader is the initial Bootstrap class loader Core APIs Class loader • Implemented in native code Extensions Extensions • Loads all “Core” APIs Class loader User defined class loader System Classpath extend the system class Class loader classes loader User-defined • Application classes customized Other loading mechanism Class loader Core APIs and extensions are “protected” inside the VM • Those classes cannot be loaded by other class loaders 2008 JavaOneSM Conference | java.sun.com/javaone | 16
  • 17. Java Class Loaders Code Sample - loadClass // verify if it was already loaded clazz = findLoadedClass(name); Check if the class if (clazz != null) { is already loaded return clazz; } try { Find the Class clazz = findClass(name); } catch (ClassNotFoundException e) { If can't find, clazz = findSystemClass(name); check on system } classpath if (resolve) { resolveClass(clazz); } return clazz; 2008 JavaOneSM Conference | java.sun.com/javaone | 17
  • 18. Java Class Loaders Code Sample - findClass String path = classname.replace('.', '/') + ".class"; byte[] raw = null; for (int i = 0; i < CLASSPATH.length; i++) { JarEntry classFile= Get one entry on CLASSPATH[i].getJarEntry(path); the class path and if (classFile != null){ search file try { raw = readFromJAR(CLASSPATH[i], Read the Class classFile); bytes break; } catch (IOException e) { throw new ClassNotFoundException("", e); } } } if (raw == null) { throw new ClassNotFoundException("" + name); } return defineClass(name, raw, 0, Define the class raw.length); 2008 JavaOneSM Conference | java.sun.com/javaone | 18
  • 19. Java Class Loaders Class Loader on Java ME platform (CLDC) CLDC does not allow user-defined class loaders When a MIDlet is running, the only class loader is the main KVM loader • Similar to the bootstrap class loader KVM Class loader only load • Core KVM classes (CLDC, MIDP) • Optional packages • MIDlet JAR 2008 JavaOneSM Conference | java.sun.com/javaone | 19
  • 20. Agenda Application Model Application Container Java Class Loaders Motorola Java ME Platform Emulator Scenario Main Issues in Java ME Container Design Conclusions 2008 JavaOneSM Conference | java.sun.com/javaone | 20
  • 21. Motorola Java ME Platform Emulator Scenario Motorola supports different device platforms according to the target market • Low tier: Motorola OS • High tier: MOTOMAGX (Linux) • Multi-media device: UIQ (Symbian) • Productivity Device: Windows Mobile MIDlet Application Model is supported on ALL platforms But each platform has a different set of supported JSRs and hardware capabilities 2008 JavaOneSM Conference | java.sun.com/javaone | 21
  • 22. Motorola Java ME Platform Emulator Scenario Motorola OS Linux OS Crypto API Media Streaming Bluetooth API WMA 2.0 Windows Mobile OS Bluetooth API Location API A Motorola Java ME platform Emulator needs to address those different kinds of devices • Same Application model, but with different runtime platform An application model container is the best solution for that 2008 JavaOneSM Conference | java.sun.com/javaone | 22
  • 23. Motorola Java ME Platform Emulator MoJa Container Requirements UEI Compliant IDE Motorola Java ME Container Single Application Model, MIDlet, but different platforms and devices Host runtime platform is the Java SE platform MoJa Container Allow that each device can define its own set of supported APIs Integrated on any UEI Compliant IDE Loads the MIDlet and the JSRs classes JRE 2008 JavaOneSM Conference | java.sun.com/javaone | 23
  • 24. Agenda Application Model Application Container Java Class Loaders Motorola Java ME Platform Emulator Scenario Main Issues in Java ME Container Design Conclusions 2008 JavaOneSM Conference | java.sun.com/javaone | 24
  • 25. Main Issues in Java ME Platform Container Design High Level View MIDlet JAR MoJa Container can access ALL Java SE APIs MIDP and JSRs implementation MIDP & JSRs Implementation can • Access each other • Access the container internal classes • Access all Java SE APIs MoJa Container MIDlet JAR can • Access its own classes • Access the MIDP & JSRs Interfaces Java VM & JavaSE APIs 2008 JavaOneSM Conference | java.sun.com/javaone | 25
  • 26. Main Issues in Java ME Platform Container Design Four Issues How to represent each specific JSR? How to represent each Device? How to handle the MIDlet suite under execution? How to separate the Java ME platform from the Java SE platform? 2008 JavaOneSM Conference | java.sun.com/javaone | 26
  • 27. Issue 1: How to represent each specific JSR? CLDC/MIDP Architecture Define the Concept of Optional Packages (JSR) • Depends on CLDC and/or MIDP and there is no dependency between each other Solution • Define a common platform (supported by ALL devices) • Design each JSR as a separated JAR that depends only on the common platform 2008 JavaOneSM Conference | java.sun.com/javaone | 27
  • 28. How to represent each specific JSR? JSRs Logical View JSRWWW JSRXXX JSRYYY JSRZZZ etc... Common MIDP Platform MoJa Common platform is CLDC, MIDP, JSR 75 (File System) and JSR 135 • Common platform can be organized in a single JAR file Each other JSR can have its own JAR MoJa Container will have a base of JSRs that it supports 2008 JavaOneSM Conference | java.sun.com/javaone | 28
  • 29. Issue 2: How to represent each Device? Each device must indicate the set of JSRs that it supports from the JSRs Base MoJa Container has two main components that handles the device representation • DeviceHandler JSRs Base • JMELoader JSRWWW JSRWWW JSRXXX Device A JSRYYY DeviceHandler JSRZZZ JSRYYY JSRZZZ JMELoader 2008 JavaOneSM Conference | java.sun.com/javaone | 29
  • 30. How to represent each Device? Each device is represented by a property/XML file • List all the JSRs supported by that device DeviceHandler is responsible to • Parser the device property file that list all supported JSRs • Go to the JSRs base • Locate JSR JARs • Start the JMELoader pointing to ALL Device JSRs JMELoader is responsible to • Find classes inside the JSRs JARs • Load classes inside the JSRs JARs 2008 JavaOneSM Conference | java.sun.com/javaone | 30
  • 31. Issue 3: How to handle the MIDlet suite under execution? A MIDlet suite is represented by its • Java Application Descriptor (JAD File) • JAR File The Suite JAR has all classes and resources that are necessary to execute the MIDlet MoJa Container has two main components that handles the device representation • DeviceHandler • MIDletLoader MIDlet DeviceHandler MIDletLoader Suite JAD File JAR File 2008 JavaOneSM Conference | java.sun.com/javaone | 31
  • 32. How to handle the MIDlet suite under execution? When the MIDlet is executed, the DeviceHandler is responsible to • Read / Parse the Suite JAD file • Locate the Suite JAR File • Start the MIDletLoader pointing to the MIDlet JAR File • Create the MIDlet it self and manage its state transitions MIDletLoader is responsible to • Find classes inside the MIDlet JAR • Load classes inside the MIDlet JAR MIDletLoader the only responsible to load MIDlet classes / resources 2008 JavaOneSM Conference | java.sun.com/javaone | 32
  • 33. Issue 4: How to separate the Java ME platform from the Java SE platform? MIDlet Tries to Load a Class MIDletLoader and JMELoader Class Loaders both avoid the MIDlet from accessing any non Java ME class JMELoader class loader allow access to all Java SE classes • But MIDletLoader doesn't MIDletLoader MIDlet JAR works here JMELoader JSRs and Common Platform works here MoJa Container JRE 2008 JavaOneSM Conference | java.sun.com/javaone | 33
  • 34. How to separate the Java ME platform from the Java SE platform? MIDlet Tries to Load a Class MIDletLoader execute the following steps to load a class 1. Check if the class is inside the MIDlet JAR 2. If it is not, ask JMELoader to load the class (JSRs JARs) 3. If the class is not found until step 2, a ClassNotFoundException is returned JMELoader execute the following steps 1. Check if the class is inside the JSRs JARs; 2. If it is not, check if the class is inside the Common Platform; 3. If it is not, ask the system class loader to load the class; 4. If the class is not found until step 3, a ClassNotFoundException is returned. 2008 JavaOneSM Conference | java.sun.com/javaone | 34
  • 35. Main Issues in Java ME Platform Container Design Summarized Answers How to represent each specific JSR? • MoJa has a common platform • Each JSR has it own JAR that depends on the common platform How to represent each Device? • Device property represents a device • DeviceHandler understands the device property file • JMELoader loads all JSRs JARs How to handle the MIDlet suite under execution? • DeviceHandler manage the MIDlet execution • MIDletLoader loads the MIDlet JAR How to separate the Java ME platform from the Java SE platform? • MIDletLoader only allow access to MIDlet and JSR classes • JMELoader allow access to JSRs and JRE classes 2008 JavaOneSM Conference | java.sun.com/javaone | 35
  • 36. MoJa Container Architecture High Level Logical View 3 levels of class loaders MoJa Container MIDletLoader MIDletLoader • Knows how to load all MIDlet suite specific classes and resources JMELoader JMELoader • Knows how to load all JSR specific classes and resources Java VM JavaSE Class loader Java SE System Class Loader • Knows how to load all Java SE classes and resources 2008 JavaOneSM Conference | java.sun.com/javaone | 36
  • 37. MoJa Container Architecture Load Class Sequence Diagram Load MIDlet Class Load JSR Class 2008 JavaOneSM Conference | java.sun.com/javaone | 37
  • 38. MoJa Container Architecture JMELoader Entry Points While the MIDlet is under execution, there are two main entry points on the JMELoader • loadClass(): usual load class method. Used by all classes that were loaded by JMELoader • loadMEClass(): specific load class method that only check for classes inside the OPs & Platform. loadMEClass() method guarantees that only Java ME classes are accessed by the MIDlet JSR JAR MIDlet JAR loadClass JMELoader loadMEClass 2008 JavaOneSM Conference | java.sun.com/javaone | 38
  • 39. MoJa Container Architecture MIDletLoader.loadClass() Code Sample // verify if it was already loaded clazz = findLoadedClass(name); if (clazz != null) return clazz; try { // try to find the class on MIDlet JAR classpath clazz = findClass(name); } catch (ClassNotFoundException e) { Check MIDlet JAR try { // try to find the class on Java ME library clazz = getJMELoader().loadMEClass(name, resolve); } catch (Exception exc) { Check JSRs & throw new ClassNotFoundException(); Platform } if (clazz == null) throw new ClassNotFoundException("”); } return clazz; 2008 JavaOneSM Conference | java.sun.com/javaone | 39
  • 40. MoJa Container Architecture JMELoader.loadClass() Code Sample // verify if it was already loaded clazz = findLoadedClass(name); if (clazz != null) return clazz; // try to find the class on java me library try { clazz = findClass(name); Check JSRs & Platform } catch (ClassNotFoundException e) { //try to find the class from the system clazz = findSystemClass(name); Check JRE } return clazz; 2008 JavaOneSM Conference | java.sun.com/javaone | 40
  • 41. Agenda Application Model Application Container Java Class Loaders Motorola Java ME Platform Emulator Scenario Main Issues in Java ME Container Design Conclusions 2008 JavaOneSM Conference | java.sun.com/javaone | 41
  • 42. Conclusions Java platform allows many different application models Each application model has its own particularities An application model container provides the necessary concepts to isolate each model particularities from the underlaying platform Java ME platform defines the MIDlet application models that can be implemented on top of a Java SE platform Java SE classes loader is a powerful mechanism that can be used to implement a Java ME container 2008 JavaOneSM Conference | java.sun.com/javaone | 42
  • 43. For More Information (1)A Survey of Java ME Today (Update) http://developers.sun.com/mobility/getstart/articles/survey/ (2)Sun Mobile Device Technology - Introduction to Mobility Java Technology http://developers.sun.com/mobility/getstart/ (3)MIDP Javadocs http://java.sun.com/javame/reference/apis/jsr118/ 2008 JavaOneSM Conference | java.sun.com/javaone | 43
  • 44. Christian Kurzke, Developer Platforms Architect, Motorola Inc. Gustavo de Paula, Senior Consultant for Wireless Technologies, C.E.S.A.R TS-7575, JavaSE and Cool Stuff 2008 JavaOneSM Conference | java.sun.com/javaone | 44