Nice little library to do this is located at http://www.barcodelib.com/java_barcode/main.html…
import com.barcodelib.barcode.*;
public class MyBarCode {
public static void main (String args[]) throws Exception {
Linear barcode = new Linear();
barcode.setType(Linear.UPCA);
java.util.Random r = new java.util.Random();
String str = new Integer(Math.abs(r.nextInt())).toString();
StringBuilder sb = new StringBuilder();
for (int toPrepend=11-str.length(); toPrepend>0; toPrepend--) {
sb.append('0');
}
sb.append(str);
String s = sb.toString();
System.out.println(s);
barcode.setData(s);
barcode.renderBarcode("c://barcode.gif");
}
}