Friday, 17 June 2011

Problem with preferredMapping in Spring roo

I wish to present next error I have faced during using roo as a development tool.

In command controller class I used attribute --preferredMapping createSimple
So attribute consist capital letter, it cannot have as a value with capital letter.

In generated controller mappings on controller and to view names was not correct. In html it was generated lower case, but in mapping was with a capital ones. I have to fix them by had for it running.

Monday, 13 June 2011

Problem with roo + gwt

I have upgraded Spring roo to the version 1.1.4

It ended with the problem using gwt web frontend, with an error:

GWT module's gwt.xml file not found; cannot continue

I have found the cause: https://jira.springsource.org/browse/ROO-2445

So in Spring roo ver. 1.1.4 generating gwt web is not working

Friday, 10 June 2011

Referer

We do use HTTP Headers in coding web pages for the information from the browser client use.
f.e. I used Referer header to know which from which page new request comes.

I have discovered that it is not always true. On Firefox it was, but on Chrome and IE when the link was clicked in the Flash object Referer was set to the address of that flash object.

So be careful, Referer can be
- url of the page on which link was clicked,
- url for the flash object on which link was clicked.

Wednesday, 16 March 2011

Principles of object-oriented design

SOLID - five simple principles of object-oriented design
introduced by Robert C. Martin

- Single responsibility principle (S) - that an object should have only a single responsibility
- Open/closed principle (O) - “software entities … should be open for extension, but closed for modification
- Liskov substitution principle (L) - objects in a program should be replaceable with instances of their subtypes without altering the correctness of that program
- Interface separation (I) - many client specific interfaces are better than one general purpose interface.
Dependency inversion principle (D) - Depend upon Abstractions. Do not depend upon concretions.

Saturday, 10 May 2008

Java Puzzlers by Bloch & Gafter

Summary of most important things in this book:

  • To escape characters in regular expression use Pattern.quote("."). To change replacement string Matcher.quaoteReplacement(String).
  • In java are statemant labels
  • Special values:
Double.NaN
Double.POSITIVE_INFINITY
  • Be careful:
Integer.MIN_VALUE = -Integer.MIN_VALUE
Long.MIN_VALUE = - Long.MIN_VALUE
  • Java exception checking is not enforced be the virtual machine
  • Class.newInstance can throw checked exceptions that it does not declare
  • Generic type information is checked at compile time not at runtime.
  • When a program calls a static method, the method to be invoked is selected at compile-time, based on compile-time type of a qualifier
  • Static methods annnot be overridden, they can only be hidden
  • Never call overridable methods from constuctors
  • AtomicLong - object with implementation for synchonisation
  • You must override hashcode() whenever you override equals
  • Integer literals begining with 0 are in interpreted as octal values
  • Math.abs is not guaranteed to return nonnegative result. For Integer MIN_VALUE and for Long MIN_VALUE it does not
  • Methods in object are overwritten and fields are only hidden but can be other types.
  • It is possible to hide variables, nested types and static methods.
  • A package-private method cannot be directly overridden by a method in a different package
  • Thread.join calls Object.wait on the Thread instance representing the Thread being joined. This releases the lock for the duration of the wait
  • You cannot legally access a member of a nonpublic type from an other package
  • The constructor of a non-static nested class is compiled such that it has as its first parameter an additional implicid parameter representing the immediately enclosing instance. So avoid using reflection to instantiate inner classes
  • PrintStream.write(int) is the only output method that does not flush a PrintStream
  • You must drain the output stream of a child process in order to ensure its termination. The same goes for the error stream.
  • Calling Thread.interrupted always clears the interrupted status of the current thread
  • References to constant fields are resolved at compile time to the constant values they denote.

Wednesday, 6 February 2008

Effective Java by Bloch - Second

  • Immutable object are thread-safe without need of synchronization
  • Using immutable objects is costly if we change it frequently because every time new object is created. So think about using StringBuffer over String and BitSet over BigInteger
  • Immutable classes are recommended to be final or methods to be final, what allow changes in new releases.
  • For serialization if any field in immutable object is mutable then you have to provide method readObject or readResolve
  • Think it over whether choose composition pattern or inheritance
  • Documentation of methods to be overriiden in subclass should have comment staring with: This implementation ... It should describe hot it uses other methods and how their overriding would affect results.
  • Constructors must not involve overridden methods through constructors sequence called.
  • Neither clone nor readObject may invoke overridden methods directly or indirectly.
  • To eliminate different usage of method in class and subclass you can use private helper methods and prepare methods to be overrridden to use this helper method.
  • Common usage of an anonymous class is to create object such as a Thread, Runnable, TimerTask
  • Decision which overloaded method is chosen is made on compile-time. (not runtime)
  • Overriding methods is made on run-time.
  • For money calculation use BigDecimal, int or long
  • Rather use standard exceptions like IllegalArgumentException, IllegalStateException, NullPointerException, IndexOutOfBoundsException, ConcurrentModificationException, UnsupportedOperationException, ArithmeticExceptioln, NumberFormatException.
  • Primitive variables long and double are not written or read atomically.
  • Volatile attribute on variable guarantees that any thread will see the most recently written value
  • Static fields in private static classes are initialized on first use
  • Never invoke wait outside a loop.

Wednesday, 19 December 2007

Effective Java by Bloch - First

Splendid book about pure java coding about common errors as well as good developer java templates.

I tried to summary it:

- To enforce object to be singleton do private constructor and write static method getInstance. Such objects to be serialized has to have method readResolve() declared.
- If class is not to be instantiated as well as it's subclasses do private constructor. It will prevent this things. To make instance of class it have to has possibility to call superclass constructor
- Avoid creating duplicate objects
- Eliminate obsolete object references. If references are in array and are not longer needed so do not forget to null them out.
- Avoid finalizers. Where are run be garbage collector and can have on other VM other specification f.e. very low priority. Make sure your finalizer call superclass one. It is good practice to use in class private anonymous class do things to do making sure our subclass will call it on garbage collection even if finalizer method was overridden.
- Be careful with equals method for class and it's subclasses, f.e. mixing usage Timestamp and Date in same collection can give strange errors, while first extends second, and equals method is not transitive!
- Compare values: float by Float.floatToIntBits, double Double.doubleToLongBits
- when you override equals you should also override hashCode method so equal objects return same value. It is needed for hash Collections to work as thought to be. Best to has no hashCode same if values are not equal.
- when you write clone method you should not use final properties in Object
- Cloneable interface is for cloning objects and what we have to do to produce clone of object by calling in our clone method method from superclass super.clone()
- Comparable interface is for allowing sorting objects in java Collections using it's compareTo method. If objects should not be compared then method should throw ClassCastException. Restriction to method is that it has toobey reflexivity, symmetry, transitivity and not-nullity. Objects whose methods compareTo returns 0 should also return true through equals method to have same behavior in sorted an not sorted Collections.