Flex 2: Development on a budget

My primary clients are Java shops. When I suggest using Adobe Flex 2 as a rich client tool for their Web applications, they typically ask about the cost on the server side. Expected answer: free. When I start telling them about really powerful features of Flex Data Services, they like it. They just do not like the licensing cost,which is very reasonable. But Flex 2 it’s too young, and some people are still in denial phase. It’ll change soon, but there got to be a free solution. Just to get the foot in the door. And there is one.

I’ll be using a JavaServer page (JSP) here, but you can replace a JSP with any technology you’re comfortable with: servlets, Active Server Pages, Python, PHP et al. Whatever can spit out an XML to a Web browser should work the same way.

I’ll show you a really simple application written in Flex 2 that talks to the XML producing JavaServer page. Just to make it simple, let’s take an XML with the information about employees:

lt;people gt;

lt;person gt;

lt;name gt;Alex Olson lt;/name gt;

lt;age gt;22 lt;/age gt; lt;skills gt;java, HTML, SQL lt;/skills gt;

lt;/person gt;

lt;/people gt;

Now, let’s hardcode this (I’ve got three persons) into a super simple JSP that consists of one out.println() call, where the xml should go between the double quotes:

lt;%out.println( “… “); % gt;

The complete JSP looks like this (just put your XML in one line so you won’t bother with string concatenations):

lt;%

out.println( ” lt;?xml version=\ “1.0\ ” encoding=\ “UTF-8\ “? gt; lt;people gt; lt;person gt; lt;name gt;Alex Olson lt;/name gt; lt;age gt;22 lt;/age gt; lt;skills gt;java, HTML, SQL lt;/skills gt; lt;/person gt; lt;person gt; lt;name gt;Brandon Smith lt;/name gt; lt;age gt;21 lt;/age gt; lt;skills gt;PowerScript, JavaScript, ActionScript lt;/skills gt; lt;/person gt; lt;person gt; lt;name gt;Jeremy Plant lt;/name gt; lt;age gt;20 lt;/age gt; lt;skills gt;SQL, C++, Java lt;/skills gt; lt;/person gt; lt;/people gt; “);

% gt;

Deploy this JSP under some servlet container. I have Tomcat, so I just saved it as employees.jsp under my webapp\test directory. Do a sanity check to make sure that you’ve deployed this JSP correctly: entering http://localhost:8080/test/employees.jsp in your Web browser has to return the employee data.

Now comes the client part. If you have extra $500 laying around, purchase a license of Flex Builder from Adobe and enter the code below code in its editor. If you do not want to spend any money, just type this code in any text editor and use free command line mxmlc compiler that comes with Flex 2.

lt;?xml version= “1.0 ” encoding= “utf-8 “? gt;

lt;mx:Application xmlns:mx= “http://www.adobe.com/2006/mxml

applicationComplete= “employees.send() ” gt;

lt;mx:HTTPService id= “employees ” useProxy= “false ” method= “POST ”

url= “http://localhost:8080/test/employees.jsp ” / gt;

lt;mx:DataGrid dataProvider= “{employees.lastResult.people.person} ” width= “60% ” gt;

lt;mx:columns gt;

lt;mx:DataGridColumn dataField= “name ” headerText= “Name “/ gt;

lt;mx:DataGridColumn dataField= “age ” headerText= “Age “/ gt;

lt;mx:DataGridColumn dataField= “skills ” headerText= “Skills “/ gt;

lt;/mx:columns gt;

lt;/mx:DataGrid gt;

lt;/mx:Application gt;

Not too much typing, isn’t it?

This code uses the lt;mx:HTTPService gt; component that allows you to connect to a specified URL either directly or through a proxy. In my example I just specify the URL of my JSP. The data provider of my data grid uses binding (see the curly braces) and E4X syntax to parse the XML and populate this table with the elements located under the lt;person gt; XML tag that is coming from our employees.jsp. Next month, I’ll write a piece explaining Flex data binding in more details. On the applicationComplete event, we send a request to the HTTPService object known under id employees, and our JSP readily returns the XML, which is bound to the data grid.

