Thursday, December 10, 2009

BigDecimal trim trailing zero

BigDecimal b = new BigDecimal(10.0000);
BigDecimal b1 = new BigDecimal(10.0200);

System.out.println(" Output B "+b.toPlainString());
System.out.println(" Output B "+b.toEngineeringString());
System.out.println(" Output B "+b.stripTrailingZeros());
System.out.println(" Output B "+b.doubleValue());


System.out.println(" Output B1 "+(b1.toPlainString()));
System.out.println(" Output B1 "+(b1.toEngineeringString()));
System.out.println(" Output B1 "+(b1.stripTrailingZeros()));
System.out.println(" Output B1 "+(b1.doubleValue()));

------------------------------------------
Output B 10
Output B 10
Output B 1E+1
Output B 10.0


Output B1 10.019999999999999573674358543939888477325439453125
Output B1 10.019999999999999573674358543939888477325439453125
Output B1 10.019999999999999573674358543939888477325439453125
Output B1 10.02


---------------------------------------------
Fetching the double value from the big decimal gives the desired result.

The exponential format is not desirable for the UI.

Thursday, September 10, 2009

JVM Bind Exception Port Already In Use (Windows)

a) To find the application that is using the port in windows use this command from the prompt: netstat -a -n -o

b) The next step is to kill that application or process that is using that port. Use the taskkill command from the prompt: taskkill /F  /PID 1056 where 1056 is the process id.


Friday, July 31, 2009

JSF Immediate Attribute

Here is a good explanation of the JSF immediate attribute from the apache my faces wiki

http://wiki.apache.org/myfaces/How_The_Immediate_Attribute_Works


Friday, July 17, 2009

http://xfront.com

xfront.com sheds some really good insights on XML schema namespace managing and versioning, and strategies to adopt.

Thursday, July 16, 2009

Normative Architecture

A normative architecture is one based on codes and communications.

a) Where naming patterns of objects can be applied.
b) XML Schemas can be used within an organization so that different systems can be adaptive to change(s) within an organization.
c) A central normative repository in an project would also be very usefull in terms of applying security, and modularising products.
d) In my mind even certain apsects of the frameworks, if it is backed by a database design would allow it to scale and also be descriptive. One can argue that frameworks can also reflect/extend or other ways and capture this information, however there would be more control over what can be added and prevented when a framework si backed by db schema.

Just reading up on architecture ... and gathering some points.





Monday, July 13, 2009

One To Many Pattern

When you have an one to many design paradigm. Any code re-factoring that you should apply that involves fixes to be done on the many side should be done on the originating point of the code base.

Friday, July 10, 2009

Software Engineering (List Of Books)

