What is Object In Java – OOPS Concept

Last modified date

For beginners this might be little confusing question what actually is Object in Java. if we did not understand the concept of Object in Java, we are going to stuck in a situation in fixing the bugs. When i was a beginner i searched in many of websites to understand the concept of Object in Java, but no where i found the exact answer. But one final day i figured it, and Java was very easy to understand write code.

In many websites i have seen that people takes off topic example to explain Object Oriented Programming, which create lot of confusion comparing it with our real time application development or learning. But i will be straight with you explaining real time examples which make you more easy to understand the concept of Object Oriented Programming.

What is Object ?

In simple words Object maybe a ready made Class or creating custom Class, and we use those class where ever we require in our project to reduce the code writing.

What is Ready Made Class?

Just image we are writing a Class to print date, most commonly to print date we import Util package. We will look at an example here how to print Date with ready made class.

package intactabode;
import java.util.Date;
public class PrintDate {
  public static void main(String[] args) {	
    Date d=new Date();
    System.out.println(d);	
  }
}
// Output : Wed Apr 04 14:23:18 IST 2018

if we observe in the PrintDate Class in main method i just printed the date by simple importing import java.util.Date; I Just created the Object of the Date by calling Date d=new Date(); printed the reference variable d. Now coming to the conclusion, where Date is a ready made Class we can use it any where we required by just importing java.util.Date and print the reference variable to get the output. The same way in any project you may have requirement of other Objects. The Java professional have created several number of Jars where we just need to add those Jars to our projects and use them by importing the packages and creating required class Objects.

To make it little bit more clear about Objects, lets assume we have created a form entry using Swings/Windows Builder/SWT. To design a form entry we require the Objects like JFrame, JDilalog, JLabel, JTextField, JPasswordField, JButton, JScrollPane  and etc, all the components are internally Objects with ready made Classes which are present in SWT package. We use those object as per our requirements and get their properties.

What is custom Class ?

In the above example i have discussed how to print the date by importing the util package into our class and getting its property with less writing of code. But there may be a case we want some different requirements depending on your client requirements or our own project, and we don’t have any ready made classes to get their properties.In such cases we write our own Classes and use them whenever we have requirements of your custom Class.

 

intactabode