Compile and run this program, and it’ll show you the following:

Not a bad result for a dozen lines of code.

Of course, it’s better to be rich and healthy than poor and ill. But my point is that even poor (or pretending to be poor) people can use Flex 2 with their existing server side Web tools for free.

Who needs protected variables?

For years, object-oriented programmers knew that one of the main OOP features is encapsulation: an ability to hide and protect object internals. Private and protected properties were invented to support this. But who are we hiding from? From stupid developers who will decide to use our smart framework classes.

In some OOP languages only descendent classes can access protected variables from the ancestor. Java relaxed this rule a little bit and allows accessing protected variables from classes located in the same package. Recently, I had to extend a class from a particular third party framework, which had a protected variable defined. My class was not located in the same package as that third party component… Let’s look at this example.

The code below works fine:

public class Father {

   protected int abc = 25;

}

public class Son extends Father{

   public Son (){

   System.out.println( "abc= " + abc);

  }

}

public class MyNewClass {

   public static void main(String[] args) {

     Son son = new Son();

     System.out.println( "Son.abc= "+ son.abc);

   }

}

The class MyNewClasss is happily printing


abc=25
Son.abc=25

Now move the Father and Son to the package com.thirdparty.framework.

After adding the import com.thirdparty.framework.*; to MyNewClass, the code still does not compile complaining that son.abc is not visible. Of course, because designers of the third party framework wanted to protect their precious abc variable, and they wanted to force me to inherit MyNewClass from their Father or Son.. Did they achieve their goal? Not at all. They just forced me to create a Grandson in my default package with a public getter to the abc property.




import com.thirdparty.framework.Son;
public class Grandson extends Son {

   public int getAbc(){
  
     return abc;

   }
}

And MyNewClass now looks as follows:




public class MyNewClass {

   public static void main(String[] args) {

     Grandson grandson = new Grandson();

     System.out.println( "Grandson.abc= "+ grandson.getAbc());
   }
}

It’s just annoying that I need to add the GrandSon because designers of the third party framework decided to make the abc protected.

If you want to restrict the access to a property, make it private and give me a public getter, if needed. If you want to let everyone work with a property, make it public.

But who needs this protected access level?

Top ten ways to screw up an enterprise Java application

Tonight, I “ve attended Java SIG meeting in New York. CameronPurdy of Tangosol was presenting on ten thing that will help you to screw your enterprise Java application. This was a re-run of his JavaOne talk.

#10 To specify your data access model before you understand the granularity

#9 Assuming that container will take care of transactions

#8 Using a stateless architecture

#7 Design the application for deployment on a single server and assume that that server will handle reliability and scalability for you

#6 Using popular technologies such as WebServices for component integration and remoting

#5 Rolling your own frameworks

#4 Distributing of synchronous objects across the network

#3 Design logic and data flow assuming that this is a single user system

#2 Compensate for lack of knowledge of the application domain by maintaining flexibility

#1 Put off the system testing until the application is ready to deploy

It “s always fun to listen to Cameron.

How I improved my Java skills over the weekend

I spent last weekend in the classroom studying Java and popular frameworks. Actually, I was moving from one classroom to another trying to absorb as much information as possible while attending a traveling Java symposium called Non Fluff Just Stuff. For busy Java professionals who can not attend training during business hours this seminar is a steal. Even though all speakers are published authors and well known in the industry Java experts, the tuition is very modest. This seminar does not include any sales pitches: there is no vendors there. Just the training.

I started with the session on Spring Framework delivered by Stuart Halloway. His message was clear: programming has to be simple. Spring is a well crafted framework, that can be used in a variety of ways: entire Spring framework, some of its components, with or instead of Java EE.

Since the sessions run in four parallel tracks, you often have to make a tough decision: which one to attend. What really helps is that the CD will all presentations is given to attendees as soon as they are registered. Let me repeat, not soon after the seminar, not we “ll let you know when the slides are published, but b-e-f-o-r-e. I was browsing the slides to pick up the next session .

