The Stack Overflow podcast is back! Listen to an interview with our new CEO.

Hot answers tagged

30

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 live down at the beach. If you find yourself riding past my house, and it's hot outside, you might come to my front door, knock and ask if you could have a soda. I ...


26

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. They enable thinking about iteration at a higher level than just counting compact coding I use them whenever available. The collection knows its members....


26

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 students about the two different audiences for code: the computer itself (which is the one kids naturally think about), and other is human beings, which students ...


20

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 bi-yearly release schedule: there will be a new version of Java released every March and September. Each release is also guaranteed to receive two updates (one ...


18

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 always demonstrate good naming in all examples that you use and in all quizzes and exams that you give them; even for very simple exercises. The Naming Standard ...


13

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 wallet containing the money belongs to the object father If the wallet is private, then you have to get your father to open it and pay. If the wallet is protected, you can go and ...


12

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 of starting with Hello, world. and user input because I think it (main, System.out.println, and Scanner) produces too much of a cognitive load at once . I always ...


11

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 ultimately motivate the entire system. My lesson introduces a few more ideas than just permissions (it's really how I get started with Ojects), but the key ideas of ...


10

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 practice -- when iterating, we almost always iterate over lists and other collective (and it's generally considered bad practice to modify a data structure you're ...


10

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 difference is that an "object" in C++ is built on the stack, like a struct, not on the heap. It takes additional work and a lot of understanding to become ...


9

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 you create a problem there are a set of fields to fill in. I'd attach a screenshot, but the network I'm on blocks imgur. I'll try to come back and add an image ...


9

There is much discussion here about how a traditional for seems more powerful than a foreach, but a traditional for with sentinel value can only be used to iterate over an indexable collection. Data structure like sets and maps are prevalent, and iterating over them by index would be technically and conceptually absurd. (You've already outlined places where ...


8

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 forget about the variable (just like Dory) after reaching the end of the the block. So a block declares the "scope" of Dory's short term memory. I've been ...


8

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 trap: neither you nor your students has any idea what languages they will work with in the future, so neither you nor your students have any idea what ...


7

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 some level, to a non-abstract class before you can instantiate an object It is not legal to directly instantiate an object of an abstract class With an ...


7

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 This is something missing in the curriculum you provided. I don't know how important it really is, but I like the idea to introduce comments because I ...


6

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 accessible only inside the block. So: if(shouldGoIntoBlock){ int x=10;//created in the block System.out.println("printed from if body: "+ x); else{ ...


6

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 year to ensure that students slowly gain some familiarity with those environments. Reasons for IDEs: Convenience Easy integration with GitHub Error ...


6

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 expected outputs against actual outputs. Students get feedback on what test cases passed and which did not. These can then be converted directly into student ...


6

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: class Animal { static int moveSpeed = 4; int currentLocation = 10; void Walk() { // Can you tell which variable is static without looking above? ...


6

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 school. You don't have to go to each individual student and tell them that their principal has changed. It worked really well this year because we did get a ...


6

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 this with some digital images of SATA on an optical disc drive as well as a solid state hard drive. Some discussion follows regarding the variety of brands and ...


6

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 often wind up on StackOverflow. It has been my experience that the very basic searches that those students often perform wind up at SO pages that are rather too ...


6

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 teach a class in Shop by giving each student a box of tools and no instruction? The quality of the official documentation is, as you note, excellent, but there ...


6

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 form with information about themselves and tell them that getting all the answers correct will determine whether they pass the course or not. Of course, I ...


6

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 same course. Here are some of the benefits: No need to explain what are classes on a imperative programming course, since Kotlin programs can only have a main(...


6

First, it is not "well accepted" that processing sorted array is more efficient. It depends on what you do. If you spend your time inserting, for instance, then sorted arrays are not necessarily a good choice. You are better off inserting at the end (say if you have resizable arrays such as Vector<X> or ArrayList<X> in Java), and then sort ...


5

Here is my system. I give it top marks for ease of sharing, but one downside is that it does not do any kind of autograding without some scripting on my part. I purchased a paid subscription to Dropbox. This allows me to set up read-only folders. At the beginning of the term, I copy/paste all of the names from the course into an Excel spreadsheet and ...


5

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 during runtime, and that the names of the primitive variables that we use in our code are removed by the compiler, and replaced with memory locations. They are ...


5

One way to approach this might be to have students identify what they all have in common and what they each possess individually. That which is common -- like the school they are attending or the class (and maybe grade level) they are in -- should be static. That which is not -- like name or age -- should not be static. You could also go into sufficient ...


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