Over a million developers have joined DZone.

Internetmusic With Java

DZone's Guide to

Internetmusic With Java

· Java Zone ·
Free Resource

Bring content to any platform with the open-source BloomReach CMS. Try for free.

A small group on twitter started a funny (or stupid?) mem #internetmusiker (which is internet-musician in English). The initial idea came from FR31H31T. The task was to slightly change a name of a musician, band or song and get a phrase which sounds like an internet- or computer-technical phrase. The results were sometimes very funny and my favourite examples are:

Nine inch Mails, Modem Talking, Deftunes, Wii valdi oder iValdi and Sudo Lindenberg (look here for the full list)

Now I wanted to know which phrases were the most retweeted once and I wrote a small Java application which uses the twitter4j API to do this task.

Twitter twitter = new Twitter(login, pw);
for (int page = 1; page < 1500; page++) {
Query query = new Query("internetmusiker");

try {
QueryResult res = twitter.search(query);
if (res.getTweets().size() == 0) {
log("No more tweets found");
log("page:" + page + " found " + res.getTweets().size() + " tweets");
for (Tweet twe : res.getTweets()) {
} catch (TwitterException ex) {
log("End of search reached", ex);
To avoid a full search for the next time I saved the results via my small helper object StoreableTweet to a text file and used ‘query.setSinceId(maxId);’ while querying.

To calculate the retweets there is no API provided (or am I wrong?) so I needed to parse for a ‘RT @name text’ and look up the text within all the tweets. For that I created a hash map with the text content as keys.

Map<String, StorableTweet> mappedTweets = new HashMap();

for (StorableTweet stw : allTweets) {
String key = stw.getTextToRetweet();
if (mappedTweets.containsKey(key))
log("Mapped tweets collection already contains tweet:"
+ stw.toPersistentString());

mappedTweets.put(key, stw);

for (StorableTweet stw : allTweets) {
if (stw.getOrigRetweetedText().length() > 0) {
StorableTweet retweet = mappedTweets.get(
if (retweet == null)
log("Skip retweet: cannot find retweet "
+ stw.toPersistentString());


Again you can look here for the resulting html file. So start your own with #internetmusiker oder even #internetmusician?

From http://karussell.wordpress.com

BloomReach CMS: the API-first CMS of the future. Open-source & enterprise-grade. - As a Java developer, you will feel at home using Maven builds and your favorite IDE (e.g. Eclipse or IntelliJ) and continuous integration server (e.g. Jenkins). Manage your Java objects using Spring Framework, write your templates in JSP or Freemarker. Try for free.


Opinions expressed by DZone contributors are their own.

{{ parent.title || parent.header.title}}

{{ parent.tldr }}

{{ parent.urlSource.name }}