JAVA Introduction ការណែនាំពី Java

Slides:



Advertisements
Similar presentations
Operating Systems Components of OS
Advertisements

OO Programming in Java Objectives for today: Overriding the toString() method Polymorphism & Dynamic Binding Interfaces Packages and Class Path.
June 1, 2000 Object Oriented Programming in Java (95-707) Java Language Basics 1 Lecture 6 Object Oriented Programming in Java Language Basics Objects.
The Bridge Pattern.. Intent Decouple an abstraction from its implementation so that the two can vary independently Also known as: Handle/Body.
OOP Languages: Java vs C++
Programming Languages and Paradigms Object-Oriented Programming.
Overview of Previous Lesson(s) Over View  OOP  A class is a data type that you define to suit customized application requirements.  A class can be.
220 FINAL TEST REVIEW SESSION Omar Abdelwahab. INHERITANCE AND POLYMORPHISM Suppose you have a class FunClass with public methods show, tell, and smile.
Sadegh Aliakbary Sharif University of Technology Fall 2011.
JAVA Introduction ● One of the main JAVA design goal is reducing complexity for programmer – Development time is half or less comparing to equivalent C++
Introduction to Object Oriented Programming. Object Oriented Programming Technique used to develop programs revolving around the real world entities In.
1 Java Inheritance. 2 Inheritance On the surface, inheritance is a code re-use issue. –we can extend code that is already written in a manageable manner.
Sadegh Aliakbary. Copyright ©2014 JAVACUP.IRJAVACUP.IR All rights reserved. Redistribution of JAVACUP contents is not prohibited if JAVACUP.
Class Relationships Lecture Oo10 Dependencies. References n Booch, et al, The Unified Modeling Language User Guide, Chapt 5 p.69, Chapt 9 130, Chapt 10.
Programming Languages and Paradigms Object-Oriented Programming.
Objected Oriented Programming & Design JAVA Shishir Gupta (704) (704)
Introduction to Object Oriented Programming CMSC 331.
Inheritance - Polymorphism ITI 1121 Nour El Kadri.
Genericity Ranga Rodrigo Based on Mark Priestley's Lectures.
Chapter 3 Inheritance and Polymorphism Goals: 1.Superclasses and subclasses 2.Inheritance Hierarchy 3.Polymorphism 4.Type Compatibility 5.Abstract Classes.
1 Programming Paradigms Object Orientated Programming Paradigm (OOP)
Object Oriented Software Development
Chapter 6 Introduction to Defining Classes. Objectives: Design and implement a simple class from user requirements. Organize a program in terms of a view.
Chapter 1 Introduction to Objects. Outline of the chapter  The basic concepts of object-oriented programming (OOP)  An overview of OOP development methods.
1 Lecture 6: Polymorphism - The fourth pillar of OOP -
Programming with Java © 2002 The McGraw-Hill Companies, Inc. All rights reserved. 1 McGraw-Hill/Irwin Chapter 5 Creating Classes.
Lecture 10 Concepts of Programming Languages Arne Kutzner Hanyang University / Seoul Korea.
9-Dec Dec-15  INTRODUCTION.  FEATURES OF OOP.  ORGANIZATION OF DATA & FUNCTION IN OOP.  OOP’S DESIGN.
Salman Marvasti Sharif University of Technology Winter 2015.
Object-Oriented Programming Chapter Chapter
 Objects versus Class  Three main concepts of OOP ◦ Encapsulation ◦ Inheritance ◦ Polymorphism  Method ◦ Parameterized ◦ Value-Returning.
