Ben++

J2ME

Java String Comparing Optimization
1. == and String.equals()

Firstly look into this code:

String s1 = "test";
String s2 = "test";
boolean result = s1== s2;

What the result will be? It will be true. not because the content of s1 and s2 are equal, but because the s1 and s2 references are so.

The == operator, when applied to references, simply compares the references themselves for equality, and not the referenced objects. s1 s2 here are two references to this "test" string-valued constant in Constant Pool, and we should know all strings in this pool are guaranteed to be unique.

Conversely, if two references are equal using ==, then you can be sure that they refer to identical objects. So if you are comparing strings, and there is a good chance of encountering identical ones, then you can say:

if (s1 == s2 || s1.equals(s2))
...

"Always perform a cheap test before an expensive on, if you possibly can", here == is much cheaper than equals().

2. Interning Strings

The Java String class has a method called intern(), it returns a string that has the same contents as this string, but is guaranteed to be from a pool of unique strings. Saying:
str = str.intern();
adds the string to the pool if not already there, and returns a reference to the interned string. Interned strings can be compared with each other using ==, which is much cheaper than using equals() to do the comparison.  For any two strings s1 and s2, s1.intern() == s2.intern() is true if and only if s.equals(t) is true.

An example of interning strings:

// interning strings 
public class str_intern { 
    public static void main(String args[]) { 
        String str = new String("testing"); 
        // interning not done 
        if (str == "testing") 
            System.out.println("equal"); 
        else 
            System.out.println("unequal"); 
        // interning done 
        str = str.intern(); 
        if (str == "testing") 
            System.out.println("equal"); 
        else 
            System.out.println("unequal"); 
    } 
}
 
In the first example, the test str == "testing" compares false, because str is a reference to a string that is a copy of the literal "testing", while "testing" itself is an interned string, and therefore the corresponding references are distinct.  In the second example,  the test compares true, because str has been interned, and the reference returned from the intern() call is identical to the reference to the "testing" literal already in the internal string pool.

String interning is a very fast way of doing comparisons within a pool of strings, with an initial cost incurred in actually doing the interning, comparing with existed strings by equals(Object).

发表于 @ 2006年12月12日 12:57 AM | 评论 (0)

Be tracked wherever you are by your employer!
From Horst Thieme's blog @ SUN

Trisent TrilocatorTrisent is a technology company that has created a revolutionary new way to continuously track the location of mobile phones. Unlike Cell-ID technology the system is continuously aware of the location of the tracked phone, when a phone moves the location is automatically updated. This is a real alternative to GPS and it uses standard mobile phone handsets! Trisent argues: "GPS handsets are expensive, they drain your battery quickly and in many situations they cannot see the satellites so they don't always work. Trisent's technology overcomes these problems by using off-the-shelf technology which works anywhere with mobile coverage."

Trisent, a scottish mobile company, partners together with russian operator Vimpelcom to roll this service out. Perhaps a nightmare for every worker but a great control about their employees for the companies using this service. The only opportunity NOT to get tracked is by switching of the mobile phone...

More info at http://www.trisent.com/.

发表于 @ 2006年09月21日 7:14 PM | 评论 (0)

JavaMasters 2006大赛


Java Masters 2006
展示创意, 赢取你的德国之旅

The game goes on ... the players change – slightly.“

Sun Microsystems很荣幸再一次为你带来Java Masters大赛――这次我们的合作伙伴变成了BenQ Mobile(前Siemens Communications Mobile Devices Business)。不变的是我们将继续为独立开发者和小型公司提供一个向全世界展示创意的舞台!

比赛已经进入第四个年头,我们感受到更大的乐趣,收到了更多的高质量移动应用。是Java社区和开发者的活力让这个比赛成功,这也鼓励了我们继续推动这个大型的全球性比赛。

作为移动Java领域的两个重要推动者,BenQ Mobile和Sun Microsystems再一次挑战全世界学生和公司的创意――展示你们为我们最新Java™手机BenQ Siemens SXG75, S75 and CX75开发的原创程序!

你能成为“Student Java Master”或者“Professional Java Master”,你能获得由BenQ Mobile和Sun Microsystems提供的丰富奖品和商业机会!

„Let the games begin! “

比赛已经在2006年2月6日开始,截止至2006年5月21日。
了解详情,参加比赛,下载BenQ Mobile "Mobility Tool Kit" (MTK) 和"NetBeans 5.0 Mobility Pack"――

敬请浏览
www.javamasters.org

发表于 @ 2006年04月20日 4:19 PM | 评论 (4)

Location Sensing for Mobile Computing--移动计算中的位置感知
Location Sensing for Mobile Computing
.
Oriana Riva
University of Helsinki, Department of Computer Science
FIN00014
University of Helsinki, Finland
riva@cs.helsinki.fi

Download PDF file



前几天看到的论文,很棒~详细接受当前移动定位发展情况和遇到的问题。


户外定位技术
  • 基于无线网络的解决方案:利用网络服务商的基站信息进行定位。
  • 手持设备解决方案:GPS设备,本来这对无线设备用户是没什么吸引力的,但去年在德国看到了西门子SXG75,它集成了GPS模块,试用了利用GPS模块开发的程序后,对GPS在手机上的应用前景有了新的看法。另外,JavaMasters 2005商业组冠军Nikolay开发的MobiTrack,也是GPS应用程序,不过需要额外配置一个蓝牙GPS接受器,通过蓝牙与手机通讯;地图信息从Google Map获取。虽然这软件很Cool,但我觉得没有太大的市场,因为没太多人愿意额外花钱去购买一个GPS接收器并带着它漫街跑--接受器的体积有半台手机大了。不过如果手机制造上集成了GPS模块,情况又会很不一样。
  • Hybrid解决方案

室内定位技术
-- 这才是我感兴趣的。
  • 红外
  • 超声波
  • IEEE 802.11
  • 蓝牙
  • RFID射频识别
  • 室内GPS
随着JSR-82 Java APIs for Bluetooth的广泛应用,蓝牙定位成了可能,主要是利用接收到的蓝牙信号的强弱来判断距离,但光有距离怎么可以定位?难道需要两个蓝牙设备作为基站?还是蓝牙信号具有方向性?这我还学要研究。

另外JSR-179 Location API就实现了不少室内和室外的定位技术。

 

发表于 @ 2006年01月07日 4:56 PM | 评论 (3)

[J2ME] An article about the Media API ( JSR 135 )
Motocoder, Motorola's developer center, has released an article about the JSR 135, better known as the Mobile Media API.

The article includes a working example of an application that allows to capture images by camera.

Download the article ( pdf )


发表于 @ 2005年12月30日 4:05 AM | 评论 (0)

[J2ME] About the JSR-135 Mobile Media API

    摘要:The proposed Multimedia API specification provides a high-level interface to sound and multimedia capabilities of a device running J2ME. The target is to enable versatile multimedia functionality in J2ME applications. The specification willl address the scalability of a Multimedia API for various devices. To focus the effort, care will be given to ensure that this API will support basic sound functionality on constrained memory devices, with the possibility of additional functionality supported     (全文共10620字)——点击此处阅读全文

发表于 @ 2005年12月30日 4:00 AM | 评论 (0)

第1页,共1页

news



我的豆瓣
我的Flickr

订阅Rss到我的MixWeb个性化主页

New Posts

导航

blog stats

文章

收藏

相册

Friends

Other

存档


正在读取评论……