Tuesday, 8 October 2019

Introduction to classes

Introduction to classes

java,class in java,java tutorial,classes in java,java class,class,java (programming language),object class in java,class and object in java,classes and objects in java,learn java,java classes,java programming,pojo class in java,class class in java,what is class in java,class member in java,java (software),abstract class in java,class creation in java,defining a class in java

What is a class

Object and Class are the two basic principles of Object Oriented Programming

They can be considered as the two sides of a coin, which cannot be disintegrated.

Each object belonging to a class, contains entire set of data and functions included in the class.

Understand concept of classes-

A class is a user defined blueprint or prototype from which objects are created.

  It represents the set of properties or methods that are common to all objects of one type.

 In general, class declarations can include these components, in order:

Modifiers : A class can be public or has default access.

Class name: The name should begin with a initial character.

Superclass(if any): The name of the class’s parent (superclass), if any, preceded by the keyword extends. A class can only extend (subclass) one parent.

Interfaces(if any): A comma-separated list of interfaces implemented by the class, if any, preceded by the keyword implements. A class can implement more than one interface.

Body: The class body surrounded by braces, { }.

Object


Introduction to object 

java,object,java tutorial,object in java,object class in java,what is object in java,class and object in java,class in java,java objects,java (programming language),java classes,java tutorials,classes in java,object oriented programming java,


What are object-
Objects are a unique entity which contain data and function group together.

In Object oriented programming problem is break down to small components called object's.

Understanding objects-
To understand objects in object oriented programming(OOP) let's consider a object from real world.

The object from real world consist following characters-
• It is visible .
• It can be defined and describe.
• It can be brought into action.

Example let's consider camera as a real world object. It has -
• Camera is visible
• Camera are used to click photographs
• We can click photos by clicking a button on camera.
Every object contains a characteristic and behavior let take example of potato

It's characteristic-
• It is brown in colour
• It is oval in shape
It's behavior-
• It is used to make vegetables
• It is also used in making many products like chips.

The objects, which we have discussed above are real world objects

 In fact, a program does not deal with real world object. The program uses software objects.

 Let us relate a real world object with the software object.

• The state or characteristic of real world object are data members in software object.
• In the same way behavior in real world object are considered as the function or method in software object.

You can understand by given below image
java,object,java tutorial,object in java,object class in java,what is object in java,class and object in java,class in java,java objects,java (programming language),java classes,java tutorials,classes in java,object oriented programming java,
Let's consider a class has object car. So by above picture you can understand the characteristics of object(car) are fuel and maxspeed, and its behavior are drive(),refule(),getfule(),setspeed(),etc.

Creation of object in a program-

1) Using new Keyword : Using new keyword is the most basic way to create an object.

 This is the most common way to create an object in java. Almost 99% of objects are created in this way.

 By using this method we can call any constructor we want to call (no argument or parameterized constructors).


2) Using New Instance: 

If we know the name of the class & if it has a public default constructor we can create an object –Class.forName

We can use it to create the Object of a Class. Class.forName actually loads the Class in Java but doesn’t create any Object. 

To Create an Object of the Class you have to use the new Instance Method of the Class.


3) Using clone() method: 
Whenever clone() is called on any object, the JVM actually creates a new object and copies all content of the previous object into it.
 Creating an object using the clone method does not invoke any constructor.
To use clone() method on an object we need to implement Cloneable and define the clone() method in it.

Wednesday, 2 October 2019

Introduction to object oriented programming with java.

object oriented programming,what is object oriented programming,object oriented programming java,object-oriented programming,programming,object oriented,object,object-oriented programming

Procedure oriented approach-
                           The procedure oriented approach allows the user to develop their logic by applying a number of functions that would enable program productivity.

In procedure oriented programming system, many instruction are written to carry out any task.

Theses information is group together to form function. We focus more on function rather than data.

You can clearly understand the concept by below flow diagram.

object oriented programming,what is object oriented programming,object oriented programming java,object-oriented programming,programming,object oriented,object,object-oriented programming

In this system the global data is loosely attached to the function.

They keep floating throughout the program. In order to manke any change in the function you may need to reschedule the associat data value.

 This may affect the normal sequence of the programming logic-

Characteristics of procedure oriented programming.

• Emphasis is more on function rather than data.
• Function share global data.
• Data value can keep floating from one function to another.
• It uses top down approach of programming.

Why there is need for object oriented programming-

1) As data value are globally to all function on procedure oriented programming, so if you want in make change in any data value you may need to make necessary changes in all the function.

2) It is not suitable to solve complex problem in real situation.


Introduction to object oriented programming-

Object oriented approach is to standardize the program by creating partitioned memory data for both data and function.

It has been developed to improve program productivity and also to overcome the traditional approach of programming.

In contrast to these, object oriented programming does not allow data to flow freely from function to function and procedure to procedur.

 In this system, the complete problem is decomposed into a number of entities called object.

 These objects are created and maintained along with a set of related data.

The data are created in such a way that they cannot be chaned or edite from other functios or objects.

The data of an object can be accessed through functions associated with that object.

However, function of an object. can access the function of the other object. You can understand more from give below diagram.

object oriented programming,what is object oriented programming,object oriented programming java,object-oriented programming,programming,object oriented,object,object-oriented programming

Features of object oriented programming-

• It gives stress to data items rather than function.
• It makes complete problem/program easier by dividing it to number of objects.
• The object can be used as bridge to have data flow from function to function.
• You can easily modify the data without changing function.

Basic elements of object oriented programming-

Classes
Object
• Data abstraction
• Polymorphism
• Inheritance
• Dynamic binding
• Encapsulation
• Data hiding