Pages

Saturday, October 29, 2011

RESTful Web Services: Jerseylicious... a Jersey based client

I thought that I would provide a simpler example than the RESTful Web Services book. In this example I am using Jersey (JAX-RS Reference Implementation) client to do the same thing as Apache HTTP Client.

You can download the Apache Maven NetBeans project here: jerseylicious.zip

JerseyliciousApp.java


RESTful Web Services: DeliciousHttpClient Example

I have been working on designing a replacement architecture for an enterprise application at work. As a result, I have been doing a lot of work with REST. The seminal work on REST is RESTful Web Services by Leonard Richardson and Sam Ruby from O'Reilly & Associates. The book is a couple of years old, but relevant today. There is only one issue with the book. There are a number of examples that do not work as expected in the current framework editions.
One such example is using Apache Commons HTTP Client. This particular framework is deprecated, and has been replaced by Apache HTTP Components.
The example code below demonstrates how to perform a RESTful call to del.ic.io.us to retrieve saved bookmarks. This is based on the application listed on page 35 of the book.
The Apache Maven based project can be downloaded here: delicious.zip.

 

DeliciousHttpClient.java


Wednesday, October 26, 2011

Creating NetBeans Project with Existing Source Code

This is the second video in the series on how to simplify your coding with NetBeans. In this video I demonstrate how to import code from the Apache Commons CLI project into NetBeans. The source code IS NOT in a native format that NetBeans understands like Apache Maven. The files are imported into a NetBeans project with existing sources.

As with most code that you download, there are some dependencies which are unsatisfied. I demonstrate how to download the dependencies, and put the jar files into the project. Finally, I successfully build it.


Thursday, October 20, 2011

Creating a NetBeans Project from the Web

I created a simple demonstration of how to use NetBeans to open an Apache Commons CLI project directly from the Internet and build it along with the Javadocs.

This is the first of two video examples demonstrating the power of NetBeans to be more productive immediately.


SerialVersionUID Generator for NetBeans 7.0.1

's SerialVersionUID Generator For NetBeans has been updated for use in NetBeans 7.0.1. If you have a need to generate SerialVersionUIDs for your Serializable classes. This is the plugin for you. You can download it from here.

http://kenai.com/projects/nb-svuid-generator/downloads/directory/nbms/nb7.0.1

Thursday, October 13, 2011

JDK7: String in Switch Example

switch in Java was always considered not particularly useful prior to Java 5. In Java 5, enum was added to the language. This made it more useful to use switch statements, but was still incomplete. A feature request that has been long in waiting is the ability to use a String in a switch.

Finally, in Java 7 SE we get the ability to use a String in a switch statement. This feature, I believe, will make the use of switch more prevalent in code which is post JDK 6.

The example below was developed using NetBeans 7.1 Beta on Oracle Solaris Express 11. The NetBeans Java project is located here: StringSwitch.zip.

This code was presented at the Greenville Java Users Group. The Unicode has a hidden message which is displayed when run.

StringSwitch.java


Wednesday, October 12, 2011

Try...Catch...Finally Puzzle Part II

In the first version, I think that the people missed the interesting stuff. So here is a modified version, of the code. Remember, the real question is what to expect. It will compile, and run. The two examples are more interesting.

NOTE: This is not an example of how to do something right. This is absolutely the wrong way to handle exception handling in Java.

Main.java



Main2.java


Here is the NetBeans project for the code: FinallyReturn2.zip

Tuesday, October 11, 2011

Try...Catch...Finally Puzzle

I showed a similar example at my last GreenJUG meeting. In the example code below, I have a try{...}catch(Exception e) {...}finally{...} puzzle.

Before running the code ask yourself three questions: does it compile, does it run, and what is the result?

Tell me what the expected result is supposed to be and why?

Main.java


The example code is a NetBeans project and can be downloaded here: FinallyReturn.zip

The Java Life

When Oracle contacted me about doing a survey for them to use at JavaOne 2011 I had no idea what they had planned. As a result I sent back my survey with a bunch of fun loving answers. Some of them serious, but most were simply funny answers. I guess a couple of the other JUG Leaders had the same idea.

The result was a video which was a video called "The Java Life" which aired at the opening JavaOne and JavaOne Community keynote addresses. I have attached the video for your enjoyment. The lyrics are below it, and finally you can see my survey responses.

