Friday, November 1, 2013

Upgraded to OSX Mavericks on my Mac

Hi,

I upgraded my Mac with OSX Mavericks.  Apple claims that they have made improvements on speed, multiple windows and yeah, they seem to have succeeded in that.

Upgradation process went smooth and it was quick and steady.

Cheers,

Ujjwal Soni

Friday, October 25, 2013

New line break problem with EPPLUS when exporting data

Hi,

Recently i have been facing an issue while exporting data  using C# and EPPLUS. I used below solution to get that done ::

Since my data is coming from stored procedure and this data is stored in a single column, i used a special character to seperate data.

ENTRY1***ENTRY2

so in excel this will be displayed as

ENTRY1
ENTRY2

if you send data from DB like for example :: ENTRY1\r\nENTRY2, it didnt work even if i convert that to a string. So, i replaced this special character in my c# code.


  int rowCnt=ws.Dimension.End.Row;
           for (int i = 1; i <= rowCnt; i++)
           {
             using (var rngs = ws.Cells["FD"+i])
             {
               var rt1 = rngs.RichText.Text;
               if (!string.IsNullOrEmpty(rt1))
               {
                 rngs.RichText.Clear();
                 rngs.Style.WrapText = true;
                 var rt2 = rng.RichText.Add(rt1.Replace("***", "\r\n"));
                 rngs.Style.WrapText = true;
               }
             }
           }


Cheers,

Ujjwal Soni

Thursday, October 17, 2013

Internationalization in Demandware

i18n / internationalization

Although internationalization (or i18n for short) covers a number of different aspects, its primaryrole is to provide pages in multiple languages. To ensure this can be achieved, one should never include language-specific text in a template or controller directly. Instead of this, one should use the Demandware property mechanism. As familiar from languages such as Java, this permits thedefinition of entities known as "property" files, which assign the actual language-specific texts to unique keys. Since Demandware loads all property files automatically, this means you always have access to the keys of all property files.

Instead of using the Resource class from Demandware, you should utilize the i18n method provided by the framework. This offers a few extensions that, among other things, permit the utilization of property file content in frontend JavaScript functions.
Sample property file ("user.properties"):

user.profile.complete.head=Complete Your Profile
user.profile.complete.promo=What is this?
user.profile.complete.buttons.next=Next

Cheers,

Ujjwal Soni

Demandware UX Studio plugin installation in eclipse

Step 1:  In Eclipse, from the main menu,  select  Help > Install New Software.
The Available Software dialog appears.

Step 2:  In the Work with field, enter the URL for your version of Eclipse:

    Indigo - http://updates.demandware.com/uxstudio_pr/3.7
    Juno - http://updates.demandware.com/uxstudio_pr/4.2

Step 3:  Select Demandware from the list and select Next. At this point Eclipse will compare the UX Studio requirements with what is available to ensure compatibility. After this process is complete,
 the Install Details dialog appears. 

Step 4:  Select the I accept the terms of the license agreements button and then select Finish. The Installing Software dialog appears showing the progress of the installation.

Step 5:  Select Yes when prompted to restart Eclipse.

Thanks,

Ujjwal Soni

Wednesday, October 16, 2013

Demandware Graphical Pipelines Disadvantages

Hi,

Below are some disadvantages i discovered while working on demandware :

The graphical pipelines have a number of disadvantages. First, they are highly static and difficult to maintain. Above all, however, it is also theoretically impossible to work on a pipeline with multiple developers. The reason for this is that even the repositioning of a single pipe let leads to changes at various places in the XML file – a file in which the pipeline is ultimately saved. This leads to a situation where conflicts that occur when merging before checking-in to a shared repository are very difficult – or impossible – to resolve. In addition, the URLs that result from the pipeline model are strictly predefined (
...demandware.../PIPELINENAME-ACTION
)

Above all, i found implementing MVC model much better and easy in comparision to Graphical Pipeline.

Comments are welcomed.

Cheers,

Ujjwal Soni

Thursday, October 10, 2013

SharePoint Vs LifeRay

