Monday, September 28, 2009

Development of Rural India

Although india is a fast developing nation, but the benefits of development is not reaching in deeper part of india. Unemployment, lack of basic infrastructure like Roads, Irrigation, Electricity are major problems. if these problems are solved through some structural changes india can become super fast growing economy.

Road construction companies should keep doing surveys about where they can create new roads n where they can do repairs. Instead of government ordering them they should proactively do it. Same applies to Dams construction.. Development should be pull based rather than push based. Somewhere i feel that indian corporate is more trustworthy than the local political representative.

Government has to solve irrigation problem asap as farming is still not a profit making business for major section of farmers. There is huge risk in farming as much is dependent on rains. If government cannot gurantee irrigation then farming should be nationalised in such regions. Afterall government cant leave people to make irrational choices of doing farming n trapping themselves in losses and debts. Many times farmers take double risk of rains and cash crops which often proves fatal.

There are so many industrial estates which are under ot not utilised. Work should be outsourced to from urban areas to such remote locations and railway frieghts should be waived on such outsourcing.

Sunday, August 30, 2009

Swing ResultSet Column Table Component

Hear is a ready to use component for JTable in swing which will also show column titles. By default the JTable only displays the data which is strange although. This code is free and can be used easliy in commercial and opensource applications.
Yet this component does not have alignment facility depending on Integer or String or Date datatypes. Will update once done.

Steps to use the class
1. Create a class ResultSetTableModel.java in package src.components.
2. Create a JTable and add it to JScrollPane.
JTable tblSuppliers = new JTable();
tblSuppliers.setVisible(true);
JScrollPane scrollpane = new JScrollPane(tblSuppliers);
pnlCenter.add(scrollpane,BorderLayout.CENTER);
3. Create the ResultSet,Create Model and set Model.
stmt = conn.createStatement();
ResultSet rs = stmt.executeQuery(strQuery);
ResultSetTableModel qtm = new ResultSetTableModel();
qtm.setResultSet(rs);
tblSuppliers.setAutoCreateColumnsFromModel(true);
tblSuppliers.setModel(qtm);


Code for ResultSetTableModel.java is as follows.
package src.components;

import java.sql.ResultSet;
import java.sql.ResultSetMetaData;
import java.sql.SQLException;
import java.util.Vector;

import javax.swing.table.AbstractTableModel;

public class ResultSetTableModel extends AbstractTableModel {
Vector cache;

int colCount;

String[] headers;

String currentURL;

public ResultSetTableModel() {
cache = new Vector();
}

public String getColumnName(int i) {
return headers[i];
}

public int getColumnCount() {
return colCount;
}

public int getRowCount() {
return cache.size();
}

public Object getValueAt(int row, int col) {
return ((String[]) cache.elementAt(row))[col];
}

public void setResultSet(ResultSet rs) {
cache = new Vector();
try {
ResultSetMetaData meta = rs.getMetaData();
colCount = meta.getColumnCount();

headers = new String[colCount];
for (int h = 1; h <= colCount; h++) {
headers[h - 1] = meta.getColumnName(h);
}

while (rs.next()) {
String[] record = new String[colCount];
for (int i = 0; i < colCount; i++) {
record[i] = rs.getString(i + 1);
}
cache.addElement(record);
}
fireTableChanged(null);
} catch (Exception e) {
cache = new Vector();
e.printStackTrace();
}
}

}

Saturday, August 29, 2009

Browser Embed In Swing

SWT Browser component is quite handy when you want to include support for platform independent browser support from your swing application.
Its more over important when you want to show modal window with a browser, because in case of non modal window you can anyways start IE instance from Runtime call.

The benefit of using Browser component in Swing is that it gives you enough control over the contents you can change anytime from website.
Also its saves you the time of rewriting the stuff written in Website again in Swing or AWT. Same stuff can be used here by directly pointing to Website Form/Page URL.

You have 2 options to go with.
1. chrriis.dj.nativeswing.swtimpl.components.JWebBrowser and
2. org.eclipse.swt.browser.Browser

I would suggest you to go with SWT Browser component.
One problem you will face with JWebBrowser is that the component creates problem with java 1.6. Its makes whole application
go crazy and all screens seams to get repaint problems.
Another problem you will face in JWebBrowser is that the component shows Custom window then a window.open call is made in
HTML page. You might like to open it in Default webbrowser of your operating system.
It allthemore becomes unacceptable when you have shown JWebBrowser component in JDialog window and you have clicked on window.open link.
It will show a window which is kind of hung and you cannot scroll or do any thing with the new window until you close the modal window.
One more problem you will encounter with JWebBrowser is that if you want to decide if opening of new window is to be allowed should be allowed
or not on the basis of URL location clicked, you have to
make a hidden JWebBrowser Component,
set it as browser instead of new window browser.
Dispose the new window using arg0.getNewWebBrowser().getWebBrowserWindow().dispose() in windowWillOpen open.
Ensure that you dispose the new window before setting the webbrowser.
Cancel the Opening of URL in locationChanging event and get the URL.
These long steps are to be followed if you want to intercept the opening up of new Window.

Good thing about JWebBrowser is that it is licensed under LGPL. So you can use it in your commercial projects also. You need not publish your code to users in case of LGPL.
A word for Christopher Deckers, author of JWebBrowser. Please make it work under Java 1.6. Just a call to NativeInterface.open starts the problems of repainting the windows.

