Set Barcode Checksum using Java

This short guide explains how to set a barcode checksum using Java. It has details to set the IDE, a list of steps, and a sample code to implement a checksum in barcode using Java. You will learn the behavior of different types of barcodes with and without checksum using the sample code in this guide.

Steps to Apply Barcode 128 Checksum using Java

  1. Set the environment for using Aspose.BarCode for Java to apply the barcode checksum
  2. Import the barcode generation modules from the configured barcode library
  3. Create the BarcodeGenerator instance by providing the encode type and barcode text
  4. Set the flag to remove the checksum and create the barcode image
  5. Set the flag to add a checksum and create the barcode image

These steps define the process of adding or removing the barcode checksum. Create the BarcodeGenerator object by setting the EncodeType and text for the barcode, and save the barcode image by disabling the checksum. In the next steps, enable the checksum and generate the barcode image.

Code to Add Code 128 Checksum using Java

The above sample code can be used to set the UPC checksum using Java by setting the EncodeTypes enumerator value to UPCA. The try catch() block is used for removing the checksum, as many encoding types require the checksum to be mandatory. If we disable the checksum, the barcode generation raises exceptions like UPCA, GS_1_CODE_128, CODE_128, SCC_14, and ISBN, etc.

This article has guided us to enable/disable checksums and handle exceptions for those barcodes that require a mandatory checksum. To change the QR code color, refer to the article Change QR code color using Java.

 English