This is very informal gathering. Attendees casually talk with each presenter in the classrooms, during the breaks, and they eat together. For example, over the breakfast after my prediction that AJAX will be gone from the business applications landscape in three years, Stuart Halloway has immediately bet a beer that this was wrong and AJAX will become even stronger. What “s your take, who “s gonna pay for the beer? By the way, Stuart, I drink Leffe beer.

Here “s another important observation: to be a cool presenter at Java conferences, you need to purchase an Apple notebook and use IntelliJIDEA IDE for the live demos. Most of the presenters used this combo. I am using IntelliJ already, but I “m still working on the slide show for my wife that would give her a reason to let me spend another $2K for an Apple notebook (we already have three iPods in the house to support Steve Jobs lifestyle ).

Neal Ford delivered an interesting talk on how to become more productive at work. This talk is about making a comfy environment for a programmer. Programmers are weird creatures, and for them a comfy environment means to have proper code editors, the version control system and the like. Neal is the guy who actually spent time studying all these little shortcuts, utilities and tricks that various OS “s have but we do not know about. Knowing these things can substantially improve your productivity.

I “m not going to list all the sessions here: all presenters were top notch! OK, just one more: Brian Goetz. Yes, the author of the excellent book on threads. We “ve discussed several subjects with Brian, but let me just give you a couple of Q and A “s.

At some point, there was a discussion about Hibernate, and I “ve asked him, “What is your personal preference, using Hibernate or SQL for data persistence? rdquo;. Brian said, that every time he uses on of these, he thinks that he should have been using the other one.

Here “s my next question, rdquo;A requirement to write the GUI-related operations in the event-dispatching thread complicates Swing programming a lot. If you had a chance to redesign Swing, would you implement it differently so the life of the Java programmers would have been easier? rdquo;.

Brian said, “No. So far any GUI toolkit that tried to support multithreaded GUI failed. There are two reason that can lead to the GUI update: the user interaction and the application itself, and unless you have a single dedicated thread that updates the GUI, it “s very difficult to avoid lock-ordering inconsistencies, which leads to deadlock “.

Brian “s presentation about Java memory model was a heavy duty stuff. I felt as if a Thai-style massage was being applied to my brain. Luckily, there was a lunch break after this talk where Jay Zimmerman, the man behind this event raffled off several books and iPods. Jay has managed to build an all-stars team that travels around the country for years. Think of it this way: JavaOne speakers are coming to your town, to share with you the latest trends, tricks and techniques that are important for any professional Java programmer (the emphasis is on the word professional). To put it simple, you can “t go wrong with NFJS.

Java does not need Botox

During my 25 years in software development, I lived through different trends in programming and usually changed my primary programming language every five years or so. While teaching students to program in whatever language was hot at the time, I kept warning them, “Do not fall in love with any programming language as it “s just a tool rdquo;. But here I am, living with Java for eight years. Isn “t it time for a divorce? The short answer is no. As of today, there is nowhere to go. Java was a really well crafted and MARKETED language. I do not know how Sun Microsystems was able to pull it off, but it just happened.

Most importantly, Java puts bread on my table. I am a professional programmer, and can not just jump up when I see a group of kids praising a new programming language. This might sound rude, but show me the money. If the language XYZ is the best thing that happened to the world, why dice.com does not list jobs asking for the XYZ skills?

The market is not there yet? See you in a year or two.

When people discuss programming languages, they often fight over specific features that this particular language has while Java does not . So? Java does not allow for dynamic objects, closures and continuations. So? Who cares? Just go to dice.com and type the word Java. You “ll get 15 thousand jobs.

Is Java the primary language that pays my bills today? Hell, yes. Are there other languages/technologies I work with? Hell, yes. Am I happy that Java is trying to add new features to the language? Hell, no. Someone proposes adding closures to the language. There are some attempts to introduce data binding to Java Beans. Get real guys, you can “t teach an old dog new tricks. When I hear about all these additions to Java, I see an aging woman that keep coming to her doctor for another Botox injection. These doll-looking faces do not trick men anymore. The same applies to Silicon (not as in Silicon Valley). Are these boobs real? Keep Java simple, let it age gracefully! It “s a very robust platform for enterprise and mobile applications and let “s leave it right there. Fine-tuning of the JVM is fine, but I do not need new language features. Id ” rather use some other modern language that can be easily integrated with Java EE.

