1 / 25

Advanced Programming in Java

This agenda covers topics such as packages in Java, package hierarchy, famous Java packages, package access, writing a packaged Java project, inheritance in Java, UML class diagrams, and a quiz.

juliane
Télécharger la présentation

Advanced Programming in Java

An Image/Link below is provided (as is) to download presentation Download Policy: Content on the Website is provided to you AS IS for your information and personal use and may not be sold / licensed / shared on other websites without getting consent from its author. Content is provided to you AS IS for your information and personal use only. Download presentation by click this link. While downloading, if for some reason you are not able to download a presentation, the publisher may have deleted the file from their server. During download, if you can't get a presentation, the file might be deleted by the publisher.

E N D

Presentation Transcript


  1. Advanced Programming in Java SadeghAliakbary Sharif University of Technology Fall 2010

  2. Agenda • Packages • Inheritance Sharif University of Technology

  3. Package • A package contains a group of classes • Organized together under a single namespace • Packages organize classes belonging to the same category or providing similar functionality • A package provides a unique namespace for the types it contains • Classes in one package has the same folder • Packages may contain other packages • Hierarchy of packages Sharif University of Technology

  4. Some famous java packages • java.util • java.lang • java.io Sharif University of Technology

  5. Java Packages • import keyword • Class Qualified Name = package-name + class-name • For example • java .lang.String • java.lang.Math • double sqrt = Math.sqrt(123); • java.util.Scanner • java.awt.Event • org.w3c.dom.events.Event Sharif University of Technology

  6. Using packages Sharif University of Technology

  7. java.lang • java.lang is implicitly imported Sharif University of Technology

  8. Package Access • Remember public and private access specifiers • The default access has no keyword • It is commonly referred to as package access • and sometimes friendly • Other classes in the current package have access to that member • To classes outside of this package, the member appears to be private. Sharif University of Technology

  9. Write a packaged java project • Lets write … Sharif University of Technology

  10. Inheritance Sharif University of Technology

  11. Sharif University of Technology

  12. Sharif University of Technology

  13. UML Class Diagram Sharif University of Technology

  14. Sharif University of Technology

  15. Sharif University of Technology

  16. Sharif University of Technology

  17. UML Class Diagram Sharif University of Technology

  18. Inheritance • Java offers inheritance • As any object oriented programming language • Code reuse • extends keyword • is-a relationship Sharif University of Technology

  19. Faculty & Staff • Attributes of staff is inherited to Faculty Sharif University of Technology

  20. Shapes Example • Shape is an abstract class • The definition of some methods should be changed in sub-classes • getArea() • getPerimeter() Sharif University of Technology

  21. Terminology • Class Rectangle is inherited from class Shape • Rectangle is a subclass of Shape • Rectangle is a child of Shape • Rectangle is a derived class of Shape • Shape is the super-class of Rectangle • Shape is the parent of Rectangle • Shape is the base-classof Rectangle • Rectangle is-a Shape Sharif University of Technology

  22. Inheritance in java • Every class is inherited from class Object • Primitive-types are not objects • Object class has some operations • equals() • toString() • … • Every class adds some operations • And changes some operations • toString() Sharif University of Technology

  23. Quiz! Sharif University of Technology

  24. Quiz • Draw a UML class diagram for these Classes • Person (name, phoneNumber) • Student (average, entranceYear) • MS Student (thesis title) • Instructor (offeredCourses) Sharif University of Technology

  25. Sharif University of Technology

More Related