programming paradigms

Download Programming paradigms

Post on 19-Dec-2014




0 download

Embed Size (px)





2. A.V.C College of Engineering Department of Computer Science & Engineering 2013 Odd Semester SYLLABUS CS2305 PROGRAMMING PARADIGMS L T P C 3 0 0 3 AIM: To understand the concepts of object-oriented, event driven, and concurrent programming paradigms and develop skills in using these paradigms using Java. UNIT I OBJECT-ORIENTED PROGRAMMING FUNDAMENTALS 9 Review of OOP - Objects and classes in Java defining classes methods - access specifiers static members constructors finalize method Arrays Strings - Packages JavaDoc comments UNIT II OBJECT-ORIENTED PROGRAMMING INHERITANCE 10 Inheritance class hierarchy polymorphism dynamic binding final keyword abstract classes the Object class Reflection interfaces object cloning inner classes proxies UNIT III EVENT-DRIVEN PROGRAMMING 10 Graphics programming Frame Components working with 2D shapes Using color, fonts, and images - Basics of event handling event handlers adapter classes actions mouse events AWT event hierarchy introduction to Swing Model-View- Controller design pattern buttons layout management Swing Components UNIT IV GENERIC PROGRAMMING 8 Motivation for generic programming generic classes generic methods generic code 2 3. and virtual machine inheritance and generics reflection and generics exceptions exception hierarchy throwing and catching exceptions Stack Trace Elements - assertions logging UNIT V CONCURRENT PROGRAMMING 8 Multi-threaded programming interrupting threads thread states thread properties thread synchronization thread-safe Collections Executors synchronizers threads and event-driven programming TOTAL=45 PERIODS TEXT BOOK: 1. Cay S. Horstmann and Gary Cornell, Core Java: Volume I Fundamentals, Eighth Edition, Sun Microsystems Press, 2008. REFERENCES: 1. K. Arnold and J. Gosling, The JAVA programming language, Third edition, Pearson Education, 2000. 2. Timothy Budd, Understanding Object-oriented programming with Java, Updated Edition, Pearson Education, 2000. 3. C. Thomas Wu, An introduction to Object-oriented programming with Java, Fourth Edition, Tata McGraw-Hill Publishing company Ltd., 2006. 3 4. CS2305 PROGRAMMING PARADIGMSnit No Title I Object-oriented Programming Fundamentals II Object-oriented Programming Inheritance III Event-Driven Programming IV Generic Programming V Concurrent Programming 4 5. CS2305 PROGRAMMING PARADIGMS UNIT I OBJECT-ORIENTED PROGRAMMING FUNDAMENTALS 1) Review of OOP Concepts a) Encapsulation b) Inheritance c) Polymorphism 2) Objects and Classes in Java 3) Language Basics a) Comments b) Data Types c) Variables d) Statements e) Functions 4) Defining Classes 5) Methods 6) Access Specifiers 7) Static Members 8) Constructors a) Parameterized Constructors b) this Keyword c) Garbage Collection 9) Finalize Method 10) Arrays a) One Dimensional Arrays b) Multi Dimensional Arrays 11) Strings 12) Packages 13) JavaDOC Comments 14) References 1. Review OOP concepts The object oriented paradigm is built on the foundation laid by the structured programming concepts. The fundamental change in OOP is that a program is designed around the data being operated upon rather upon the operations themselves. Data and its functions are encapsulated into a single entity. OOP facilitates creating reusable code that can eventually save a lot of work. Polymorphism permits to create multiple definitions for functions. Inheritance permits to derive new classes from old ones. Benefits of object oriented programming Data security is enforced. Inheritance saves time. User defined data types can be easily constructed. A.V.C College of Engineering 6. CS2305 PROGRAMMING PARADIGMS Inheritance emphasizes inventions of new data types. Large complexity in the software development can be easily managed. Java History Java is a general-purpose object oriented programming language developed by Sun Microsystems of USA in 1991. Originally called oak by James Gosling, one of the inventors if the language. This goal had a strong impact on the development team to make the language simple, portable, highly reliable and powerful language. Java also adds some new features. While C++ is a superset of C. Java is neither a superset nor a subset of C or C++. C++ C Java Basic concepts of Object oriented programming All Java programs are object oriented. Computer programs consist of two elements: code and data. In process oriented model code acting on data. Procedural languages such as C employ this model. To manage increasing complexity object-oriented Programming approach was conceived. Object-oriented programming organizes a program around its data (that is, objects) and a set of well-defined interfaces to that data. An object-oriented program can be characterized as data controlling access to code. Abstraction An essential element of object-oriented programming is abstraction. Abstraction refers to the act of representing essential features without including the background details or explanations. For example, people do not think of a car as a set of tens of thousands of individual parts. They think of it as a well-defined object with its own unique behavior. This abstraction allows people to use a car to drive to the grocery store without being overwhelmed by the complexity of the parts that form the car. They can ignore the details of how the engine, transmission, and braking systems work. Instead they are free to utilize the object as a whole. The Three OOP Principles All object-oriented programming languages provide mechanisms to implement the object-oriented model. They are Encapsulation Inheritance Polymorphism A.V.C College of Engineering 7. CS2305 PROGRAMMING PARADIGMS a) Encapsulation Encapsulation is the mechanism that binds together code and the data it manipulates, and keeps both safe from outside interference and misuse. For example, shifting gears does not turn on the headlights in car, because it encapsulates the information about all process. In Java the basis of encapsulation is the class. A class defines the structure and behavior (data and code) that will be shared by a set of objects. For this reason, objects are sometimes referred to as instances of a class. Thus, a class is a logical construct and an object has physical reality. b) Inheritance Inheritance is the process by which one object acquires the properties of another object. This is important because it supports the concept of hierarchical classification. For example Bird Attributes: Feathers Lay eggs Flying bird Attributes: ----------- ---------- Non flying bird Attributes: ----------- ----------- The bird 'robin ' is a part of the class 'flying bird' which is again a part of the class 'bird'. The concept of inheritance provides the idea of reusability. c) Polymorphism Polymorphism means the ability to take more than one form. Subclasses of a class can define their own unique behaviors and yet share some of the same functionality of the parent class. Shape Draw() Circle Object Draw() Box Object Draw() Triangle Object Draw() 8. 2. Class and Object Class defines a new data type. Once defined, this new type can be used to create objects of that type. Thus, a class is a template for an object, and an object is an instance of a class. Class A class is a blueprint or prototype from which objects are created. The entire set of data and code of an object can be made of a user defined data type with the help of a class. We can create any number of objects for the same class. A.V.C College of Engineering 9. CS2305 PROGRAMMING PARADIGMS For example the construction of building requires a plan. Without plan we can't construct building. Here plan acts as class. Building acts as object. Using the same plan we can build any number of buildings. In the same way we can create any number of objects for the same class. Class tells the objects state and behavior. Basically class tells what the object should have. Object Object is an instance of class. Object is real world entity which has state, identity and behavior. It may represent a person, a place, a bank account, a table of data or any item that the program has to handle. JAVA Program structure A file containing Java source code is considered a compilation unit. Such a compilation unit contains a set of classes and, optionally, a package definition to group related classes together. Classes contain data and method members that specify the state and behavior of the objects in your program. Java programs come in two flavors: 1. Standalone applications that have no initial context such as a pre-existing main window 2. Applets for WWW programming Execution begins when you launch the java virtual machine and tell it to find a particular class. After finding the class, java executes the enclosed main() method with signature: public static void main(String[] args) { ... } Program Execution Create a source code file using a text editor. The source code is then compiled using the java compiler javac. Each java program is converted into one or more class files. The content of the class file is a set of instructions called bytecode to be executed by Java Virtual Machine (JVM).Java introduces bytecode to create platform independent program. JVM is an interpreter for bytecode which accepts java bytecode and produces result. Java Source Code Java Compiler (Javac) Java Byte Code (.class) Java Virtual Machine Java program Output A.V.C College of Engineering 10. CS2305 PROGRAMMING PARADIGMS 3. Language Basics a) Comments Java comments make your code easy to understand, modify and use. Java supports three different types of comment styl