Teaching Java and OOP
-
-
Number of slices to send:Optional 'thank-you' note:
-
-
Campbell and I have made a few comments recently about what we see as a shortcoming in the way students are being taught programming and Java these days. We have seen a number of students who said that they have completed at least one course in Java programming but are still woefully in the dark about basic language and programming concepts. My son, who is now taking his second Java programming course at a large university in the US MidWest, is in the same boat in terms of the instruction he's receiving although I don't think he's quite as lost as some of the students we've seen here lately.
Campbell and I think that starting students off with largely procedural style programming exercises and then trying to add objects later is ineffective, confusing, and possibly even detrimental. We think that it's entirely possible to teach proper object thinking and OOP programming in Java from the start and still make it very accessible to beginners.
I'm inviting newcomer Paul West and perhaps some of his colleagues to join this discussion.
-
-
Number of slices to send:Optional 'thank-you' note:
-
-
In another thread, Paul West wrote:... They have just been introduced to objects--they still get classes and objects confused!
One reason I like JavaFX is that it does have some web-dev features in it (FXML), but the main issue is the support may be dwindling. On the other hand, Swing has so many resources and legacy applications.
IMO, if they are still getting classes and objects confused, then trying to teach them technologies like Swing and JavaFX will only add to that confusion. At most, console input/output would be more appropriate and would allow you and the students to focus more on the more important concepts of object-orientation, program organization and factoring/refactoring, and clarity.
Here's one example of a student who has one prior Java programming class under his belt: https://coderanch.com/t/670267/java/java/Tips-improvement
IMO, this student is far from where he should be in terms of learning progress. After a semester of Java programming instructions, he should at least have a handle on all the basic program and control structures like if-then-else, while-loop, for-loop, methods, etc. Spending the better part of an entire semester on for-loops is ridiculous! Granted, this may be an extreme example but other students we've seen around here (and from what I've seen in my son's course syllabus) don't seem to be faring much better.
I'm basing my judgement on my own experience from way back in the late 1980s, in the Philippines! The first programming class I took as an engineering student was Pascal programming. Our first machine problem was to generate the Fibonacci series to the Nth number. I think our second machine problem was to calculate factorial(N) iteratively. Then recursively. Somehow, most of us were still able to complete those programs. I should note that although that was my first programming course, it was the second for many of my classmates who had taken the course on BASIC programming in the previous semester.
I realize there might also be a natural bias in the samplings we're seeing here at the Ranch since it's unlikely that we'll see as many of the students who are not as lost as the ones who show up here. Still, in my conversations with my son about his classes, I get as sense that there are still a good number of students who are essentially getting left behind.
-
-
Number of slices to send:Optional 'thank-you' note:
-
-
-
2 -
-
Number of slices to send:Optional 'thank-you' note:
-
-
Paul West wrote:At my University, the base classes go Procedural Programming (C)-> OOP (JAVA) -> Data Structures(C++), which is (probably) common.
For me, the progression was Procedural Programming (Pascal) then Data Structures & Algorithms (Pascal) I && II. OOP wasn't included in the curriculum in my time although there were courses on AI, Prolog, and LISP for higher years.
I think the main problem for students who start off with Java as their first programming language is that they lack context in procedural programming. When I started learning Java, I could compare it to what I know from languages like C, BASIC, and Pascal. I also had the advantage of having worked with Delphi/Object Pascal. I guess you could say that I had a bit of an advantage over these kids in terms of learning Java and OOP. The difference, I think, is context. I could put "object-thinking" in context and could see the differences and advantages that OOP brought to the table. Most of these kids don't have that and being thrown into a mixed paradigm of writing procedural code in a supposedly object-oriented language like Java causes a lot of confusion.
-
-
Number of slices to send:Optional 'thank-you' note:
-
-
Paul West wrote:One reason I like JavaFX is that it does have some web-dev features in it (FXML)
I agree with Junilu. It isn't worth going through JavaFX in my opinion as there is nothing special about it, especially FXML. It follows MVC architecture and the magic story ends here. Even Oracle encourages to use Scene Builder along with FXML for auto code generation, so that simplifies and speeds up things even more. There should be a course about Web Authoring which supposed to teach about web-dev features, but that is not much to do with Java programming language concepts as such.
I too believe that time spent on JavaFX better would be spent for a deeper grasp of main language concepts. The main program's logic in JavaFX application going to be in a model and might controller parts where again we go back to concepts Junilu have mentioned. So, to go with GUI before good grasp of objects is putting a cart in front of horse.
-
-
Number of slices to send:Optional 'thank-you' note:
-
-
-
-
Number of slices to send:Optional 'thank-you' note:
-
-
I wonder if that's not like dropping people blindfolded into the forest and telling them to find their way out. The similarity is that in both situations, the subject or "victim" if you will, has no context. They don't have a point of reference from which to plan their way forward and out of the situation they find themselves in.
If, on the other hand, you showed them the lay of the land first, so that they can get a sense of the big picture and where they are headed, that might give them a better chance of navigating through the thick underbrush.
I'll try to give an example later.
-
2 -
-
Number of slices to send:Optional 'thank-you' note:
-
-
One of the big reasons to start off thinking of programs as step-by-step is that what the programs are (until we go to multi-processing.) I see it as important to help build up the intuition before moving on to advance features (OOP.)
In other words, I think Procedural should be taught before OOP as it lays down the groundwork before proceeding to code organization, design, etc...
As for JavaFX vs Swing. Let me point out that I do one week of GUIs. Everything else I test their classes (usually via JUnit.)
-
-
Number of slices to send:Optional 'thank-you' note:
-
-
Paul West wrote:I do not think Java is a good first programming language. OOP is not intuitive until foundational programming syntax/semantics are established (control flow, data types, algebra, function, etc...)
...
In other words, I think Procedural should be taught before OOP as it lays down the groundwork before proceeding to code organization, design, etc...
In many schools, like my son's, that's a moot point. Java is the first programming language many academic programs have in their curriculum. Also, there are many self-taught programmers who, for some reason or another, want to start out with Java. Most of the books and training material available out there pretty much take the same approach though. Again, I have to go back to finding a way to give the learner more context. Most of the first lessons dive right into details, without so much as a mention of the bigger picture.
Here's an outline that I'm toying around with:
1. Programming as problem solving
2. Stating the problem
3. Envisioning the desired end state
4. Identifying main steps for solving the problem
5. Decomposition - breaking things down into smaller tasks
6. Putting everything together
7. Using tests to drive the problem solving process
This can probably be shortened to just items 1, 2, 3, and 4 to start with. Then as the problems become more complicated and solutions more involved, you can add on decomposition, orchestration, and testing. Somewhere in there, you can show the difference between procedural thinking and object thinking. I have to go now but I can share a couple of examples I'm playing around with later this evening.
-
-
Number of slices to send:Optional 'thank-you' note:
-
-
I think the real problem is that OOP is not intuitive full stop. We see lots of people here writing pure procedural code, and they have completely failed to add objects to that. If it is so easy to add objects after teaching selection and iteration (which are intuitive), why don't we see people writing good OO code here?Paul West wrote:. . . OOP is not intuitive until foundational programming syntax/semantics are established . . .
I was taught Java® differently. We started with objects; they were simple, but didn't involve selection or iteration. Only after we had seen objects did we see if or while.
-
-
Number of slices to send:Optional 'thank-you' note:
-
-
There are three kinds of actuaries: those who can count, and those who can't.
-
-
Number of slices to send:Optional 'thank-you' note:
-
-
Campbell Ritchie wrote:If it is so easy to add objects after teaching selection and iteration (which are intuitive), why don't we see people writing good OO code here?
I think that expecting students to write good OO code is a tall order. I’m sure some exceptional ones can but not many. I think that understanding programming syntax, control flow, data types etc is easier than understanding OO concepts. Many students leave university with a rudimentary understanding of what objects are and how they communicate with each other. It takes a while to fully understand this. It takes even longer to learn how to write good OO code as this requires a reasonably good grasp of OO principles (like SOLID) and design patterns which some seasoned programmers struggle with. I've been programming for a year and a half and it took me a while to fully grasp basic concepts of OO programming like encapsulation, inheritance and polymorphism. In university, you learn enough about these OO concepts to pass an exam but I think that a student needs real world experience in order to fully grasp these OO concepts.
-
-
Number of slices to send:Optional 'thank-you' note:
-
-
Now if the issue on this site is that students start with Java as their first programming language and work on procedural coding, then yes that is absolutely terrible.
To expand on Daniel's point of a BS in CS student's grasp of OOD, keep in mind that we aim to create generalists who can pick up on topics easily. I'm not saying a student shouldn't know the basics (encapsulation, polymorphism via inheritance, separation of labor, etc..), but that trade-offs are made. Example: Do you we teach advance Design Patterns or Caches? Furthermore, all the Universities I've attended as a student and faculty have CS as a packed major. In other words, we do not have enough time to cover everything. American Universities have time constraints.
For my OOP class I've been slowly adding Design Patterns and other OO principles. It would be great if there was a good list of questions about OOD. Most I find are: write a class that does blah blah blah. Instead, I'd prefer, Design a system that does blah blah adhering to <insert Desin Pattern/Paradigm here>. The questions should have a grading rubric that helps me identify good student solutions and bad because there will be so many of each.
-
-
Number of slices to send:Optional 'thank-you' note:
-
-
-
-
Number of slices to send:Optional 'thank-you' note:
-
-
I have started recommending to participants of the TDD workshop that I give at work to start getting better at refactoring before they start trying to write tests first. To get better at refactoring, they need to get better at recognizing code smells. To get better at recognizing code smells, they need to recognize when principles have been violated, and to that, they need to understand principles. So for me, it all boils down to knowing principles first. Everything else follows from there. In this progression, I think learning about patterns would be somewhere around when you start learning to get better recognizing code smells and refactoring.
-
-
Number of slices to send:Optional 'thank-you' note:
-
-
By introducing students to the concept of giving objects the responsibility of performing tasks in the program early on, I think this allows them to form a good mental model with which they can take on the of encapsulation and inheritance. I think the first concept that needs to be understood before all that though is that of "assignment of responsibility" - which is related to functional decomposition, and you can easily make contrasts between procedural style Java and object-style Java to show that.
Then you can introduce examples where data is involved, like say introduce a message variable that can change values, then require that the program be able to display greetings in various languages. Then add more twists to the requirements to build on top of what's already been written. Each progression would show how the program can be written procedurally and then contrasted with code that uses objects. This at least gives them some context and a way to better see the point of using object-orientation. With these simple examples you can already show decomposition, abstraction, good naming, and organization of the code.
-
-
Number of slices to send:Optional 'thank-you' note:
-
-
Junilu Lacar wrote:I'm a big fan of refactoring to patterns instead of starting off with a pattern in mind. I'm also a big fan of simplicity, hence, I often make references to the 4 Rules of Simple Design. Patterns evolved out of instances. Someone had a problem, they solved it a certain way. Someone else had a similar problem, and they came up with a similar solution. After a third time, somebody said, "Hey, there's a common theme here..." and then the pattern was given a name, defined, and publicized. It seems logical to me to have students go through that same process of discovery and recognition, rather than telling them, here's what you want to do, and this is the pattern that you want to use to do it. That gives them only the end goal and the solution, leaving out the most important thing, IMO, about patterns: the context in which a problem can be solved by applying a pattern. And I don't buy an argument that says, "Well, the problem is 'How do we achieve this goal?'" It's not, and if you think it is, then I don't think you understand enough about patterns.
I looked at the TOC for Refactoring to Patterns and it looked good, so I requested my free exam copy -- a perk of academia. I have considered using Design Patterns as my book, but that is a little advance for the students.
I think a little history will help people understand my position right now. When I started at the University, the course order was [Alice or VB] -> C++ -> Java I -> Data Structures (C++). In other words, it was very language focused, which I wanted to change. I put in a request to change Intro to Computer Science to Procedural Programming and Java I to Object Oriented Programming. Last week that got approved, so I'm in this transition period were the course is still "Java I", but I'm focusing more on OOP. Right now, I'm trying to figure out the best way to setup the new course as all the old materials are heavily Java focused. The current book is Java Foundations: Introduction to Program Design and Data Structures which does have some OOP, but focuses on Data Structures--an important subject covered in the next course. If you have suggestions, please send along!
I get the feeling most people here would agree the change is for the better, although some would want to change the order. BTW, Alice/VB courses are for people with no programming experience who want to get an idea of programming. So, while Java/OOP is technically the third course, I generally say it is the second programming course. (If you have ever done Alice before you will see why.)
Your example is a good start, especially for getting terminology down (which is hard at first.) I just need a good source that can continue it throughout the course. Aka, a textbook...
-
-
Number of slices to send:Optional 'thank-you' note:
-
-
Piet Souris wrote:What I'm missing sofar: what kind of students are we talking about?
These are college students in their second or third semester of Computer Science at an accredited 4-year private University. They have gone through a basic Procedural Programming course (no Objects) so they understand basic data types, control structures, functions, and divide-n-conquer. Most are Computer Science majors, but some are minoring. Most that minor are in Graphic Design.
Most students (majors and minors) are taking a networking class along with this one.
-
-
Number of slices to send:Optional 'thank-you' note:
-
-
I would love to see collaborative development (working either in pairs or groups of 3 or 4) be encouraged more, at least when working on course projects. Being familiar with pair or mob programming would really prepare your students for the kind of real-world development done at leading tech companies these days.
-
-
Number of slices to send:Optional 'thank-you' note:
-
-
I looked around and got a hold of "The Object-Oriented Thought Process" (TOOTP), and I'm liking it so far (haven't finished reading it yet.) My main concern is the focus on theory instead of practice--the students need lots of concrete examples. The TOOTP book provides some good examples, but I believe they need more of how to write the Java syntax (the book does not cover Java syntax extensively.) In other words, I believe the students would get the semantics, but be lost on the syntax (a common problem in my courses.) I'm debating on letting them "use the Internet" or sticking with a second book to fill in the need. Do you have any suggestions, the search has become extremely monotonous...
Currently I'm looking at http://www.tutorialspoint.com/java/java_tutorial.pdf and have requested a copy of "Core Java Volume I--Fundamentals" to fill in the practical need.
Thanks again for all the help,
~Paul
-
-
Number of slices to send:Optional 'thank-you' note:
-
-
Is this that book? I have an earlier edition and I wasn't particularly taken by it, though other people liked the newer edition more. See our books pages. I agree that books about refactoring are a long way beyond the reach of the students we are discussing here.Paul West wrote:. . . "The Object-Oriented Thought Process" (TOOTP) . . .
-
-
Number of slices to send:Optional 'thank-you' note:
-
-
-
-
Number of slices to send:Optional 'thank-you' note:
-
-
https://coderanch.com/t/671520/java/Java-Inheritance-Error
https://coderanch.com/t/671579/java/returning-String-representation-Ball-Path
I walked my son through a full solution (about 50 lines of code) of that ball drop simulation problem and it took less than 20 minutes for him to fully comprehend what he would need to do. In those 20 minutes, I demonstrated the importance of choosing good names, showed him how to refactor (rename) to clarify intent, showed him how to organize the code and how to refactor (extract) to eliminate duplication as well as clarify intent, showed him a better way to generate a random boolean value using java.util.Random.nextBoolean() instead of Math.random(). More importantly, I walked him through the thought process I used to attack the problem and come up with the solution. All this will give the student the context that they will very rarely, if ever, discover themselves if left alone with just step-by-step instructions. They also lose the opportunity to think about good names, semantics, and organization when they are given detailed instructions like what to name a class. In the case of the ball drop simulation, I don't even agree with the requirement to call the class "Path" -- I used "Ball" instead in my solution and it reads a lot better and makes a lot more sense.
As Andy Hunt said, "Always consider context" and I think that's what a lot of instructors don't give to their students enough.
-
-
Number of slices to send:Optional 'thank-you' note:
-
-
It takes only a few minutes to explain the thought process and motivation behind the refactoring here. With just a few minutes of investment, the student gains a valuable tool that he/she can use in similar situations in the future.
-
-
Number of slices to send:Optional 'thank-you' note:
-
-
Refactoring is not too advance for my class. What I stated was that the book Refactoring to Patterns would be too much of a jump to use solely for my class. The issue I'm having is finding a good book to bridge from I-have-no-idea-what-an-object-is-and-I'm-a-terrible-coder to refactoring. From your example, I'm always amazed how confusing "private boolean bouncesRight()" is to my students... Private!? Boolean!? rand.something!? You would be amazed how many times I see students type Random.nextInt() and they look at me like it should work perfectly! >.<
I know how some other Java classes are taught which lead to a lot of How and leave out Why/What. Please understand that my students seem to grasp Why/What fairly well. I have finished grading the midterm and they did well (80%+) on the SOLID portion which required them to read code, identify why the code was poor (smells) and then stub out a solution. What they did less well on was following the iterations of a for loop. Yes, literally they knew how to apply LSP, but failed on how many iterations are in a simple two variable for loop. (!!!)
~Paul
-
-
Number of slices to send:Optional 'thank-you' note:
-
-
-
-
Number of slices to send:Optional 'thank-you' note:
-
-
-
-
Number of slices to send:Optional 'thank-you' note:
-
-
Another one is when you explain the arrow code anti-pattern to them. I've seen experienced programmers get very sheepish when I point out the problem in that example. I get a lot of "Huh, I never knew this was a bad practice" admissions of guilt and even once had a group tell me "Huh, and all this time, we thought that nesting was a good thing. We do that a lot."
-
-
Number of slices to send:Optional 'thank-you' note:
-
-
Junilu Lacar wrote:Another thing that bothers me is that there seems to be a general perception that refactoring is too advanced a concept for beginners. I just don't see how hard it can be for a beginner to understand the benefit of doing something like this:
[code]
// Initial code
if (Math.random() < 0.5) {
return "R"
} else {
return "L"
}
// First refactoring: use java.util.Random instead
I guess it is pretty much subjective. This method is so easy to read, that I certainly would not refactor it. I would change the '0.5' for a parameter 'p' though, to enable to solve the assignment even when the nails were biased in the way the ball would bounce. Or I would have this method return a 1 or a 0, with some extra function f: int -> string. Having such a method allows one to easily adjust the solution when the assignment would have been about drawing red and green balls with substitution, given some ratio for these balls. The real context being that the assignment is just a demo of that well known toy about the binomial distribution, and maybe the deeper problem is simply some lack of decent maths. Would the student be able to reckognise how to answer a question like: what is the chance the ball ends up in some specific bin?
There are three kinds of actuaries: those who can count, and those who can't.
-
-
Number of slices to send:Optional 'thank-you' note:
-
-
-
-
Number of slices to send:Optional 'thank-you' note:
-
-
-
-
Number of slices to send:Optional 'thank-you' note:
-
-
-
-
Number of slices to send:Optional 'thank-you' note:
-
-
The story will continue...
-
-
Number of slices to send:Optional 'thank-you' note:
-
-
I definitely want to put something in that document about the lack of context given to students. We see numerous examples here where students are given lots of details but have very little idea of what the big picture is that all these little nuts and bolts fit into. That is, there seems to be a disproportionate focus on mechanics and technical details (like the obscure Design-By-Contract notation that I discussed in another thread) and less on principles and foundational skills like problem solving approaches, organization, clarity, abstraction, functional decomposition, etc.
Are there other things anyone can suggest that would go into a document that lists the "Top 5 Concerns about the Misalignment Between Industry and Academia"?
-
-
Number of slices to send:Optional 'thank-you' note:
-
-
-
1 -
-
Number of slices to send:Optional 'thank-you' note:
-
-
While I wish there was a simpler solution, I'm starting to believe that the students just need to go through the pain.
So a quick top 5 off the top of my head:
1) Team Experience (see above)
2) Abstraction: It takes students awhile to how simplify their thinking improves productivity.
3) Public/Contract: It takes students awhile to realize that anything will be sent to their public methods. I make my test cases pure evil. Public/Contract should be simple, yet powerful enough to fulfill the requirements.
4) Refactoring: Most student seem to believe it is best to just rewrite the entire thing. There are numerous was to refactor code. Hopefully I'll have time this semester to go through them.
5) Testing: This goes with #3, but more of a your test cases are part of your code. IE: we need to be able to measure the quality of your code as well as the code submitted.
Thanks Junilu on staying on this, I'm interested to see what come out!
-
-
Number of slices to send:Optional 'thank-you' note:
-
-
I heard back from a faculty committee chair today. They seem willing to discuss my concerns but also asked me to cite "standard literature, e.g., well-cited papers in conferences devoted to CS education such as SIGCSE, that may be directly related to your suggestions." I just replied that I have no such references to give them since the concerns I have come mostly out of personal experience, and informal observations and discussions like this. I'll put my concerns and things we've discussed here in a writeup that summarizes what I want to address with them. Hopefully, I can make a compelling enough case to keep the conversation moving forward.
-
-
Number of slices to send:Optional 'thank-you' note:
-
-
-
-
Number of slices to send:Optional 'thank-you' note:
-
-
-
-
Number of slices to send:Optional 'thank-you' note:
-
-
Unfortunately, I believe a good number of public college/university have a difficult time with dissuading students from certain career paths. I have taught at a public college and I've talked to some professors from others. There is a push to meet a graduation quota which essentially drives a "lower bar" for classes. It also dissuades professors form have "the talk" as well. This is coupled with the fact that the US is in short supply of programmers has only made the situation worse.
Sadly, I have no solution to this problem because there is so much money in the University system. =(
Junilu -- So a University asked for academic papers showing why academia is disconnected from reality? ba dum ching! In seriousness, I'm glad someone has at least attempted to show the problem.
| Stop it! You're embarassing me! And you are embarrassing this tiny ad! The new gardening playing cards kickstarter is now live! https://www.kickstarter.com/projects/paulwheaton/garden-cards |










