A Sneak Peek Of Objects in Java

Home /

Table of Contents

In programming fundamentals, an object is a self-contained entity that encapsulates properties (also called state) and behaviors (also called methods or functions) that can be performed on that object. Objects are the building blocks of object-oriented programming and are used to model real-world entities, such as people, cars, buildings, and more. Each object has a unique identity, and its properties and behaviors are defined by its class, which serves as a blueprint or template for creating objects. The use of objects in programming allows for more modular and maintainable code, as well as better organization and abstraction of complex systems.

The Origin and History of Tea

Let us take a walk in the history lane. We are going to tell you the origin of tea.

Tea is frequently regarded as a uniquely British beverage. However, the history of tea dates back much further.

The origins of tea can be traced back to China. Legend has it that in 2737 BC, the Chinese emperor Shen Nung was sitting beneath a tree while his servant boiled drinking water when some of the tree's leaves blew into the water. Shen Nung, a well-known herbalist, decided to try the infusion that his servant had made by accident. The tree was a Camellia sinensis, and the drink it produced was known as tea. It is impossible to know whether or not this story is true. However, tea drinking was certainly established in China many centuries before it was even heard of in the west. Tea containers have been discovered in tombs dating from the Han dynasty (206 BC - 220 AD), but it was during the Tang dynasty (618-906 AD) that tea became firmly established as China's national drink.

For millennia, it was a medicinal beverage made by boiling fresh leaves in water, but around the 3rd century CE, it became a daily drink, and tea cultivation and processing began.

It became so popular that in the late eighth century, a writer named Lu Yu wrote the first tea book, the Ch’a Ching, or Tea Classic. Tea was introduced to Japan shortly after this by Japanese Buddhist monks who had traveled to China to study. Tea drinking has become an important part of Japanese culture, as evidenced by the evolution of the Tea Ceremony, which may have its origins in the rituals described in the Ch’a Ching.

In 350 CE, the first account of planting, processing, and drinking methods was published. The first seeds were brought to Japan around 800, and cultivation was well established by the 13th century. In 1810, Chinese from Amoy brought tea cultivation to Formosa (Taiwan). Tea cultivation in Java began with the Dutch in 1826, when they brought seeds from Japan and workers and implements from China.

How to Properly Make Tea

Now let us hear a story. Once upon a time, when the world was still green, there was a town called Teaville. The location, like its name, was endowed with one of the world’s finest tea plants. And, yes, there was a tea maker who made the best tea in the village. To make a cup of tea, all he needed was hot water and tea. However, there are a few extra steps he used to take to make a proper cup of tea. We are going to give you the recipe below.

The ingredients you need are:

  • Loose Tea: When you only need tea and water, you always prefer loose tea to tea sachets or tea bags.
  • Filtered Water: Better water makes better tea.
  • Teapot with infuser: Use a teapot with a large infuser. It makes it easier for the tea leaves to unfurl and steep.


Here’s a quick rundown of how to properly make tea.

  • Boil Water: Different teas require different temperatures to brew. The recommended water temperature is listed on the tea packaging.
  • Warm-up teapot: This is a minor detail that elevates your tea to a higher level, and almost no one does it. They should, however. Fill half the teapot with boiled water, give it a few swirls, and then discard the water. We’re warming the teapot so that when we add hot water for tea, the temperature doesn’t drop too much.
  • Put the tea into a teapot and add hot water.
  • Cover the teapot and steep tea: Set your phone’s timer to steep it for the appropriate amount of time. The steep time varies depending on the type of tea, so check the tea package to see what is recommended. It is usually no more than 5 minutes.
  • Strain tea solids and pour hot tea into tea cups.

While making tea you always remember the following:

  • Use Filtered water: You make sure that the water is filtered so that the water won’t add any other taste to your tea.
  • Set the correct water temperature: You know that the temperature of the water is a little tricky. Some teas require only boiled water, whereas others are more sensitive to hot water (especially green tea), so you always make sure the water temperature is correct. Most of your efforts are invested here. 
  • Steep for the correct amount of time: You always have it in the back of your mind that tea that has been overstepped produces a bitter cup. This is the time to use your smartphone’s timer. Follow the steeping time recommendations on the tea package, but in general, black tea should be steeped for 4-5 minutes, green and oolong for 3 minutes, and white tea should be steeped for 4 minutes. Herbal tea is the only tea that should be steeped for more than 5 minutes. You should carefully maintain this.
  • Use Loose Tea: Tea in tea bags is the leftover broken bits, or “tea dust,” collected after processing tea. That doesn’t sound particularly appealing, does it? A high-quality tea is made from rolled whole tea leaves. As the tea steeps, it will unfurl in the water, allowing you to see the entire leaf.
  • Warm the teapot. This is an important step in ensuring that the tea brews properly in hot water.
