Posts

Showing posts from April, 2019

Object Comparison: the equals and hashCode methods

Image
I wrote this back in March, 2012 for my Object-Oriented Programming class at Texas Wesleyan University in Fort Worth. I got this out of the "vault" because my son, who is in High School, has a friend who had a question on this very topic. I thought I had posted this to my blog and was shocked when I learned that was not the case. So, here we go... The equals method In my opinion, this is probably the most overlooked topic taught in Java. I have worked (and still work) with developers who seem to struggle with the concept of object comparison in Java. In Data Structures, you may have learned this concept. I will attempt to illustrate and simplify this concept using a "real life" example. For my illustration, I will use the famous Russian Dolls. A "Russian Doll," as it is typically known, is a set of wooden dolls of decreasing size placed one inside the other. Basically, all dolls with the exception of the smallest one are hollowed so t

Java Keywords (Part IX): Switch Statements

We are up to 26 grayed out keywords! Considering that the two keywords with asterisks are not going to be covered, that's 54% keywords covered. With those keywords, you can write simple classes that can do all sorts of tasks. You can change the flow of operations by using flow-control keywords like if/else and loop operations using for, while, and do/while. You can also skip iterations while looping or terminate loops early by using continue and break respectively. This blog will illustrate a more effective way (in certain cases) to change flow of operations by using the keyword switch . I suggest that if you have not read any of the articles in Java Keyword series, go back read them before proceeding further. Also, go back and read the one about Data Types. All of these articles are from September 2018. That should help you find them quickly. You can also use the "search" option at the top of this page. Java keyword list abstract continue for ne

Java Keywords (Part VIII): Skipping Loop Iterations and Escaping Loops

This should be a short one. This blog deals with the use of only two keywords: break and continue . The Java keyword list has 24 keywords grayed out. That almost 50% of keywords covered by these series of articles. I suggest that if you have not read any of the articles in Java Keyword series, go back read them before proceeding further. Also, go back and read the one about Data Types. All of these articles are from September 2018. That should help you find them quickly. You can also use the "search" option at the top of this page. Java keyword list abstract continue for new switch assert default goto * package synchronized boolean do if private this break double implements protected throw byte else import public throws case enum instanceof return transient catch extends int short try char final interface static void class finally long strictfp volatile const * float native super while

Object-Oriented Programming Basics: What is in a Class?

EDITORIAL NOTE : This article was published briefly back in 2016 and quickly set back to draft because I wasn't happy with its contents. It is a shame that it was taking me three years to revisit this topic and work on a new and improved version. At least, I'm hoping it will be to the liking you the reader. Keep in mind that the opening paragraph will still read as if I just wrote it for my (former) students at Texas Wesleyan. I started working on lecture on the topic of Object-Oriented (OO) Programming by gathering some material, old and new, when I realized this might be good and simple post for my second attempt at blogging. To be completely honest, in the 8 hours I spent collecting information and preparing material for this week's lecture, I realized I still made some of the mistakes I am about to blog about. I am actually hoping I can write a series of postings regarding Object-Oriented Programming (OOP). But to do so, I must start from the very beginning.