Java performance and memory optimization is one of the challenging tasks in Java programming. In case of big Java projects we must consider this. Here I listed few techniques for Java performance and memory optimization.
1. Use mutableStringbuffer/stringbuilderClasses instead of immutable string objects.
2. In caseI/O operationsUse buffering when writing to and reading from
Files and/or streams.Avoid Reader/writers use streamsInstead of this.
3.Remove references to the short-lived objectsFrom long-lived objects like Java collections.
3. Create objects before entering the loop andAvoid creating new objects for each iteration.
4. UseArraylists, hashmapInstead of vector, hashtable etc wherever possible.
5. Reduce calltoDate, calendar, Etc related classes.
6. Use logging frameworks likeLog4jWhich uses I/O buffers instead of system. Out. println.
7.Set Initial Capacity of a collection. Empty vector has array size 10.
8. Use tools likeJprofiler,Jprobe, optimizeitTo find memory leaks in your Java application.
9. Improve Java application performance usingSwingworkerClass.
10. UseThread pooling and database connectionPooling techniques wherever possible.