Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • Home
  • SEARCH
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 8288053
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 8, 20262026-06-08T12:12:04+00:00 2026-06-08T12:12:04+00:00

From the Java Virtual Machine specification : A class file consists of a stream

  • 0

From the Java Virtual Machine specification:

A class file consists of a stream of 8-bit bytes. All 16-bit, 32-bit, and 64-bit quantities are constructed by reading in two, four, and eight consecutive 8-bit bytes, respectively. Multibyte data items are always stored in big-endian order, where the high bytes come first. In the Java platform, this format is supported by interfaces java.io.DataInput and java.io.DataOutput and classes such as java.io.DataInputStream and java.io.DataOutputStream.

This chapter defines its own set of data types representing class file data: The types u1, u2, and u4 represent an unsigned one-, two-, or four-byte quantity, respectively. In the Java platform, these types may be read by methods such as readUnsignedByte, readUnsignedShort, and readInt of the interface java.io.DataInput.

Aside from the irritating mentioning of "64-bit quantities" (there is no u8, long and double are splitted in two u4 items), I don’t understand how to handle the u4 type.

For u1 and u2 it’s clear:

  • u1: read with readUnsignedByte, store in an int
  • u2: read with readUnsignedShort, store in an int

The specification advises this:

  • u4: read with readInt, store in an int (?)

What happens to values greater than Integer.MAX_VALUE? Does this advice silently imply that all values of type u4 are less than or equal to Integer.MAX_VALUE?

I came up with this idea:

  • u4: read with readUnsignedInt, store in a long

Unfortunalety, there is no such method. But that’s not the problem, since you can easily write your own:

public long readUnsignedInt() throws IOException {
    return readInt() & 0xFFFFFFFFL;
}

So, here are two questionable spots:

  1. The Code attribute:

Code_attribute {
…
u4 code_length;
u1 code[code_length];
…
}

Why is code_length not of type u2? Later it says:

The value of the code_length item must be less than 65536.

  1. The SourceDebugExtension attribute:

SourceDebugExtension_attribute {
…
u4 attribute_length;
u1 debug_extension[attribute_length];
}
…
Note that the debug_extension array may denote a string longer than that which can be represented with an instance of class String.

Why? Can u4 values indeed exceed Integer.MAX_VALUE (since I think this is the maximum length of a String instance)?

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-08T12:12:05+00:00Added an answer on June 8, 2026 at 12:12 pm
    1. To easily lift 64K code length restriction, if such a need arise.
    2. Since there is no mention that u4 values cannot exceed Integer.MAX_VALUE, then one must assume that u4 values can exceed Integer.MAX_VALUE. JVM spec lefts nothing implicit.
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

We are working on a project to handle virtual machine managers from a Java
I am trying to create a Java virtual machine from C++ and invoke the
From Java, I'm extracting an executable into a location specified using File.createTempFile(). When I
From Java, is it possible to get the complete commandline with all arguments that
I have two applications running in the same java virtual machine, and both use
I'm after a book to learn about the internals of the Java virtual machine.
I was reading this question to find out the differences between the Java Virtual
If you decompile the java.lang.Class class in java from the rt.jar library you will
Possible Duplicate: Catching java.lang.OutOfMemoryError OutOfMemoryError are: Thrown when the Java Virtual Machine cannot allocate
From Java, I run a C++ app which logs its progress as it proceeds,

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.