Tuesday, January 27, 2015

Creating a Class in Java - Part 1

Lets take a look how we can use objects and classes to create a small program using Java.

Assuming the you have installed Eclipse IDE. Eclipse is IDE(Integrated Development Environment) that is used to create Java applications, it is an industry standard tool which is used globally by many software engineers.

Download Link : https://eclipse.org/downloads/packages/eclipse-ide-java-ee-developers/lunasr1a

Open Eclipse and then go to the File-->New-->Java Project-->Enter your project name and click on finish.

Then on the left side you can see the Package Explorer tab and inside that you will find your created project. Right click on the project folder that your created previously.

Click on class:




Next, give the class a name, I had given the Name as Person.



Then you will see your class appearing like this :



In the future tutorials lets look how to add attributes and methods for the Person class.

Introduction Object Oriented Concepts - Part 1

Nuts and Bolts:

 What is an object?

An object is an element that is used by people in a daily basis, for example, my table,  my chair, my mobile phone and many other in the real world can be considered as an object.Almost everything surrounding us is an object. 

So why does computer programming uses object? Object is the basic construct of object oriented programming which allows the people developing the software to so see the elements in the world as objects.

Example : Lets consider a Person, you can say John is an object of type Person.

 Next lets look the second most import concept of Object Orientation(OO).

What is a class?

A class is a template for creating objects, examples of class are, Person, Car & etc. Even a concept is also consider as a class, for example, in a banking environment cash deposit, cash withdrawal, credit transfer. 

Class will contain attributes(characteristics of the class) & methods(behaviors or actions of the class).

Lets look at the same Person - John example. In this example,
Class - Person
Object - John
Attributes - First name, Last Name, Age, Gender & etc.
Methods - eat, sleep, walk, jump, work. study & etc.