Every great story on the planet happened when someone decided not to give up, but kept going no matter what.
--Your friends at LectureNotes

Note for Object Oriented Programming Using JAVA - OOPJ By Abhishek Kumar

  • Object Oriented Programming Using JAVA - OOPJ
  • Note
  • Biju Patnaik University of Technology BPUT - BPUT
  • Computer Science Engineering
  • 11 Topics
  • 1 Offline Downloads
  • Uploaded 2 months ago
Abhishek Kumar
Abhishek Kumar
0 User(s)
Download PDFOrder Printed Copy

Share it with your friends

Leave your Comments

Text from page-1

UNIT I INTRODUCTION TO OOP AND JAVA FUNDAMENTALS Object Oriented Programming - Abstraction – objects and classes - Encapsulation- InheritancePolymorphism- OOP in Java – Characteristics of Java – The Java Environment - Java Source File Structure Compilation. Fundamental Programming Structures in Java – Defining classes in Java – constructors, methods - access specifiers - static members - Comments, Data Types, Variables, Operators, Control Flow, Arrays, Packages - JavaDoc comments. OBJECT-ORIENTED PROGRAMMING Object-Oriented Programming (OOP) is a programming language model organized around objects rather than actions and data. An object-oriented program can be characterized as data controlling access to code. Concepts of OOPS  Object  Class  Inheritance  Polymorphism  Abstraction  Encapsulation OBJECT Object means a real word entity such as pen, chair, table etc. Any entity that has state and behavior is known as an object. Object can be defined as an instance of a class. An object contains an address and takes up some space in memory. Objects can communicate without knowing details of each other's data or code, the only necessary thing is that the type of message accepted and type of response returned by the objects. An object has three characteristics:  state: represents data (value) of an object.  behavior: represents the behavior (functionality) of an object such as deposit, withdraw etc.  identity: Object identity is typically implemented via a unique ID. The value of the ID is not visible to the external user. But, it is used internally by the JVM to identify each object uniquely. CLASS Collection of objects is called class. It is a logical entity. A class can also be defined as a blueprint from which you can create an individual object. A class consists of Data members and methods.The primary purpose of a class is to hold data/information. The member functions determine the behavior of the class, i.e. provide a definition for supporting various operations on data held in the form of an object.Class doesn’t store any space. INHERITANCE Inheritance can be defined as the procedure or mechanism of acquiring all the properties and behavior of one class to another, i.e., acquiring the properties and behavior of child class from the parent class. When one object acquires all the properties and behaviours of another object, it is known as inheritance. It provides code reusability and establishes relationships between different classes. A class which inherits the properties is known as Child Class(sub-class or derived class) whereas a class whose properties are inherited is known as Parent class(super-class or base class). Types of inheritance in java: single, multilevel and hierarchical inheritance. Multiple and hybrid inheritance is supported through interface only. 1

Text from page-2

POLYMORPHISM When one task is performed by different ways i.e. known as polymorphism. For example: to convince the customer differently, to draw something e.g. shape or rectangle etc. Polymorphism is classified into two ways: Method Overloading(Compile time Polymorphism) Method Overloading is a feature that allows a class to have two or more methods having the same name but the arguments passed to the methods are different. Compile time polymorphism refers to a process in which a call to an overloaded method is resolved at compile time rather than at run time. Method Overriding(Run time Polymorphism) If subclass (child class) has the same method as declared in the parent class, it is known as method overriding in java.In other words, If subclass provides the specific implementation of the method that has been provided by one of its parent class, it is known as method overriding. ABSTRACTION Abstraction is a process of hiding the implementation details and showing only functionality to the user. For example: phone call, we don't know the internal processing.In java, we use abstract class and interface to achieve abstraction. ENCAPSULATION Encapsulation in java is a process of wrapping code and data together into a single unit, for example capsule i.e. mixed of several medicines.A java class is the example of encapsulation. DIFFERENCE BETWEEN PROCEDURE-ORIENTED AND OBJECT-ORIENTED PROGRAMMING Procedure-Oriented Programming Object-Oriented Programming In POP, program is divided into small parts In OOP, program is divided into parts called functions called objects. In POP,Importance is not given to data but to In OOP, Importance is given to the data rather 2

Text from page-3

functions as well as sequence of actions to be than procedures or functions because it works as done. a real world. POP follows Top Down approach. OOP follows Bottom Up approach. POP does not have any access specifier. OOP has access specifiers named Public, Private, Protected, etc. In POP, Data can move freely from function to In OOP, objects can move and communicate with function in the system. each other through member functions. To add new data and function in POP is not so OOP provides an easy way to add new data and easy. function. In POP, Most function uses Global data for In OOP, data can not move easily from function sharing that can be accessed freely from function to function,it can be kept public or private so we to function in the system. can control the access of data. POP does not have any proper way for hiding OOP provides Data Hiding so provides more data so it is less secure. security. In POP, Overloading is not possible. In OOP, overloading is possible in the form of Function Overloading and Operator Overloading. Example of POP are : C, VB, FORTRAN, Example of OOP are : C++, JAVA, VB.NET, Pascal. C#.NET. FEATURES OF JAVA The main objective of Java programming language creation was to make it portable, simple and secure programming language. Apart from this, there are also some awesome features which play important role in the popularity of this language. The features of Java are also known as java buzzwords. A list of most important features of Java language are given below. Simple Java is very easy to learn and its syntax is simple, clean and easy to understand. According to Sun, Java language is a simple programming language because:  Java syntax is based on C++ (so easier for programmers to learn it after C++).  Java has removed many confusing and rarely-used features e.g. explicit pointers, operator overloading etc.  There is no need to remove unreferenced objects because there is Automatic Garbage Collection in java. Object-oriented Java is object-oriented programming language. Everything in Java is an object. Object-oriented means we organize our software as a combination of different types of objects that incorporates both data and behaviour. Object-oriented programming (OOPs) is a methodology that simplifies software development and maintenance by providing some rules. Basic concepts of OOPs are: 1. Object 2. Class 3. Inheritance 4. Polymorphism 5. Abstraction 6. Encapsulation Platform Independent 3

Text from page-4

Java is platform independent because it is different from other languages like C, C++ etc. which are compiled into platform specific machines while Java is a write once, run anywhere language. A platform is the hardware or software environment in which a program runs. There are two types of platforms software-based and hardware-based. Java provides software-based platform. The Java platform differs from most other platforms in the sense that it is a software-based platform that runs on the top of other hardware-based platforms. It has two components: 1. Runtime Environment 2. API(Application Programming Interface) Java code can be run on multiple platforms e.g. Windows, Linux, Sun Solaris, Mac/OS etc. Java code is compiled by the compiler and converted into bytecode. This bytecode is a platform-independent code because it can be run on multiple platforms i.e. Write Once and Run Anywhere(WORA). Secured Java is best known for its security. With Java, we can develop virus-free systems. Java is secured because: o No explicit pointer o Java Programs run inside virtual machine sandbox 4

Lecture Notes