The Proper Workplace of a Software Developer

Yesterday, I was visiting my business partner Anatole. For many years he works from home – he’s not a big fan of a corporate environment. Beside being a top notch software developer, he’s always trying to optimize his workplace. I took a picture of his desk and thought you’d be interested to see it.

The room is well lit. A bunch of high quality monitors go easy on Anatole’s eyes. His main three computers run Mac OS, Windows, and Linux.

Sometime he writes code while sitting, sometimes he’s standing. The monitor and keyboard on the right slide up and down easily. Walking on the treadmill (left) at the speed of one mile per hour while programming practically eliminates bugs. The stepper is the right place to be during the Skype meetings with corporate clients.

So are you ready to hire Anatole for your next project?

mailto: an elegant solution with limitations

On my current project (Flex and Java) the client wants to email certain data to certain recipients. If the mail content and recipients wouldn’t require manual processing, I’d written a Java server side program that would retrieve the data and sent it to a predefined list of recipients. This is not the case though. The client wants to see the data in an email client (MS Outlook) and be able to add some text to the email body, edit the To, CC, and the subject fields.

That’s why I decided to go with a client side solution. There is this handy protocol mailto, and if you’ll prepare the URL that starts like “mailto:…”, contains the To, CC, Subject, and Body – your program will obediently open the mail client with all the field pre-populated. In Flex, you need to use the function navigateToURL(), but this solution works for any programming language or HTML links. So far so good. I’ve easily implemented this elegant solution giving the client the best of both worlds – automatic mail generation with the ability to massage the text.

But my happiness didn’t last long, cause there was yet another innocent requirement – the data should be formatted. Nothing fancy – like columns in the grid. For example, the email body could have contain the following part:

John Smith                5,678
Mary Lou                        12
B Ramalinga Raju          101

Not a rocket science, right? I also though so and quickly wrote two functions to pad a string with spaces from the left and from the right to a certain length. Then I formed each line concatenating the right-padded 20-char long name with the left-padded 10-char long number. Quick test with printing the result in the console of my IDE – it works! What a great programmer I am, aren’t I?

After passing the same data to the mailto, it opened MS Outlook, and the mail body looked similar to this:
John Smith            5,678
Mary Lou                      12
B Ramalinga Raju         101

My perfect alignment went down the drain. And the worst part is that there is no solution to this problem. The mail client was using a font that allocated different width to each characters and my padding was resulting in different width depending on what characters presented in the name of the person. If I could pass HTML to the mailto URL, this would solve my issue. I could have used HTML Table with cell alignment. But mailto allows to pass only simple text (URL encoding didn’t help either).

I hit the wall. What’s next? Will tell the client, “I give you an elegant and flexible solution, but I can’t align the text. Either manually change the font of the data to one of the monospace font, or set Courier to be a default font in MS Outlook “. I’ve implemented lots of non-trivial solutions for this client, but hey, technology has its limits too.

What if the client answers, “No, I need perfectly aligned report and I hate Courier font?” I’ll answer, “No problem, everything can be fixed. I can certainly come up with a custom solution. It’ll take me N days to implement” After multiplying my daily rate by N the client may reconsider and agree to live with my monospace font solution. This is is good example of a situation, when there is a huge price difference between 100% and 99% automated solution.

P.S. If you run into a similar problem in the Flex TextArea component, the solution is the same – set the fontFamily attribute to use one of the monospace solutions, for example:

<s:TextArea fontFamily=”_typewriter”/>

I Hate This Triangle

Microsoft Word 2011 is the program that crashes the most on my Macbook. To be fair to this edition, I need to say that MS Word 2008 was no better in this department. I got used to it and save my documents every minute or so. I understand that it’s not easy to develop application for the OS that’s not yours. Fifteen years ago Microsoft put Word Perfect out of business using the intimate knowledge of their own OS. OK, this was in the past, but I’m wondering what the UI designers of this hugely popular word processor were thinking about when they assigned three different functions to one little triangle on the toolbar?

