Presentation is loading. Please wait.

Presentation is loading. Please wait.

Introduction to Object Oriented Programming Java.

Similar presentations


Presentation on theme: "Introduction to Object Oriented Programming Java."— Presentation transcript:

1 Introduction to Object Oriented Programming Java

2 Resources If you are new to programming in Java, there is an online book which is serves as a good introduction: ●Thinking in Java 3 rd edition This can be found at: http://www.mindview.net/Books/TIJ/

3 Development Environment  You can use the command line and notepad to edit and compile java programs.  You can also use jedit  BlueJ is a tool which will help you format code, compile and test your programs.

4 OOP Introduction  Introduced in the 60s as a proposed solution to the sprawl of software  Allowed designers to describe the system entities in plain language and design functions and attributes for each entity.  The interaction or interfaces between the entities can also be designed easily.

5 An OO Approach class Student{ /* attributes */ String name; int age; int courseNumber; int fees; boolean enrolled; /* Methods */ public getName(){... } public int getAge() {...} public int getFees() {...} } class StudentRecords{ /* attributes */ Student [] database; Course [] allCourses; /* Methods */ public void enrollStudent(Student s) {... } public void disenrollStudent (Student s) {... } public int getTotalStudents() {... } }

6 Advantages of OO Programming  The software is modular and reusable i.e. we could reuse our code for Student in an examRecords system  It is extendable, and maintainable  i.e. if we decided to store students mobile phone numbers, it'd just be a small change to the Student class.

7 OO Programming Vocabulary ● class ● object ● method/attribute ● inheritance ● encapsulation ● abstraction ● polymorphism

8 Class A class is a definition of a well defined entity, containing attributes and methods. This is a real world entity class Employees { }

9 Object  An object is an instance of a class.  e.g. Employee e1 = new Employee();  e1 is now an object of type Employee.

10 Method  A method is simply a well defined function within a class.  Example methods in Employee...  getSalary();  getDOB();  add();  remove();

11 Attribute ● An attribute is an instance variable which represents some data within a class. For example, all employees have a name and a salary. so... ● class Student{ String name; float salary;..etc. }

12 Inheritance ● Inheritance allows you to define classes which inherit the behaviour and attributes of other classes. ● For example, you may have one Employee class, but 3 different types of employees (permanent staff, part time staff and managers). Rather than write 3 entirely separate classes you can inherit the standard employee characteristics from a base class.

13 Inheritance Example Employee PermanentPartTimeManager forthnightSalary weeklySalary monthlySalary

14 Advantages of this approach  Less code, therefore easier to maintain  Reusable Employee class

15 Encapsulation ● We've seen how to specify the behaviour of an object, the idea of encapsulation is to hide the details of how something is achieved. ● e.g. If you are using a class that someone else has written, you want to be able to call a method (Save File for example) without knowing what is going on in the background.

16 Abstraction ● Abstraction a principle used to enable inheritance. ● Using abstraction you develop general classes that are appropriate to the problem, and then for specific problems inherit from these general classes. ● e.g. an Employee class models the typical behaviours of employees, but for parttime staff you'll need more specific methods.

17 Polymorphism ● Polymorphism is a type of encapsulation that is aimed at decoupling software systems. ● Polymorphism literally means “many forms“, and its idea is to allow subclasses to have their own specific implementations of methods. e.g. calculateSalary is a different process for our three types of employee.


Download ppt "Introduction to Object Oriented Programming Java."

Similar presentations


Ads by Google