Sun Microsystems has excellent engineers who can craft a brand new language in a year or so. May be creating a new language is better than trying to add patches to Java here, there and everywhere? Just come up with some cool language, while Java is still strong.

If James Gosling will get together with Guy Steele, they can come up with a new practical language for enterprise software developers, and I “m sure that this new language will beat crap out of other languages/tools/technologies that became popular by coining a catchy acronym or were born on the railroad.

Java is here to stay for another ten years, at least on the server side. But I do not wish Java to be around for the same reason as Cobol, which is still with us because there is no money for the funeral: too many Cobol applications were written and deployed in production.

I’ll keep looking around and use other languages or technologies that can compliment Java EE applications, but I “ll remain loyal to Java for another three years or so with a hope that something “s gotta give.

A quote of the day

I’ve got an email that contained a quote describing the way we live:

“Normal Life is getting dressed in clothes that you buy on credit for work, driving through traffic in a car that you are still paying for, in order to get to a job that you need so badly so you can pay for the clothes, car and the house that you leave empty all day in order to afford to live in it. ”

I do not know who’s the author of this quote, but it’s well said.

The person who sent me the quote added a short comment: “Each working day shortens your life by 8 hours “. This is yet another correct assessment of the lifestyle that many of us have in the USA. I’d change 8 to 12 though since many of us leave for work at 7AM and come back home at 7PM or later.

During the last couple of months I’ve heard from more that one programmer a statement like this, “I’d like to relocate to another country…let it pays less, but I’m tired here…I can sell my house here and it’ll get me going for a while… “. I guess, they started to fell like the burning candles that will be replaced by fresh ones soon.

Pretty sad posting for Saturday… Let’s add some postive and happy ending. How about this one:

The life is not easy in the USA, but I’ll stick around…because it’s even more difficult anywhere else.

How to write an RSS reader in AJAX

IBM Developers work has a tutorial on how to build an RSS reader using AJAX. The amount of code you need to write is scary (and this is not the complete code). Adobe Flex 2 plus a simple Java programming to support DB interaction allows you to achive the same functionality using A LOT LESS coding.Just take a look at this screen:

