Sponsored Ad

Monday, November 9, 2009

C# .Net and Java

To understand this must have some knowledge of computer internals, for example. Opcodes, instruction templates, etc. I guess you already know this code as well them.As usual starts with the main method. The first line says that print? Hello? is a normal print statement. A specific instruction, with type information, is constructed by replacing the? T? Established in instruction in the opcode column of print in the type column. In this case it is a load instruction type reference. Instruction Invokespecial should the name of an instance initialization method, a method in the current class or a method in a superclass of the current class. Class & initialization methods of the interface is invoked implicitly by the Java virtual machine, but never invoked directly from any Java virtual machine instruction, but is invoked only indirectly, as part of the class initialization.

invokevirtual or  invokespecial is used to accession a  protected method of a superclass, then the type of the class example being accessed must be the same as or a subclass of the stream class.The Java virtual machine uses local variables to pass parameters on method invocation. On class method invocation any parameters are passed in consecutive local variables starting from local variable 0.

Java Hello Program:

Code Snippet
  1. class Hello
  2. {
  3.  
  4.     public static void main(String args[])
  5.     {
  6.         System.out.println("Hello");
  7.     }
  8.  
  9. }

 

Disassembled Java Hello Program:

Code Snippet
  1. class Hello
  2. {
  3.  
  4.     Hello()
  5.     {
  6.         // 0 0:aload_0
  7.         // 1 1:invokespecial #1 <Method void Object()>
  8.         // 2 4:return
  9.     }
  10.  
  11.     public static void main(String args[])
  12.     {
  13.         System.out.println("Hello");
  14.         // 0 0:getstatic #2 <Field PrintStream System.out>
  15.         // 1 3:ldc1 #3 <String "Hello">
  16.         // 2 5:invokevirtual #4 <Method void PrintStream.println(String)>
  17.         // 3 8:return
  18.     }
  19.  
  20. }

0 comments:

Post a Comment

Sponsored Ad

More Related Articles

Website Update

Followers