Search icon CANCEL
Arrow left icon
Explore Products
Best Sellers
New Releases
Books
Videos
Audiobooks
Learning Hub
Conferences
Free Learning
Arrow right icon
Arrow up icon
GO TO TOP
High Performance with Java

You're reading from   High Performance with Java Discover strategies and best practices to develop high performance Java applications

Arrow left icon
Product type Paperback
Published in Jul 2024
Publisher Packt
ISBN-13 9781835469736
Length 306 pages
Edition 1st Edition
Languages
Tools
Arrow right icon
Author (1):
Arrow left icon
Dr. Edward Lavieri Jr. Dr. Edward Lavieri Jr.
Author Profile Icon Dr. Edward Lavieri Jr.
Dr. Edward Lavieri Jr.
Arrow right icon
View More author details
Toc

Table of Contents (26) Chapters Close

Preface 1. Part 1: Code Optimization FREE CHAPTER
2. Chapter 1: Peeking Inside the Java Virtual Machine 3. Chapter 2: Data Structures 4. Chapter 3: Optimizing Loops 5. Chapter 4: Java Object Pooling 6. Chapter 5: Algorithm Efficiencies 7. Part 2: Memory Optimization and I/O Operations
8. Chapter 6: Strategic Object Creation and Immutability 9. Chapter 7: String Objects 10. Chapter 8: Memory Leaks 11. Part 3: Concurrency and Networking
12. Chapter 9: Concurrency Strategies and Models 13. Chapter 10: Connection Pooling 14. Chapter 11: Hypertext Transfer Protocols 15. Part 4: Frameworks, Libraries, and Profiling
16. Chapter 12: Frameworks for Optimization 17. Chapter 13: Performance-Focused Libraries 18. Chapter 14: Profiling Tools 19. Part 5: Advanced Topics
20. Chapter 15: Optimizing Your Database and SQL Queries 21. Chapter 16: Code Monitoring and Maintenance 22. Chapter 17: Unit and Performance Testing 23. Chapter 18: Leveraging Artificial Intelligence (AI) for High-Performance Java Applications 24. Index 25. Other Books You May Enjoy

Additional string operation strategies

String pooling and lazy initialization are excellent optimization strategies that can help improve the overall performance of our Java applications. In addition to these strategies, we can ensure that our string concatenation operations are efficient, that we properly leverage regular expressions, and that we efficiently handle large text files. This section reviews techniques in each of those areas.

Concatenation

String concatenation – the joining of two or more strings into one – using the plus (+) operator often results in inefficient code. This concatenation creates a new string object, which we want to avoid. Let’s look at two alternatives that offer better performance.

This first alternative uses StringBuilder. In the following example, we create a StringBuilder object, append five string literals to it, convert the StringBuilder object to String, and then output the results:

public class ConcatenationAlternativeOne...
lock icon The rest of the chapter is locked
Register for a free Packt account to unlock a world of extra content!
A free Packt account unlocks extra newsletters, articles, discounted offers, and much more. Start advancing your knowledge today.
Unlock this book and the full library FREE for 7 days
Get unlimited access to 7000+ expert-authored eBooks and videos courses covering every tech area you can think of
Renews at €18.99/month. Cancel anytime