Object Oriented Programming Language

  • Java programming language is a object oriented language. Object-oriented programming enables you to think of program elements as objects.
  • Object oriented programming (OOP) is a programming paradigm based on the concept of "objects - Real world entity", which may contain data, in the form of fields often known as attributes and code in the form of procedures often known as methods.
  • The objected oriented paradigm is not just a programming style but also a design method for building systems. Object oriented languages allow the programmer to specify self contained units and specify them as objects which are made up of data and the methods or operations which can be performed on the object.
  • The prime purpose of object oriented programming is to create an object in code that has certain properties (Variable / Data Member) and behavior (Function or Method / Member Function).
  • For example, a car is an object that manipulates its speed and direction to transport people from one place to another.
    This car object encapsulates all the functions and data that it needs to get its job done.
    It has a switch to turn it on, a wheel to control its direction and brakes to slow it down.
    These functions directly manipulate the car's data, including direction, position and speed.
    When you travel in a car, however you do not have to know the details of how these operations work.
    To stop a car, for example, you simply step on the brake pedal.
    You do not have to know how the pedal stops the car. You simply know that it works.
    All these functions and data work together to define the object called a car.
    Moreover, all these functions work for every car (vehicle) individually.
    You are not likely to confuse a car with a dishwasher, a tree or a playground.
    A car is a complete unit "an object - real world entity" with unique properties and behavior.
  • Objects have state (variables / fields / data members / properties)
    Objects have actions (methods / functions / member function / behavior)
    Objects build upon each other (inheritance)
    Syntax to create an object classname objectname = new classname();
  • Each and every Object in the real world contains two things PROPERTY and BEHAVIOR.
    Example: Imagine you are a factory owner, you want to describe a generic phone
    • Step 1: List generic phone properties eg: height, weight, colour, etc.
    • Step 2: List generic phone behavior eg: make call, receive call, send sms etc.

What is meant by class in Java?

  • A class is nothing but a blueprint or a template for creating different objects which defines its properties and behaviors.
  • A class can contain (fields / data members) and (functions / member function) to describe the behavior of an object.
  • Example = class A+bc class name must not contain any operator.
  • Example = class A bc class name must not contain any space. (Underscores are allowed)
  • Example = class import class name must not be keyword.
  • Example = class 123 class name must not be a number.
  • Example = class 1Abc class name must not be start from a number.
  • class name should be meaningful, according to its functionality.
  • Example = class DemoOfJava every first word in class name should be capital to increase readability of the code.
  • When you are saving the java program, so keep the file name and class name same.
  1. public class Hp
  2. {
  3. public static void main (String args[])
  4. {
  5. System.out.println("Hp = Hello Programmer");
  6. }
  7. }
  8. Command Prompt (cmd)
  9. To Compile - javac hp.java
  10. To Run - java Hp
  11. Result - Hp = Hello Programmer
  1. public class Hp
  2. {
  3. public static void main (String args[])
  4. {
  5. System.out.println("Hp = Hello Programmer");
  6. }
  7. }
  8. Command Prompt (cmd)
  9. To Compile - javac hp.java
  10. To Run - java hp
  11. Result - Error: Could not find or load main class hp

Method

  • A method in object oriented programming (OOP) is a procedure associated with an object class.
  • An object is made up of behavior and data.
  • Data is represented as properties of the object and behavior as methods.
  • Methods are also the interface an object presents to the outside world.

| Copyright ©2016 | All Rights Reserved |
| Design by Uves Khan |

Free Web Hosting