Here is a good list of books for software engineering (http://0rencs.blogspot.com/2008/02/good-reading-material.html)

In addition, this also looks like a good book (http://www.amazon.com/gp/product/0849322960/ref=sip_pdp_dp_2)

Product Development Link from MIT open course ware (http://ocw.mit.edu/OcwWeb/Sloan-School-of-Management/15-783JSpring-2006/LectureNotes/index.htm)

Different perspectives on product development (http://www.ulrich-eppinger.net/)




Thursday, July 9, 2009

CodeNaut: Tabbed Command Window (Windows)

CodeNaut: Tabbed Command Window (Windows)

Tabbed Command Window (Windows)

For regular desktop development where you need to have multiple command windows open I found this http://sourceforge.net/projects/console/ utility very usefull.

a) Name your command windows and set default locations, and open them as a tab.
b) Set wallpapers for command windows.
c) Copy and paste text. 

I wish you could highlight specific words in the command window that will be a cool feature to have.


Simple Double Dimension Array Example

The following is an example for a single column...

final class cat{
    
    cat(String catName){
        this.catName = catName;
    }
    
    public String catName;
    
    public String getCatName(){
        return this.catName;
    }
    
    public void setCatName(String catName){
        this.catName = catName;
    }
    
    public String toString(){
        return this.catName;
    }
}

 java.util.ArrayList<cat> catList = new java.util.ArrayList<cat>();
 cat a = new cat("a");
 cat b = new cat("b");
 cat c = new cat("c");
 cat d = new cat("d");
 cat e = new cat("e");
 catList.add(a);
 catList.add(b);
 catList.add(c);
 catList.add(d);
 catList.add(e);
 
 for(int i = 0 ; i < catList.size(); i++){
     cat ref = catList.get(i);
     System.out.println(" Cat List "+ref.toString());
 }
 
 Object[][] dubdim = new Object[catList.size()][1];
 for(int i = 0; i < dubdim.length; i++){
     dubdim[i][0] = catList.get(i);
 }

 for(int i = 0; i < dubdim.length; i++){
     System.out.println(dubdim[i][0]);
 }

 
 
 

Tuesday, May 5, 2009

Publish DB Documentation using Schema Spy

You can create database documentation and relationship diagrams in a jiffy using
"Schema SPY". Schema Spy allows you to generate the metadata about the database and all sorts
of statistics that are helpfull at a glance. It supports multiple databases to generate the schema documentation of course if you are a java developer it should be more simpler, to get this configuration working.


You may optionally need a graphical library to draw the relationships called graphviz.

Other dependencies are to have the driver jar files in the class path and execute the schema spy jar from the command line.

Thursday, April 30, 2009

Multiple Faces-Config.xml in your JSF application.

Modular JSF code.

Facelets are a great templating tool for JSF and can also give performance benefits when you properly structure the way you load the pages.

If you want to modularize your web application by packing the backing beans in separate jar files, the JSF specification allows you to do that. All you have to do is pack the beans in a separate jar

file and in the META-INF folder you put your faces-config.xml file. According to the JSF specification all the jar files that contain a faces-config.xml are also automatically loaded.

You can also pack the jsp files that are specific to the module in the same jar. The trick you define a custom class that implements "com.sun.facelets.impl.ResourceResolver" interface and in your web.xml file add the facelet parameter to tell your web app to use the new custom resource resolver.


<code>
<context-param>
<param-name>facelets.RESOURCE_RESOLVER</param-name>
<param-value>my.very.small.company.CustomResourceResolver</param-value>
</context-param>
</code>


The resource resolver has one single method to implement and here is a snapshot of that code.


<code>
public URL resolveUrl(String path) {
try {
if(null != path && path.contains("/CUSTOM_INCLUDE/")){
path = path.substring(path.indexOf("/CUSTOM_INCLUDE/") + 20);
URL url = THISCLASS.class.getClassLoader().getResource(path);
return url;
}
// Default ResourceResolver
return Resource.getResourceUrl(FacesContext.getCurrentInstance(), path);
} catch (IOException e) {
throw new FacesException(e);
}
}
</code>


Though this mechanism works for the jsp pages and the java files as separate sub modules, if the code depends on CSS or java script then that does not get included properly. A new framework is available on java.net called "weblets" that looks much better than the above approach.

Debugging MySql queries using My-Sql proxy.

MySql introduced a cool new utility called MySql proxy which allows you to route the queries to the database via a proxy.

The proxy utility has a lot of features and one of the very basic features is to log the queries that are routed through it and log the time taken for the query execution. This helps when you want to tune the application.

Download the utility and unzip it to a location, configure the proxy port as mentioned in your datasource and configure the original database port in your proxy. It comes bundled with a few sample scripts supported by a programming language called "lua" (btw just heard about this ). Dont worry about the new programming language, the sample scripts are good enough to get you started.


Another surprise bonus was if you have hibernate /other applications in your web layer you can see how many queries that are run against the database.

Thursday, March 5, 2009

Encoding URL's to access a resource over HTTP in Java

In java the URI class is more flexible to construct much more flexible URL's and also supports encoding.

URI uri = new URI("http","localhost","/temp/XYZ.xsd",null);
URL url = uri.toURL();
URLConnection urlConnection = url.openConnection();
urlConnection.setDoOutput(true);    

Quote from the sun documentation "The recommended way to manage the encoding and decoding of URLs is to use URI, and to convert between these two classes using toURI() and URI.toURL()."  I did see this only on the 1.5 version not on 1.4 version of the doc. 

Setup apache to serve xml files.

Apache by default is configured to serve html files, if you want to setup Apache to serve other files then you have to edit the "httpd.conf" file. This file is usually located in your apache installation folder conf directory, open the file using notepad search for the following tag "<IfModule mime_module>" within this tag you have to tell apache to serve other content types, you have to add the new type that you want to publish with the following values

    AddType application/xhtml+xml .xhtml .xml

    AddEncoding xhtml xml

The first variable defines the type of media and the second tell the encoding that you want to use, this will instruct the browser to handle these media types respectively. For a list of registered media types see here.