Java Project Maintenance – 5 Tips

No doubt that, Java is the leading enterprise software development language in current context and it comprises with vast technology stack to support many (good to say all) sectors which are deal by enterprise systems. It is rich with thousands of APIs and millions of developer community who willing to help and share the experience.

java_2

Scope wise or functionality wise, an Enterprise Java Project is usually inherits the complexity. This complexity causes for headache in all of the software development life cycle phases and especially in maintaining phase of the system. Maintenance involved bug fixing, adding new functionalities, trace back historic records and give reasons for the system behaviors, migrations, back up, etc… In this article I try to point it out 5 tips that we need to consider to do a good job in system maintaining.

1. Documentation

Larger systems are very difficult to understand by going through the code line by line. Having with component designing documents, API designing documents it is very easy to narrow down the component or sub component that we need to see if it needs to fix or add new functionality. Even we can get to know the use case also, if we have the Requirement Spec. Each of new CR should properly versioned and documented and it will help to get deep understanding on current system. For a new comer also it is a great help that if he can refer a good documentation of the system. In maintenance perspective system documentation is the most crucial factor that will affect to do better system maintenance.

2. Logging

Logging is a basic discipline that we follow when we are developing the system. Programmers use many logging tools in application level or beyond the application level. Logging involved load balancer logs, server logs and back end db level logs (Oracle PL/SQL programs logs). It is very important to convince, that programmers what it needs to log, at which place and in which log level going to use. If not once the system has deployed it is difficult to trace back the issues. Another important aspect is how to use files for the logging, especially is it going to use different logs for each of the component or going to use central log for every component. System maintainer considers the convenience of the log tracing and System user considers the performance of the system.

3. Employees

This aspect is not a technical thing but relate with the people management. Any given time an employee can jump to a new company and there for it needs to have a backup resource if that person is critical to the system. It should have a proper knowledge transferring mechanism, so the backup person can take over the system if it needs. This aspect help for a better system maintenance and both company and customer will proceed with a good customer relationship.

4. Issue Tracking 

It is very important to track the issues when a system is in maintenance phase because company needs to identify what are the places it needs to have further expansions and bug fixes. There are many tools in the market for this purpose and some of them are free to use. Some companies use issue tracking systems as a knowledge base and whenever a similar issue is arising they will refer the earlier case to resolve it. Some of the SLA oriented companies use these systems for their billing proofs too.

5. Code Base Management

Unprofessional code base management leads system’s code base mess. This is very important discipline because large systems keep on adding new things and changing the existing code base. So it increases the complexity day by day in code base aspect. For this process also there are many tools are available in the industry and some of the famous tools are Subversion and GIT. When the code base becomes larger it needs to clean up repeating code segments and organize code base in more logical manner. Some people bit reluctant to change the code base because they consider the effects of it for the existing production functionalities, but after couple of months or even couple of weeks it will mess the code base and make code base more complicate. Code review also needs to execute in periodical manner by the senior developers to point out juniors programming wrong disciplines. Apart from that this process will help to save the code base consistency. .

I like to see these 5 tips will help you to overlook when it designs the system and itself at the maintenance phase.

Arrys.sort and Collections.sort

Arrays class and Collections are classes which used to sort arrays or lists contain the objects. Main difference of both two is Arrays.sort for sorting only arrays and Collectins.sort for sorting lists.

Arrays.sort method

Based on array type there are many sort method implementations exist in Arrays class. Note that each of these methods needs an array as an argument. If we are going to sort our owned type then we need to implement Comparable or Comparator interfaces that we have discussed above the post. In that case we can use

static void sort(Object[] a) for natural ordering or

static <T> void sort(T[] a, Comparator<? super T> c) for Comparator based sorting.

Since sort method is static we can use these methods without instantiating the Arrays class.

import java.util.Arrays;

public class ArraysSortTest {

public static void main(String args[]) throws Exception {

int array[] = { 2, 5, -2, 6, -3, 8, 0, -7, -9, 4 };

Arrays.sort(array);

for (int i = 0; i < array.length; i++) {

if (i == 0)

System.out.print(array[i]);

else

System.out.print(“,” + array[i]);

}

}

}

