Final keyword in Java
The Final keyword is used in Java on an entity that cannot be changed.
Here are a few different contexts in which final can be used:
Meaning: A final class cannot be subclassed. Advantage: Security or efficiency. Example: java.util.System
Meaning: The method cannot be overridden in a subclass. Advantage: Preventing unexpected behavior crucial to the functionality of the class.
Meaning: The variable is immutable, meaning once assigned, it cannot be reassigned. This is different from constant keyword since constant should be known at compile time and final need not be. Advantage: Optimization.
Posted at 11:06AM Mar 04, 2008 by Manveen Kaur in General | Comments[0]
This leap year: hop to it!
Today is what makes this year a leap year!
Posted at 01:58PM Feb 29, 2008 by Manveen Kaur in General | Comments[0]
JPA Query with wildcards
Here is a short tip on using LIKE expression with JPA .
What we are trying to do is get all the items that matches a pattern anywhere in their name.
In simple SQL, what I want to do is:
SELECT userName FROM Profile p WHERE p.userName LIKE %pattern%;
I'm using annotations to create a named query.
@NamedQuery(name="Profile.getUsernameWithPattern", query="SELECT p FROM Profile p WHERE p.userName LIKE ?1 ORDER BY p.userName ASC")
(This will even sort the result!!)
Here's the code that demonstrates using this query:
Query query = strategy.getNamedQuery("Profile.getUsernameWithPattern");
query.setParameter(1, "%" + pattern + "%");
query.getResultList();
Hope you found this tip helpful!
Posted at 11:01AM Feb 26, 2008 by Manveen Kaur in General | Comments[0]
Localizing field labels in struts 2
A short tip about localizing field labels in your jsp page in struts 2. First off, the message should be present in the message resource bundle. Now how do you read it into the field label?
Here's how:
<s:password label="%{getText('password')}" name="password" />
How does this work?
The framework takes care of this.
In the text filed, the expression %{getText('password')} tells the framework to lookup "password" in the message resources.
Posted at 11:34AM Feb 25, 2008 by Manveen Kaur in General | Comments[0]
On code monkeys and project schedules
On project scheduling ...
and deliverables ...
and implementation ...
Posted at 03:08PM Feb 20, 2008 by Manveen Kaur in General | Comments[0]