Reference for Main Program_subroutine
Reference for Main Program_subroutine
Subroutine
FOR REFERENCE ONLY
•In programming, a main program and a
subroutine (also called a function,
procedure, or method, depending on the
language) work together to structure a
program efficiently. They help improve
code organization, reusability, and
readability.
•The main program is the central part of
a software application that controls the
overall flow of execution. It is where the
execution starts and typically
coordinates the use of subroutines.
Key Characteristics of a Main
Program
• Entry Point: The execution of the program starts
from the main program.
• Controls Flow: It calls subroutines when needed.
• Manages Data Flow: It may pass data to subroutines
and handle returned values.
• Often Minimal Logic: Ideally, the main program
should not contain complex logic but should delegate
tasks to subroutines.
Example of a Main Program (Python)
• def add_numbers(a, b): # Subroutine
• return a + b
• if __name__ == "__main__":
• main() # Execution starts here
Subroutine(Function/Procedure)
• A subroutine is a block of code that performs a
specific task. It is designed to be reusable and can be
called multiple times from different parts of the
program.
• Types of Subroutines
• Functions: Return a value after execution.
• Procedures (Void Functions): Perform an action but
do not return a value
Key Characteristics of a Subroutine
• int main() {
• int result = multiply(5, 4); // Calling the function
• cout << "Multiplication result: " << result << endl;
• return 0;
• }
Thinks to remember….
• The main program is the entry point and controls
the overall execution.
• Subroutines help structure the program by
breaking it into smaller, reusable blocks.
• Using subroutines makes programs modular,
efficient, and maintainable.
Java Virtual Machine (JVM)
architecture
Class Loader
• Loads class files into the JVM.
• Responsible for linking classes and preparing them for execution.
Method Area