Collections.sort method

As I described before, this method only accepting list based data structures. Similar to Arrays.sort there are many list based overloaded methods for sort. For the types that we have created we can use following favor of sort methods.

static <T extends Comparable<? super T>> void sort(List<T> list)

Sorts the specified list into ascending order, according to the natural ordering of its elements.

static<T> void sort(List<T> list, Comparator<? super T> c)

Sorts the specified list according to the order induced by the specified comparator.

I have copied method description from the java doc directly is quit explainery to understand.

import java.util.ArrayList;

import java.util.Collections;

import java.util.List;

public class CollectionsSortTest {

public static void main(String[] args) {

List<Integer> list = new ArrayList<Integer>();

list.add(5);

list.add(4);

list.add(3);

list.add(7);

list.add(2);

list.add(1);

Collections.sort(list);

for (Integer integer : list) {

System.out.println(integer);

}

}

}

Java Object Sorting

Object sorting is not a small topic and even I can not explain it completely in a small blog post, I tried to summarize important areas that a normal java programmer needs to know in day to day programming. Java programmers can use this post to refresh the knowledge about the java object sorting and for a new comer also can use this to understand how Java favors of object sorting.

java-logo

Comparable and Comparator

Whole Java sorting mechanism is based on one of the above sorting interface. The practical usage is depends on the system architectural design and both interfaces are equally rich in object sorting. Some designers do not like to implement interfaces in domain objects. They like to see them in pure attributes with corresponding setters and getters. They came to that decision because in that case they can use Comparator interface to sort the objects with having more control on sorting attributes. But still designer may like to put sorting logic inside the domain class because he is sure based on which attributes this object could sort.

Comparable example:

public class Vehicle implements Comparable { 

      private int vehicleId;     

       @Override

           public int compareTo(Object arg0) {

             Vehicle vehicle = (Vehicle) arg0;

                     return (this.getVehicleId() < vehicle.getVehicleId()) ? -1: (this.getVehicleId()> vehicle.getVehicleId()) ? 1:0 ;

       }

       public int getVehicleId() {

            return vehicleId;

      }

       public void setVehicleId(int vehicleId) {

            this.vehicleId = vehicleId;

      }

}

When we are implementing Comparable interface we have to implement the compareTo method and it takes comparing object as an argument.

Comparator example:

import java.util.Comparator;

public class VehicleIdBasedComparator implements Comparator <Vehicle>{

@Override

     public int compare(Vehicle vehicle1, Vehicle vehicle2) {

         return (vehicle1.getVehicleId() < vehicle2.getVehicleId()) ?-1:

(vehicle1.getVehicleId() > vehicle2.getVehicleId()) ? 1:0 ;

}

}

Here it implemented Comparator interface and corresponding campare method. It takes comparing two objects as arguments. Note here we can come up with many comparator classes with deferent compare method implementation. It means we can change the logic inside the compare method and we can compare objects based on deferent attributes in Vehicle class.

In practical usage we can used both implementations to sort objects. I will discuss the practical usage of above implementations in next sections of the post.  Following table describes important things that you need to know about Comparable and Comparator interfaces.

Topic Comparable Comparator
Package java.lang.Comparable java.util.Comparator
Method int compareTo(Object o1) int compare(Object o1,Object o2)
Implementation Considerations Sorting logic must be in same class whose objects are being sorted. Hence this is called natural ordering of objects Sorting logic is in separate class. Hence we can write different sorting based on different attributes of objects to be sorted.E.g. Sorting using id,name etc.
Sorting method This method compares this object with o1 object and returns a integer.Its value has following meaning
1. positive – this object is greater than o1
2. zero – this object equals to o1
3. negative – this object is less than o1
This method compares o1 and o2 objects. and returns a integer.Its value has following meaning.
1. positive – o1 is greater than o2
2. zero – o1 equals to o2
3. negative – o1 is less than o1

Why it is such important to use View Objects

Current enterprise application development domain, MVC  based development  is a common thumb of rule. Last couple of days I designed a Java Spring MVC based application for my client. I thought to write a blog post on View Object’s importance in application design domain and hope others will harvest design knowledge from it.

View Objects are the objects we use to represent data on web pages. In MVC based development’s view object plays it role between the controller and the view layer. When we need to show information on a web page or when we need to take user input from a front end, view objects come and rescue us. Most of the Java frameworks like Spring, Structs, JSF support for view object binding between the view layer and the controller layer and usually named as backing bean binding.  Its important to know difference between domain and view objects different. Domain objects represent actual domain specific artifacts and view object only for user interaction. Some developers are directly using domain objects as views and that will lead to a complex and unmaintainable application design.

Think a scenario a GET request coming from a browser for a resource. That request ask for a shoe shop. So user needs to see current exist shoe brands. In this case we can use view object to set our exist brand names to it and  front end technology can show them to the user.

public class ShoeShopView {

private List<String> availableBrandList;

public List<String> getAvailableBrandList() {

// get data from a service and return a String List

}

}

So we can use view objects to push data to the front end and show them to the user. When data come from the user’s end we can use view objects to pass data to the server. As an example we may need only user’s identification number and application internally access a service and retrieves related information for that number. So in this scenario we do not need information which we can retrieve from the internal service. We can clearly identify that this view object does not need to represent a User domain object because it only deals with the user’s inputs.

In case of a complex front end application needs to use reusable front end components with the help of  Tiles sort of technology. View objects come to handy in this kind of scenario and we can design the system with component based jsp pages with view objects. View objects help to design much decouple jsps with help of it. Lets take we may need to show a form to a user and which needs to take decoupling objects data. In this case we can create partial forms and concat them according to the generating form.

Install OpenOffice 3.2 in Fedora 12

Default Fedora installation comes with AbiWord installation and it helps greatly to our day to day word processing works. Only word processing is not enough todays context and we mostly need to create presentations, drawings and do some basic maths calculations. For our world Sun gives OpenOffice as a complete office package as Microsoft does.  In this blog I talk about the openoffice 3.2 installation in fedora 12.

step 01:

