Thursday, April 11, 2013

Java basic by Ashish -

This is my first blog on java concept, I am just sharing an overview of the basic definition of java and there concept. More details and example of every concept will be shared in next post.

 Please read and share your comment/feedback, if anything is not correct please feel free to share it.

"Sharing knowledge is the best way of improvements"





Java is a platform independent language -
Here one questions comes in my mind what is platform in programming environment ?  Platform is nothing but an system where we can compile and run our program source code. i.e windows operating system , UNIX operating system and so on.

Java is platform independent because java source code compiled in windows system can be executed in UNIX based system, there is no need of compiling the code again in new environments  JVM.
So java is also called as "write once run anywhere".

Java is object oriented language -

Java programming  is built upon object orientation -


OBJECT is nothing but any real world thing which has the attributes, behavior and states, i.e. car,bike,bicycle

CLASS in java is the template of similar objects or you can say it represent the states and behavior of objects. like car is class of similar objects (maruti 800,i 10, i 20 etc are type of car object).

Java has below main OOP concept  -

 Inheritance

Inheriting the properties of parent class in child class is called Inheritance, in Java inheritance is primarily introduce for  Code Re usability.
I.e. Shape is parent class and it can contain the draw function which has the implementation of how any shape can be draw.

Now square,rectangle can extend the shape class and reuse the draw function code to implement their own drawing logic.

Here the child classes inheriting the properties of parent class Shape.

Encapsulation
Hiding the implementation details from the outer world is called encapsulation , in more details biding of data members and methods into a single unit is called encapsulation .

Encapsulation can be achieved by making instance variable as private and methods as a public.

encapsulation will ensure that no other class will able to change your implementation logic, they can just use the functionality as it is.

Abstraction - 
Abstraction in java can be achieved by interface and abstract class, don't go in details for interface and abstract class as of now i will cover these concept in my next blog with example.

Abstraction in terms of java programming refers to showing important aspect of program to other program.
 

For example - TV remote is use for controlling the channels it doesn't show how its internal functionality is working to change the channel.

TV remote making structure is called encapsulation (i. e. Binding of data and its method together) and its button panel is called abstraction (showing number on buttons and its functionality is abstract for user.).
 

Polymorphism -  
Polymorphism in java refers to many forms of single object for example an actor can be associate with different role like he can do role of father , he can do role of son and so on.

In Java polymorphism can be achieved by 2 ways -

Method overloading - Method overloading in which 2 method inside same class with same name should have different parameter, return type is not mandatory to be change. it can be achieved  in single class.

Method overriding - Method name and parameter should be same, implementation needs to be change in derived class. it can be achieved in 2 classes.

Practical example and source code of each and every concept will be shared in next post, be in touch .

Thanks.
 

No comments:

Post a Comment