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

  • SEARCH
  • Home
  • 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 7526405
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 30, 20262026-05-30T03:49:13+00:00 2026-05-30T03:49:13+00:00

I was reading java bytecode and saw this: getfield #5 (Field java.lang.String name) What

  • 0

I was reading java bytecode and saw this:

getfield #5 (Field java.lang.String name)

What does #5 mean?

And how can I write a program in bytecode?

  • 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-05-30T03:49:15+00:00Added an answer on May 30, 2026 at 3:49 am

    Java class files and bytecode

    Java class files (bytecode-files) is composed by different components:

    http://en.wikipedia.org/wiki/Java_class_file

    • Magic Number: 0xCAFEBABE
    • Version of Class File Format: the minor and major versions of the class file
    • Constant Pool: Pool of constants for the class
    • (…)
    • Fields: Any fields in the class
    • Methods: Any methods in the class
    • Attributes: Any attributes of the class (for example the name of the sourcefile, etc.)

    The number #5 simply refers to a location in the constant pool. And in that position a CONSTANT_FieldRef is found which contains a reference to a CONSTANT_NameAndType among other attributes. And CONSTANT_NameAndType contains a reference to a CONSTANT_Utf8 (which contains the actual string/name.)

    So the flow looks like this:

    getfield #number -> FieldRef -> NameAndType -> Utf8 -> string
    

    http://java.sun.com/docs/books/jvms/second_edition/html/ClassFile.doc.html

    So instead of saving a whole string in each getfield instruction a number is saved. This improves performance in the interpreter (or JIT) and space in the class file.

    Hand-write bytecodes

    Hand-written bytecodes can be assembled to a class file with this tool (it contains a lot of examples):

    http://jasmin.sourceforge.net/

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

Reading Java Concurrency In Practice, there's this part in section 3.5: public Holder holder;
While reading some Java source, I came across this line: ((Closeable) some_obj).close(); some_obj is
I was reading about java web start from wiki . Can someone please tell
I am reading some Java text and the text says that we can only
I am reading a java program, when it sending messages through socket, it aways
I recently asked this question: Best choice? Edit bytecode (asm) or edit java file
I am new to Hibernate, reading this book Java persistence with Hibernate and I
As I understand from reading this post about the new invokedynamic bytecode instruction in
I am reading the Java Hashmap documentation but I don't understand this sentence. Note
I was reading Java Platform Performance (sadly the link seems to have disappeared from

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.