Hot answers tagged

36 votes
Accepted

When mentoring individuals, teach clean coding and simple/effective thinking or let them do it their way?

As someone who has now taught CS for many years, let me first reassure you that teaching clear, clean coding is entirely worthwhile. I think this is especially true for those who will not go off into ...
Ben I.'s user avatar
  • 33.1k
32 votes
Accepted

Explaining access levels and visibility in OOP

Here's an analogy that I've used for several years, and that students seem to understand. It doesn't focus on the rules, but why we have public and private and protected. "Most of you know that I ...
Stephen Gilbert's user avatar
28 votes

Teaching the tradeoffs of the foreach loop

I think the advantages are huge, overwhelming. They avoid off by one errors - the bane of the novice programmer needing to allocate an explicit iterator - avoiding adding names to the namespace. ...
Buffy's user avatar
  • 36.1k
27 votes

How can we teach good naming practice for students learning Java?

Fair warning, I do not demand any particular naming convention (such as NetBeans) from my students. This leaves me with variable naming only for the purpose of clarity. I speak constantly to my ...
Ben I.'s user avatar
  • 33.1k
20 votes
Accepted

The impact of switching to Java 10

General overview on updating to Java: First, a general observation about updating to Java. Previous versions of Java used to be released about once two years or so. As of 2017, Java has switched to a ...
Michael0x2a's user avatar
  • 4,005
19 votes

How can we teach good naming practice for students learning Java?

There are at least two parts to teaching naming. The first is to have a good standard that the students know and understand. This can be provided in a checklist. But the more important aspect is to ...
Buffy's user avatar
  • 36.1k
14 votes

Parent class variable pointing to Child class

Just to add on to Bryan R's response, upcasting is typically automatic, as a side-effect of data structures or methods that store or utilize a parent type. There's not much point to the example in ...
Ben I.'s user avatar
  • 33.1k
13 votes

Explaining access levels and visibility in OOP

What my teachers used was the following example, which is pretty simple and most people understood. Your father orders a pizza. The delivery guy arrives and expects payment. The ...
shalah allier's user avatar
12 votes

Explaining access levels and visibility in OOP

Ooh, this is one of my favorite lessons! I don't introduce package private and protected in the same lesson as private and public, because there are 3 principles that I want them to absorb that ...
Ben I.'s user avatar
  • 33.1k
12 votes

The order of subjects in beginner's curriculum

We teach AP CS assuming that our students come to us with no prior computing background. Being that the language for AP CS A is Java, we plan our sequencing accordingly. We don't follow the approach ...
iFrame's user avatar
  • 171
10 votes

Teaching the tradeoffs of the foreach loop

I think foreach loops are great, and are almost always preferred over for loops. While for loops are fundamental material and definitely should be covered, they're sort of infrequently used in ...
Michael0x2a's user avatar
  • 4,005
10 votes
Accepted

Teaching C++ to students that know Java

Actually, the similarities between C++ and Java are fairly shallow and the differences are very deep. The syntax of both is derived from C, but the underlying ideas are very different. The biggest ...
Buffy's user avatar
  • 36.1k
9 votes

What autograding software do folks use for Java code?

For simple stuff I've used CodingBat. They've got an authoring system buried on the site. It's not terribly difficult to create your own questions, although the instructions are pretty wordy. When ...
Ryan Nutt's user avatar
  • 3,029
9 votes

Teaching the tradeoffs of the foreach loop

There is much discussion here about how a traditional for seems more powerful than a foreach, but a traditional ...
VisualMelon's user avatar
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 ...
Matthew Fahrenbacher's user avatar
8 votes

Analogy for abstract classes

The rules for abstract classes are the same as for other classes, with a few minor differences: An abstract class may have methods that do not have a body An abstract class has to be sub-classed, at ...
Gypsy Spellweaver's user avatar
8 votes
Accepted

Explaining how an Interface is a contract

A few things jump out from the official Java documentation: As far as an example goes, the idea of a Remote as an interface works really well based on this explanation. Methods form the object's ...
Peter's user avatar
  • 9,102
8 votes

Explaining how an Interface is a contract

This answer draws on Java examples. I start the interface discussion with a mechanical SATA hard drive in my hand. I discuss the interface called SATA and its universality across devices. I expand ...
ThisClark's user avatar
  • 293
8 votes

Motivation for learning C++ when you know Java

I think you're having trouble justifying the study of C++ because of the way that you're thinking about it. If you are aiming towards the practical benefits, then you immediately get to the following ...
Ben I.'s user avatar
  • 33.1k
8 votes

Java: The Complete Reference, which edition to follow

The fundamental question is, whether your goal is to learn programming (in which case the language doesn't matter at all … theoretically at least) or to learn Java. If you want to learn programming, ...
Jörg W Mittag's user avatar
7 votes
Accepted

The order of subjects in beginner's curriculum

I once wrote a course to introduce Java. My order of topics was as follows: (Note: Those are not lessons, just the order I've written the topics down). Obligatory Hello World, console output Comments ...
TuringTux's user avatar
  • 1,011
7 votes

How can we teach good naming practice for students learning Java?

Something I have used is to present the students with a paper form (like an application form). Each of the fields is labeled sequentially with A, B, C, etc. Then I ask the students to fill out the ...
Fritz Sieker's user avatar
  • 1,203
7 votes

When mentoring individuals, teach clean coding and simple/effective thinking or let them do it their way?

I emphasize readability and maintenance of code. Therefore, I will assign a project and later turn around and require another student to complete the second half of it. Everyone ends up maintaining ...
ThisClark's user avatar
  • 293
7 votes

Parent class variable pointing to Child class

A common case is if there are multiple subtypes of Dog, you might create an ArrayList which can hold any type of dog. Or you might have a method that takes a reference to a Dog (doesn't care what ...
Bryan R's user avatar
  • 508
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 ...
ItamarG3's user avatar
  • 6,297
6 votes

Command-line Java in AP CS A

Similar to @ncmathsadist, I use both command-line environments and IDEs, and I have only found them enhancing each other. We do most of our work in IDEs, but a few assignments are done in CLIs every ...
Ben I.'s user avatar
  • 33.1k
6 votes

What autograding software do folks use for Java code?

I would recommend repl.it classroom It allows creation of a course and assignments within that course. Assignments can be auto-graded using unit testing (JUnit) or by providing inputs and comparing ...
Todd Whittaker's user avatar
6 votes
Accepted

Analogy for static objects (or members)

Static members belong to the type, not the instance Static members are best seen as belonging to the type rather than the instance. If you're inside a class, it can be harder to see: ...
Nat's user avatar
  • 897
6 votes

Analogy for static objects (or members)

I use school colors and principal's name. If someone comes in tomorrow and says your principal is no longer Mr. Smith, it's now Ms. Jones then that change is made for every object (student) in the ...
Ryan Nutt's user avatar
  • 3,029
6 votes

Explaining how an Interface is a contract

I believe that using the term "contract" is hurting more than helping. Most students in that age-range have no personal experience with contracts, so the term is too abstract or remote. Secondly, ...
Gypsy Spellweaver's user avatar

Only top scored, non community-wiki answers of a minimum length are eligible