public interface OPCAdminFacade extends EJBObject {
public OrdersTO getOrdersByStatus(String status)
throws RemoteException, OPCAdminFacadeException;
public Map getChartInfo(String request,
Date start,
Date end,
String requestedCategory)
throws RemoteException, OPCAdminFacadeException;
}Anything that interests me finds place here. Software dominates my interests and hence a good part of this blog as well.
Tuesday, June 02, 2009
Design patterns - Session Facade
Web Services Notes (Source)
For 2 business applications to communicate with each other (distributed computing env.) they need.
Thursday, May 28, 2009
java.util.Calendar and java.util.Date
java.util.Date – Is a point in time (maintains millisecond accuracy)
java.util.Calendar –helps manipulate and compare java.util.Date
To convert Date to Calendar
Calendar cal1 = Calendar.getInstance();
Date currentTime = new Date(); // run on May, 28th 2009
cal1.setTime(currentTime);
assertEquals(2009, cal1.get(Calendar.YEAR)); // returns true
assertEquals(Calendar.MAY, cal1.get(Calendar.MONTH)); // returns true
assertEquals(28, cal1.get(Calendar.DATE)); // returns true
To convert Calendar to Date
Date date2 = cal1.getTime();
To find dates relative to each other – example to find the date tomorrow and yesterday
Calendar cal1 = Calendar.getInstance();
Date currentTime = new Date();// run on May, 28th 2009
cal1.setTime(currentTime);
cal1.roll(Calendar.DATE, 1); // one day after the date represented by cal1 i.e. 29th
assertEquals(2009, cal1.get(Calendar.YEAR)); // returns true
assertEquals(Calendar.MAY, cal1.get(Calendar.MONTH)); // returns true
assertEquals(29, cal1.get(Calendar.DATE)); // returns true
cal1.roll(Calendar.DATE, -1); // one day before the date represented by cal1 i.e. 28th
assertEquals(2009, cal1.get(Calendar.YEAR)); // returns true
assertEquals(Calendar.MAY, cal1.get(Calendar.MONTH)); // returns true
assertEquals(28, cal1.get(Calendar.DATE)); // returns true
Monday, May 25, 2009
JDBC Notes (Source)
Type 1: Drivers that implement JDBC APIs to map to another API such as ODBC. Dependent of native library (limited portability). e.g. JDBC-ODBC bridge
- Establish a connects
- Load the driver
Class.forName("org.apache.derby.jdbc.EmbeddedDriver");// Driver document details class name to use- Creates a instance of the driver clas
- Registers the instance with DriverManager
- Once created the driver instance can make a connection to DBMS.
i. Using DriverManager
- Works with Driver interface to manage the set of drivers available to a jdbc client (code that makes jdbc calls)
- JDBC client provides the URL (of the data source to connect to) and requests a connection with the DriverManager
- DriverManager finds out a driver that recognizes the URL and uses the driver to connect to the data source
- URL Pattern
- Making a connection
Connection conn = DriverManager.getConnection("jdbc:derby:COFFEES");Connection conn = DriverManager.getConnection("jdbc:derby:COFFEES", "babu", "babupassword"); // Connect to COFFEES database using babu/babupassword as cred.- If one of the drivers registered with DriverManager recognizes JDBC URL, then the driver establishes connection with the specified DBMS
- DriverManager.getConnection() returns a open connection
- The DriverManager manages all details of establishing the connection
- Only driver authers need to know about Driver interface
- Increases application portability by using a logical name for data sources instead of referencing driver specific information in the JDBC client/application
- Some examples:
// DataSource as a JNDI resource
InitialContext ic = new InitialContext()
DataSource ds = ic.lookup("java:comp/env/jdbc/myDB");Connection con = ds.getConnection();
// DataSource implementation provided by vendor
DataSource ds = (DataSource) org.apache.derby.jdbc.ClientDataSource()
ds.setPort(1527);
ds.setHost("localhost");ds.setUser("APP");ds.setPassword("APP");Connection con = ds.getConnection();
The start of nuclear weapons
July 16th, 1945 - First U.S. Nuclear test
July 26th, 1945 - U.S., Britain (a day before Churchill's end of term )and China give ultimatum(Not intended to be acceptable by Japan)
August 6th, 1945 - Hiroshima bombing (Bomb name: Little boy, Uranium based)
August 9th, 1945 - Nagasaki bombing (Bomb name: Fat Man, Plutonium based)
August 29th, 1949 - First U.S.S.R Nuclear test
Friday, May 22, 2009
Overriding methods can only throw exception that are thrown by the overridden method
import java.io.IOException;
interface TestInterface
{
void test();
}
public class Second implements TestInterface
{
public void test() throws IOException
{
System.out.println("Second.test() invoked");
}
public static void main(String[] args) throws IOException
{
TestInterface j = new Second();
j.test();
}
}
C:\users\Babu\temp\java>javac Second.java
Second.java:10: test() in Second cannot implement test() in TestInterface; overridden method does not throw java.io.IOException
public void test() throws IOException
^
1 error
An implementation of a method need not throw all exceptions thrown by the interface
import java.io.IOException;
interface TestInterface
{
void test() throws IOException;
}
public class Second implements TestInterface
{
public void test() // DOES NOT THROW IOEXCEPTION
{
System.out.println("Second.test() invoked");
}
public static void main(String[] args) throws IOException
{
TestInterface j = new Second();
j.test();
}
}
C:\users\Babu\temp\java>javac Second.java
C:\users\Babu\temp\java>java Second
Second.test() invoked
All methods of a interface are public
import java.io.IOException;
interface TestInterface
{
void test() throws IOException;
}
public class Second implements TestInterface
{
void test() throws IOException
{
System.out.println("Second.test() invoked");
}
public static void main(String[] args) throws IOException
{
Second j = new Second();
j.test();
}
}
C:\users\Babu\temp\java>javac Second.java
Second.java:10: test() in Second cannot implement test() in TestInterface; attempting to assign weaker access privileges; was public
void test() throws IOException
^
1 error
Tuesday, May 05, 2009
log4j log levels
Eric says:
Trace – I use for start and end of methods.
Debug – I use for low level debugging, info about the processing of single records.
Info – I use as a sparse group type comment, like ‘101 records processed.’
Warn – I use when something I don’t like happened, but the user may not care.
Error – I use when something un-expected happened and I’m stopping the processing.
Fatal –
I don’t really use fatal I suppose I should – but how is it different then Error
Friday, April 24, 2009
Tuesday, April 14, 2009
Wednesday, March 25, 2009
Tuesday, February 24, 2009
No. of people in prison per 100,000 citizens
http://en.wikipedia.org/wiki/File:Prisoner_population_rate_UN_HDR_2007_2008.PNG
Friday, February 20, 2009
How to write a generic API
Joel made an interesting point today. His approach to writing generic APIs. When there is only one use case for an API. Write the API specific to that use case. When you discover the second use case then generalize the API.
Thursday, February 19, 2009
Wednesday, February 18, 2009
String concatenation in Java with +
In Java if you System.out.println(“String 1” + “String2”) then there are no issues. The compiler will optimize it and there is no performance penalty. But if you do a String one = “String1”; String two = “String2”; System.out.println(one + two), then the compiler does not optimize this and there IS a performance issue. In these cases use String.format(“%s %s”, one, two).
For static Strings + concatenation is fine, for dynamic Strings, use String.format().
Sunday, February 15, 2009
Craftsmanship and Ethics
How to become a professional programmer
1. Short iterations - 1 to 2 weeks is fine. 4 weeks is too long. You have deployable software. Not deployed software. It is a business decision to decide is the deployable software should be deployed.
2. Best way to establish requirements is to implement your best guess and compare it against what the customer needs. Give the small changes to the customer and ask him if that is what they want. Don't ask the customer to sign off on the requirements document.
3. Separate what is likely to change from what is likely NOT to change and put them in different parts. E.g. Do not put business rules in GUI code. GUI and business rules change for different reasons. GUI changes for merit reason. Business rules change for policy rules. No validation in javascript. There is a way to get user experience and at the same time separating what changes from what does not.
4. Always better to DO than NOT DO (wait for req., Module b from group b). If you are wainting, help the other group achieve it.
5. NEVER be blocked. Decouple dependencies by creating stubs, mocks & stimulators. Your code can run without their code.
6. Architectures that impede software development. Doon't try to solve every problem tthat is. Do you create more difficulties than you solve. Have several simple architectures for the enterprise. Architects must write code. They must live the mess they create.
7. How do you address mess? Face that you have a mess and solve it increamentally solve it. Bit by Bit, day by day. Simple rule. Check in the code that is a little better than you checked it out.
8. No grand re-design. Mgmt. does not want it. It is expensive. Where are the reqs. for the new re-deisgn system? In the old system. The old system is changing. New system has to catch up. So one little bit at a time.
9. Practise progressive widening. Small/thin feature from GUI to DB. Then widen it one thin feature at a time.
10. Progressive deepening. Get something working in one layer and stretch it across other layers. GUI programmer waited for middle layer. GUI wrote simple dirty middle layer. Then write SOA, DAO etc...
11. Make it work, right, fast
12. Slowed down by bad code. Why did Jim write it? Bad code is not something that slows down somebody months from now, but us, right now. Don't write and you will not read. We did not have time to write it well. You are going to be significantly slowed down by this code but you did not take the time to avoid being significantly slowed down. You look at your 2 hours ago code and surprised at what it does. DO NOT WRITE BAD CODE. Bad code saves a few thousand $s. But bad code will increase repeating maintenance cost. Our product is code not the behaviour. It does not matter if the product behaves as expected. If code is bad, product is bad. Bad code stays with the team. If regression rate is high, there is a chance that code is fast. The only way to go fast is to slow down and write the code well.
13. Write clean code: Every line of code is the way you expect it to be. No surprises. As you read it its obvious. how big should a function be? Small, good function and variable names. Clean code begins with 1 line of good code.
14. TDD - test driven development. Do not write a unit of production code without writing test code. Stop writing unit test code the moment the test code fails. Compilation failure is unit test failure. Write production code. Stop writing production code until unit test passes. Write more unit test code. Keep swinging between unit test and production code every 30 seconds.
15. What makes s/w flexible. Tests. Test runnable in a simple fashion.
16. Don't use QA to find bugs. QA will find. But programmer's should aim at QA not finding bugs.
17. Increase code coverage. It should be as close to 100%. 90% is pretty good.
18. Avoid debugging. Look at the code. You had it working a minute ago. Do it rarely.
19. Automate them. Manual tests - less. Manual test should be explorative.
20. Done means - all tests passes.
21. Test through the right interface. Tesing through GUI, when GUI changes, tests fails. Do not test business rules through the GUI. Test business rules through a different test. Test only GUI code through the GUI test scripts.
22. Training. Make sure new people work with old people.
23. Write code because you care. Free ware tools are good quality. I will be as well as I can.
Friday, February 13, 2009
Thursday, February 12, 2009
Nice advice
- Hard work: All hard work bring a profit, but mere talk leads only to poverty.
- Laziness: A sleeping lobster is carried away by the water current.
- Earnings: Never depend on a single source of income. [ At least make your Investments get you second earning ]
- Spending: If you buy things you don't need, you'll soon sell things you need.
- Savings: Don't save what is left after spending; Spend what is left after saving.
- Borrowings: The borrower becomes the lender's slave.
- Accounting: It's no use carrying an umbrella, if your shoes are leaking.
- Auditing: Beware of little expenses; A small leak can sink a large ship.
- Risk-taking: Never test the depth of the river with both feet. [ Have an alternate plan ready ]
- Investment: Don't put all your eggs in one basket.
Have heard that the author is Warren Buffet. But not sure.
Wednesday, February 11, 2009
Brand New Day - Nice poem this
At the end of the day you are worn out, you are
worn out, and too tired to sleep
But then you do dream of wonderful things
That you might do, right on through to the next
day
And then you wake up
The sun's on your face
You're stretchin' while you're sayin'
It's a Brand New Day!
It's a brand new day and the sky is clear
So let's come together, everybody cheer
Come out people from everywhere
Let's see your faces, the day we'll share
Come on and celebrate a Brand New Day
Everyday!
Call out to the workers and the children in the
schools
It's a day of celebration so put down your tools
and
Celebrate a Brand New Day Everyday!
Come see the mountains and come see the
shores
Mother nature is calling so come climb aboard
and
Celebrate a Brand New Day Everyday! Let's go
At the end of the day there is no doubt you are
worn out
Ooh but then you do dream of wonderful things
Wonderful things you might do
And then you wake up
The sun's on your face
You're stretchin' while you're sayin'
It's a Brand New Day!
Celebrate a Brand New Day, Everyday!
Celebrate a Brand New Day, Everyday!
Author - not me :-)
Wednesday, February 04, 2009
Saturday, January 24, 2009
Friday, January 23, 2009
Confusion are not just within me...good to know that :-)
“Among other things, you’ll find that you’re not the first person who was ever confused and frightened and even sickened by human behavior. You’re by no means alone on that score, you’ll be excited and stimulated to know. Many, many men have been just as troubled morally and spiritually as you are right now. Happily, some of them kept records of their troubles. You’ll learn from them - if you want to. Just as someday, if you have something to offer, someone will learn something from you. It’s a beautiful reciprocal arrangement. And it isn’t education. It’s history. It’s poetry.”
- J.D. Salinger, The Catcher in the
Wednesday, January 21, 2009
Running a Single JUnit test class in maven
mvn test -Dtest=StudentServiceTest. Details
Monday, January 19, 2009
APIs in Java Interfaces
No access specifiers in method signatures specified in Interfaces. Implementation qualifiers like “final” not to be included in arguments. Details follow.
A close shave
“What might have been” causes you to be sad because you are comparing yourself with how good things would have been had you been successful.
Your comparisons can determine your happiness
The bronze medalist is happiest because he compares himself with those who did not get any medal.
The silver medalist is not as happy because he compares himself with the gold medalist. Happiness is a function of who you compare yourself with.
Secret of happiness is mild contentment not extra-ordinary happiness
People who are have extra-ordinary happiness also experience extra-ordinary sadness. Details
Friday, January 16, 2009
Strange are Madoff's ways
The $50 Billion Ponzi scheme fraudster was investigated thrice by the SEC and they could find nothing wrong with him. Strange world this.
U.S. not the country with most cars person....surprise!!!

