There are some good tips , but a lot of mistakes in this artical: Using byte instead of integer does not reduce the jar size, rather it reduces the heap size. Changing "zip settings" does not reduce jar in anyway Try different visibility modifiers of members and methods - really need to clarify that advise... what modifier changes exactly make jar smaller? "If it is possible try to combine all variables or class members of the same type in the array" again this is a heap reduction, not jar size
public class InlineMe {
private boolean b = false;
private int ints[] = null;
public boolean isB() {
return b;
}
public void setB(boolean b) {
this.b = b;
}
protected int[] init(int r, int len){
ints = new int[len];
for (int i = 0; i < ints.length; i++) {
ints[i] = r;
}
return ints;
}
public void print(){
for (int i = 0; i < ints.length; i++) {
int anInt = ints[i];
System.out.print("anInt = " + anInt+" ");
}
System.out.println("");
}
}
public class Main {
private static final int LEN = 6;
// public int[] ints;
int i1 = 5;
int i2 = 5;
int i3 = 5;
int i4;
public static void main(String[] args) {
InlineMe ims[] = new InlineMe[LEN];
Main m = new Main();
m.i4 = 5;
/*m.ints = new int[4];
for (int i = 0; i < m.ints.length; i++) {
m.ints[i] =5;
}*/
for (int i = 0; i < ims.length; i++) {
ims[i] = new InlineMe();
InlineMe im = ims[i];
im.init(i * 2, i + 1);
im.setB(i % 2 == 0);
}
for (int i = 0; i < ims.length; i++) {
InlineMe im = ims[i];
if (im.isB())
im.print();
}
}
}
public class Main {
private static final int LEN = 6;
public int[] ints;
// int i1 = 5;
// int i2 = 5;
// int i3 = 5;
// int i4;
public static void main(String[] args) {
InlineMe ims[] = new InlineMe[LEN];
Main m = new Main();
// m.i4 = 5;
m.ints = new int[4];
for (int i = 0; i < m.ints.length; i++) {
m.ints[i] =5;
}
for (int i = 0; i < ims.length; i++) {
ims[i] = new InlineMe();
InlineMe im = ims[i];
im.init(i * 2, i + 1);
im.setB(i % 2 == 0);
}
for (int i = 0; i < ims.length; i++) {
InlineMe im = ims[i];
if (im.isB())
im.print();
}
}
}
KinGarold 16:07, 24 May 2007 (UTC)
Well, the byte code of an array element is more than the byte code of a normal integer reference, so it's just a matter of referencing the array elements enough times and the array version of the code will be bigger. But this is really an acedemic argument. If you try to write code this way, micro-managing it to minimise the code size, your code is going to end up totally unmanageable and your never going to finish your application on time.
"your code is going to end up totally unmanageable" - I agree :) --KinGarold 10:14, 28 May 2007 (UTC)
Most of the obfuscators perform methods inlining, on a method length criterion.
Each case is different, so play around with the inlining limit
Review:
This article provides several useful tips for reducing the size of JAR installer files. It is generally advisable to keep JAR files as small as possible, as large files take a long time to download, and some devices place a size limit on JAR files due to resource limitations. The article divides the advice for reducing JAR files size into two sets of tips, one set for reducing the size of the resources (such as images) which the midlet uses, and the other set for reducing the size of class files in the JAR.
Some of the most practical and most useful tips are also the most useful to perform. Clearly, there is no need to store high resolution images with 24-bit color depth if these images are to be rendered on a small screen. Reducing image resolution and color depth can dramatically reduce the size of a JAR file, as images often consume more space than the class files. Reduction of class file size can now often easily be performed using an IDE such as NetBeans, where the programmer merely has to select a level of obfuscation, and the end result is a smaller class file (through variable renaming and removal of redundant code).
--Larry101 16:26, 23 September 2009 (UTC)