chVvw8E5AXBGLU7IGMpYXKZUGnNyqk2qYAwBb5a6YaDGvOJyAyFDBevC57X HOfxaivZAxI2n8768ej Bg3o57e - A Sneak Peek Of Objects in Java

He did all of this so that when people came to his shop, he could serve them tea with enough milk and sugar. Those who requested a black would be served a mixture of tea and water. He was a successful brewer who lived a long and prosperous life.

We suppose you have all of the ingredients listed above. Keeping this in mind let us make a cup or two of fine tea.

And now, if you could replace the story’s main character with a modern-day Tea Vending Machine, how would a programmer think of making it work? Please continue reading…

Allow me to be a humble programmer. Please? Please? Ok! Thank you!

Objects and Classes in OOP

The tea vending machine is the object for me. What I want is for it to make tea to my liking. So, when I program, I would create a class called TeaVendor, because when I turn on the machine, it should perform all of the functionalities of the teamaker from the story. We will tell you later how to make a class and why we need to make a class.

We need a “function” to get the tea leaves out of the tray. Oh no! A function was called to see if the tray was empty, and it simply returned Yes. Beep beep beep and display the message “You there, I’m out of tea.” “Get me some right now!”

We need a function to check the measure of the water or a water level indicator. It’s critical to check the water level indicator to determine how much water you’ll need to boil, and the amount of water that should be indicated at least 4 or 4.5, so the tea won’t be too full for the teacup.

Now you need to define some parts’ properties on something called attributes. It provides value to the functions and allows them to be updated on the fly. There are some that must be consistent throughout.

All of these small details are enclosed in a wrapper known as a class, which represents the object as a whole known as the tea vending machine.

In object-oriented programming, an object is something that has some properties and performs some tasks that have been assigned to it.

Now let us use this concept to further understand objects in programming.

Suppose we have a cat. The cat’s name is “TheCat”. We know it is a silly name for a cat. But it serves our purpose.

image 3 - A Sneak Peek Of Objects in Java
A cute ragdoll cat.

TheCat is of the breed “Ragdoll”. TheCat is of “ideal” size.

These are the states or properties of the “TheCat”. What about the functions of TheCat? What may it do? It may “meow meow”. 

LA6ER57qnlWFiPz Q 6MdCKGJUNLKoPCgkOPnocICWlcselR2gQ027VieXQGfNjODNM2I0S0ijdgq4HBS9dwJ2vpZnxdcsaKubvwWOH9y8IRRcFUfdfJvB24AJ982JTK5c8XvK8sJ Lze1 Nlul Vo - A Sneak Peek Of Objects in Java

The attributes or properties of an object are called instance variables in Java. It is the values that an object knows about itself. Things an object can do are called methods in java. In the CAT object name, breed, and size are the instance variables of CAT, and the sound() is the method(that a CAT can do). Think of an instance as another way of saying an object.

Some more examples of objects(instances) may be:

- A Sneak Peek Of Objects in Java
TSvkB3aqN NTiwEESpfIF5Ynwpwd2NuVgHWVMY8nvJXwsjCeG3oE wMNtGZkoxYgcpyJjl2 2JPFgbe8RDSDQPd3 0o0whXB5UzETuGhDtSSwvIGekXJWfPoJQ2ubfPFwZ01sJ8ggGdSZyLjhnafFU - A Sneak Peek Of Objects in Java

In the next tutorial, we will tell you how to make an object in Java. How to use an object. Then it will make much more sense to you.

Methods are the actions that an object can take. When you design a class, you consider the data that an object will need to know about itself, as well as the methods that will operate on that data. Methods that read or write the values of instance variables are common in objects. Alarm objects, for example, have an instance variable that holds the alarmTime and two methods for getting and setting the alarmTime.

MP 0tYHEK4dRqnaX8fXtHQBgWCEKrNYnG9UX8v3HNT5IQpdvK 1XjEVdSJ1GQrs - A Sneak Peek Of Objects in Java
Share The Tutorial With Your Friends
Twiter
Facebook
LinkedIn
Email
WhatsApp
Skype
Reddit

Check Our Ebook for This Online Course

Advanced topics are covered in this ebook with many practical examples.

Other Recommended Article