<p>If one understands objects, fields, and variables, static fields should be easy to understand (e.g. as fields of a "class object"). And if one does not understand objects, one can not apply OOP or software design, which makes it very hard (maybe even impossible) to really understand that material.</p>

<p>Therefore, a solid and accurate understanding of objects, fields and variables seems worth investing into even at the price of covering less of the official curriculum.</p>

<p>I am however not sure the memory spaces of the JVM are the best tool to communicate this, because your students may not know what memory spaces are. After all, memory spaces are like objects in that they host variables, so if people are unaware that variables exist in a scope and are bound to its lifetime, naming that scope "memory space" rather than "object" won't help.</p>

<p>BTW, when Java programmers say "Memory Model", they often refer to the <a href="http://docs.oracle.com/javase/specs/jls/se8/html/jls-17.html#jls-17.4" rel="nofollow noreferrer">so named chapter</a> in the Java Language Specification, which gives a formal mathematical model for memory as seen by concurrently executing threads. That would probably be too advanced for your course ;-)</p>

CC BY-SA 3.0
2017-07-07T21:58:42.773Z
Hi meriton! Welcome to [cseducators.se]! Glad to have your input here. I hope to see you around more!
thesecretmaster
CC BY-SA 3.0
2017-07-07T21:12:25.227Z
2017-07-07T21:12:25.227Z
meriton
<p><code>Static</code> is within the AP subset and is fair game for the examination.  Oddly enough, the memory model of Java that operates here is not, so students <em>could</em>, hypothetically, memorize a series of arbitrary rules and be fine here.</p>

<p>If you think it seems silly to teach about <code>static</code> without at least giving a passing understanding of how memory works, then you and I are on the same page.  However, in this instance, I provide a simplified (and terribly inefficient!) view of memory usage, because I don't want to delve too far down this rabbit hole in what is essentially an introductory class.  (Especially because we haven't yet covered the all-important idea of passing <code>this</code> as a parameter.)</p>

<p>Here is a picture of the PowerPoint slide with the setup itself (sans animation).  Also not seen is another slide that says, "Hey class, when can a <em>lie</em> serve the <em>truth?</em> ... <strong>Right now!</strong>")</p>

<p><a href="https://i.sstatic.net/H9DrT.gif" rel="nofollow noreferrer"><img src="https://i.sstatic.net/H9DrT.gif" alt="my false model of static"></a></p>

<p>There are more slides, and quite a bit of discussion.  But in essence, this model allows me to ask discussion questions like:</p>

<ul>
<li>Why are there 3 <code>Doubler</code>s in memory?</li>
<li>Why is there only one <code>count</code>?</li>
<li>What did <code>static</code> actually accomplish?</li>
<li>What would happen if we called <code>val++</code> from inside <code>method()</code>. Is there any reasonable way for Java to interpret this?</li>
<li>What would happen if we called <code>count++</code> from inside <code>doubleVal()</code>?  Is there any reasonable way for Java to interpret this?</li>
</ul>

<p>Now, as for the situation you are in, it sounds like you've already devoted a lot of time to this.  I would not spend a great deal more time on <code>static</code>.  There is a <em>lot</em> in the exam, and <code>static</code> is not heavily tested.  I might do one more quick attempt to try to clarify this idea, but then move on.  There is, as you said, plenty else to do.</p>

CC BY-SA 3.0
2017-07-08T07:25:42.123Z
I like the slide and questions. If used together.
ctrl-alt-delor
CC BY-SA 3.0
2017-07-07T22:13:41.293Z
2017-07-07T22:13:41.293Z
Ben I.
<p><b>Disclaimer:</b> I am teaching in Canada and therefore I am unfamiliar with the American AP CS A and AP CS P curricula that others may have talked about. In my school board at least, it is still very grey what exactly to teach in AP CS. Essentially this is a grade 12 course continuing from grade 11 (which taught variables, arrays, loops, functions and simple inheritance). The goal of AP as posed to regular is to focus more on OOP, specifically SOLID principles.</p>