OpenOffice used sun JRE as execution platform. So first it needs to install JRE in you’r machine. You can download new JRE from sun site  and install it (http://java.sun.com/javase/downloads/index.jsp).

Note : Adition to JRE installation it may need to install sun SDK if you plane to do some programe stuff  with JAVA SE. If you plane to install SDK then it install both development environment and also JRE. For that follow below steps.

Download SDK rpm package (Currently version is jdk-6u20-linux-i586-rpm.bin) and follow http://java.sun.com/javase/6/webnotes/install/jdk/install-linux-RPM.html steps to correct installation.

Step 02:

After installation JRE then you can download OpenOffice package from OpenOffice download site (http://download.openoffice.org/other.html). Please note that to choose correct OS and 32/64 bit version.

Step 03:

Then go to package download directory and extract the package.

  1. tar xvzf OOo_3.0.0_LinuxIntel_install_xxxxxx.tar.gz
    This will create a source directory with the OpenOffice.org installation. The directory will have a rather long name but be prefixed by “OOO3…”.
  2. su to root, if necessary, and navigate to OpenOffice.org installation directory, the OOO3… source directory.
    Since the default packaging of OpenOffice.org for Linux is RPM, you will likely need to be root to run the rpm command.
  3. cd into the RPMS subdirectory of the source directory.
    You should see a lot of rpms here and one sub-directory called “desktop-integration”.
  4. Install this new version by typing rpm -Uvih *rpm.
    By default, this will install OpenOffice in your /opt directory.
  5. Finally, cd to desktop-integration. Depending on your package manager/system, install the appropriate desktop interface. For Fedora it needs to choose red-hat based openoffice.org3.2-redhat-menus-3.2-9472.noarch.rpm. So issue rpm -Uvih openoffice.org3.2-redhat-menus-3.2-9472.noarch.rpm command.

Step 04:


Still things may be not working. It may be rise “/opt/openoffice.org3/program/soffice.bin: error while loading shared libraries: libstlport_gcc.so: cannot enable executable stack as shared object requires: Permission denied” issue. You need to execstack some libraries.

(execstack is a program which sets, clears, or queries executable stack flag of ELF binaries and shared libraries – man pages)

execstack -c /opt/openoffice.org/ure/lib/libstlport_gcc.so
execstack -c /opt/openoffice.org/ure/lib/libgcc_s.so.1
execstack -c /opt/openoffice.org/ure/lib/libstdc++.so.6

Now you can enjoy OpenOffice facilities in you’r favorite Fedora distribution.

Installing mysql gem in Fedora12

When I try to install mysql gem in fedora 12 new distribution I had to faced some issues. So I think the way I figured out may help to others also to get rid this issue. First I mention what I have earlier installed in my machine.

  • ruby(1.8.6)
  • rubygems (1.3.5)
  • rails (2.3.5)
  • Mysql Server version: 5.1.41 Source distribution and client

So what I need was to configure mysql which can be used in my rails projects. To do that follow the below steps as those are listed.

  • log as root and install ruby-devel and mysql-devel. These liabraries provide lot of neccery configuration instructions needs to mysql gem.
# yum install -y ruby-devel 
# yum install -y mysql-devel

  • Then fire normal gem installing command as

# gem install -y mysql -p http://proxy_address:port — –with-mysql-config=/usr/bin/mysql_config

If u are not work under proxy you can eliminate “-p http://proxy_address:port&#8221; part.

I think this will help you for your developings.

Each firefox user with owned user profile

Most of the web users love to use Firefox because it is the greatest browser still present in the world. You may have faced same experience as I, which is same pc same user accont used by many users. We are going to experience clouding world and we are not depend on the Machine os. Recently Google also announced they are going to make chrome os as a web os. Though there are lot of Web Operating Systems we are not familiar with them as we do with firefox. Of course firefox is not a web os but it seems like one of that. Amazon cloud supports only on Firefox. There are lot of add-ons which make Firefox as webtop.

images

So I think its better if Firefox works as a normal webos. Then anyone who work on same user account in the same machine will not be a issue when dealing with the web. Firefox will handle all the user based settings. Users only have to log to the user account of the Firefox and customized profile will be prompt to the user by Firefox.

Commanding for War Games

Actually this is not my opinion and it is belongs to Mr. BLD Senavithne. He is my e-Business teacher and the thing he told us is fantastic and I think this will useful for others. I think most of you have played “General” kind of war games. Every time when we are playing, we have to move our mouse and click in thousand times. Actually what happen in real wars Rankers usually order to the soldiers. Now a days we are using voice recognitions systems in our pcs. If not computer game players do not think twice for spent little too much bit of money for buying equipments for playing games.

To give a better experience to the player game developers can make games which can command using a mike or something.

North Korean Issue

These days North Korea does lot of military based researches and some of them are nuclear ones. By the way USA and some of other European countries blamed for that. So I though to talk about this topic.

We all know UK accepts anything if its came form USA side and actually that is a shame for them. American (USA people) came form UK but they challenge UK on long time ago and finally they won the freedom form the UK. Now its seems like UK struggling to get rid from USA governing on UK and though they accepting anything told by the USA. So afterward I don’t think world should consider the what the UK saying because they only append the part of “We are with you” to the Americans decisions. By the force of this economical crisis USA was fallen and before that by the help of Tony Blear and other leaders, UK also faced the economical difficulties. Anyway USA has the ability to survival from this crisis and UK also should have a way to get rid of it. So they are try to create good relationship with the USA and get the advantages of that and it seems like other European countries are not too much worried about UK. We all know what UK did when Europeans were went to the Euro. So the reason to talk more about the USA and UK they are the main opposite parties in the North Korean issue. I have a doubt that both these countries do have the ethical right to reject the North Koreans doings. They are talking a world of peas and we all seen what they did to Iraq and Afghanistan and earlier to Vietnam.

After the World War II, Soviet Union and United State troops controlled the northern and southern halves of the country respectively by defeating the Japan. Northern part lead to a communist country and southern part lead to more open economical governing. Actually Korea is one of a best symbol which represent worlds main two governing forces. I don’t think Koreans need to live in two separated countries. It seems powerful countries made this wound and now all the Koreans had to bear this wound and they need to cure from this. Japan is the side of USA in most of the time and china and Russia are main threat for USA. So USA help as much as they can to protect South Korean government and China and Russia help for North Korea to protect communist government and by doing that they also revenging from USA.

Last week North Korea did a nuclear research under the land. They said it was succeed. Anyway South Korea has reactors and they make electricity by use of them and still North Koreans try to engage the reactors for the electricity producing. Both countries has the nuclear power. Anyway North Korea stands now on eight place in the nuclear weapons power and they has great and powerful ground army near 1,000,000. I am adding some important details comparing North and South Korean military power.

_45837223_ns_korea466x224

Based on these facts it is obvious that South Korean have the fear on North Korea. Now its seems like other countries like China also considering this issue and they  told they are not accepting the research done by the North Koreans. Anyway if USA or China can do the nuclear experiment why  North Korean can not do. One time India told that to USA as an reply when they doing the “Agni” missal experiments and USA opposed to that.

What I feel now is most of the countries try to increase their military power. Not only North Korea but also India (baying AWACAS planes), Pakistan, Israel, China ( they also going to increase the power of their navy), Iran, etc. So are they ready for the another world war?

Observer Pattern

First of all I need to emphasis that any pattern does not depend on a language and actually it is a powerful concept. Programmer should have the ability to format it according to the language going to use. My first explanation is based on Observer Pattern. This pattern use to implement to one-to-many relationship. Here we have a subject object and if its state is changed it inform to all the observer objects.  Let me explain it first using Java.
In Java we have pre implemented way of this pattern but I think its better to explain how we implement this pattern on our hand with better suiting to our interest and after that I explain how to use the lava pre-implemented pattern implementation.
First we define an interface for create concrete subject class. Here I need to note that we always try to code for an interface and not use concrete classes. This is good programming practice and it helps to manage code very much and dynamic object creation. Basically this interface and concrete class is for doing the a server kind of a job by managing the observers and they are some sort of clients.

public interface Subject {
public void registerObserver(Observer o);

/* observers are the clients who were been updating when subject status were changed*/
public void removeObserver(Observer o);
public void notifyObservers();
}

Now we are defining the ConcreteSubject class.
import java.util.*;
public class ConcreateSubject implements Subject {
private ArrayList observers;
public ConcreateSubject() {
observers = new ArrayList();
}
public void registerObserver(Observer o) {
observers.add(o);
}
public void removeObserver(Observer o) {
int i = observers.indexOf(o);
if (i >= 0) {
observers.remove(i);
}
}

public void notifyObservers() {
for (int i = 0; i < observers.size(); i++) {
Observer observer = (Observer)observers.get(i);
observer.update();
}
}
}

Now we need to inform the updates to the observers. To implement that I used an interface named it as Observer. Here one to many relationship perform as one subject relate to many observers.

public interface Observer {
public void update();
}

Now we are implement it using concrete observer class.
public ConcreteObserver implements Observer {
public void update(){
System.out.println(“updated”);
}
}

So that’s it. Now we are considering the Java inbuilt observer pattern support. Resource classes are available in the java.util package. Here we have Observable interface works as the Subject interface in our previous example and Observer is as normal Observer as in our previous example. (source codes of below examples took from http://www.java2s.com/Code/Java/Design-Pattern/Observableandobserver.htm)

import java.util.Observable;
import java.util.Observer;

public class MessageBoard extends Observable {
private String message;

public String getMessage() {
return message;
}

public void changeMessage(String message) {
this.message = message;
setChanged();
notifyObservers(message);
}

public static void main(String[] args) {
MessageBoard board = new MessageBoard();
Student bob =  new Student();
Student joe = new Student();
board.addObserver(bob);
board.addObserver(joe);
board.changeMessage(“More Homework!”);
}
}

class Student implements Observer {
public void update(Observable o,  Object arg) {
System.out.println(“Message board changed: ” + arg);
}
}