Toggle menu
Toggle personal menu
Not logged in
Your IP address will be publicly visible if you make any edits.

진격의안드로이드&Java: Difference between revisions

From ZeroWiki
imported>novaman
No edit summary
(Repair batch-0007 pages from live compare)
 
(22 intermediate revisions by 3 users not shown)
Line 1: Line 1:
__TOC__
== 강의록 ==  
== 강의록 ==  
* [http://www.slideshare.net/novathinker/1-java-key Chapter 1]
* [http://www.slideshare.net/novathinker/1-java-key Java-Chapter 1]
* [http://www.slideshare.net/novathinker/2-runtime-data-areas Chapter 2]
* [http://www.slideshare.net/novathinker/2-runtime-data-areas Java-Chapter 2]
* [http://www.kandroid.org/board/data/board/conference/file_in_body/1/8th_kandroid_application_framework.pdf Android]


== 강의 내용 ==
== 강의 내용 ==
=== ByteCode.java ===
=== ByteCode.java ===
==== cmd에서 Compile & Decompile 방법 ====
// Compile
// notepad++ 에서 UTF8(BOM 없음) 선택후 다음과 같이 cmd에서 컴파일
javac -encoding utf8 ByteCode.java
// Decompile
javap -c ByteCode.class
==== 기본 소스 ====
  public class ByteCode{
  public class ByteCode{
  public ByteCode() {
  public ByteCode() {
Line 18: Line 31:
  }
  }


  // notepad++ 에서 UTF8(BOM 없음) 선택후 다음과 같이 cmd에서 컴파일
  // Result of Decompile
  javac -encoding utf8 ByteCode.java
Compiled from "ByteCode.java"
public class ByteCode {
  public ByteCode();
    Code:
        0: aload_0
        1: invokespecial #1                  // Method java/lang/Object."<init>":()V
        4: getstatic    #2                  // Field java/lang/System.out:Ljava/io/PrintStream;
        7: ldc          #3                  // String hello
        9: invokevirtual #4                  // Method java/io/PrintStream.println:(Ljava/lang/String;)V
      12: return
  public void methodOperandStack();
    Code:
        0: iconst_5
        1: istore_1
        2: iconst_1
        3: istore_2
        4: iload_1
        5: iload_2
        6: iadd
        7: istore_3
        8: return
}
 
==== 1차 수정 ====
public class ByteCode{
public ByteCode() {
System.out.println("hello");
}
public void methodOperandStack(){
try{
int a, b, c;
a = 5;
b = 1;
c = a + b;
} catch(Exception e){
}
}
}
 
// Result of Decompile
  Compiled from "ByteCode.java"
public class ByteCode {
  public ByteCode();
    Code:
        0: aload_0
        1: invokespecial #1                  // Method java/lang/Object."<init>":()V
        4: getstatic    #2                  // Field java/lang/System.out:Ljava/io/PrintStream;
        7: ldc          #3                  // String hello
        9: invokevirtual #4                  // Method java/io/PrintStream.println:(Ljava/lang/String;)V
      12: return
  public void methodOperandStack();
    Code:
        0: iconst_5
        1: istore_1
        2: iconst_1
        3: istore_2
        4: iload_1
        5: iload_2
        6: iadd
        7: istore_3
        8: goto          12
      11: astore_1
      12: return
    Exception table:
        from    to  target type
            0    8    11  Class java/lang/Exception
}


* Decompile
==== 2차 수정 ====
  javap -c ByteCode.class
  public class ByteCode{
public ByteCode() {
System.out.println("hello");
}
private static final boolean optimize = false;
private final void methodOperandStack(){
if(optimize){
int a, b, c;
a = 5;
b = 1;
c = a + b;
}
}
}


// Result of Decompile
Compiled from "ByteCode.java"
public class ByteCode {
  public ByteCode();
    Code:
        0: aload_0
        1: invokespecial #1                  // Method java/lang/Object."<init>":()V
        4: getstatic    #2                  // Field java/lang/System.out:Ljava/io/PrintStream;
        7: ldc          #3                  // String hello
        9: invokevirtual #4                  // Method java/io/PrintStream.println:(Ljava/lang/String;)V
      12: return
}

Latest revision as of 01:32, 27 March 2026

강의록

강의 내용

ByteCode.java

cmd에서 Compile & Decompile 방법

// Compile
// notepad++ 에서 UTF8(BOM 없음) 선택후 다음과 같이 cmd에서 컴파일

javac -encoding utf8 ByteCode.java
// Decompile

javap -c ByteCode.class

기본 소스

public class ByteCode{
	public ByteCode() {
		System.out.println("hello");
	}
	
	public void methodOperandStack(){
		int a, b, c;
		a = 5;
		b = 1;
		c = a + b;
	}
}
// Result of Decompile

Compiled from "ByteCode.java"
public class ByteCode {
  public ByteCode();
    Code:
       0: aload_0
       1: invokespecial #1                  // Method java/lang/Object."<init>":()V
       4: getstatic     #2                  // Field java/lang/System.out:Ljava/io/PrintStream;
       7: ldc           #3                  // String hello
       9: invokevirtual #4                  // Method java/io/PrintStream.println:(Ljava/lang/String;)V
      12: return

  public void methodOperandStack();
    Code:
       0: iconst_5
       1: istore_1
       2: iconst_1
       3: istore_2
       4: iload_1
       5: iload_2
       6: iadd
       7: istore_3
       8: return
}

1차 수정

public class ByteCode{
	public ByteCode() {
		System.out.println("hello");
	}
	
	public void methodOperandStack(){
		try{
			int a, b, c;
			a = 5;
			b = 1;
			c = a + b;
		} catch(Exception e){
		}
	}
}
// Result of Decompile

Compiled from "ByteCode.java"
public class ByteCode {
  public ByteCode();
    Code:
       0: aload_0
       1: invokespecial #1                  // Method java/lang/Object."<init>":()V
       4: getstatic     #2                  // Field java/lang/System.out:Ljava/io/PrintStream;
       7: ldc           #3                  // String hello
       9: invokevirtual #4                  // Method java/io/PrintStream.println:(Ljava/lang/String;)V
      12: return

  public void methodOperandStack();
    Code:
       0: iconst_5
       1: istore_1
       2: iconst_1
       3: istore_2
       4: iload_1
       5: iload_2
       6: iadd
       7: istore_3
       8: goto          12
      11: astore_1
      12: return
    Exception table:
       from    to  target type
           0     8    11   Class java/lang/Exception
}

2차 수정

public class ByteCode{
	public ByteCode() {
		System.out.println("hello");
	}
	
	private static final boolean optimize = false;
	private final void methodOperandStack(){
		if(optimize){
			int a, b, c;
			a = 5;
			b = 1;
			c = a + b;
		} 
	}
}
// Result of Decompile

Compiled from "ByteCode.java"
public class ByteCode {
  public ByteCode();
    Code:
       0: aload_0
       1: invokespecial #1                  // Method java/lang/Object."<init>":()V
       4: getstatic     #2                  // Field java/lang/System.out:Ljava/io/PrintStream;
       7: ldc           #3                  // String hello
       9: invokevirtual #4                  // Method java/io/PrintStream.println:(Ljava/lang/String;)V
      12: return
}