如果找到了对您有用的资料,烦请点击右手边的Google广告支持我继续共享知识,谢谢! http://dengpeng.spaces.live.com/

2008年7月14日星期一

Simplest Java SE Web Service Tutorial

CircleFunctions.java

package geometricalws;

import javax.jws.WebMethod;
import javax.jws.WebParam;
import javax.jws.WebService;
import javax.jws.soap.SOAPBinding;

@WebService(name = "Circle", serviceName = "CircleService", portName = "CirclePort")
@SOAPBinding(style = SOAPBinding.Style.RPC)
public class CircleFunctions {

@WebMethod(operationName = "area")
public double getArea(@WebParam(name = "r") double r) {
return Math.PI * (r * r);
}

@WebMethod(operationName = "circumference")
public double getCircumference(@WebParam(name = "r") double r) {
return 2 * Math.PI * r;
}
}

Main.java

/*
* To change this template, choose Tools | Templates
* and open the template in the editor.
*/

package geometricalws;

import javax.xml.ws.Endpoint;

/**
*
* @author Administrator
*/

public class Main {

/**
* @param args the command line arguments
*/

public static void main(String[] args) {
String wsAddress = "http://localhost:8765/GeometricalWS/CircleFunctions";
Endpoint.publish(wsAddress, new CircleFunctions());
System.out.println("Web service was published successfully.\n" +
"WSDL URL: " + wsAddress + "?WSDL");
// Keep the local web server running until the process is killed
while (Thread.currentThread().isAlive()) {
try {
Thread.sleep(10000);
} catch (InterruptedException ex) {
}
}
}
}





Read this document on Scribd: nb02-part6-jsews

2008年7月12日星期六

Change local in NetBeans IDE

My operating platform is Chinese version, while I prefer to user English version IDE. It's strange that the menu and label are still Chinese words even if I downloaded and installed a English version NetBeans. Java's i18n is great, so NetBeans can adjust its local according to Operating Platform by default.
To change the NetBeans local to English version, modify the file $NETBENA_HOME/etc/netbeans.conf
add "--local en" in "netbeans_default_options"
For example, the original:
netbeans_default_options="-J-Xms32m -J-Xmx128m -J-XX:PermSize=32m -J-XX:MaxPermSize=160m -J-Xverify:none -J-Dapple.laf.useScreenMenuBar=true "
Modified:
netbeans_default_options="-J-Xms32m -J-Xmx128m -J-XX:PermSize=32m -J-XX:MaxPermSize=160m -J-Xverify:none -J-Dapple.laf.useScreenMenuBar=true --locale en"

http://lilyblack.spaces.live.com/Blog/cns!90FA6316A38FD1CD!236.entry

2008年6月12日星期四

Markov and You

http://www.codinghorror.com/blog/archives/001132.html

In Finally, a Definition of Programming I Can Actually Understand I marvelled at particularly strange and wonderful comment left on this blog. Some commenters wondered if that comment was generated through Markov chains. I considered that, but I had a hard time imagining a text corpus input that could possibly produce output so profoundly weird.

So what are these Markov chains we're talking about?

One example of Markov chains in action is Garkov, where the long running Garfield cartoon strip meets Markov chains. I present below, for your mild amusement, two representative strips I found on the Garkov hall of fame:

garkov-sample-1.png

garkov-sample-2.png

Garfield's an easy target, though:

  • Garfield Minus Garfield. What it says on the tin. Surprisingly cathartic.
  • Lasagna Cat. Almost indescribably strange live action recreations of Garfield strips. If you only click one link in this post, make it this one. Sanity optional.
  • Garfield Variations. Hand-drawn versions of Garfield in underground "comix" style, usually on paper napkins.
  • Barfield. Garfield strips subtly modified to include amusing bodily functions.
  • Permanent Monday. Literary commentary on selected strips.
  • Arbuckle. Strips faithfully redrawn by random internet "artists", with one dramatic twist: Jon can't actually hear Garfield, because he is, after all, a cat.
  • Garfield Randomizer. Sadly defunct -- combined random panels to form "new" Garfield strips.

