A Funny Java Flavoured Look at the World

Sunday, April 30, 2006

Interfaces vs abstract classes

I recently read an article titled interface vs abstract class and imagined an Alien versus predator type block buster movie, introduced in a boxing Rocky style of course

It is an interesting question, so I thought I would type it into google to see what else came up. I will assume the readers of this blog know the difference between interfaces and abstract classes but JavaRanch have this artice that states

"1. You can implement multiple interfaces at the same time, but only extend one class
2. An abstract class is allowed to contain implementation (non-abstract methods, constructors, instance initializers and instance variables) and non-public members"
Part of the argument regarding this question is also linked to theory that you should favour composition over inheritance. Abstract classes have to be extended which means they don't conform to a number of Object orientated rules which if you want to get a good grounding on it's worth reading Robert C. Martin articles on the subject, many of which can be found here

When I first starting to learn Java I really struggled to understand the use and idea behind interfaces they seemed very pointless to me. Abstract classes on the other hand were not so hard to understand (although not fully) because you can put some code in them. I think you start understanding the idea of both and then start to understanding when you should use one or the other is once you start thinking about the design of your code. I personally found this happened when reading the OO articles by Robert C. Martin and also seeing the good designs by reading a book on design patterns (head first design patters, very good). Once I saw that I could see the value of interfaces and abstract classes and the OO articles helped me to understand why the designs were good.

Back to the discussion at a hand, this site provides a good introduction to Abstract class and Interfaces. The JavaRanch article has these points to decide whether to use Abstract class or an Interface

"1. use an abstract class, if you want to provide common implementation to subclasses,
2. use an abstract class, if you want to declare non-public members,
3. use an interface if you want to provide the implementing classes the opportunity to inherit from other sources at the same time."
I think the important point to consider when decided if you want to use an Abstract class is will it contain code that will be used by the subclasses (classes that extend the abstract class). Will the subclass be the same as the baseclass (superclass) but with extra methods and code or/and will they override some of the superclass methods. So if the classes that will implement an abstract class or interface will need to use the same code then I would say you want this code to be an abstract class.

Be warned though you have to be cautious when deciding to use an Abstract class because it is then making the classes than extend it completely dependent on the abstract class. This can mean any changes you need to make to a core method can break all the classes that extend the Abstract class. On the other hand Abstract classes do allow you do add non abstract methods with out effecting the classes that extend it but if you add a method to an interface they all have to implement that method.

So when should you use interfaces. I usually think about interfaces as behaviours. Interfaces are a bit like contracts, a guarantee that the a class that implements them will have certain methods, they might not have anything in but we won't worry about that here. The classic example of interfaces is implementing algorithm's, which in my mind is a classic textbook example which you read, understand but then can never make it relevant to your work because there aren't many times you need to implement a number of different algorithms.

An example of interface implementation (in my opinion) is the sorting collections using the comparator. A quick summary of the comparator interface is used to order collections, it has two methods but I will just talk about compare(T o1, T o2) and it returns an int, Returns a negative integer, zero, or a positive integer as the first argument is less than, equal to, or greater than the second. It uses Generic functionality so T means a class. You extend comparator, implement the compare method which takes two objects you have made and then works out a way to decides whether the first object should be sorted higher than the second object.

This is an excellent example of using an interface correctly, it is a behavior, it is not something you would want to be an abstract class because each class would probably want to overwrite the compare function. Another point to consider when thinking about using an interface is would other classes want to use this functionality. Abstract classes have firm hierarchy, Interfaces can be implemented by any class anywhere.

Interfaces also have the advantage of allowing classes to implement many interfaces where as you can only extend one abstract class.

This article offers a brief discussion on Intefaces versus Abstract Classes and this discussion gives a number of opinions from different people which is useful.


Summary

I think it depends on the functionality and purpose of your planned functionality. If you want to create some default behaviour and provide some base code with abstract methods for extending classes to implement then abstract classes are the way to go, which is why they are often used in frameworks.

If you want to implement behaviour that could be used by many un related classes and you don't want a hierarchy for the classes that implement the code then you want to implement an interface.

Obviously I'm not an expert and I just giving my opinion on a very complex topic, so please for give me if I have written anything stupid or completely incorrect, it was a very interesting topic to try and write about, also a very tricky one. I would like to people to comment on their ideas on how they decide to use Abstract classes or interfaces. I never use to like Interfaces because you would have to write the code for each implementing class but now I realise that if you use the interface in the correct way this is a good thing and interfaces allow you decouple your code and protect your code from changes by allowing it easy to change the code behind the interface, especially adding in new implementing classes and using them.



SCJP FAQ

I'm sure a lot of people studying for the SCJP Java 5 exam will have been to the Java Ranch but in case you haven't I highly recommend you visit this page, it has links to loads of goods sites and also has lots of really useful information.

I really found useful and interesting because they are a collection of frequently asked questions on the SCJP

SCJP FAQ

Not only does the link above have links to useful pages it is almost a one stop shop tackling topics links to mock exams, sun resources, exam preparation, questions like the difference between the 1.4 exam and the 1.5 exam.

about where to find but it also has answers questions about the SCJP Java 1.5/5 exam, topics like, what I like is that it has information no SCJP exam gotcha's

What are some potential trips/traps in the SCJP exam?

Can I have more than one class in a .java source file?

What are the important I/O constructors and methods?

The Java Ranch also has an excellent forum which you can find questions and answers on SCJP questions The Forum is a good thing to check maybe once a day and read a question that is interesting or you don’t know the answer to. If youpracticee for the exam in little bit sized chucks like this it doesn’t seem to much effort and in the end all the little bits add up to a large whole.

Saturday, April 29, 2006

Free PDF - varargs sample chapter

I have found a link to a sample chapter on the Java 5 feature - vararg also known as Variable arguments. This is also on the Java 5 SCJP Exam so anyone studying for that should give this chapter a read.

The chapter is from the book Java 5.0 Tiger: A Developer's Notebook By David Flanagan, Brett McLaughlin. The chapter talks about how to create and use variable-length arguments list. So it's a good resource for people wanting to study varargs for the SCJP Java 5 exam and also for people who are interested in writing varags code and using varargs

if you want a bit more VarArg action

There is also to a sun's tutorial on VarArgs this is from there Tech Tips news letter

VarArgs for people who haven't used them, allows you to pass a number (one or more) of types of objects into a method. So a simple example would be passing people's names into a method, some people who have one name e.g. Madonna (1 String) some people could have names with lots of middle names e.g. Benjamin James Hosking(5). It's quite a good feature and is quite useful in certain situations and better than having an array variable.

here is the link

http://www.onjava.com/catalog/javaadn/excerpt/javaadn_ch05.pdf

I hope it helps all you people studying for the Java 5 exam

Friday, April 28, 2006

Enums sample Chapter

On one of my favourite sources of free sample chapters, I found a link to a sample chapter on the new Java 5 feature - enums. Enumeration types to give them there full name is a way to create Constants in Java. Enums are more than constants they are more a constant data type.

A simple Example of a potential Enum would be days of the week.

The chapter is from the book Java 5.0 Tiger: A Developer's Notebook By David Flanagan, Brett McLaughlin. This is an excellent resource for people looking to study for the SCJP Java 5 exam or for people who would like to know how Emums works and best of all its free.

