When and where are strings initialized / stored in Java source code?
                                        
                    •
                    Java                                    
                This is the source code I have
public class Koray {
    public static void main(String [] args) {
            System.out.println("This is a sample program.");
    } 
}
When I compile this, I get the bytecode When I look at the bytecode with the hexadecimal viewer, I see a part:
19 54 68 69 73 20 69 73 20 61 20 73 61 6D 70 6C 65 20 70 72 6F 67 72 61 6D 2E
This can be read as
This is a sample program.
If a byte is interpreted as a character
When I do
javap -c Koray.class
After splitting this class, I see:
Compiled from "Koray.java"
public class Koray {
  public Koray();
    Code:
       0: aload_0       
       1: invokespecial #1                  // Method java/lang/Object."<init>":()V
       4: return        
  public static void main(java.lang.String[]);
    Code:
       0: getstatic     #2                  // Field java/lang/System.out:Ljava/io/PrintStream;
       3: ldc           #3                  // String This is a sample program.
       5: invokevirtual #4                  // Method java/io/PrintStream.println:(Ljava/lang/String;)V
       8: bipush        10
      10: istore_1      
      11: return        
}
My question is, where do I see this string in the disassembled text? I just saw it in the comments
Solution
See LDC instruction? It loads a constant from the runtime constant pool This is where your string is stored
                            The content of this article comes from the network collection of netizens. It is used as a learning reference. The copyright belongs to the original author.
                        
                                            
                        THE END
                    
                    
                    
                                                        二维码
                        
                        
                                                
                        