Primitive Vs Reference type
For primitive types; char, byte, short, int, long, float, double and boolean, ALWAYS use “==” (double equal) operator to compare for equality, this does not go against common sense, in fact, this is the probably the default thinking of many programmers — I hope by now you’ve gotten over the “=” as a way to [...]
Java interfaces
An interface is a like a class — well not really — it’s an interface, it contains 100% abstract methods. There is an explanation on abstract methods in this post . When you define interfaces, you are not reusing any behavior, you are enforcing behavior, you are guaranteeing that whoever inherits this interface, will provide [...]
Java array basics
An array is a data structure that allows you access and manage many variables using a uniform name. Imagine it like a pigeon hole, with rows and columns, you can identify a specific location in a pigeon by addressing it using row and column coordinates; Now imagine how that can be a useful thing if [...]
Java constructors
Constructors are special method — Let me take that back, they are not methods, they are constructors, they just look a bit like methods.
Abstract classes
A class with at least one abstract method, is an abstract class (should be defined as an abstract class) – by this definition, a Java class becomes concrete when the following 2 conditions are met. There are no abstract methods defined inside the class The abstract modifier is not preceding the class keyword on the [...]
Final classes
Final classes are classes that cannot be inherited. It might be confusing at first, specially knowing that one of the benefits of object oriented programming is the ability to re-use functionality via inheritance, so why would we want to prevent inheritance? Consider this scenario; You are a consultant, you have been asked to write a [...]
An instance of a class is called an object
This phrase is very common in Java literature, hence we need to have a better understanding of what it means. Remember when we defined a class on Java class fundamentals, we talked about its parts, and how we’re supposed to define it, now we’ll talk about it and we’re going to include object in the [...]
Java classes, a deeper look
If you haven’t read the Java class fundamentals, read that first, then come back here, you will need an high level understanding of Java classes first. I left out some details during the introduction on Java class fundamentals, for good reason, it makes the article a bit easier to understand, so why another article on [...]
Accessibility
4 keywords that affect accessibility are public, protected, package (the default) and private. You probably have seen many times over that package is the default, or default is also the same as package in Java, what it means is just, that you if don’t do anything, don’t put any access keyword in front of either a variable, [...]
Java packages
Java packages provides a directory like or folder like structure that allows you to organize your Java classes. It also enables you to implement stricter access control at a class level, state and method level. When you create a non-trivial application, the number of classes could easily be in the hundreds, you will eventually want [...]
How to make Java objects talk to each other
One Java object can talk to another Java object by sending and responding to messages. So what are messages in terms of Java codes? The methods that you define inside your classes constitutes the messages, hence if you don’t define any method inside your classes (what good are they then?), then there is no invoke-able [...]
Inheritance
Inheritance happens in Java in 2 ways. At the class level via the extends keyword, and the other is the at the interface level, via the implements keyword.
Java class fundamentals
Java classes makes creation of Java objects possible, classes and objects are inseparable. I’m not really sure how I can make the distinction clear between classes and objects, I’m sure that by now there is a good chance you heard about a class being a “cookie cutter” or a “blue print” for objects. So let [...]
Java objects, what are they really?
I almost shied away from this subject because it’s very complex, and I’m not sure I can add value to the already voluminous definitions of Java objects on the Internet, but I have other intentions why I’d like to take a shot at this, someday these small chunks of info I’ve posted here will become [...]