Here's the link

http://www.oreilly.com/catalog/javaadn/chapter/ch03.pdf

Why is Eclipse called Eclipse

Here is my friday 'Why is' blog entry, this week I have looked up why Eclipse is called Eclipse. There are a few articles I have seen for the naming of Eclipse. It of course has an excellent name which would hint at the project eclipsing Sun's efforts at creating an IDE for Java but rumour has it this isn't how it got it's name.

This is a quote from What's in a Name article, a link to it is below

"It turned out Sun wasn't the target of the Eclipse moniker, though. In his keynote at the EclipseCon 2005 conference in March, Lee Nackman, chief technology officer and vice president of Design, Construction, and Test Tools at IBM's Rational Software division, said Microsoft Corp. was actually the company IBM wanted to "eclipse" and was the true object of IBM's attention."

I have also said read somewhere that they called the project Eclipse not because it would eclipse Microsoft's Visual Studio or Sun's NetBeans but that some one at IBM said that it would Eclipse anything that they had done before. I nice romantic sounding story.

The name you think isn't that important but in 2003, Sun Microsystems it was rumoured where going to join the Eclipse Foundation but said it would join the foundation whilst it was still named Eclipse. The also officially said they were working on their own IDE, which is probably more likely.

I have found two interesting article about the naming of Eclipse

What's in a name?

This article is a good background on Eclipse

The Eclipse Phenomenon

You can also check out the Eclipse history and other stuff at their site although I prefer to spend time looking at all the plugins myself

What's the difference between Java 5 and Java 1.5

We were going to ask the question in the title to people we were interviewing for a job. The amusing thing was when we asked people in the office no one knew the answer (except me because I am studying for my Java 1.5/5/Tiger exam).

It just highlights the stupid naming scheme used by Java, for a company who have a document on coding conventions to produce such a random naming structure seems odd, firstly you have the it called Java 5 and then Java 1.5 and also it is known by an animal Tiger, why do we need three names.

I could understand the lower numbers (but not both) when they were releasing dot releases but I think I read some where that they were no longer doing that. Here are the names of future releases which I got from Sun's site.

J2SE 5.0 (1.5.0) Tiger Sept 29, 2004

Future Releases
J2SE 6.0 (1.6.0) Mustang Not yet released
J2SE 7.0 (1.7.0) Dolphin Not yet released


The words, complete shambles spring to mind, why bother having two release numbering systems, does anyone else do this. I also forget they also changed the code for the development kit as well to JDK from Java 2 SDK. I heard a good joke on the Java Posse podcast they wondered if someone would one day make a new JVM which did Generics in a different way but what would they call it one of the Java Posse members asked. Java 2 was his response.

I found this document on sun's website it does have an interesting part where you can see where the release number is used.

The upcoming feature release of J2SE is version 5.0. We have changed the version of this release from 1.5.0 to 5.0 to better reflect the level of maturity, stability, scalability and security built into J2SE. (This release is also known as "Tiger".)

Platform and Product Names Use Version 5.0

Version 5.0 is used in the platform and product names -- the leading "1." was dropped. Where you might have expected to see 1.5.0, it is now 5.0 (and where it was 1.5, it is now 5). The names are now:


Full Name Abbreviation
Platform name JavaTM 2 Platform Standard Edition 5.0 J2SETM 5.0
Products delivered
under the platform
J2SETM Development Kit 5.0 JDKTM 5.0
J2SETM Runtime Environment 5.0 JRE 5.0

Due to significant popularity within the Java developer community, the development kit has reverted back to the name "JDK" from "Java 2 SDK" (or "J2SDK"), and the runtime environment has reverted back to "JRE" from "J2RE". Notice that "JDK" stands for "J2SE Development Kit". The name "Java Development Kit" has not been used since 1.1, prior to the advent of J2EE and J2ME.

As before, the "2" in Java 2 Platform Standard Edition indicates the 2nd generation Java platform, introduced with J2SE 1.2. This generation number is also used with J2EE and J2ME.

Where Is Version 1.5.0 Still Used?

J2SE also keeps the version number 1.5.0 (or 1.5) in some under-the-cover places that are visible only to developers, where the version number is parsed by programs. In these cases, 1.5.0 refers to exactly the same platform and products numbered 5.0. Version numbers 1.5.0 and 1.5 are used at:

  • java -version (among other info, returns java version "1.5.0")
  • java -fullversion (returns java full version "1.5.0-b64")
  • javac -source 1.5 (javac -source 5 also works)
  • java.version system property
  • java.vm.version system property
  • @since 1.5 tag values
  • jdk1.5.0 installation directory
  • jre1.5.0 installation directory
  • http://java.sun.com/j2se/1.5.0 website (http://java.sun.com/j2se/5.0 also works)

Can Blogging Boast Your Career

I read this article which was titled Blogs Essential to a good career, dispute the ludicrous title it was still fairly interesting article. I don't think it is essential but I think it has some advantages to your career but not really in the way his article eludes to.


It's interesting that the article mentions people google potential employees. I can back this up as we do this at the company I work for and it's sometimes it's quite a shock what people put on their blogs and websites and I would put out a word of warning to some people. Your website or blog can sometimes be the first impression of you potential employers will get, so it may be prudent to tone down some of the views and comments. I know this comment is going agaisn't free speech and you should be able to have anything you want on your blog or website but the contents of blogs/web sites can effect employees decision on who they employ

Anyway back on to the subject, these are the main subjects of the arties of similar quality but one of them has a website with some dodgy content or strong opinions on a subject, this could be the deciding factor.

The points I agree with in his article are

1. Blogging creates a network.
3. Blogging is great training.
8. Blogging makes the world a better place.

I think Blogging doesn't create a network because by reading peoples blogs you do get to know people and you may have heard of their/read their opinions on things before you meet them. Also other people discuss opinions put forward on other blogs

I have found writing entries for my blog, very interesting and good training for a number of reasons. The first reason is if I'm not sure what to write about in my blog, I will sometimes think what would I find interesting, this will lead me to look up another article or search for a particular topic, Duck Typing was a good example, I decided to research what it was and then wrote this blog entry

I have also found that you do learn topics better when you sit down to write a blog entry about them. I will often search for some information on the topic. I also believe it takes a greater knowledge to describe something so people with or without knowledge of the subject can understand the post.

Finally I think you think about what you are doing in your job more and look for things to blog about. So I certainly think writing a blog acts as a sort of training.

I also agree that Blogging makes the world a better place. There is a lot of people taking articles and blog entries from other people but without ever returning the favour or passing on their knowledge. I hope that by my writing a blog it helps people to understand problems or just passes on some factual information or perhaps learns how not to write Java code ;-)

I hope that my blog may help people studying for their SCJP exam or people just programming on a daily basis. I am glad to contribute back to the community

I also think that blogs have added a fantastic resource to the internet because blogs, particuarly in programming. Blogs allow people to write about their experiences with certain technologies or problems and give their opinions on topics. This is vastly different from reading an article someone has wrote. An example of this is on the Duck Typing post I did, I found the comments just as useful as the blog entry. I think what I am trying to say is blogs allow people to down their ideas and experiences which can be more useful and powerful than a technical article

