BY N.RUBA ASST.PROF/DEPT. OF CA, BON SECOURS COLLEGE FOR WOMEN, THANJAVUR.
 JAVA - A general purpose, high- level, object-oriented, cross- platform programming language developed by James Gosling at Sun Microsystems in 1995.  In structured programming, a complex program is broken into sets of smaller, understandable tasks; but it is very hard to maintain.
 Introduction to oop ◦ A procedure is defined as a collection of instruction executed in sequential order.  Oops concept was introduced by Xerox Corporation in early 1970s.  The first object oriented language was Smalltalk.  Oops languages: C++,Java and Eiffel.
 Objects and Classes are building blocks of OOP.  Object is a Programming entity in OOP. ◦ It has data components representing the present state of the object as well as functions also called methods.  Object contains ◦ Attributes- data associated with the object ◦ Methods-functions and code which operate on the data
 Class is a model or pattern from which an object is created.  Class is a special module that defines an object. ◦ The process of creating an object from a class is called instantiation. ◦ Every object is an instance of a particular class
 There are 3 main characteristics Encapsulation •Abstraction via encapsulation •Data hiding Inheritance •Single •multiple Polymorphism •Operator overloading •Function overloading
Encapsulation-The concept of sealing data and methods that operate on the data into an object(a single unit) .  Abstraction via encapsulation  data hiding  Abstraction via encapsulation  Software object is an abstrat entity in that we view it from outside. Without concerning oueselves with detail of how it work on the inside.  E.g Car and its gear.  Dividing a program into modules is called modularity. Not having to know the internal implementation of a module is called abstraction
 Data hiding ◦ Encapsulation provide the hiding of data information. ◦ It prevent user from seeing the internal working of an object. ◦ This is used to protect data, that should not be manipulated by the user. ◦ Every class can hide some of the part, every element (field or method) of one class can have one of the three level of visibility. ◦ They are  Public  Private and  protected
 Public elements are completely visible from outside the class. They form the interface with the outside world  Private elements are visible only to methods of the class itself.  Protected elements are something between public and private. ◦ (act as private elements, but they are completely visible to inherited child classes)
 Benefits of encapsulation ◦ Improves program reliability ◦ Reduces maintenance ◦ Lends usability ◦ Facilitates information hiding ◦ Improves modularity ◦ Makes coding easier
BASE CLASS CHILD CLASS BASE CLASS CHILD CLASS
 Advantages of using inheritance : ◦ Increased productivity ◦ Reduced maintenance ◦ Standardization  The major drawback of inheritance is added overhead.  An user must know changes in the methods of base class before using the derived classobjects.  Though the derived class objects may not require all the functionalities of a base class,the derived class implements all the methods of base class. This increases the amount ofmemory required for execution of the program.  Since common functionalities exist in the base class, there is an execution overhead forderived class due to the implementation of base class methods when compared to havingthe functionalities in a single class itself. In the case of a chain of inheritances, the executionOverhead may increase further.
 Allows an entity to take a variety of representations ◦ Operator overloading  Is the ability to use an operator on different argument types e.g operator ‘+’ is used to add either integers or floating point numbers.(for adding two nos and concatenation of two strings)  Java does not support user-defined operator overloading.
 Function overloading ◦ -is the ability to access different implementations of functions using the same name. ◦ E.g  printdate(String Str) {……}  //ans: August 3,2020  Printdate(int dd,int mm, int yyyy) {…..}  //ans:3,8,2020
 Two types of function overloading ◦ Early binding  Allows us to have two functions in the same class that have the same name with different parameters and different datatypes passed to it.  E.g add(int a, int b)  add(int a, int b, float c)  Early binding takes place during compile time. ◦ Late binding
 Late binding ◦ Allows us to have functions with same name in base and derived classes. But the derived class function will override the base class function.  Base class functions draw()  Derived function fill()
 METHOD OVERRIDING SHAPE DRAW( ) DRAW( ) DRAW( ) DRAW( )
 In classical procedural (or structural) programming, there are techniques to write a code that handles some general task  The most important techniques of that kind are functions (proceduresor sub- routines). The large program is partitioned into functions that each perform a specifictask.  The main program calls these functions, which in turn may call other functions. The majorconcern of this programming is with respect to the data. Data are passed around from one non-member function to another and are available everywhere throughout the large program.  This allows the user to access the data directly, alter it from several points in the program and inadvertently introduce mistakes. If one programmerchanges the representation of the data in the computer's memory by rearranging fields withina structure (record), other functions in the program may need to be rewritten and must then beretested to account for this change. That means the data are not well protected in procedureoriented programming. Though local variables in a function can be accessed within the function,they are not useful if they must be accessed by different functions.
 In contrast, OOP safely encapsulates collections of functions (called methods) with the data they manipulate.  The data can only be manipulated by its own functions.  This feature protects the data from rest of the program.Though the concepts of object oriented programming are different from procedural oriented programming, structured programming constructs are still used in OOP especially in the codingof methods.
 Code reusability  Code modularity  Easier maintenance  Design stability  Improved communication between developers and users  Seamless transition from design to implementation
 Execution overhead-derived classes can be very complex because of inheritance and polymorphism ◦ Once a derived class is initiated all the data and functions from the base classes are carried along with it.some of these , or even most of it may not be used  Abstraction may lead to performance degradation
 High learning curve ◦ OOP is different from traditional programming. ◦ We must develop strong base classes and understand the functionality of class libraries before take advantages from it.  Difficulty in establishing base classes ◦ Good foundation must be created before derive other classes.

