Menu

Java Explained: Object-Oriented Basics Without the Jargon
πŸ“°

Java Explained: Object-Oriented Basics Without the Jargon

DEV Community: javaΒ·The Practical DeveloperΒ·about 1 hour ago
#nyS88HPf
#devtojava#devto#dev#java#object
Reading 0:00
15s threshold

Introduction

Java has been around since 1995 and still runs an enormous share of the world's backend systems, Android apps, and enterprise software. Its staying power comes from one idea, taken seriously: everything in your program is an object β€” a thing with data and behaviour.

That sounds abstract. It becomes concrete with one example: a bank account.

Classes and objects

A class is the blueprint. An object is a thing built from that blueprint. You write the class once, then create as many objects from it as you need.

public class BankAccount { private double balance ;

public BankAccount ( double startingBalance ) { balance = startingBalance ; }

public void deposit ( double amount ) { balance += amount ; }

public double getBalance () { return balance ; } }

BankAccount mine = new BankAccount ( 100 ); mine . deposit ( 50 ); System . out . println ( mine . getBalance ()); // 150.0

Enter fullscreen mode

Exit fullscreen mode

BankAccount is the class; mine is an object.…

Continue reading β€” create a free account

Join HashtagPLUS to read full articles, follow hashtags, vote, and join the conversation.