Who said Oracle doesn't listen?



Future Perfect / l.inc design
9.1.11

SPOKEN:
In the cubicles representin’ for my JAVA homies…
In by nine, out when the deadlines are met, check it.

CHORUS:
We code hard in these cubicles
My style’s nerd-chic, I’m a programmin’ freak
We code hard in these cubicles
Only two hours to your deadline? Don’t sweat my technique.

Sippin’ morning coffee with that JAVA swirl.
Born to code; my first words were “Hello World”
Since 95, been JAVA codin’ stayin’ proud
Started on floppy disks, now we take it to the cloud.

On my desktop, JAVA’s what’s bobbin’ and weavin’
We got another winning app before I get to OddEven.
Blazin’ code like a forest fire, climbin’ a tree
Setting standards like I Triple E….

Boot it on up, I use the force like Luke,
Got so much love for my homeboy Duke.
GNU Public Licensed, it’s open source,
Stop by my desk when you need a crash course

Written once and my script runs anywhere,
Straight thuggin’, mean muggin’ in my Aeron chair.
All the best lines of code, you know I wrote ‘em
I’ll run you out of town on your dial-up modem.

CHORUS:
‘Cause…
We code hard in these cubicles
Me and my crew code hyphy hardcore
We code hard in these cubicles
It’s been more than 10 years since I’ve seen the 404.

Inheriting a project can make me go beeee-serk
Ain’t got four hours to transfer their Framework.
The cleaners killed the lights, Man, that ain’t nice,
Gonna knock this program out, just like Kimbo Slice

I program all night, just like a champ,
Look alive under this IKEA lamp.
I code HARDER in the midnight hour,
E7 on the vending machine fuels my power.

Ps3 to Smartphones, our code use never ends,
JAVA’s there when I beat you in “Words with Friends”.
My developing skills are so fresh please discuss,
You better step your game up on that C++.   
 

We know better than to use Dot N-E-T,
Even Dan Brown can’t code as hard as me.
You know JAVA’s gettin’ bigger, that’s a promise not a threat,
Let me code it on your brain

WHISPERED:
so you’ll never forget.

CHORUS:
We code hard in these cubicles,
it’s the core component…of what we implement.
We code hard in these cubicles,
Straight to your JAVA Runtime Environment.

We code hard in these cubicles,
Keep the syntax light and the algorithm tight.
We code hard in these cubicles,
Gotta use JAVA if it’s gonna run right.

We code hard in these cubicles
JAVA keeps adapting, you know it’s built to last.
We code hard in these cubicles,
Robust and secure, so our swag’s on blast

CODE HARD


Here is my original survey...

Here are some answers for you to your questions. It was fun. I hope you enjoy the answers.

What is your favorite Java enabled device?
A: SunSpot

Have you ever used Java in an unconventional way?
A: Named my cat 'Java', tried to teach my 5 year old to program with it, and poured it in a beer to make sure I did not waste it.

Have you ever heard of Java being used in an unconventional way?
A: Yes, ask Adam Bien about his thermostat.

What would you say is the best use for Java?
A: Besides drinking it, it is also really good for removing rust, and creating great MVC Model 2 design n-tier enterprise applications.

What project that you've worked on are you most proud of?
A: A good question. I think that the Java boot camp project on Java.net is a great project. I like to teach others to program. Oh, and my boss says everything that I am currently working on!

Is there something universally frustrating about being a programmer?
A: Yes, computers won't bend to my mind control. Most programmers know what they want their applications to do. The implementation is the difficult part. I am only partly kidding about the mind control!

If Java had an enemy, what/whom do you think it would be?
A: Actually my cat Java has a nemesis called 'chipper' the chipmunk who taunts him from outside the bay windows. Duke the champion of all that is good fears only TEN. TEN. TEN. (.NET backwards).

What is the worst thing to hear about a project as a Java programmer?
A:  ... and can you have that done by 5:00 PM?

Describe your Ideal Day
A: I wake up and go sailing. The wind is perfect and I beat Larry in a race with a Sunfish. He is so impressed, he donates his BMW-Oracle race boat to my Alma Mater Maine Maritime Academy, and asks for remedial sailing lessons. Oh, and I get all of my coding projects done... before 5 PM. ;-)

