Java Interfaces

A Java Interface, as first glance, may look similar to a class. However, there are important differences, not only in how it is used, but in defining it from a class that make it worth noting. Uses of an Interface Java prevents a developer from extending a Class with two or more classes. This is…

Inheritance in Java

As you’ve seen in the UML class relationships, there is the ability to define a class, and a subclass. The subclass will get all of the properties and methods of the parent class, and can then add additional properties and methods that are not available in the parent. Consider two classes, a Shape2D and a…

Java Constructors

Each object has a special method called a constructor. The constructor can be overloaded as necessary. Typically, you will have a default constructor (sometimes called a no-arg constructor), where no parameters is passed to the constructor. This special method is used to constructor an object when it is created. It is very similar to a…

Overloading Java Methods

As was mentioned briefly in talking about Java Instance Methods, you can overload a Java method, just as you would overload a C++ function/method. (C doesn’t allow for overloading, only C++). Since there is no method prototype, it is easy to just write your new method. I like to group my overload methods together, so…

Class Methods in Java

In object oriented programming, you consider the object which you are programming about, for example, a car. You then consider the attributes about the object, for example, the make, model, color, year built, etc. You also have consider the operations of the object. i.e. What can it do? A car for example could turn on…

Static Methods in Java

Static methods in Java work on the same basic idea of static functions in other languages like C/C++. The idea is that sometimes you have a function that either needs to be shared between instances, instead of tied to a specific instance, or to be used without needing to create an object from the class…