Java Code 39 Generator Tutorial
Generate, create barcode Code 39 images in Java Class, JSP Pages, Jasper Report, Eclipse BIRT
Download Java Barcode Generator Free Evaluation
Purchase Java Barcode Generator SDK License
This Java Barcode Generator proves very helpful for our project. Thanks a lot!
- Charly Nelson

Generate, Create, Print, Draw Code 39 barcode in Java projects

  • Easy to Generate Code 39 in Java class, Java Bean, Applet, Swing applications
  • Create Code 39 in JSP, Java Servlet, EJB, Tomcat, JBoss server side projects
  • Print, draw Code 39 barcode images in Jasper Reports, iReport & Eclipse BIRT Java reporting software
  • Generating & encoding high quality Code-39 Bar Code images in GIF, JPEG, & EPS formats formats
  • Compatible with ISO / IEC 16388 (2nd edition 2007-05-15)
  • Completely written in Java source code
  • Simple to redistribute Java Code 39 barcode library. No registration key. No activation code
  • Mature Code-39 barcode generation Java library

Java Barcode Code 39 Generator Introduction
Java Barcode Code 39 is a Java barcode generator Java library which generates industry standard Code 39 and other 1D (linear) and 2D (matrix) barcode images in Java, Jasper Reports, iReport, and Eclipse BIRT projects.

You can download the trial package of Java Barcode library, which includes compiled Java library (Jar file) to generate Code 39 in your Java program, detailed tutorial for generating barcodes in Java, and complete sample Java source code to generate Code 39 in Java class. Downloaded Java barcode generation software allows you to create and print QR Code, Data Matrix, PDF417, Code 128, Code 93, Intelligent Mail, UPC, OneCode and other linear and 2d barcodes.

Java Code 39 Generator - Barcode Code 39 Introduction

Code 39 (also known as "USS Code 39", "Code 3/9", "Code 3 of 9", "USD-3", "Alpha39", "Type 39") is a barcode symbology that can encode uppercase letters (A through Z), digits (0 through 9) and a handful of special characters like the $ sign. Code 39 is restricted to 44 characters.

Java Code 39 Generator - Barcode Code 39 Introduction

Java Code 39 Generator encodes:
  • 0, 1, 2, 3, 4, 5, 6, 7, 8, 9
  • Uppercase letters (A - Z)
  • - (Dash), $ (Dollar), % (Percentage), (Space), . (Point), / (Slash), + (Plus)
  • Code 39 Extension can encodes all 128 ASCII characters
How to Generate Code 39 in Java Class?
Below is the sample code for generating Code 39 in Java Class. You can view complete Java Code 39 Generator Demo Source Code
// Build Java Code39 barcode object 
Code39 barcode = new Code39();

// Encode Code39 data

// Generate Code39 barcode & print into Graphics2D object
barcode.drawBarcode("Java Graphics2D object");

// Generate Code39 barcode & encode into GIF format

// Generate Code39 barcode & render into JPEG format

// Draw Code39 barcode & paint into EPS image format
How to Create Code 39 image in HTML or JSP pages?
  1. Under demo package, copy barcode folder and its contents to your tomcat.
  2. Start tomcat, navigate to http://YourDomain:Port/barcode/barcode?DATA=0123456789&TYPE=CODE39
  3. To create bar code images in html or jsp pages, you can insert an image tag (img) into your page.
  4. For example, <img src="http://YourDomain:Port/barcode/barcode?DATA=0123456789&TYPE=CODE39"/>
  5. The above Java codes will not produce any Code 39 image files in your server system, using the above methods to draw Code 39 in JSP, html pages.
How to Generate Code 39 Image in Java Servlet Class?
import com.onbarcode.barcode.AbstractBarcode; 
import com.onbarcode.barcode.Code39;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import javax.servlet.ServletException;
import javax.servlet.ServletOutputStream;

