Java, Java Tutorial, Software Development

Chapter 5: Java Classes – The Blueprints And Building Blocks

In How To Write Your First Java Program, we installed an IDE and wrote a basic Java program. We also learned about the essential components of that program’s Java source codes – the keyword class and the main method. Here on after, we’ll use the word “application” to refer to the word “program.”

Java Classes

What are Java classes? Java classes are blueprints and building blocks akin to atoms. These are codes we write using the class keyword. As blueprints, they represent the design of the whole application. Like building blocks, we can build them into bigger chunks and, finally, the application itself. These two metaphors are meaningful because Java generally deals with classes. In other words, everything in Java is a class (except for a few minor things we’ll talk about in later posts).

Java Objects

Java objects are live instances of Java classes. When we create something based on a blueprint, we create a living entity of that blueprint. In Java speak, we call that entity an object. If we had a design for a car, that is its blueprint. On the other hand, when we built an actual vehicle based on that design, that car is an object.

If we only had a class for our application, how do we create an object from that class? If we’re starting up from that same class, we can’t. Only the JVM does that.

IMPORTANT

When we talk about creating something from a blueprint, we are expressing that intent in the codes. The actual object creation happens when the application is running inside the JVM. Therefore, Java objects are live instances within a running application.

We have these classes – ToyotaCarApplication (startup class) and ToyotaFortunerBlueprint (blueprint class).

Lines 8, 11, 14, and 17 express the intent of creating four unique live instances of Toyota Fortuner based on the blueprint class ToyotaFortunerBlueprint. When the JVM executes these lines, it will create actual live objects whose lives end when the application completes its execution and terminates.

 

What’s Next?

That was an easy ride! Next, we’ll look at Java objects and their properties and behaviors.

Chapter 6: Java Object And Its Properties And Behaviors

Loading

Got comments or suggestions? We disabled the comments on this site to fight off spammers, but you can still contact us via our Facebook page!.


You Might Also Like