It been long time that i had got an opportunity to demonstrate my driving skills on road, and was memorizing when did I had a good test for my good driving skills, the first thing that comes to my mind is a drive from Atlanta to Birmingham.
Let me give my driving background first, I’m always fascinated by Cars and a great fan of Formula 1 and in particular to Michael Schumacher and Ferrari. I’m used for driving manual gear cars with a drive on right side, mostly driven in Asia and United kingdom where traffic is considerable good, when moved to states, needed to drive a automated gear cars, not much of traffic on streets, cars hasa left drive (rigth traffic), to make life even difficult very polite drivers , low seep limits on a good roads and photo enforcement in most of the places
Sometime back I was working in Atlanta, GA, the one place where I love to drive. Here most of the traffic drives is very very aggressively. I’m a frequent visitor to Phoenix, AZ; so any guess how does Birmingham come into picture? Yes its because of Southwest airlines. Couple of times I had to pickup my flight from Birmingham, according to maps, the drive time between the two places should be approximately to 2 hours 20Min’s (around 150 miles). After driving for a while a in Atlanta, thought its an 1 hr and 40Min’s drive and having obtained a boarding card, ideally a door to door of 2 hours and 30 - 40 min’s is an ideal time for drive (need to be a bit careful in time calculations, Alabama is in CST and Georgia in EST).
Already, I missed couple of factors,
- I’m starting my drive on a Friday afternoon 2pm (weekend traffic).
- Any road works?
The drive from Atlanta to Birmingham is on I20 from east to west; for most part of the freeway official speed-limit is 75miles/ hour. Every time I had driven from Atlanta to Birmingham, it was definitely never without action, excitement!
My Trip to Birmingham started on a bad note, Got stuck in traffic in Atlanta Just before I could enter I 20 freeway, It was a delay of 6Min’s, was getting nervous as I knew I’m on road which I have no knowledge about, and that’s the last southwest flight from Birmingham to Phoenix; so pretty much knew what should I do if I miss my flight
. Once Entered into I 20, well its all mine, Friday traffic was there, but as long as I was in Georgia, the whole traffic moves at a higher speed so no real problems till 50miles, all of sudden a “Work Zone” sign for next 6miles; hmm getting interesting
drove about a mile at reduced speed, then another surprise, slow traffic and eventually no movement in the car (may be 10feet) for 25 minutes, totally frustrated, saw a small gap in front of me, so moved around 3feet, here you goo….bang!!! its from the back, someone hit me from back! hmm stopped the car to check the damage, a small dent and its was a old lady driver who expressed her apology, considering time constraints immediately back to car; after 40 Min’s of near stand still situation, suddenly found my car running at 40miles/hour then slowly to hitting the speed limit on the road, car speed limit slow traffic, a quick mathematics says I need an “average speed” of 80miles + 10-15minutes for car parking and security + boarding (Assumption was Birmingham is a small airport). May times, was revisiting my decision, would it be good to return back ? but same time wanna to give a try.
The opportunity to test driving skill was presented to me in a most beautiful way, drove to the potential of my car for next 50miles, the expected average speed was so high that my speed is not making any significant impact on the overall time, so complete 100miles; here comes another surprise, “work zone next 6miles”, hmm I don’t remember if I had followed the speed limits, but mostly it was a empty work zone roads! after that its all driving on I20 in a deep forests no sharp turns and not many narrow roads, but once reached the outskirts of Birmingham, traffic was there, not so crowded, comparatively, the average speed seems to be low in Birmingham, reached airport 13Min’s before my flight schedule, car parking in Birmingham was the best (just 1min walk), I parked in C12 slot (which later realized is the nearest place to reach airport security), a 30sec run, I’m in airport, a minute to find the security location and if my flight was still there, around 10 Min’s left at in front of security, Luckily, I’m the lone one at security counter (small airports are handy ah
) 6minutes left,1 minute run to boarding area, “well, you are too close sir” was the greeting I got! Sounded like honey to ears, ” I made it”.
Now thinking back, the only thing, I was missing the other day was “Rain”, I love driving in rainy conditions, it would have been awesome had it rained, although I wasn’t sure If I could have make it to my flight 
Written by Ravi Nallakukkala on April 13th, 2007 with no comments.
Read more articles on Uncategorized.
I come from a strong Eclipse background and in my new assignment, my project team uses IntelliJ IDE; So thought let me check this IntelliJ editor. As expected (after being loyal to Eclipse for many years) first I noticed all the bad things about IntelliJ, Here’s my list of bad things (Let me know if there is a better way of using IntelliJ to get around my problems)
- Once you setup you project on IntelliJ, next time when you open IntelliJ, It takes long time to open the project/ IDE (does some scanning of Java/ jar files) worst part is you can’t even minimize that window/ run the process in back ground.
- Upon installing a plug-in, Eclipse asks for a restart of workbench and upon your approval for restart, eclipse automatically restarts, For the same, Interestingly IntelliJ asks “You need to shut down IDEA to activate changes in plugins. would you like do it now? “; (Notice question doesn’t say ‘Restart’ ); So as expected, you have to (re)start your IDEA explicitly after installing a plugin.
- You Can’t drag and drop a Java file from one folder to another folder.
- IntelliJ expects a developer to configure the classpath twice, once to build the application and the second to run the application compared with eclipse where the same class is used by default.
- With little time i spend on IntelliJ, haven’t found a way to add some pre-configured code templates.
Written by Ravi Nallakukkala on April 11th, 2007 with 2 comments.
Read more articles on Editors.
- Using Spring 2.0 and Java 5, it is possible to declare the transactions using annotation-based approach.
- Spring framework supports @Transactional annotation for declarative transaction handling, this annotation can be used on a concrete class or method (with public visibility) of a concrete class. This annotation can be used on an interface, but this will only work as you would expect it to if you are using interface-based proxies.
- The default @Transactional settings are:
- The propagation setting is PROPAGATION_REQUIRED
- The isolation level is ISOLATION_DEFAULT
- The transaction is read/write
- The transaction timeout defaults to the default timeout of the underlying transaction system, or none if timeouts are not supported
- Any RuntimeException will trigger rollback, and any checked Exception will not.
- Enabling the configuration of transactional behavior based on annotations can be done as follows
<tx:annotation-driven transaction-manager=”txManager”/> where txManager points the underlying transaction manager and the tx namespace refers to http://www.springframework.org/schema/tx
- Transaction rollback can be controlled though Transactional annotation for the property ‘rollbackFor’ and ‘rollbackForClassName’.
- Timeout for the transaction can be controlled through the Transactional annotation for the property ‘timeout’.
- Example usage for Declarative transaction with Annotations
(more…)
Written by Ravi Nallakukkala on April 10th, 2007 with no comments.
Read more articles on Spring.
Unit Testing involves testing unit components or modules of Code and validating that they work properly. It’s a proactive procedure, which means that code written by developers needs to be unit tested at the unit level. All test cases are independent of each other and are to be written and executed by development team.
Prior fixing a bug, write a unit test to reproduce it. When the bug is fixed, verify the fix using the unit test. All methods need to be covered by the tests. The tests need to covers all paths through the unit. Unit Tests will ensure errors are picked up at the earlier stage and will facilitate easy integration.
Unit Testing Process
The figure below illustrates the Unit Testing Procedure and it encourages developers to write test cases before they start developing their use cases.

