2-OOPS (Object Oriented Programming Specification) concepts:


1. Encapsulation       2.  Polymarphism    3. Inheritance


Encapsulation  :  Encapsulation is the concept of binding data along with its corresponding functionalities.
                            Encapsulation came  into existence in order to provide security for the data present inside
                            the program.  Ex : Class.
Ø   Encapsulation is the back bone of OOP languages.
Ø Java supports all the OOP concepts. (I.e. Encapsulation, Polymorphism, inheritance) and hence it is known as Object Oriented Programming language.
Ø C++ breaks the concept of Encapsulation because the main () method in a C++ Program is declared outside a class hence it is not a pure OOP language in fact it is a Poor OOP Language.
Any program contains two parts:
1. Data part       2. Logic part.
·        Out of data and logic highest priority is given to data. But in Structured programming languages the data insecurity is high.
·        Thus in the process of securing data in structured programming languages ,the concept of encapsulation came into existence.
·        In Structured programming language programs, the global variables play a vital role.
·        But because of these global variables there is data insecurity in the structured programming language programmers. i.e. functions that are not related to some variables are not  related to
·        Some variables will have access to those variables and thus data may get corrupted in this way data is insecure.
·        This is what people say in general about data insecurity but this is not  the actual reason
·        Let us assume that we have a ‘C’ program with two hundred functions assume that it is a project now if any up gradation is required, then the client i.e. The user of this program or s/w comes to the IT company and asks the programmers to update it according to his requirement.


The actual concept is as follows.
·        Now we should note that it is not guaranteed that the programmers who developed this program will still be working with that company. Hence this project falls into the hands of new programmers. Automatically it takes a lot of time to study the project itself before upgrading it.  It may not be surprising  that the time required for writing code to upgrade the project may be very less when compared to the time required for  studying the project .Thus maintenance becomes a problem .

·        If the new programmer adds a new function to the exiting code in such a way of upgrading it ,
·        There is no guarantee that it will not affect the existing functions in the code, this is because of global variables. In this way data insecurity is created.

·        To overcome these problem programmers developed the concept of Encapsulation.
·        For example let us have a Structured programming language program with Ten Global variable and twenty functions.
·        It is sure that all the twenty functions will not use all the global variables. Three of the global variables may be used only by two functions but in a structured programming language like ‘C’ it is not possible to restrict the access of global variables by some limited number of functions.

                        Every function will have access to all the global variables.
·        To avoid this problem, programmers have designed a way such that the variables and the functions which are associated with or operate on those variables are enclosed in a block. And that block is called a Structure or Class. And that class is given a name, just as a function is given a name.

·        Now the variables inside the block cannot be called as Local variables because they are not local to only one function and they cannot be called as global variables because they are confined to a block and not global. Hence these variables are known as Instance Variables”.




A Simple java Program :-



Rules and Regulations:-
Ø The Class name should with the Capital Letter (not mandatory) but it is a conventional rule.
Ø Java is Case sensitive
Ø All key words in java are written in small letters.
Ø As a convention anything that starts with a Capital Letter is treated as a name of a Class in java.
Following is a simple program that prints   “hello world” message.
Ex:   public class Hello {
        public static void main (String [] args)     {
         System.out.println ("Hello world");
          }   }
In the above Program, “hello” is the class name. We have the main method which has the only one statement in it.Note 1:- no method or function should be written in a program without mentioning its return data type. Even in this program main () is a method and it returns nothing hence the keyword void is present before it. Void indicates that the main () method does not return anything.
·        In the above program public, static, void are keywords main () is a method. String is a class. Println ()   is a method and System is class.
Let us save this programme as Hello.java.
·        Now we compile the programme with following command in Command Prompt. 
  [     D:\>   javac  Hello.java   ]
·        After the execution of the command Hello.class is created.
·        In other words it is the command given to the java compiler to convert the contents of the mentioned source into its equivalent byte code. Now the following command is given to the JVM to execute the .class file.
         Note: - Use edit plus editor for developing java program’s.
          Key words  à blue.     Predefined classes -à red



Other part of the programme is displayed in black.
So easily recognize the syntactical and grammatical errors.






As soon as the programme is compiled

D:\> javac Beginner.java

Beginner.class file will be formed

D:\> java Beginner


When the above command is given   necessary part    i.e.  main() method of a .class file is converted into its executable code and is loaded into the RAM from the hard disk and made available for CPU for execution.
Now till       y = y+1 no problem.
But when the control comes to the statement x=x+1 it generates a compilation error because x is not a variable declared in main. But we should note that int x=10; is declared inside the class but presently it is not available to the CPU as it is not in the RAM.
Now by using some procedure if we are able to transfer the contents of hard disk to the RAM then x will be resent in the RAM and it will be available to the main and thereby to the CPU for execution.
The procedure of loading the contents of hard disk to the RAM dynamically at runtime is done by creating an Object.  (This is need of creating an Object.)




No comments:

Post a Comment