Currently, I’m working on a 200-page document, and need to change the width of most of the paragraphs to 5.5 inches. To do this, I need to place the cursor in a paragraph (or highlight several of them) and drag this little triangle to the 5.5″ mark on the ruler. The text in the paragraph gets rearranged accordingly. This operation is about changing the right indent. The problem is that when you hover the mouse pointer over this little triangle, it reveals two other functions: Right Margin and Left Tab. So if you’re not lucky, instead of changing the width of the paragraph, the size of the page gets changed or this freaking triangle gives birth to a little bent black arrow (this is Left Tab) which starts moving on its own on the ruler without having any effect on my paragraph. The fact, that I do this editing while commuting to work on the bus complicates aiming on this triangle, which shakes a little making my User Experience even worse.

I wonder if Microsoft designers are preparing Word to be used on Tablets, where people will use fingers or styluses? They should completely change their attitude to the users. The majority of us ain’t no marksmen, you know. Give us some controls we can use.

If you want to update my Reader…

During the last two years, every week or so, a little icon starts jumping up and down on the screen of my MacBook. This is Adobe Acrobat Reader asksing me if I’d like to upgrade it. Since I’m a polite person, during the first six months I was clicking OK. Please do. Sure, upgrade my free Acrobat Reader. During the last 18 months I was simply ignoring this request and was closing this little jumping icon.

Two weeks ago, during Adobe MAX, Rainn Wilson from The Office was hosting a Sneaks event. He started with asking Adobe to do something with this Update the Reader button. I knew exactly what he was talking about. Everyone laughed.

Five minutes ago this little beast started jumping up again. I clicked on it hoping that after Mr. Wilson mentioned it in front of the five thousand people in the Nokia Theater things changed. So I clicked on this mofo again. It showed me the usual popup:

I pressed OK. Guess what? Nothing changed. The usual response came up once again:

Dear Adobe, can you please find some cash and hire a good programmer who can fix this issue once and forever? If you think that I’m asking for too much, please turn this freaking update offer off, will you?

During the recent Adobe conference the bank Weezer performed their smash hit – the Sweater Song, which includes the following words:

If you want to destroy my sweater
Pull this thread as I walk away

I have my version:
If you want to upgrade my Reader
Do it quick and, please, walk away!

Update. A reader A.T. has hinted that there’s a configurable item Updater in the in the Reader’s Preferences, which allows to turn the automatic updates off. Thank A.T!

Adobe MAX 2011 Was Good Despite The Keynotes

Just came back from LA, where I spent three days at MAX – the main Adobe conference. Four people from our company were there and all liked it. I went there to see if the company is still strong,  has a clear road map that, hopefully, matches  my understanding of where IT population is moving. Adobe does seem strong despise the bleak keynotes. I mean, the special effects were fine, the screen was huge, the projection software was pushing three million pixels a second to the monitors with showing ballet dancer and iPads running Adobe’s software.

Our seats were shaken from the bass as hard as if we were in IMAX during the Inception movie. But almost six thousand people have gathered in the Nokia not just to see a nice stage backdrop. The Adobe actors didn’t deliver good performance – the keynotes were not well prepared. Traditionally, Kevin Lynch runs the day one (the CEO prefers hiding away during MAX) and Ben Forta was the day two host.  As opposed to last year, I had a feeling that both of them were asked to host the keynotes just a couple of days before the conference, and didn’t have time to prepare.

In the past, the first day’s keynote was for both designers and developers and the second was more of a community show. It seems that Adobe quietly realized that bringing desinopers and devigners in the same boat is utopia even with Flash Catalyst. Below is a photo of the devigner’s leg with Adobe’s goody bag.

