Hi,
usually I am not a web guy, my work is focused on the business logic and infrastructures. but from time to time i find myself developing some web applications since it's a very important part in any application. long time ago i usually used to work with struts but today struts is not so popular and i usually pick spring MVC for this issue. but when one of my customers wish to know more about JSF i decided to pick up the glove and take JSF 2.1 to a test drive. when i had my devlopments in struts i thought what should be better struts or JSF, in that point JSF was not mature enough but now when JSF 2.1 is already in the air i thought about giving it another chance. well JSF did make a long way since than.
Today JSF is satisfy web framework that give you everything that you need in the server side, including:
1. Full MVC framewok that simplify the nevigation and create seperation in the model, view & control.
2. cross platform rich web UI component that provide better look & feel to the application.
3. AJAX library that enable you to preform AJAX calls
so i decided to take a ride on the JSF see if the rumers are true...
well, i build some basic app and i did have some troubles but basically it looks good.
Well, the idea here is that you have new HTML tags that can be used inside the JSP page and you can inject a code to the JSP if you register the class as a component in the JSF.
this is very diffrent from struts and spring MVC since the HTML looks very diffrent.
i think that front end developers that work with HTML & javascript can find this framework a real treat since it is very much web oriented and the HTML really talks to you. However, server guys like me can find a hard time to optimize it and get full control on behind the scene of this framework.
So probably it will not be my choise as a framework but i can understand why some programmers will love it.
Thursday, March 21, 2013
Wednesday, March 13, 2013
java interoperability
Hi, I would like to thank to all the participants that listen
to my lecture about interoperability between java and other languages inside
the JVM process. In the following link you can download the lecture presentation
as well as the code of the presentation.
https://www.dropbox.com/s/hh0ys4gvbehvj0l/script.zip
Friday, March 8, 2013
Java memory leaks
Last week i visited one of my customers that had a memory problem.
His application's memory keep rising no matter how much memory they allocate for it.
Each time OutOfMemory Error has accrued the RnD advice the support to increase the memory size.
However, after few days the old OutOfMemory error happened again.
I told the RnD manager that his application suffer from memory leaks, just like C++ it's also a bug.
The RnD manager told me: "we are working in java with GC it's impossible to have memory leaks" well, in java we also may have memory leaks but it is very diffrent from C++.
In java the application will suffer from memory leaks in the following example:
His application's memory keep rising no matter how much memory they allocate for it.
Each time OutOfMemory Error has accrued the RnD advice the support to increase the memory size.
However, after few days the old OutOfMemory error happened again.
I told the RnD manager that his application suffer from memory leaks, just like C++ it's also a bug.
The RnD manager told me: "we are working in java with GC it's impossible to have memory leaks" well, in java we also may have memory leaks but it is very diffrent from C++.
In java the application will suffer from memory leaks in the following example:
public static void main(String[] args) {
Observable ds = new Observable();
Main m = new Main();
ds.addObserver(m);
// do some work...
// when finish work with main forget removing m from observer
}
so in this case even if m was removed from other data structure it's still in the heap of the program.
The problem is even worse when you are working with application server since you need to understand how beans released from the memory.
Such bugs are difficult to detect since you don't know which object is leaked and you have to deeply understand your program in order to clean all your code.
However, most of the professional profilers provide you tools to handle memory leaks and you can use them to clean your code. In addition, there are some tools in the java language and some good best practices to avoid memory leaks.
so after 1 day of workshop training that i provide for this customer there are no more questions about memory leaks and the guys start working and removed most of the memory leaks from their application. Now it's work better and the customer stop complaining about the endurance of the application.
Saturday, March 2, 2013
Why using solr search engine instead of searching in DB
Next week at the 6.3 i will lecture about solr in windows azure user group here.
and i thought it will be nice to explain why i think it's better to use search engine like solr instead of using database search capabilities or implement your own search by iterate your data structure and looking for matches. before i start counting the reasons let me say that i think solr is good but any search capabilities based on lucene framework the bible of the text search is also good enough. notice that some databases use lucene framework for there search so if you are using these capabilities maybe you don't need solr after all. So let me count some major advantages for working with solr (and lucene) 1. Performance 2. Ranking 3. Flexibility 4. Clustering & Cloud support 5. Solr is free open source Let me provide more details about each advantage
Performance
Solr is fast, i mean very fast. millions of documents can return result in few milliseconds! this is the whole idea of indexed search engine you spend some time in indexing each string in inverted file and you get really fast search. and search must be ultra fast otherwise nobody will use it.
Ranking
Search is not about finding is about ranking! the most important thing is search is to provide the most relevant results at the top of the search result. needless to say that the most relevant results has to return first so solr stored the data in a way that most relevant results the boosted documents will have the fastest access. Flexibility
Let's say your user type with typo or write something in singular and the word exist in plural or even write word that just sounds the same of the word. if you don't have lucene as a search framework it is almost impossible to get such results. but in solr you can add plugins for different languages that will support such cases.
Clustering Cloud support
Today when many applications are SAAS and implements multi tenancy and sometimes you need to search on billions of documents having a tool that allow you to split your work for hundreds of nodes and allow you to work in cores for each customer you have your own core is not trivial. more than that ranking is calculated due to other documents in the system so such capabilities is very hard to implement.
Solr is free open source
And all of this for free in easy to use interface with the ability to add your own code with very large and quality community that will help you provide enterprise search for your application.
and i thought it will be nice to explain why i think it's better to use search engine like solr instead of using database search capabilities or implement your own search by iterate your data structure and looking for matches. before i start counting the reasons let me say that i think solr is good but any search capabilities based on lucene framework the bible of the text search is also good enough. notice that some databases use lucene framework for there search so if you are using these capabilities maybe you don't need solr after all. So let me count some major advantages for working with solr (and lucene) 1. Performance 2. Ranking 3. Flexibility 4. Clustering & Cloud support 5. Solr is free open source Let me provide more details about each advantage
Performance
Solr is fast, i mean very fast. millions of documents can return result in few milliseconds! this is the whole idea of indexed search engine you spend some time in indexing each string in inverted file and you get really fast search. and search must be ultra fast otherwise nobody will use it.
Ranking
Search is not about finding is about ranking! the most important thing is search is to provide the most relevant results at the top of the search result. needless to say that the most relevant results has to return first so solr stored the data in a way that most relevant results the boosted documents will have the fastest access. Flexibility
Let's say your user type with typo or write something in singular and the word exist in plural or even write word that just sounds the same of the word. if you don't have lucene as a search framework it is almost impossible to get such results. but in solr you can add plugins for different languages that will support such cases.
Clustering Cloud support
Today when many applications are SAAS and implements multi tenancy and sometimes you need to search on billions of documents having a tool that allow you to split your work for hundreds of nodes and allow you to work in cores for each customer you have your own core is not trivial. more than that ranking is calculated due to other documents in the system so such capabilities is very hard to implement.
Solr is free open source
And all of this for free in easy to use interface with the ability to add your own code with very large and quality community that will help you provide enterprise search for your application.
Monday, February 18, 2013
Project coin and operator overloading
Today there a lot of programming languages running on the JVM. one of the arguments of the advocates of these languages is that java is old language that require you to write a lot of code while you can simplify and shorten your code if you will use language like scala.
This is the reason why in java 7 there is a new project - coin project that wish to simplify the syntax of java.
in java 7 the following features were added:
1. using string and enums for switch statement
2. enable adding more than one exception in the catch clause.
3. the diamond operator in generics (removing generics in the constructor)
4. ability to call exotic names of methods that exist in other JVM languages - i will refer to it soon.
and one still in thinking process:
5. adding notation to access collection - this one i would like to discuss.
Collections are widely used in java and array is pretty much old fusion, however, it is very nice that you can write array[i].
It can be very nice if you can do it to collections as well.
for (int i = 0; i < list.size();i++){
list[i] = something(i);
}
first, i'm not sure it is such a bright idea since it discourage users to use iterator, but there is something appealing in this idea.
so if you wish to create a solution for it, you can go in two ways:
collections that provide us index should implement an interface, the list interface - so array should implement list too?
and the operator [] will be overloaded only on the list interface. this solution is not generic solution and you can ask yourself why this interface should get operator overloading and other java objects not.
or finally we will have operator overloading in java and the integration with languages like scala will be much simpler.
it can be nice if you will be able to write the following code:
if (newDate > oldDate){
doSomething();
}
this is really can be nice...
and it will also resolve number 4 that i said that i will refer to it later. now you don't need exotic names for functions that support operator overloading.
however, operator overloading has problem in java since in java we have only two types of variables: primitive & references.
and operators refers to variable and not for objects, let examine the following code:
if (person1 == person2){
doSomething();
}
the == operator refer to the reference and not to the object. so now if you wish to overload the == operator you can't check if the references point on the same object! so it is a problem to implement operator overloading in java.
so you can add syntax sugar in the coin project but it is not feet to a common standard.
and one more thing what happened if the object itself is null, what happened in the operator invocation.
so i guess, full operator oveloading is not simple in java. but i really be happy to see more thoughts about this idea.
Thursday, February 14, 2013
will we abandon mobile applications
Today most of the java applications has web UI interface and not rich client application.
It is almost a curse to develop a rich client application that run on the client side.
In one of the projects that i did in a very big enterprise company i herd one of the managers says:
I do not wont to install anything on the user machine, only anti virus and OS.
No doubt, web UI has a lot of advantages and today with HTML5 you can get rich client application look & feel in your web browser.
so it looks very reasonable to abandon rich client technologies like swing and use web development instead.
and with tools like GWT it looks very easy to work in web development and you don't have to work with java script if you don't like it.
However, today we are facing a very big revolution, the mobile revolution we are replacing our computers and laptops with mobile phones and tablets.
But in this world we would like to install applications on our device! even if we write it in java script we wrap it in installation, why?
there are probably a lot of answers:
1. very easy to install
2. can use the app store / Google play for earn money and promotions
3. better user experience
4. better performance
5. more capabilities from the device hardware (GPS,jyro...)
let me answer it one by one:
1. install on desktop is also quite easy
2. This is an advantage but i ask myself is it a silver bullet?
3. also in desktop
4. also in desktop
5. many applications that don't need extra from the hardware still used as applications.
more than that i suspect that the factors that made us abandon rich client and focus on web still exist in mobile
slow the computer
viruses
security
and many more...
so do you think one day we will stop using applications and return to the web again?
Wednesday, February 6, 2013
Thanks god for ARM in java 7
One of the most disturbing thing that was exist in java was closing resources such files.
first, you need to remember to close the file and put it finally since there is a chance that you will suffer from exception, but in the finally you have to protect yourself from getting null since the exception can happened in the creation of the stream or the channel.
so the code should look like this:
FileInputStream FileReader= null;
FileOutputStream FileWriter = null;
try {
FileReader= new FileInputStream("in.txt");
FileWriter = new FileOutputStream("out.txt");
int var;
while (var = FileReader.read()) != -1)
FileWriter .write(var);
} finally {
if (FileReader!= null)
FileReader.close();
if (FileWriter != null)
FileWriter .close();
}
In addition, the close method throw exception as well so you need to handle it as well.
This is very tricky code and very easy to make mistakes. no wonder spring provides useful templates for this issue.
But from java 7 with automatic resource management we don't have to take care of it anymore.
from java 7 you can write the same code like this:
try (
FileInputStream FileReader= new FileInputStream("in.txt");
FileOutputStream FileWriter = new FileOutputStream("out.txt")
) {
int var;
while((var= FileReader.read()) != -1 )
FileWriter .write();
}
since OutputStream and InputStream implements the interface closeable with the method close, the close method will be called automatically if the object was created since the code is in try brackets. so now java take care the close of the file.
I believe it will save a lot of time and many bugs mainly for novice programmers.
Subscribe to:
Posts (Atom)