However going with SWT Browser is not a eazy path either. You may face problems like
1. JVM Crashes
2. Not fitting easily in JDialog window and fits in JFrame.
3. Browser opens up in JDialog only once and dont come up next time onwards.
4. Your JDialog window shows up but the Browser dont show up.

To avoid JVM Crashes ensure that your window creation and displaying is all in SwingUtilities.invokeLater.
Let the shell loop be out of SwingUtilities.invokeLater. To ensure that JDialog and Browser both shows up,
you set location, size and visible for canvas, shell and browser component.
To ensure that the browser always comes up on window you might have to make use of small sleeps of 1 second outside your SwingUtilities.invokeLater.
This is to ensure that Window is created and shownup on screen before you try to set the browser component on the window.

The code written using SWT Browser component is completely platform independent. You can run vncserver service on your linux box and connect to it using vncclient and see your
application running in Linux environment using MOZILLA browser instead of IE.


If you need any advice or help on the topic please leave a comment here.

Friday, May 15, 2009

JVM Crash in Java Awt Client Exe

The JVM for Java is written in c++ language. When a JVM crashes it creats a file in hard disk from where the class is running. The file contains name of error. For Example EXCEPTION_ACCESS_VIOLATION. So how do you solve this error. The error file may state the thread in which the error occured. Once that is known you can apply some logic regarding what may the reason for crash.

If you are facing error in awt.dll and AWT-Windows" daemon, chances are that you are getting this error because of request focus. Check again the request focus calls. Some of the request focus may not be useful.

Saturday, April 25, 2009

Keep Updated to Google News through RSS

Are you in one of following situations.

1. You are staunch user of RSS Reader and less of Mail
2. You scroll through daily news paper and look only for specific subjects of new.
3. You are student and like to read more online and less from books.
4. You want to get news for all major news paper in your Reader for your topics.
5. Basically, You want Google News Alerts in Reader instead of Your Mail box.

Just now I noticed, RSS feed provided in Google News page. I dont know since when it is available, but i am quite sure its added there of late. I had a long list of subscription of Google News Alert around 2 years back. But ever since i shifted to Google Reader i have disabled all Google News Alerts.

RSS feed on Google News is rightly put there.. exactly as per my expectation and requirement..

Monday, April 20, 2009

Oracle Improves Productline

Oracle is now able to provide range of products and services to its clients like Storage, computers, operating system, database, middle ware and applications. This is because Oracle and Sun's product line compliment each other. However,clouds of uncertainty started hovering above overlapping areas like MySQL, Glassfish and Java. MySql however is not a straight competitor of Oracle database as user base is different.
This deal seems to be more beneficial form Oracle's point of view.It would be interesting to see how Java is able to grow under love and affection of this Step mother. With this deal, all Sun project seams to go on a slow track for some time as Oracle probably will be evaluating each of them and try to align them with their goals. IBM would surely be repenting on missing the deal with Sun.

Java Community favours the deal over IBM because Oracle would do more justice to take it ahead. IBM already have java based products but doesn't seam to be committed to high standards and reliability as is Oracle. Sun was more than generous at funding projects like JavaFx,Openoffice,NetBeans. This would change now I think!!

Friday, March 20, 2009

Java Serialization fails on Slow Network

Software like humans have behaviour, and more we use one we come to know about its behaviour..A Socket and ServerSocket connection was abruptly throwing EOFException in a slower network of 2 mbps but the same works without a single problem on the 100 mbps network. Apparently, Java was not throwing the timeout exception.

This problem was not coming always. The data flow of byte array was flowing properly without any problem in most of the cases.. But all of sudden, some of the packets seemed to be dropped.. As the receiving program did not get the complete bytes it was not able to construct a complete object using deserialization.

This whole problem embedded inside full fledged application makes it difficult to locate. DataOutputStream.writeUTF and DataInputStream.readUTF seams to fail.

In this process some tools came quite handy. AutoIT was a good tool for simulating user interface test cases. Its very easy to write script for making mouse clicks, keypress and window activation. I am sure its going to be useful to me in many of future projects. Another tool was Speed Limiter. When we do load testing in 100 mbps network our application works differently then over slower network. This makes it important to do load testing over slower networks like 56 kbps(Dial up), 1mbps, 2 mbps(BroadBand) networks. The timeouts, buffer size, queue size should be tuned for these network connections. We can run Speed Limiter on the Server system, on the port on which server was going to run and run the server on different port. Then we can mention the port mapping in Speed Limiter. You can select different speeds at which you want to do simulation. Only feature i missed in this tool was jerks or spike. In real network the connection gets stuck for some seconds and then starts again. This cannot be simulated here.

Coming back to core problem, i thought that there might be some software component in network like Antivirus which may be dropping/blocking some packets. But it was not the case. The problem was with the connection timeout. It the connection timeout was set to 10000 and above using Socket.setsotimeout function the problem gets solved..

So all that appeared to be a serialization problem was actually a timeout problem.

There are other serialization problems which i am facing like a long value being serialized over network gets divided by 32 on the receiving end. Then in one more case a String if has length more than 128 bytes gives StreamFormatException when serialized. I will update about same once i resolve the issues..