The first day was for designers and the consumers. Adobe joins the rest of IT world that hangs out in the cloud these days. Now you can subscribe to the Creative Cloud Platform and publish your own magazines (MAX attendees were promised a free year subscribtion). Adobe’s cloud is targeted not only for developers, but for consumers as well. Create photo albums like with Google’s Picasa. The difference is that there is no need to manually synchronize the photos between multiple devices. If you managed to put the photos on your notebook, they are automatically shown on your iPad. This app is called Carousel.  Work with Photoshop right on your tablet (carrying stylus is back in style). Create custom themes with Kuler or collages with Collage. Proto is for creating the prototypes of Web pages on tablets. Debut allows to access your Photoshop and Illustrator’s design from anywhere using tablets…

During the first day keynote, I had a feeling that Adobe spent this year creating applications primarily for iPad. Kevyn Lynch kept repeating the word iPad dozens of times. But after attending the demos of all these consumer-oriented applications, I realized that most of them will be released on Android first and only after on iOS. Most of them (except the Carousel) were developed in Adobe AIR. In other words, Adobe eats their own dog food.

I’d like to see more technical evangelists on the main stage during the keynotes.  They are developers’ rock stars. They’ve traveled day in and day out around the world spreading the word about the latest and greatest Adobe’s products.  They deserve to be treated as the first class citizens. This was happening in the past, but not any longer. Director of Evangelism Ben Forta was the only evangelist on stage (Ben used to evangelize ColdFusion, which wasn’t even mentioned once during the keynotes). Unfortunately, during the last year Adobe lost a number of really good technical evangelists to other employers.

After the keynotes, I’ve attended a number of technical sessions, which somewhat corrected the situation. Most of the sessions were of good technical level.

These are some important news for Flex/AIR developers:

  1. AIR Captive Runtime means that your application will not depend any longer on the availability of the AIR runtime on the platform you’re deploying to. The runtime becomes a part of your application. This started as a workaround to the strict policies for the deployment on iOS devices, but now it works the same on other platforms too. This will increase the size of your application by 6-8MB, which is not bad. For Java developers I can add that Oracle plans to do the same thing (in 2013) with the future versions of JavaFX applications – a small JVM inside the application.
  2. The next major release of Flash Player will support multi-threading. Developers will be able to start their ActionScript in a  background thread that will have access to the display object. Threads won’t share any resources hence developers don’t need to worry about race conditions. The new class Promise will allow to start a thread asynchronously and receive a result of its execution some time later. It seems to be the similar to Java’s Future class.
  3. Enroll in this pre-release program to know more.

  4. Flex Builder 4.6 should have serious improvements in the compilation speed.  Get on the pre-release program to get it now.
  5. AIR native extensions become handy to all mobile developers who want to use the mobile underlying OS sooner than AIR will come up with the wrapper classes encapsulating the same functionality. Our company has released beta of ClearDS that will compliment native extensions in Android.

 

The highlights of the conference were  traditional Sneaks, where Adobe showed exciting experiments that may make it into the future products. Let me tell you, they have some bad ass engineers and mad scientists! Adobe has posted all videos from Sneaks. Rainn Wilson from The Office hosted the Sneaks, and let me tell you – he did a great job!

The second evening ended with an excellent party called MAX Bash. The organization of this event was perfect. Ravioli with wild mushrooms were yummy. And then, Weezer came on stage. They kicked some asses big time!   It’s the rock band of the top tier, and it shows! “If you want to destroy my sweater…” –  you know who they are. My older son went to eleven of their shows already.  Even if Adobe wouldn’t have introduced multiple thread in Flash Player, I’d forgive them just for bringing Weezer to the conference. Jeff Houser was standing in the crowd, recorded the music and published it here. Love his tweet: “Whoever that screaming girl was on stage left at Weezer Max Bash; you screech and sing all over my recording.” That girl had a great time, really.

