8
votes
How to illustrate scope problem when creating variables inside `if` statements in Java
I like to use an analogy from Finding Nemo. I tell them their programming language has the same problem Dory has - short-term memory loss. When a variable is declared within a block, Java will ...
6
votes
How to illustrate scope problem when creating variables inside `if` statements in Java
I explain this with a saying:
What happens in the block stays in the block
Now, this isn't exactly how it works, but the idea is that the students remember that what they create in a block, is ...
5
votes
How to illustrate scope problem when creating variables inside `if` statements in Java
I teach my students a bit about the stack as part of the very first lesson of the year. As a result, they are aware coming in that primitive variables are stored next to one another in the stack ...
4
votes
First Time teaching 6th & 7th grade computer science
Concur with @Ben about HTML5 (see disclaimer, below).
Recommend investigating the Computer Science Field Guide (don't be distracted by the TLD, the Curriculum Guides include AP-CSP. (and New Zealand ...
3
votes
How to illustrate scope problem when creating variables inside `if` statements in Java
Java, like C/C++ has block scope. When you create a variable in a block, the stack pointer moves to make room for it. When the block ends, the stack pointer moves back. This makes the variable ...
3
votes
How to illustrate scope problem when creating variables inside `if` statements in Java
You should be able to copy/paste block of codes that does not use other variables. But in your examples what if you want to copy/paste that to a code that already declared x? It would not work
...
2
votes
How to illustrate scope problem when creating variables inside `if` statements in Java
Something that might be helpful is using computers. Files created on the school computer in the classroom don't exist anywhere else. The file can be copied somewhere else, just like passing it back ...
2
votes
First Time teaching 6th & 7th grade computer science
I have a few thoughts:
Scratch is wonderful, and very appropriate to that age group. TinkerCAD is another great alternative.
HTML/CSS is fine as an entree into JavaScript for front end web ...
1
vote
How to illustrate scope problem when creating variables inside `if` statements in Java
Another benefit of block-level scope is that because variables defined in a block go out of scope at the end of that block, their values are then eligible for garbage collection (assuming no other ...
Only top scored, non community-wiki answers of a minimum length are eligible
Related Tags
scope × 2curriculum-design × 1
programming × 1
java × 1
ap-computer-science-a × 1
scratch × 1
secondary-education × 1