Creating and java.util.sql objects from Calendar object

Date, time and calendar manipulation always seem to trouble average developers. Well it does for me too, sometimes. In this particular very simple tutorial, I have shown how we can create object and object from Calendar object.

import java.util.Calendar;

public class DateUsingCalendar {
	 * @param year - an integer representing the year
	 * @param month - an integer from 0-11 (Jan - Dec)
	 * @param dayOfMonth - an integer from 1-31
	public static void createDateFromCalendar(int year, int month,
			int dayOfMonth) {

		 * Creates a current calendar using
		 * the default time zone and locale.
		Calendar myCalendar = Calendar.getInstance();

		 * Resets all the attributes of calendar

		 * Let's try setting our values
		myCalendar.set(Calendar.YEAR, year);
		myCalendar.set(Calendar.MONTH, month);
		myCalendar.set(Calendar.DATE, dayOfMonth);

		 * We will try creating a new sqlDate using this
		 * Calendar Object
		java.sql.Date sqlDateObj = new java.sql.Date(

		 * We will try creating a new java util Date object
		 * using this Calendar Object
		java.util.Date utilDateObj = myCalendar.getTime();

		 * Let's try printing these dates to the console

		System.out.println("Date in sql date format: "+sqlDateObj);
		System.out.println("Date in util date format: "+utilDateObj);


	public static void main(String[] args) {
		int year=2009;
		int month=5; //June (January being 0)
		int dayOfMonth=11;
		createDateFromCalendar(year, month, dayOfMonth);

Here is the output:
Date in sql date format: 2009-06-11
Date in util date format: Thu Jun 11 00:00:00 CDT 2009

Bar Code Generation In Java Using iText API

You need to download iText.jar from in order to be able to run this Barcode Example. This tutorial is about generating various BarCode types using Java and iText API. The generated bar codes will then be exported to a PDF file. Here are the kinds of bar codes we will be generating:

      BarCode 128
      Barcode 39
      BarCode EAN
      BarCode EANS upplemental
      BarCode Inter 25
      BarCode Postnet
      BarCode PostnetPlanet

Here is the code that generates these bar codes for our website “”

 * @ Author Kushal Paudyal
 * Original Code referenced from Lowagie iText tutorial website.
package com.sanjaal.utilities;

import java.awt.Color;

import com.lowagie.text.Chunk;
import com.lowagie.text.Document;
import com.lowagie.text.Element;
import com.lowagie.text.Image;
import com.lowagie.text.PageSize;
import com.lowagie.text.Phrase;
import com.lowagie.text.Rectangle;
import com.lowagie.text.pdf.Barcode;
import com.lowagie.text.pdf.Barcode128;
import com.lowagie.text.pdf.Barcode39;
import com.lowagie.text.pdf.BarcodeEAN;
import com.lowagie.text.pdf.BarcodeEANSUPP;
import com.lowagie.text.pdf.BarcodeInter25;
import com.lowagie.text.pdf.BarcodePostnet;
import com.lowagie.text.pdf.PdfContentByte;
import com.lowagie.text.pdf.PdfPTable;
import com.lowagie.text.pdf.PdfTemplate;
import com.lowagie.text.pdf.PdfWriter;

public class BarCodeGenerator {
PdfContentByte contentByte;

public void generateBarCode() {
	/** Step 1: Create a Document*/
	Document document = new Document(PageSize.A4, 50, 50, 50, 50);

	try {

		/** Step 2: Create PDF Writer*/
		PdfWriter writer = PdfWriter.getInstance(document,
				new FileOutputStream("sanjaalDotCom_BarCode1.pdf"));

		/** Step 3: Open the document so that we can write over it.*/;

		/** Step 4: We have to create a set of contents.*/
		contentByte = writer.getDirectContent();

		PdfPTable table = new PdfPTable(2);

		String myText = ""; // Text to encode

		table.addCell("CODE 39");
		table.addCell(new Phrase(new Chunk(createBarCode39(myText
				.toUpperCase()), 0, 0)));

		table.addCell("CODE 39 EXTENDED");
		table.addCell(new Phrase(new Chunk(createBarcode39Extended(myText),
				0, 0)));

		table.addCell("CODE 128");
		table.addCell(new Phrase(new Chunk(createBarcode128(myText), 0,

		table.addCell("CODE INTERLEAVED");
		String myTextNum = "12345";
		table.addCell(new Phrase(new Chunk(createBarcodeInter25(myTextNum),
				0, 0)));

		table.addCell("CODE POSTNET");
		table.addCell(new Phrase(new Chunk(createBarcodePostnet(myTextNum),
				0, 0)));

		table.addCell("CODE PLANET");
		table.addCell(new Phrase(new Chunk(
				createBarcodePostnetPlanet(myTextNum), 0, 0)));

		String myTextEAN13 = "1234567890123";
		table.addCell("CODE EAN");
		table.addCell(new Phrase(new Chunk(createBarcodeEAN(myTextEAN13),
				0, 0)));

		table.addCell("CODE EANnWITHnSUPPLEMENTAL 5");
		table.addCell(new Phrase(new Chunk(createBARCodeEANSUPP(
				myTextEAN13, "12345"), 0, 0)));

	} catch (Exception de) {

	// step 5: we close the document

public static void main(String args[]) {
	new BarCodeGenerator().generateBarCode();

 * Method to create barcode image of type Barcode39 for mytext
public Image createBarCode39(String myText) {
	 * Code 39 character set consists of barcode symbols representing
	 * characters 0-9, A-Z, the space character and the following symbols:
	 * - . $ / + %

	Barcode39 myBarCode39 = new Barcode39();
	Image myBarCodeImage39 = myBarCode39.createImageWithBarcode(
			contentByte, null, null);
	return myBarCodeImage39;

/**Creating a barcode image using Barcode39 extended type for myText*/
public Image createBarcode39Extended(String myText) {
	Barcode39 myBarCode39extended = new Barcode39();
	Image myBarCodeImage39Extended = myBarCode39extended
			.createImageWithBarcode(contentByte, null, null);
	return myBarCodeImage39Extended;

/** Creating a barcode image using Barcode 128 for myText*/
public Image createBarcode128(String myText) {
	Barcode128 code128 = new Barcode128();
	Image myBarCodeImage128 = code128.createImageWithBarcode(contentByte,
			null, null);
	return myBarCodeImage128;

/** Creating a barcode image using BarcodeEAN for myText*/
public Image createBarcodeEAN(String myText) {
	BarcodeEAN myBarcodeEAN = new BarcodeEAN();
	myBarcodeEAN.setCodeType(Barcode.EAN13); // 13 characters.
	Image myBarCodeImageEAN = myBarcodeEAN.createImageWithBarcode(
			contentByte, null, null);
	return myBarCodeImageEAN;

/** creating a barcode image using BarCodeInter25 for myText*/
public Image createBarcodeInter25(String myText) {
	BarcodeInter25 myBarcode25 = new BarcodeInter25();
	Image myBarCodeImageInter25 = myBarcode25.createImageWithBarcode(
			contentByte, null, null);
	return myBarCodeImageInter25;

/**creating a barcode image using BarcodePostnet for myText*/
public Image createBarcodePostnet(String myText) {
	BarcodePostnet myBarcodePostnet = new BarcodePostnet();
	Image myBarcodeImagePostnet = myBarcodePostnet.createImageWithBarcode(
			contentByte, null, null);
	return myBarcodeImagePostnet;

/** creating a barcode image using BarCodeInter25 */
public Image createBarcodePostnetPlanet(String myText) {
	BarcodePostnet myBarCodePostnetPlanet = new BarcodePostnet();
	Image myBarCodeImagePostntPlanet = myBarCodePostnetPlanet
			.createImageWithBarcode(contentByte, null, null);
	return myBarCodeImagePostntPlanet;

public Image createBARCodeEANSUPP(String myTextPrimary,
		String myTextSupplementary5) {
	PdfTemplate pdfTemplate = contentByte.createTemplate(0, 0);
	BarcodeEAN myBarcodeEAN = new BarcodeEAN();
	PdfTemplate ean = myBarcodeEAN.createTemplateWithBarcode(contentByte,
	BarcodeEAN codeSUPP = new BarcodeEAN();
	BarcodeEANSUPP eanSupp = new BarcodeEANSUPP(myBarcodeEAN, codeSUPP);
	Image imageEANSUPP = eanSupp.createImageWithBarcode(contentByte, null,;
	return imageEANSUPP;

Simple Tag Generator In Java For Music Blogs

For those of you who run a music blog, you might have faced the tiresome job of writing bunch of tags, I have written this simple program in Java that generates the tags for your use. I personally developed this for my one of my Music Blogs, and I find this quite useful to generate a bunch of tags at once which I can copy paste to my WordPress based blog.

You can customize this program as required to suite your needs.

You can download the original file for free and use it for any of your purposes.

package com.kushal.utils;
 * @author KushalP
 * For those who maintain music blog, this simple program
 * might be useful for generating music tags.
 * I developed this for my personal use for my following blog:

public class SimpleTagGenerator {

	public static void main(String args [])
		 * Param 1 : Album Name
		 * Param 2 : Artist Name
		 * Param 3 : Song Name
		generateTag("Division Bell", "Pink Floyd", "Marooned");

	public static void generateTag(String album, String artist, String song)
		String artistTags="";
		String albumTags="";
		String songTags="";

		if(artist!=null && artist.length() >0 )
			artistTags+=artist +" Guitar Tabs, "+
						artist+ " Latest Songs, "+
						artist+ " MP3 Downloads,"+
						artist+ " Latest Albums, "+
						artist+ " Songs Download, "+
						artist+ " Lyrics Download, "+
						artist+ " MP3 Songs";

		if(album !=null && album.length() > 0)
			albumTags+=artist +" "+ album+" "+ "Songs Download, "+
						artist +" " +album+" "+  "MP3 Download,"+
						artist +" "+ album+" "+ "Lyrics Download, "+
						artist + " "+album+" "+  "Guitar Tabs," +
						artist +" "+album+" "+ "Guitar Chords,";		


		if(song!=null && song.length() > 0 )
			songTags+=	artist +" "+song+" "+"Guitar Tabs, "+
						artist +" "+song+" "+ "MP3 Downloads,"+
						artist +" "+song+" "+ "Songs Download,"+
						artist +" "+song+" "+ "Guitar Chords,"+
						artist +" "+song+" "+ "MP3 Song,"+
						artist +" "+song+" "+ "Lyrics Download,"+
						artist +" "+song+" "+ "Music Video";		




Here are the sample tags generated for the the parameters that I passed in the application while calling generateTag method i.e. generateTag(“Division Bell”, “Pink Floyd”, “Marooned”);

Pink Floyd Guitar Tabs, Pink Floyd Latest Songs, Pink Floyd MP3 Downloads,Pink Floyd Latest Albums, Pink Floyd Songs Download, Pink Floyd Lyrics Download, Pink Floyd MP3 Songs,Pink Floyd Division Bell Songs Download, Pink Floyd Division Bell MP3 Download,Pink Floyd Division Bell Lyrics Download, Pink Floyd Division Bell Guitar Tabs,Pink Floyd Division Bell Guitar Chords,,Pink Floyd Marooned Guitar Tabs, Pink Floyd Marooned MP3 Downloads,Pink Floyd Marooned Songs Download,Pink Floyd Marooned Guitar Chords,Pink Floyd Marooned MP3 Song,Pink Floyd Marooned Lyrics Download,Pink Floyd Marooned Music Video