So I don't think writing a blog is essential to your career but it could help, of course it does depend what you put in your blog and if other people find it interesting. Is the opposite true, does a bad blog ruin your career, now that's a scary thought

Thursday, April 27, 2006

Java Project Names - From Sparkler to Dolphin

ever wondered what the code names were for the releases of Java, I did too and I found this information at Sun's website. It's hard to believe but it looks as if they have improved slightly, the first few releases where just silly, Pumpkin or playground anyone

The document is below but here is the link if you fancy that Sun code names

Since 1.2.2, major releases 1.3, 1.4.0, 5.0 and 6.0) are named after birds or mammals, while minor releases are named after insects, given that they are bug-fix releases. (Hopper is short for grasshopper and ladybird is another term for ladybug.)

VERSION CODE NAME RELEASE DATE
JDK 1.1.4 Sparkler Sept 12, 1997
JDK 1.1.5 Pumpkin Dec 3, 1997
JDK 1.1.6 Abigail April 24, 1998
JDK 1.1.7 Brutus Sept 28, 1998
JDK 1.1.8 Chelsea April 8, 1999
J2SE 1.2 Playground Dec 4, 1998
J2SE 1.2.1 (none) March 30, 1999
J2SE 1.2.2 Cricket July 8, 1999
J2SE 1.3 Kestrel May 8, 2000
J2SE 1.3.1 Ladybird May 17, 2001
J2SE 1.4.0 Merlin Feb 13, 2002
J2SE 1.4.1 Hopper Sept 16, 2002
J2SE 1.4.2 Mantis June 26, 2003
J2SE 5.0 (1.5.0) Tiger Sept 29, 2004

Future Releases
J2SE 6.0 (1.6.0) Mustang Not yet released
J2SE 7.0 (1.7.0) Dolphin Not yet released
Note: Dragonfly (or dragon, for short) was an interim code name for J2SE 5.1, which has been folded into Mustang, so is no longer a separate release.

Taming the Tiger, an article archive about Java 5 resources

I found a link to a Java 5 article resource at the IBM developer works website.

one article in particular I found useful, it gives a good overview of what you will be tested on the SCJP Java 5 exam. There is also a good article about collections

It had a good summary of the Exam objectives in no particular order

The seven categories of objectives for the exam are as follows:

  • Declarations, initialization, and scoping
  • Flow control
  • API contents
  • Concurrency
  • Object-oriented concepts
  • Collections/generics
  • Fundamentals

Declarations, initialization, and scoping

The initial section describes everything you need to know about the basics of the Java programming language. Expect to be tested on covarient return types, JavaBean naming conventions, and the ability to read nested class listings. Here is also where you are expected to develop classes and interfaces, understand abstract classes, deal with the differences of static and non-static methods and variables, and work with constructors and return values. There's nothing here that should sound too complicated to an experienced developer, but there are some things thrown in to trip you up. For example, don't assume that just because code lines up at the same tab stop that it is a method for the same class. Instead, ignore white space and tab stops when reading code. Expect little tricks like that to try to confuse you. Remember: follow the {}s.

Flow control

Most people should find this section easier than the others, having to deal with the familiar for-loops, while-loops, and do-while loops. However, it also includes content about the assertions and for-each loops. The other big section of content to explore here is exception handling. If you have a good grasp of try-catch-finally and where exceptions come from, you should do fine here.

API contents

This topic is mostly a catchall for those that don't fit elsewhere. It might require a good amount of study time if you have not used certain areas of the platform. Most of you should be familiar with working with the I/O streams for bytes and characters, but some of you might be unfamiliar with object serialization. You may be less familiar with locales and formatting dates and numbers.

The 1.4 release introduced regular expression handling, and it is covered here too. Also, there is the different primitive wrapper classes with autoboxing/unboxing and the string handling classes of String, StringBuffer, and the new StringBuilder. If you aren't familiar with StringBuilder, be sure to learn how it is different from StringBuffer.

Lastly, there is the reading and writing of formatted input and output using the new Scanner and Formatter classes. Because of the broad nature of this topic, don't feel like you should spend an equal amount of time studying each; give yourself at least twice as long for this section.

Concurrency

The concurrency section is not about the new java.util.concurrent package. Instead, it is about understanding the use of Thread and Runnable, along with the proper use of synchronization, wait(), notify(), and notifyAll(). You should know how and when to lock objects properly when accessing critical sections of code.

Object-oriented concepts

The object-oriented concepts section requires that you have a good understanding of object-oriented programming principals and practices, like when to use inheritance, how to implement is-a and has-a relationships, and the differences in overriding and overloading methods. If you understand why you want loose coupling tied to high cohension and can describe its benefits, you should do well here.

Collections/generics

One of 5.0's bigger additions is with generics. You'll need to understand the differences between the various collection types, when to use each, and the importance of overriding both hashCode and equals. You'll need to know how to write generic methods and classes -- not just use them. You should expect to be tested on dealing with sorting through both the Comparable and Comparator interfaces. If you haven't used generics much, you should spend some time focusing on this area.

Fundamentals

The fundamentals section requires you to understand various key aspects of the language, tools, and underlying virtual machine. You can expect questions on garbage collection, operator precendence and usage, access modifiers, JAR files, and the class path. Be sure you know the difference between primitive and object references and the autoboxing features found in 5.0.

Does your Development team reward stupid coding errors, they should

I saw this blog entry that says at Sun's Prague office when someone does a cvs commit that breaks the build they get an ugly ceramic "golem" on your desk...Possibly for weeks or months. Here is a link to the article with a picture

We have something similar at my work, recently brought back by me. We use a toy Roger Mellie, for those of you who don't know Roger Mellie (shame on you) but he is a character from an adult (lots of swearing and rude jokes) cartoon. He even has an entry on Wikipedia

We pass "award" when some one does what I like to call a "Schoolboy error". An error that for want of a better word is just plain dumb. A really stupid error that leaves you completely baffled until you realised that its something stupid that you have done, its usually even better if they get someone else over to try and work out the problem, complete embarrassment

I liked this article because we a soft toy what we called excited man. The person who makes a “Schoolboy error” gets the shame of having the toy displayed on his desk.

I have reintroduced the “Schoolboy Error” trophy at work and as soon as I did I earnt it immediately. I had been trying to get hibernate to work recently and I was having a bit of a wrestle with it. I found I just couldn't specify a config file, hibernate was picking up the config file I had clearly placed in the correct directory, I was shouting at the screen, cursing hibernate and then whilst stepping through the code for about the 50th time I noticed that I had spelt hibernate.cfg.xml – that is what it should have been instead I had written in

hibernate.cgf.xml

it still almost looked okay even now , until you notice the I have put cgf instead of cfg.

I think its a good thing to have in the office because firstly it gives everyone a laugh and sometimes it can prevent other develocommittingiting the Schoolboy Error themselves

This error reminds me of an error a customer had done recently. A few weeks ago I had to upgrade a customer because they were experiencing the dreintermittentitten problem. This is usually some kind of machine set up problem, especially if it works one minute and then not the next. So whilst I was there upgrading their system in a last ditch lets upgrade em and hopes it fixes the problem. The customer (an oracle forms developer) checked in some code to use some of the new functionality then just after checking in the code we managed to recreate the problem. It turned out that the customer had mis typed CENTERLINE and had put in CENTRELINE in only one instance of the code (which loaded up a layer called CENTERLINE, except it doesn't if you don't spell it correctly). So the main reason I went to the customers site was to actually fix a problem with his spelling.

A classic school boy error if ever I saw one. Still me and the chap basked in the glory of fixing the problem rather than dwelling on the cause.

I am still waiting for some one else in the team to reclaim the Roger Mellie doll from desk, I have the utmost faith in my fellow programmers. If anyone else has any good examples of school boy errors please put them in the comments and if you are bored at work I would recommend you check out Roger Mellie's profanisaurus viz link iabsolutelylutly hilarious.


why I wanted to use Hibernate but couldn't

I have been recently working on some JDBC connection code. I was hoping to use hibernate for the connection stuff even though I had already written some code to connect to a database. The reason why I wanted to use hibernate was if the user then changed their datasource then it would be an easy case of just changing the connection config, which in hibernate is called hibernate.cfg.xml

One of the advantages of using hibernate is it has it's own sql language - hql. This means you can write some Hql and then it will convert this into any database you want to use. The beauty of this is you no longer have to worry about the different sql syntax on different databases.

I am currently trying to use Access the sql is just slightly different

this worked in oracle


Select Place_Name,easting,Northing from citytown where lower(Place_Name) like lower('a%') order by Place_Name where rownum < 21


where as this works in access

Select top 20 Place_Name,easting,Northing from citytown where (Place_Name) like ('a%') order by Place_Name

there are other examples of slight syntax differences which means you have create different sql statments depending on what connection you are using.

The other benefits of using Hibernate is they have more developers working on it, so you are getting a good solid product with many hours of effort and testing put it, not to mention any future development. Hibernate also supports lots of databases which you might need in the future. Not to mention their database connection code is firstly much better written, faster and more efficent.

Another reason why I am glad I have looked at the hibernate and got some oracle examples working was because lots of companies are using it at the moment, so it's a good thing to put on your CV.

I was also impressed with the design of hibernate with regards to the code intergrating with the configuration files. It made it very flexiable because the configuration files make it very modular, allowing you to plugin your config files and point to Java files you have created but without having to really extend any of the hibernate classes. As with many well designed pieces of software I am also impressed by how such good design can look so simple, a sort of complex simplicity. Hibernate was very easy to setup and use and comes with an excellent tutorial, which is straight forward and easy to follow.

I like the idea of mapping database tables to POJO's (plain old java objects) and abstracting the database to a connection file.

I'm certain Hibernate has many other qualites and this isn't a review of Hibernate, it was more a blog about why I wanted to use

Although I couldn't use Hibernate because hibernate doesn't support Microsofts Access database, well I it doesn't support it on their supported Databases page. I had a look and someone had done some work on it but I couldn't be bothered with trying to implement their own access dialect. I found it very useful and interesting trying hibernate and I look forward to using it in the future.

I view hibernate and using things like it, similar in some ways to using Struts in your web app. Let Struts/Hibernate do all the boring fundamental/structural code so you can concentrate on writing the more exciting crowd pleasing code. In Hibernates case I don't want to write code to deal with different connection urls or the different flavour of syntax used by different database, let hibernate deal with it. It also has the benefit of becoming an industry standard, so if a new developer joins your team, there is a decent chance he will understand hibernate where as he would probably have to learn to unravel some home made database connection code.

The final comment I would like to make is I would urge developers who have only used hibernate to write some connection code yourself, so at least you know what hibernate is doing and then you can appreciate why using hibernate is a good idea.

if anyone would like to comment on their experiences with hibernate please do, I would be interested into what other people think about it.

Wednesday, April 26, 2006

Why you should use the this keyword

I have recently turned on CheckStyle as I blogged about earlier and I was saying I thought it had improved my coding style and the quality of the code I was writing.

I have turned on the rule called Require This under the group coding problems

Checks that code doesn't rely on the "this." default, i.e. references to instance variables and methods of the present object are explicitly of the form "this.varName" or "this.methodName(args)".

To start with I found it really annoying because it would keep moaning on at me to keep putting this infront of class variables and the Name of the class for Static variables.

I persisted with it because I thought someone must have made this rule for a reason. Today I have started to feel it paying off because now when I look at the code I can see what type of variables they are instantly. It seems more straight forward when you know what a static variables and what a class variables and finally what are the method variables, they are easy to spot because they are ones that aren't so long.

I have also found that while I am putting this infront of a variable or the class name for static variables I am now considering what level the variable should be at. If I think that the variable is going to be used by more than one method then I bring it up to be a class variable. I know this is basic programming but I was interested by the fact that I am now thinking about this more. I am also bringing up more variables to be static final variables.

I was thinking about doing something like this before in eclipse but by using the editor and colouring the different variables in different colours. I did some of the variables but the different colours looked a bit confusing but with using the this keyword everything is becoming a lot clearer.

It should also have some benefits when someone else comes to look at the code I have been writing because they should be able to get a clear idea about the variables being used and what level they are.

if you like this post you should read my blog entry using final variables which also has a link to a sample chapter



Warning - Taking the SCJP Java 5 Exam Encourages Cleaning and Ironing!

I have found out there are some unusual side effects that no one warns you about when you decide to take the Java 1.5 exam. I'm normally quite a messy a person, as anyone who has seen my desk at work would testify too, not that many people have actually seen my desk because it is camouflaged with all sorts of papers, notes, books (to show I'm studious) and old Papers.

I only study for the SCJP Java 5 exam at home but some study at night and on weekends. Sometimes it is so boring that I will use any excuse to stop studying. Recently like many students I have had to urgently start cleaning the flat, much to the amusement and bewilderment of my girlfriend who has never seen such behaviour in me before. Along with cleaning there are other mundane things I urgently must attend to, things like

reorganizing my CD's
loading up the washing machine and hanging up the clothes that were in it
organise all my files
start reading other un Java exam related text books
draw pictures of animals with hats
ironing all my shirts for the week

The other positive side effect of studying for the SCJP Java 5 exam is that I often feel the need to reward myself with new CD's (to help me study) and my CD collection has grown and a very healthy rate and for a change I have actually listened to them all loads.

Help Improve your Coding Standards

I have recently started using the CheckStyle plugin for eclipse. When I initially installed it, nothing happened. I was slightly surprised I thought the code would have flagged a few areas for improvement.

aha, I then found out you that you had to turn it on, I wonder why they would code it like that. I turned it on and baam, yellow highlighter everywhere and I mean every where, practically on every line. Now I understand why you have to turn CheckStyle on.

CheckStyle to people who don't know, it is an open source (free) tool that helps coders to write code to certain standards and also stick to various best practices. For companies who have a number of developers working on the same code, standards can be a vital area, particularly if individual developers all code to different standards.

I often had a disagreement at work with the placement of brackets on if statements

I use to like this style

if (true)
{
//some code here
}
else
{
//the else code here
}

he preferred

if (boolean test) {
//if code
} else {
//else code
}

In the end we settled the dispute by going with the Java coding standard, I still think the code above is easier to read because the brackets match up. Still before we came to a truce and the second style was chosen I wrote code with brackets seen in the first version. Now when I come to check the code I have written the first thing I notice is the brackets are all in the wrong place. This is just one trivial problem but if you have many different coding standards and styles then when you have to fix a bug in another developers code you can waste a lot of time just trying to decipher the strange looking code (compared to your style) and merely trying to understand what is actually happening before you can even work on diagnosing the problem.

This is where CheckStyle comes in. When you are writing new code it warns you to put a JavaDoc comment in, it gives you warnings about naming conventions and placement of brackets and numerous other rules. The result is if everyone in your team used CheckStyle then you would end up with similar looking code and written to meet certain standards. I can certainly see the benefits if you work somewhere where people leave and join frequently.

Some of the rules and standards in CheckStyle might be a bit to strict or you may disagree with them. I am currently removing the rules which I don't think are relevant or are a bit over the top and hopefully I will end up a set of rules which I can get the other developers to use.

As I mentioned early using CheckStyle with legacy code can be a bit of a nightmare because it will flag up hundreds of warnings. It is a similar situation to when you start thinking about implementing unit tests, you look at your legacy code and think where do I start and then think there is so much unit tests to write is it worth (is it possible). Using CheckStyle with Legacy code can be almost impossible. My advice is to turn it on and then slowly change a few lines to conform to the rules and just do a bit at a time but don't spend all morning trying to get your code up to the Check Style standards. You could implement a limited set of rules for legacy code so that it is up to a certain level. I do think its worth changing the code and setting it in the right direction, you will feel the benefit later on where you see code that all looks the same and you can just concentrate on the logic not the syntax.

Finally there are some of the rules that make you write good code. Here are some of the features I like

Checking for duplicate code
warning if variables aren't used
making incoming parameters final
checking for magic numbers
making sure brackets are placed in the correct position
making me write JavaDocs (so I don't have to do them all at the end)
making sure you code adheres to sun naming conventions

There are many more but it certainly makes you think when you are coding and I have found that I am now wanting to write code that passes all the tests and I probably wouldn't write code that met such standards if I didn't have CheckStyle nagging me to change it.

If you are interested in CheckStyle here is a link to the eclipse plugin

CheckStyle Eclipse Plugin

I also found an interesting article on CheckStyle here

The article promoted me to write about how I have used CheckStyle and really like it

Tuesday, April 25, 2006

You know you have started to write better code when changing things isn't too painful

When you go back to some code and it's actually quite easy to add some more code to it.

The code I was looking at was adding a new block of code, without going into to much detail the code was dealing with connections and I was adding in an Access connection. I had tried to do this in hibernate but it doesn't support Access databases.

So I had to add in another connection block. All I had to do was extend my baseConnection class and create my new AccessConnection object and then add one if in my baseConnectionFactory and I was away. The code that uses the connections is in a Struts action (general database search) and it uses the baseConnection superclass so it didn't have to change at all. The code also picks up the connections details from an xml file.

I have to admit that this was one of the few occasions that going back and adding to some code didn't involve *Wedging* it in and re writing it. Some of it was legacy code but this particular code I had refactored before and this time. I also did some refactoring (pulling up a method into the super class) but I think you always do that.

Anyway it has certainly has shown the benefits of firstly spending some time designing a piece of code properly and separating out the dependencies of the code. It also has shown me the benefits of refactoring the code when you are in there fixing a bug or adding some new code in. I think I have heard this mentioned as code debt, if you wedge in a quick fix into the code then you are in debt to that code. So even though you have benefited by adding the fix in quickly, next time when you have to change it again you may have your debt called in and will have to fix it properly. Last time I did fix the code to a better standard and this time I have felt the benefit

Of course the downside is that there is already much better connection code out there and why am I wasting my time writing connection is a completely different story.

Are you an Early Bird or a Night Owl

I've been studying for my Java 5 exam and most of the time I prefer to work late at night, hence why I am writing this blog late at night.

The main reason why I like studying so late is that I feel that there isn't anything else to do at this time, so I can focus on the work and not get side tracked. The only thing on TV is complete rubbish. I have read that people can be split into to two different camps

Night Owls or Early Birds

I am certainly I night owl as I like staying up late and hate getting up early. I think that it's quite useful if you know this you can then work to the schedule. Watch some TV and chill out earlier and then do some studying later.

I have also read in my Head First Java book that they recommend

Make this the last thing you read before bed. Or at least the last challenging thing.

The book mentions that your brain continues to digest and process the information after you have finished reading it. So it is a good idea not to do anything else after you have learnt some new information. This makes learning something just before you go to bed an ideal time because you don't do anything whilst sleeping.

The above doesn't really matter if you are a night owl or early bird, it just recommends that you read before bed.

The BBC have a test if you are curious to find out what you are, I imagine you already know but here's the link anyway BBC Link

I'm sure I'm not the first or will be the last person staying up late to revise for the Java exam

Monday, April 24, 2006

Free Online Tutorials

Free Online Tutorials by Sang Shin on various subjects like J2EE Programming with Passion and Servlets, JSP's and lots of web tutorials. He also has a semester like online courses where you have to do homework, so if you fancy going back to school this might be for you.

Sang Shin is presently working for Sun Microsystems as a Technology architect, consultant, and evangelist. He speaks on various Java and Solaris related technologies to worldwide developer audience.


http://www.javapassion.com/

he has a number of good online tutorials

here also has many more



this is a link to the a presentation of the features in Java 5. This is quite useful for people studying for their SCJP Java 5/1.5 exam

http://www.javapassion.com/j2se/Tiger.pdf

Well any information that will help you with the exam is good in my eyes.

Concurrency Podcast


The current podcast from the Software Engineering Radio is about concurrency and Threads and is worth listening too. Here is a description of the episode

This is the first part of a series of Concurrency episodes. In this part Alex and Michael motivate and introduce the topic. We explain fundamental terms, such as thread, process, or mutex and discuss typical challenges, such as deadlocks and race conditions. Here are some related links:

I would also recommend listening to the other podcasts as well

Pay Reviews - Get What You Can

I did a blog entry recently about average Java wages and thought I would do a blog about pay/yearly reviews. I can only talk about my experiences of reviews and they probably aren’t the same as other peoples but perhaps it’s similar to other people out there.

I feel people seem to get a bit too excited about pay reviews and suddenly start to believe they are going to get a massive pay rise from the company. Usually the same company who haven’t sent you on any training for the rest of the year and won’t pay your expenses because you lost the receipt, suddenly people think they are suddenly going to give you a wheelbarrow of cash and a hearty pat on the back (it only happens if you work in sales)

People imagine they are going to get a big pay rise but are much more realistic when it comes to calculating the pay rises that are going to be given to everyone else. I think that in reality everyone is going to get the same percentage wage increase, this is the safest thing to do because it doesn’t single anyone out and its hard to moan to your fellow worker that you think you should get a bigger increase than them.

One of the worse scenarios to be in when working at a company is when you join the company on higher wages than the people who have been working their for ages. They feel it’s unfair they are getting paid less for doing the same job. Well in a word it is but it’s never going to change, so if you don’t like it move jobs. The reason people moving job get paid more is because the company is paying for their experience.

The reason why people who stay at a company get paid less (for the same job sometimes) is because companies give them lower wage increases. Companies in reality will give you a lowest wage increase they think they can get away with. Why do they do this because they can. I actually think this can be a bit of false economy sometimes because if that person leaves to get a better paid job then they are probably going to have to pay someone else an increased wage to replace them (unless they get a young pup and train him up). It also doesn’t take into account the knowledge the person has on the industry and working practises of the company but overall I’m guessing it saves the company a few quid.

It is hope I think that makes us think we might get a massive pay increase, just dreaming of all the things you could buy with the extra money. We expect to much but I think you can still influence the review so that you can get more.

There are things you can improve, things to help you have a better life but I think you have to try and use the system and not be too radical in your training demands.

Training is usually in small companies non-existent or worse. Firstly I would ask for some training and explain the benefits and why you think it would be beneficial to the company (and your CV of course). This is an area I think people can try a bit harder, firstly look for free training courses or conference that you can go on. Secondly try and choose something like an Exam, this may mean doing some work outside of working hours or you could get them to give you an hour or two a week, just remember in the end you will benefit and the company might pay for the exam and a book (because it looks good for them to firstly train people to trick new recruits and they can boast about having qualified programmers). The downside is that you will have to do a bit of work in your time but the benefit is you will be certified and that will always be on your CV.

Ask if the company will buy you a book and maybe give you some time to read it. I know it’s not much but in the end it’s better than nothing. If they are really tight ask if you can have a couple of hours to research technologies that might be useful to the company, you will benefit by learning and keeping up to date with the new technology. I know the last few things don’t seem like much but they are better nothing and the company would like to give you something which isn’t going to cost them much, be proactive and offer them some solutions.
Wages

The real bottom line of any pay review/yearly review. Firstly if you haven’t got the pay rise you think you deserve put your self in your employees shows, what would you do if you were in their shoes and what do you think you were realistically going to get. I am of the opinion really that they have decided your pay rise (or no pay rise) before you have the review and nothing you say is going to change their mind but that doesn’t mean you shouldn’t try.

I saw someone recently who told his boss that he wasn’t happy with his pay rise and then the next day they offered some more. I suppose what I am trying to say is, if you don’t tell them you are unhappy with the pay review how are they going to know. Don’t be rude and start sulking/shouting but just state you are unhappy, say why you are unhappy and the reasons for that. I think it would probably help your cause to maybe get some industry averages to back up your case, perhaps ask if you could have your wage validated (unless you think you are being over paid of course).

If all else fails ask if you can earn a pay rise by reaching a target of some kind or becoming qualified/certified.
Responsability

This is a good way of becoming more important, gaining more skills, showing you want to progress (you’re a company man). If your job is going now where try and get more responsibility by suggesting to your boss a new project and some time to do it. This suggestion is something to do if you are eager to move your career on and not if you want an easy life because it will be a case of giving yourself more work and responsibility.
Summary

In the end if you aren’t happy with your pay review then start looking for another job, vote with your feet. Quite a few people who have been in a job a long time seem to develop the fear over moving jobs but I would say that if you work hard and are good at your job, what have you got to fear. You will probably get more money if you move (but money isn’t everything of course) and changing jobs can be positive in many ways, a new challenge. There is also the possibility that if you are as good as you think you are they could always match the wages of your new role.

This blog has been a bit of brain dump today but what I think I am trying to say (using lots of words) is that don’t get your hopes up, pay reviews/yearly reviews are often a bit of an anti climax but if you want to get the most out of them you have to be pro active and put some effort in to try and get the results from it you want. Don’t sit there and let your boss do all the talking, get in there and get what you can, the worse than can do is say no and at least you know you tried.

What is Duck Typing and What does Cedric Beust have to do with it

Whilst searching for a bit of blurb about Cedric Beust as he was one of the authors of a Java 5 Features article I typed his name into wikipedia and he had an entry on explaining what Duck Typing is. I have often heard of Duck typing and often wondered what exactly it was.

So I thought I would pass on the knowledge, wikipedia has this as a definition of Duck Typing

In computer science, duck typing is a term for dynamic typing typical of some programming languages, such as Smalltalk, where a variable's value itself determines what the variable can do. It also implies that an object is interchangeable with any other object that implements the same interface, regardless of whether the objects have a related inheritance hierarchy.

Dave Thomas, in the Ruby community, initially used the term in the context of dynamic typing.[citation needed] His premise could be explained by the folklore saying, "If it walks like a duck and quacks like a duck, it must be a duck." One can also say that the duck typing method ducks the issue of typing variables.

I have to be honest on the first pass of that explanation I still felt a bit confused. The way I understand it, it seems that it means that you don't need to add the type to the class, the compiler just works it out at runtime (e.g. "If it walks like a duck and quacks like a duck, it must be a duck"). I think I heard Cedric talking about this on a JavaPosse podcast. There are links on the wikipedia page for duck typing on Dynamic Typing. I'm afraid I am to lazy to read that page as it was rather long.

I think I have also heard that the newer languages like Ruby implement Duck typing, so hopefully in the future Java will Cherry pick that functionality and put it into Java.

So how does Duck typing fit into Java Currently, well Wikipedia has a link to this article

Java Does Duck Typing

This article has the description of Duck Typing as

Duck Typing is a powerful feature included primarily in newer languages. It provides the following capability: An object having all the methods described in an interface can be made to implement that interface dynamically at runtime, even if the object’s class does not include the interface in its implements clause.

So now my understanding of Duck Typing is, it is dynamically implementing an interface at runtime even if the class doesn't implement the interface at design (compile) time.

I'm not sure if I really understand what Duck Typing is or if I understand what it is but don't understand how/why you would want to use it.

if anyone would like to post a comment/link to what Duck Typing is and why it is useful then please do, I would greatly appreciate it.

There is one final thing to be cleared up here, What has Cedric Beust got to do with Ducks and their Typing. Well he has a blog entry linked to it on Wikipedia warning users about the perils of Duck Typing in Python

reading this article mentions the dangers of Duck Typing and that objects, it has this quote

the verification that the object does respond to such methods is not made when the object is passed as a parameter to the method, but on the invocation of the said methods, which explains why parameters to methods are usually not typed all

So Duck Typing sounds like it means the verification of an object is based on the methods, so you can pass any object as a parameter as long as it implemented a certain method. Which means many objects could be used in methods but without having to actually implement the interface on all of them. It sounds like Duck Typing takes away the need to implement interfaces on your objects but thenwhat'ss the harm in implementing an interface, apart from the effort of typing the line which says implements, especially if the class has the method.

well if I ever understand Duck Typing I will be sure to blog down the answer, I hope reading this has been a waste of your time because some one will hopefully write what Duck Typing is as a comment ;-)

Sunday, April 23, 2006

Java 5 feature articles

I found an two articles summarising the new features in Java 1.5. This is decent document and it briefly explains what they all are and what they do. It's a very good introduction to the Java 5 features and are probably useful for people who are just about to start learning for their SCJP 5 Exam (CX-310-055) This list of the topics is of the information in the articles

Enhanced for loop
Annotations
Static imports
Variable-length arguments
Enums
Generics
Autoboxing

With the exception of Generics all the new features make programming in Java easier and I think there are some really good features. You wonder why they didn't add them in before.

I really like the Enhanced for Loop, it makes looping through collections much easier and for most scenerios brings about the death of the irerator.

Static imports are a bit of a wierd one, I don't think I have ever really written a class where I used a lot of Static classes, to the extent I wished I could import a class to save me typing its name. I actually think its a bit confusing for people looking at code with static imports because it's not obvious you are calling a method on a static class. I'm not a big fan of this one.

Variable-Length arguements (var args) I like this, the ability to have a number of variables of the same type.

http://www.theserverside.com/blogs/showblog.tss?id=JDK5Practice


The second article is written by Joshua Bloch and Neal Gafter
http://www.theserverside.com/blogs/showblog.tss?id=JDK15

I think the first article was written by Cedric Beust and Cedric is the creator
of TestNG, which is something on my to look at list

Saturday, April 22, 2006

GetBlogs can get out

I submitted my blog to GetBlogs but the cheeky b*%$($£ refused to list my blog, with an email below

"We regret to inform you that at the current time, we have decided not to include your listing in our directory."


How did they know my blog was rubbish I thought, who had told them, damn I knew I shouldn't have told my girl friend (it took me about 3 hours to explain what a blog is) who then told my Mum, who then told every in the family and anyone else who will listen. All I told them was don't bother reading any of it, you will find it boring, just click on the adverts ;-)

Anyway I thought I would see what blogs they had listed on there, hoping to be impressed by the quality that my blog wouldn't be worthy to shine its boots. Onto thesoftwaree and Technology section and the first blog is this

Ben Tinney - A Whole Lotta Nothing
A discussion about computers (particularly, but not exclusively related to interesting web sites, software, visual Basic, C+, and NQC), plus other bits about lego mindstorms, and life in general....

My initial bitter thought (still feeling hurt about the rejection) was that sounds rubbish, LEGO MINDSTORMS, obviously my blog can't hit these high hights. In the name of research I thought I would have a look at the site

The current blog entry is this

Longhorn Transformation Pack

Want to change the looks of your Windows XP and make it look like the upcoming Microsoft Longhorn?


Why the hell would anyone want to do that!

I left the blog at this point, although I have become a little bit fond of it now and I mustn't forget thatit isn'tt Ben Tinney I'm having a rant about. I looked at a few more blog entries and some a interesting (ish). Ben Tinney does make you think, like his entry on

Get the worlds longest email

He starts the entry by saying "this is the funniest and longest email address I have ever seen" and then shows examples of the address being to long to add in many web forms. Excellent stuff. He does have aninterestingg entry on titled "An Evening with Google", I'm being serious now. Giving me this fact

"The infamous "I feel lucky" is nearly never used. However, in trials it was found that removing it would somehow reduce the Google experience. Users wanted it kept. It was a comfort button."

Anyway I recommend you check his blog out. Back to GetBlogs, I typed in Java to search on and most of the top ten results were about JavaScript and then the first Java blog I clicked on took me to a link that wasn't working.

So GetBlogs it's your loss, I wouldn't join your blog directory if you paid me, okay I would join if you paid me but that's very unlikely but just to let you know, not that they are listening but I wouldn't join your blog directory if you got down on your blog directory knees and begged me.


Friday, April 21, 2006

Why is Netbeans called Netbeans

The blog entry explains why NetBeans is called NetBeans
 
I have decided to start a "why is" section of my blog. I think I will expand it above the brief explanation to a bit of research about the topic (usually an IDE or a piece of software)
 
It took me a while to find out what how NetBeans got its name and in the end I had to read the history but which was actually quite interesting because it seemed a long journey to success.
 
To summarise (taken from the History of NetBeans link below)
 
 NetBeans started as a student project (the two founders Jan (Ian) Formánek, Jaroslav (Yarda) Tulach) in the Czech Republic (originally called Xelfi), in 1996. The goal was to write a Delphi-like Java IDE in Java. Xelfi was the first Java IDE (Integrated Development Environment) written in Java, with its first pre-releases in 1997.  Not only was Xelfi the first IDE for Java, it was the first IDE written in Java, Xelfi as shareware on the web for $20 per license.  Then a local businessman Roman Stanek invested some money into the project and they became a company.
 
THE NAME BIT
 
The original plan for the business was to develop network-enabled JavaBeans components. Jarda Tulach, who designed the IDE's basic architecture, came up with the name NetBeans to describe what they would do. The IDE would be the way to deliver them - and that's where the name NetBeans comes from. When the spec for Enterprise Java Beans came out, it made more sense to work with the standard for such components than to compete with it - but the name stuck.
 
Then in 1999 Sun brought them and NetBeans became the flag ship tool set of Java.  Finally in June 2000 they decided to make NetBeans Sun's first sponsored open source project
 
If you are interested in reading about the history of NetBeans it's not that long an article and it is quite interesting (as far as history's of computer firms go)
 

free Hibernate sample chapters

I have chosen to implement hibernate in my current project I am working on so I have found some free sample chapters to help me on my way.
 
If you haven't used hibernate I would recommend going thought the reference documentation supplied with hibernate as this gives you an easy tutorial to follow and gives you code which you can build on.  The sample chapters tend to look at things in a bit more detail, which might help you if you are going to be using hibernate to do more than standard database work.
 
I also found almost a books worth of sample chapters on hibernate
 
The first couple of sample chapters come from
 
 
this first chapter is going through a hello world example, it is titled

Introducing and integrating Hibernate

 
I haven't read the second sample chapter

Advanced mapping concepts

 
there is also this book
 
 
 
 
 
Finally
 

Thursday, April 20, 2006

Java Tips

I stumbled upon this Java tips site yesterday and found some interesting tips, which were explained in great detail. So in the name of self improvement it’s worth checking out the Java Tips site.

it has a lot of Java tips but it also has some tips on other API's and I found the Ant one quite useful - ant tips

I wish I had seen the JDBC tips the other day as I was searching about trying to find out how to connect to an sql server database - JDBC tips

The website is quite useful but there are some simple tips like What is a constructor which has been read 353 times !!

I don't know if its criticism or just my opinion but I actually found the site quite hard to navigate in terms of finding useful tips. The tips are split into quite big sections like Java SE, Java ME, Java Applications, Java Libraries. These are then split into smaller sections but in the end you have to spend your time looking about to find a good tip. I just felt it wasn't very initiative.

On the positive side there is a lot of tips here and the tips that I looked at where well written and are certainly through, it will just take you a bit of time to hunt down that killer tip.

so for the people who are studying for the SCJP Java 5 certification then these will certainly help you, especially if you aren't sure about the new features.

How to use getenv() in Java SE 5.0
Introduction to Autoboxing
Using the VarArgs Language Feature
The Enhanced For Loop
Covariant Parameter Types

I hope you find these useful

How long do you stay a programmer

I wondered today if you become bored of programming, the everyday cut and thrust of programming problems. I personally don't believe you become bored of programming but I think at some point you want to earn more money and this means becoming a manager of programmers.

before you ask I am not in this position but I know a few people who are/were.

One of them who left where I work said, I don't want to be a code monkey for ever.

now apart from his elegant phrase of code monkey it did bring an interesting question to the forefront. It's funny but what age do you want to stop being a code monkey. It is a very interesting question because

