# What is temp and how it works (constructor)

**URL:** <https://discourse.processing.org/t/what-is-temp-and-how-it-works-constructor/40506>\
**Category:** Beginners\
**Created:** [January 8, 2023, 9:24am UTC](https://discourse.processing.org/t/what-is-temp-and-how-it-works-constructor/40506 "2023-01-08T09:24:33Z")\
**Posts on this page:** 6\
**Page:** 1

<div class="post-metadata">

**Author:** ![Siyue](https://avatars.discourse-cdn.com/v4/letter/s/9de0a6/32.png) [@Siyue](https://discourse.processing.org/u/Siyue)\
**Post date:** [January 8, 2023, 9:24am UTC](https://discourse.processing.org/t/what-is-temp-and-how-it-works-constructor/40506/1 "2023-01-08T09:24:33Z")

</div>

So from processing tutorial https://www.youtube.com/watch?v=NrwaKOsplZk&list=PLzJbM9-DyOZyMZzVda3HaWviHqfPiYN7e&index=36 , there is a “temp” argument to define the diameter. my question is any relative explanation for temp and how would I use it properly. I didn’t get how to name one value with temp and how things get related: eg, from the video : why D is referring to temp D, why use letter D but not A B C? I am confused with the naming and using rules of “temp”.

---

<div class="post-metadata">

**Author:** ![jafal](https://yyz2.discourse-cdn.com/flex036/user_avatar/discourse.processing.org/jafal/32/19112_2.png) [@jafal](https://discourse.processing.org/u/jafal)\
**Post date:** [January 8, 2023, 10:38am UTC](https://discourse.processing.org/t/what-is-temp-and-how-it-works-constructor/40506/2 "2023-01-08T10:38:56Z")

</div>

> [@Siyue](#):
>
> why D is referring to temp D, why use letter D but not A B C? I am confused with the naming and using rules of “temp”.

To explain why see and Read links below 👇

> **[class / Reference](https://processing.org/reference/class.html)**
>
> Keyword used to indicate the declaration of a class. A class is a composite of fields (data) and methods (functions that are a part of the class) which may be instantiated as objects. The first lette…

> **[Lesson: Object-Oriented Programming Concepts (The Java™ Tutorials \>...](https://docs.oracle.com/javase/tutorial/java/concepts/index.html)**
>
> This beginner Java tutorial describes fundamentals of programming in the Java programming language

https://www.youtube.com/embed/YcbcfkLzgvs?feature=oembed&wmode=opaque&list=PLRqwX-V7Uu6bb7z2IJaTlzwzIg_5yvL4i

[![](https://img.youtube.com/vi/OGXrIhRopFo/maxresdefault.jpg "Using Classes in Processing") ](https://www.youtube.com/watch?v=OGXrIhRopFo)

---

<div class="post-metadata">

**Author:** ![Siyue](https://avatars.discourse-cdn.com/v4/letter/s/9de0a6/32.png) [@Siyue](https://discourse.processing.org/u/Siyue)\
**Post date:** [January 8, 2023, 11:08am UTC](https://discourse.processing.org/t/what-is-temp-and-how-it-works-constructor/40506/3 "2023-01-08T11:08:07Z")

</div>

thanks. but I watched the 8.1 object-oriented programming and class reference. It didn’t solve my problem:" what is temp "

---

<div class="post-metadata">

**Author:** ![Chrisir](https://yyz2.discourse-cdn.com/flex036/user_avatar/discourse.processing.org/chrisir/32/45_2.png) [@Chrisir](https://discourse.processing.org/u/Chrisir)\
**Post date:** [January 8, 2023, 12:00pm UTC](https://discourse.processing.org/t/what-is-temp-and-how-it-works-constructor/40506/4 "2023-01-08T12:00:43Z")

</div>

A variable (parameter) is passed to the constructor.

Since it signifies the diameter it’s named D.

The variable is forgotten as soon as the constructor has been run; therefore the variable is temporary. This is abbreviated to temp. So it’s tempD for a temporary diameter.

Sometimes you see `d_in` (`_in` for incoming parameter) as a name or even `d_` as a name.  
It’s just important that the parameter has a different name than the name of the variables in the class (where we copy the temporary incoming variable into).

You did that correctly with your two bubbles.

---

<div class="post-metadata">

**Author:** ![Siyue](https://avatars.discourse-cdn.com/v4/letter/s/9de0a6/32.png) [@Siyue](https://discourse.processing.org/u/Siyue)\
**Post date:** [January 8, 2023, 1:38pm UTC](https://discourse.processing.org/t/what-is-temp-and-how-it-works-constructor/40506/5 "2023-01-08T13:38:28Z")

</div>

> [@Chrisir](#):
>
> The variable is forgotten as soon as the constructor has been run; therefore the variable is temporary. This is abbreviated to temp. So it’s tempD for a temporary diameter.
> 
> Sometimes you see d\_in as a name or even d\_ as a name. It’s just important that the parameter have a different name than the names of the variables in the class (where we copy the temporary incoming variable into)
> 
> You did that correctly with your two bubbles

hello Chris,  
thanks a lot.  
I still have some more questions about Temp. (is this short for temporary?)  
what if I want to define not only the diameters instead of color of the bubble. where you put the value and how will you name your temp and make sure there is a value pass to the constructor ?  
thank you. and yes. I try to figure out the OOP and I almost figure out. haha

---

<div class="post-metadata">

**Author:** ![Chrisir](https://yyz2.discourse-cdn.com/flex036/user_avatar/discourse.processing.org/chrisir/32/45_2.png) [@Chrisir](https://discourse.processing.org/u/Chrisir)\
**Post date:** [January 8, 2023, 2:30pm UTC](https://discourse.processing.org/t/what-is-temp-and-how-it-works-constructor/40506/6 "2023-01-08T14:30:55Z")

</div>

> [@Siyue](#):
>
> is this short for temporary?

Yes, temp is short for temporary, not permanent

> [@Siyue](#):
>
> what if I want to define not only the diameters instead of color of the bubble. where you put the value and how will you name your temp and make sure there is a value pass to the constructor ?

The name tempD is arbitrary. You can choose every name as a parameter as long as it’s not the same name as in the class variable.

You can separate parameters with comma.

```auto
Bubble (float tempD, color tempColor) {
   diameter = tempD;
   colBubble = tempColor; 
}

```

see [class / Reference / Processing.org](https://processing.org/reference/class.html)

**By the way**

you can also use the same name and use “this.”

```auto
Bubble (float diameter , color colBubble ) {
   this.diameter = diameter ;
   this.colBubble = colBubble ; 
}

```

**Example**

```auto
// Declare and construct two objects (h1, h2) from the class HLine 

HLine h1 = new HLine(20, 2.0); 
HLine h2 = new HLine(50, 2.5); 

void setup() {
  size(200, 200);
  frameRate(30);
}

void draw() { 
  background(204);
  h1.update(); 
  h2.update();
} 

// =======================================================================

class HLine { 
  float ypos, speed; 

  // constr 
  HLine (float y, float s) {  
    ypos = y; 
    speed = s;
  }// constr 

  void update() { 
    ypos += speed; 
    if (ypos > height) { 
      ypos = 0;
    } 
    line(0, ypos, width, ypos);
  } // method
} // class  
//

```
