163x Filetype PDF File size 1.22 MB Source: www.velhightech.com
VELTECH HIGHTECH Dr.RANGARAJAN Dr.SAKUNTHALA ENGINEERING COLLEGE DEPARTMENT OF COMPUTER SCIENCE AND ENGINEERING CS8391- OBJECT ORIENTED PROGRAMMING UNIT-1 IINTRODUCTION TO OOP AND JAVA FUNDAMENTALS Object Oriented Programming - Abstraction – objects and classes - Encapsulation- Inheritance - Polymorphism- 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. 1. Explain oops concepts in Detail. Object-Oriented Programming: OOP is defined as object oriented programming. Basic Concepts of OOP 1) Class 2) Object 3) Method 4) Inheritance 5) Data Abstraction 6) Data Encapsulation 7) Polymorphism 8) Message Passing Defining the Class: A class is defined by the user is data type with the template that helps in defining the properties. Once the class type has been defined we can create the variables of that type using declarations that are similar to the basic type declarations. In java instances of the classes which are actual objects Eg: Class classname [extends superclassname] { [fields declarations;] [methods declaration;] } VELTECH HIGHTECH Dr.RANGARAJAN Dr.SAKUNTHALA ENGINEERING COLLEGE Page 1 VELTECH HIGHTECH Dr.RANGARAJAN Dr.SAKUNTHALA ENGINEERING COLLEGE DEPARTMENT OF COMPUTER SCIENCE AND ENGINEERING Field Declaration Data is encapsulated in a class by placing data fields inside the body of the class definition. These variables are called as instance variables. Class Rectangle { int length; int width; } Method Declaration A Class with only data fields has no life, we must add methods for manipulating the data contained in the class. Methods are declared inside the class immediate after the instance variables declaration. Eg: class Rectangle { int length; //instance variables int width; Void getData(int x, int y) // Method Declartion { Length =x; Width = y; } } Creating the objects: An object in java essentially a block of memory, which contains space to store all the instance variables. Creating an object is also referred as instantiating an object. Object in java are created using the new operator. Eg: Rectangle rec1; // Declare the object Rec1 = new Rectangle //instantiate the object VELTECH HIGHTECH Dr.RANGARAJAN Dr.SAKUNTHALA ENGINEERING COLLEGE Page 2 VELTECH HIGHTECH Dr.RANGARAJAN Dr.SAKUNTHALA ENGINEERING COLLEGE DEPARTMENT OF COMPUTER SCIENCE AND ENGINEERING The above statements can also be combined as follows Rectangle rec1 = new Rectangle; Methods: Methods are similar to functions or procedures that are available in other programming languages. Difference B/w methods and functions Difference b/w method and function is method declared inside class, function can be declared anywhere inside are outside class Writing methods in java if we had to repeatedly output a header such as: System.out.println("GKMCET"); System.out.println ("Allapakkam"); System.out.println ("Meppedu Road"); We could put it all in a method like this: public static void printHeader() { System.out.println("GKMCET"); System.out.println("Allapakkam"); System.out.println("Meppedu Road"); } Inheritance: Inheritance is the process of forming a new class from an existing class or base class. The base class is also known as parent class or super class, the new class that is formed is called derived class. Derived class is also known as a child class or sub class. Inheritance helps in reducing the overall code size(reusability) of the program, which is an important concept in object oriented programming. Data Abstraction: Data abstraction increases the power of programming language by creating user defined data types. Data abstraction also represents the needed information in the program without presenting the details. Data Encapsulation: VELTECH HIGHTECH Dr.RANGARAJAN Dr.SAKUNTHALA ENGINEERING COLLEGE Page 3 VELTECH HIGHTECH Dr.RANGARAJAN Dr.SAKUNTHALA ENGINEERING COLLEGE DEPARTMENT OF COMPUTER SCIENCE AND ENGINEERING Data encapsulation combines data and functions into a single unit called class. When using Data Encapsulation, data is not accessed directly; it is only accessible through the functions present inside the class. Data encapsulation enables the important concept of data hiding possible. Polymorphism: Polymorphism allows routines to use variables of different types at different times. An operator or function can be given different meanings or functions. The ability of objects to respond differently to the same message or function call. Message passing: A message passing system provides primitives for sending and receiving messages using objects. These primitives may by either synchronous or asynchronous or both. 2. Explain the Characteristics/ Features of Java in Detail. 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 polularity of this language. The features of Java are also known as java buzzwords. Following is a list of most important features of Java language. The Java Features given below are simple and easy to understand. ➢ Simple ➢ Object-Oriented ➢ Portable ➢ Platform independent ➢ Secured ➢ Robust ➢ Architecture neutral ➢ Dynamic ➢ Interpreted ➢ High Performance ➢ Multithreaded ➢ Distributed Simple Java is very easy to learn and its syntax is simple, clean and easy to understand. According to Sun, Java language is simple because: syntax is based on C++ (so easier for programmers to learn it after C++). removed many confusing and/or rarely-used features e.g., explicit pointers, operator overloading etc. 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: VELTECH HIGHTECH Dr.RANGARAJAN Dr.SAKUNTHALA ENGINEERING COLLEGE Page 4
no reviews yet
Please Login to review.