Java, Java Tutorial, Software Development

Chapter 5: Java Classes – The Blueprints And Building Blocks

java Sort Enum Properties Monitor Directory File Lambda Expression parameter return types Validate XML String XSD ExecutorService AutoCloseable Try-With-Resources Convert LocalDateTime OffsetDateTime Run Codes Before Shutdown XML Tag Lambda PostgreSQL JDBC invoke JavaScript Applet SFTP Batch hang block main thread MySQL JDBC try-with-resources delete Unencrypted SoapFault Apache CXF Remove XML Element XSLT skip execute finally public static void main constructor fields Eclipse convert Iterator Stream StreamSupport XMLEncoder XMLDecoder rename P6Spy JDBC Example PDF Version JasperReports Run from Ant iReport Page Numbers Count entities persistence context hibernate

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.


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

Got comments, or suggestions? Please visit our Facebook page!

You Might Also Like