Introduction to Object and Classes

Home / Introduction to Object and Classes

  • Introduction to Object and Classes

    Computers which was invented as a machine is now doing more than what a machine can do and is now become a mind amplification tool. The major part for this movement of a machine as an expressive medium is Object-oriented programming (OOP). Thus here we give you the big picture of Object-oriented programming first and then let you understand the concepts of Java.

    Objects and the progress of abstraction

    Any programming language that you point is providing abstraction.  The kind and quality of an abstraction is directly related to complexity of the problem you’re trying to solve. Kind here means “What is it that you are abstracting?”, thus a simple example is Assembly language is an abstraction of the machine. While we try to solve a problem, then we as a programmer should try to establish an association between the machine model or solution space where you try to implement the solution and the problem that you are actually trying to solve or can be said as the problem space where the problem exist like a business. 

    In an object-oriented approach, there is a tool provided to represent the elements in the problem space. The elements that are represented in the problem space is converted to the “objects” in the solution space.  As real world object, we have characteristics and behaviors for the objects we describe in the program. The characteristics and behaviors of the objects in the solution in turn means the operations it performs and the state it has. Thus with the creation of object, the OOP allows you to explain the problem in terms of a problem rather than as a solution that will run in the computer. We can describe the object as “an object has state, behavior, and identity.
    As mentioned above, the object will have internal data, methods, and each object can be different from every other object and thus to put into more meaning each object that we create will have a unique address in the memory. 

    What is a class?

    Aristotle was the first to tell “the class of fishes and the class of birds”. By this we say, each object is unique but is part of a class of objects which has the characteristics and behaviors in common. Thus Objects which are identical except their state during execution of a program are bunched together as a class and thus we use the keyword class to define a class. Class is an abstract data type and this is the very fundamental concept of OOP. Abstract data type is just similar to that of the built-in data types like you can create variables of abstract data type and perform operations on those variables.
    For example, every account will have a balance where the customer can deposit money, withdraw money, check the account balance. But each account will have different balances and each account will be associated with different customers. Here account is a class and the individual user holding an account is an object.  A class is really like a data type, for example, integer data type also has a set of characteristics and behaviors like + to add two integers, - to subtract two integers. The only difference between a user-defined class and the in-built data type is user-defined class will be designed to fit into a problem whereas the in-built data type is to represent a unit of storage. 

    Once we create a class, anyone can make as many objects as they want from the class and manipulate those objects. We have created an object now but how to get those objects to do some useful work. There should be a way to draw something on the screen using an object or turn on a switch. Thus an object can satisfy certain requests. The request that we can make with those objects are defined in the interface and the type of the object you create will define the interfaces. For example, let’s take the account example we saw before.

    Account - Type name

    -- Interface --

    Withdraw(int money)

    Deposit(int money)

    BalanceCheck()

     

    Account acc1 = new Account();
    Acc1.BalanceCheck();
    An interface thus determines the request that you make through an object. The code to satisfy these request will be there with the hidden data and this is called as implementation.

    In the above example, the name of the class is account. We have created an account object called acc1. With this object acc1, we can withdraw money, deposit money, and check for the balance. Thus to make a request like to check the balance, we connect the method BalanceCheck with the object through a dot or period. 

    Learn Java from College to Corporate, the best IT training institute in Chennai, aiming to provide the best Java training in Chennai. We have the best tutors from the industry and we aim in giving you the best industry level training in Java.

    Comments

    Leave a Reply