Tuesday, July 12, 2011

Bad Version Number in .class file

java.lang.UnsupportedClassVersionError: Bad version number in .class file
at java.lang.ClassLoader.defineClass1(Native Method)
at java.lang.ClassLoader.defineClass(ClassLoader.java:621)
at java.security.SecureClassLoader.defineClass(SecureClassLoader.java:12

If you have been developing in java and have been at it for a while..you may have encountered the above exception...

Before jumping into the fix, lets first discuss the problem itself..."Bad Version number in .class file"...What does it mean?

To figure it out, run the command javap -verbose {classFileName} on the command prompt(assuming win os). Sometimes the output generated is too much, so you might want to direct the output to a file.
Now in the output of the above command, search for words such as major version and minor version and you will find something like (obviously, the numbers can be different in your case)

  minor version: 0
  major version: 50

The following table tells you that the java platform version for the combination is 1.6
major  minor Java platform version 
45       3           1.0
45       3           1.1
46       0           1.2
47       0           1.3
48       0           1.4
49       0           1.5
50       0           1.6
Essentially, this means that my code was compiled using java 1.6. Now your error happens when the java runtime tries to run the file and finds the version number in the .class file inappropriate. This can only happen if your runtime java version is lower than the compile time java version.

The fix: Fix the runtime java version or compile in a lower version of java as appropriate. In an ideal world, both of them should be the same but they may differ for a variety of reasons,so just make sure the runtime version is the same or higher than the compile time version...

Now, depending on how you are running your program..you will need to make changes at different places...if you were running your program in Eclipse..you will need to change the 'Run' configuration (JRE tab)..if you are dropping a library in ant by developing a custom task..you will need to make sure that ant has a suitable version of java..(to figure out which version of java ant is using..run ant in the verbose mode)..pointing  JAVA_HOME to the correct jdk/jre typically fixes the ant issue

Hope this helps..

Sunday, January 9, 2011

End of an Affair - Completing SCEA Part 2 & 3

Ever since i submitted my exam on Jan 9th, i have been following a ritual. I wake up every morning and the first order of the day is to check my gmail. This morning was a pleasant surprise when Oracle sent a terse mail that i have been certified as an Enterprise Architect on the JEE Platform.

I have never been much of a blogger but this becomes an opportune moment to talk about my experience with the exam particularly because it took me about 1.5 years to get it all done(total lapsed time) and i feel its time to give back to the community who provided me enough help to walk through my own journey.

Enough Blabber...lets talk about the assignment now..

If you have looked into the assignment in some level of detail, you will be faced with the following kind of issues/questions -
  • How much time would it take to complete the assignment? 
  • There are too many opinions about addressing a problem in the assignment, and sometimes they conflict with each other
  • The assignment is slightly vague and somethings don't seem right/don't seem to add up.
  • Which UML should i follow? - 1.x or 2.x
  • Which tool should i use?
  • What technology stacks do i use to realize the solution?
  • Some people say that they write a whole lot of stuff besides whats required by Sun in the exam?
  • Should i have one class diagram or multiple class diagrams?
  • What should be the level of detail in my sequence diagrams?
  • How do i know when i am ready and my solution is complete?
  • What do they ask in Part 3?
I am sure there are many more questions and i can't even list all of them..but the above were the kind of questions i had when i was working on my assignment..

Let me take a shot at answering the above questions with my own impressions of the exam, as usual feedback/suggestions/brick bats(softer ones) are always appreciated.

How much time would it take to complete the assignment?

It took me about 20 days to finish Part 2 and 3. I did not work on the assignment for 1 whole year and spent about 4-5 hours each day(for 20 days) towards the end of my 1 year deadline. Most of the actual time was spent in understanding the problem statement.Do not underestimate it. The technology solutions are relatively simpler but understanding the gaps in the problem statement, understanding the nuances of the problem statement is much more challenging. I had identified and informally documented the risks of a possible system even before i started documenting the solution to my assignment. How much time you take depends on your level of experience in designing solutions but 60-70 hours seems a right estimate to me.

There are too many opinions about addressing a problem in the assignment, sometimes they conflict and sometimes they conflict with each other

This is one of the biggest problems(misery?) of this exam. There are too many 'opinions' out there and they often conflict with each other. To top it all you don't know which opinion to trust. The problem is escalated because all of them seem to have qualified the exam and yet they disagree on important pieces of the solution.Sun doesn't provide exam scores (just a Pass/Fail grade) and hence you don't know whose answer was closer to the bulls eye.You can mitigate this problem with your own knowledge and experience(there is no other way). If you don't have an opinion on a particular issue (example: should you be using jms or soap?), then you shouldn't be appearing for the exam.In my opinion (and i am not a exam guru), the exam is about two things - providing an architecture solution and defending it. If you have experience providing solution architectures you will know that there are multiple ways of getting anything done and more often than not there are no clear choices.Hence develop a solution,listen to others ideas but follow your own gut.There is a time to listen to opinions and there is a time to shut them out.

The assignment is slightly vague and somethings don't seem right/don't seem to add up.

On Javaranch, someone posted a reply from Sun Microsystems that the assignment is deliberately vague and i couldnt agree more. If choices were simple and Romeo could marry Juliet , everyone would be an architect. So, make assumptions(logical ones) around the aspects which you feel are vague, tell the examiner how the assumption has influenced your architecture and move on. Two different people can give two different assumptions and end with radically different architectures. All you have to ensure is that the assumption is logical and makes sense in context to the problem. For example, in an e-Commerce application you can't assume that there is no authentication/authorization module but you can assume that such a module is outside the scope of the solution you are presenting.There is a difference in both assumptions and i think it's important.

Which UML should i follow? - 1.x or 2.x

I followed a mix of both (Class and Sequence diagrams were 1.4 compliant while Component Diagram and Deployment diagram was 2.0 compliant) and i passed. I know people who have used 1.x and passed and i know people who used 2.x and passed.So, anything is fine as long as you are UML compliant. The assignment which i downloaded never mentioned anything about a version of the UML but just expected UML compliance.

Which tool should i use?
I used StarUML and Astah Community Edition.Both were free but depending on your operating platform and taste and willingness to spend - there are a bunch of UML tools out there which can be used. A tool does not make you pass/fail an exam,the solution does. Just make sure that you know your tool is UML compliant and the version to which it is compliant.

What technology stacks do i use to realize the solution?
This is an area where you will find a vast difference of opinion. Depending on the JEE version you use (1.4 or 5 or beyond), your technical choices will change. I know people who have used Struts/Spring and while in the real world i would probably nominate 'spring' as my defacto choice ,the examiners are paid by sun/oracle.I wouldnt go to the extent to say that a non JEE stack will offend them(the same has been said on JavaRanch) but i would recommend to play it safe..so stick to the standard JEE stack.

Some people say that they write a whole lot of stuff besides whats written in the exam?

This was one of my major issues while i was done with my assigment, people actually write reams of text ranging from architectural overview to a note on 'meeting the QoS requirements' although sun doesnt ask for it.I think writing a bit about your architecture makes sense but do understand that the questions in part 3 are related to defending your architecture and hence everything you are writing is probably redundant . However, i would recommend that you write about your contentious architecture decisions and a brief solution overview to allow the examiner to connect on your frequency.

Should i have one class diagram or multiple class diagrams?
Again, there are multiple opinions on this one. I submitted one class diagram but i know people who have split the class diagram. I think its ok that you split the class diagram but i would recommend that you split it by feature and not by layer. The latter would require the examiner to jump between multiple diagrams to understand one feature of your solution. Splitting them by features is rather logical.But if you can, try not to split it and let the class diagram by the looking glass into your whole solution.

What should be the level of detail in my sequence diagrams?
 Some people include method signature and some don't. I did include method signatures in my sequence diagrams. From an exam perspective, i would recommend that you stick to the 'Cade' style of showing JSP's,etc.

How do i know when i am ready and my solution is complete?
I would recommend what Cade does, get your solution peer reviewed.It helps

What do they ask in Part 3?
Part 3 is a 2 hour exam(minus the survey time) and all about defending your architecture. Search in JavaRanch and you will get plenty of hints.As an overview, some questions were about non functional requirements(how does your solution achieve them?) while others were explaining why certain alternatives weren't better.

My Advice for this part: Read all questions before you start answering them, as some questions are similar and you will need to choose which part of your explanation fits where.

My References(for part 2 and 3)

My Advice:
  1. As far as possible, keep it simple. When in doubt think , Occam's Razor
  2. This solution doesn't need you to think outside the box. If you think it is simple and routine, yes it is. Do not think outside the box because someone said so.
  3. Know basic UML . The UML standard is pretty intense and during my preparation i could never search to confirm if the UML i was using was valid. So, i stuck to what i know is valid. Martin Fowler is a good reference, keep it handy.
  4. Follow the  JavaRanch SCEA Forum.It helps to debate ideas to fine tune your own and it also helps to know that you aren't alone
  5. Think more about the business solution (and problem statement) and lesser about technology(as the tech stack is pretty defined in JEE).
  6. Document your assumptions and risks while you are developing the solution(and not at the end), this helps you capture details which you might miss at the end.
  7. Keep the assumptions sensible and ensure that they do not radically alter the intent of the problem statement in the assignment.
Some other blogs i liked (Obviously, i ain't the only one who likes to talk...)
I am sure there are many more blogs out there(maybe even better ones) but i liked them for their honest assessment of the exam.

Due to Oracle's exam policy i cannot talk about my Assignment or the specifics of my solution but i hope this post helps someone complete the exam successfully.