Interesting facts these:
There are more cars per person in

Thursday, January 15, 2009
Wednesday, January 14, 2009
Listing all check-ins on a specific day
The following SVN command lists all check-ins on a specific day(s).
> svn log --revision {20090113}:{20090114}
------------------------------------------------------------------------
r4900 | bsubburu | 2009-01-13 16:54:12 -0700 (Tue, 13 Jan 2009) | 1 line
XYZA-2823. Implemented blah blah blah
------------------------------------------------------------------------
r4902 | jweight | 2009-01-13 17:28:38 -0700 (Tue, 13 Jan 2009) | 1 line
XYZA -2823. Increased blah blah blah
Friday, January 09, 2009
Nice talk on India, Pakistan conflict
http://fora.tv/2008/11/20/Neil_Joeck_The_US_And_Pakistan_Next_Steps
Thursday, January 08, 2009
Treatment (yesterday and today) of Mr Ramalinga Raju - a glaring example of how assuming we are
I have always felt that we Indians are very assuming. If somebody is successful in creating of perception of being good the first few times then he is good for the rest of his life and vise-versa (If we get a perception of somebody being bad the first few times then he is bad for the rest of his life).
Till yesterday Mr Raju, for the Indian media and Indians in general, was a super here of India Inc. Because we bought into his image promotion. We bought into his false-hood (or public relations as it is called to give it legitimacy).
Something like the size of a Maytas acquisition needed to wake us all up and smell foul. Now we start the journey to the other side. Mr Raju the evil of corporate
Till yesterday Mr. Raju was, actually, a liar. To us, He was a super hero of corporate
I am no big fan of Mr Raju. In fact I do not know much about him. But my point is our (the Indian society) treatment of him brings out the flaw in our attitude.
Wednesday, January 07, 2009
Why use @Override annotation
If a method is annotated with @Override but does not correctly override a method (in one of the super-classes or interface), then the compiler will report an error. So this is a means to use the compiler to enforce your idea that the methods overrides some other method.
E.g. of a startElement() method exposed in ContentHandler.
/**
* ……
*/
@Override
public void startElement(
final String uri,
final String localName,
final String qName,
final Attributes atts
) throws SAXException
{……
Tuesday, January 06, 2009
BidiMap
This Map can be looked up by both the key and the value WITH the same performance. The catch is that the values should also be unique. Which is expected as the values become the keys in reverse lookup.
A simple example:
import org.apache.commons.collections.BidiMap;
import org.apache.commons.collections.bidimap.TreeBidiMap;
public class BidiMapDemo {
public static void main(String[] args)
{
BidiMap map = new TreeBidiMap();
map.put("
map.put("IN", "
map.put("
System.out.println(
String.format(
"Lookup by Key. key: %s Name: %s",
"US",
map.get("US") // returns "
)
);
System.out.println(
String.format(
"Lookup by value. Name: %s Key: %s",
"
map.getKey("
)
);
}
}
Output:
Lookup by Key. key: US Name:
Lookup by value. Name:
Monday, January 05, 2009
Indian deep space network
Sunday, January 04, 2009
java and sax xml programming basics
Notes:
Sax exposes a org.xml.sax.XMLReader interface which must be implemented by all XML parsers. xerces implemented this interface in the org.apache.xerces.parsers.SAXParser class.
The first step is to create an instance of XMLReader. So
package test;
import org.xml.sax.XMLReader;
public class SaxRead1
{
public static void main(String[] args)
{
XMLReader reader = null;
}
}
Next to create an instance of SAXParser and assign it to XMLReader reference. So
package test;
import org.apache.xerces.parsers.SAXParser;
import org.xml.sax.XMLReader;
public class SaxRead1
{
public static void main(String[] args)
{
XMLReader reader = new SAXParser();
}
}
SAX call backs:
Wednesday, December 31, 2008
Locale.getDefault() to get default locale
Creating a unique, sorted list of countries in Java
Locale[] allCountries = Locale.getAvailableLocales();
Map
for (Locale currentCountry : allCountries)
{
if (! "".equals(currentCountry.getISO3Country()))
{
String countryName =
currentCountry.getDisplayCountry(
FacesContext.getCurrentInstance().getViewRoot(
).getLocale());
uniqueCountries.put(
countryName, currentCountry.getISO3Country());
}
}
Then you can use the map to do whatever. Here is an example to generate a list of JSF SelectItems
List
for (String currentCountryCode : uniqueCountries.keySet())
{
countrySelectItems.add(
new SelectItem(
uniqueCountries.get(currentCountryCode),
currentCountryCode
)
);
}
Sunday, November 30, 2008
Saturday, November 29, 2008
Maven Basics
The basic concept of Maven is a project. A project can create only one artifact. E.g. a web project can create a war file as an artifact. To work around this restriction of one artifact per project, a project can have sub-projects. Each of the sub-projects can have a artificat by themselves. The project's responsibility now is to take the sub-project's artifacts and make one artifact.
A project is defined as any directory with a project.xml in it. If sub-directories of a project directory have project.xml then they are project directories too.
All project artifacts (artifacts resulting from projects) are stored in repositories. There are remote and local repositories. Local repository is created in ./maven/repository. In windows its "c:/Documents and Settings/
The structure of repository on a windows box:
c:/Documents and Settings/babu.subburathinam/maven/repository/commons-loggging/jars/commons-logging-1.0.7.jar
Instead of each project having a copy of its dependencies, all libraries are lodged in a repository and all projects share the libraries available in the repository. Each project will inturn publish its artifact on to the repository. This process of a project publishing its artifact is called "install"ing in maven lingo. This process of each project publishing its (snapshot and release) artifacts to a central repository helps in continuous integration. This is how: Daemon processes running in build servers can build each project with its updated dependencies several times a day, deploy and test the built artifacts. Thus, integration issues if any will surface much before the release date of a specific project.
Inputs to maven:
One of the input files to maven is Project Object Model (POM) file. This file describes the project to maven. This file has the following structure:
01
02
03
04
05
06
07
08
09
10
11
12
13
14
15
16
17
Line 2 - Root element of XML
Line 3 - This tag is unused but needed.
Line 4 - A directory with this name is created in Maven repository to hold the artifacts of projects sharing the group id.
Line 5,6 - The id and version is used to create the artifact name as
Line 7 - Name of the project
The project Management section has project information such as the organization, its web site, location of SCM (Software configuration management), deployment and issue tracking sites, developer lists, mailing lists, etc...Most of this section is optional. The contents of project.xml can be extended. Most of the content is defined at the enterprise level and each project can override what is appropriate to it.
An example of the project management section:
01
02
03
04
05
06
07
08
09
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29 ...
30 ...
31
32
33
34
35
36
37
38
39 ...
40 ...
41
* Lines 01-05 - Organization details
* Line 08 - Top level package for the project
* Line 09 - Project Logo
* Line 12 - Project web site
* Line 14 - The site where the project is hosted
* Line 15 - Physical location of project deployment
* Line 16 - Physical location where the project distributions are available
* Lines 18-21 - SCM to access the project source
* Lines 23-31 - Mailing list for the project
* Lines 33-41 - Developers in the project
General structure of a maven project:
Maven Project Root
- maven.xml // Project definition file
- src // source directory
-- conf // Configuration within source
---xyz.properties // config gile
--java // java source
---com
----access
-----dev
------Hello.java
- test // test directory
-- conf // test configuration
---abc.properties // test config file
--java // java test files
---com
----access
-----dev
------TestHello.java
Project dependency section
In this section the project indicates all the dependecies that it has on artifacts of other projects. An example:
01
02
03
04
05
06
Line 1 - Starts the dependencies
Line 3 - The artifact that this project depends on is at the directory named "BeanUtils" in the repository
Line 4,5 - The artifact name is "commons-beanutils-1.5.jar" (using
Project build section
This section indicates the location of source, test and resource files. This is defined at the org. level or main project level for sub-projects to follow. If this section is not specified, no build ever gets done. Once build is over, all unit tests specified in the unit test section are executed. The contents of this section should match the actual layout of the code in the filesystem.
01
02
03
04
05
06
07
08
09
10
11
12
13
14
15
16
17
18
19
* Line 02 - Email address to send notification about the build status
* Line 03 - Folder containing the source files for the project. The source can be java, jsp and so on.
* Line 04 - Directory containing the unit test files for the project.
* Lines 05-09 - The test file name pattern to run after the build is completed
* Lines 11-19 - Resources to be copied in case a jar is created.
Project reports sections
Once build is done, reports and documentation about the build are generated.
e.g.
Monday, October 08, 2007
EJB and WebLogic
WebLogic Version | EJB Version |
7.0 | 2.0 |
8.1 | 2.0 |
9.0 | 2.1 |
9.1 | 2.1 |
9.2 | 2.1 |
10 | 3.0 |









