4 Class files and bytecode

 

This chapter covers

  • Class loading
  • Reflection
  • The anatomy of class files
  • JVM bytecode and why it matters

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

Consider the following scenarios that a senior Java developer might encounter: 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 class loading.

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 even why they occur.

This chapter focuses on the aspects of the platform that underlie these concerns. We’ll also discuss some more advanced features, but they are intended for those folks who like to dive deep and can be skipped if you’re in a hurry.

4.1 Class loading and class objects

4.1.1 Loading and linking

4.1.2 Class objects

4.2 Class loaders

4.2.1 Custom class loading

4.2.2 Modules and class loading

4.3 Examining class files

4.3.1 Introducing javap

4.3.2 Internal form for method signatures

4.3.3 The constant pool

sitemap