If we wants to compare non-english characters for sorting, tabular then we do not have option to do that in normal string comparison(which will do straight away based on character to character comparison).
For Instance, I have Umlaut(ä, ë, ï and etc.,), if we compare with (au, eu, iu) then it will say both are different. But, in german/latin locale , these characters are equal respectively(au==ä). And additionally, 'ae' has to be treated by comparator as a single character.
From on, JDK 1.4 , java.text package introduced to get this job done.
Example from Sun JAVA DOC:
String Norwegian = "< a,A< b,B< c,C< d,D< e,E< f,F< g,G< h,H< i,I< j,J" +
"< k,K< l,L< m,M< n,N< o,O< p,P< q,Q< r,R< s,S< t,T" +
"< u,U< v,V< w,W< x,X< y,Y< z,Z" +
"< \u00E5=a\u030A,\u00C5=A\u030A" +
";aa,AA< \u00E6,\u00C6< \u00F8,\u00D8";
RuleBasedCollator myNorwegian = new RuleBasedCollator(Norwegian);
Please find more detail from Sun JAVADOC, which is nicely written with samples.
java.text.Collator.java
java.text.RuleBasedCollator.java
Monday, December 7, 2009
Wednesday, November 18, 2009
AJAX : Asynchronous JavaScript and XML
AJAX: Asynchronous JavaScript and XML
Using Javascript accessing the minimalistic data from server and partially refreshing the content in webpage. In general, HTTP request will try to refresh/restore the entire HTTPDocument, instead of that just refresh particular area in HTTPDocument.
In 2005, Google suggest has heavily used AJAX and bring it in to familiar. If we type in google search bar, we will get some suggestion based on the typed character sequence, with number of people has searched the same phrase till now. This made googler smile and select the right phrase combination listed by google search bar.
AJAX uses XMLHttpRequest in browser, to send and receive the information from server. This object will be created using ActiveXObject in older browsers, in IE7 onwards we can created directly using new XMLHttpRequest().
function getXMLHTTP()
{
var xmlhttp;
if (window.XMLHttpRequest)
{
// code for IE7+, Firefox, Chrome, Opera, Safari
xmlhttp=new XMLHttpRequest();
}
else
{
// code for IE6, IE5
xmlhttp=new ActiveXObject("Microsoft.XMLHTTP");
}
return xmlhttp;
}
XMLHttpRequest object has two public apis (open(), send()) and two property (onreadystatechange, readyState).
Open API: This method call establishes connection to the server with using three arguments.
xmlhttp.open("GET","greetings.asp",true);
First argument tells what HTTP method used.
Second argument hold URL, and third talks about Asynchronous call or not.
Send API:This method call sends the request to URL specified in open API, where this API capable of passing the QueryString to the Server.
xmlhttp.send(null);
No queryString passed to Server
xmlhttp.send("action=Greetings&name=Krishna");
Send querystring to the server.
If open API's third argument is false, then we will get the response in synchrnous.
If the third argument set to true then Asynchronously response will come .
How to catch the reponse which comes in asynchronously, yeah, we have a property that will help us to refer a javascript function.
xmlhttp.onreadystatechange=function(){}
whenever http connection state get change this method will be get called. There are five states possible for this XMLHTTPRequest are given below.
Now, we have to write the program which will act based on the state.
if(xmlhttp.readyState==4){//do something for request completion.}
Sample code to play with AJAX
<html>
<body>
<script type="text/javascript">
function searchFunction(str)
{
xmlhttp=getXMLHTTP();
xmlhttp.onreadystatechange=function()
{
if(xmlhttp.readyState==4)
{
document.getElementById("searchResult").innerHTML = xmlhttp.responseText;
}
}
xmlhttp.open("GET","http://www.google.com/search?q="+str,true);
xmlhttp.send(null);
}
function getXMLHTTP()
{
var xmlhttp;
if (window.XMLHttpRequest)
{
// code for IE7+, Firefox, Chrome, Opera, Safari
xmlhttp=new XMLHttpRequest();
}
else
{
// code for IE6, IE5
xmlhttp=new ActiveXObject("Microsoft.XMLHTTP");
}
return xmlhttp;
}
</script>
<form name="myForm">
Search <input type="text" id="search" name="search" onkeyup="searchFunction(this.value);" />
<p/>
</form>
<div id="searchResult">ads</div>
</body>
</html>
For tutorials and more details : http://www.w3schools.com/Ajax/
Using Javascript accessing the minimalistic data from server and partially refreshing the content in webpage. In general, HTTP request will try to refresh/restore the entire HTTPDocument, instead of that just refresh particular area in HTTPDocument.
In 2005, Google suggest has heavily used AJAX and bring it in to familiar. If we type in google search bar, we will get some suggestion based on the typed character sequence, with number of people has searched the same phrase till now. This made googler smile and select the right phrase combination listed by google search bar.
AJAX uses XMLHttpRequest in browser, to send and receive the information from server. This object will be created using ActiveXObject in older browsers, in IE7 onwards we can created directly using new XMLHttpRequest().
function getXMLHTTP()
{
var xmlhttp;
if (window.XMLHttpRequest)
{
// code for IE7+, Firefox, Chrome, Opera, Safari
xmlhttp=new XMLHttpRequest();
}
else
{
// code for IE6, IE5
xmlhttp=new ActiveXObject("Microsoft.XMLHTTP");
}
return xmlhttp;
}
XMLHttpRequest object has two public apis (open(), send()) and two property (onreadystatechange, readyState).
Open API: This method call establishes connection to the server with using three arguments.
xmlhttp.open("GET","greetings.asp",true);
First argument tells what HTTP method used.
Second argument hold URL, and third talks about Asynchronous call or not.
Send API:This method call sends the request to URL specified in open API, where this API capable of passing the QueryString to the Server.
xmlhttp.send(null);
No queryString passed to Server
xmlhttp.send("action=Greetings&name=Krishna");
Send querystring to the server.
If open API's third argument is false, then we will get the response in synchrnous.
If the third argument set to true then Asynchronously response will come .
How to catch the reponse which comes in asynchronously, yeah, we have a property that will help us to refer a javascript function.
xmlhttp.onreadystatechange=function(){}
whenever http connection state get change this method will be get called. There are five states possible for this XMLHTTPRequest are given below.
State | Description |
---|---|
0 | The request is not initialized |
1 | The request has been set up |
2 | The request has been sent |
3 | The request is in process |
4 | The request is complete |
Now, we have to write the program which will act based on the state.
if(xmlhttp.readyState==4){//do something for request completion.}
Sample code to play with AJAX
<html>
<body>
<script type="text/javascript">
function searchFunction(str)
{
xmlhttp=getXMLHTTP();
xmlhttp.onreadystatechange=function()
{
if(xmlhttp.readyState==4)
{
document.getElementById("searchResult").innerHTML = xmlhttp.responseText;
}
}
xmlhttp.open("GET","http://www.google.com/search?q="+str,true);
xmlhttp.send(null);
}
function getXMLHTTP()
{
var xmlhttp;
if (window.XMLHttpRequest)
{
// code for IE7+, Firefox, Chrome, Opera, Safari
xmlhttp=new XMLHttpRequest();
}
else
{
// code for IE6, IE5
xmlhttp=new ActiveXObject("Microsoft.XMLHTTP");
}
return xmlhttp;
}
</script>
<form name="myForm">
Search <input type="text" id="search" name="search" onkeyup="searchFunction(this.value);" />
<p/>
</form>
<div id="searchResult">ads</div>
</body>
</html>
For tutorials and more details : http://www.w3schools.com/Ajax/
Saturday, October 31, 2009
Java Memory Arrangements
Java Memory Arrangements
Java Memory is splitted in to three generation - Young Generation, Tenured Generation, and Permanent Generation.
- Young Generation
Infant mortality data are get stored in young generation, means any new objects created and stored here. This has One Eden and two survivor spaces, where one survivor space always empty. If data get filled in survivor space and ready to long live then it will be copied to Eden space. Usually in Solaris, two equal space alotted for eden and survivorspace.
Once the Eden space get filled then Minor Collections(Garbage Collections) get triggered and tenured objects will be copied to Tenured Generation.
Specifying bigger young generation for the application which does have more infant moratality objects, would give better performance.
- Tenured Generation
Long live tenured objects will be stored in this space. Once the Tenured generation get filled then Major collections(Garbage Collections) will be triggered. This collection costs more, because of the fact that it will operate on all long living objects. In general, keeping more space for long running applications like Application Server , would result better performance.
Major and Minor collections happened based on the tuning parameters set. In general, 40% of Heap(-Xmx) filled then major collections starts and shrinks up to -Xms value. This percentage can be reset using -XX:MinHeapFreeRatio. If the application shrinks and expands the memory allocation (malloc) then this will cost the performance. Hence, this has to be controlled and set using -XX:MaxHeapFreeRatio to some percentage, which always application needed size in the entire tenure.
Keeping -Xms and -Xmx value equal will result better performance for GUI, and server applications.
- Permanent Generation
Loaded classes and Classe definitions are get stored in this space. In general, this space will be occupied in physical memory while application start up based on the value of -XX:PermSize. Maximum size permanent generation space can be set by -XX:MaxPermSize.
If the application has more number of classes and object has to be created/loaded at the given point of time then this space has to be set high. Even this property helps to improve the performance and avoids OutOfMemoryError, which comes for PermGen space full.
Java Application Memory= Heap + PermGen Space.
In JRocket, there is no concept of PermGen Space. Hence, JRocket users no need of worrying about these properties.
Subscribe to:
Posts (Atom)
Recent Posts
Texts
This blog intended to share the knowledge and contribute to JAVA Community such a way that by providing samples and pointing right documents/webpages. We try to give our knowledege level best and no guarantee can be claimed on truth. Copyright and Terms of Policy refer blogspot.com