Posts
Enforce non-instantiability with private constructors
- Get link
- X
- Other Apps
The Beauty of the Null Object Pattern
- Get link
- X
- Other Apps
Before we start... Let me start by saying this: NEVER dismiss an idea without giving it any consideration. That was the mistake I made when I first encountered an article about this design pattern many years ago. I was thrown off by the name and without even attempting to find out what this design pattern was all about, I moved on to other things. That was a huge mistake and I am not afraid to admit it. I urge you not to make that mistake. And if you have already, never make that mistake again. Trust me, you will thank me later. For now, let me tell you my story and attempt to explain when to use it along with a simple example on how to implement this pattern. The Null Object Pattern By definition, the main purpose of this pattern is to have an Object-Oriented alternative to the absence of objects by creating objects that display "do nothing" behavior. That sounds like a mouthful. In simplest terms, it is meant to provide a mechanism to replace null references w...
Java Keywords (Part XIII): Import Keyword and the Concept of Java Packages
- Get link
- X
- Other Apps
We are up to 36 keywords covered in previous articles! That's 75% keywords covered. We have only 12 keywords to cover and I will be covering 2 of those in this article. I am so excited about getting to nearly the end of the series. As I mentioned before, knowing the Java keywords and being able to explain their usage correctly, is something that you will most likely need in an entry level Java programmer job interview. If this ever helps one of you, I would love to hear from you! This article will illustrate the use of the keywords import and package . This is going to be a very short article. I promise. I suggest you start with Java Keywords (Part I) before proceeding further, if you have not read any of the previous articles in the Java Keyword series. 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. The se...
Java Keywords (Part XII): Implementing Interfaces and Extending Classes
- Get link
- X
- Other Apps
We are up to 34 keywords covered in previous articles! That's 71% keywords covered. We have only 16 keywords to cover and I will be covering 2 of those in this article. This article will illustrate the use of the keywords implements and extends for implementing functionality outlined in interfaces as well as extending the functionality of a class. I suggest you start with Java Keywords (Part I) before proceeding further, if you have not read any of the previous articles in the Java Keyword series. 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. The series was written with natural progression in mind. Therefore, some of the keywords already covered may be used in code examples illustrated here. Java keyword list abstract continue for new switch assert default goto * package synchronized ...
Java Keywords (Part XI): Throwing Exceptions
- Get link
- X
- Other Apps
We are up to 32 keywords covered in previous articles! That's 67% keywords covered. We have only 16 keywords to cover and I will be covering 2 of those in this article. This article will illustrate the use of the keywords throw and throws , in Java Exception Handling. It will not get into specific usages of Exception Handling. For that, please go to my article covering this topic. Also, be on the lookout for a new article covering other facets of Java Exception Handling, such as "try with resources." I suggest you start with Java Keywords (Part I) before proceeding further, if you have not read any of the previous articles in the Java Keyword series. 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. The series was written with natural progression in mind. Therefore, some of the keywords already co...
Java Keywords (Part X): Try, Catch, and Finally Blocks
- Get link
- X
- Other Apps
We are up to 29 keywords covered in previous articles! That's 60% keywords covered. We have only 19 keywords to cover and I will be covering 3 of those in this article. This article will illustrate the use of the keywords try , catch , and finally , in Java Exception Handling. It will not get into specific usages of Exception Handling. For that, please go to my article covering this topic. Also, be on the lookout for a new article covering other facets of Java Exception Handling, such as "try with resources." I suggest you start with Java Keywords (Part I) before proceeding further, if you have not read any of the previous articles in the Java Keyword series. 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. The series was written with natural progression in mind. Therefore, some of the keywords al...
Object Comparison: the equals and hashCode methods
- Get link
- X
- Other Apps
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
- Get link
- X
- Other Apps
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...