Similarity between SharePoint and LifeRay
NoSharePoint Server 2010Liferay 6.0.9 CE
1SharePoint have web Part which only render in portion of the PagesLiferay have Portlet which also have same feature
2Per User Website provide by SharePoint (Standard and Enterprise Edition contain this feature)Per User custom Page is present in Liferay
3User Profile does collaboration part for SharePointOpenSocial provides collaboration plugins for LifeRay
4Finding Employee(User) is very easilyFinding Employee(User) Search is very easily
5Visual Studio 2010 IDE contain template for SharePointEllipse or Liferay Studio IDE contain template for SharePoint
6Multi tenancy is fulfilled with Farm / Site CollectionMulti tenancy is fulfilled with Department (as per Liferay )
7SharePoint Setup information is store in Database and registryLiferay Setup information is store in XML file only
8Document Versioning and Co –Worker changes can be done in SharePointLiferay Plug ins Social Office provide very similar feature in it.
Difference between SharePoint and Liferay
NoSharePoint Server 2010Liferay 6.0.9 CE
1Publishing Feature which give provision for user to have data entry pages convert into WebPagesLiferay does not have any such provision for Publishing
2Database is very complex and customization is not recommendedLiferay Database is very simple and custom query can be written on it
3SharePoint Designer give huge boost to Information Worker to work on itInformation worker need to be depend Developer for lots of activity which can be done by Information Worker
4SharePoint UI is different and learning is requireLiferay UI is very simple and easily to learn in it.
5Lots of Activity can be done without writing single line of CodePlugins can help but still user does not have lots of controls as compare to SharePoint
6User can View their Microsoft Office content in the BrowserLiferay does not have this provision in it
7SharePoint Enterprise Search is too huge and provide lots of option to filter and data gathering  and so onLiferay search is simple as compare to SharePoint Enterprise Search (Plugins can make Liferay search upto SharePoint Enterprise Search)
8Business Connectivity Service provide option for integrated with another Enterprise Product with in OrganizationLiferay does not have any such feature either Plugins or Web Service can fulfil this needs
9SharePoint Does not have chat service integrated with itLiferay have chat and lots of other service integrated with it (plugins are provided with setup)
10Microsoft Own SharePointCommunity Developed and Open Source
11Support is very Expensive from Microsoft and never come under LicenseEnterprise Edition provide Support which is part of the license
12Single Instance cannot be @ zero cost  ( Windows Server 2008 R2 , SQL Server 2008 & )Single Instance can be @ zero cost (Ubantu OS, My SQL Database)
Personnel Option
  1. Liferay is very cheap and good solution for small and mid size enterprise
  2. Liferay UI is too good and user can learn very easily
  3. SharePoint is good tools for Rich and Large organizations
  4. SharePoint have lots of feature as compare to Liferay
  5. Liferay is better than other CMS tools like Dot Net Nuke , Orchard , Word Press , Joomla or Drupal
Reference
  1. http://www.liferay .com
  2. LifeRay Development Guide
  3. LifeRay Administrator Guide
  4. http://www.microsoft.com/sharepoint

Monday, September 16, 2013

Tuesday, August 6, 2013

Copying files over network shared folder using Java

Problem :: One of my blog reader posted a problem that he cannot copy files over a network shared folder using java.

Solution :: Java alone doesn't have support for networked file sharing. But if you use a library, like Samba, then you can. 

You can check below source code which successfully copies file from my local drive to a shared network folder ::

/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */
package networkupload;

import java.io.BufferedReader;
import java.io.File;
import java.io.FileInputStream;
import java.io.IOException;
import java.io.InputStreamReader;
import java.net.InetAddress;
import java.net.MalformedURLException;
import java.net.URL;
import jcifs.Config;
import jcifs.smb.NtlmPasswordAuthentication;
import jcifs.smb.SmbFile;
import jcifs.smb.SmbFileOutputStream;

/**
 *
 * @author ujjwal
 */
public class NetworkUpload {

