Skip to main content

Posts

Showing posts from March, 2014

A Quick Java Decompilers Comparison in the Case of String Concatenation

Introduction Java decompilers are great tools to give insight about efficiency of compiled code. Currently there are two popular java decompilers: cavaj and jd-gui. Comparison Case It is a well-known fact that concatenation of strings is not an efficient way of building strings using some number of other string obects. Since string objects are immutable, each concatenation creates a new string, this will continue until final string object is created. All created string objects other than the final one, are intermediate objects and nothing but garbage. For this reaseon java compiler converts string concatenations into StringBuilder statements. Using decompilers lets see if this is really true. Below are the original source code and decompiled versions of original code using two decompilers. // original source code logger . debug ( "bulkId:"   +  bulkId  +   " is TIME_RULES_VIOLATED..." ); logger . debug ( new  StringBuilder ( "bulkId:&qu

Java Application as Windows Service

  Introduction In cases when it is needed to run application in background and to start whenever system starts then it is required to make it a service. In windows platform an application needs to have service capabilities such as start, stop and status to run it a service.  For java applications this capability is not inherent and a wrapper application is needed to achieve this.  Apache Commons-Daemon  project is one common tool for this.   Steps 1-        Java Application needs to implement  org.apache.commons.daemon.Daemon  interface.   public   class  ServiceWrapper  implements  Daemon  {      private   final   static  Logger logger  =  LoggerFactory . getLogger ( ServiceWrapper . class );      private   static   final  ServiceWrapper serviceWrapper  =   new  ServiceWrapper ();      static   void  main ( String []  args )   throws  Exception  {         String mode  =  args [ 0 ];         logger . info ( "ServiceWrapper main started" );    

JPA Entity Utils

Introduction This tool uses hibernate-tools to generate JPA entity classes and schema exports. My IDE was not supporting Entity generation and I needed a small tool to generate entities. Resultant tool is 9MB size and capable of both generating entity classes from database connection and generating sql schema from entity classes. Application Schema Exporter uses  org.hibernate.tool.hbm2ddl.SchemaExport  to create table DDL definitions and executes them in provided db connection by reading JPA entity classes. Pojo exporter uses  org.hibernate.tool.hbm2x.POJOExporter  to connect a jdbc connection and generate entity classes using reverse engineering. Hibernate.reveng.xml file can be provided to limit tables to generate pojo files. For more information about hibernate tools see  http://docs.jboss.org/tools/latest/en/hibernatetools/html/ant.html Conclusion Project files and application binaries can be downloaded from sourceforge site. Project fi