tags:

views:

591

answers:

6

Can I code once in J2ME and run it on any mobile phone just like I can using the .Net compact framework?

Thanks

+4  A: 

You will run into differences in how each provider has implemented their JVM. Since each phone's hardware is different, they all work slightly differently. Most stuff will work, but there might be some differences.

Mike Pone
+1  A: 

Neither J2ME nor .NET Compact Framework are ubiquitous, (though J2ME is supported on an impressive number of phones) You can only run either on phones that support them. So in either case you can write once and run wherever the platform/framework is supported.

cmsjr
+1  A: 

Yep, you can run your midlets on any java supported phones.

But when it comes to j2me coding, the slogan "write once, run anywhere" becomes

"write once, rewrite everywhere"

or

"write once, debug everywhere"

Manoj
I prefer the slightly more optimistic (and possibly achivable) version: "write once, test everywhere" :)
Martin
+4  A: 

Several areas that suffer from fragmentation:

  • If you only use basic GUI controls, your application may look a bit different from one phone to the next. If you don't you have to write code that handles different screen sizes and input methods (keypad vs touchscreen).

  • Manufacturers have a tendency to either interpret the specifications for multimedia and networking differently, or simply ship phones containing bugs. Some mobile network operator will only allow HTTP network trafic.

  • The security policies that regulate file system access are different from one phone to the next. RMS records can be limited in size on some phones.

  • Performance varies widly from one phone to the next.

...

QuickRecipesOnSymbianOS
+3  A: 

The J2ME code that you write needs a certain environment on the phone in terms of the runtime and the classes that are accessible to it. Depending on what you use in your application you would be able to run it on some phones and it wont work on other. For e.g. let say you a J2ME application that uses MIDP 2.0 and CDLC 1.1. Now, your app will only work on phones that support these profiles.

You normally target a certain segment of mobile phones when writing mobile phone applications. You dont expect an acceleratometer application to work on phones that dont have an acceleratometer! ( I dont think J2ME has any support for acceleratometers though ;) )

Prashast
That's not the case; see the Sensor API (JSR 256). http://jcp.org/en/jsr/detail?id=256
funkybro
I didn't there was a JSR for that. Anyways, the point I was trying to convey is that you target phones based on their capabilities and your application requirements.
Prashast
+1  A: 

First of all, I'd like to say that most of the comments here are true, different JVMs may work slightly differently indeed and you should remember about APIs you are using.

However, there's one more consideration that should be taken into account: standardization. I mean such things as Mobile Services Architecture (MSA - JSR 248), they greatly simplfy things by creating some standart sets of APIs. Moreover, they carry some clarifications to included APIs and rules on how to implement them.

Also such things as MIDP 2.1 are tightening standarts. 2.1 verison is basically 2.0, but with "bolts tightened": more strict rules that make some aspects clear and remove potential fragmentation. For example, there's a requirement to include double buffering in any case or to support touch screen in Java if a device has one.

Having said that, I should conclude that fragmentation is really decreasing, manufacturers do adopt standarts like JSR 248. But test your applications as much as needed anyway, we're all people and JVM developers also make mistakes and leave bugs in their code.

Malcolm