What is your favorite snack?
A: Beer

What is your favorite beverage?
A: Guinness... or as noted above with Java.

Do you have any hobbies?
A: Dreaming! Java programming, Sailing, Hiking, Kayaking, Rafting, Canoeing, Camping, Biking, Yoga, Paper Airplanes, Model Airplanes, Linux, Shooting, Fire Fighting, and just about anything that could get you killed in a horrific fantastic epic manner.

What are your favorite video games?
A: Fallout 3, and Fallout New Vegas.

What/Which gaming system(s) do you use?
A: PS3 and Nintendo Wii

Do you hang out with other Java programmers?
A: Yes, they are great people. Common interests, and common bonds make great friends.

What do you do together when you hang out?
A: DRINK BEER! We have intellectually stimulating conversations about which algorithms are best suited to solve complex coding challenges. Who am I kidding, WE DRINK BEER and discuss everything from the cute waitress to particle physics (yes very geeky).

Tell me a funny story that happened while on the job?
A: Don't drink and team code. Let's just say it can be...interesting. We were working over a weekend on a project and came across a corner case on the project. The software was for use by field service engineers working remotely. The case was to submit a service ticket it had to have a) time, b)parts, c) both, and d) (CORNER CASE) an attempt to submit a ticket with nothing. I commented that only a "moron" would do that. My partner agreed, and I thought it would be funny to place a pop-up in the code called a "Moron Alert". We ran it, drank more, ran it some more, and laughed at my cleverness... one problem. Yup, you guessed it. Anyway, the application gets deployed and has been running for 3 years until someone (a moron) gets the alert. His manager calls me crying from laughing so hard. He had asked the engineer what he did to get "MORON ALERT...MORON ALERT...MORON ALERT. What are you a moron for trying to submit a ticket without parts, or time. Are you a moron (Yes/No). Only the yes button works. Funny!

What websites or blogs do you visit most often?
A: My own (http://javaevangelist.blogspot.com). I can't seem to remember my own solutions to problems until I Google it, and discover I covered it in my own blog. Arun Gupta (http://blogs.oracle.com/arungupta/), and Java.net.

What are your favorite TV shows?
A: All things sports especially baseball, and college football.

What are your favorite movies?
A: Metropolis, Blade Runner, and Apocalypse Now.

Who is your favorite band, or recording artist?
A: Front Line Assembly.

Who are your favorite comedians?
A: Sarah Palin, Nancy Bachman, and the crew of Saturday Night Live.

What are your favorite viral videos?
Flu Attack! How A Virus Invades Your Body

Outside of work, how much time do you spend on a computer?
A: According to my wife, far too much time. I have a computer on my nightstand, and I have fallen asleep with my hands on the keyboard. Thankfully I don't drool.

What are some stereotypes of Java programmers? How accurate are they?
A: What someone is stereotyping us! I want to be monotyped! People should hear a single voice. Java programmers are supposedly introverted, and lack social skills. They are not accurate... I am an extrovert.

Are there common characteristics of Java programmers who do not fit the stereotype(s)?
A: Bruno Souza, Martijn Verburg, Stephan Janssen, and of course me. All of them are friendly, honest, approachable, and kind. They are willing to help others if you simply ask, and love to code.

Are there any inside/industry jokes in the Java world?
A: Have you seen the videos that JavaZone puts out. http://jz11.java.no/trailer_video.html

What do you love about Java itself, or love about being a Java programmer?
A: Java has a promise to "write once...run anywhere." This is a powerful tenet of the language. This power allows you to be creative in ways that only are limited by your imagination. In 1995, people had a vision about what could be possible, but if you asked them today whether it would power Predator Drones, or control the Large Hadron Collider (LHC); the answer would have been no. If you asked them today if they are surprised; the answer would be no. I like being able to dream, and to teach my kids to dream. There fantasies are our future, one hopefully powered by Java.

If you weren't a Java Programmer, what might be your focus/passion?
A: I love the ocean, and I would likely go back to being a Merchant Mariner. I love to sail, and I am passionate about preserving the oceans. Perhaps I would work on engineering more efficient sailing methods for merchant vessels to reduce the reliance on fossil fuels.