Chapter 5. Class files and bytecode

 

This chapter covers

  • Classloading
  • Method handles
  • The anatomy of class files
  • JVM bytecode and why it matters
  • The new invokedynamic opcode

One tried-and-trusted way to become a more well-grounded Java developer is to improve your understanding of how the platform works. Getting to grips with core features such as classloading and the nature of JVM bytecode can greatly help with this goal.

Imagine you have an application that makes heavy use of Dependency Injection (DI) techniques such as Spring, and it develops problems starting up and fails with a cryptic error message. If the problem is more than a simple configuration error, you may need to understand how the DI framework is implemented to track down the problem. This means understanding classloading.

Or suppose that a vendor you’re dealing with goes out of business—you’re left with a final drop of compiled code, no source code, and patchy documentation. How can you explore the compiled code and see what it contains?

All but the simplest applications can fail with a ClassNotFoundException or NoClassDefFoundError, but many developers don’t know what these are, what the difference is between them, or why they occur.

This chapter focuses on the aspects of the platform that underlie these development concerns. We’ll also discuss some more advanced features—they’re intended for the enthusiasts and can be skipped if you’re in a hurry.

5.1. Classloading and class objects

5.2. Using method handles

5.3. Examining class files

5.4. Bytecode

5.5. Invokedynamic

5.6. Summary

sitemap