Discussion Unit 3 (Programming I) PDF

Title Discussion Unit 3 (Programming I)
Course Programming 1
Institution University of the People
Pages 5
File Size 137.5 KB
File Type PDF
Total Downloads 37
Total Views 139

Summary

Unit 3 Discussion Post Assignment Programming I
Unit 3 Discussion Post Assignment Programming I
Unit 3 Discussion Post Assignment Programming I
Unit 3 Discussion Post Assignment Programming I
Unit 3 Discussion Post Assignment Programming I...


Description

Discuss the concept of parameters. What are parameters for? What is the difference between formal parameters and actual parameters? Give an example in Java code that illustrates formal parameters and actual parameters.

Parameters have various meanings in different programming languages. Parameters are the interfaces of methods. Their job is to pass information to the method from their home inside a pair of parentheses. Parameters essentially help methods execute necessary tasks. In Java, there are actual and formal parameters. Actual parameters sometimes referred to as arguments, are values that are passed when a method is being called. These values can be specified by any expression as long as it matches the same datatype as a formal parameter. When a method is called in Java, the actual parameters in the method call statement are evaluated, and the values are assigned to the formal parameter in the method’s definition. Then the body of the method is executed (Eck, 2019).

Formal parameters are a defined list of variables declared inside of a function definition. Formal parameters variables have to be named (the name does not have to be the same as the actual parameter, but it has to be the same data type) and specified by certain types such as a boolean, string, double, or int. They are a temporary placeholder for the actual parameter.

There are a few differences between actual and formal parameters. The key difference that you should remember is that actual parameters are values that are passed to the function when it is called. Formal parameters are variables defined by functions and receive values when the function is executed. Another difference is that formal parameters are unbound variables that use a specific data type such as int, double, string, or boolean. In contrast, actual parameters can use any expression or literal as long as it matches the data type that is formally defined. Lastly, unlike formal parameters, actual parameters can be changed. In other words, the output from actual parameters can be different.

Example

References Eck, D. J. (2019). Introduction to programming using Java, version 8.1. Hobart and William Smith College. http://math.hws.edu/javanotes

Your Discussion should be at least 250 words in length, but not more than 750 words. Once you’ve completed your initial post, be sure to respond to the posts of at least 3 of your classmates.

Difference → actual parameters are values that are passed to the function when it is executed. Formal parameters are variables that are defined by the function that receives values when that function is called. Unlike formal parameters, actual parameters can be changed.

Formal parameters → (dummy parameters) parameters in a method definition. Must be a name (simpler identifier). Very much like a variable. Identifier that is used in a method to stand for the value that’s passed into the method by a caller. Formal

parameters are confined to an actual value only as long as the method is active. Once a method returns to its caller, they no longer contain any values and cannot be used to store the state of an object. Only valid within the method. Don’t need to be named the same as the actual parameters but they need to be the same data type. Referred to as parameters because it is the list of variables in a method. List of variables in a method. Variables that are written / declared in the function definition and receive their values when the call to that function is made. The type of data that a method can receive. Must be a name and a specified variable type such as: int, string, boolean or double. Formal Syntax → function_name(datatype variable_name) Actual parameters → (arguments) passed to a method. When a method is called, the actual parameters in the method call statement are evaluated and the values are assigned to the formal parameters in the method’s definition. Actual parameter is a value so it can be specified by any expression, provided that expression computes a value of the correct type. The type of the actual parameter must be one that could legally be assigned to the formal parameter with an assignment statement. The actual value that is passed into the method by a caller. Can be referred to as an argument. Values / variables passed while calling a function. What is passed to a method. A value that can be specified by any expression. Actual Syntax → function_name(variable name(s));...


Similar Free PDFs