Lesson 2: Understanding our HelloWorld program – Classes and Object-Oriented Programming

After writing our first Java program in Lesson 1, it is important to go over our code and make sure that we are familiar with what we have written. If you don’t understand everything by the end of this lesson, that is alright. Some of what we go over will make more sense with time.

First lets talk about classes. In this case, our class name was “HelloWorld.” When creating classes in Java, it is necessary to enclose everything within curly brackets { }.

In order to understand the concept of classes, its important to take a step back and look at the bigger picture in Java.

Java is an Object-Oriented Programming language. Object-Oriented Programming is used to organize software by creating objects and assigning methods and variables to them.

One good example would be having a fish as a class.  Then, under our fish class, we can have different types of fish with different characteristics/traits.  Because we already have the fish class, we can use that as a base for our specific fish, instead of starting from scratch for every fish.

By having a fish class, we can have all three unique fish inherit traits from the broad fish class.

There are four important ideas that make up the fundamentals of OOP. 

Encapsulation: This refers to keeping information in an object and not letting other objects access or change it.

Polymorphism: Broadly speaking, it means the capability of an object to take many forms.  (The best way to remember this is to look at the Greek roots of the word.  Poly means “many” and morphism means “forms.”

Abstraction:  Only presenting the necessary methods or information in our code.  This is mainly done to make our code less difficult to read.

Inheritance:  Inheriting/reusing code from other objects in order to keep our program from having redundant code.

Now that we have gone over the fundamentals of OOP, what should we takeaway from this?

Our objects (in OOP) are identified by classes.  Once again, do not be worried if you don’t understand everything I just went over.  Just keep in mind that Java is an OOP and be familiar with the 4 principle definitions of an OOP listed above.

Now that we have a basic idea of classes and OOP, we will go over methods in Lesson 3. 

GitHub link.

Leave a Reply

%d bloggers like this: