Archive for November, 2008

InteliJ Program

Sunday, November 9th, 2008

Some time ago I agree to take participation in Banner Program. Now I’ve got JetBrains Banner on my sidebar, currently still pointing to ReSharper . I IntelliJ user but some time ago I get ReSharper. I’ve got two account that was merged. Currently I’ve got only one and wait for banner for InteliJ 8.

If you plan to buy IntelliJ Idea or ReSharper fill free to use my customer id (if you want), maybe I get T-shirt or even free IntelliJ personal license. Of course T-shirt is the thing I want the most because JetBrains participate in WJUG give away program, and every presenter gets it own IntelliJ license. Because of that I currently preparing something to get license for IntelliJ 8 :) .

Packages – Java Specification chapter seven

Saturday, November 8th, 2008

Today I cover chapter seven. Java programs are set of packages. Packages prevent name conflicts.

  • Packages has two kind of members the first is subpackage the second one is top level class or interface.
  • In the same package it is forbidden to have two members with the same name. So in package java.lang when we have ref subpackage then we can’t have ref class or interface definition and vice versa.
  • I was very surprised when I read this, so I quote some paragraphs here. It amazed me:

    The packages may be stored in a local file system in simple implementations of the Java platform. Other implementations may use a distributed file system or some form of database to store source and/or binary code.

    Such a database must not impose the optional restriction on compilation unit in file-based implementations. For example, a system that uses a database to store packages may not enforce a maximum of one public class or interface per compilation unit.

  • The simple file strategy just map every package on directory and compilation unit on file. One thing to mention here is what we can do when package or compilation unit has name with character that can not correctly use on file system. As convention java use some character as escape and choose from non valid identifier character. I try to get this situation on my mac but without success.
  • Compilation unit consist from three parts which are optional
    • package declaration
    • import declaration
    • top level type declaration – I can believe in that so I check this and it is true, there can be no class in compilation unit empty compilation unit
  • The keyword package may optionally be preceded by annotation modifiers, annotation must have annotation.Element.Type.PACKAGE otherwise compiltime error occurs.
  • Package annotation is placed in package-info.java file in directory containing the source files for the package. Technically package-info.java can contain the source code for one or more package-private classes.
  • It is recommended that if package-info.java exists than it takes the place of package.html and should contains javadoc for this package.
  • Compilation unit that has no package declaration is part of an unnamed package. Unnamed package cannot have subpackages.
  • Implementation of Java platform must support AT LEAST one unnamed package, and it MAY support more than one. So we should be aware that two classes without package has different access then package to themselves.
  • Single Type Import Declaration import single type by giving its canonical name. Once imported the name can be used without qualification also in parameterized type. If two single type import declaration attempts to import type with the sam name, we get compiletime error unless they are the same.
  • Type Import on Demand allows all accessible types declared in the package to be imported as needed.
  • Type Import on Demand NEVER causes any other declaration to be shadowed (Single Type Import shadows name declared in compilation unit).
  • Static imports are analogous to normal import but they import static members.
  • Each compilation unit import automatically java.lang.*
  • Top Level Type both class and interface can have one of the following access modifiers: protected, private, static. In this case compiletime error “modifier …….. not allowed here
  • We should consider to make package names unique, and one of workaround is use of ClassLoader to isolate packages with the same name.

SpringSource – Developing Rich Web Applications with Spring

Friday, November 7th, 2008

Today I’ve just finished a training from SpringSource about developing Rich Web Developing. Our trainee was Marten Denium. This was very nice training and one day we go with Marten to CK Oberza. It was quite nice time, and we get some information about Spring 3.0, maintenance policy, Spring Tool Suite and of course about how Marten was recruited, how his daily job look like ( with some interesting story)

The training is very nice and if you have occasion to have it, just get it, a bonus added is that when SpringSource will finish certification path so thanks to this you get free voucher. We also get this certificate.

The training consist of SpringMVC topic, WebFlow, Spring-JS, JSF with Spring-Faces, Spring Security and many more. You can read detailed information here.

Also during the training Lukasz asked many questions Marten defended quite nice but form time to time we have right, as Marten said today it was the first time when he has so detailed and refreshing question( usually he has question that he can answer to them “Read the funking manual” :) .

During one of the lab I found bug (thanks to firebug) and rose it in JIRA. Martin added comment which I want to also added after I rose this issue. Nice training, and Marten is OK.

Names – Java Specification chapter six

Tuesday, November 4th, 2008

Today I cover chapter six of Java Specification. The chapter is about names. Names are used to refer to entities in our program. Name can be : (package, class type, interface type, field, method, reference type, type parameter, constructor, exception handler or local variable.

  • Name can be simple (without dot) and qualified (with dot)
  • Every declaration has scope, which means that the ‘name’ is recognized in this scope (simple name).
  • In determining the ‘name’ meaning we use context of the occurrence, and than we know if the name is package, type, variable or method (can use the same name). See example below.
  • Access control can be specified. Access is different concept than scope. Access defines qualified access to the ‘name’
  • Declaration introduce an entity into a program and also may introduce a name. Note that constructor use the name of the class in which they are declared, so it doesn’t introduce a name.
  • Not all identifiers are part of the name. They can be used also as : in declarations, field access expression, method invocation expression, qualified class instance creation, as label in label statement (also break and continue). For example label can have the same name as variable.
  • Scope of declaration is the region of the program when we can refer to entity by simple name.
    • scope of parameter is the entire body of method or constructor
    • scope of local variable in a block is the rest of the block starting with its initializer.
    • scope of local variable declared in for statement includes (initializer, any further declaration to the right, expression and code part and contained statement.
    • scope of a parameter of an exception handler is the entire block associated with catch statement.
  • Declaration may be shadowed by another declaration of the same name. Shadowing is different from hiding and obscuringshadowing example
  • Obscured declaration may occur in context when we cannot refer to a visible type or package via its simple name. A simple example when we have two classes with the same name.
  • No two distinct members of the same package may have the same name, but members of different packages may.
  • Warning: Class or interface may have two or more fields with the same name if they are declared in different interfaces and inherited. See example below.
  • Method is overloaded if the method has signature that is not override equivalent.
  • If the method is abstract than new declaration is said to implement it, otherwise its override it.
  • Interface gets all method signatures from Object (if it don’t declare it), but it can not override final Object methods.
  • Array members are
    • public final field length
    • public method clone, the return type of clone is T[]
    • all members from Object class without clone method.
  • There is a paragraph (6.5) about name meaning, the algorithm of determining this has three steps.
    • context causes a name to fall into one of six categories: ( PackageName, TypeName, ExpressionName, MethodName, PackageOrTypeName or AmbiguousName)
    • name classified as PackageOrTypeName or AmbiguousName is reclassified to be PackageName, TypeName, ExpressionName, MethodName.
    • the resulting category determines the meaning of the name (or compilation time error if the name has no meaning).
  • Algorithm is many pages long and it has nothing interesting for real developers, so I omitted it here.
  • One note is that names may be qualified by type names, but not by types in general so that is not possible to access a class variable through a parameterized type. The same rule applies to methods see example:
  • Accessibility is a static property that can be determined at compile time.
  • Package is always accessible
  • Public class or interface may be accessed by any code.
  • All members of interfaces are implicitly public !!!.
  • Public members are accessible, protected members are accessible then they are accessible for package and outside package only for the implementation of that object., private members are accessible only for the body of the top level class, otherwise we say there is default access which is accessible only from package in which the type is declared.
  • Some tricky examples:

  • FQN means Fully Qualified Name, for primitives it is just the same (eg. for long is “long”) for reference types is name with package (eg for Object it is java.lang.Object).
  • Last paragraph ($6.8) is about convention, but as we know every one has its own the best one.

about me

My name is Sebastian Pietrowski. I've finished Warsaw University as Master degree. I started my journey with Java 1.1 with Thread and JDBC programing in 1998 as I worked for merlin.pl. In 1999 I've passed Java Programer Certificate for Java 1.2, and was solution architect of merlin.pl infrastructure when we was moving from pl/sql to J2EE. It was great performance optimization with 10 times more req/sec than in requirements and 85 times faster as original solution.

Currently I work as Expert Software Development Java at F.Hoffmann-La Roche. The company was founded in 1896 and today, Roche employs over 80.000 people. After work I'm involved in activities related to Scala/Lift, Ruby/Rails/Merb, Python/Django. This is because I try to be pragmatic also I'm focused on application performance and tuning with success in my daily work.

My Yoda's motto: Do, or do not. There is no try.