     public static void main(String[] args) throws IOException {
  final String userName = "Ujjwal";
  final String password = "ujjwal12345";
  final String domain = "ujjwal12345";
  //source path begins with / as i am using macbook (mac osx), in your case it will be windows drive path
  final String sourcePath = "/Developer/test.pdf";
  final String destinationPath = "smb://192.168.60.14/ftp/test.pdf";

  copyFileUsingJcifs(domain,userName, password, sourcePath, destinationPath);

  System.out.println("The file has been copied using JCIFS");
 }

 public static void copyFileUsingJcifs(final String domain,final String userName,
   final String password, final String sourcePath,
   final String destinationPath) throws IOException {


  final NtlmPasswordAuthentication auth = new NtlmPasswordAuthentication(
    domain, userName, password);
  final SmbFile sFile = new SmbFile(destinationPath, auth);
  final SmbFileOutputStream smbFileOutputStream = new SmbFileOutputStream(
    sFile);
  final FileInputStream fileInputStream = new FileInputStream(new File(
    sourcePath));

  final byte[] buf = new byte[16 * 1024 * 1024];
  int len;
  while ((len = fileInputStream.read(buf)) > 0) {
   smbFileOutputStream.write(buf, 0, len);
  }
  fileInputStream.close();
  smbFileOutputStream.close();
 }
  
}

If you face any issues implementing this code, you can contact me ::
Cheers,
Ujjwal Soni

Monday, August 5, 2013

Useful Java Utilities and Frameworks

There are so many useful Java frameworks and utilities out there that are free and open source that it boggles the mind. Here are a few of my recent favorites. Feel free to add your own to the list. There are many many more that I did not add to this list because they are very common (e.g. log4J, JUnit, etc.)
  • Joda Time Java Date/Time replacement
  • XStream “A simple library to serialize objects to XML and back again.”
  • Rome Java tools for parsing, generating and publishing RSS and Atom feeds.
  • Google Collections “a suite of new collections and collection-related goodness for Java 5.0, brought to you by Google. This library is a natural extension of the Java Collections Framework you already know and love. “
  • Google Guice (DI Framework) “Put simply, Guice alleviates the need for factories and the use of new in your Java code. Think of Guice’s @Inject as the new new. You will still need to write factories in some cases, but your code will not depend directly on them. Your code will be easier to change, unit test and reuse in other contexts.”
  • EasyMock “EasyMock provides Mock Objects for interfaces in JUnit tests by generating them on the fly using Java’s proxy mechanism.”
  • Apache Commons Tons of useful utilities for Java that I can’t pick just one.
  • GWT Java-Ajax web framework – very cool
  • JFreeChart “JFreeChart is a free 100% Java chart library that makes it easy for developers to display professional quality charts in their applications.”
  • Java Mozilla HTML Parser a wrapper around Mozilla’s HTML Parser.
  • Lucene “High-performance, full-featured text search engine library written entirely in Java.”
  • Squirrel SQL “Graphical Java program that will allow you to view the structure of a JDBC compliant database, browse the data in tables, issue SQL commands etc,”
  • NIO.2 Ok, technically not an open source framework. This is the new version of NIO that will be included in Java 7. This is what we’ll be using in place of File and many of the other classes in the java.io package. Pretty cool.

Tuesday, July 9, 2013

SQL Server 2012 Connection using Java Source code written in Jdk 1.4

I  tried many Jdbc drivers but all failed giving errors like "Unsupported Major Minor Version".  Later i found a cool driver which allows connection smoothly using jdk 1.4 source code and it compiles quite well, its also better in comparision to other drivers in terms of performance.

JSQLConnect JDBC_2.0_Driver connects fine using jdk 1.4, 1.5 source code.

If you need help/alternate, comment this post or email me.

Cheers,

Ujjwal Soni

Back-porting jtds driver to jdk 1.4

Recently, i had to connect to MS Sql server 2012 using source code compiled under jdk 1.4, so, i back-ported jtds driver to jdk 1.4, backporting process went fine but when i tried to connect it to MS Sql server 2012 using my java code, it entered into endless non-responsive loop. So, i gave up this back-porting process.