So let's proceed to the "kov" part of Garkov. The best description of Markov chains I've ever read is in chapter 15 of Programming Pearls:

A generator can make more interesting text by making each letter a random function of its predecessor. We could, therefore, read a sample text and count how many times every letter follows an A, how many times they follow a B, and so on for each letter of the alphabet. When we write the random text, we produce the next letter as a random function of the current letter. The Order-1 text was made by exactly this scheme:
t I amy, vin. id wht omanly heay atuss n macon aresethe hired boutwhe t, tl, ad torurest t plur I wit hengamind tarer-plarody thishand.

We can extend this idea to longer sequences of letters. The order-2 text was made by generating each letter as a function of the two letters preceding it (a letter pair is often called a digram). The digram TH, for instance, is often followed in English by the vowels A, E, I, O, U and Y, less frequently by R and W, and rarely by other letters.

Ther I the heingoind of-pleat, blur it dwere wing waske hat trooss. Yout lar on wassing, an sit." "Yould," "I that vide was nots ther.

The order-3 text is built by choosing the next letter as a function of the three previous letters (a trigram).

I has them the saw the secorrow. And wintails on my my ent, thinks, fore voyager lanated the been elsed helder was of him a very free bottlemarkable,

By the time we get to the order-4 text, most words are English, and you might not be surprised to learn that it was generated from a Sherlock Holmes story ( "The Adventure of Abbey Grange'').

His heard." "Exactly he very glad trouble, and by Hopkins! That it on of the who difficentralia. He rushed likely?" "Blood night that.

So the text in Garkov strips is generated in exactly this way, but using words instead of letters. The input corpus is, as you'd expect, the text of many old Garfield strips.

What's amazing to me about Markov chains is how unbelievably simple they are. A Markov chain has no memory of previous states: the next state (word, in our case) is chosen based on a random dice roll and a lookup into a table of the states that tend to historically follow the current state in the input corpus. Given an adequate input corpus, they work almost uncannily well, a testament to the broad power of rudimentary statistical inference. Garfield's been around since 1978, and still going str.. well, going, so there's no shortage of material to work with.

Now let's try it ourselves. I fed the text of the last twelve Paul Graham essays to this online Markov generator, using two word groupings -- what Bentley refers to as "Order-2". Here's what I got back:

You can feel the need to take advantage of increased cheapness, however. You're not all playing a zero-sum game. There's not some fixed number of startups; we fund startups we fund to work on matters of passing importance. But I'm uncomfortably aware that this is part of any illusions about the problem of overeating by stopping eating. I couldn't simply avoid the Internet had become, because the company is the new trend of worrying obsessively about what it meant for someone, usually an outsider, who deliberately stirred up fights in a startup than just start it. You know how the A List is selected. And even that is more work.

But Markov chains aren't just useful for automatically generating Paul Graham essay parodies. They're also quite practical. You might even say Markov chains are a large part of what powers today's internet. Most remarkably, to me at least, Markov chains underly Google's trillion dollar PageRank formula:

The [PageRank] formula uses a model of a random surfer who gets bored after several clicks and switches to a random page. The PageRank value of a page reflects the chance that the random surfer will land on that page by clicking on a link. [PageRank] can be understood as a Markov chain in which the states are pages, and the transitions are all equally probable and are the links between pages.

As a result of Markov theory, it can be shown that the PageRank of a page is the probability of being at that page after lots of clicks. This happens to equal t-1 where t is the expectation of the number of clicks (or random jumps) required to get from the page back to itself.

Incidentally, if you haven't read the original 1998 PageRank paper, titled The PageRank Citation Ranking: Bringing Order to the Web (pdf), you really should. It's remarkable how, ten years on, so many of the predictions in this paper have come to pass. It's filled with interesting stuff; the list of the top 15 PageRank sites circa 1996 in Table 1 is an eye-opening reminder of how far we've come. Plus, there are references to pornographic sites, too!

Markovian models -- specifically, hidden Markov Models -- are also related to our old friend, Bayesian spam filtering. They're even better! The most notable example is the CRM114 Discriminator, as outlined in this excellent presentation (pdf).

How to Turn a Bayesian into a Markovian

If you play with the Markov text synthesizer, you'll quickly find that Markov methods are only as good as their input corpus. Input a bunch of the same words, or random gibberish, and that's what you'll get back.

But it's sure tough to imagine a more ideal input corpus for Markovian techniques than the unimaginable vastness of web and email, isn't it?

[advertisement] Read the largest case study ever published about lightweight peer code review in Best Kept Secrets of Peer Code Review. Free book, free shipping.

3D Accelerometer Based Gesture Control Human Computer Interface

ABSTRACT: We developed a gesture based human computer interaction interface. Wireless sensor node is used to capture human body acceleration data. To segment received acceleration data stream, we developed an algorithm based on sliding window and standard deviation. To recognize gesture, Hidden Markov Model (HMM) which is a machine learning algorithm is used. Series prototype applications are built to demonstrate possible gesture based applications in future. We conducted several experiments as well. Finally, we got highest 96% accuracy and lowest 17% accuracy.

KEYWORDS: body sensor network, wireless sensor network, data stream processing, hidden markov model, machine learning, gesture recognition, human-computer interface

Source code will be available later

2008年5月31日星期六

Learning from Data Streams

Learning from Data Streams
Processing Techniques in Sensor Networks
Gama, Joao; Gaber, Mohamed Medhat (Eds.)
2007, X, 244 p. 73 illus., Hardcover
ISBN: 978-3-540-73678-3

 

Sensor networks consist of distributed autonomous devices that cooperatively monitor an environment. Sensors are equipped with capacities to store information in memory, process this information and communicate with their neighbors. Processing data streams generated from wireless sensor networks has raised new research challenges over the last few years due to the huge numbers of data streams to be managed continuously and at a very high rate.

The book provides the reader with a comprehensive overview of stream data processing, including famous prototype implementations like the Nile system and the TinyOS operating system. The set of chapters covers the state-of-art in data stream mining approaches using clustering, predictive learning, and tensor analysis techniques, and applying them to applications in security, the natural sciences, and education.

This research monograph delivers to researchers and graduate students the state of the art in data stream processing in sensor networks. The huge bibliography offers an excellent starting point for further reading and future research.

 

Written for:
Researchers and libraries
Keywords:

    * Data Stream Processing
    * Predictive Learning
    * Sensor Data
    * Sensor Networks
    * Tensor Analysis
    * TinyOS

http://www.mediafire.com/?4meme1vtxjc

Hello jtwitter!

A easy to use Java interace to Twitter API. http://thinktankmaths.com/java-twitter/

Very simple:

1. Add this component jar to your project library

2. invoke it by following code:

Twitter t = new Twitter("your_username", "your_password");
t.updateStatus("This message will be submitted to twitter!");


3. Done


I have created a Netbeans Java project to show the demo. Please download it from http://www.mediafire.com/?msh4dotngd9

2008年5月29日星期四

Comparing Mobile Platforms: Java ME and Adobe Flash Lite

http://blogs.sun.com/mobility_techtips/entry/comparing_mobile_platforms_java_me

By Bruce Hopkins

If you’re a mobile developer, you may have noticed that more devices these days are supporting Adobe Flash Lite. According to the latest figures, approximately 300 million devices in the market support some form of the Flash Lite specification. Of course that’s nothing compared to the 1.2 billion (yes, that’s with a “b”) Java ME devices that are currently available, but I thought that it would be worthwhile to see the strengths and weaknesses of each platform side by side. In the tables that follow, I’ll compare the latest and greatest specifications for both platforms in the following categories:

Graphics
Multimedia
Local Device Accessibility
Security
Network Connectivity
Miscellaneous

Our first category for comparison is graphics. As you can see in the table below, the Flash Lite 3 platform supports all the standard rasterized graphic formats and supports FLA (Flash format) and SVG formats for vector graphics. In my opinion, FLA is a superior vector graphics format compared to SVG, and the tools required to create sophisticated applications are easier (and more widely available) to use for FLA compared to SVG. So, the Flash Lite 3 platform is a worthy competitor in the graphics department for mobile applications, and it is easy to see why many Flash Lite applications are games. One downside, however, is that Flash Lite 3 has no support for 3D graphics.

Graphics

When it comes to multimedia (the playback of various formats and codecs of audio and video). The Flash Lite 3 platform is a clear winner. It not only supports the Flash 8 video specification but also Sorensen video, which is an industry standard for compressed video. Both platforms support streaming audio and video, which is crucial when your mobile device needs to communicate with a media server.

Multimedia

How do the two platforms compare when you want to gain access to local resources on the mobile device? As you can see in the table below, the Java ME MSA specification gives the developer an unprecedented amount of access to local resources such as the GPS radio, camera, and microphone.

This may be a little known fact: both platforms support the capability to initiate a request to the handset to dial a phone number. However, since the Java ME MSA platform can also read phonebook entries on the local device, it’s more suited for creating powerful business applications. Note that there are Java ME and Flash Lite implementations that do have access to sensor data from accelerometers, but such functionality is not a part of the Java ME MSA spec or Flash Lite 3.

Accessibility

In the security realm, both platforms support HTTPS, so you can use either platform to securely communicate with a SSL-enabled web server. However, applications that use the Java ME MSA platform can also use digital certificates for secure identification. MSA devices have the added ability to use various encryption algorithms to secure data at rest (that is, on the filesystem).

Security

Which platform provides more options for connectivity when your mobile application needs to communicate with external resources? The following table gives you a good idea of what you can expect when you create a mobile application that needs to communicate to a networked or local device. As you can see, both platforms support the capability for mobile applications to initiate requests using raw TCP sockets or with the HTTP protocol. However, mobile devices that support the Java ME MSA standard have the additional capability to act as servers, and wait for incoming requests on various protocols on both TCP and UDP transports. This allows the mobile device to communicate in a peer-to-peer mode without the necessity of server-to-proxy requests between them. If you’re in server mode, your application doesn’t even need to be running in order to receive its data. The PushRegistry allows Java ME application to “wake up” upon an incoming network request.

Mobile devices that adhere to the Java ME MSA standard also have the ability to use the local serial and infrared ports on the mobile device.

Connectivity

The following capabilities really didn’t fit in any of the categories discussed earlier in this article. For those of you who have never developed Flash Lite applications, you may be surprised to learn that it supports floating point math, XML parsing, and even TCP/IP networking without necessitating the use of a threading framework for its developers.

Miscellany

Conclusion

Each platform has its own strengths and weaknesses when it comes to mobile application development. Flash Lite-enabled devices are really good at displaying graphics and multimedia, which lends itself to several gaming applications. On the other hand, devices that support the Java ME MSA platform are the obvious choice when you need to communicate with Bluetooth devices, use location based services, capture audio/video, render 3D graphics, or perform any form of asynchronous communication.

I’m really glad to see that one of the Java ME licensees, Sony Ericsson, has made significant progress on bridging the gap between both platforms with its Capuchin technology, which was announced in late April: "...a Java ME API that defines a bridge between the Java ME and Adobe Flash Lite programming environments. This API makes it possible to use Flash Lite as the front end and Java ME as the back end of applications, meaning that Flash tools can be used for UI design while still having access to all the phone services available to Java ME." Both platforms have made significant advances from their initial 1.0 versions. I can’t wait to see what’s on the horizon for both platforms as the standards evolve.