Create Excel File in Java using Apache POI Library

Author posted by Jitendra on Posted on under category Categories JAVA and tagged as Tags , , , with 5 Comments on Create Excel File in Java using Apache POI Library

Recently, I came across requirement to create ExcelSheet from thin Java Client used by Salesforce. So, I though to share my experience on Creating Excel Sheet in Java. As we know that Java is product of Oracle and Excel is product of Microsoft. Off-course, There will be no standard functionality available in Java to achieve our requirement of creating Excel Sheet. However thanks to Apache for their POI Library. POI Stands for “Poor Obfuscation Implementation” as the file formats created by this library is obfuscated poorly with help of reverse Engineering. Anyways, we don’t have to bother about it and thankful to them for providing such wonderful library.

Apache POI library can be used to create Excel Sheet, Word Document and PowerPoint. In this post, we will be totally focusing on Excel Sheet using “XSSF (XML Spreadsheet Format)” component.

Prerequisite :
Add all jar files downloaded from Apache POI download site in Java Program’s build path. Continue reading “Create Excel File in Java using Apache POI Library”

Creating First Application in Heroku using Eclipse

Hello Readers, in this article we will see step by step procedure to deploy your first (Hello World) program in Heroku. There are two ways, first going through series of Commands of “Heroku” and “GIT” and other simple and smart way is to use Eclipse Capability with Heroku. To make things easier we will go by second method.

!Deprecated!

This tool / blog post is deprecated. Please follow this guide to deploying applications to Heroku from Eclipse. If you still want to follow this post, then download Eclipse plugin for Heroku from here.

Prerequisites:

Installation and Set up:
First we will need to Install Heroku Plugin in Eclipse. To install it, Navigate to “Help | Install New Software” and click on “Add” button.

Give any name in website like “Heroku Plugin” and enter this URL in Location https://eclipse-plugin.herokuapp.com/install and click on “Ok” and Finish Installation. It will install the Heroku Plugin required to start your first Plugin.

Next step is setting up your Credentials for Heroku :

Navigate to “Window | Preferences | Heroku”, Here either enter your UserName and Password of Heroku Account and click on “Login” or enter you API key, which you can find by logging into your Heroku Account.

Setting up Credentials for Heroku in Eclipse
Setting up Credentials for Heroku in Eclipse

Continue reading “Creating First Application in Heroku using Eclipse”

Merge PDF in Salesforce Using Java, ITextPDF and OAuth 2

Its long time, since i wrote any article because of my busy schedule However this time i came with advance one. In this article we are going to use the J2EE (Servlet) to Merge PDF attachment inside salesforce with the help of OAuth and ITextPDF jar file. The reason of writing this article is that there is no native support by Apex to merge two attachments in Salesforce. Either we have to go for AppExchange product like CongaMerg or Drawloop or we can write our own code in any other language like Java and C# and with the help of REST API we can save get and save attachment in Salesforce.

First we will need to setup the OAuth permission so that our local J2EE application can interact with Salesforce. For this login to Salesforce account and Navigate to “Set up | App Set up | Develop | Remote Access” and enter the information. Be careful about the “Callback URL”. It must match in your code. After creating the “Remote Access”, note “Consumer Key” and “Consumer Secret” which will be needed in your code.

Update : “Remote Access” is renamed to Connected App. So throughout this article, if you see image of “Remote Access” then please consider it as Connected App.

Create Remote Access in Salesforce.com for OAuth 2
Create Remote Access in Salesforce.com for OAuth 2

Continue reading “Merge PDF in Salesforce Using Java, ITextPDF and OAuth 2”

Simple guide to setup SSL in Tomcat

Author posted by Jitendra on Posted on under category Categories JAVA, JSP, Servlet and tagged as Tags , , with 1 Comment on Simple guide to setup SSL in Tomcat

I have enabled SSL in tomcat many times however initially I struggled to get it in running condition. So I thought to share a simple approach I am following now days.

Step 1:

Run tool “Keytool“ provided by the JRE to create a “keystore file”.
The command to run tool is:

keytool -genkey -alias tomcat -keyalg RSA -keystore D:/.keyStore

Where “D:/.keystore” is the path where file should be created.
Instead of alias “tomcat” any other name can be used.
After running above command, you will be asked many questions, so answer them correctly as shown in below image:

Tomcat SSL keytool to create keystore file
Tomcat SSL keytool to create keystore file

Remember the password provided, as it will be needed in next step. Continue reading “Simple guide to setup SSL in Tomcat”

Complete Salesforce Deployment Guide using Ant Migration Tool

Step by Step tutorial of Salesforce Migration using ANT tool with Proxy settings and retrieving content from Salesforce Organization

Following are the three ways to Migrate code, objects, schema etc… from organization to another :

  1. Change sets (From Salesforce site)
  2. Eclipse (Using “Deploy to force.com server” option in Eclipse)
  3. ANT (Java based tool)

We are going to discuss the ANT based migration, step by step:

Prerequisite:
JDK 1.5 or above

Step 1:
Download ANT distribution from – “http://ant.apache.org/bindownload.cgi

Step 2:
Set Environment variable “ANT_HOME“. The path should be of parent folder of “bin”. Also add the “bin” folder to your path.

Step 3:
Check whether ANT is installed or not properly by running command “ant -version“. It might be possible that you receive message something like “unable to find tools.jar“. You can copy this jar from “JDK_HOME/lib/tools.jar” to “JRE/lib” folder.

Continue reading “Complete Salesforce Deployment Guide using Ant Migration Tool”

Pass by Value and Pass by Reference