Java Secret: What is called before main.

Overview

The starting point for core java applications is the main(String[]) method. But is there any code which is called before this method and do we even need it?

The class has to be initialised

Before calling main, the static block for the class is called to initialise the class.

public class Main {
    static {
        System.out.println("Called first.");
    }
    public static void main(String... args) {
        System.out.println("Hello world.");
    }
}
prints
Called first.
Hello world.

Can we avoid having a main()

Normally, if you don't have a main() method, you will get an error. However if your program exits before calling main() no error is produced.
public class Main {
    static {
        System.out.println("Hello world.");
        System.exit(0);
    }
}
prints
Hello world.

The premain method

If you have Java agents, those agents can have a premain method which is called first. Instrument package

public static void premain(String agentArgs, Instrumentation inst);
The Instrumentation class gives the agent access to each class' byte code after it is read and before it is linked, giving the agent the option to change byte code.

One interesting feature of the Instrumentation class is the getObjectSize() which will give you the size of an object.

High performance libraries in Java



There is an increasing number of libraries which are described as high performance and have benchmarks to back that claim up. Here is a selection that I am aware of.

Disruptor library

http://code.google.com/p/disruptor/

LMAX aims to be the fastest trading platform in the world. Clearly, in order to achieve this we needed to do something special to achieve very low-latency and high-throughput with our Java platform. Performance testing showed that using queues to pass data between stages of the system was introducing latency, so we focused on optimising this area.
The Disruptor is the result of our research and testing. We found that cache misses at the CPU-level, and locks requiring kernel arbitration are both extremely costly, so we created a framework which has "mechanical sympathy" for the hardware it's running on, and that's lock-free.
The 6 million TPS benchmark was measured on a 3Ghz dual-socket quad-core Nehalem based Dell server with 32GB RAM.
http://martinfowler.com/articles/lmax.html

Java Chronicle

https://github.com/peter-lawrey/Java-Chronicle
This library is an ultra low latency, high throughput, persisted, messaging and event driven in memory database. The typical latency is as low as 16 nano-seconds and supports throughputs of 5-20 million messages/record updates per second.
It uses almost no heap, trivial GC impact, can be much larger than your physical memory size (only limited by the size of your disk). and can be shared between processes with better than 1/10th latency of using Sockets over loopback.

It can change the way you design your system because it allows you to have independent processes which can be running or not at the same time (as no messages are lost) This is useful for restarting services and testing your services from canned data. e.g. like sub-microsecond durable messaging.
You can attach any number of readers, including tools to see the exact state of the data externally. e.g. You can use; od -t cx1 {file} to see the current state.

Colt Matrix library

http://acs.lbl.gov/software/colt/
Scientific and technical computing, as, for example, carried out at CERN, is characterized by demanding problem sizes and a need for high performance at reasonably small memory footprint. There is a perception by many that the Java language is unsuited for such work. However, recent trends in its evolution suggest that it may soon be a major player in performance sensitive scientific and technical computing. For example, IBM Watson's Ninja project showed that Java can indeed perform BLAS matrix computations up to 90% as fast as optimized Fortran. The Java Grande Forum Numerics Working Group provides a focal point for information on numerical computing in Java. With the performance gap steadily closing, Java has recently found increased adoption in the field. The reasons include ease of use, cross-platform nature, built-in support for multi-threading, network friendly APIs and a healthy pool of available developers. Still, these efforts are to a significant degree hindered by the lack of foundation toolkits broadly available and conveniently accessible in C and Fortran.

The latest stable Colt release breaks the 1.9 Gflop/s barrier on JDK ibm-1.4.1, RedHat 9.0, 2x IntelXeon@2.8 GHz.

Javolution

