my dog learned polymorphism*
The moose likes Java Micro Edition and the fly likes AJAX code in j2ME applictaion Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login
JavaRanch » Java Forums » Mobile » Java Micro Edition
Bookmark "AJAX code in j2ME applictaion" Watch "AJAX code in j2ME applictaion" New topic
Author

AJAX code in j2ME applictaion

Priyanka Gawada
Greenhorn

Joined: May 08, 2012
Posts: 12

I want to develop a simple project in j2ME which should have AJAX functionality, web services, and a rich interface.

Kindly help me on whether AJAX is possible in J2ME applications without using any external or third-party API. If yes, provide me some small snippets for trying.

Also, suggest me an application which can be built using AJAX, web services and user interface in J2ME. Should a SMS facility can also be included in the application.

Thanks.
Walter Gabrielsen Iii
Ranch Hand

Joined: Apr 09, 2011
Posts: 158
No AJAX isn't possible because you don't have html, css or Javascript in Java ME.

Well actually it's possible to call up a server using javax.microedition.io.Connector to return a Connection, HttpConnection or HttpsConnection, among others.

Then you just need to rewrite the AJAX XMLHttpRequest to send a request using Java's Connection : HTTPConnection/HTTPSConnection instead. Methods GET and Post are supported by HTTPConnection, the url is of course supported, and you can use a Thread/Runnable combo for async=true).

Java ME can also process XML using the SAX parser from SAXParserFactory (javax.xml.parsers) In JSR 172. So that takes care of the response part. But, with SAX you need to do your own work overwriting the methods of the DefaultHandler class.

Java ME can do SMS.
Priyanka Gawada
Greenhorn

Joined: May 08, 2012
Posts: 12
Thanks for the reply.
Call up server is fine, still Javascript will be required to send asynchronous call. So, may be AJAX is still not possible on J2ME.
I heard about Java ME. But not understood what it is clearly?
Do you have any idea regarding this?
Walter Gabrielsen Iii
Ranch Hand

Joined: Apr 09, 2011
Posts: 158
As far as graphics, you get the things in javax.microedition.lcdui and javax.microedition.lcdui.game packages.

That means the screen graphics forms:
Alert,
Form (and its associated items: ChoiceGroup, CustomItem, DateField, Gauge, ImageItem, Spacer, StringItem, TextField),
List,
TextBox
Or make your own screens with Canvas, or GameCanvas and their assosiated paint() method and Graphics object.
Walter Gabrielsen Iii
Ranch Hand

Joined: Apr 09, 2011
Posts: 158
You don't need Javascript for asynchronous tasks because you've got Java! To be more specific asynchronous (done at the same time) tasks are done in Java using Threads.

In Java ME you have the following options:

1. run() method and Thread Object:
java.lang.Runnable -- the run() method a class needs to implement to run its run() asynchronously.
java.lang.Thread -- the object that you need to "start()" the Runnable task in its own thread of execution(asynchronous task).

2. Timer, TimerTask
java.util.TimerTask -- this is like Runnable but for tasks that can be scheduled with a time setting.
java.util.Timer -- this is like Thread but with time scheduling instead of starting things right away.


Also if you learn about methods Object.wait(), Object.notify(), Thread.interrupt(), Timer.cancel(), and the synchronized block features of Java then you can extend the lifetime of your threads, and have them wait in the background not wasting resources until something happens.
Walter Gabrielsen Iii
Ranch Hand

Joined: Apr 09, 2011
Posts: 158
What is Java ME? Java ME is the mobile edition (ME) of the Java programing language. Java is an object-oriented, platform independent --so you don't need a specific Operating System or computer platform to run it-- language for programmers who want their programs to run on many different platforms without needing to recompile their program for each one.
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: AJAX code in j2ME applictaion
 
Similar Threads
Please suggest some projects
Suggestion for a good project
JAX-RPC Based Web service
AJAX with WebWork or Struts
Please help me