Photo by Jacek Dylag on Unsplash

Exceptions in Java are events that occur when there is disruption to the normal flow of the program and the null pointer exception is one of these events. The NullPointerException occurs when a reference variable should point to an object but instead it points to null. Before we get into the details thought, it is important to understand reference types and how they work in Java.

Consider the following two lines:


Photo by Jonas Jacobsson on Unsplash

Polymorphism refers to an objects ability to take on different forms. In Java, it is a simple, yet fundamental concept of objected oriented programming. In order to understand polymorphism, it is important to have a solid grasp of inheritance and interfaces in Java.

A class is considered to be polymorphic if it passes more than one “is-a” test. An “is-a” test is a simple way of identifying the type a class belongs to; if the class belongs to more than one type then it is considered to be polymorphic. Consider this example:


Photo by Jonathon Young on Unsplash

Access modifiers in Java are keywords that are used to specify the accessibility of fields, methods, constructors and classes. There are four access modifiers, each specifying a certain level of accessibility:

  1. public: can be accessed from anywhere

2. protected: can be accessed from within the class itself, the package and by subclasses

3. package-private (default): can be accessed within the class itself and the package only

4. private: can be accessed only within the class

Giving a field a public access modifier allows it to be accessed from anywhere. However, it is important to keep in mind that labelling fields…


Read this to ace every interview question regarding interfaces.

Photo by Killian Cartignies on Unsplash

What are interfaces?

An interface is a reference type similar to a class but different in a sense that it can only contain abstract methods, default methods, static methods, (only default and static methods in interfaces can have a method body) nested types and constants. Interfaces cannot be instantiated; hence they do not have constructors. Instead, interfaces are implemented by classes (or extended by other interfaces).

What is a reference type?

Reference data types in Java are those which contain references to the address of dynamically created objects. …


Photo by Robert Katzki on Unsplash

Packages in Java correspond with the directory structure in your project. They are used to group and control accessibility of related classes, interfaces and sub-packages.

The advantages of using packages are:

  • Better access control: Packages equip the developer with better access control.
  • Avoid name conflicts: Using packages prevents you from running into naming conflicts; for example, if you have a com.admin.User and a com.standard.User classes, you won’t run into a name conflict even though these two classes share the same name.
  • Better organization: If you’re working on a very large project, having an organized project structure is a must and…

Photo by Tracy Adams on Unsplash

In Java, a class can be derived from an existing class and when that happens, the derived class inherits the fields and the methods from that existing class. In Java, and many other languages, this is called inheritance. The class that is derived from an existing class is often referred to as the subclass or child class. The class that is being derived from is called the super class or the parent class.

Consider a simple inheritance digram below.


Photo by Nate Grant on Unsplash

Before we begin discussing the toString method, it is important to have a basic understanding of the class hierarchy in Java. All classes in Java inherit from the Object class; the Object class is at the root of the class hierarchy in Java.


Photo by Blake Connally on Unsplash

In Java, as is the case with most programming languages, strings are immutable; once a string is initialized with a value, it cannot be changed.

What is it and when should I use it?

Take a look at the following code for instance:


Photo by Joshua Woroniecki on Unsplash

Static and final keywords in Java are at the core of the language and it is important to have an in-depth understanding of their function.

static variables

If you’ve every written a Java program of any scale, you’ve come across the “static” keyword. Your first program probably looked something like this:


Photo by antonio molinari on Unsplash

In this short article, I am going to introduce and implement the binary tree data structure. I will also answer questions such as “What is a full binary tree and what is a complete binary tree?”and “How do I traverse a binary tree?”.

First, let’s cover the basic definition of a tree. In computer science, data structures such a arrays, stacks, queues and linked lists are all linear data structures; they differ from trees, which have a hierarchical structure. A tree data structure is composed of nodes; each tree has a root node which has zero or more child nodes…

Anton Suprun

Computer Science Student, Programming Enthusiast

Get the Medium app

A button that says 'Download on the App Store', and if clicked it will lead you to the iOS App store
A button that says 'Get it on, Google Play', and if clicked it will lead you to the Google Play store