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 ...
  • 31.7k
31 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 ...
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. ...
  • 35.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 ...
  • 31.7k
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 ...
  • 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 ...
  • 35.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 ...
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 ...
  • 171
11 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 ...
  • 31.7k
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 ...
  • 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 ...
  • 35.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 ...
  • 3,039
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 ...
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 ...
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 ...
  • 31.7k
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, ...
7 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 ...
7 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 ...
  • 283
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 ...
  • 971
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 ...
  • 1,113
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 ...
  • 283
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 ...
  • 6,227
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 ...
  • 31.7k
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 ...
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: ...
  • 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 ...
  • 3,039
6 votes

Example for For vs While Loop (in Java)

If I'm interpreting your question correctly you'd like real life examples that translate to code. Maybe something like the following. You want to drive or ride your bike to the ice-cream shop a few ...
  • 35.1k
6 votes

Using Oracle's Java Documentation as a Teaching Tool

One obvious benefit, which is really a good goal in and of itself, is that students get used to utilizing documentation. Many students don't use the internet as a resource at all, and those that do ...
  • 31.7k
6 votes

Using Oracle's Java Documentation as a Teaching Tool

I will ask some rhetorical questions below - they aren't meant to be snarky. That, of course, depends on the textbook. I would think that the documentation alone would be a terrible idea. Would you ...
  • 35.1k
6 votes

Java or Kotlin for beginners (procedural programming knowledge is existing)?

I've been using Kotlin for two years now on an introductory course on imperative programming (bachelor's first semester) and I'm very happy with this decision. Before Kotlin, I was using Java for the ...
  • 1,503

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