Compare the Difference Between Similar Terms

Difference Between Attribute and Parameter

Key Difference – Attribute vs Parameter
 

The key difference between attribute and parameter is that an attribute is a variable of any type that is declared directly in a class while a parameter is a variable defined by the function that receives a value when it is called.

In programming languages such as Java, there are concepts like objects, classes and functions. When coding, the programmer should follow the specific syntax related to the programming language. An attribute is used with classes and objects while a parameter is used with functions or methods. This article discusses the difference between attribute and parameter.

CONTENTS

1. Overview and Key Difference
2. What is Attribute
3. What is Parameter
4. Side by Side Comparison – Attribute vs Parameter in Tabular Form
5. Summary

What is Attribute?

Programming languages such as Java supports Object Oriented programming. This programming paradigm is based on objects. An object has a state and behaviour. The state is represented by the data values. They are also called as fields or attributes. The behaviour or the functionality is represented by methods. A class is a blueprint to create an object. Therefore, an object is an instance of a class. A student object can hav e attributes such as student id and name. An Employee can have attributes such as employee ID, name, salary and department. An Animal object can have attributes such as name, favourite food etc.

Figure 01: Java Program with Attributes

According to the above program, the Rhombus class has two attributes that are diagonal1 and diagonal2. It also has the constructor and a method to calculate the area.  In the main program, an object of Rhombus is created. Two values are passed to the constructor, and those will assign to the diagonal1 and diagonal2 attributes. When calling the calArea method, the area of the Rhombus is calculated, and it will return the answer, which is a double value. Finally, the calculated area will print on the screen. The two diagonal values are the attributes of the class and of the object r1.

What is Parameter?

A Function is a major concept in programming. It is a set of statements to perform a specific task. Functions increase code reusability. There can be predefined functions provided by the programming language. The programmer can also write his own functions. They are called as user-defined functions. The term parameter is associated with the function. A parameter is similar to a place holder. The syntax of the function is as follows.

<access modifier> <return type> <function name> <(parameters)> {

// function code

}

The access modifier represents the visibility of the method. It can be private, public etc. A private method is accessible within the class.  A public method is accessible by all the classes. The return type defined the output from the function. If it is an integer, the return type is int. If it is a double value, then the return type is double. If the function does not return anything, it is declared as void. The function name is the actual name of the function to identify it. The parameters are the variables defined by the function that receives the values when the function is called. The function code is placed inside the curly braces.

Figure 02: Java Program with Parameters

According to the above program, the length and width values are passed into the calArea function. In statement calArea (length, width); the length and width are arguments. In the function definition, there is calArea (int a, int b); The length value is copied to variable ‘a’ and width value is copied to variable ‘b’. These ‘a’ and ‘b’ are parameters. The argument values are copied to parameters when the function is called.  The calculated area is returned from calArea. The result is assigned to the variable area in the main program. Finally, the area of the rectangle is printed.

What is the Difference Between Attribute and Parameter?

Attribute vs Parameter

An attribute is a variable of any type that is declared directly in a class. A parameter is a variable defined by the function that receives a value when it is called.
 Usage
An attribute is used with classes and objects. A parameter is used with a function or a method.

Summary – Attribute vs Parameter

Attribute and parameter are two terms associated with programming. This article discusses the difference between attribute and parameter. The difference between attribute and parameter is that an attribute is a variable of any type that is declared directly in a class while a parameter is a variable defined by the function that receives a value when it is called.

Reference:

1.“Java Object and Classes.”, Tutorials Point, 24 Mar. 2018. Available here