Friday, November 9, 2012

Some Smart Social Media Marketing Tips

In today world, social media is the finest and essential way to market your business successfully. It is not an easier task especially with the lack of proper knowledge and understanding about different social media marketing strategies. There is large number of social media networks such as twitter, Google plus, Facebook, my space and so on which act as the powerful medium to market business and this is the reason  many business are hiring digital media agency that are expert in marketing strategy to market your business on social media. For some extent you can also do social media marketing of your business, here are some smart tips for social media marketing:

Post content which your target audience like to read not the content which you like to read. Many beginners write content based on their taste without considering type of the audience they are writing. Blogging about being businessman is good if your audience are business owners.
Determine social media marketing return on investment by examining and comparing return on investment on other advertising methods. Instead of comparing each and every thing, it will be better to compare the amount of traffic different channels are driving to your site.
Offer mobile check-in deals to provide products and services

Tuesday, November 6, 2012

Simple Java program to Watermark an Image

A watermarking is a technique that allows an individual to add copyright notices or other verification messages to digital audio, video, or image signals and documents. It  may be visible, hidden, or a combination of both. Lets see how it can be achieved using a simple Java program. Below is the simple code however you can customize it according to your requirement.

Please see the self explanatory Java program below.

MySQL - JDBC example for BLOB storage

A blob (binary large object) is a collection of binary data stored as a single entity in a database. Blobs can be used to store images, audio or other multimedia files. There are four variation of blob datatype -
  • TINYBLOB - Maximum length of 255 (2^8 - 1) characters i.e 25 bytes
  • BLOB - Maximum length of 65535 (2^16 - 1) characters i.e 64 KB
  • MEDIUMBLOB - Maximum length of 16777215 (2^24 - 1) characters i.e 16 MB
  • LONGBLOB - Maximum length of 4294967295 (2^32 - 1) characters i.e 4GB

About the example: We will create a table in mySql and see how to insert/reterive an image using JDBC.

First lets create a table in MySQL. Please see the syntax below, we have used MEDIUMBLOB as it would be sufficient for medium size object stotage. You can use any other as per your requirement. We have just 3 columns pic_id as a auto increment primary key, pic_name will hold the picture name and pic_file a blob which will store actual picture.

CREATE TABLE blobtest (
PRIMARY KEY (pic_id),
pic_name VARCHAR(100) NOT NULL,

Monday, November 5, 2012

How to iterate Java object in JavaScript using JSON?

You may require passing a java object to javascript and iterating through it. Java object could be literally anything whether it List, Map, List of Map, Map of List etc.
For example: ArrayList<String>, Hashtable<String,String>, ArrayList<Hashtable<String,String>>, Hashtable<String,ArrayList<String>> etc.

This can be easily achieved using JSON. To run below JSP you need to include json-simple-1.1.1.jar in classpath. Download the JAR file from

About the example: In below example I have created a java object i.e. HashMap<String, ArrayList<String>>. Add some values to the object. Convert the object into JSON string using method JSONValue.toJSONString(). In JavaScript pass the JSON string to JSON.parse() and get the corresponding JavaScript object. Now you are ready to iterate it using below syntax. Please see the self explanatory example below.

Friday, November 2, 2012

Convert an object to json string and vice versa in Java and Javascript

Today we will see how to convert an object to json string and vice versa. An object could be JSONObject or any Java Object for example Map of list, List of map etc. Also please see my earlier post on Java Examples for JSON encoding, click here.

Note - To run below examples you need to include json-simple-1.1.1.jar in classpath. Download the JAR file from

Example 1 : Convert JSONObject to JSON String and vice versa

Output :


Thursday, November 1, 2012

JSTL: How to access fmt:message from Javascript

You might have seen How to use fmt:message and ResourceBundle from JSP and Java in my earlier post, click here.

Now we will see how to use fmt:message from Javascript. Its very simple to use JSTL's fmt tag in JavaScript to localize alert messages.

I found two ways in which you can access values from a property file in javascript. Please see the sample codes below.

Method 1.

<%@ taglib uri="" prefix="fmt"%>
<script type="text/javascript">
var msg = {
prop1: "<fmt:message key="prop1" />",
prop2: "<fmt:message key="prop2" />"

function test() {  


Method 2.

<%@ taglib uri="" prefix="fmt"%>
<script type="text/javascript">
<fmt:message key="prop1" var="prop1"/>    
var prop1 = "${prop1}";

function test() {