15 Tips To Make Your Java Application Run Faster

Abhishek Singh
7 min readDec 31, 2022
Image generated by the author (using midjourney.com)

1-Avoid Use Of Multiple If-else Statements-

We use conditional statements in our code for decision-making. The conditional statements should not be overused. If we are using too many conditional if-else statements it will impact performance since JVM will have to compare the conditions each time.

This can become worse if the same is used in looping statements like for loop, while loop, etc.

If there are too many conditions in your business logic try to group the conditions and get the boolean outcome and use it in the if statement.

Also, we can think of using a switch statement instead of multiple if-else if possible. Switch statement has a performance advantage over if — else. The sample is provided below as an example which is to be avoided as follows:

Example:

if(condition1){    
if (condition2) {
if (condition3 || condition4) { execute ..} else { execute..}

Note: Above sample is to be avoided and use this as follows:

boolean result = (condition1 && condition2) && (condition3 || condition4)

2-Avoid Using String Objects For Concatenation-

--

--

Abhishek Singh

I am a senior software engineer. I love to write articles on java. Follow me on LinkedIn - https://in.linkedin.com/in/abhishek-singh-java