One more credit to Adobe – they start publishing Max technical session right after the event ended. The developer track’s sessions are here. Enjoy! This year Adobe MAX and JavaOne conferences where hosted at the same time, and I couldn’t be at two places at the same time, but some of the JavaOne presentations are posted at Parleys.com – look for the JavaOne 2011 channel there.

Overall, it was informative and fun event. The future of Flex is solid. We can stay where we are.

Pandora Radio, Blacks, and Whites

Presently I work for a client that has an open floor setup, which means that lots of noises and conversations are happening at any given moment. But I prefer listening to the music while developing software, and  the Internet radio Pandora really helps. I’ve created several radio stations, and based on my mood, I listen to a hard rock, jazz, blues or other genre.

Since there is no free lunch, Pandora used to insert audio commercials between the songs. No problems here. I understand. This morning, I noticed that Pandora got a facelift, and it seems that the main reason was to free some screen real estate for visual advertisement. Now it’s getting annoying.

All of a sudden, my browser’s window became fool  of women. This is no good. I’m working here, guys.There are people around me. They pay me well for developing software. And what do they see? Are we paying Yakov for having fun staring at all these women?

But things got even more interesting.  I noticed that all these beautiful ladies were black. This got me thinking why would Pandora assume that I’m specifically interesting in black women? The title on the top of the screen read something like “Find local black women in your area.” This is when having analytical thinking helps. At the time, I was listening to the radio station that  was playing reggae music. Got it?

After a while, I switched to another radio station that was playing Joane Osborne and the likes. Guess what? The browser’s window got filled with the faces of white women.

I suspect that Pandora is trying to be smart in showing context-sensitive ads targeting the proper audience.Do they assume that people listening to reggae are most likely into black women and fans of Joanne Osborne are whites?

So far it’s just my assumption, and would require a lot more hours spent listening to various types of music. I like women. I really do. There are gorgeous white, black and latino women (the rumor has it that J. Lo is available again). My question is, what kind of radio station should I create to see all of them at once and not in a into-your-face manner? If I won’t find the answer, I’m going to have to shell out 36 bucks for a year of ad-free Pandora.

Oops…It’s getting even more interesting…Here comes a large banner offering me “High Quality Generic Viagra”. Guys, I may lose this contract with my client, and won’t have money to buy high quality blue pills from your sponsors.

 

The Axe Soup, Cake Mixes, and Frameworks

I always get excited when I see another person questioning the use of frameworks that ask you to either replace one language with another or write additional code as a life support to sustain the framework’s functioning. This time my kudos to Christin Gorman, who did a great job explaining why using the Hibernate framework over SQL is a bad choice.  Watch this video , where Christin uses the Cake Mix metaphor to deliver her message loud and clear.

In the past I was using a different metaphors. One was about the goat and rabbi. The other one is about the Axe Soup a.k.a. Stone Soup.  I remember this story about a soldier returning back from war. He was very hungry, and, when reached some village, he asked a women living there to give him some food. She rejected. Then he asked for a pot of water so he could cook a soup form his axe. She became curious and agreed. After placing the axe in a boiling water he asked if she had just one small potato to add some flavor to the Axe Soup. She gave the potato. Than he asked the woman about a small onion, and on and on and on.  When the soup was ready, he removed the axe from the pot and fed himself with a tasteful soup.

This is pretty much the situation in many enterprise IT shops that blindly prefer using frameworks to the programming language itself.  If you didn’t get the analogy, Hibernate ORM framework is an axe. Add it to the project (the pot), then write some HQL queries, which is a replacement of SQL, learn and use a couple of dozen annotations, and after all this is done you won’t need to worry about JDBC.

Well, you may need to fine tune the HQL,  but it’s later…But now we are covered. We are hibernating as everyone else, yay!  If something will ever go wrong, we can always remove Hibernate from our code, right? Sure, the same way as the soldier pooled out the axe from the soup, when his project was complete.

