简体   繁体   中英

J2ME - Code once and run everywhere?

我可以在J2ME中编写一次代码并在任何手机上运行,​​就像我可以使用.Net紧凑框架一样吗?

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.

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.

...

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 eg 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 ;) )

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.

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"

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.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM