One problem you often see when dealing with UML is that some developers don’t get the idea that what you see in class diagram should translate directly into code they draw a class diagram and write some code and neither bare any resemblance to each other. This, and other blog forthcoming blogs in the series, demonstrate the link between diagrams and code.
Java tips, observations, bugs and problems from the world of Spring, Weblogic, Oracle, MySQL and many other technologies...
Thursday, 31 March 2011
Wednesday, 30 March 2011
Comparison of POJB Construction Patterns
There are a number of ways that you can create a Plain Old Java Bean each with their own quirks, benefits and problems, so which is best? The most useful? The safest? The table below compares several POJB construction techniques highlighting the benefits and problems of each one. Just in case you’re wondering, my favourite happens to be the ‘Builder Pattern’ as described in Effective Java by Joshua Bloch, second edition...
Tuesday, 29 March 2011
SQL*Plus Reminder
This is a reminder of all those Oracle SQL*Plus commands that you and I should know.
1. Saving SQL to a file:
Save filename[.ext] [cre[ate]]|[replace]|[append]
Default ext is SQL.
2. Running a SQL script without loading first:
Start filename
Or on the command line:
Sqlplus user/password@database @filename
1. Saving SQL to a file:
Save filename[.ext] [cre[ate]]|[replace]|[append]
Default ext is SQL.
2. Running a SQL script without loading first:
Start filename
Or on the command line:
Sqlplus user/password@database @filename
Monday, 28 March 2011
Oracle Function Based Indexes
Oracle’s function based indexes are a powerful feature that, from experience, is rarely seen or used by Java developers. I guess that this is because if a Java developer has anything to do with SQL at all, then they’ll usually write their SQL, test it and deliver it to the source control system. At that point, the project’s DBA (if there is one and if he has the time) takes a look at the new SQL and does a bit of tuning if necessary. This makes me think that function based indexes are really a ‘DBA thing’. So, for Java programmers, in this blog I’m going to demonstrate function based indexes using a simple EMPLOYEE table, which we’ll first need to create and populate, so bare with me as this is the boring bit.
Sunday, 27 March 2011
SQL Performance - Avoiding Full Table Scans and Other Tips
When and How to Avoid Full Table Scans
You need to avoid full tables scans because they usually slow down the performance of your application. Therefore, you should avoid using them when reading large tables and this can be achieved by judicious use of indexes.
You need to avoid full tables scans because they usually slow down the performance of your application. Therefore, you should avoid using them when reading large tables and this can be achieved by judicious use of indexes.
Saturday, 26 March 2011
Improving SQL Performance Part - 1
Proper Arrangement of Tables in the FROM Clause
The order in of tables specified in a FROM clause may make a difference to database performance. This dependency is based on how the parser reads the SQL statement. Depending upon the parser, some users have found that listing the larger tables in a from clause last proves to be more efficient.
The order in of tables specified in a FROM clause may make a difference to database performance. This dependency is based on how the parser reads the SQL statement. Depending upon the parser, some users have found that listing the larger tables in a from clause last proves to be more efficient.
Friday, 25 March 2011
More SQL Examples
This is a further crib sheet, with lots of SQL examples - well a few any way. It's just a quick of finding things that I don't use very often.
SQL Example Select Statements
SQL Example Select Statements
Thursday, 24 March 2011
SQL Select Clauses Crib Sheet
Adding to yesterday's simple crib-sheet, today's blog is my SQL clauses crib-sheet...
Wednesday, 23 March 2011
Tuesday, 22 March 2011
Collections that support the remove() method
The JSE Collection specification states that the implementation of remove() is optional and that if unimplemented an UnsupportedOperationException is thrown. So, I thought that it would be handy to know which collection classes support remove() and which don’t. Using the following code I get some interesting results...
Labels:
Collections,
Iterator,
Java
Monday, 21 March 2011
Iterator.remove() - a gotcha
The JSE Iterator specification states that the implementation of remove() is optional and that if unimplemented an UnsupportedOperationException is thrown. I suspect that this can, and does, lead to problems as best practice tells us that you should always used a collection interface as opposed to its concrete implementation...
Labels:
Collections,
encapsulation,
Iterator,
Java
Sunday, 20 March 2011
Collections that Support Iterator.remove()
The JSE Iterator specification states that the implementation of remove() is optional and that if unimplemented an UnsupportedOperationException is thrown. I suspect that this can, and does, lead to problems as best practice tells us that you should always used a collection interface as opposed to its concrete implementation...
Labels:
Collections,
Iterator,
Java
Saturday, 19 March 2011
CircularBuffer Unit Tests
Yesterday, I dumped the code for a CircularBuffer into this blog, with the idea being that a circular buffer is a collection class that’s missing from the JSE Collections framework.
Today, I’m adding the JUnit tests for that piece of code, just to prove it works! A few days ago I blogged about a Google Tech Talk given by Misko Hevery,
Today, I’m adding the JUnit tests for that piece of code, just to prove it works! A few days ago I blogged about a Google Tech Talk given by Misko Hevery,
Labels:
Collections,
Iterator,
Java,
JUnit,
Specifications,
Test Driven Development,
Unit Tests
Friday, 18 March 2011
A Circular Buffer
The other day, I came across one of those rare situations where I needed a collection class type that’s not supported by the JSE. I had the need to gather some statistics, and only needed to know the most recent 100 values... the sort of functionality that can easily be supplied by an old fashioned circular buffer.
Labels:
Collections,
Iterator,
Java,
Specifications
Thursday, 17 March 2011
Database Referential Integrity
Database Referential Integrity is something everyone should know. I know I do; it’s like knowing the colour green, it’s something that is obvious, in fact it’s so obvious that I couldn’t explain it the other day when asked. So here is a brief overview and a quick link to the more in-depth wikipedia explanation.
Wednesday, 16 March 2011
Database ACID Acronym
This is something I knew, but like a lot of things forgot... and I got asked but couldn’t remember - although I could remember the theory behind it. There is a really good full description of this on wikipedia, so the table below is just something to jog your memory.
Labels:
ACID,
Database,
Transactions
Tuesday, 15 March 2011
Unit Tests and Specifications
I came across this the other day whilst watching a Google Tech Talk on youtube. The lecturer, Misko Hevery, was talking about writing testable code – something in which I’ve a great interest and, half way through his lecture, he started talking about specifications. At first this seemed to confuse half the audience in that they seemed to assume that the lecturer was talking about artifacts such as Requirements, or Functional Design specifications which were the sort of thing that was usually written in Word before the advent of UML (or Booch / OMT if you’re that old). What he was actually talking about was the formalisation of unit tests using a scenario based naming framework.
Labels:
Java,
Specifications,
Unit Tests
Monday, 14 March 2011
Law of Demeter
The Law of Demeter keeps popping up in various software blogs and writings and I have to hold my hand up and say that I’ve never really understood what it meant. So, this blog corrects all that.
Labels:
Java,
Law of Demeter
Sunday, 13 March 2011
Entity Relationship Diagram Reminder
This little blog is a gentle reminder of the components of a simple entity relationship diagram. As with any ‘little’ example, the entities are involved are somewhat contrived. In this case we have a customer table linked to an address table.
Saturday, 12 March 2011
PL/SQL Implicit Cursor Attributes
Oracle allows you to access information about the most recently executed SQL statement (INSERT, UPDATE, DELETE and MERGE) by referencing one of the following special implicit cursor attributes:
Friday, 11 March 2011
Exception Strategy: Runtime or Checked
Half the battle in trying to build a good application is in designing a coherent way of managing exceptions and dealing with errors. You may think that this is obvious, but I’ve worked on projects where it hasn’t been done and one of the worst side effects of not highlighting errors is to invisibly loose them making your system both buggy and difficult to fix.
Labels:
Exceptions,
Java
Thursday, 10 March 2011
UML: Inheritance and Java
One problem you often see when dealing with UML is that some developers don’t get the idea that what you see in class diagram should translate directly into code they draw a class diagram and write some code and neither bare any resemblance to each other. This, and other blog forthcoming blogs in the series, demonstrate the link between diagrams and code.
Labels:
Inheritance,
Java,
UML
Wednesday, 9 March 2011
UML: Interface Realisation and Java
One problem you often see when dealing with UML is that some developers don’t get the idea that what you see in class diagram should translate directly into code they draw a class diagram and write some code and neither bare any resemblance to each other. This, and other blog forthcoming blogs in the series, demonstrate the link between diagrams and code.
Tuesday, 8 March 2011
UML: A Class with Attributes and Methods and Java
One problem you often see when dealing with UML is that some developers don’t get the idea that what you see in class diagram should translate directly into code they draw a class diagram and write some code and neither bare any resemblance to each other. This, and other forthcoming blogs in the series, demonstrate the link between diagrams and code.
Monday, 7 March 2011
UML, Aggregation and Java
One problem you often see when dealing with UML is that some developers don’t get the idea that what you see in class diagram should translate directly into code they draw a class diagram and write some code and neither bare any resemblance to each other. This, and other blog forthcoming blogs in the series, demonstrate the link between diagrams and code.
Labels:
Aggregation,
Java,
UML
Sunday, 6 March 2011
Refactoring Code - An Example
package refactoring;
/**
* This little tip was inspired by the book "Beginning EJB 3 Application Development" by Kodali
* and Whetherbee published by aPress. The code is the method aVeryBadMethod() tries to
* Initialize a simple wine by country database. However, IT IS JUST PLAINLY WRONG. Were they
* being deliberately stupid? Or just plain lazy? Or just trying to prove a point? I think it's
* appalling that code examples should be this wrong.
*
* This example takes that code and fixes it, but then goes through the possible options for
* making it better, and why you should choose them.
*
*
*/
Labels:
Agile,
EJB,
Enum,
Java,
Refactoring,
Test Driven Development
Saturday, 5 March 2011
Configuring Debugging on a Weblogic Server
One of the useful and really speedy things yon can do is to debug and step through EJB code that is deployed on your Weblogic server as your integration tests are running. Doing this sorts out all kind of problems very quickly. To do this you need to modify your setDomainEnv.cmd file and setup a remote debugger on Eclipse.
Friday, 4 March 2011
SQL Join Optimisation
Java developers are often required to write their own SQL after all, it’s a necessary evil which means that often doesn’t get the thought it requires, which, in turn, can lead to inefficient SQL and slow systems.
Take, for example, a hypothetical scenario whereby you need to select a list of all the employees in you company and the department they’re in. Given that this information is held in two tables: employee and department, you could write some simple SQL that goes:
Take, for example, a hypothetical scenario whereby you need to select a list of all the employees in you company and the department they’re in. Given that this information is held in two tables: employee and department, you could write some simple SQL that goes:
Labels:
Join,
Optimisation,
SQL
Thursday, 3 March 2011
Listing Charactersets
One of the seemingly most neglected areas of coding is the mystic surrounding character sets and I guess that the reason for this is that no-one really cares too much about it. Several European wide systems I’ve worked on did specify a character set, and that was UTF8 and I suspect that this was mainly because it’s a default standard that’s big enough to hold every character for every European language plus lots of others. But, there are lots of character sets, so do we need them all? I guess not, but I think that for historical reasons we’re stuck with them...
Labels:
charset,
environment,
Java
Wednesday, 2 March 2011
Rounding Doubles
One of the problems with doubles is that you can never be sure of the number of decimals places that it will round to. This is an age old problem and in the bad old days, you had to do all the rounding yourself, which often lead to rounding errors. The usual way of attacking the problem was to write a rounding method based on the use of scaling:
Labels:
Java
Tuesday, 1 March 2011
Installing MySQL on Solaris (Part 4 - Initializing the Database)
Once you've installed MySQL, the next step is to create your database and get the whole thing running. To do this:
1. Change the operating user from root to mysql by typing:
1. Change the operating user from root to mysql by typing:
Labels:
Database,
Installation,
MySQL
Subscribe to:
Posts (Atom)