I really like many improvements that made Java EE 6 light , easy, and really helpful. I like the concept of pruning, which means gradually getting rid of the useless JSRs. But if you ask me, I’d pruned JPA 2.0 without thinking twice. The goal of this 500-page spec is to replace SQL with another language. Why? I don’t know.

Cristin is right, professional chefs never use cake mixes. But, unfortunately, the modern IT shops are more like the fast food chains than Michelin restaurants.

A Good Reason to Fire a Programmer

During the last 12 hours I had to fill out a registration form on one Web site and purchase a bus ticket one another. Both user experiences (UX) made me really sad. The reason “s the same: software developers don “t give a shit about their profession. They simply don “t care.

UX #1.

The site registration form had a half dozen fields to fill out, which I did. After pressing the Submit button, just one thing has happened: the border in the box where I entered the user ID became red. That “s it. No error messages. I had a feeling that, for some reason, they didn “t like the value I “ve selected for my user id. Was it too difficult to show a short message explaining what did I do wrong? Maybe their software developers don “t know how to display the validation error text? Not the case.

After changing the id and pressing the button Submit again, the following text was displayed on top of the window: rdquo;One or more entered values are wrong. rdquo; This time the red border was surrounding the box where I entered the phone number. Is it hard to show the format you expect? I “m not even asking you to use a pre-formatted field hellip; OK, I guessed the required format. But I had a feeling that this unknown software developer just spat into my face and is giggling behind the monitor “s glass.

These phone entry field are poorly programmed in every other form I fill out. Have you seen the validation message like “Please remove all dashes and spaces from the phone number rdquo;? Any programmer who wrote anything just a little bit more complex than “Hello World rdquo; should know how to programmatically remove all unwanted characters from the string. Or maybe they don “t?

The next job interview I “ll start with writing the following phone number on the piece of paper:

1 800 555-1212

Then I “ll ask this candidate with the resume having the word Senior all over it to write the code removing anything but digits from this text. If he “s not done within 5 minutes, the interview “s over.

UX #2.

This morning I was purchasing online a bus ticket to go from Manhattan to New Jersey (a one hour ride). The address section had a text area where I “ve entered my address and below was a dropdown titled Country and populated with a hundred or so entries. Why in the world it starts with Afghanistan? Is this particular bus route popular among the Afghan citizen? Is this even safe to ride on this bus? What did the developer and his incompetent boss were thinking about? They were thinking about anything but the people who would be using this Web site. Does it require MS in Computer Science to add United States at the top of the list of countries? They don ‘t care.

It “s really sad. Random people are developing software. On the UI side they get away with such quality because people are too forgiving and don “t know any better. On the server side they survive because the hardware became very inexpensive. Instead of writing efficient code, they throw more CPU or scale horizontally by adding more commodity Linux boxes. Waiting to see how these so-called programmers will survive in the mobile space where both memory and CPU are not scalable, at least now.

I know that UI developers working in our company read this blog. Guys, if you “ll deploy an application in QA with the UI showing such disrespect to the users, you are fired. Nothing personal, but this would indicate a serious issue with your attitude toward your profession. You don “t belong here.

Java, Soviet Union, and Job Interviews

Back in the seventies, I was taking entry exams to the Kiev Politechnic Institute (KPI). I lived in Ukraine, which was a part of the Soviet Union. At that time people of the Jewish descent had really hard time in getting into most of the colleges and universities. Typically, there were four entry exams for the engineering majors: the verbal math, the written math, the verbal physics, and essay. There were no such things as multiple choice tests ndash; we had to solve problems.

Being a Jewish boy myself, I was raised knowing that getting into college will be extremely difficult for me, and I had to be much better prepared than regular Ukrainian and Russian kids. I was strong in math (can’t say this about the Physics though).

Anyway, during the first written test at KPI, there was a problem with the purposely wrong description. Each of the four hundred people that were taking this test had to solve it. I caught the trick in that problem, and my written math grade was 4 out of 5. Two hundred and twenty people got 2 out of 5, which meant that they wouldn’t even accepted to the second exam.