The Flex 2 code below populates the bottom portion of the screen with financial news based on the selected stock on top ( (it does not work with a DB to store the RSS source so it’d add some 50 lines of Java code ). The data come from the Yahoo! Finance RSS feed. The URL looks as follows: http://finance.yahoo.com/rss/headline?s=MSFT

The suffix can be MSFT or whatever is selected on top is being passed to the code below.

Flex lt;mx:HTTPService gt; object is used through a proxy deployed under Tomcat or any other servlet container.

The entire application code and its description can be found in this article.

lt;?xml version= “1.0 ” encoding= “utf-8 “? gt;

lt;mx:Panel xmlns:mx= “http://www.adobe.com/2006/mxml

title= “News ” width= “100% ” height= “100% ” gt;

lt;mx:DataGrid id= “newsGrid ” width= “100% ” height= “100% ”

dataProvider= “{newsFeed.lastResult.channel.item} ” variableRowHeight= “true ” gt;

lt;mx:columns gt;

lt;mx:DataGridColumn headerText= “Date ” dataField= “pubDate ” width= “200 “/ gt;

lt;mx:DataGridColumn headerText= “Title ” dataField= “title ” wordWrap= “true ” / gt;

lt;mx:DataGridColumn headerText= “Description ” dataField= “description ” wordWrap= “true ” / gt;

lt;mx:DataGridColumn headerText= “Link ” width= “130 ” gt;

lt;mx:itemRenderer gt;

lt;mx:Component gt;

lt;mx:LinkButton label= “{data.link} ” click= “navigateToURL(new URLRequest(data.link), ‘_blank’) “/ gt;

lt;/mx:Component gt;

lt;/mx:itemRenderer gt;

lt;/mx:DataGridColumn gt;

lt;/mx:columns gt;

lt;/mx:DataGrid gt;

lt;mx:HTTPService id= “newsFeed ” useProxy= “true ”

destination= “YahooFinancialNews ” concurrency= “last ”

resultFormat= “e4x ” fault= “onFault(event) ” gt;

lt;/mx:HTTPService gt;

lt;mx:Script gt;

lt;![CDATA[

import mx.utils.ObjectProxy;

import mx.rpc.events.*;

public function set security(value:String):void {

this.title = “News: ” + value;

newsFeed.send({s:value});

}

private function onFault(event:FaultEvent):void {

mx.controls.Alert.show

(

“Destination: ” + event.currentTarget.destination + “\n ” +

“Fault code: ” + event.fault.faultCode + “\n ” +

“Detail: ” + event.fault.faultDetail, “News feed failure ”

);

}

]] gt;

lt;/mx:Script gt;

lt;/mx:Panel gt;

Would you hire me?

Recently, I was talking to a couple of Java guys about what to put and what not in the resume (CV). One of them said: “I do not know, because I do not have a resume. I have more work than I can handle, and if I need cash, I just announce that I’m available “.

I was really impressed! Of course, he is not an average Java developer, but a well known person in the industry. But still…

During the last year or so, if I need to interview a job applicant for a senior position, I spend about 30 seconds skimming through his/her resume. Yeah, yeah, yeah…same old, same old: J2EE, Struts, EJB, design patterns… developed, lead, participated. I am not sure though, if knowledge of Struts and design patterns is a plus or a minus, but it’s irrelevant for this discussion. Then, I go to Google and key in the name of the job applicant. If I see some activity there, I consider it a huge plus. If the person blogs, you can get a feeling of the temper and attitude of this person. Knowing Java is good, but if this is a nasty person, would you want to spend eight hours a day with this guy/gal? If s/he participates in the technical forums, you can have an idea about the technical abilities and interests of the candidate.

A couple of days ago, James McGovern blogged about how to hire a consultant, and he thinks the same way. Internet can help you in making this kind of a decision. He talks about consultants only, but I do not see why the same approach would not work for employees?

Hiring is about finding capable people with the personality and attitude that fits your organization. It’s not about people who know a particular API or a framework.

Let’s take J2EE APIs. I did not have a chance to work with Java Connectors (JCA). Would this stop you from hiring me for developing an application that heavily relies on JCA? I know Java and the rest of J2EE. Don’t you think that I can pick it up pretty fast, and can contribute to your project in other ways without being the JCA expert?

So let’s get back to my original question, “Would you hire me without seeing my resume? “. Google my name, and it’ll bring you enough technical and non-technical materials that would give you an idea of my personality and abilities. I’m sure that there are people who do not like me, but there are people who do. The fact that there are people who subscribe to my blog tells me that some people want to hear my opinion (I’ve got plenty of those) on a regular basis. This does not mean that they like me, but they are interested in my opinion.

So here I am again: if you want to hire me, please send me the following: the cIty and the country where you want me work, the project and my role’s description, and how much are you willing to pay. I’m not going to show you my resume, and I’m not going to go through technical interviews.

Are you up to the challenge?

WTFM-2

Last week I’ve written the WTFM blog, and then Sys-Con decided to reprint it. Apparently, Active MQ guys got offended and left angry feedbacks there. They did not get my message. I have nothing against their software, but if they do care or do not know how to write documentation ABOUT THEIR PRODUCT, I will write about it publicly. They teach me how to get help from the open source vendors. Thank you very much. I was just asking for a short writeup describing how to configure Apache Active MQ with Apache Tomcat…

Most people do not know how to document their creation. They describe the details of their software, but they do not write the BEST PRACTICES MANUAL on WHY AND HOW we should use their software. If you turn the key, the engine will start. If you press this pedal, the car will move. Why won’t you start with the statement that this car has been produced to get you from the point A to point B and the most effective speed is from 50 to 70mph? Or this may not be the case, and this car has been created just to improve your social importance, which means that the make and model matters more than efficiency?

Kathy Sierra is an excellent writer. I’m sure you know her Head First books. Yesterday she’s bloged about her photography classes, and she ran into the same issue: lack of best practices manual. This is what she writes about the photography class she’s attended:

“For most of us, the problem was NOT that we couldn’t learn how to use anything but automatic “P ” mode. The problem was that we didn’t know why or when to use anything else.
It wasn’t simply a camera problem–it was a photography problem. The camera manuals describe precisely how to turn the dials and push the buttons, but never tell us why we’d want to. They focus on the tool rather than the thing the tool enables (taking pictures). What good does it do to master a tool if we haven’t understood (let alone mastered) the thing we’re using the tool for? ”

That’s the major problem of most of the open source vendors. They do not bother explaining WHY and HOW should I use their software in the real world, where people are already using someone else’s software (surprise, surprise!). Pleeease, if you are about to make the world a better place by offering us your tool, sit down and desrcibe the best practices of using it with what the most popular products that we already have. Not just how to use it, but the proper way of using it. If you can’t describe it BEFORE your software is ready, do not even start working on it. Most likely this project will fail.

Dead souls from overseas

Today “s topic is how to lead offshore programmers. To make this discussion a bit more interesting, let “s go back in time into the first half of the 19th century.

The novel “Dead Souls rdquo; by the Russian writer Nikolai Gogol was published in 1842. At that time, landowners paid taxes based on the number of people registered with their properties. Often, landowners were taxed even for the dead souls after people would pass away. Guess what, one entrepreneur named Chichikov, started visiting landowners offering to purchase dead souls from them, as this would lower their taxes. Why Chichikov would need to have legal rights to these dead souls? C “mon, it “s elementary, Watson! He wanted to inflate his importance in the society by showing the large number of souls he owned, so he could take a large loan against them.

Now, by a magic wand, we are back in the 21st century. You are a team leader (a technical guy) on a project that includes both local programmers and an offshore team of Java developers. The boss said that there is no budget for hiring American programmers, so the management has decided to hire a large and well known offshore corporation called Shmata Consulting. You firm can hire three Shmata “s programmers for the salary of one American with the same skills. I “ve already written that things may not be as rosy as they look on paper, but here “s yet another twist to it. While technical leaders work harder as they need to find a substantial chunk of additional time EACH DAY explaining to the offshore team how to write code and fix errors, the managers of Shmata Consulting send their time shits (did I spell it wrong?) to your manager for approval. By now, you should be able to guess who these dead souls may be. You believe that three programmers from overseas are coding for your project, but the manager might be receiving (and signing) timesheets (yes, this is the correct spelling) of 5 people, and each of these souls was working their dead asses off putting 80 hours a week. Talking about cheap labor. Talking about Chichikov of the 21st Century. Two centuries ago Mr. Chichikov has founded the Dead Souls Movement, without even realizing how to do these things on a large scale. They did not have the Internet in Russia-1842, so his “crimes rdquo; sound like an innocent joke of a kindergarten boy.

Anyway, what “s the bottom line? Is there anything you (the tech lead) can do about it? Yes you can, namely:

1. Interview and hire each offshore developer personally. Phone tech interviews are OK. Do not agree on working with an offshore team that someone else has put together.

2. Ask your manager to show you the timesheets BEFORE signing them

3. Do not leave your work without giving assignments to each of the offshore developers. Remember, if you forget to give work to your local people, this can be fixed an hour later. But if you did not give the assignments to the offshore peers, you lsquo;ve lost a day because of the time difference.

4. Make a habit to have a quick 20-min morning conference call with that remote team of telecommuters (you can just dream of working remotely, aren “t you). Find out what are their issues. Do not postpone these meeting to the end of the week ndash; too much time will be lost.

These simple rules may prevent your project from being yet another failure with “cheaper rdquo; (but still inflated) cost. You may not like this kind of job, but at least you “ll know that you are in better a control of live souls, and if some little dead soul will sneak in, kill it again. You can “t get convicted for a murder of someone who was already dead.