Introduction to Java -unit-1

  • 1.
    BY N.RUBA ASST.PROF/DEPT. OF CA, BONSECOURS COLLEGE FOR WOMEN, THANJAVUR.
  • 2.
     JAVA -A general purpose, high- level, object-oriented, cross- platform programming language developed by James Gosling at Sun Microsystems in 1995.  In structured programming, a complex program is broken into sets of smaller, understandable tasks; but it is very hard to maintain.
  • 3.
     Introduction tooop ◦ A procedure is defined as a collection of instruction executed in sequential order.  Oops concept was introduced by Xerox Corporation in early 1970s.  The first object oriented language was Smalltalk.  Oops languages: C++,Java and Eiffel.
  • 4.
     Objects andClasses are building blocks of OOP.  Object is a Programming entity in OOP. ◦ It has data components representing the present state of the object as well as functions also called methods.  Object contains ◦ Attributes- data associated with the object ◦ Methods-functions and code which operate on the data
  • 5.
     Class isa model or pattern from which an object is created.  Class is a special module that defines an object. ◦ The process of creating an object from a class is called instantiation. ◦ Every object is an instance of a particular class
  • 6.
     There are3 main characteristics Encapsulation •Abstraction via encapsulation •Data hiding Inheritance •Single •multiple Polymorphism •Operator overloading •Function overloading
  • 7.
    Encapsulation-The concept ofsealing data and methods that operate on the data into an object(a single unit) .  Abstraction via encapsulation  data hiding  Abstraction via encapsulation  Software object is an abstrat entity in that we view it from outside. Without concerning oueselves with detail of how it work on the inside.  E.g Car and its gear.  Dividing a program into modules is called modularity. Not having to know the internal implementation of a module is called abstraction
  • 8.
     Data hiding ◦Encapsulation provide the hiding of data information. ◦ It prevent user from seeing the internal working of an object. ◦ This is used to protect data, that should not be manipulated by the user. ◦ Every class can hide some of the part, every element (field or method) of one class can have one of the three level of visibility. ◦ They are  Public  Private and  protected
  • 9.
     Public elementsare completely visible from outside the class. They form the interface with the outside world  Private elements are visible only to methods of the class itself.  Protected elements are something between public and private. ◦ (act as private elements, but they are completely visible to inherited child classes)
  • 10.
     Benefits ofencapsulation ◦ Improves program reliability ◦ Reduces maintenance ◦ Lends usability ◦ Facilitates information hiding ◦ Improves modularity ◦ Makes coding easier
  • 11.
    BASE CLASS CHILD CLASS BASECLASS CHILD CLASS
  • 12.
     Advantages ofusing inheritance : ◦ Increased productivity ◦ Reduced maintenance ◦ Standardization  The major drawback of inheritance is added overhead.  An user must know changes in the methods of base class before using the derived classobjects.  Though the derived class objects may not require all the functionalities of a base class,the derived class implements all the methods of base class. This increases the amount ofmemory required for execution of the program.  Since common functionalities exist in the base class, there is an execution overhead forderived class due to the implementation of base class methods when compared to havingthe functionalities in a single class itself. In the case of a chain of inheritances, the executionOverhead may increase further.
  • 13.
     Allows anentity to take a variety of representations ◦ Operator overloading  Is the ability to use an operator on different argument types e.g operator ‘+’ is used to add either integers or floating point numbers.(for adding two nos and concatenation of two strings)  Java does not support user-defined operator overloading.
  • 14.
     Function overloading ◦-is the ability to access different implementations of functions using the same name. ◦ E.g  printdate(String Str) {……}  //ans: August 3,2020  Printdate(int dd,int mm, int yyyy) {…..}  //ans:3,8,2020
  • 15.
     Two typesof function overloading ◦ Early binding  Allows us to have two functions in the same class that have the same name with different parameters and different datatypes passed to it.  E.g add(int a, int b)  add(int a, int b, float c)  Early binding takes place during compile time. ◦ Late binding
  • 16.
     Late binding ◦Allows us to have functions with same name in base and derived classes. But the derived class function will override the base class function.  Base class functions draw()  Derived function fill()
  • 17.
     METHOD OVERRIDING SHAPE DRAW() DRAW( ) DRAW( ) DRAW( )
  • 18.
     In classicalprocedural (or structural) programming, there are techniques to write a code that handles some general task  The most important techniques of that kind are functions (proceduresor sub- routines). The large program is partitioned into functions that each perform a specifictask.  The main program calls these functions, which in turn may call other functions. The majorconcern of this programming is with respect to the data. Data are passed around from one non-member function to another and are available everywhere throughout the large program.  This allows the user to access the data directly, alter it from several points in the program and inadvertently introduce mistakes. If one programmerchanges the representation of the data in the computer's memory by rearranging fields withina structure (record), other functions in the program may need to be rewritten and must then beretested to account for this change. That means the data are not well protected in procedureoriented programming. Though local variables in a function can be accessed within the function,they are not useful if they must be accessed by different functions.
  • 19.
     In contrast,OOP safely encapsulates collections of functions (called methods) with the data they manipulate.  The data can only be manipulated by its own functions.  This feature protects the data from rest of the program.Though the concepts of object oriented programming are different from procedural oriented programming, structured programming constructs are still used in OOP especially in the codingof methods.
  • 20.
     Code reusability Code modularity  Easier maintenance  Design stability  Improved communication between developers and users  Seamless transition from design to implementation
  • 21.
     Execution overhead-derivedclasses can be very complex because of inheritance and polymorphism ◦ Once a derived class is initiated all the data and functions from the base classes are carried along with it.some of these , or even most of it may not be used  Abstraction may lead to performance degradation
  • 22.
     High learningcurve ◦ OOP is different from traditional programming. ◦ We must develop strong base classes and understand the functionality of class libraries before take advantages from it.  Difficulty in establishing base classes ◦ Good foundation must be created before derive other classes.