SlideShare uma empresa Scribd logo
1 de 49
Java™Platform, Micro Edition Part 6 – Record Stores, Distribution andLocalization v3.0a – 14 April 2009 1 Andreas Jakl, 2009
Disclaimer These slides are provided free of charge at http://www.symbianresources.com and are used during Java ME courses at the University of Applied Sciences in Hagenberg, Austria at the Mobile Computing department ( http://www.fh-ooe.at/mc ) Respecting the copyright laws, you are allowed to use them: for your own, personal, non-commercial use in the academic environment In all other cases (e.g. for commercial training), please contact andreas.jakl@fh-hagenberg.at The correctness of the contents of these materials cannot be guaranteed. Andreas Jakl is not liable for incorrect information or damage that may arise from using the materials. This document contains copyright materials which are proprietary to Sun or various mobile device manufacturers, including Nokia, SonyEricsson and Motorola. Sun, Sun Microsystems, the Sun Logo and the Java™ Platform, Micro Edition are trademarks or registered trademarks of Sun Microsystems, Inc. in the United States and other countries.  Andreas Jakl, 2009 2
Contents Record Stores Input/OutputStreams Distribution Deployment Pre-Processing Obfuscation OTA-Deployment Localization Andreas Jakl, 2009 3
Record Stores Save your data Andreas Jakl, 2009 4
Persistent Data Most applications have to store something, e.g.: Settings Current status / progress / high scores User documents and results MIDP requires: Non-volatile memory At least 8kB Full file system access is optional (JSR 75) Andreas Jakl, 2009 5 
Records: can be thought of rows in a table Record Store & Records Andreas Jakl, 2009 6 Record Store Integer value, role of a primary key for the database Stores the record data
Record Management System MIDP Record Management System (RMS) works like DBMS Device-independent reading and writing, hides real database-file and location Database = “Record Store” Consists of a number of recordswith automatically assigned, unique IDs: 1, 2, ... Record = Array of bytes To change content: read byte array  modify it  replace original record Andreas Jakl, 2009 7
MIDlets and Record Stores MIDlets can access all record stores in their suite With a fully qualified name also from other suites Andreas Jakl, 2009 8 Record Store “S” Record Store “T” MIDlet Suite A MIDlet 1 MIDlet 1 Names must be unique within a single MIDlet suite MIDlet 2 MIDlet 2 Record Store “S” MIDlet Suite B
Record Store Features Record Store saves: Time + Date of last modification Version number (integer), incremented for each operation that modified the contents Individual operations (write, ...) are atomic, synchronous and serialized When MIDlet uses multiple threads to access a single record store, it is responsible for synchronization Andreas Jakl, 2009 9
RecordStore API Opening / Creating a Record Store RecordStorers = RecordStore.openRecordStore(        String recordStoreName, booleancreateIfNecessary); recordStoreName: MIDlet suite-unique name, up to 32 (Unicode) chars createIfNecessary: if it does not exist, create it or throw an exception Add Records intnewId = rs.addRecord(byte[] data, intoffset, intnumBytes); newId: ID of the record that was created (1, 2, ...) data: byte-array to add as a new record offset: index into data buffer (first byte to write), usually 0 numBytes: number of bytes to use (length of data to write) Andreas Jakl, 2009 10
RecordStore API Reading a record byte[] record = rs.getRecord(intrecordId); record: copy of the data stored in the record recordId: ID of the record to retrieve Close the record store rs.closeRecordStore(); Delete a record store RecordStore.deleteRecordStore(String recordStoreName); Andreas Jakl, 2009 11
Byte-Arrays Working with Andreas Jakl, 2009 12
Streams Java offers comfortable streams to: Create byte arrays on the fly (ByteArrayOutputStream) Write standard data types to the stream (DataOutputStream) Andreas Jakl, 2009 13 String object String object DataOutputStream.writeUTF(); DataInputStream.readUTF(); DataOutputStream DataInputStream ByteArrayOutputStream ByteArrayInputStream byte[] byte[]
Output Stream Example Andreas Jakl, 2009 14 // Open (+ create) the record store with the name "MyData" RecordStorers = RecordStore.openRecordStore("MyData", true); // First create the byte array output stream which can generate the array ByteArrayOutputStreambos = new ByteArrayOutputStream(); // On top of that, create the data output stream,  // which can serialize several standard Java data types DataOutputStream dos = new DataOutputStream(bos); // Write data to the stream dos.writeInt(667487); dos.writeBoolean(true); dos.writeUTF("Test"); // Flush data to make sure everything is commited down streams dos.flush(); // Grab byte array from the stream byte[] recordOut = bos.toByteArray(); // Add a new record to the record store, write the whole array from 0 to its length intnewRecordId = rs.addRecord(recordOut, 0, recordOut.length); // Finished working on the record store – close it dos.close();			// Closes underlying output stream as well rs.closeRecordStore(); (example omits catching Exceptions for clarity)
Byte Array Contents of the byte array: Andreas Jakl, 2009 15 dos.writeInt(667487); dos.writeBoolean(true); dos.writeUTF("Test"); Int (4 bytes) Boolean (1 byte) Number of bytes used (2 bytes) String UTF-8 encoded String (4 bytes) DataOutputStream-Methods only save data, no type information  you have to remember what you wrote and read it in exactly the same order
Reading Rather similar to writing: Andreas Jakl, 2009 16 // Open the record store with the name "MyData" RecordStorers = RecordStore.openRecordStore("MyData", false); // Get record contents byte[] record = rs.getRecord(newRecordId); // First create the byte array input stream which accesses the byte array ByteArrayInputStreambis = new ByteArrayInputStream(record); // On top of that, create the data input stream,  // which can interpret the contents byte array as Java data types DataInputStreamdis = new DataInputStream(bis); // Read data from the stream int version = dis.readInt(); booleanfirstStart = dis.readBoolean(); String userName = dis.readUTF(); // Finished working on the record store – close it dis.close(); 			// Closes underlying input stream as well rs.closeRecordStore(); (example omits catching Exceptions for clarity)
... back to the RecordStore Enough reading and writing ...  Andreas Jakl, 2009 17
RecordStore API Modify (= overwrite, replace) existing record rs.setRecord(intrecordId, byte[] newData, intoffset, intnumBytes); recordId: ID of the record to replace data: byte-array to add as a the new record offset: index into data buffer (first byte to write), usually 0 numBytes: number of bytes to use (length of data to write) Andreas Jakl, 2009 18
Strategy – Settings Saving application settings Write all settings to a byte array into one record of a single record store If possible: Write directly after settings change, not when exiting the application You never know when and how the program is closed(battery removed?) Read on application start-up Use default settings for “file not found”-Exception Andreas Jakl, 2009 19
Settings – Existing Record When saving settings, check: New record store was created ->add record Record store already exists -> replace record Andreas Jakl, 2009 20 if (rs.getNumRecords () == 0) {					// Check if record store already contains our settings record rs.addRecord(recordOut, 0, recordOut.length);		// Add new record to the store, will get position 1 } else { rs.setRecord (1, recordOut, 0, recordOut.length);	// Replace previous settings-record }
Settings – Version Save version of data structure to prevent problems after updating application (Version of Record Store only saves # of modifications!) Store version at the beginning of the stream dos.writeShort (1);	    // Version Check version when reading stream int version = dis.readShort();if (version == 1) { /* Continue parsing */ } Andreas Jakl, 2009 21
Strategy – Database Application with database (e.g. time management) Multiple records per record store.Each record = one entry, which consists of the data, written as a byte array as usual Serializing Objects Used to save object’s state to a sequence of bytes Allows rebuilding an identical object later on Not supported in current CLDC Write it yourself: Use a stream to put all relevant data into a stream; read and create obj. in a static method Andreas Jakl, 2009 22
Example – Database I Andreas Jakl, 2009 23 ContactData class, contains information about a person public class ContactData {     private String name;	// Saves name of the contact     private int age;		// Saves age     public ContactData (String name, int age) { 	this.name = name; this.age = age;     } /** Write all relevant data to the stream, which will allow rebuilding the object when reading the stream. */     public void externalize(DataOutputStream dos) throws IOException { dos.writeUTF (name); dos.writeInt (age);     } /** Read data from the stream and use it to create and return a new instance of this object. */     public static ContactDatainternalize(DataInputStreamdis) throws IOException { 	String tmpName = dis.readUTF (); inttmpAge = dis.readInt (); 	return new ContactData(tmpName, tmpAge);     }     /** Return relevant information in string form. */     public String toString() { 	return ("Contact data: Name = " + name + ", Age = " + age);     } }
Example – Database II Andreas Jakl, 2009 24 Main application – save contacts to the database // Create new vector that will contain all contact data Vector names = new Vector(); names.addElement (new ContactData("Valerie Dimeling", 20)); names.addElement (new ContactData("Ginger Hay", 54)); try { RecordStore.deleteRecordStore ("myRs");				// Make sure no record store already exists RecordStorers = RecordStore.openRecordStore("myRs", true);	// Create a new record store ByteArrayOutputStreambos = new ByteArrayOutputStream();	// Create streams for writing data DataOutputStream dos = new DataOutputStream(bos); // Go through the vector and create a record for each element     for (Enumeration e = names.elements (); e.hasMoreElements (); )     { ContactDatacd = (ContactData) e.nextElement ();    // Get next element of the vector cd.externalize (dos);					// Let the instance externalize itself into our stream dos.flush();							// Make sure everything is written 	byte[] record = bos.toByteArray ();			// Get byte array from the record rs.addRecord (record, 0, record.length);    		// Add the record to the store bos.reset ();							// Clear the output stream so that we can start from scratch     } dos.close (); […]
Example – Database III Andreas Jakl, 2009 25 Main application – restore database from the record store // Read back data using a record enumerator to go through all elements     // Record enumerator would be more powerful, we do not use the advanced features here RecordEnumerationrenum = rs.enumerateRecords (null, null, false);     while (renum.hasNextElement ())     { 	byte[] record = renum.nextRecord ();						// Get data of the next record ByteArrayInputStreambis = new ByteArrayInputStream(record);	// Input streams for parsing data DataInputStreamdis = new DataInputStream(bis); ContactDatacd = ContactData.internalize (dis);	// Internalize and create new instance (static method) System.out.println(cd);	    				// Print information to console dis.close();     } rs.closeRecordStore ();			// Close the record store } catch (RecordStoreException ex) { ex.printStackTrace(); } catch (IOException ex) { ex.printStackTrace(); }
Advanced Access Sorting RecordComparator Searching RecordFilter Notification of changes RecordListener Andreas Jakl, 2009 26
Distributing MIDlets Let others experience your fabulous applications! Andreas Jakl, 2009 27
Device Fragmentation Mobile devices vary in: Screen size Colour depth Speed Optional API support (Bluetooth, ...) Bugs (+ their workarounds) Solution (in NetBeans): Project configurations + pre-processing (like in C++) Andreas Jakl, 2009 28
Project Configurations Project Configurations used for Setting variables that are used for pre-processing Including required files to .jar-archive Modify build settings (Obfuscation, ...) Create new configuration Project Properties  Manage Configurations ...  Duplicate one of the configurations Andreas Jakl, 2009 29
Adapt Abilities Define variables for pre-processing e.g. ScreenWidth, support for APIs, ... Andreas Jakl, 2009 30
Fragment your Code Use pre-processor directives to adapt code depending on abilities of current project configuration Andreas Jakl, 2009 31
Adapt Included Resources Choose which files to include for each project configuration: Andreas Jakl, 2009 32
Set Active Configuration Right click on the project  “Set Active Project Configuration”: Defines which pre-processor block is active Andreas Jakl, 2009 33 “SmallScreen” ScreenHeight = 128 “MediumScreen” ScreenHeight = 320
Optimization – Obfuscation Original intention: Make reverse engineering more difficult Code more difficult to read after de-compilation Renames classes to “a.class, b.class, …” Removes non-used methods, variables, classes  Significant size reduction Over-the-Air = expensive! MIDlet size restrictions in many phones Improves speed (less code to load / parse) Andreas Jakl, 2009 34
Obfuscation Andreas Jakl, 2009 35 Original archive 79.2 kB Obfuscated 42.9 kB = 45% smaller!
Define Obfuscation Level For release builds: Activate obfuscation (max. level) Don’t use it for debugging Andreas Jakl, 2009 36
Build All Configurations Andreas Jakl, 2009 37 ... creates own directory and .jar/.jad for each configuration Default configuration located in base directory
Over-The-Air Deployment Transmitting MIDlets to phones Andreas Jakl, 2009 38
Why OTA for Deployment? Some phones (Samsung, Sagem, BREW,...) do not support installing MIDlets through the PC or Bluetooth Only alternative: Download directly through mobile phone (UTMS)  Over-the-Air (OTA) delivery Andreas Jakl, 2009 39
Over-the-Air Andreas Jakl, 2009 40 HTTP Web Server Mobile Device AMS (Application Management Software) JAD-Server JAR-Server Notification Server GET /midlet.jad GET /midlet.jar POST /install-notify (900 Success) 200 OK 200 OK 200 OK
Web Server – MIME Types Add MIME-Types for .jad and .jar to your web server Required for the phone to correctly handle the files Then, simply provide a link to the .jad-file on your website The .jad-file contains the link to the .jar archive Andreas Jakl, 2009 41 Example screenshot: SiteAdmin-Tool used at:http://www.site5.com/
Automated Deployment Andreas Jakl, 2009 42 Make sure the .jar-URL is set correctly in the .jad-file that you upload to your webserver!
Localization Prepare for the international market Andreas Jakl, 2009 43
Localization Mobile phones available on a global market Goal: Make source code independent of language, load text for user language from a file Query current language: String locale = System.getProperty ("microedition.locale"); Examples:en-US, en-GB, de-DE NetBeans: Provides ready-made LocalizationSupport-class & tools for managing message bundles Andreas Jakl, 2009 44 
Add Support Class Andreas Jakl, 2009 45
Define Settings You can usually accept the default values: Andreas Jakl, 2009 46
Add Localized String Tools  Internationalization  Insert Internationalized String... Andreas Jakl, 2009 47 Get the localized string from your source code using the static function: Initialization will be done automaticallywhen you retrieve the first message.
Message Bundle Add additional locales for new languages Define same keys in all files Andreas Jakl, 2009 48
Thanks for your attention That’s it! Andreas Jakl, 2009 49

Mais conteúdo relacionado

Mais procurados

Mais procurados (10)

Save Java memory
Save Java memorySave Java memory
Save Java memory
 
Understanding C# in .NET
Understanding C# in .NETUnderstanding C# in .NET
Understanding C# in .NET
 
4 gouping object
4 gouping object4 gouping object
4 gouping object
 
Java nio ( new io )
Java nio ( new io )Java nio ( new io )
Java nio ( new io )
 
Eclipse Memory Analyzer Tool
Eclipse Memory Analyzer ToolEclipse Memory Analyzer Tool
Eclipse Memory Analyzer Tool
 
Thread
ThreadThread
Thread
 
Collections forceawakens
Collections forceawakensCollections forceawakens
Collections forceawakens
 
JDK1.7 features
JDK1.7 featuresJDK1.7 features
JDK1.7 features
 
Computer Science Assignment Help
Computer Science Assignment HelpComputer Science Assignment Help
Computer Science Assignment Help
 
sqlmap internals
sqlmap internalssqlmap internals
sqlmap internals
 

Destaque

Java ME - 07 - Generic Connection Framework, HTTP and Sockets
Java ME - 07 - Generic Connection Framework, HTTP and SocketsJava ME - 07 - Generic Connection Framework, HTTP and Sockets
Java ME - 07 - Generic Connection Framework, HTTP and SocketsAndreas Jakl
 
Java ME - 02 - High Level UI
Java ME - 02 - High Level UIJava ME - 02 - High Level UI
Java ME - 02 - High Level UIAndreas Jakl
 
Java ME - 03 - Low Level Graphics E
Java ME - 03 - Low Level Graphics EJava ME - 03 - Low Level Graphics E
Java ME - 03 - Low Level Graphics EAndreas Jakl
 
Java ME - 05 - Game API
Java ME - 05 - Game APIJava ME - 05 - Game API
Java ME - 05 - Game APIAndreas Jakl
 
Java ME - 08 - Mobile 3D Graphics
Java ME - 08 - Mobile 3D GraphicsJava ME - 08 - Mobile 3D Graphics
Java ME - 08 - Mobile 3D GraphicsAndreas Jakl
 
Java ME - 04 - Timer, Tasks and Threads
Java ME - 04 - Timer, Tasks and ThreadsJava ME - 04 - Timer, Tasks and Threads
Java ME - 04 - Timer, Tasks and ThreadsAndreas Jakl
 
Java ME - 01 - Overview
Java ME - 01 - OverviewJava ME - 01 - Overview
Java ME - 01 - OverviewAndreas Jakl
 

Destaque (7)

Java ME - 07 - Generic Connection Framework, HTTP and Sockets
Java ME - 07 - Generic Connection Framework, HTTP and SocketsJava ME - 07 - Generic Connection Framework, HTTP and Sockets
Java ME - 07 - Generic Connection Framework, HTTP and Sockets
 
Java ME - 02 - High Level UI
Java ME - 02 - High Level UIJava ME - 02 - High Level UI
Java ME - 02 - High Level UI
 
Java ME - 03 - Low Level Graphics E
Java ME - 03 - Low Level Graphics EJava ME - 03 - Low Level Graphics E
Java ME - 03 - Low Level Graphics E
 
Java ME - 05 - Game API
Java ME - 05 - Game APIJava ME - 05 - Game API
Java ME - 05 - Game API
 
Java ME - 08 - Mobile 3D Graphics
Java ME - 08 - Mobile 3D GraphicsJava ME - 08 - Mobile 3D Graphics
Java ME - 08 - Mobile 3D Graphics
 
Java ME - 04 - Timer, Tasks and Threads
Java ME - 04 - Timer, Tasks and ThreadsJava ME - 04 - Timer, Tasks and Threads
Java ME - 04 - Timer, Tasks and Threads
 
Java ME - 01 - Overview
Java ME - 01 - OverviewJava ME - 01 - Overview
Java ME - 01 - Overview
 

Semelhante a Java ME - 06 - Record Stores, Distribution and Localization

Symbian OS - Dynamic Arrays
Symbian OS - Dynamic ArraysSymbian OS - Dynamic Arrays
Symbian OS - Dynamic ArraysAndreas Jakl
 
Session9 J2ME Record Management System
Session9 J2ME Record Management SystemSession9 J2ME Record Management System
Session9 J2ME Record Management Systemmuthusvm
 
Symbian OS - Memory Management
Symbian OS - Memory ManagementSymbian OS - Memory Management
Symbian OS - Memory ManagementAndreas Jakl
 
Symbian OS - Descriptors
Symbian OS - DescriptorsSymbian OS - Descriptors
Symbian OS - DescriptorsAndreas Jakl
 
JavaOne 2013: Memory Efficient Java
JavaOne 2013: Memory Efficient JavaJavaOne 2013: Memory Efficient Java
JavaOne 2013: Memory Efficient JavaChris Bailey
 
Data Storage In Android
Data Storage In Android Data Storage In Android
Data Storage In Android Aakash Ugale
 
Code Documentation. That ugly thing...
Code Documentation. That ugly thing...Code Documentation. That ugly thing...
Code Documentation. That ugly thing...Christos Manios
 
Chapter 12 - File Input and Output
Chapter 12 - File Input and OutputChapter 12 - File Input and Output
Chapter 12 - File Input and OutputEduardo Bergavera
 
Java căn bản - Chapter12
Java căn bản - Chapter12Java căn bản - Chapter12
Java căn bản - Chapter12Vince Vo
 
Embedded systems programming.ppt
Embedded systems programming.pptEmbedded systems programming.ppt
Embedded systems programming.pptnasir khan
 
Android | Busy Java Developers Guide to Android: Persistence | Ted Neward
Android | Busy Java Developers Guide to Android: Persistence | Ted NewardAndroid | Busy Java Developers Guide to Android: Persistence | Ted Neward
Android | Busy Java Developers Guide to Android: Persistence | Ted NewardJAX London
 
Expanding the control over the operating system from the database
Expanding the control over the operating system from the databaseExpanding the control over the operating system from the database
Expanding the control over the operating system from the databaseBernardo Damele A. G.
 
Global objects in Node.pdf
Global objects in Node.pdfGlobal objects in Node.pdf
Global objects in Node.pdfSudhanshiBakre1
 
Browser exploitation SEC-T 2019 stockholm
Browser exploitation SEC-T 2019 stockholmBrowser exploitation SEC-T 2019 stockholm
Browser exploitation SEC-T 2019 stockholmJameel Nabbo
 
The program reads data from two files, itemsList-0x.txt and .docx
The program reads data from two files, itemsList-0x.txt and .docxThe program reads data from two files, itemsList-0x.txt and .docx
The program reads data from two files, itemsList-0x.txt and .docxoscars29
 
C5 c++ development environment
C5 c++ development environmentC5 c++ development environment
C5 c++ development environmentsnchnchl
 

Semelhante a Java ME - 06 - Record Stores, Distribution and Localization (20)

Symbian OS - Dynamic Arrays
Symbian OS - Dynamic ArraysSymbian OS - Dynamic Arrays
Symbian OS - Dynamic Arrays
 
Session9 J2ME Record Management System
Session9 J2ME Record Management SystemSession9 J2ME Record Management System
Session9 J2ME Record Management System
 
Symbian OS - Memory Management
Symbian OS - Memory ManagementSymbian OS - Memory Management
Symbian OS - Memory Management
 
Symbian OS - Descriptors
Symbian OS - DescriptorsSymbian OS - Descriptors
Symbian OS - Descriptors
 
JavaOne 2013: Memory Efficient Java
JavaOne 2013: Memory Efficient JavaJavaOne 2013: Memory Efficient Java
JavaOne 2013: Memory Efficient Java
 
Data Storage In Android
Data Storage In Android Data Storage In Android
Data Storage In Android
 
Lab 1 Essay
Lab 1 EssayLab 1 Essay
Lab 1 Essay
 
Code Documentation. That ugly thing...
Code Documentation. That ugly thing...Code Documentation. That ugly thing...
Code Documentation. That ugly thing...
 
Chapter 12 - File Input and Output
Chapter 12 - File Input and OutputChapter 12 - File Input and Output
Chapter 12 - File Input and Output
 
Java căn bản - Chapter12
Java căn bản - Chapter12Java căn bản - Chapter12
Java căn bản - Chapter12
 
Embedded systems programming.ppt
Embedded systems programming.pptEmbedded systems programming.ppt
Embedded systems programming.ppt
 
treeview
treeviewtreeview
treeview
 
treeview
treeviewtreeview
treeview
 
Android | Busy Java Developers Guide to Android: Persistence | Ted Neward
Android | Busy Java Developers Guide to Android: Persistence | Ted NewardAndroid | Busy Java Developers Guide to Android: Persistence | Ted Neward
Android | Busy Java Developers Guide to Android: Persistence | Ted Neward
 
Expanding the control over the operating system from the database
Expanding the control over the operating system from the databaseExpanding the control over the operating system from the database
Expanding the control over the operating system from the database
 
Global objects in Node.pdf
Global objects in Node.pdfGlobal objects in Node.pdf
Global objects in Node.pdf
 
Browser exploitation SEC-T 2019 stockholm
Browser exploitation SEC-T 2019 stockholmBrowser exploitation SEC-T 2019 stockholm
Browser exploitation SEC-T 2019 stockholm
 
The program reads data from two files, itemsList-0x.txt and .docx
The program reads data from two files, itemsList-0x.txt and .docxThe program reads data from two files, itemsList-0x.txt and .docx
The program reads data from two files, itemsList-0x.txt and .docx
 
Sqllite
SqlliteSqllite
Sqllite
 
C5 c++ development environment
C5 c++ development environmentC5 c++ development environment
C5 c++ development environment
 

Mais de Andreas Jakl

Create Engaging Healthcare Experiences with Augmented Reality
Create Engaging Healthcare Experiences with Augmented RealityCreate Engaging Healthcare Experiences with Augmented Reality
Create Engaging Healthcare Experiences with Augmented RealityAndreas Jakl
 
AR / VR Interaction Development with Unity
AR / VR Interaction Development with UnityAR / VR Interaction Development with Unity
AR / VR Interaction Development with UnityAndreas Jakl
 
Android Development with Kotlin, Part 3 - Code and App Management
Android Development with Kotlin, Part 3 - Code and App ManagementAndroid Development with Kotlin, Part 3 - Code and App Management
Android Development with Kotlin, Part 3 - Code and App ManagementAndreas Jakl
 
Android Development with Kotlin, Part 2 - Internet Services and JSON
Android Development with Kotlin, Part 2 - Internet Services and JSONAndroid Development with Kotlin, Part 2 - Internet Services and JSON
Android Development with Kotlin, Part 2 - Internet Services and JSONAndreas Jakl
 
Android Development with Kotlin, Part 1 - Introduction
Android Development with Kotlin, Part 1 - IntroductionAndroid Development with Kotlin, Part 1 - Introduction
Android Development with Kotlin, Part 1 - IntroductionAndreas Jakl
 
Android and NFC / NDEF (with Kotlin)
Android and NFC / NDEF (with Kotlin)Android and NFC / NDEF (with Kotlin)
Android and NFC / NDEF (with Kotlin)Andreas Jakl
 
Basics of Web Technologies
Basics of Web TechnologiesBasics of Web Technologies
Basics of Web TechnologiesAndreas Jakl
 
Bluetooth Beacons - Bluetooth 5, iBeacon, Eddystone, Arduino, Windows 10 & More
Bluetooth Beacons - Bluetooth 5, iBeacon, Eddystone, Arduino, Windows 10 & MoreBluetooth Beacons - Bluetooth 5, iBeacon, Eddystone, Arduino, Windows 10 & More
Bluetooth Beacons - Bluetooth 5, iBeacon, Eddystone, Arduino, Windows 10 & MoreAndreas Jakl
 
Which new scenarios are enabled by Windows 10 for NFC, Bluetooth LE & Beacons?
Which new scenarios are enabled by Windows 10 for NFC, Bluetooth LE & Beacons?Which new scenarios are enabled by Windows 10 for NFC, Bluetooth LE & Beacons?
Which new scenarios are enabled by Windows 10 for NFC, Bluetooth LE & Beacons?Andreas Jakl
 
Mobile Test Automation
Mobile Test AutomationMobile Test Automation
Mobile Test AutomationAndreas Jakl
 
Qt App Development - Cross-Platform Development for Android, iOS, Windows Pho...
Qt App Development - Cross-Platform Development for Android, iOS, Windows Pho...Qt App Development - Cross-Platform Development for Android, iOS, Windows Pho...
Qt App Development - Cross-Platform Development for Android, iOS, Windows Pho...Andreas Jakl
 
WinJS, Apache Cordova & NFC - HTML5 apps for Android and Windows Phone
WinJS, Apache Cordova & NFC - HTML5 apps for Android and Windows PhoneWinJS, Apache Cordova & NFC - HTML5 apps for Android and Windows Phone
WinJS, Apache Cordova & NFC - HTML5 apps for Android and Windows PhoneAndreas Jakl
 
Nokia New Asha Platform Developer Training
Nokia New Asha Platform Developer TrainingNokia New Asha Platform Developer Training
Nokia New Asha Platform Developer TrainingAndreas Jakl
 
Windows Phone 8 NFC Quickstart
Windows Phone 8 NFC QuickstartWindows Phone 8 NFC Quickstart
Windows Phone 8 NFC QuickstartAndreas Jakl
 
Windows (Phone) 8 NFC App Scenarios
Windows (Phone) 8 NFC App ScenariosWindows (Phone) 8 NFC App Scenarios
Windows (Phone) 8 NFC App ScenariosAndreas Jakl
 
Windows 8 Platform NFC Development
Windows 8 Platform NFC DevelopmentWindows 8 Platform NFC Development
Windows 8 Platform NFC DevelopmentAndreas Jakl
 
NFC Development with Qt - v2.2.0 (5. November 2012)
NFC Development with Qt - v2.2.0 (5. November 2012)NFC Development with Qt - v2.2.0 (5. November 2012)
NFC Development with Qt - v2.2.0 (5. November 2012)Andreas Jakl
 
06 - Qt Communication
06 - Qt Communication06 - Qt Communication
06 - Qt CommunicationAndreas Jakl
 
05 - Qt External Interaction and Graphics
05 - Qt External Interaction and Graphics05 - Qt External Interaction and Graphics
05 - Qt External Interaction and GraphicsAndreas Jakl
 

Mais de Andreas Jakl (20)

Create Engaging Healthcare Experiences with Augmented Reality
Create Engaging Healthcare Experiences with Augmented RealityCreate Engaging Healthcare Experiences with Augmented Reality
Create Engaging Healthcare Experiences with Augmented Reality
 
AR / VR Interaction Development with Unity
AR / VR Interaction Development with UnityAR / VR Interaction Development with Unity
AR / VR Interaction Development with Unity
 
Android Development with Kotlin, Part 3 - Code and App Management
Android Development with Kotlin, Part 3 - Code and App ManagementAndroid Development with Kotlin, Part 3 - Code and App Management
Android Development with Kotlin, Part 3 - Code and App Management
 
Android Development with Kotlin, Part 2 - Internet Services and JSON
Android Development with Kotlin, Part 2 - Internet Services and JSONAndroid Development with Kotlin, Part 2 - Internet Services and JSON
Android Development with Kotlin, Part 2 - Internet Services and JSON
 
Android Development with Kotlin, Part 1 - Introduction
Android Development with Kotlin, Part 1 - IntroductionAndroid Development with Kotlin, Part 1 - Introduction
Android Development with Kotlin, Part 1 - Introduction
 
Android and NFC / NDEF (with Kotlin)
Android and NFC / NDEF (with Kotlin)Android and NFC / NDEF (with Kotlin)
Android and NFC / NDEF (with Kotlin)
 
Basics of Web Technologies
Basics of Web TechnologiesBasics of Web Technologies
Basics of Web Technologies
 
Bluetooth Beacons - Bluetooth 5, iBeacon, Eddystone, Arduino, Windows 10 & More
Bluetooth Beacons - Bluetooth 5, iBeacon, Eddystone, Arduino, Windows 10 & MoreBluetooth Beacons - Bluetooth 5, iBeacon, Eddystone, Arduino, Windows 10 & More
Bluetooth Beacons - Bluetooth 5, iBeacon, Eddystone, Arduino, Windows 10 & More
 
Which new scenarios are enabled by Windows 10 for NFC, Bluetooth LE & Beacons?
Which new scenarios are enabled by Windows 10 for NFC, Bluetooth LE & Beacons?Which new scenarios are enabled by Windows 10 for NFC, Bluetooth LE & Beacons?
Which new scenarios are enabled by Windows 10 for NFC, Bluetooth LE & Beacons?
 
Mobile Test Automation
Mobile Test AutomationMobile Test Automation
Mobile Test Automation
 
Qt App Development - Cross-Platform Development for Android, iOS, Windows Pho...
Qt App Development - Cross-Platform Development for Android, iOS, Windows Pho...Qt App Development - Cross-Platform Development for Android, iOS, Windows Pho...
Qt App Development - Cross-Platform Development for Android, iOS, Windows Pho...
 
WinJS, Apache Cordova & NFC - HTML5 apps for Android and Windows Phone
WinJS, Apache Cordova & NFC - HTML5 apps for Android and Windows PhoneWinJS, Apache Cordova & NFC - HTML5 apps for Android and Windows Phone
WinJS, Apache Cordova & NFC - HTML5 apps for Android and Windows Phone
 
Nokia New Asha Platform Developer Training
Nokia New Asha Platform Developer TrainingNokia New Asha Platform Developer Training
Nokia New Asha Platform Developer Training
 
Windows Phone 8 NFC Quickstart
Windows Phone 8 NFC QuickstartWindows Phone 8 NFC Quickstart
Windows Phone 8 NFC Quickstart
 
Windows (Phone) 8 NFC App Scenarios
Windows (Phone) 8 NFC App ScenariosWindows (Phone) 8 NFC App Scenarios
Windows (Phone) 8 NFC App Scenarios
 
Windows 8 Platform NFC Development
Windows 8 Platform NFC DevelopmentWindows 8 Platform NFC Development
Windows 8 Platform NFC Development
 
NFC Development with Qt - v2.2.0 (5. November 2012)
NFC Development with Qt - v2.2.0 (5. November 2012)NFC Development with Qt - v2.2.0 (5. November 2012)
NFC Development with Qt - v2.2.0 (5. November 2012)
 
06 - Qt Communication
06 - Qt Communication06 - Qt Communication
06 - Qt Communication
 
05 - Qt External Interaction and Graphics
05 - Qt External Interaction and Graphics05 - Qt External Interaction and Graphics
05 - Qt External Interaction and Graphics
 
04 - Qt Data
04 - Qt Data04 - Qt Data
04 - Qt Data
 

Último

Google AI Hackathon: LLM based Evaluator for RAG
Google AI Hackathon: LLM based Evaluator for RAGGoogle AI Hackathon: LLM based Evaluator for RAG
Google AI Hackathon: LLM based Evaluator for RAGSujit Pal
 
Handwritten Text Recognition for manuscripts and early printed texts
Handwritten Text Recognition for manuscripts and early printed textsHandwritten Text Recognition for manuscripts and early printed texts
Handwritten Text Recognition for manuscripts and early printed textsMaria Levchenko
 
Transforming Data Streams with Kafka Connect: An Introduction to Single Messa...
Transforming Data Streams with Kafka Connect: An Introduction to Single Messa...Transforming Data Streams with Kafka Connect: An Introduction to Single Messa...
Transforming Data Streams with Kafka Connect: An Introduction to Single Messa...HostedbyConfluent
 
#StandardsGoals for 2024: What’s new for BISAC - Tech Forum 2024
#StandardsGoals for 2024: What’s new for BISAC - Tech Forum 2024#StandardsGoals for 2024: What’s new for BISAC - Tech Forum 2024
#StandardsGoals for 2024: What’s new for BISAC - Tech Forum 2024BookNet Canada
 
Strategies for Unlocking Knowledge Management in Microsoft 365 in the Copilot...
Strategies for Unlocking Knowledge Management in Microsoft 365 in the Copilot...Strategies for Unlocking Knowledge Management in Microsoft 365 in the Copilot...
Strategies for Unlocking Knowledge Management in Microsoft 365 in the Copilot...Drew Madelung
 
From Event to Action: Accelerate Your Decision Making with Real-Time Automation
From Event to Action: Accelerate Your Decision Making with Real-Time AutomationFrom Event to Action: Accelerate Your Decision Making with Real-Time Automation
From Event to Action: Accelerate Your Decision Making with Real-Time AutomationSafe Software
 
Neo4j - How KGs are shaping the future of Generative AI at AWS Summit London ...
Neo4j - How KGs are shaping the future of Generative AI at AWS Summit London ...Neo4j - How KGs are shaping the future of Generative AI at AWS Summit London ...
Neo4j - How KGs are shaping the future of Generative AI at AWS Summit London ...Neo4j
 
How to Troubleshoot Apps for the Modern Connected Worker
How to Troubleshoot Apps for the Modern Connected WorkerHow to Troubleshoot Apps for the Modern Connected Worker
How to Troubleshoot Apps for the Modern Connected WorkerThousandEyes
 
Scaling API-first – The story of a global engineering organization
Scaling API-first – The story of a global engineering organizationScaling API-first – The story of a global engineering organization
Scaling API-first – The story of a global engineering organizationRadu Cotescu
 
Salesforce Community Group Quito, Salesforce 101
Salesforce Community Group Quito, Salesforce 101Salesforce Community Group Quito, Salesforce 101
Salesforce Community Group Quito, Salesforce 101Paola De la Torre
 
The Role of Taxonomy and Ontology in Semantic Layers - Heather Hedden.pdf
The Role of Taxonomy and Ontology in Semantic Layers - Heather Hedden.pdfThe Role of Taxonomy and Ontology in Semantic Layers - Heather Hedden.pdf
The Role of Taxonomy and Ontology in Semantic Layers - Heather Hedden.pdfEnterprise Knowledge
 
How to convert PDF to text with Nanonets
How to convert PDF to text with NanonetsHow to convert PDF to text with Nanonets
How to convert PDF to text with Nanonetsnaman860154
 
A Domino Admins Adventures (Engage 2024)
A Domino Admins Adventures (Engage 2024)A Domino Admins Adventures (Engage 2024)
A Domino Admins Adventures (Engage 2024)Gabriella Davis
 
Unblocking The Main Thread Solving ANRs and Frozen Frames
Unblocking The Main Thread Solving ANRs and Frozen FramesUnblocking The Main Thread Solving ANRs and Frozen Frames
Unblocking The Main Thread Solving ANRs and Frozen FramesSinan KOZAK
 
Understanding the Laravel MVC Architecture
Understanding the Laravel MVC ArchitectureUnderstanding the Laravel MVC Architecture
Understanding the Laravel MVC ArchitecturePixlogix Infotech
 
Transcript: #StandardsGoals for 2024: What’s new for BISAC - Tech Forum 2024
Transcript: #StandardsGoals for 2024: What’s new for BISAC - Tech Forum 2024Transcript: #StandardsGoals for 2024: What’s new for BISAC - Tech Forum 2024
Transcript: #StandardsGoals for 2024: What’s new for BISAC - Tech Forum 2024BookNet Canada
 
Slack Application Development 101 Slides
Slack Application Development 101 SlidesSlack Application Development 101 Slides
Slack Application Development 101 Slidespraypatel2
 
SQL Database Design For Developers at php[tek] 2024
SQL Database Design For Developers at php[tek] 2024SQL Database Design For Developers at php[tek] 2024
SQL Database Design For Developers at php[tek] 2024Scott Keck-Warren
 
04-2024-HHUG-Sales-and-Marketing-Alignment.pptx
04-2024-HHUG-Sales-and-Marketing-Alignment.pptx04-2024-HHUG-Sales-and-Marketing-Alignment.pptx
04-2024-HHUG-Sales-and-Marketing-Alignment.pptxHampshireHUG
 
08448380779 Call Girls In Friends Colony Women Seeking Men
08448380779 Call Girls In Friends Colony Women Seeking Men08448380779 Call Girls In Friends Colony Women Seeking Men
08448380779 Call Girls In Friends Colony Women Seeking MenDelhi Call girls
 

Último (20)

Google AI Hackathon: LLM based Evaluator for RAG
Google AI Hackathon: LLM based Evaluator for RAGGoogle AI Hackathon: LLM based Evaluator for RAG
Google AI Hackathon: LLM based Evaluator for RAG
 
Handwritten Text Recognition for manuscripts and early printed texts
Handwritten Text Recognition for manuscripts and early printed textsHandwritten Text Recognition for manuscripts and early printed texts
Handwritten Text Recognition for manuscripts and early printed texts
 
Transforming Data Streams with Kafka Connect: An Introduction to Single Messa...
Transforming Data Streams with Kafka Connect: An Introduction to Single Messa...Transforming Data Streams with Kafka Connect: An Introduction to Single Messa...
Transforming Data Streams with Kafka Connect: An Introduction to Single Messa...
 
#StandardsGoals for 2024: What’s new for BISAC - Tech Forum 2024
#StandardsGoals for 2024: What’s new for BISAC - Tech Forum 2024#StandardsGoals for 2024: What’s new for BISAC - Tech Forum 2024
#StandardsGoals for 2024: What’s new for BISAC - Tech Forum 2024
 
Strategies for Unlocking Knowledge Management in Microsoft 365 in the Copilot...
Strategies for Unlocking Knowledge Management in Microsoft 365 in the Copilot...Strategies for Unlocking Knowledge Management in Microsoft 365 in the Copilot...
Strategies for Unlocking Knowledge Management in Microsoft 365 in the Copilot...
 
From Event to Action: Accelerate Your Decision Making with Real-Time Automation
From Event to Action: Accelerate Your Decision Making with Real-Time AutomationFrom Event to Action: Accelerate Your Decision Making with Real-Time Automation
From Event to Action: Accelerate Your Decision Making with Real-Time Automation
 
Neo4j - How KGs are shaping the future of Generative AI at AWS Summit London ...
Neo4j - How KGs are shaping the future of Generative AI at AWS Summit London ...Neo4j - How KGs are shaping the future of Generative AI at AWS Summit London ...
Neo4j - How KGs are shaping the future of Generative AI at AWS Summit London ...
 
How to Troubleshoot Apps for the Modern Connected Worker
How to Troubleshoot Apps for the Modern Connected WorkerHow to Troubleshoot Apps for the Modern Connected Worker
How to Troubleshoot Apps for the Modern Connected Worker
 
Scaling API-first – The story of a global engineering organization
Scaling API-first – The story of a global engineering organizationScaling API-first – The story of a global engineering organization
Scaling API-first – The story of a global engineering organization
 
Salesforce Community Group Quito, Salesforce 101
Salesforce Community Group Quito, Salesforce 101Salesforce Community Group Quito, Salesforce 101
Salesforce Community Group Quito, Salesforce 101
 
The Role of Taxonomy and Ontology in Semantic Layers - Heather Hedden.pdf
The Role of Taxonomy and Ontology in Semantic Layers - Heather Hedden.pdfThe Role of Taxonomy and Ontology in Semantic Layers - Heather Hedden.pdf
The Role of Taxonomy and Ontology in Semantic Layers - Heather Hedden.pdf
 
How to convert PDF to text with Nanonets
How to convert PDF to text with NanonetsHow to convert PDF to text with Nanonets
How to convert PDF to text with Nanonets
 
A Domino Admins Adventures (Engage 2024)
A Domino Admins Adventures (Engage 2024)A Domino Admins Adventures (Engage 2024)
A Domino Admins Adventures (Engage 2024)
 
Unblocking The Main Thread Solving ANRs and Frozen Frames
Unblocking The Main Thread Solving ANRs and Frozen FramesUnblocking The Main Thread Solving ANRs and Frozen Frames
Unblocking The Main Thread Solving ANRs and Frozen Frames
 
Understanding the Laravel MVC Architecture
Understanding the Laravel MVC ArchitectureUnderstanding the Laravel MVC Architecture
Understanding the Laravel MVC Architecture
 
Transcript: #StandardsGoals for 2024: What’s new for BISAC - Tech Forum 2024
Transcript: #StandardsGoals for 2024: What’s new for BISAC - Tech Forum 2024Transcript: #StandardsGoals for 2024: What’s new for BISAC - Tech Forum 2024
Transcript: #StandardsGoals for 2024: What’s new for BISAC - Tech Forum 2024
 
Slack Application Development 101 Slides
Slack Application Development 101 SlidesSlack Application Development 101 Slides
Slack Application Development 101 Slides
 
SQL Database Design For Developers at php[tek] 2024
SQL Database Design For Developers at php[tek] 2024SQL Database Design For Developers at php[tek] 2024
SQL Database Design For Developers at php[tek] 2024
 
04-2024-HHUG-Sales-and-Marketing-Alignment.pptx
04-2024-HHUG-Sales-and-Marketing-Alignment.pptx04-2024-HHUG-Sales-and-Marketing-Alignment.pptx
04-2024-HHUG-Sales-and-Marketing-Alignment.pptx
 
08448380779 Call Girls In Friends Colony Women Seeking Men
08448380779 Call Girls In Friends Colony Women Seeking Men08448380779 Call Girls In Friends Colony Women Seeking Men
08448380779 Call Girls In Friends Colony Women Seeking Men
 

Java ME - 06 - Record Stores, Distribution and Localization

  • 1. Java™Platform, Micro Edition Part 6 – Record Stores, Distribution andLocalization v3.0a – 14 April 2009 1 Andreas Jakl, 2009
  • 2. Disclaimer These slides are provided free of charge at http://www.symbianresources.com and are used during Java ME courses at the University of Applied Sciences in Hagenberg, Austria at the Mobile Computing department ( http://www.fh-ooe.at/mc ) Respecting the copyright laws, you are allowed to use them: for your own, personal, non-commercial use in the academic environment In all other cases (e.g. for commercial training), please contact andreas.jakl@fh-hagenberg.at The correctness of the contents of these materials cannot be guaranteed. Andreas Jakl is not liable for incorrect information or damage that may arise from using the materials. This document contains copyright materials which are proprietary to Sun or various mobile device manufacturers, including Nokia, SonyEricsson and Motorola. Sun, Sun Microsystems, the Sun Logo and the Java™ Platform, Micro Edition are trademarks or registered trademarks of Sun Microsystems, Inc. in the United States and other countries. Andreas Jakl, 2009 2
  • 3. Contents Record Stores Input/OutputStreams Distribution Deployment Pre-Processing Obfuscation OTA-Deployment Localization Andreas Jakl, 2009 3
  • 4. Record Stores Save your data Andreas Jakl, 2009 4
  • 5. Persistent Data Most applications have to store something, e.g.: Settings Current status / progress / high scores User documents and results MIDP requires: Non-volatile memory At least 8kB Full file system access is optional (JSR 75) Andreas Jakl, 2009 5 
  • 6. Records: can be thought of rows in a table Record Store & Records Andreas Jakl, 2009 6 Record Store Integer value, role of a primary key for the database Stores the record data
  • 7. Record Management System MIDP Record Management System (RMS) works like DBMS Device-independent reading and writing, hides real database-file and location Database = “Record Store” Consists of a number of recordswith automatically assigned, unique IDs: 1, 2, ... Record = Array of bytes To change content: read byte array  modify it  replace original record Andreas Jakl, 2009 7
  • 8. MIDlets and Record Stores MIDlets can access all record stores in their suite With a fully qualified name also from other suites Andreas Jakl, 2009 8 Record Store “S” Record Store “T” MIDlet Suite A MIDlet 1 MIDlet 1 Names must be unique within a single MIDlet suite MIDlet 2 MIDlet 2 Record Store “S” MIDlet Suite B
  • 9. Record Store Features Record Store saves: Time + Date of last modification Version number (integer), incremented for each operation that modified the contents Individual operations (write, ...) are atomic, synchronous and serialized When MIDlet uses multiple threads to access a single record store, it is responsible for synchronization Andreas Jakl, 2009 9
  • 10. RecordStore API Opening / Creating a Record Store RecordStorers = RecordStore.openRecordStore( String recordStoreName, booleancreateIfNecessary); recordStoreName: MIDlet suite-unique name, up to 32 (Unicode) chars createIfNecessary: if it does not exist, create it or throw an exception Add Records intnewId = rs.addRecord(byte[] data, intoffset, intnumBytes); newId: ID of the record that was created (1, 2, ...) data: byte-array to add as a new record offset: index into data buffer (first byte to write), usually 0 numBytes: number of bytes to use (length of data to write) Andreas Jakl, 2009 10
  • 11. RecordStore API Reading a record byte[] record = rs.getRecord(intrecordId); record: copy of the data stored in the record recordId: ID of the record to retrieve Close the record store rs.closeRecordStore(); Delete a record store RecordStore.deleteRecordStore(String recordStoreName); Andreas Jakl, 2009 11
  • 12. Byte-Arrays Working with Andreas Jakl, 2009 12
  • 13. Streams Java offers comfortable streams to: Create byte arrays on the fly (ByteArrayOutputStream) Write standard data types to the stream (DataOutputStream) Andreas Jakl, 2009 13 String object String object DataOutputStream.writeUTF(); DataInputStream.readUTF(); DataOutputStream DataInputStream ByteArrayOutputStream ByteArrayInputStream byte[] byte[]
  • 14. Output Stream Example Andreas Jakl, 2009 14 // Open (+ create) the record store with the name "MyData" RecordStorers = RecordStore.openRecordStore("MyData", true); // First create the byte array output stream which can generate the array ByteArrayOutputStreambos = new ByteArrayOutputStream(); // On top of that, create the data output stream, // which can serialize several standard Java data types DataOutputStream dos = new DataOutputStream(bos); // Write data to the stream dos.writeInt(667487); dos.writeBoolean(true); dos.writeUTF("Test"); // Flush data to make sure everything is commited down streams dos.flush(); // Grab byte array from the stream byte[] recordOut = bos.toByteArray(); // Add a new record to the record store, write the whole array from 0 to its length intnewRecordId = rs.addRecord(recordOut, 0, recordOut.length); // Finished working on the record store – close it dos.close(); // Closes underlying output stream as well rs.closeRecordStore(); (example omits catching Exceptions for clarity)
  • 15. Byte Array Contents of the byte array: Andreas Jakl, 2009 15 dos.writeInt(667487); dos.writeBoolean(true); dos.writeUTF("Test"); Int (4 bytes) Boolean (1 byte) Number of bytes used (2 bytes) String UTF-8 encoded String (4 bytes) DataOutputStream-Methods only save data, no type information  you have to remember what you wrote and read it in exactly the same order
  • 16. Reading Rather similar to writing: Andreas Jakl, 2009 16 // Open the record store with the name "MyData" RecordStorers = RecordStore.openRecordStore("MyData", false); // Get record contents byte[] record = rs.getRecord(newRecordId); // First create the byte array input stream which accesses the byte array ByteArrayInputStreambis = new ByteArrayInputStream(record); // On top of that, create the data input stream, // which can interpret the contents byte array as Java data types DataInputStreamdis = new DataInputStream(bis); // Read data from the stream int version = dis.readInt(); booleanfirstStart = dis.readBoolean(); String userName = dis.readUTF(); // Finished working on the record store – close it dis.close(); // Closes underlying input stream as well rs.closeRecordStore(); (example omits catching Exceptions for clarity)
  • 17. ... back to the RecordStore Enough reading and writing ... Andreas Jakl, 2009 17
  • 18. RecordStore API Modify (= overwrite, replace) existing record rs.setRecord(intrecordId, byte[] newData, intoffset, intnumBytes); recordId: ID of the record to replace data: byte-array to add as a the new record offset: index into data buffer (first byte to write), usually 0 numBytes: number of bytes to use (length of data to write) Andreas Jakl, 2009 18
  • 19. Strategy – Settings Saving application settings Write all settings to a byte array into one record of a single record store If possible: Write directly after settings change, not when exiting the application You never know when and how the program is closed(battery removed?) Read on application start-up Use default settings for “file not found”-Exception Andreas Jakl, 2009 19
  • 20. Settings – Existing Record When saving settings, check: New record store was created ->add record Record store already exists -> replace record Andreas Jakl, 2009 20 if (rs.getNumRecords () == 0) { // Check if record store already contains our settings record rs.addRecord(recordOut, 0, recordOut.length); // Add new record to the store, will get position 1 } else { rs.setRecord (1, recordOut, 0, recordOut.length); // Replace previous settings-record }
  • 21. Settings – Version Save version of data structure to prevent problems after updating application (Version of Record Store only saves # of modifications!) Store version at the beginning of the stream dos.writeShort (1); // Version Check version when reading stream int version = dis.readShort();if (version == 1) { /* Continue parsing */ } Andreas Jakl, 2009 21
  • 22. Strategy – Database Application with database (e.g. time management) Multiple records per record store.Each record = one entry, which consists of the data, written as a byte array as usual Serializing Objects Used to save object’s state to a sequence of bytes Allows rebuilding an identical object later on Not supported in current CLDC Write it yourself: Use a stream to put all relevant data into a stream; read and create obj. in a static method Andreas Jakl, 2009 22
  • 23. Example – Database I Andreas Jakl, 2009 23 ContactData class, contains information about a person public class ContactData { private String name; // Saves name of the contact private int age; // Saves age public ContactData (String name, int age) { this.name = name; this.age = age; } /** Write all relevant data to the stream, which will allow rebuilding the object when reading the stream. */ public void externalize(DataOutputStream dos) throws IOException { dos.writeUTF (name); dos.writeInt (age); } /** Read data from the stream and use it to create and return a new instance of this object. */ public static ContactDatainternalize(DataInputStreamdis) throws IOException { String tmpName = dis.readUTF (); inttmpAge = dis.readInt (); return new ContactData(tmpName, tmpAge); } /** Return relevant information in string form. */ public String toString() { return ("Contact data: Name = " + name + ", Age = " + age); } }
  • 24. Example – Database II Andreas Jakl, 2009 24 Main application – save contacts to the database // Create new vector that will contain all contact data Vector names = new Vector(); names.addElement (new ContactData("Valerie Dimeling", 20)); names.addElement (new ContactData("Ginger Hay", 54)); try { RecordStore.deleteRecordStore ("myRs"); // Make sure no record store already exists RecordStorers = RecordStore.openRecordStore("myRs", true); // Create a new record store ByteArrayOutputStreambos = new ByteArrayOutputStream(); // Create streams for writing data DataOutputStream dos = new DataOutputStream(bos); // Go through the vector and create a record for each element for (Enumeration e = names.elements (); e.hasMoreElements (); ) { ContactDatacd = (ContactData) e.nextElement (); // Get next element of the vector cd.externalize (dos); // Let the instance externalize itself into our stream dos.flush(); // Make sure everything is written byte[] record = bos.toByteArray (); // Get byte array from the record rs.addRecord (record, 0, record.length); // Add the record to the store bos.reset (); // Clear the output stream so that we can start from scratch } dos.close (); […]
  • 25. Example – Database III Andreas Jakl, 2009 25 Main application – restore database from the record store // Read back data using a record enumerator to go through all elements // Record enumerator would be more powerful, we do not use the advanced features here RecordEnumerationrenum = rs.enumerateRecords (null, null, false); while (renum.hasNextElement ()) { byte[] record = renum.nextRecord (); // Get data of the next record ByteArrayInputStreambis = new ByteArrayInputStream(record); // Input streams for parsing data DataInputStreamdis = new DataInputStream(bis); ContactDatacd = ContactData.internalize (dis); // Internalize and create new instance (static method) System.out.println(cd); // Print information to console dis.close(); } rs.closeRecordStore (); // Close the record store } catch (RecordStoreException ex) { ex.printStackTrace(); } catch (IOException ex) { ex.printStackTrace(); }
  • 26. Advanced Access Sorting RecordComparator Searching RecordFilter Notification of changes RecordListener Andreas Jakl, 2009 26
  • 27. Distributing MIDlets Let others experience your fabulous applications! Andreas Jakl, 2009 27
  • 28. Device Fragmentation Mobile devices vary in: Screen size Colour depth Speed Optional API support (Bluetooth, ...) Bugs (+ their workarounds) Solution (in NetBeans): Project configurations + pre-processing (like in C++) Andreas Jakl, 2009 28
  • 29. Project Configurations Project Configurations used for Setting variables that are used for pre-processing Including required files to .jar-archive Modify build settings (Obfuscation, ...) Create new configuration Project Properties  Manage Configurations ...  Duplicate one of the configurations Andreas Jakl, 2009 29
  • 30. Adapt Abilities Define variables for pre-processing e.g. ScreenWidth, support for APIs, ... Andreas Jakl, 2009 30
  • 31. Fragment your Code Use pre-processor directives to adapt code depending on abilities of current project configuration Andreas Jakl, 2009 31
  • 32. Adapt Included Resources Choose which files to include for each project configuration: Andreas Jakl, 2009 32
  • 33. Set Active Configuration Right click on the project  “Set Active Project Configuration”: Defines which pre-processor block is active Andreas Jakl, 2009 33 “SmallScreen” ScreenHeight = 128 “MediumScreen” ScreenHeight = 320
  • 34. Optimization – Obfuscation Original intention: Make reverse engineering more difficult Code more difficult to read after de-compilation Renames classes to “a.class, b.class, …” Removes non-used methods, variables, classes  Significant size reduction Over-the-Air = expensive! MIDlet size restrictions in many phones Improves speed (less code to load / parse) Andreas Jakl, 2009 34
  • 35. Obfuscation Andreas Jakl, 2009 35 Original archive 79.2 kB Obfuscated 42.9 kB = 45% smaller!
  • 36. Define Obfuscation Level For release builds: Activate obfuscation (max. level) Don’t use it for debugging Andreas Jakl, 2009 36
  • 37. Build All Configurations Andreas Jakl, 2009 37 ... creates own directory and .jar/.jad for each configuration Default configuration located in base directory
  • 38. Over-The-Air Deployment Transmitting MIDlets to phones Andreas Jakl, 2009 38
  • 39. Why OTA for Deployment? Some phones (Samsung, Sagem, BREW,...) do not support installing MIDlets through the PC or Bluetooth Only alternative: Download directly through mobile phone (UTMS)  Over-the-Air (OTA) delivery Andreas Jakl, 2009 39
  • 40. Over-the-Air Andreas Jakl, 2009 40 HTTP Web Server Mobile Device AMS (Application Management Software) JAD-Server JAR-Server Notification Server GET /midlet.jad GET /midlet.jar POST /install-notify (900 Success) 200 OK 200 OK 200 OK
  • 41. Web Server – MIME Types Add MIME-Types for .jad and .jar to your web server Required for the phone to correctly handle the files Then, simply provide a link to the .jad-file on your website The .jad-file contains the link to the .jar archive Andreas Jakl, 2009 41 Example screenshot: SiteAdmin-Tool used at:http://www.site5.com/
  • 42. Automated Deployment Andreas Jakl, 2009 42 Make sure the .jar-URL is set correctly in the .jad-file that you upload to your webserver!
  • 43. Localization Prepare for the international market Andreas Jakl, 2009 43
  • 44. Localization Mobile phones available on a global market Goal: Make source code independent of language, load text for user language from a file Query current language: String locale = System.getProperty ("microedition.locale"); Examples:en-US, en-GB, de-DE NetBeans: Provides ready-made LocalizationSupport-class & tools for managing message bundles Andreas Jakl, 2009 44 
  • 45. Add Support Class Andreas Jakl, 2009 45
  • 46. Define Settings You can usually accept the default values: Andreas Jakl, 2009 46
  • 47. Add Localized String Tools  Internationalization  Insert Internationalized String... Andreas Jakl, 2009 47 Get the localized string from your source code using the static function: Initialization will be done automaticallywhen you retrieve the first message.
  • 48. Message Bundle Add additional locales for new languages Define same keys in all files Andreas Jakl, 2009 48
  • 49. Thanks for your attention That’s it! Andreas Jakl, 2009 49