Posts

Java Keywords (Part V): Classes vs Interfaces

This is not a break in my Java Keyword series. This is a continuation of the series that focuses in two things. The primary goal is to explain what an interface is (which differentiates them from classes) and go over a few examples that illustrate why interfaces are not just needed, but essential for robust and reusable software solutions. Because of new improvements introduced with Java 8, I will also introduced the concept of default methods; although will do so in a separate article... A second part to this one. I feel doing that is necessary for keeping the scope of this article as narrow as possible for the sake of simplicity and clarity. Interestingly enough, how to use interfaces will also be covered in a separate article where I will be discussing the Object-Oriented concept of inheritance. In the new article, I will be emphasizing in the keywords extends , implements , and super . The Java keyword list has 18 keywords grayed out. This article will only cover th...

Java Keywords (Part IV): Classes and Objects

This is not a break in my Java Keyword series. This is a continuation of the series that focuses in two things. The first part will focus on the anatomy of a class, which I have covered (somewhat) already. The second part focuses in the concept of a class constructor. Lastly, and as a related topic to that second part is how to invoke class constructors and explains what happens when this occurs (which I have somewhat covered already). View this article as a way to tie loose ends before moving on to other topics. In the end, I will wrap up the keywords class and the new operator. 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 ...

Java Keywords (Part III): Returning Values from Methods

I have covered 7 keywords so far in the "Java Keyword" series, plus the eight primitive data types in my "Data Types" blog. In this article, I will discuss the keywords return and void . But, in order to understand their usage, I must get into a bit deeper discussion of some fundamentals of computing. 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 Keyword marked with an asterisk (*) are keywords that, although valid, are not used by programmers. Although the list above is arranged in alphabetical order, I will go through them in a different order. Method return val...

Java Keywords (Part II): Modifiers

Image
I will continue to show the keyword list on subsequent articles. However, I will gray out the keywords previously discussed. Since the eight primitive data types were also previously discussed, I will gray out those as well. Keywords that were mentioned but not discussed, like package will remain listed until properly explained and illustrated. 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 Keyword marked with an asterisk (*) are keywords that, although valid, are not used by programmers. Although the list above is arranged in alphabetical order, I will go through them in a different or...

Java Keywords (Part I): Creating Classes

Image
I think it is important for every beginner-level developer to fully understand the proper usage of keywords of any language. I will write a multi-part series outlining all Java keywords (as of Java 8), providing an explanation regarding it usage (or multiple usages), and illustrate this with simple examples. So, without further ado, lets examine this topic. The Java language contains 50 keywords of which only 48 are used. The following is a list of all the keywords in the Java programming language. 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 Keyword marked with an asterisk (*) are key...

Data Types

Image
The meaning of data type in programming To properly define what is a data type in computer science, we must understand first what "type" means. After perusing the web for a definition, I found this: -A category of people or things having common characteristics . In computer science, in this case specifically for programming in Java, a data type is simply a categorization of things (objects) that have common characteristics. For illustration purposes, let us consider something we are all familiarized with: money. Since I am American, I am more familiarized with American currency . Therefore, I will use that for my first example. American currency comes in bills or banknotes (generally referred as paper currency) and in metallic form called coins. Using the definition of data types, the generic data type known as "American Currency" can be further classified as "Paper Currency" and "Coin". Why do this? Because, although all...

Java Packages

I was watching a video today where this topic was brought up and I was kind of surprised at how some people categorize the importance of packages in Java. I will go over two main reasons why packages are important. Before I got into details, let start by enumerating the two reasons I am discussing in this blog. The first, and most common reason, is for organization purposes. I am sure you have heard this many times. The second reason, and the one I believe is badly overlooked, is protection to restrict access to your classes and features. Use packages to organize your classes and features The first point you should know about packages is that packages are basically the folders where your classes reside. This concept should not be foreign to anyone. If you have used a computer at least once in your life, you should already be aware why folders are helpful in keeping your files organized. If you are like me, you love to create folders to keep your files organized and to quickly...

The REAL Builder Pattern

Image
I have been reading about Design Pattern lately, and I ran across some articles about the Builder Pattern that are not accurate at all. Because of that, I decided to write a short article about what this pattern is and how to properly implement it. I will start by providing a short description of what this pattern is. I will follow that with some context by providing hypothetical usages for this pattern, and conclude with a (hopefully good) code example. What is the Builder Pattern? Even these bad articles got one thing right: The Builder Pattern is a Creational Pattern . This means that the pattern's main goal is to provide a reusable solution for creating objects. You may ask, why are there more than one creational pattern? Isn't invoking a class constructor enough? Well... yes and no. Why use Builder Pattern? Experts (people who know more than me) have determined that using one of these creational patterns is preferred over invoking the constructor of a c...