ISBN Object-Oriented Programming Chapter Chapter
Data Design and Implementation. Definitions Atomic or primitive type A data type whose elements are single, non-decomposable data items Composite type.
Introduction to OOP CPS235: Introduction.
Java Programming, Second Edition Chapter Twelve Advanced Inheritance Concepts.
1 n Object Oriented Programming. 2 Introduction n procedure-oriented programming consists of writing a list of instructions and organizing these instructions.
CSCI-383 Object-Oriented Programming & Design Lecture 17.
Sadegh Aliakbary Sharif University of Technology Fall 2010.
ISBN Chapter 12 Support for Object-Oriented Programming.
Introduction to Objects Abstraction:The object-oriented approach Everything is an object. A program is a bunch of objects telling each other.
Class Inheritance Part II: Overriding and Polymorphism Corresponds with Chapter 10.
Applications Active Web Documents Active Web Documents.
Inheritance Modern object-oriented (OO) programming languages provide 3 capabilities: encapsulation inheritance polymorphism which can improve the design,
Modern Programming Tools And Techniques-I
Visit for more Learning Resources
Jim Fawcett CSE681 – SW Modeling & Analysis Fall 2014
Object-Oriented Analysis and Design
Object-Oriented Programming (OOP) Lecture No. 45
Inheritance and Polymorphism
Unit-2 Objects and Classes
Polymorphism.
INTRODUCTION TO OBJECT-ORIENTED PROGRAMMING (OOP) & CONCEPTS
Interfaces and Inheritance
Lecture 23 Polymorphism Richard Gesick.
Ada – 1983 History’s largest design effort
Packages and Interfaces
Week 6 Object-Oriented Programming (2): Polymorphism
Advanced Programming Behnam Hatami Fall 2017.
More Object-Oriented Programming
Polymorphism Professor Hugh C. Lauer CS-2303, System Programming Concepts (Slides include materials from The C Programming Language, 2nd edition, by Kernighan.
Support for Object-Oriented Programming
Introduction to Data Structure
Java History, Editions, Version Features
CIS 199 Final Review.
Introducing Java.
Polymorphism 2019/4/29.
Object-Oriented Programming
Lecture 10 Concepts of Programming Languages
CMSC 202 Exceptions.
Lecture 6: Polymorphism
Presentation transcript:

JAVA Introduction ការណែនាំពី Java One of the main JAVA design goal is reducing complexity for programmer Development time is half or less comparing to equivalent C++ programs Language support for multi-threading and network programming Cross-platform programs, dynamic code change, security Java programs run in a Virtual Machine environment Programs are compiled to an intermediate form Intermediate code is run by VM

Introduction to Object Orientation Why OO? What is wrong with non OO programming languages like C? Is it really needed to learn OO? What are the differences of making a program using OO than non OO way? Orientation=ការតំរង់ទិស

Progress of abstraction Programming languages makes abstractions Assembly language is abstraction of the machine language Fortran, Basic, C and many others were abstractions for assembly language The above languages makes abstractions for machines They don't provide abstraction of problem space Object orientation Provides abstractions of problem space Elements of problem space are represented as Objects

Object? Characteristic of Smalltalk by Alan Kay Booch: Everything is an object A program is a bunch of objects telling each other what to do by sending messages Each object has its own memory made up of other objects Every object has a type (what messages can send to it?) All object of a particular type can receive the same messages Booch: An object has state, behavior and identity

An object has interface A Type or Class of an object Describes a set of objects with identical characteristics (data elements) and behaviors (functionality) Light lt = new Light(); lt.on();

Objects as service providers A program is a set of objects that provide services to other objects Program design then is a process of finding or creating objects that solve the problem Service provider view helps making High Cohesive objects This view also helps others understand program Cohesive=ស្អិតរមួត

Hidden implementation Regarding an object we can distinguish two roles: Creator of the object: wants to expose only what is necessary for the client programmer Users of the object (client programmer): Only wants to know what an object does for him/her Enforce client programmers to not access those parts of an object that they should not Makes it possible to change internal structure of an object without worrying of effects on clients Java uses public, private and protected for these access controls

Reusing the implementation Code reuse is one of the main advantages that OO languages provide One way of reusing an object is to place it inside another object: Creating a member object (composition)

Inheritance: Reusing the interface Creating a class based on a similar already implemented class

Inheritance: Reusing the interface With inheritance you create a new type The new type includes all the members of base type It also has same interface of base type If we inherit a new class from a base class and don't implement methods, then methods have same behavior as base class Differentiating between derived class and base class: Adding new methods to the derived class Overriding existing methods

Inheritance: Reusing the interface បដិសេធវិធីសាស្រ្តដែលមានស្រាប់ បដិសេធវិធីសាស្រ្តដែលមានស្រាប់ Inheritance: Reusing the interface Overriding existing methods IS-A relationship

Inheritance: Reusing the interface Adding new methods IS-LIKE-A relationship

Interchangeable objects with polymorphism Sometimes it is much convenient to treat objects in a type hierarchy all as base class objects It allows to write code that does not depend on the specific type of objects: For all shape object O { o.draw(); } But what happens when one shape object is actually a circle or a triangle or a square? The key is late binding: runtime binding

Interchangeable objects with polymorphism Suppose we have: void doStuff(Shape s) { s.erase(); // ... s.draw(); } and we have: Circle circle = new Circle(); Triangle t = new Triangle(); dostuff(c); dostuff(t);

Interchangeable objects with polymorphism Calls to dostuff works correctly. At runtime draw() and erase() methods of correct object is called. The process of treating a derived type as a base type is called upcasting

Abstract base class and interfaces Often it is needed that base class only represent a common interface for its derived classes. One main usage is for upcasting. This is done by making the class abstract. An abstract class can't be instantiated It is also possible to have an abstract method (which means it is not implemented yet) Interface is like abstract class, but in interface there is no method definition at all One of the big differences between C++ and Java is that C++ doesn't have interface concept, and Java does not have multiple inheritance

Object creation, use and lifetimes Technically OOP is just about abstract data typing, inheritance and polymorphism. But some other issues are also important in writing OO programs. One important issue is object lifetime: C++ approach: Programmer controls memory allocation and disposal Memory leaks is a major headache for programmers Java approach: System controls memory allocation and disposal. Garbage collector takes care of removing objects that are no longer in use. Programmers are not worrying about memory leaks

Containers In many useful programs it is needed to store a collection of objects. The number of objects are not known at the program development time Every OO language has facilities to store collection of objects Java has several different type of Lists, Maps and Sets used as containers Containers provides methods to: Put elements in Get elements out

Iterators One of the standard ways to traverse all elements of a container is by the use of iterators An iterator hides the details of a container from the code that is accessing that container An iterator provides a SEQUENCE view of container It does not matter if the container is a ArrayList, LinkedList or Stack. An iterator provides a sequence access to the elements of the container So it is possible to change a data structure (if needed) without disturbing the client's code

The singly rooted hierarchy Java has a single rooted base class which is named Object All objects inherits from Object class Therefore all the Objects share a common interface One usage is toString() method, which all the objects inherits from Object class Another usage is for garbage collection

Downcasting vs. templates/generics Containers in Java stores and retreive objects of type Objects.When adding a object to a container it is upcasted to Object. When retrieving an object from container it is of type Object and normally is casted again but down the hierarchy to a specific type. This is named downcasting But you should know the exact type of the object for downcasting Another approach is what is in C++. It is named templates. When creating a container we specify the type of objects that is stored there. Next version of Java supports this with the name generics

Object clean up and garbage collector Java keeps track of object references and if all references to an objects is deleted, garbage collector delete the object from memory In C++ there is no garbage collector. The Java way is much convenient for programmers But for some application areas (like real time systems), CPU time wasted by garbage collector is not acceptable

Exception handling Exceptions are thrown when an error occurs Exceptions can be caught by an exception handler It simplifies writing programs by enabling to treat exception as alternative path to normal program execution Exceptions provides some mechanism to reliably recover from a bad situation Java provides a solid exception handling that forces the programmers to write code to handle exceptions Exceptions are a kind of object in Java

Concurrency (multi-threading) Java simplifies writing multi-threading programs It shares CPU time between threads However, shared resources should be managed by programmers Synchronized keyword is used for controlling access shared resources

Persistence Normally when a program terminates, all objects are destroyed Sometime it is needed to have objects even after program terminates Java provides a way to store and retrieve objects on non-volatile memory. This is named Serialization in Java

Java and the internet Web? Client-Server programming. Client-side programming: HTML, Javascript, Plug-ins, Java applets Server-side programming: CGI, Java web applications, .Net and C# Java applications: Standalone applications, Server-side applications, client-side applets