Filed under: Technology and Software
Everything boils down to the concept. Irrespective of what language or Technology you are using to implement your Business Process…. I think the JTable of Swings and DataGrid of .net is a typical examples to prove it.
Before i move further, In brief MVC(Model View Controller) is an Architecture, where in the the Business Logic resides in the Model, n the User interaction ie JSPs, JSFS,aspx… will be at the View .. and controller orchestrates the interactions of Model and View.. for More details about MVC Read Here..
I like to quote the similiarities b/w the Java Swings JTable and .net’s Datagrid
JTable is one of the most powerful, customizable, and difficult pieces of the entire API. With the exception of JTree, no other object within the API can be used in so many ways.
In both JTable and DataGrid , Model and Controller not segregated unlike Struts Framework. In JTable for just displaying the data which is static, we use the simple arrays or vectors, usually we ust array for storing the name of the columns like String[] cols={“col1″,”col2″,”col3″}. and the data to be displayed for each columns can be stored in the vectors.
In the sophisticated JTable where in the data can be updated ,deleted , fetched, we write the user defined TableModel which extends the AbstractTableModel ,and overrides the different methods like getColumncount(), getColumnNames(),getValueAt(int row,int col),getRowCount(),and Constructors which is shown as follows:-
public void mytableModel extends AbstractTableModel{
public mytableModel(){ ….}
public mytableModel(List l){…..}
public int getColumnCount(){ return 0;}
public int getRowCount{return 0;}
public Object getValueAt(int row, int col) {
return null;
}
}
We, use this TableModel for our JTable. So now why TableModel.. whats the use of this.. As i was talking about MVC this Table acts as the Controller. It is from this TableModel the Data can be manupulated. When ever the User wants to accesst the data from the JTable say 2 Row, 3rd Column data, it actually doesnt get the reference of the data from the JTable’s View ie the presentation Layer which shows in rows, columns on the GUI. It actually fetches from the this Controller,the method getValueAt(int row, int col) will return the data object from the datasource. To put in simple words the Presentation layer of the JTable just shows the data which is there in the data Source. it can be ArrayList,Vector etc. when the data is to be retrieved. The required col and row value is passed to the method getValueat(int row, int col ) which queries the datasource and fetches the data object. when ever the data is updated or changed the data in the Datasource is updated and the fireTableDataChanged() is called to notify the Listeners that the data is changed it he Datasource and it needs to refresh the same int he Presentation Layer.
Now where is M-> Model for the JTable? The Model of the JTable is another Class or a bean which fetches and updates the data as follows:-
class modelClass{
protected String Name;
protected String Designation;
public AudioRecord() {
Name = “”;
Designation = “”;
}
public String getName() {
return Name;
}
public void setName(String nam) {
this.Name = nam;
}
public String getDesignation() {
return Designation;
}
public void setDesignation(String desig) {
this.Designation = desig;
}
}
In the above Class ie Model Class, I have just used the String Variables.. the datasource as i mentioned can be anything like ArrayList, Vector.
So that was the JTable explained from MVC perspective. My aim was to just highlight the MVC Concept so the actual coding for the JTable is omitted.
DataGrid of .Net
So that was about JTable. Now lets analyse how the famous Datagrid of the .net can be explained wrt to MVC architecture.
As we all know there is no much hitches about the .Net coding as much of the so called dirty work is already done by MS(for which we pay!) has a simple coding as follows:-
System.Web.UI.WebControls.DataGrid dgrid;
dgrid.DataSource = dsource;
// Here dsourcethe dataSource
dgrid.DataBind();
// This will bind the data from the datasource to the Viewer or the Presentation Layer of the DataGrid.
Likewise JTable even there the data source can be anything.. it can be an ArrayList, Vector, Dataset etc… when we say dgrid.DataSource=dsource, this would be actually establishing the relationship b/w the Presentation Layer and the Model ie the datasource which is hidden where as in JTable the customTableModel’s constructor take it in as the parameter. In the .Net class similiar to customTableModel is hidden , Developer need not worry about the coding about that class as its done in the framework. Secondly when the dgrid.DataBind() method is called, the data in the DataGrid gets refreshed similiar to the JTable’s Listener fireTableDataChanged();.
Again when the particular data needs to be retrieved the Datagrid refers to the Datasource and again the Model class implementation which i have explained above wrt modelClass is readily given in the .net framework, so there is no need to code for it. This proves that Concept of MVC is injected in both JTable of JFC(Java Swings) and the Datgrid of the .Net framework.
Ref web sources
http://www.javalobby.org/articles/jtable/
http://www.awprofessional.com/articles/article.asp?p=332278&rl=1
Filed under: Technology and Software
Well, It has always been a big fight b/w Java guys and .Net guys. Its a great news for Java guys according to a survey by eweek magazine and JavaLobby.org which says Java is one language which can be used for diverse requirements.
This link gives the top 10 Languages http://www.javalobby.org/java/forums/t78504.html
and another article which says :- “Top 10 Languages to Learn, Java 3x More Jobs than C#” http://www.eweek.com/article2/0,1759,2016415,00.asp?kc=EWRSS03119TX1K0000594 check out the Jobs requirements of Languages.. Its mind boggling to see none are near to amount openings for Java Professionals.
Sun acquires JRuby, the Ruby version for JVM .. its a great initiative from Sun .. http://www.javalobby.org/java/forums/t78292.html
Filed under: Technology and Software
Yes, Back with some interesting idea, I have an idea of designing and developing an RSS Reader. ya i know , we have got umteen number of RSS readers. So i wanted to have some features which isnt there in other RSS Readers. So i would like to request all you guys to give some inputs if you have any , so that i can try to have it in the new RSS Reader.. BTW i thought of making the code available to any one who is interested to enhance it .. SO just pull up ur socks N give some inputs..


