Anything that interests me finds place here. Software dominates my interests and hence a good part of this blog as well.
Friday, December 31, 2010
Nicest and sweetest days
- L. M. Montgomery through Julie911
One-to-one mapping in Hibernate
Using Shared Primary Key:
Using Foreign Key:
Using Join Table:
Tuesday, December 28, 2010
Thursday, December 09, 2010
You need to keep finding yourself, a little more each day, that real, unlimited you.
You need to keep finding yourself, a little more each day, that real, unlimited Fletcher Seagull. He’s your instructor. You need to understand him and to practice him.
- Richard Bach in “Jonathan Livingston Seagull”
Practice and see ... the good in every one... and to help them see it in themselves
“I don’t understand how you manage to love a mob of birds that just tried to kill you.”
“Oh, Fletch, you don’t love that! You don’t love hatred and evil, of course. You have to practice and see the real gull, the good in every one of them, and to help them see it in themselves. That’s what I mean by love. It’s fun, when you get the knack of it.”
- Richard Bach in “Jonathan Livingston Seagull”
Freedom is the very nature of ... being...whatever stands against that freedom must be set aside, be it ritual or superstition or limitation in any form
Freedom is the very nature of ... being...whatever stands against that freedom must be set aside, be it ritual or superstition or limitation in any form
- Richard Bach in “Jonathan Livingston Seagull”
You have the freedom to be yourself, your true self, here and now, and nothing can stand in your way. It is the Law
You have the freedom to be yourself, your true self, here and now, and nothing can stand in your way. It is the Law
- Richard Bach in “Jonathan Livingston Seagull”
We're free to go where we wish and to be what we are
…Jonathan said the time had come to return to the Flock.
“We’re not ready!... We’re not welcome! We’re Outcast! We can’t force ourselves to go where we’re not welcome, can we?”
“We’re free to go where we wish and to be what we are,” Jonathan answered
Easier to practise high performance than it was to understand the reason behind it.
Jonathan’s students found “it was easier… to practice high performance than it was to understand the reason behind it”.
- Richard Bach in “Jonathan Livingston Seagull”
The gull sees furthest who flies highest
“…Those gulls who you came from are standing on the ground, squawking and fighting among themselves. They’re a thousand miles from heaven …they can’t see their wing tips! Stay here. Help the new gulls here, the ones who are high enough to see what you have to tell them.” Jonathan replied “What If Chiang (the master expert gull) had gone back to his old worlds? Where would you have been today?”
Meaning of flight beyond a way of travel to get a breadcrumb
…Jonathan found himself thinking time and again of the Earth from which he had come. If he had known there just a tenth, just a hundredth, of what he knew here, how much more life would have meant! He stood on the sand and fell to wondering if there was a gull back there who might be struggling to break out of his limits, to see the meaning of flight beyond a way of travel to get a breadcrumb from a rowboat. Perhaps there might even have been one made Outcast for speaking his truth in the face of the Flock. And the more Jonathan practiced his kindness lessons, and the more he worked to know the nature of love, the more he wanted to go back to Earth. For in spite of his lonely past, Jonathan Seagull was born to be a instructor, and his own way of demonstrating love was to give something of truth that he had seen to a gull who asked only a chance to see truth for himself.
Perfection
“It’s strange. The gulls who scorn (to despise) perfection for the sake of travel go nowhere, slowly. Those who put aside travel for the sake of perfection go anywhere, instantly….”
- Richard Bach in “Jonathan Livingston Seagull”
Tuesday, November 23, 2010
Good instincts
Good instincts usually tell you what to do long before your head has figured it out.
- Michael Burke
Friday, November 19, 2010
Letting go and holding on
“All the art of living lies in a fine mingling of letting go and holding on.”
- Henry Ellis through Julie911
I walk in peace
“The mind can go in a thousand directions, but on this beautiful path, I walk in peace. With each step, the wind blows. With each step, a flower blooms.”
- Thich Nhat Hanh through Julie911
Thursday, October 14, 2010
Monday, October 11, 2010
Slow down and enjoy life
“Slow down and enjoy life. It’s not only the scenery you miss by going too fast — you also miss the sense of where you are going and why.”
- Eddie Cantor through Julie911
Thursday, October 07, 2010
Why is patience so important? Because it makes us pay attention.
“Why is patience so important? Because it makes us pay attention.”
- Paulo Coelho through Julie911
Thursday, September 30, 2010
You’re never given a dream without also being given the power to make it true
- Richard Bach through Julie911
How people treat you is their karma; how you react is yours.
“How people treat you is their karma; how you react is yours.”
- Wayne W. Dyer through Julie911
The most significant gifts
“The most significant gifts are the ones most easily overlooked. Small, everyday blessings: woods, health, music, laughter, memories, books, family, friends, second chances, warm fireplaces, and all the footprints scattered throughout our days.”
- Sue Monk Kidd
Losing, in a curious way is winning.
“That’s what learning is, after all; not whether we lose the game, but how we lose and how we’ve changed because of it, and what we take away from it that we never had before, to apply to other games. Losing, in a curious way is winning.”
- “The Bridge Across Forever” by Richard Bach through Julie911
Monday, September 27, 2010
Thursday, September 23, 2010
An introduction to the default maven build lifecycle and the compiler plugin
Download word document file here.
Frequently used mvn targets
Target | Purpose |
compile | generate class files from .java files |
test | Run test cases. If need be compile main and test source (all source in ${base-dir}/src/test/java confirming to **/*Test.java, **/Test*.java **/*TestCase.java and excludes **/Abstract*Test.java and **/Abstract*TestCase.java |
test-compile | Compile only test source and not execute it |
package | Make the jar/war/ear, deploy into target directory |
install | deploy the jar/war/ear (build if necessary) into the local repository (~/.m2/repository) |
clean | Removes target directory |
eclipse:eclipse | Generate eclipse .project files |
Monday, September 13, 2010
Java Generics - Part 4
Wildcards:
Consider the a method that prints all the elements of a collection (pre 1.5 code):
private static void printCollection(Collection objectCollection)
{
for (Object element: objectCollection)
{
System.out.println( element );
}
}
The above code when invoked as follows:
printCollection( Arrays.asList( new String[] {"test", "another test"} ) );
gives the following output:
test
another test
Lets write the same method using generics:
private static void printCollection(Collection<Object> objectCollection)
{
for (Object element: objectCollection)
{
System.out.println( element );
}
}
But now the same invocation ( printCollection( Arrays.asList( new String[] {"test", "another test"} ) ); ) will lead to a compile time error! :
PrintCollection.java:8: printCollection2(java.util.Collection<java.lang.Object>) in PrintCollection cannot be applied to (java.util.List<java.lang.String>)
printCollection2( Arrays.asList( new String[] { "test", "another test" }) );
^
1 error
This is because when the String[] is converted to a List, it returns a List<String>. And a List<String> is not a List<Object> (although String is a Object. Why? Read this)
To resolve this issue, we could use…wildcards as follows:
private static void printCollection2(Collection<?> objectCollection)
{
for (Object element: objectCollection) // compiler error will result for objectCollection.add(anything). Because Collection<?> specifies an unknown element type<terminology>. And the compiler has no way to check the type of “anything” against the unknown type. Null is exception.
{
System.out.println( element );
}
}
Saturday, September 11, 2010
Java Generics - Part 3
List<Student> is NOT a List<Person>.
Isa relationships do not apply for generics. Why? Check the following listing:
1 List<String> nameList = new ArrayList<String>();
2 List<Object> objectList = nameList; // Now objectList is an alias for nameList
3 obecjtList.add( new Student() ); // a Student would have been added to a List<String>
Assuming the above code snippet would compile (it will not), it has introduced a Student object into a List of Strings. This violates one of the very basic reasons for having generics (type checking). So Isa relationships do not work with generics.
BTB, the above code will fail compilation with the following compiler error:
NoIsaInGenerics.java:8: incompatible types
found : java.util.List<java.lang.String>
required: java.util.List<java.lang.Object>
List<Object> objectList = nameList; // Now objectList is an alias for nameList
^
NoIsaInGenerics.java:9: cannot find symbol
symbol : variable obecjtList
location: class NoIsaInGenerics
obecjtList.add( new Student() ); // a Student would have been added to a List<String>
^
2 errors
Java Generics - Part 2
A custom parametrized type:
Consider the following oversimplified DAO interfaces:
public interface StudentDAO
{
Student getStudent( Long studentId );
}
class Student
{
private Long id;
private String name;
// accessors and mutators
}
The above interface is specific for Student. But the same interfaces will hold good for other entities too, like Professor, Course etc... If the interfaces like the above are to be implemented, then there would be a Professor getProfessor( Long professorId ), Course getCourse( Long courseId). This is redundant, violates the DRY (Do not Repeat Yourself) principle. Since there is a getEntity() method is all the cases, the above interface can be written using generics as follows:
public interface DataAccessInterface<T> // 1 Parameterized type 2 T is formal type paramter
{
T getEntity( Long EntityKey ); // 3 T can be used where ordinary types can be used
}
The above DAO interface will be used as follows:
DataAccessInterface<Student> studentDAO; // 4 Student is actual type argument
Now, DataAccessInterface<T> is a parameterized type, T is the name of the formal type paramter. After T has been declared in the interface declaration, it can be used instead of normal types throughout the interface declaration.
When a reference to a parameterized type is declared (at 4 above), the actual type to be passed to the formal types is also specified. At this time, all occurrences of the formal type (T) will be replaced by the actual type (Student).
Saturday, August 28, 2010
The most important part of your life
- Lost
We can't let other people decide who you are
you have to decide that for yourself
-Lost
Sunday, August 22, 2010
Superiority should be such a big burden to carry
Wednesday, August 04, 2010
Java Generics - Part 1
Generics were introduced in JDK 5.0. Generics help write re-usable code without losing type safety. Type safety helps write robust programs. The most common usage of generics is in the collections API.
Prior to generics, a Collection could theoretically hold values of various types. Like so:
import java.util.Collection;
import java.util.LinkedList;
class Generics1
{
public static void main(String[] args)
{
Collection nameList = new LinkedList();
nameList.add( new Integer(0) ); // 1 Integer added to collection
nameList.add( "test" ); // 2 String added to collection
System.out.println( nameList );
}
}
Compiling the above code with JDK 5.0 and above will result in a “warning”. But the class file does get generated. Like so:
$ javac Generics1.java
Note: Generics1.java uses unchecked or unsafe operations.
Note: Recompile with -Xlint:unchecked for details.
Running the class file does give the following output:
$ java Generics1
[0, test]
But now we have a Collection with a Integer and a String. Its highly un-likely that a programmer would expect to see a Integer in a nameList.
To enforce type safety that the nameList can only hold String instances, change the declaration of nameList like so:
import java.util.Collection;
import java.util.LinkedList;
class Generics1
{
public static void main(String[] args)
{
Collection<String> nameList = new LinkedList<String>();
nameList.add( new Integer(0) ); // Violation (Integer added to String collection) caught by compiler.
nameList.add( "test" );
System.out.println( nameList );
}
}
Now, the compiler checks each operation on the Collection and ensures that only Strings find place in the Collection (type correctness). Compilation fails if there are violations (like above):
$ javac Generics1.java
Generics1.java:8: add(java.lang.String) in java.util.Collection<java.lang.String> cannot be applied to (java.lang.Integer)
nameList.add( new Integer(0) );
^
1 error
Since all Collection elements are held as java.lang.Object in a non-generic Collection, all fetches must be cast to the appropriate type. Failing to do so will result in a compilation failure. Like so:
import java.util.List;
import java.util.LinkedList;
class Generics1
{
public static void main(String[] args)
{
List nameList = new LinkedList();
nameList.add( "test" );
String firstName = nameList.get(0);
System.out.println( firstName );
}
}
$ javac Generics1.java
Generics1.java:9: incompatible types
found : java.lang.Object
required: java.lang.String
String firstName = nameList.get(0);
^
Note: Generics1.java uses unchecked or unsafe operations.
Note: Recompile with -Xlint:unchecked for details.
1 error
This issue can be resolved by explicitly casting the assignment or typing the collection with generics like so:
List<String> nameList = new LinkedList<String>();
$ java Generics1
Test
In the above case, List is a generic interface with a type parameter.
Thursday, July 22, 2010
A friend who cares
“When we honestly ask ourselves which person in our lives mean the most to us, we often find that it is those who, instead of giving advice, solutions, or cures, have chosen rather to share our pain and touch our wounds with a warm and tender hand. The friend who can be silent with us in a moment of despair or confusion, who can stay with us in an hour of grief and bereavement, who can tolerate not knowing, not curing, not healing and face with us the reality of our powerlessness, that is a friend who cares.”
- Henri J.M. Nouwen
Friday, July 09, 2010
JSF request processing lifecycle in brief
1. Restore View Phase: For a new/fresh request, this phase creates a component tree starting with the UIViewRoot. For a post back request (a request from a previously generated JSF response), the component tree is restored (when state saving method is client, the tree is de-serialized from the request. When state saving method is server, the tree is restored from the server’s cache).
2. Apply Request Values Phase: The values held in the request are fetched and set on the appropriate components. At the end of this phase, the component tree has all the value submitted in the request. The server invokes processDecodes() on UIViewRoot and that call trickles down the entire tree invoking the decode() method on each component. ValueHolder and EditableValueHolder components update the component values and AcionSource components queue an ActionEvent for processing in further phases. If immediate attribute is “true”, validation happens at this phase.
3. Process Validation Phase: All component in the tree convert and validate their values (that was set in step 2). The server invokes processValidators() on the UIViewRoot (and that in-turn recursively invokes processValidators() on each component). Each component’s processValidators() invokes the converter and validators associated with the component. If a component fails conversion or validation, its valid property is set to false and a FacesMessage is queued (and rendered in render response phase).
4. Update Model Values Phase: The backing beans are updated with validated values in the component tree. The server invokes processUpdates() on UIViewRoot which invokes processUpdates() on each component. The processUpdates() method of UIInput types will invoke updateModel() which will update the backing bean.
5. Invoke Application Phase: Any action method or actionListener methods are invoked in this phase. In phase 2 these components would have queued an ActionEvent. The server invokes the processApplication() on UIViewRoot. This method will invoke the broadcast() method on each ActionSource in the component tree for each queued ActionEvent.
6. Render Response Phase: The encodeXX() method on each component is invoked. Each method uses its renderer to generate response and persist the component state so that it can restored in a future request.
Wednesday, July 07, 2010
ui:debug to inspect JSF component tree and UI state
On several occasions, it would be handy to view the component tree and view state.
The <ui:debug..> makes this possible. Using the plain tag with no attributes specified is the most simplest usage:
<ui:debug />
To view the The component tree, load the page holding this tag and press Ctrl+shift+d. This should bring up a new window. But Ctrl+shift+d happens to be a browser shortcut for “Organize bookmarks” in Firefox and the “Bookmark Manager” in Google Chrome. So we need to change the default hotkey which is done as follows:
<ui:debug rendered="true" hotkey="o"/>
Now reload the page and press Ctrl+shift+o. Now a new window opens with the “Component Tree” and “Scoped Variables”.
1. The component tree gives a inundated lists all UI components starting with UIViewRoot.
2. The scoped variables lists various beans in various scopes (e.g. Request Parameters, View Attributes, Request Attributes, Session Attributes, Application Attributes)
The rendered attribute can be used to turn off this feature in production.
Tuesday, July 06, 2010
String.split() trivia
The String.split() method converts a given string to an array based on a regular expression.
Examples:
System.out.println( Arrays.toString( "0:1::::".split( "[:]" ) ) ); // Output: [0, 1]
System.out.println( Arrays.toString( "::::4:5".split( "[:]" ) ) ); // Output: [, , , , 4, 5]
System.out.println( Arrays.toString( "0:1::::".split( "[:]", -1 ) ) ); // Output: [0, 1, , , , ]
As the documentation notes, “blah”.split(“:”) is the same as “blah”.split(“:”, 0) which does not include trailing empty strings.
Tuesday, June 29, 2010
Internet connection speeds
Internet connectivity technologies – fastest to slowest
1. Fiber optics
2. Cable
3. DSL
4. Dish
5. Dial-up
Friday, June 25, 2010
Unchecking a html radio button
Given the following code,
<input type="radio" value="PG" name="courseType" /> Post Graduate </input>
<input type="radio" value="UG" name="courseType" /> Under Graduate </input>
To check the "PG" html radio button in jQuery:
jQuery(blahBlahBlah).attr('checked', 'true');
To uncheck it:
jQuery(blahBlahBlah).removeAttr('checked');
Note: the following will **NOT WORK**
jQuery(blahBlahBlah).attr('checked', 'false');
jQuery(blahBlahBlah).attr('checked', '');
Monday, June 21, 2010
Tomorrow is always fresh with no mistakes in it.
“Tomorrow is always fresh with no mistakes in it.”
- Anne of Green Gables through Julie911
You know, I think you try a little harder when you're scared.
“You know, I think you try a little harder when you’re scared.”
- Rocky Balboa through Julie911
Sunday, June 20, 2010
Knowing to read
"Yes."
"I can't read it," he said. "I can't read anything. This is the greatest sadness of my life. I'll do anything so the children of my village never have to know this feeling. I'll pay any price so they have education they deserve"
...Mortenson says "...Here was this illiterate man, who'd hardly ever left this little village in the Karakoram,"..."yet he was the wisest man I've ever met."
- From "Three Cups of Tea" by Greg Mortenson and David Oliver Relin
The oppressor benefits for the day, the oppressed - for life
Twaha leaned toward Mortenson. "This man Haji Mehdi. No good." he whispered.
Mortenson was already acquainted with Haji Mehdi, the nurmadhur of Askole. "He made a show of being a devout Muslim," Mortenson says. "But he ran the economy of the whole Braldu Valley like a mafia boss. He took a percentage of every sheep, goat, or chiken the Balti sold, and he ripped off climbers, setting outrageous prices for supplies. If someone sold so much as an egg to an expedition without paying him his cut, Haji Mehdi sent his henchmen to beat them with clubs."
... Mehdi ...said ..."I have heard that an infidel has come to poison Muslim children, boys as well as girls, with his teachings....Allah forbids the education of girls. And I forbid the construction of this school."
"We will finish out school," Haji Ali said evenly. "Whether you forbid it or not."
....
"And you, are you not a muslim?" Medhi said, turning menacingly toward Haji Ali. "There is only one God. So you worship Allah? Or this kafir?"
Haji Ali clapped his hand on Mortenson's shoulder. "No one else has ever come here to help my people. I 've paid you money every year but you have done nothing for my village. This man is a better Muslim then you. He deserves my devotion more than you do."
"If you insist on keeping your kafir school, you must pay a price" Medhi said,..."I demand twelve of your largest rams"
"As you wish," Haji Ali said, turning his back on Mehdi, to emphasize how he had degraded himself by demanding a bribe....
"You have to understand, in these villages, a ram is like a firstborn child, prize cow and family pet all rolled into one"...
....
'It was one of the most humbling things I've ever seen," Mortenson says, "Haji Ali had just handed over half the wealth of the village to this crook, but he was smiling like he'd just won a lottery."
..."Don't be sad...Long after all those rams are dead and eaten this school will still stand. Haji Hehdi has food today. Now our children have education forever"
- From "Three Cups of Tea" by Greg Mortenson and David Oliver Relin
Friday, June 11, 2010
JSF 2.0 - Automatic resource bundle resolution
...
JSF 2.0 Templating
Element 1. Template
Element 2. Section ContentsNot standard terminology
</html>
Element 3. Composition
The composition brings the template (template.xhtml in this example) and section contents (login.xhtml) together by specifying which section contents (each in its own xhtml) should go into which sections (defined in the template)Wednesday, June 09, 2010
I can choose my thoughts
“There is so much about my fate that I cannot control, but other things do fall under the jurisdiction. I can decide how I spend my time, whom I interact with, whom I share my body and life and money and energy with. I can select what I can read and eat and study. I can choose how I’m going to regard unfortunate circumstances in my life — whether I will see them as curses or opportunities. I can choose my words and the tone of voice in which I speak to others. And most of all, I can choose my thoughts.”
- Elizabeth Gilbert: Eat, Pray, Love through Julie911
other people's way of living
“I’ve learned about other people’s way of living: how you cope with life’s challenges, how you celebrate good times, how you feel about issues, how awesomely goofy some of you are, and how, in the end, we all truly just want the same thing: to love and be loved, to understand and be understood, to leave this world knowing that we mattered and made a difference. We are all different, but so much alike.”
- Julie911