At the verbal math exam, each applicant had to randomly pick a sheet (a.k.a. ticket) with different written problems. Everybody was sitting in a large auditorium preparing their answers followed by the face-to-face conversation with a professor. He or she was reviewing your solutions and could ask additional questions.

I glanced at my sheet – all problems were easy for me. I quickly wrote the answers, then helped to a girl sitting next to me (this was her 5th attempt to get admitted) and wrote all the answers to the guy in the military costume – guys who server in the army had a preferential treatment (you may be surprised, but helping other people during the tests was considered a noble thing to do in the USSR). Each of them had a face-to-face before me and each of them got a quick 4 without any additional questions. I said to myself, that if they got 4, I could expect getting 6 out of 5.

Then was my turn. All answers for the ticket problems were correct, and then the professor started to ask me additional questions. After answering 11 (!) questions correctly, he asked me the next one from trigonometry, “What’s the difference between the graphs of functions arcsine and arccosine”. Piece of cake. I started answering “The function arcsine looks the same as arccosine,  …” He didn’t let me finish or draw the graphs. “Stop. So you think that arsine and arccosine look the same? Your grade is 2 (failed). ” This meant the end of my exams. No i understand, that I should have selected each word more carefully, but getting 2 after seeing how people who know nothing are fetting 4?

I was speechless for a moment… He didn’t let me finish the sentence! I started mumbling that I was awarded a second place in the math Olympiad of the central borough of Kiev. Then I pooled out the award certificate… He just said, “Apparently your math was better back then, but now you have a serious gap in trigonometry ”

Two months later I went to Novocherkassk, Russia, which was a town 600 miles away from home, got two easy fives on both math tests, 4 on essay and 3 on physics, and got admitted to the Applied Math major.

Several years ago, I was browsing books on Amazon and found a pretty interesting one – “You Failed Your Math Test, Comrade Einstein “. The authors compiled many tough math problems that were prepared specifically for the Jewish students applying to the Soviet “ivy league ” universities. I bought this book to show my respect to the authors for their work. People who live in Ukraine now, tell me that this practice is gone, and everyone has equal opportunities on entrance exams…I wish all the best to the people of Ukraine.

So what does all this have with Java and job interviews here in the USA? These days I often interview people who apply for jobs. A face to face interview is similar to that entrance verbal exam. The only difference is that in the USA people are graded based on their skills rather than ethnicity.

But let’s imagine for a moment that you are conducting a technical interview on Java programming and need to have a special question to ensure that the person you don’t like won’t pass. I ‘m going to arm you with one.

After years of interviewing enterprise Java developers of different levels, I can attest that 90% of them don’t bother learning new features of the language and just get by using whatever they learned some time in their past. For example, nine out of ten people still believe that there are only two way of creating a Java thread ndash; subclass a Thread or implement Runnable. You also thought so? I know. The “new way rdquo; was introduced to Java only six years ago. You want to learn another way? Get my recent book “Java Programming. 24-hour Trainer. ”

Here’s the killer question that 95% of the Java programmers won’t answer correctly. “Give all examples of usage of the keyword final”.

The candidate sits quietly for 30 seconds just to show that he ‘s thinking about the best way of answering this easy question, then he writes the following on a piece of paper:

– If a method declared final, this method can’t be overridden.

static final double convertToCelsius(double far){

return ((far – 32) * 5 / 9);

}

–  If a class is declared final, you can “t be subclass (extend) it

final class Tax { …};

– The value for the final variable can be assigned only once

static final int BOILING_TEMP = 212; // in Fahrenheit

Say politely, “Great, this is correct. Are these all uses of the keyword final that you can recollect? ” As I said earlier, the chances that the candidate knows the fourth use are about 5%. He goes, “Java has no any other use of the final keyword, I ‘m positive.” At this point you thank him for giving you great answers and say that an HR person will be in touch shortly. This is one of the major differences between the USA and USSR. We don’t say give the final answers while the candidate is still here. The phrase “Your answer is wrong ” or “You have a serious gap in trigonometry” could lead to unpredictable reaction of the candidate. We don’t want any conflicts. Let him leave in peace.