Author posted by Jitendra on Posted on under category Categories Apex, JAVA and tagged as Tags , with 4 Comments on Pass by Value and Pass by Reference

This topic has always been part of discussion where the answer is not satisfactory and convinced to others. Using this article, I will try to explain the concept of parameter passing in Apex Method. This Complete topic is applicable for Java also.

Before moving ahead let’s have a summary on what is “pass by value” and “pass by reference”.

“Pass by value” means when a method is called, a second copy of the parameter variable is made in memory, and this copy is passed to the method as a parameter. This copy can be modified in the method, but the original variable in the caller is unchanged, and the changes to the copy are lost upon return.

“Pass by reference” means when a method is called, that actual variable is passed to the method.

Question: parameters in method are passed by value or pass by reference?
Maximum answers: primitive data types like Integer, Double are pass by value and Objects are pass by reference.
However, the above statement is not perfect.

Correct Answer: parameters are passed by value in Apex as well as in Java. Where, in case of object the copy of reference is first made and then passed, therefore we can change the fields of object inside method however we cannot change the Object itself.
Let’s discuss this in more detail. I am going to explain two scenarios in which I will try to change the field value and in second example I will try to change Object itself. Continue reading “Pass by Value and Pass by Reference”

How to create Immutable Class in Java

Author posted by Jitendra on Posted on under category Categories JAVA and tagged as Tags , with Leave a comment on How to create Immutable Class in Java

creating the Immutable class in Java with simple source code example

We have heard the word “Immutable class” lots of time in Java. The best example is class “String“. Immutable class is the class whose value cannot be changed throughout the life cycle. We cannot change the content of String class, everytime new reference is created when we change the content, that is the basic difference between String and StringBuffer Class.
In this article, i will explain the step by step process to create the custom Immutable class in Java.
Our class should not able to derived and for that we will declare our class as final. The values cannot be change and thats why we will declare all the variables as final and we will provide only the getter methods as we cannot write setters because of final variables.
So to summarize, following steps needs to be taken: Continue reading “How to create Immutable Class in Java”

Create SOAP message using Java

Author posted by Jitendra on Posted on under category Categories JAVA and tagged as Tags , , with Leave a comment on Create SOAP message using Java

Step by Step Example of creating SOAP Message using core Java API

In this article, i am going to create the SOAP Message by using core Java Only. SOAP Stands for ” Simple Object Access Protocol”, which is used to exchange the structured information via Webservices.

SOAP Message consist of following three parts:

  1. SOAP-ENV:Envelope
  2. SOAP-ENV:Header
  3. SOAP-ENV:Body
SOAP Message Format for Web Services
SOAP Message Format for Web Services

Continue reading “Create SOAP message using Java”

Quartz framework tutorial with example – Schedule job in Java

Author posted by Jitendra on Posted on under category Categories JAVA and tagged as Tags , with 6 Comments on Quartz framework tutorial with example – Schedule job in Java

Tutorial of the Quartz framework for Java. Schedule job without loosing the performance of the application

What is Quartz?

Quartz is a job scheduling system that can be integrated with, or used along side virtually any other software system. The term “job scheduler” seems to conjure different ideas for different people. As you read this tutorial, you should be able to get a firm idea of what we mean when we use this term, but in short, a job scheduler is a system that is responsible for executing (or notifying) other software components when a pre-determined (scheduled) time arrives.
Quartz is quite flexible, and contains multiple usage paradigms that can be used separately or together, in order to achieve your desired behavior, and enable you to write your code in the manner that seems most ‘natural’ to your project.
Quartz is very light-weight, and requires very little setup/configuration – it can actually be used ‘out-of-the-box’ if your needs are relatively basic.
Quartz is fault-tolerant, and can persist (‘remember’) your scheduled jobs between system restarts.
Although Quartz is extremely useful for simply running certain system processes on given schedules, the full potential of Quartz can be realized when you learn how to use it to drive the flow of your application’s business processes.

Why not just use java.util.Timer?
Since JDK 1.3, Java has “built-in” timer capabilities, through the java.util.Timer and java.util.TimerTask classes – why would someone use Quartz rather than these standard features?
There are many reasons! Here are a few:

  1. Timers have no persistence mechanism.
  2. Timers have inflexible scheduling (only able to set start-time & repeat interval, nothing based on dates, time of day, etc.)
  3. Timers don’t utilize a thread-pool (one thread per timer)
  4. Timers have no real management schemes – you’d have to write your own mechanism for being able to remember, organize and retrieve your tasks by name, etc.

Continue reading “Quartz framework tutorial with example – Schedule job in Java”

Step By Step Hibernate Tutorial Using eclipse WTP

Author posted by Jitendra on Posted on under category Categories Hibernate, My SQL and tagged as Tags , with 30 Comments on Step By Step Hibernate Tutorial Using eclipse WTP

Step By Step Hibernate (ORM Tool) Tutorial Using eclipse WTP

Hibernate is the ORM tool widely used in java community to persist the java object using Object Relational Mapping (ORM) concept. ORM reduces number of lines to interact with database with optimized query language which is Hibernate Query language (HQL).

In this example, we will create a simple login application using hibernate tool of eclipse. We will use eclipse WTP (Web Tools Platform), to install “Hibernate Tools”. Follow below steps :

In Eclipse IDE, menu bar, select “Help” >> “Install New Software …” put the Eclipse update site URL “http://download.jboss.org/jbosstools/updates/stable/helios”

Eclipse Install New Software - Hibernate
Eclipse Install New Software - Hibernate

Continue reading “Step By Step Hibernate Tutorial Using eclipse WTP”