Affiliate links on Android Authority may earn us a commission.Learn more.

What is Object Oriented Programming?

July 10, 2025

Java is the primary language used to create Android apps. Java, you may have heard, is an ‘object oriented’ programming language. But what precisely does that mean?

Before Object Oriented Programming

One of the easiest ways to understand what is meant by ‘object oriented’, is to define what it isnot. Before Object Oriented Programming (OOP) programs were written an imperative way, essentially a long list of commands (instructions). In imperative programming, you write your code the way you would write an essay: from top to bottom.

In fact, my first programming language was BASIC on the ZX Spectrum which wasvery muchimperative. So much so, that all the lines were numbered as ’10, 20, 30’ etc. If I wanted the program to repeat something it had already done earlier, then I could use the command ‘GOTO 320’ to get it to jump back to a certain point and then continue to progress as before.

Article image

The problem with this kind of programming is that it can get incredibly complicated and difficult to navigate as the code gets larger. If you’ve built a program that’s millions of lines long (which is common) and you have commands that jump between seemingly random points in that code, it becomes almost impossible to follow, or to find errors when things start going wrong. This is what some people now refer to as ‘spaghetti code’.

To fight the spaghetti, new programming languages were invented which tried to make the code more modular, more structured. These new procedural languages promoted GOTO free code, with nested control structures along with procedure calls. A procedure (or function) is a discreet unit of logic which performs a task give a certain input. After procedural and structured programming came object oriented programming.

Article image

The Idea Behind Object Oriented Programming

It’s perhaps best to think of OOP as a design philosophy. With procedural languages there was no connection, no relationship between the data being used and the procedures which used them. One procedure could alter a data structure and then a seemingly unrelated procedure could also alter it. With OOP the procedures (which are now called methods) and the data are intrinsically tied together.

A great side effect of object oriented programming is also just how easy it makes it for us to share code withother peopleand to build more elaborate programs without having to handle every last line ourselves. OOP is ideal for collaboration and facilitates an open source attitude.

Article image

There’s a certain elegance to object oriented programming and while it’s a lot more complicated to grasp, it pays off once youdoget to grips with it.

What is an Object?

The way the data and the methods work on the data is by being tied together in an object. An object contains data and behaviors. To define an object, to define the data and to define its methods, you use a class. Let’s imagine you want to create a class to represent a bank account. The class, let’s call it BankAccount, would have some data likeaccount holder name,account number andbalance. The methods would be things like getAccountHolderName() or deductFromAccount(). By default only the methods that belong to the BankAccount class have the right to work on the data associated with the class. By limiting access to the data then, a class can be sure that no other part of the program has manipulated its data. It also means that an object can hide its internal data structures from other objects.

When designed properly, a class (and probably a set of other dependent classes – classeswithinclasses that inherit the same properties and data) can be re-coded and improved without affecting the other parts of the program that use it. As long as the public facing interface remains the same (the API), and as a long as the functionality remains consistent.

Article image

That is how the Android SDK works (in part). Google releases new versions of the SDK frequently, however our Android programs still build and work as before because Google doesn’t change the behavior, however it might re-work the internals of the classes.

An Example

To demonstrate how all this works, let’s see how we might actually write the code for our bank managing example. I’m going to share the code twice: once without comments so you can look it over and try to work it out without me getting in the way, and oncewithcomments explaining what each line does.

Okay, now here it is with the comments added. A comment is anything with ‘//’ preceding it, which means it is not part of the code. You’ll often see these marking up programs to make them easier to navigate!

Article image

Don’t worry if you don’t follow all of that right away, it can take a little time to get your head around. For those that are looking at this purely theoretically, hopefully this has helped illustrate how you might actually use objects and classes in practice. For those actually starting to play with Java, maybe it will help phrases like ‘this’ seem a little obtuse and provide some context for why things are structured the way they are!

Moving Forward

This rabbit hole goes pretty deep, but if you’re struggling with all that, then the analogy that many people will use is that a class acts like a blueprint to build the object, just as a real blueprint builds a house. An object meanwhile is a collection of behaviors (commands) and data which are useful for the code to function.

There are more advantages to OOP. For example, one object can be derived from another. Going back to the BankAccount example, if the bank also offered savings accounts then a saving account is a type of BankAccount but with some extra data, sayinterestRate. That might also be a new method, like calculateInterestEarned(). But it still needs access to the other methods and data likebalanceor deductFromAccount().

When a class is derived from another class it is known as inheritance. Technically a more generic base class is called a ‘superclass’ and the derived class is called a subclass.

If you did want to get a better understanding of what it means to code in an object oriented programming language though, then I would actually recommend having a little play with Python. Python is a particularly simplistic and straight forward programming language that just happens to use objects and classes. And I use the term ‘simplistic’ in the best possible way – it’s very elegant and makes the whole concept a lot easier to grasp whereas Java can be pretty daunting for a newcomer.

As ever though, focus on learning what youneedto know to complete the jobs you are working on. Don’t get bogged down with unnecessary theory until you need it!

Thank you for being part of our community. Read ourComment Policybefore posting.