<p>With that out of the way, here's the situation. I am teaching a summer course to high school students who want an enriched Computer Science course in order to succeed in University. This is the first time this course is offered during the summer (and my first time teaching this course). This week, I decided to go over some review of Java basics to gauge the overall knowledge of my class. Ironically enough, everyone seemed to know variables and access modifiers, but as I began going over some Inheritance, students became confused over static variables, static space and where variables were.</p>

<p>I drew out a simple memory model and showed where static, heap, stack and meta-space. I could already tell there were a lot of blank faces <em>(okay, let's back track)</em>. I essentially explained that things declared in the static space are global to the project and belong to a class as posed to instances. However, surprise surprise, I spent majority of this week helping students with "non static variable cannot be referenced in a static context". </p>

<p>For the rest of the term, I am wondering if I should devote a week to thoroughly explaining what exactly the static keyword means, what static space is and the Java memory model, or continue with the material (as there is a lot to cover) and just try to stray away from involving static space and variables in my examples?</p>

CC BY-SA 3.0
2017-07-07T17:03:46.987Z
Perhaps a better place to get an answer for this is the [APCS community board](https://apcommunity.collegeboard.org/group/apcompsci). There are lots of knowledgeable people there.
Buffy
CC BY-SA 3.0
2017-07-07T18:02:28.533Z
Why would topics for AP-A be a gray area? The [course description](https://secure-media.collegeboard.org/digitalServices/pdf/ap/ap-computer-science-a-course-description.pdf) pretty clearly lays out what topics to cover?
Ryan Nutt
CC BY-SA 3.0
2017-07-07T18:27:18.120Z
@RyanNutt Like i've said in the disclaimer, your reference is American and in Canada, Colleges are different from Universities. I'm just trying to gauge what other high school teachers are doing, instead of following an American description in a Canadian school.
Kaneki
CC BY-SA 3.0
2017-07-08T07:13:47.943Z
Please do not apologise (Disclaimer) for not being American; Just state where you are from. This is not Computer Science Educators USA. Everyone else please recognise that the internet is global, there will be people form all over the world her. So say “in the USA the …. says …”
ctrl-alt-delor
CC BY-SA 3.0
2017-07-08T07:29:02.590Z
The most important thing to know about static is that there is **almost** no use for it. Except: profiling (see Ben's slide) and creating a factory of global state. There is also Main, this is just a shame, and hard to explain in the first lesson, but needed. Note that this model (use of static), is not the only one. It is only used in the C++ family of languages (C++, Java, C♯, …). Eiffel offers a very different one that is worth looking at.
ctrl-alt-delor
<curriculum-design><secondary-education><static>
Should Java Static space and Memory Model be a part of AP CS
# Should Java Static space and Memory Model be a part of AP CS

(Asked by: username_0 on 2017-07-07)

**Disclaimer:** I am teaching in Canada and therefore I am unfamiliar with the American AP CS A and AP CS P curricula that others may have talked about. In my school board at least, it is still very grey what exactly to teach in AP CS. Essentially this is a grade 12 course continuing from grade 11 (which taught variables, arrays, loops, functions and simple inheritance). The goal of AP as posed to regular is to focus more on OOP, specifically SOLID principles.

With that out of the way, here's the situation. I am teaching a summer course to high school students who want an enriched Computer Science course in order to succeed in University. This is the first time this course is offered during the summer (and my first time teaching this course). This week, I decided to go over some review of Java basics to gauge the overall knowledge of my class. Ironically enough, everyone seemed to know variables and access modifiers, but as I began going over some Inheritance, students became confused over static variables, static space and where variables were.

I drew out a simple memory model and showed where static, heap, stack and meta-space. I could already tell there were a lot of blank faces *(okay, let's back track)*. I essentially explained that things declared in the static space are global to the project and belong to a class as posed to instances. However, surprise surprise, I spent majority of this week helping students with "non static variable cannot be referenced in a static context".

For the rest of the term, I am wondering if I should devote a week to thoroughly explaining what exactly the static keyword means, what static space is and the Java memory model, or continue with the material (as there is a lot to cover) and just try to stray away from involving static space and variables in my examples?

**Tags:** curriculum-design, secondary-education, static

> **Comments:**
> **username_1**: Perhaps a better place to get an answer for this is the [APCS community board](https://apcommunity.collegeboard.org/group/apcompsci). There are lots of knowledgeable people there.  
> **username_2**: Why would topics for AP-A be a gray area? The [course description](https://secure-media.collegeboard.org/digitalServices/pdf/ap/ap-computer-science-a-course-description.pdf) pretty clearly lays out what topics to cover?  
> **username_0**: @RyanNutt Like i've said in the disclaimer, your reference is American and in Canada, Colleges are different from Universities. I'm just trying to gauge what other high school teachers are doing, instead of following an American description in a Canadian school.  
> **username_3**: Please do not apologise (Disclaimer) for not being American; Just state where you are from. This is not Computer Science Educators USA. Everyone else please recognise that the internet is global, there will be people form all over the world her. So say “in the USA the …. says …”  
> **username_3**: The most important thing to know about static is that there is **almost** no use for it. Except: profiling (see Ben's slide) and creating a factory of global state. There is also Main, this is just a shame, and hard to explain in the first lesson, but needed. Note that this model (use of static), is not the only one. It is only used in the C++ family of languages (C++, Java, C♯, …). Eiffel offers a very different one that is worth looking at.  

---

## 2 answers

### Answer by username_6 on 2017-07-07. Score: 3 | Accepted answer

`Static` is within the AP subset and is fair game for the examination. Oddly enough, the memory model of Java that operates here is not, so students *could*, hypothetically, memorize a series of arbitrary rules and be fine here.

If you think it seems silly to teach about `static` without at least giving a passing understanding of how memory works, then you and I are on the same page. However, in this instance, I provide a simplified (and terribly inefficient!) view of memory usage, because I don't want to delve too far down this rabbit hole in what is essentially an introductory class. (Especially because we haven't yet covered the all-important idea of passing `this` as a parameter.)

Here is a picture of the PowerPoint slide with the setup itself (sans animation). Also not seen is another slide that says, "Hey class, when can a *lie* serve the *truth?* ... **Right now!**")

[![my false model of static](https://i.sstatic.net/H9DrT.gif)](https://i.sstatic.net/H9DrT.gif)

There are more slides, and quite a bit of discussion. But in essence, this model allows me to ask discussion questions like:

* Why are there 3 `Doubler`s in memory?
* Why is there only one `count`?
* What did `static` actually accomplish?
* What would happen if we called `val++` from inside `method()`. Is there any reasonable way for Java to interpret this?
* What would happen if we called `count++` from inside `doubleVal()`? Is there any reasonable way for Java to interpret this?

Now, as for the situation you are in, it sounds like you've already devoted a lot of time to this. I would not spend a great deal more time on `static`. There is a *lot* in the exam, and `static` is not heavily tested. I might do one more quick attempt to try to clarify this idea, but then move on. There is, as you said, plenty else to do.

> **Comments:**
> **username_3**: I like the slide and questions. If used together.  

---

### Answer by username_4 on 2017-07-07. Score: 2

If one understands objects, fields, and variables, static fields should be easy to understand (e.g. as fields of a "class object"). And if one does not understand objects, one can not apply OOP or software design, which makes it very hard (maybe even impossible) to really understand that material.

Therefore, a solid and accurate understanding of objects, fields and variables seems worth investing into even at the price of covering less of the official curriculum.

I am however not sure the memory spaces of the JVM are the best tool to communicate this, because your students may not know what memory spaces are. After all, memory spaces are like objects in that they host variables, so if people are unaware that variables exist in a scope and are bound to its lifetime, naming that scope "memory space" rather than "object" won't help.

BTW, when Java programmers say "Memory Model", they often refer to the [so named chapter](http://docs.oracle.com/javase/specs/jls/se8/html/jls-17.html#jls-17.4) in the Java Language Specification, which gives a formal mathematical model for memory as seen by concurrently executing threads. That would probably be too advanced for your course ;-)

> **Comments:**
> **username_5**: Hi username_4! Welcome to [cseducators.se]! Glad to have your input here. I hope to see you around more!  

---

