Java(part 1)

Java is a simple and yet powerful object oriented programming language and it is in many respects similar to C++. Java originated at Sun Microsystems, Inc. in 1991. It was conceived by James Gosling, Patrick Naughton, Chris Warth, Ed Frank, and Mike Sheridan at Sun Microsystems, Inc. It was developed to provide a platform-independent programming language.

This site gives you an Introduction to Java Programming accompanied with some  java examples. Its a complete course in java programming for beginners to advanced java.

OBJECT ORIENTED PROGRAMMING

Object Oriented Programming is a method of implementation in which programs are organized as cooperative collection of objects, each of which represents an instance of a class, and whose classes are all members of a hierarchy of classes united via inheritance relationships.

OOP Concepts

Four principles of Object Oriented Programming are:Abstraction
Encapsulation
Inheritance
Polymorphism

Since Java is an object oriented programming language it has following features:

Reusability of Code – Emphasis on data rather than procedure – Data is hidden and cannot be accessed by external functions – Objects can communicate with each other through functions – New data and functions can be easily added – Simple – Reusability of Code – Portable (Platform Independent) – Distributed -Robust – Secure – High Performance – Dynamic – Threaded – Interpreted

Unlike many other programming languages including C and C++ when Java is compiled, it is not compiled into platform specific machine, rather into platform independent byte code. This byte code is distributed over the web and interpreted by virtual Machine (JVM) on whichever platform it is being run.

Object Oriented Programming is a programming method that combines:
a) Data
b) Instructions for processing that data
into a self-sufficient ‘object’ that can be used within a program or in other programs.

Language Concepts

Object:  is a bundle of related variables and functions (also known methods).Objects share two characteristics: They have State and Behavior.
State: State is a well-defined condition of an item. A state captures the relevant aspects of an object
Behavior: Behavior is the observable effects of an operation or event,

Examples:
eg 1:
Object: House
State: Current Location, Color, Area of House etc.
Behavior: Close/Open main door.

eg 2:
Object: – Car
State: Color, Make
Behavior: Climb Uphill, Accelerate, SlowDown etc.

Note: Everything a software object knows (State) and can do (Behavior) is represented by variables and methods (functions) in the object respectively.

Class

A class is a prototype that defines the variables and the methods common to all objects of a certain kind. Member Functions operate upon the member variables of the class. An Object is created when a class in instantiated.

How to create an Object?

An object is created when a class is instantiated

Declaring an Object of class:

ClassName Objectname;

Object definition is done by calling the class constructor:

Constructor: A special member function which will be called automatically to initialize the data member of a class whenever object is instantiated.
Memory space is allocated only when a class is instantiated i.e. when an object is created

Defining a variable :
E.g. GraduationCourse mycourse= new GraduationCourse();

 

Leave a Reply

Your email address will not be published. Required fields are marked *