Guidelines for Unit Test Cases
- Write the test before implementing the functionality using a test driven approach. Every software component (business modules, services, DAOs, models or controllers of the presentation tier) will be designed to be tested.
- When a bug is identified in the code and later fixed, as a good practice write a unit test to validate it.
- Use Mock Object to collaborate with other components.
- Write the tests for normal success case, boundary conditions or any exceptional conditions.
- Make a decision if it’s really appropriate to write tests for simple methods or simple classes. These will get tested later during Integration Testing (like DTOs, get/set,..).
- Unit Test for Business Objects that only encapsulate data is not necessary. Only if the BO implements Business Logic, then this has to be tested using a unit test.
- While testing the Business Logic Layer, unit tests need to be written for every service interface. Use Mock Objects for DAO’s. Components used within the service implementation that contain validation logic will need to be tested independently. E.g. Validators, Convertors.
- For the Presentation Layer one would need to set up the page, pageView, pageModel and the PageContext. Mock Objects will be used to model the PageContext.
- The Test Coverage should be continuously monitored. Clover/ Cobertura could be used to for code coverage.
- The names of Java source files for testing end with ‘Test’, as in MyClassTest.java.
- While testing the Data Access Layer, make sure every DAO method has been tested. After each test the transaction should be rolled back so cleaning of the database is not required. (spring framework will do job of automatic rollback of data changes to the database).
Unit Testing Tools
Consider a combination of JUnit and EasyMock to write Unit Test Cases. These tools are integrated with Eclipse (hopefully with Intellij) to merge unit tests with the development process.
Unit Testing Framework - JUnit
JUnit provides a Java based framework for unit testing. In order to setup JUnit one has to download the junit.jar file which is freely downloadable and append it to your classpath. JUnit will be integrated with the Eclipse development environment.
- While writing unit tests, any class that contains test methods should subclass the TestCase class. A TestCase can define any number of public testXXX() methods.
- To check the expected and the actual test results, one has to invoke the variation of assert() method.
- The Test Class having several testXXX() methods can use the setup() and teardown() methods to initialize and release any common objects under test.
- TestCase instances can be composed into TestSuite hierarchies so that all test methods are invoked
EasyMock
EasyMock, an open source library provides an easy medium to generate mock objects for a given interface. This facilitates running Junit tests for individual classes with the collaborators being simulated with Easy Mock Objects.
To get a Mock Object, we need to perform the following steps:
- Create a Mock Object for the interface we would like to simulate
- Setup the Expected behavior. Record the expected method calls.
- Switch the Mock Object to replay state. If no expected behavior is set, then call to any methods of the collaborator class with throw an exceptions.
- Call object under test
- Validate if the expectations have been met.
- Code Snippet using JUnit & EasyMock
import junit.framework.TestCase;
import static org.easymock.EasyMock.createMock;
import static org.easymock.EasyMock.expect;
import static org.easymock.EasyMock.replay;
import static org.easymock.EasyMock.reset;
import static org.easymock.EasyMock.verify;
public class UserServiceImplTest extends TestCase {
private UserDao userDaoMock;
private UserService us;
public void setUp() throws Exception {
// 1. create the mock for our DAO
userDaoMock = createMock(UserDao.class);
// 2. create an instance of the class under test
us = new UserServiceImpl();
// 3. wire test object and mock
us.setUserDao(userDaoMock);
}
/**
* after each test method call the mock has to be reset
*/
public void tearDown() throws Exception {
reset(userDaoMock);
}
}
Written by Ravi Nallakukkala on April 8th, 2007 with no comments.
Read more articles on Design.
In my new project, my team was using IntelliJ as their IDE and I come from a strong Eclipse background, Initially it was hard time to find out all the Shortcut Keys for IntelliJ so thought I could document the shortcut keys that I commonly use, I will update this list as my learning experience continues with IntelliJ
| Description |
Eclipse shortcut |
IntelliJ Shortcut |
| Navigate a Java Type |
CTRL + ALT + T |
CTRL + N |
| Navigate a Resource |
CTRL + ALT + R |
CTRL + SHIFT +N |
| Last Modified Source |
ALT + Left arrow |
CTRL + ALT + left arrow |
| Debug |
F11 |
Shift + F9 |
| Open Declaration |
F3 |
CTRL + SHIFT + B |
| Open Hierarchy |
F4 |
CTRL + H |
| Organize Imports |
CRTL + SHIFT + O |
CTRL + ALT + O |
| Find |
CTRL + F |
CTRL + F |
| Find Again/ previous |
F3 / SHIFT + F3 |
F3 / SHIFT + F3 |
| Step Into |
F5 |
F7 |
| Step Over |
F6 |
F8 |
| Step Out |
F7 |
Shift + F8 |
| Resume |
F8 |
F9 |
| To find impl of an abstract Method |
? |
Ctrl + Alt + B |
Written by Ravi Nallakukkala on April 6th, 2007 with no comments.
Read more articles on Editors.
Java serialization is a process of saving an object’s state to a byte stream and rebuilding the bytes into a Java object (may be at some future time).
As serialization is a concept based on maintaining the state of the object, so every attribute inside the object will have an impact on the amount of data serialized.
To explain the impact of unused variables on Java serialization lets take an example.
(more…)
Written by Ravi Nallakukkala on April 4th, 2007 with no comments.
Read more articles on Java/ J2EE.
Its me again, For past few days my life is all about searching, search criteria and analyzing its result. The product I work has to scale up-to returning search results of the magnitude of few hundred records. Unfortunately we don’t have the luxury of having the pagination for these search results, hence there is a high amount of tuning required on the server side.
In this article I will be describing a SOA based search design for handling bulk data in a multi layered architecture; The project I was working was architect to have 3 layers: Facade Layer, Services Layer and a DAO Layer.
Facade layer was implemented though EJB 3 and as expected was the main communication interface for the client, our clients talk to the server side Facade though the Data Transfer Objects (Dto); One of the main responsibility of the facade is to convert Dto objects passed by the clients to the Business Object (Bo) for request processing and during response scenario, facade also converts the Business objects to the Dto and send the response to the client.
Service Layer is the place where the main business logic will placed,the communication to/ from the services layers always happens through the Business Objects. Main responsibilities of this layer include invoking the Data Access Object Layer (Dao) and invoking other Services.
Data Access Object Layer is mainly responsible for invoking the persistence api (most of the cases, it will be ORM like hibernate, JPA).
To achieve the flexibility in the design approach, Dto are used to communicate between the client and server, but it has to be noted that all the processing on the server side happens on Business Objects.
Considering this architecture, Even for a search case too, search criteria will be passed to the server in the form of a Dto, and in the facade layer this search criteria dto will be converted to a Bo and then the criteria in the form of a Business object will be passed to the Dao and based on the persistence technology an appropriate query will be executed and the results in the form of the Bo will be returned to the facade, where again the Bo will be converted to the Dto objects.
Now, this approach works very well for low to medium volume search result sites; in order to optimize this search we have been looking around for some options and finally arrived at saying “For searches, why not allow the criteria (Dto equivalent) to be passed to the Dao layer and get the results from Dao in the form of Dto”. Essentially, all we are doing is eliminating the conversions from Bo to Dto and vice-versa. For large volume Search results, the conversation to/ from Dto/Bo makes a big differences (time consuming process). This approach also gives us a flexibility of selecting any specific attribute in an entity (unlike the case-of the Query though Business Objects, the entire Business Object will be loaded even though you need a single attribute of that entity)
There is already some support by JPA to support this kind of architecture for searches, for example look at the following query
select new com.alpha.beta.SearchResult(emp.id, emp.name, emp.salary) from Employee emp
Now the ‘SearchResult’ class should have a constructor matching to the above construct
i.e,
public class SearchResult{
private Long id;
private String name;
private BigDecimal salary;
public SearchResult(Long id, String name,BigDecimal sal){
this.id = id;
this.name = name;
this.salary = sal
}
}
If the query retuns a ‘List’, In this example the list will contain a list of ‘SearchResult’ Objects.
To Summarize the advantage of this approach (of bi-passing the layers for search)
- There is no extra conversation To / From Dto/ Bo.
- It also possible for some cases to load the attribute without loading the entire Business Object.
- This approach also leaves the developer to use native SQL for complex sql which may not be implemented through some Persistence API.
Written by Ravi Nallakukkala on April 1st, 2007 with no comments.
Read more articles on Design.
One of the biggest problem which is commonly faced in searches is pagination; On the first day of my new job, I was asked to looked the performance issues related in the search functionality of the application. When I looked at the application, application is slow when the users gets a search results of magnitude of 6000 records( each record had 10 fields to be displayed) and all the results were displayed in a single HTML page (Even if you had designed one search implementation, you would have guessed what the problem is).
There is no pagination concept implemented for this search/ problem, its a logical thing to say this search program is using whole lots of memory and slow. Assuming the search queries are already fine-tuned, Slowness can be mainly attributed to the HTML rendering by the browser. IE browser render the complete HTML and then displays it to the user so the slowness can be easily be found compared to Firefox 2, where the browser starts displaying the data as it receives (rather completely render it and displays it).
Given this background, Now we started seriously looking at pagination as the only option. In pagination, could think three approaches as a potential solutions
- Real time pagination on the server side.
- Criteria Caching based pagination on Server side.
- Pagination on the UI front.
Lets go in details of each one of them.
Real time pagination on the server side :
This is an approach where from the UI, always pass the search criteria plus the page start record and the end record (or size of the page). So your server implementation will have these two extra arguments along with your query and returns you only the required result set which needs to be passed to front end.
On the implementation front, you could handle this scenario at two levels
- Write a stored procedure which takes your criteria and start and end record (or Size) for the page as argument and using ‘cursors’ you can return only the required result set, for more details on oracle specific result set using cursor click here
- Say you are using ORM tools like hibernate, they make our life even easier you could try something like
Query q = s.createQuery( “your query….” );
q.setMaxResults(PAGE_SIZE);
q.setFirstResult(PAGE_SIZE * pageNumber);
List page = q.list();
- For more details on this hibernate approach click here
Lets looks at the pros and cons of this approach
- Its a real time pagination search, say your query is based on order by name, on the first page we show say 25 records, in the mean while say another user deletes few records (say 20 to 25th record gets deleted), now when the first user click the next button, the request goes as original criteria and retrieve the records from 26th to 50th record and we return 26 to 50 th records (because of the deletion, ideally we should have displayed from 20th to 45th records), essentially now we are not showing 5 records this is a disadvantage. For the same example, addition of records ‘could’ be an advantage for this approach.
Criteria Caching based pagination on Server side
This is an approach where all records matching to the search criteria will be fetched from the database to the the server and cached. Caching is based the search criteria and a timeout period.
From the UI point of view, request will contain the search criteria plus the start record and the size( r the end record) to be fetched.
Lets looks at the pros and cons of this approach
- This solution should fairly work for most of the search cases, unless you have a requirement for real time pagination.
- When Caching is considered, Caching algorithm plays an important role and this also has to take care of the timeout period and the memory allocated for the caching mechanism.
- Arriving on the timeout period is quite crucial as this directly impacts your performance of the search. Too low timeout (is very near to real time pagination case) will cause too many hits to your database and can cause slowness also has the drawbacks of real time pagination. Too long timeout period will have the drawback of having out-dated data on the server cache.
Pagination on the UI front
This is an approach where all the records corresponding the search criteria will be retrieved from the database and held in the controller of the UI Framework and using custom tag libraries the records could be displayed in the Jsp/ Servlet.
Here are some of the recommendations for writing your own custom pagination tab lib
- The bean will have attributes for collection of all the records, total number of pages, records per page and start record number for the current page.
- On the first display of the page, read all the corresponding records for this page and store the bean in HTTP Session.
- On the selection of the next page, previous page, etc.,; retrieve the bean from the HTTP Session and then calculate which data needs to be displayed.
Lets looks at the pros and cons of this approach
- This would be dream design approach for small volume search results (where memory is not a constraint).
- Most the cases, you do have a memory constraint, hence this may not be a feasible approach.
Written by Ravi Nallakukkala on March 30th, 2007 with 2 comments.
Read more articles on Design and Hibernate.
Nope.
Weblogic 8 (including all service packs) supports only jdk 1.4.x
For more information…
http://e-docs.bea.com/platform/suppconfigs/configs81/81_over/overview.html
Written by Ravi Nallakukkala on March 26th, 2007 with no comments.
Read more articles on Servers.
Dozer is a powerful, but simple Java Bean to Java Bean mapper that recursively copies data from one object to another.
Dozer supports simple property mapping, complex type mapping, bi-directional mapping, implicit-explicit mapping, as well as recursive mapping. This includes mapping collection attributes that also need mapping at the element level.
This is different from Bean utils, which copies the data recursively for the object which has the same property names. Bean-Utils has a restriction for working with complex data types.
Dozer tool can be found here
here’s some of the key advantages found on Dozer
- Can define the mapping / exlude mapping in a configuration mapping file.
- Support for Spring (tested Dozer 3.0/ 3.1 with Spring 2.0).
Recommanded Usage Scenario:
- Highly recommanded for the scenarios, where the usage of design patterns for Data Transfer Object (Dto) and Business Objects (Bo).
- For scenario of Data transfer from UI form elements to Data transfer objects (Dto).
Disadvantages for Dozer
- I used this tool under Java 5/ Spring 2.0. Dozer was instantiated using Spring. our architecture was like, all the business Objects (Bo) were placed in one project. Had a facade (facade has Dto) for a set of functionalitie. Now the problem was the definition of spring configuration for the dozer, as Dto and Bo were present in various projects, so this created a need for the definition spring configuration definition on a top level project than at leaf level.
Written by Ravi Nallakukkala on March 25th, 2007 with no comments.
Read more articles on Spring and Tools.