The mission is accomplished – he failed the job interview!

Recently released Java 7 has a new feature called final rethrow. In my opinion, it’s a pretty useless feature you can live without. Besides, it makes the code more difficult to read. Now, it’s legal to write something like this:

private void throwExceptions() throws A, B, C {

try {

throwAccordingToIndex(new Random().nextInt(2));

} catch (final Exception e){

System.out.printf( “Caught %s and rethrowing…%n “, e);

throw e;

}

}

To make things even more confusing, writing the keyword final here is not mandatory. But hey, the candidate didn’t know about this use, which means that his skills on Java are not current. And our team of sharp developers don’t need people with rusty skills. For the next several years this question will help you eliminating the candidates you don’t want to have beer with. No one will use this feature, and Java practitioners won’t have a chance to see it in anyone’s code.

Do you like my strategy? Neither do I. I’ll remember that episode with arcsine till I die, and will never apply such techniques while interviewing candidates. So why did I write this blog? To be honest with you, I don’t know. For some reason, when I learned about this feature, I couldn’t find any other use for it other than a secret weapon for the dirty interviewers.

Update. After re-reading this blog, I realized that it didn’t cover an important use case: what if the job applicant knows about this fourth use of the final? Ask what he thinks about this new feature. If he has any opinion about this feature, hire him. He follows the latest developments in the Java language and cares to form an opinion.

Java 7: The Most Confusing Feature

Java 7 has this new feature – now you can add the keyword final to the catch clause. This feature is pretty confusing. I tried to find bits and pieces that would make me wanna write the final qualifier in front of the exception ‘s type. This blog didn ‘t help much.

I wrote a little program below that purposely divides by zero. This program works with or without the final keyword, and the output is the same. I ‘d appreciate if someone would give me a clear code example (just the code, please) that would show why this confusing feature has been added to the language.

public class TestStackTraceJava7 {

TestStackTraceJava7() {

try{

divideByZero();

} catch (ArithmeticException e){

System.out.println( “Don ‘t divide by zero! “);

}

}

// This won ‘t compile: int divideByZero() throws Exception {

int divideByZero() throws ArithmeticException {

try{

int i=25/0;

} catch (final ArithmeticException e){

System.out.println( “Caught ArithmeticException and rethrowing… “);

throw e;

}

return -1;

}

public static void main(String[]args){

new TestStackTraceJava7();

}

}

Update. I ‘d like to thank Aleksander Borisov, who responded to my post and created an example that illustrates the usage of the final exceptions.

But the question remains the same, “Why making the language more confusing than it has to be? ” Just look at this code snippet from the Alexander ‘s post:

private void throwExceptions() throws A, B, C {

try {

throwAccordingToIndex(new Random().nextInt(2));

} catch (final Exception e){

System.out.printf( “Caught %s and rethrowing…%n “, e);

throw e;

}

}

Basically this code reads, “Even though I ‘m catching only Exception, actually, it can be one of the three types of Throwable objects: A, B, or C. I need to rethrow it to the caller anyway, and by the time the caller will get it, the type Exception will change back to one of three: A, B, or C “. To make things even more confusing, writing the keyword final here is not mandatory.

Currently, I ‘m teaching a Java class for the beginners, and tomorrow session happens to be about Java exceptions. I ‘ll just briefly mention that Java 7 introduces a confusing and not overly useful feature called final rethrows. Take a note of it, but you can live happily without ever using this feature.

Actually, I know one use of it, and if I ‘m not going to fall asleep on the bus while going home from work, I ‘ll write an blog describing a quite unusual scenario when final exceptions may help you. Stay tuned…