Ten Optimization Tricks to Make Your Java Application Run Faster

lance
Javarevisited
Published in
5 min readMay 22, 2022

--

These tricks may improve the performance of your application several times.

Program performance optimization is a complex topic. It is often necessary to conduct performance analysis in combination with specific scenarios and find out bottlenecks to put forward optimization suggestions. However, suppose we pay little attention to the usual coding details and improve the performance of multiple details. In that case, the cumulative performance benefits of optimizing these details are also considerable. Today, let’s talk about some tips for Java code detail optimization.

Complex String Connection Operations Use StringBuilder

Early in my career, when doing string connection operations, I would certainly use the writing method of String a=c+e+d , This Java syntax sugar is too convenient for developers. But if you use “+” in a loop like this, you have to be careful.

String a=null;
for(int i=0;i<1000;i++) {
a=a+i;
}

We all know that string is immutable, so every assignment to string in the loop will create a new string object in heap memory. In a loop body, you will repeatedly create multiple useless objects, which will not only occupy memory space but also affect the GC time. So listen to me. If…

--

--