public class BarcodeServlet extends HttpServlet
public void doGet(HttpServletRequest request, HttpServletResponse response) throws ServletException
try {
Code39 barcode = new Code39();

ServletOutputStream servletoutputstream = response.getOutputStream();

response.setHeader("Pragma", "no-cache");
response.setHeader("Cache-Control", "no-cache");
response.setDateHeader("Expires", 0);

// Generate Code-39 barcode & output to ServletOutputStream

} catch (Exception e) {
throw new ServletException(e);
How to Generate & Print Barcode Code 39 Image in Jasper Reports?
This Java Barcode Generator also supports generating outstanding Barcode 3 of 9 in Jasper Reports. Users only need to define the data filed in Jasper Report first and then you can create Code 39 barcodes using data from data source in Jasper Reports. Here is the Complete Guide for Barcode Generation in Jasper Reports
How to Generate & Print Barcode Code 39 Image in iReport?
You can also generate, create high-quality Barcode 3 of 9 images with this Java Barcode Generator.Detailed generation are provided by, please navigate here to view how to print barcodes in iReport?
How to Generate & Print Barcode Code 39 Image in Eclipse BIRT
How to Set Generated Barcode Code 39 Image Width and Height?
  1. You can set barcode image width and height through properties barcodeWidth and barcodeHeight values.
  2. Or you can set X (bar module width) and Y (bar module height) values
Java Code 39 Generator - Property Settings
Java Code 39 Generator - in Java Class: com.onbarcode.barcode.Code39

Category Properties Value Comments
Basic Property: data
Type: String
Default: ""
Code 39 barcode data to encode

Code 39 Valid Data Char Set:
  • 0, 1, 2, 3, 4, 5, 6, 7, 8, 9 (Digits)
  • A - Z (Uppercase letters)
  • - (Dash), $ (Dollar), % (Percentage), (Space), . (Point), / (Slash), + (Plus)

Code 39 extension Valid Data Char Set:
  • All ASCII 128 characters

Property: addCheckSum
Type: boolean
Default: false
addCheckSum property is optional for Code 39. Modulo 43 will be applied, if addCheckSum property is true.
Code 39
Property: extension
Type: boolean
Default: false
Code 39 is encoding upper case letters, if you want to encode lower case letters and other 128 ASCII characters, you need set extension property to true.
Property: I
iReport & URL: I
Type: float
Default: 1.0f
The space between 2 characters in code 39. This a multiple of X module (bar width).
Property: N
iReport & URL: N
Type: float
Default: 2.0f
Wide bar vs narrow bar ratio. Valid values are 2.0 - 3.0 inclusive, default is 2.0.
Property: showStarStopInText
Type: boolean
Default: true
If true, print a * in the beginning and end of barcode text in Code 39 barcode
Property: processTilde
Type: boolean
Default: false
Set the processTilde property to true, if you want use the tilde character "~" to specify special characters in the input data, such as non-printable chars in ASCII table.

  • 1-byte character: ~0dd/~1dd/~2dd (character value from 000 ~ 255);
    Strings from "~256" to "~299" are unused
Property: autoResize
Type: boolean
Default: false
Auto resize the generated Code 39 barcode image
Property: barAlignment
Type: int
Default: 1 (center)
Barcode horizontal alignment inside the image. 0: left, 1: center, 2: right.
Property: uom
iReport & URL: UOM
Type: int
Default: 0 (pixel)
Unit of meature for all size related settings in the Java barcode library.
Valid values: 0: pixel; 1: inch; 2: cm.
Property: X
iReport & URL: X
Type: float
Default: 1
Width of Code 39 bar module (narrow bar), default is 1 pixel
Property: Y
iReport & URL: Y
Type: float
Default: 30
Height of Code 39 bar module, default is 30 pixel
Property: barcodeWidth
Type: float
Default: 0
Generated Code 39 barcode image width.

If barcodeWidth value is smaller than the barcode required minimum width size, Java barcode library will automatically reset barcodeWidth value to barcode minimum width.
Property: barcodeHeight
Type: float
Default: 0
Generated Code 39 barcode image height.

If barcodeHeight value is smaller than the barcode required minimum height size, Java barcode library will automatically reset barcodeHeight value to barcode minimum height.
Property: leftMargin
Type: float
Default: 0
Code 39 image left margin size.
Property: rightMargin
Type: float
Default: 0
Code 39 image right margin size.
Property: topMargin
Type: float
Default: 0
Code 39 image top margin size.
Property: bottomMargin
Type: float
Default: 0
Code 39 image bottom margin size.
Property: resolution
Type: int
Default: 72
Code 39 barcode image resolution in DPI (Dots per inch).
Property: rotate
iReport & URL: ROTATE
Type: int
Default: 0 (IBarcode.ROTATE_0)
Rotate Code 39 images in 0, 90, 180, 270 angles.

Valid values:
  • 0 (IBarcode.ROTATE_0)
  • 1 (IBarcode.ROTATE_90)
  • 2 (IBarcode.ROTATE_180)
  • 3 (IBarcode.ROTATE_270)
Property: backColor
Type: Color
Default: white
Code 39 image background color
Property: foreColor
Type: Color
Default: black
Code 39 image foreground color
Property: showText
iReport & URL: SHOW-TEXT
Type: boolean
Default: true
If true, printing Code 39 encoding data below the barcode, otherwise do not print.
Property: textFont
iReport & URL: TEXT-FONT
Type: Font
new Font("Arial", Font.PLAIN, 11)
Code 39 text (printed below barcode) font style.

In Java Servlet web streaming, using the url paramter in the following format:
Property: textMargin
Type: float
Default: 6
Space between barcode and printed barcode data, default is 6 pixel
Property: textColor
Type: Color
Default: black
Barcode text (printed below barcode) color
// generate barcode and output to OutputStream object
public boolean drawBarcode(OutputStream outputStream) throws Exception

// generate barcode into a new BufferedImage object
public BufferedImage drawBarcode() throws Exception

    Use this method to generate barcode, and save into gif or jpeg files
    1. to save into gif file, filename ends with ".gif", like "c:\\barcode.gif"
    2. to save into jpeg file, filename ends with ".jpg", like "c:\\barcode.jpg"
    3. to save into png file, filename ends with ".png", like "c:\\barcode.png"
public byte[] drawBarcodeToBytes() throws Exception

public boolean drawBarcode(String imageFile) throws Exception

// Generate barcode and save into EPS file, the filename must ends with ".eps"
public void drawBarcode2EPS(String filename) throws Exception

// Generate barcode on Graphics2D object within certain area
public void drawBarcode(Graphics2D g, Rectangle2D rectangle) throws Exception
Java Barcode Generator Supporting Barcode Symbology Types
Barcode for Java - Bar Code Types Geneation
OnBarcode is a market-leading provider of barcode imaging generator, reader controls and components for ASP.NET, Windows Forms, WPF, as well Java, Android, iOS (iPhone, iPad) across all major enterprise development platforms. We provides comprehensive tutorials and how-tos for various linear, 2d barcode information, such as C# in ASP.NET, C# .NET, C# Barcode Encoding, C# Barcode Image, VB.NET in ASP.NET, VB.NET Winforms, VB.NET Barcode Encoding, VB.NET Barcode Image, Java JSP Servlet. OnBarcode barcode products are supported by RasterEdge .NET HTML5 Document Viewer high quality C# Convert PDF to Tiff, C# Convert PDF to Word, C# Convert PDF to HTML, C# Convert PDF to Jpeg images, and their easy and simple documents, like C# PDF SDK, C# extract text from PDF, C# Compress PDF, Print PDF in C# and C# extract image from PDF.
Terms of Use | Privacy Policy
Copyright © . All rights reserved.