javac <옵션> <소스파일>
javac --help
로 옵션을 확인할 수 있다.
--class-path <path>, -classpath <path>, -cp <path>
Specify where to find user class files and annotation processors
-d <directory> Specify where to place generated class files
-g Generate all debugging info
--help, -help, -? Print this help message
--source <release>, -source <release>
Provide source compatibility with the specified Java SE release. Supported releases: 7, 8, 9, 10, 11, 12, 13, 14
--target <release>, -target <release>
Generate class files suitable for the specified Java SE release. Supported releases: 7, 8, 9, 10, 11, 12, 13, 14
-verbose Output messages about what the compiler is doing
--version, -version Version information
꿀팁! 단일 파일로 실행할 경우 소스로부터 실행할 수 있다.
Usage: java [options] <mainclass> [args...]
(to execute a class)
or java [options] -jar <jarfile> [args...]
(to execute a jar file)
or java [options] -m <module>[/<mainclass>] [args...]
java [options] --module <module>[/<mainclass>] [args...]
(to execute the main class in a module)
or java [options] <sourcefile> [args]
(to execute a single source-file program)
Hello.java
cat Hello.java
public class Hello {
public static void main(String[] args) {
System.out.println("Hello, CodeSquad!\n");
}
}
16진수 덤프
xxd Hello.class
00000000: cafe babe 0000 003a 001d 0a00 0200 0307 .......:........
00000010: 0004 0c00 0500 0601 0010 6a61 7661 2f6c ..........java/l
00000020: 616e 672f 4f62 6a65 6374 0100 063c 696e ang/Object...<in
00000030: 6974 3e01 0003 2829 5609 0008 0009 0700 it>...()V.......
00000040: 0a0c 000b 000c 0100 106a 6176 612f 6c61 .........java/la
00000050: 6e67 2f53 7973 7465 6d01 0003 6f75 7401 ng/System...out.
00000060: 0015 4c6a 6176 612f 696f 2f50 7269 6e74 ..Ljava/io/Print
00000070: 5374 7265 616d 3b08 000e 0100 1248 656c Stream;......Hel
00000080: 6c6f 2c20 436f 6465 5371 7561 6421 0a0a lo, CodeSquad!..
00000090: 0010 0011 0700 120c 0013 0014 0100 136a ...............j
000000a0: 6176 612f 696f 2f50 7269 6e74 5374 7265 ava/io/PrintStre
000000b0: 616d 0100 0770 7269 6e74 6c6e 0100 1528 am...println...(
000000c0: 4c6a 6176 612f 6c61 6e67 2f53 7472 696e Ljava/lang/Strin
000000d0: 673b 2956 0700 1601 0005 4865 6c6c 6f01 g;)V......Hello.
000000e0: 0004 436f 6465 0100 0f4c 696e 654e 756d ..Code...LineNum
000000f0: 6265 7254 6162 6c65 0100 046d 6169 6e01 berTable...main.
00000100: 0016 285b 4c6a 6176 612f 6c61 6e67 2f53 ..([Ljava/lang/S
00000110: 7472 696e 673b 2956 0100 0a53 6f75 7263 tring;)V...Sourc
00000120: 6546 696c 6501 000a 4865 6c6c 6f2e 6a61 eFile...Hello.ja
00000130: 7661 0021 0015 0002 0000 0000 0002 0001 va.!............
00000140: 0005 0006 0001 0017 0000 001d 0001 0001 ................
00000150: 0000 0005 2ab7 0001 b100 0000 0100 1800 ....*...........
00000160: 0000 0600 0100 0000 0100 0900 1900 1a00 ................
00000170: 0100 1700 0000 2500 0200 0100 0000 09b2 ......%.........
00000180: 0007 120d b600 0fb1 0000 0001 0018 0000 ................
00000190: 000a 0002 0000 0003 0008 0004 0001 001b ................
000001a0: 0000 0002 001c ......
javap로 디스어셈블
javap -c Hello
Compiled from "Hello.java"
public class Hello {
public Hello();
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 #7 // Field java/lang/System.out:Ljava/io/PrintStream;
3: ldc #13 // String Hello, CodeSquad!\n
5: invokevirtual #15 // Method java/io/PrintStream.println:(Ljava/lang/String;)V
8: return
}
(이미지 출처: geeks for geeks - 위 링크)