Compilation, Interpretation & Subroutines Flashcards

1
Q

What is the main difference between compilation and interpretation?

A

Compilation changes high-level code into machine code before running it. Interpretation runs code line by line without changing it into machine code.

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
2
Q

What are the levels of programming languages?

A

High-Level Languages (e.g., Java, C++)

Low-Level Languages (e.g., Machine Code)

Assembly Language (between high and low level)

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
3
Q

What are the main steps in the compilation process?

A

Lexical Analysis

Syntax Analysis

Semantic Analysis

Optimization

Code Generation

Linking

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
4
Q

What are the advantages of compilation?

A

Runs faster after compiling, better machine code, and works well on specific platforms

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
5
Q

What are the disadvantages of compilation?

A

Takes longer to compile and needs recompilation for different hardware

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
6
Q

What is cross compilation?

A

Compiling code on one platform to run on a different one

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
7
Q

What is an interpreter?

A

A program that reads and runs code line by line.

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
8
Q

What are the advantages of using an interpreter?

A

Easier to debug and test, works on any platform, and runs while modifying in real-time

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
9
Q

What are the disadvantages of using an interpreter?

A

Interpreted code runs slower because it’s handled line by line, adding extra work during execution

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
10
Q

How does combined compilation and interpretation work?

A

High-level code is compiled into bytecode, then either interpreted or JIT compiled

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
11
Q

What is a Virtual Machine (VM)?

A

A software that acts like a physical computer to run intermediate code.

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
12
Q

What is the most common virtual machine in programming?

A

The Java Virtual Machine (JVM), which executes Java bytecode.

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
13
Q

What is JIT compilation?

A

Bytecode is compiled to machine code right before running to improve performance

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
14
Q

What are subroutines?

A

Reusable code blocks that do a task and can be used anywhere in a program

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
15
Q

What are the advantages of using subroutines?

A

Reuse code, keep it organized, and reduce repetition

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
16
Q

What is a stack used for in subroutine management?

A

To store return addresses, parameters, and local variables.

17
Q

What are the primary operations performed on a stack?

A

Push (add to top) and Pop (remove from top).

18
Q

What are the call and return instructions used for?

A

Call saves the return address and jumps to the subroutine. Ret gets the address back from the stack

19
Q

What is Reverse Polish Notation?

A

A way of writing math where operators come after numbers (e.g., 3 4 + instead of 3 + 4).

20
Q

Why is Reverse Polish Notation useful?

A

No parentheses needed, so stack calculations are easier

21
Q

How would you express 3 + 4 * 2 in RPN?

22
Q

What is an operand stack?

A

A data structure that holds numbers and results during calculations

23
Q

What are stack machines?

A

Computers that use stacks, not registers, to do operations

24
Q

What is the difference between unconditional and conditional jumps?

A

Unconditional Jump: Always goes to a set address.

Conditional Jump: Goes to a new address only if a condition is true (like if x == 0).

25
Q

What is the Shunting-Yard Algorithm used for?

A

Converting infix expressions (e.g., 3 + 4 * 2) to postfix (RPN) expressions.

26
Q

What type of architecture does JVM follow?

A

An architecture that uses a stack to push and pop values while doing operations

27
Q

Why is Java considered portable?

A

Java code becomes bytecode, so it can run on any computer with a JVM

28
Q

Why do subroutines save registers?

A

Saves the caller’s register values during execution.

29
Q

Why are stacks efficient for temporary storage?

A

They follow the LIFO (Last In, First Out) rule, making push and pop quick