http://javolution.org/ Javolution real-time goals are simple: To make your application faster and more time predictable! That being accomplished through:
  • High performance and time-deterministic (real-time) util / lang / text / io / xml base classes. 
  • Context programming in order to achieve true separation of concerns (logging, performance, etc). 
  • A testing framework addressing not only unit tests but also performance and regression tests as well. 
  • Straightforward and low-level parallel computing capabilities with ConcurrentContext. Struct and Union base classes for direct interfacing with native applications (e.g. C/C++). 
  • World's fastest and first hard real-time XML marshalling/unmarshalling facility. Simple yet flexible configuration management of your application. 

Trove collections for primitives

http://trove.starlight-systems.com/
The Trove library provides high speed regular and primitive collections for Java.
The GNU Trove library has two objectives:
  • Provide "free" (as in "free speech" and "free beer"), fast, lightweight implementations of the java.util Collections API. These implementations are designed to be pluggable replacements for their JDK equivalents.
  • Provide primitive collections with similar APIs to the above. This gap in the JDK is often addressed by using the "wrapper" classes (java.lang.Integer, java.lang.Float, etc.) with Object-based collections. For most applications, however, collections which store primitives directly will require less space and yield significant performance gains.

MG4J: Managing Gigabytes for Java™

http://mg4j.dsi.unimi.it/
MG4J (Managing Gigabytes for Java) is a free full-text search engine for large document collections written in Java. MG4J is a highly customisable, high-performance, full-fledged search engine providing state-of-the-art features (such as BM25/BM25F scoring) and new research algorithms.

Other links

Overview of 8 performance libraries

http://www.dzone.com/links/r/8_best_open_source_high_performance_java_collecti.html
Sometimes collection classes in JDK may not sufficient. We may require some high performance hashtable, Bigarrays etc. Check out the list of open source high performance collection libraries.

Serialization benchmark

http://code.google.com/p/thrift-protobuf-compare/wiki/Benchmarking
This is a comparison of some serialization libraries.
Its still hard to beat hand coded serialization.

Art of Programming

I have been wondering whether my blog has more to do with art than practical purpose. I say this because I want to blog to simulate ideas rather than be a how to guide on things which most people will possibly never have a need for.
There are only two reasons we create art: for ourselves and for others
-- Brenda Behr
Art has no other purpose than to brush aside... the conventional and accepted generalities, in short everything that veils reality from us, in order to bring us face to face with reality itself.
-- Henri Bergson
Art is the perpetual motion of illusion. The highest purpose of art is to inspire. What else can you do? What else can you do for any one but inspire them?
-- Bob Dylan
Art for art's sake, with no purpose, for any purpose perverts art. But art achieves a purpose which is not its own.
― Benjamin Constant, 1804
My view is that art cannot be created purposely, and it has no direct function. However, it has an important role which is to stimulate creative thinking and stimulate a positive mind set.
Computer science and engineering is often seen as all about creating software with a purpose, so art may be forgotten. Computer science is a adolescent science and I would argue art plays its part in simulating innovation and improving productivity. How are we to find innovation and productivity which can make a dramatic different to performance, user experience or lower development times? I would say this is where art plays an important role.
Every child is an artist. The problem is how to remain an artist once we grow up
-- Pablo Picasso
In computer science, there is so much to learn all the time. There is constant change. Children acquire knowledge very easily compared with adults and I think its important to approach computer science like a child to keep up and to develop new ideas.
How do we do this?
  • Work on interesting things which will stimulate and challenge you for its own sake.
  • Take time out regularly to try new ideas
  • When you come back to your work, keep the momentum and excitement
  • Look for opportunities to improve things and improve them, don't wait to be asked.
    Do it for your own sake (and for the sake of the project)
  • If you have children, look at the way they learn. You could learn something from them.

Life is Art
--Ujjwal


 

UI Controls for Java

go for
  1. Qt Jambi
  2. jgoodies
  3. SwingX
  4. SWT
  5. NetBeans Platform
  6. Eclipse Rich Client Platform
You can also use New Kendo Framework introduced by Telerik.

I think it depends in the IDE you are using. WebLogic has custom controls (http://download.oracle.com/docs/cd/E13196_01/platform/docs81/isv/controls.html) as well as instructions on how to create your own custom controls.

Cheers,

Ujjwal Soni