0% found this document useful (0 votes)
6 views1 page

Compilation and Java Program Basics

The compilation process takes source code files as input and produces executable files through multiple steps. The compiler translates source code into object code, and the linker combines object files and libraries into a single executable file. Similarly, the Java interpretation process takes class files as input, which were produced from source code by the compiler, and combines them using the linker to produce a JAR archive or other executable file that can be run by the Java Virtual Machine.

Uploaded by

Lisa Fang
Copyright
© Attribution Non-Commercial (BY-NC)
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
6 views1 page

Compilation and Java Program Basics

The compilation process takes source code files as input and produces executable files through multiple steps. The compiler translates source code into object code, and the linker combines object files and libraries into a single executable file. Similarly, the Java interpretation process takes class files as input, which were produced from source code by the compiler, and combines them using the linker to produce a JAR archive or other executable file that can be run by the Java Virtual Machine.

Uploaded by

Lisa Fang
Copyright
© Attribution Non-Commercial (BY-NC)
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd

The Compilation Process

source file

source file

object file

#include <stdio.h>

0100100101011001000
1000010100011101011
0110100111010101100

main() {
printf("hello\n");
}

The Java Interpreter


class file

import [Link].*;

executable
file

compiler

linker

public class Hello


public void run() {
println("hello");
}
}

JAR archive

CA FE BA BE 00 03 00
00 16 07 00 1A 07 00
00 04 00 07 0C 00 13
01 00 16 2B 4C 6A 61

compiler

linker

CA
00
00
01
47
2D
14
00

FE
16
04
00
72
00
0A
18

BA
07
00
16
61
1F
00
0C

BE
00
07
2B
70
08
02
00

00
1A
0C
4C
68
00
00
17

03
07
00
6A
69
0F
08
00

00
00
13
61
63
07
0A
1C

0100100101011001000
1000010100011101011
0110100111010101100
1001011010110001011
0100100101001011011
0101101011010100101

other object files


and libraries

other class files


47
2D
14
00

1001011010110001011
0100100101001011011
0101101011010100101

72
00
0A
18

61
1F
00
0C

70
08
02
00

68
00
00
17

69
0F
08
00

JVM

63
07
0A
1C

Hello

hello

Graphic courtesy of Eric Roberts

Graphic courtesy of Eric Roberts

[Link] Hierarchy

The Add2Integers Program


class Add2Integers extends ConsoleProgram {
public void run() {
println("This program adds two numbers.");
int n1 = readInt("Enter n1: ");
int n2 = readInt("Enter n2: ");
int total = n1 + n2;
println("The total is " + total + ".");
}
}
n1
n2
total
17
25
42

Applet

JApplet

Program

Add2Integers

ConsoleProgram

Graphic courtesy of Eric Roberts

DialogProgram

GraphicsProgram

This program adds two numbers.


Enter n1: 17
Enter n2: 25
The total is 42.

Graphic courtesy of Eric Roberts

You might also like