1. I hadn't ever thought that far ahead
2. I hadn't thought about not being a code monkey
3. What does being a manager involve (handling moaning software developers!!!!)
4. Will I have to move job

The bloke who said he didn't want to be a code monkey soon left where I worked to be a "code monkey". I never thought there was really an age where you weren't a code monkey, it's not as if your body becomes weaker so you can't compete.

on the other hand I also appreciated that I would like to be a manager, I'm sure it's a dream/fantasy we all have, in our offices with a nice black comfy chair swinging about pretending to work until some young grunt pops in and we send him on his way with an ear full of good advice.

It's just I had never thought of it in the way "I don't want to be a code monkey for ever".

The main problem I have with the above statement is that most of the managers I know spend half of their life in meetings and planning other peoples work which really isn't something I aspire to do. What kind of job satisfaction do you get from that.

perhaps one day it will appeal to me but at the moment I'm happy to stay a code monkey

Wednesday, April 19, 2006

Questions and Solutions using Generics, foreach and Enumerations

The link is to a free chapter from the Java Cookbook and is a chapter called - Data Structuring with Generics, foreach and Enumerations. The chapter is set out in an interesting way because it is split up into a number of questions and solutions and then discusses things to look out for.

8.1 Using Generic Collections
8.2 Using foreach Loops
8.3 Avoid Casting by Using Generics
8.4 Let Java Convert with AutoBoxing
and AutoUnboxing
8.5 Using Typesafe Enumerations
8.6 Program: MediaInvoicer

Each the sections above are split into three parts

problem
solution
discussion

so the chapter is a good introduction to problems but it also shows you how to actually use the new functionality rather than just know enough about the new Java 5 features to pass the SCJP 5 exam, which means it useful for people who aren't doing the exam as well.

For people who read this blog often you will know my fondness for free chapters, especially for topics that are going to appear on the Sun Certified Java Programmer Exam for JDK 1.5

The chapter talks about Generic collections, which is probably the main area Generics are going to be used because Generics are mainly added to bring in type safe collections and the ability to create collections which can only hold a certain object and will complain (throw an error) if you try to put in a different object.

It also talks about the Foreach/ for-each loop which is such an easy win. It is one of those pieces of functionality which you just wonder why it wasn't added before. It removes the need for iterators but allowing you to just loop though all the items in a collection. Anyway I will get off my high horse and stop ranting on about that.

Autoboxing is a bit wierd but in a good way. It allows you to use Java's wrapper classes (Integer etc) but with Java primitive variables which means you don't have to do needless casting. It does feel like a few of the features added into Java 5, a bit of a hack. This is so the code is backwarcompatiblele but it certainly does feel they have added it onto the code they already had, especially with the angled brackets and in particular the placing of the generic types.

here is the link, enjoy

http://www.oreilly.com/catalog/0596007019/chapter/ch08.pdf

Tuesday, April 18, 2006

What is the Average Java Salary in the UK

I was wondering what the average wage for a java developer is in the uk. I found a couple of links. Also take into account that I searched for permanent positions and not contracting positions

below are the average salaries for a Java developer on the computer Weekly site

which allows you to type in your location (West Midlands, UK),

Average salaries for Programmers, Programmer in Software Houses/Consultancies, West Midlands are:

  • Salary for industry:£25999pa
  • Salary for industry within region:£25500pa
Senior developers get a bit more
  • Salary for industry:£35466pa
  • Salary for industry within region:£35466pa
This feature is based on information from Salary Services Ltd (SSL) in conjunction with Computer Weekly.

This is from from the website cw jobs website I think these jobs must take also take into account contracting rates and maybe they are more london based. Still I would like to be that Java wage

Job role Average minimum for UK Average maximum for UK sample size

.NET £41,482.10
£46,169.86
44986
Show me these jobs
ACCESS £36,037.47
£40,272.37
9880
Show me these jobs
AIX £39,481.76
£44,129.68
2033
Show me these jobs
AS/400 £34,757.68
£38,775.09
915
Show me these jobs
ASP £38,014.31
£42,534.77
27075
Show me these jobs
C, C+, C++, C# £44,256.12
£49,113.92
56839
Show me these jobs
CISCO £40,673.23
£45,230.30
10434
Show me these jobs
CITRIX £34,861.54
£39,205.60
4303
Show me these jobs
CRM £46,003.36
£50,985.93
7789
Show me these jobs
CRYSTAL REPORTS £32,312.61
£36,455.08
2649
Show me these jobs
DELPHI £35,773.46
£40,193.76
3586
Show me these jobs
EJB £45,236.64
£50,233.81
4417
Show me these jobs
EMBEDDED £38,049.09
£42,783.28
8471
Show me these jobs
ERP £42,843.93
£47,903.70
2947
Show me these jobs
EXCHANGE £37,534.88
£41,712.81
11972
Show me these jobs
FIREWALL £39,678.55
£44,247.06
1986
Show me these jobs
FOCUS £44,897.57
£49,842.93
10584
Show me these jobs
GUI £39,035.52
£43,783.34
5096
Show me these jobs
HTML £34,439.20
£38,720.37
15427
Show me these jobs
IIS £35,920.56
£40,293.14
5101
Show me these jobs
JAVA £45,371.58
£50,318.32
32118
Show me these jobs
JSCRIPT £34,468.48
£38,786.08
9884
Show me these jobs
JSP £42,911.91
£47,835.61
5907
Show me these jobs
LAN £38,750.12
£43,216.60
5215
Show me these jobs
LINUX £39,415.76
£44,003.39
12880
Show me these jobs
LOTUS PRODUCTS £32,114.15
£35,993.77
1794
Show me these jobs
NOVELL £30,924.59
£34,745.66
1136
Show me these jobs
OBJECT ORIENTED £45,558.73
£50,515.85
14964
Show me these jobs
OFFICE £45,232.37
£49,901.11
30482
Show me these jobs
ORACLE £42,972.13
£47,785.19
36643
Show me these jobs
PERL £44,393.37
£49,279.79
6111
Show me these jobs
PRINCE £46,720.79
£51,742.31
7180
Show me these jobs
RDBMS £46,072.25
£50,936.14
8159
Show me these jobs
SAP £51,099.11
£56,505.96
7410
Show me these jobs
SAS £37,934.75
£42,499.69
21374
Show me these jobs
SOLARIS £43,867.82
£48,671.41
6464
Show me these jobs
SQL £39,048.26
£43,560.63
75233
Show me these jobs
SYBASE £53,271.37
£58,479.19
6248
Show me these jobs
TCP/IP £36,269.83
£40,474.87
9099
Show me these jobs
UML £44,731.05
£49,644.12
13535
Show me these jobs
UNIX £43,621.79
£48,372.26
28044
Show me these jobs
VBA £48,390.87
£53,058.42
4236
Show me these jobs
VISUAL BASIC £38,919.34
£43,395.05
27023
Show me these jobs
WAN £39,572.90
£44,018.94
5415
Show me these jobs
WINDOWS 2000 £32,593.86
£36,460.23
10575
Show me these jobs
Windows 2003 £33,001.48
£36,933.28
2966
Show me these jobs
WINDOWS NT £32,810.00
£36,663.37
3175
Show me these jobs
XML £40,790.42
£45,505.54
24741
Show me these jobs