Programming Paradigm and Intro to JAVA Lecture

Document Details

Uploaded by Deleted User

Dr. Adeniyi Jide Kehinde

Tags

programming paradigms java programming computer science introduction to programming

Summary

This lecture provides an overview of fundamental programming paradigms, focusing on imperative, declarative, and functional approaches. It also introduces basic concepts of Java programming.

Full Transcript

Programming Paradigm and Intro to JAVA DR. ADENIYI JIDE KEHINDE oUnderstand the different programming paradigms. oUnderstand OOP paradigm. Objectives: oKnow the pros and cons of different programming...

Programming Paradigm and Intro to JAVA DR. ADENIYI JIDE KEHINDE oUnderstand the different programming paradigms. oUnderstand OOP paradigm. Objectives: oKnow the pros and cons of different programming paradigm. oChoose a paradigm suitable for any problem. oIntro to JAVA 11/18/2024 Lecture Layout 11/18/2024 Declarative PP o Declarative programming is a style of building programs that expresses logic of computation without talking about its control flow. o It often considers programs as theories of some logic. o It may simplify writing parallel programs. o The focus is on what needs to be done rather how it should be done basically emphasize on what code is actually doing. o It is divided as Logic, Functional, Database. 11/18/2024 Declarative PP – Logic PP oIt can be termed as abstract model of computation. oIt would solve logical problems like puzzles, series etc. oIn logic programming we have a knowledge base which we know before and along with the question and knowledge base which is given to machine, it produces result. oIn normal programming languages, such concept of knowledge base is not available but while using the concept of artificial intelligence, machine learning we have some models like Perception model which is using the same mechanism. oIn logical programming the main emphasize is on knowledge base and the problem. 11/18/2024 Declarative PP DATABASE/DATA DRIVEN FUNCTIONAL PROGRAMMING PROGRAMMING APPROACH o has its roots in mathematics and o This programming methodology is it is language independent. based on data and its movement. o The key principle of this o Program statements are defined by paradigms is the execution of series of mathematical data rather than hard-coding a functions. series of steps. o The function hide their o A database program is the heart of implementation. a business information system and provides file creation, data entry, update, query and reporting 11/18/2024 Imperative Programming oIt works by changing the program state through assignment statements oIt performs step by step task by changing state. oThe main focus is on how to achieve the goal. oThe paradigm consist of several statements and after execution of all the result is stored. 11/18/2024 Imperative Programming PROS CONS 1.Very simple to 1.Complex problem cannot be solved implement 2.Less efficient and less 2.It contains loops, productive variables etc. 3.Parallel programming is not possible 11/18/2024 Imperative PP – procedural PP o This paradigm emphasizes on procedure in terms of under lying machine model. o There is no difference in between procedural and imperative approach. o It has the ability to reuse the code and it was good at that time when it was in use because of its reusability. 11/18/2024 Imperative PP – Parallel Processing Approach, Declarative PP o Parallel processing: is the processing of program instructions by dividing them among multiple processors. o A parallel processing system posses many numbers of processor with the objective of running a program in less time by dividing them. o This approach seems to be like divide and conquer. o C++ supports it because of some library function. 11/18/2024 Structured Programming (SP) o Structured programming is a programming approach in which the program is made as a single structure. o It means the code will be executed instruction by instruction (one after the other), NO GOTO statement. o It does not support the possibility of jumping from one instruction to another. o It is a technique devised to improve the reliability and clarity of programs. o Structure programming language include C, C++, Java, C# etc. 11/18/2024 Two primary features of SP Generally a program is considered structure if it has the following features: 1. A structure program is a hierarchical arrangement of highly independent modules. 2. Flow within the program is controlled exclusively by only three forms of control: selection, repetition and sequencing. ◦ In some text they are also termed: selection, iteration and sequencing. ◦ The hierarchy is a structured program should be obvious from the way the control structures are nested. ◦ A top-down chart is a way to show hierarchy in a Structured program. 11/18/2024 Selection, Repetition, Sequencing Basic Control structures: ◦If then else - for selection ◦Do while - for repetition ◦Placing statement one after the other for sequencing. ◦ Others ◦ Do until, while statement - for repetition ◦ Case statement - for selection 11/18/2024 Advantages/Disadvantages of SP o Easier to read and understand. o Since its machine independent, it takes time to convert to machine code. o User friendly. o Converted machine code is not the o Easier to maintain. same for assembly language. o Mainly problem based instead of o The program depends on changeable being machine based. factors like data-types. Hence, it needs o Development is easier as it requires to be updated with the need on the go. less effort and time. o Development takes longer time as it is o Easier to Debug. language dependent. Whereas in the o Machine-independent, mostly. case of assembly language, the development takes lesser time as it is fixed for the machine. 11/18/2024 Object Oriented Programming (OOP) and some facts o Object-Oriented Programming is a paradigm that provides many concepts, such as inheritance, data binding, polymorphism, etc. o In the programming paradigm where everything is represented as an object. o Simula is considered the first object-oriented programming language. o Smalltalk is considered the first truly object-oriented programming language. o The popular object-oriented languages are Java, C#, PHP, Python, C++, etc. o The main aim of object-oriented programming is to implement real-world entities, for example, object, classes, abstraction, inheritance, polymorphism, etc. 11/18/2024 OOP cont. o It simplifies software o Encapsulation development and maintenance o Coupling by providing some concepts: o Cohesion o Object o Association o Class o Aggregation o Inheritance o Composition o Polymorphism o Abstraction 11/18/2024 Objects o Any entity that has state and behavior is known as an object. o For example, a car, pencil, chair, etc. o It can be physical or logical. o An Object can be defined as an instance of a class. o An object contains an address and takes up some space in memory. o Objects can communicate without knowing the details of each other's data or code. 11/18/2024 Class/ Inheritance o Collection of objects is called class. It is a logical entity. o A class can also be defined as a blueprint from which you can create an individual object. o Class doesn’t consume any space. o Inheritance is when one object acquires all the properties and behaviors of a another object. o The inherited object is termed the parent object. o It provides code reusability. o It is used to achieve runtime polymorphism. 11/18/2024 Polymorphism/Abstraction/ Encapsulation o Polymorphism is if one task is performed in different ways e.g., to draw something, for example, shape, triangle, rectangle, etc. o Method overloading and overriding are techniques used to achieve this, for example, a cat speaks meow, dog barks woof, etc. o Hiding internal details and showing functionality is known as abstraction. o example phone call, we don't know the internal processing. o Binding (or wrapping) code and data together into a single unit are known as encapsulation. o for example, a capsule, it is wrapped with different medicines. 11/18/2024 Coupling/Cohesion o Coupling refers to the knowledge or information or dependency of another class. o It arises when classes are aware of each other. o If a class has the details information of another class, there is strong coupling. o Access modifiers are used to display visibility level. o Cohesion refers to the level of a component which performs a single well- defined task. o A single well-defined task is done by a highly cohesive method. o The weakly cohesive method will split the task into separate parts. 11/18/2024 Association o Association represents the relationship between the objects. o There can be four types: o One to One o One to Many o Many to One, and o Many to Many o For example, One country can have one prime minister (one to one). o Association can be undirectional or bidirectional. 11/18/2024 Aggregation o Aggregation is a way to achieve Association. o Aggregation represents the relationship where one object contains other objects as a part of its state. o It represents the weak relationship between objects. o It is another way to reuse objects. 11/18/2024 Composition o The composition is also a way to achieve Association. o The composition represents the relationship where one object contains other objects as a part of its state. o There is a strong relationship between the containing object and the dependent object. o It is the state where containing objects do not have an independent existence. o If you delete the parent object, all the child objects will be deleted automatically. 11/18/2024 Advantage of OOPs over Procedure-oriented programming language o OOPs makes development and maintenance easier. o OOPs provides data hiding. o OOPs provides the ability to simulate real-world event much more effectively. o Object-based programming language follows all the features of OOPs except Inheritance. o JavaScript and VBScript are examples of object-based programming languages. 11/18/2024 Intro to JAVA o Java is the global standard for developing and delivering embedded and mobile applications, games, web-based content, and enterprise software. o Java enables you to efficiently develop, deploy, and use exciting applications and services. o In 1990, Sun Microsystems began a research project to extend the power of network computing to consumer devices, such as video cassette recorders (VCRs) and televisions. o The Green Team, a team of highly skilled software developers at Sun under the leadership of James Gosling, developed Java (originally called Oak) as their solution. 11/18/2024 Platform Independence Consider the following: JAVA JAVA code bytecode (.java) JAVA Compiler (.class) 11/18/2024 Compiling and running a JAVA program 11/18/2024 THANK YOU FOR Listening 11/18/2024

Use Quizgecko on...
Browser
Browser