3

I'm just curious as to how a string Java Assembly code is converted to bytecode? Say for example the java assembly code said this:

print 'Hello World'

I know this isn't what Java Assembly actually looks like, it's just to help get my point across. How does Java convert the above code into byte code? For example does the assembler remove the single quotes to leave this:

print Hello World

And then take the print as the instruction and everything else as the argument when converting to byte code or does it preserve the single quotes? Sorry if my question is hard to understand, if my question is hard to understand I'd be happy to edit it.

9
  • 5
    You are way off the mark... there are no quotes involved at all in this. The string is represented in bytecode just as a simple reference. The string's characters are in a separate structure, the constant pool. Commented Mar 18, 2014 at 11:23
  • 1
    First of all, I don't know what you even mean by "assembly" since no such thing is involved in the process of compiling Java to .class files. Second, strings are already numbers (what else could they be?) and in the .class file these numbers may be exactly the same as in your .java file, or may be in a different encoding, but that's not a very large difference. Commented Mar 18, 2014 at 11:33
  • 1
    Yes, that's what I mean. The same numbers encode strings in .java and in .class. Commented Mar 18, 2014 at 11:42
  • 1
    Yes, you would see it (just checked, apparently it uses UTF-8), along with many other strings, such as names of variables, referenced classes, and so on. Commented Mar 18, 2014 at 11:56
  • 1
    docs.oracle.com/javase/specs/jvms/se7/html/jvms-4.html#jvms-4.4 Commented Mar 18, 2014 at 12:06

1 Answer 1

1

There are no bytecodes, per se, involved in the storage of literal constants. The .class file just has a table of these constants, and when the class is loaded they're placed into memory, much like initializing static variables.

Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.