Monday, May 5, 2008

Rhymes For February Birthdays

BigDecimal in

Whenever a test framework we choose the easiest route, which also implies that the use of such data types as String and Integer . However, the time comes when we must face at least some types of data including the type of floating. Experience has taught me that when it comes to Java is the best type of floating-point arithmetic operations to perform is BigDecimal. Perhaps what some of begs the question - why not double . My answer would be an example taken from the http://epramono.blogspot.com :
 public static void main (String [] args) {System.out.println 
(
"(0.1 + 0.1 + 0.1 + 0.1 + 0.1 + 0.1 + 0.1 + 0.1 + 0.1 + 0.1) =" +
(0.1 + 0.1 + 0.1 + 0.1 + 0.1 + 0.1 + 0.1 + 0.1 + 0.1 + 0.1));

double d = 0.0;
while (d <= 1.0) d += 0.1;
System.out.println ("d =" + d);

System.out . println (0.0175 * 100000 = '+ 0.0175 * 100000);}
Result Output:
 (0.1 + 0.1 + 0.1 + 0.1 + 0.1 + 0.1 + 0.1 + 0.1 + 0.1 + 0.1) = 0.9999999999999999 
d 1.0999999999999999
= 0.0175 * 100000 = 1750.0000000000002
Upss ... what an unpleasant surprise: (

but not what I'm going to write my main theme is the GWT (version 1.4.1960), and in principle support for BigDecimal type in GWT, which generally speaking is simply no. This is obviously a serious problem. .. but there is a solution:
  • go to page: http://code.google.com/p/gwt-math/ .
  • download the two libraries gwt-math-2.0.1.jar , gwt-math-server-2.0.1.jar and put them in the classpath our project.
  • In the file add MyModule.gwt.xml section:
     \u0026lt;inherits name = "com.googlecode.gwt.math.Math" /> 
  • At this end of our work, we can use classes already java.math.BigDecimal, java.math.BigInteger .

In summary, it is often the case when the situation seems to be beznadziena with the help of Google comes through which we discover that the Open Source community predicted that we come across a problem. Hence the first look better than I do in his own way:)

Friday, April 25, 2008

Fissure Versus Hemorrhoids

GWT GWT - Internationalization

If the targeted group of users of our application are people of different nationalities then we adapt it to support multiple languages. The first thing that comes to us to measure the translation of texts will be permanent. The translation of texts, we can leave the linguists, but our task is to write such applications to support these texts was possible and when adding subsequent translations do not require programming work.

course fairly quickly, each developer could work around this problem by devising its own mechanism, but the developer lazy (read: effective ) przegrzebie documentation to find a mechanism which has already been invented. How it looks in GWT ...

key element that will allow us the location of solid text is a module that is included with com.google.gwt.i18n it offers several mechanisms: Constants, Messages , ConstantsWithLookup , Dictionary , Localizable . Let us focus on two basic Constants and Messages that should be used in most cases.

If you want to take advantage of these mechanisms Our module must inherit from the module com.google.gwt.i18n.I18N (file MyModule.gwt.xml packages com.mycompany.mymodule ):

  \u0026lt;module> 
\u0026lt;inherits name = " com.google.gwt.i18n.I18N "/>
\u0026lt;/ module>
\u0026lt;extend-property name="locale" values="pl,en"/>
The next step is to create files containing the text of a permanent for the various languages \u200b\u200band the default file.

Default File MyConstans.properties (included com.mycompany.mymodule.client ):
  HelloWorld = Hello World 
goodbyeWorld = Goodbye World
file for Polish language MyConstans_pl.properties (included com.mycompany.mymodule.client ):
  = HelloWorld Hello World 
goodbyeWorld = Goodbye World
File for English MyConstans_en.properties (included com.mycompany.mymodule.client ):
  HelloWorld = "Hello World 
goodbyeWorld = Goodbye World
next step is in the package stworznie com.mycompany.mymodule.client Interface MyConstans where method names will correspond to keys in files with fixed texts:
  public interface extends Constants {MyConstants 
String HelloWorld ();
goodbyeWorld String ();}
To use our lyrics are enough two lines of code in the code the customer class (eg MyModule.java )
  MyConstants myConstants = (MyConstants) GWT.create (MyConstants.class); 
Window.alert (myConstants.helloWorld ());

second mechanism, which somehow appear to extend to Constants Messages, it differs only by the fact that the text may have solid arguments. Assume that the file ErrorMessages.properties we text:

  permissionDenied = Error {0}: {1} You do not have permission to access to {2}  
then he or she defines an interface similar to Constants but the method should have as many input arguments if it has been wymienonych constants in the texts. Interface Definition ErrorMessages.java :
  ErrorMessages public interface extends Messages {String 
permissionDenied (int errorCode, String username, String resource);}

to text to be displayed permanently in the language we have two possibilities. The first is to property setting \u0026lt;meta name="gwt:property" content="locale=pl"> directly in html page:

  \u0026lt;html> 
\u0026lt;head>
\u0026lt;meta name = "gwt: module" content = "com.mycompany.mymodule.MyModule">
\u0026lt;meta name="gwt:property" content="locale=pl">
\u0026lt;/ head>
\u0026lt;body>
\u0026lt;script src = "gwt.js"> \u0026lt;/ script>
\u0026lt;/ body>
\u0026lt;/ html> The second option
This adds a parameter to the URL:
  http://www.mycompany.com/MyModule.html?locale=pl  

mechanisms, which have been described can only be used in the code under which it is generated JavaScript (which is included in the package client). While compiling GWT generates for each location a separate JavaScript file.

sum GWT provides a fairly comprehensive mechanism of internationalization, although the mechanism would be sufficient for me Messages , because I can not immediately predict that my text will not be fixed once the arguments. Another thing that gives me a disadvantage is that you can not use these mechanisms on the server side, forcing us to use the standard solution provided by the Java ResourceBundle .

Monday, January 21, 2008

Mac Desmume Cheats Soul Silver

Equal or unequal - that is the question in GWT Wizards

Someone once said, "me in the programming language does not bother?" What makes me more is that an experienced programmer who had to deal with several languages \u200b\u200b(eg C, Java) should be no problem to deal with programming in another language (eg C #). There is a lot of truth, but is without a comprehensive knowledge of the language code for this developer will definitely reliable?

Consider a simple example written in Java:
  Integer i1 = 1000; 
Integer i2 = 1000;
if (i1 == i2) {
System.out.println ("same object");}
else

{System.out.println ("different objects");}

if (i1.equals (i2)) {
System.out.println ("values \u200b\u200bof the objects are the same");

} else {
System . out.println ("value of the objects are not the same");}
Is there anything in this example, which could lead us to think - rather not. It seems clear that the first condition will be displayed on the console "Different objects" , while the second condition "equal facilities" . The first condition will be fulfilled only if we have to deal with variables that indicate precisely the same object. The second condition is already comparing the values \u200b\u200bof these objects so the case is quite obvious.

's modify this example:
  Integer i1 = 10; 
Integer i2 = 10;
if (i1 == i2) {
System.out.println ("same object");

} else {
System. out.println ("different objects");}

if (i1.equals (i2)) {
System.out.println ("values \u200b\u200bof the objects are the same");
}

else {System.out.println ("values \u200b\u200bof the objects are not the same");}
What is it? The first condition is met the result is displayed on the console "same object" . Why? The answer is simple, although not obvious in the Java language in order to save memory class instances and Short Integer with values \u200b\u200bfrom -128 127 to point to the same object (memory area). Otherwise the situation is if we use the explicit operator new :
  Integer i1 = new Integer (10); 
Integer i2 = new Integer (10);
if (i1 == i2) {
System.out.println ("same object");}


else {System.out.println ("different objects");}

if (i1.equals ( i2)) {
System.out.println ("values \u200b\u200bof the objects are the same");}


else {System.out.println ("values \u200b\u200bof the objects are not the same");}
Then you will see "different objects" .

conclusion from this is one that without a thorough knowledge of the language constructs that might seem obvious can surprise us in the least expected time. However, there is an advice: if you are czegoś pewien sprawdź to, a jeżeli jesteś czegoś bardzo pewien sprawdź to dwa razy...