Advertisment

Live CD for Developers

author-image
PCQ Bureau
New Update

What are the IDEs (Integrated Development Environment) available for

application development in the Open Source world? Here Open Source does not mean

PHP only, nor does it mean Ruby or Java. Open Source here means all of them —

Java, Ruby, PHP, C, C++ and what not.

Advertisment

Typically, there is an IDE for each language and/or technology. But IDEs like

Eclipse and NetBeans have changed the game. From within the same IDE, you can

develop, run, debug and deploy applications written in different technologies,

languages or frameworks. PCQLinux live CD for developers bundles the full

featured NetBeans IDE 6.5. You can boot off the live CD, fire the IDE, create a

new project in one of your preferred languages/frameworks and do what you do the

best — write code. The IDE assists you in the rest. Depending on the language

and framework you use, NetBeans may facilitate your development efforts via RAD

(Rapid Application Development) - quick drag-n-drop, build and run.

NetBeans makes it a breeze to write code for the latest in the Web 2.0

technology. To showcase the same, in this article we write a small web client in

Java for Twitter. Twitter (www.twitter.com) is a popular micro blogging and

social networking service. Twitter is used to share short information, in real

time, with people you know or with the world.

The web client will use REST to show the direct messages sent to a (or your)

Twitter account. Rest stands for Representational State Transfer and can be

thought of a simplified form of web services (based on SOAP protocol). An

introduction to REST can be found in the article 'SOAP and the REST' found at

the URL http://pcquest.

Advertisment


Software in the Web 2.0 Distro
All in one

NetBeans IDE, which includes:



Java SE, Java Web and EE (Enterprise Edition)


Java ME, C/C++, Ruby, PHP, SOA framework

Application servers



Glassfish V2, Personal Glassfish V3

ciol.com/content/search/showarticle.asp?arid=42818. Direct messages in

Twitter are messages/ information sent speci fically to you by other Twitter

user(s). Using the REST protocol we will retrieve the direct messages sent to a

Twitter account and display it in a web page. This code can be extended and

used, say, on your website or blog to show Twitter messages, inline with your

site content.

Get, set and go



Boot off the live CD. While booting the live CD will prompt you to accept

the NetBeans license. Press to read through the license. Once read,

press Y and ENTER to accept the license. To login, click on 'pcqlinux' and type

in the password pass@word1. To launch NetBeans, click on Applications>Prog

ramming>NetBeans IDE 6.5. Next, create a new project in Netbeans. Click on

File>New Project. Select 'Java Web' in the Categories pane and then select 'Web

Application' in the Project pane. Click on 'Next'. For the Project Name, type in

TwitterClient. Click on 'Next'. In 'Server and Settings', select 'Personal

GlassFish V3' for Server and click on 'Next'. For the Frameworks, select 'Visual

Web JavaServer Faces' and click on 'Finish'. This will show up a page called

Page1.jsp, in the middle pane, with tabs for design, JSP markup code and Java

code

Advertisment
You can create new

projects in Netbeans and select amongst a list of open source programming

languages and frameworks. Whats more, NetBeans allows you to write desktop,

web and mobile applications making it a one stop IDE and RAD tool.

Add the Twitter service



Click on the Java tab. To the class named Page1, add a new method named

getTweets, as follows:

protected void getTweets()



{


}

Advertisment

You will need to call the above method in the init() method. In this method

add the statement this.getTweets(); below the comment which says:

// TODO - add your own initialization code here

Click on the Services tab (on the left pane). Expand the 'Web Services' node.

Next, expand Twitter>What Are You Doing Service>. Drag

and drop getDirectMessagesToMe to the getTweets method body — i.e. drop it

between the opeing ({) and the closing (}) braces. A window called 'Customize

GET Saas Service' will pop up. Click on 'Ok' on this window. NetBeans will

automatically create all the required code to consume the REST web service. Next

we only require to write a few lines of code to display the direct messages on

the web page.

Advertisment

Display the Tweets



Switch to the design mode by clicking on the Design tab. From the palette,

in the right pane, expand Woodstock Basic. Drag and drop 'Static Text' component

onto the design. Right click on the 'Static Text' component and select 'Add

Binding Attribute'. Next, in the Java code, add the following import statements

at the top:

import java.util.List;

Add the following statement just above the closing braces of the try block of

getTweets( ) method:

Advertisment

this.displayTweets(result);

With this, we will pass the result of the web service call to another method

called displayTweets where we will parse through the result/response of the

service and display it.The code for displayTweets() looks like this:

protected void displayTweets(RestResponse result)

throws JAXBException



{


twitter.whatareyoudoingservice.twitterresponse.DirectMessages
directMessagesObject =

result.getDataAsObject(twitter.whatareyoudoingservice.twitterresponse.DirectMessages.class);



this.staticText1.setText("");


this.staticText1.setEscape(false);


List
directMessages = directMessagesObject.getDirectMessage();



twitter.whatareyoudoingservice.twitterresponse.DirectMessageType directMessage =
null;



for(int i=0;i
{



directMessage = directMessages.get(i);


this.staticText1.setText(this.staticText1.getText()+"
"+directMessage.getSenderScreenName()+":"+directMessage.getText());



}


}









Add the above method to the Page1 class.

Run the application by clicking on Run>Run Main Project. When prompted, enter

a Twitter username and password (using which you login at Twitter.com). The

output will show sender and the direct tweets.

Advertisment