Java Programming: Interfaces and Packages Vyacheslav Grebenyuk CTDE, AI dept., KhNURE.

Slides:



Advertisements
Similar presentations
Abstract Class, Packages and interface from Chapter 9
Advertisements

Creating Vector Graphics in the Web Learning & Development Telerik Software Academy.
Object Oriented Programming
Telerik Software Academy ASP.NET MVC.
Java™ How to Program, 9/e © Copyright by Pearson Education, Inc. All Rights Reserved.
Java™ How to Program, 9/e Presented by: Dr. José M. Reyes Álamo © Copyright by Pearson Education, Inc. All Rights Reserved.
Judul Mata Kuliah Judul Pokok Bahasan 1/total Memory Interface.
Inheritance Inheritance Reserved word protected Reserved word super
9. Inheritance 9.1 Subclasses 9.2 Polymorphism 9.3 Abstract Classes 9.4 Modifiers and Access 9.6 Object-Oriented Design with Use Cases and Scenarios.
Programming with Java © 2002 The McGraw-Hill Companies, Inc. All rights reserved. 1 Chapter 12 More OOP, Interfaces, and Inner Classes.
EEC-681/781 Distributed Computing Systems Java Tutorial Wenbing Zhao Cleveland State University
Java Programming Chapter 3 More about classes. Why?  To make classes easier to find and to use  to avoid naming conflicts  to control access  programmers.
1 Lecture 2 Java Packages  What are Java packages?  Why do wee need packages?  How to create a Java package?  Some examples.
June 1, 2000 Object Oriented Programming in Java (95-707) Java Language Basics 1 Lecture 3 Object Oriented Programming in Java Language Basics Classes,
UML Class Diagram: class Rectangle
Unit 051 Packages What is a Package? Why use Packages? Creating a Package Naming a Package Using Package Members Managing Source and Class Files Visibility.
8.1 Classes & Inheritance Inheritance Objects are created to model ‘things’ Sometimes, ‘things’ may be different, but still have many attributes.
9/4/2015Abstract classes & Interface1 Object Oriented Design and Programming II Chapter 10 Abstract classes and Interfaces.
Telerik Software Academy ASP.NET MVC.
Design Patterns that ease the design by identifying a simple way to realize relationships between entities. Antony Jekov Telerik Software Academy academy.telerik.com.
Packages F Package is a container for classes F A package is a grouping of related types (classes and interfaces) providing access protection and name.
Telerik Software Academy ASP.NET Web Forms.
What is C++, Features, IDEs
Telerik Software Academy Mobile apps for iPhone & iPad.
1 Chapter 8 – Classes and Object: A Deeper Look Outline 1 Introduction 2 Implementing a Time Abstract Data Type with a Class 3 Class Scope 4 Controlling.
Learning & Development Team Telerik Software Academy.
What are WinJS and WinRT, Using the APIs in JavaScript George Georgiev Telerik Software Academy academy.telerik.com Technical Trainer itgeorge.net.
The True power of dynamic web pages Learning & Development Team Telerik Software Academy.
Summing Up Object Oriented Design. Four Major Components: Abstraction modeling real-life entities by essential information only Encapsulation clustering.
Even More Java. Java Packages What is a package? Definition: A package is a grouping of related types providing access protection and name space management.
Introduction to Java Chapter 7 - Classes & Object-oriented Programming1 Chapter 7 Classes and Object-Oriented Programming.
Inheritance. Inheritance - Introduction Idea behind is to create new classes that are built on existing classes – you reuse the methods and fields and.
Inheritance CSCE 190 – Java Instructor: Joel Gompert Mon, August 2, 2004.
Ivaylo Kenov Telerik Software Academy Technical Assistant.
Packages. Creating and Using Packages To make types easier to find and use, to avoid naming conflicts, and to control access, programmers bundle groups.
2 Interfaces and Packages 3 What is an Interface? An interface defines a protocol of behavior that can be implemented by any class anywhere in the class.
Telerik School Academy Xamarin apps for iOS, Android & WinPhone.
The way of the ViewModel and the Binding Learning & Development Telerik School Academy.
Chapter 11: Advanced Inheritance Concepts. Objectives Create and use abstract classes Use dynamic method binding Create arrays of subclass objects Use.
Programming in java Packages Access Protection Importing packages Java program structure Interfaces Why interface Defining interface Accessing impln thru.
Access Specifier. Anything declared public can be accessed from anywhere. Anything declared private cannot be seen outside of its class. When a member.
In JavaScript Learning & Development Telerik Software Academy.
Fall 2015CISC/CMPE320 - Prof. McLeod1 CISC/CMPE320 Assignment 3 is due Sunday, the 8 th at 7pm. Problems with assn 3? Discuss at your team meeting tonight.
Object orientation and Packaging in Java Object Orientation and Packaging Introduction: After completing this chapter, you will be able to identify.
UNIT-3 Interfaces & Packages. What is an Interface? An interface is similar to an abstract class with the following exceptions: All methods defined in.
Splitting JavaScript into Dependent Modules Learning & Development Telerik Software Academy.
What to expect from the new IDE Telerik Academy Plus Visual Studio 2015 and ASP.NET 5.
Any fool can write code that a computer can understand. Good programmers write code that humans can understand. Telerik Software Academy
Serving HTTP requests Learning & Development Telerik School Academy.
SaaS Cloud Platform Providing Database Access Through RESTful API Learning & Development Telerik Software Academy.
Java Packages  What are Java packages?  Why do we need packages?  How to create a Java package?  Some examples.  Coming Next: Program Documentation.
Shared Application Telerik School Academy Xamarin apps for iOS, Android & WinPhone.
Object Based Programming Chapter 8. 2 Contrast ____________________ Languages –Action oriented –Concentrate on writing ________________ –Data supports.
 It is a pure oops language and a high level language.  It was developed at sun microsystems by James Gosling.
Server Roles and Features Borislav Varadinov Telerik Software Academy academy.telerik.com System Administrator
Java Programming: Creating a GUI with JFC/Swing Vyacheslav Grebenyuk CTDE, AI dept., KhNURE.
Java Programming: JDBC Vyacheslav Grebenyuk CTDE, AI dept., KhNURE.
SCJP 5, 1/7 Declarations, Initialization and Scoping
Chapter 15 Abstract Classes and Interfaces
Software Construction
Topic: Java Security Models
UML Class Diagram: class Rectangle
Android Programming Lecture 2
Packages Written part of final exam Alex Rudniy
Interface.
Packages and Interfaces
Package & Java Access Specifiers
Interfaces.
Inner Classes.
Presentation transcript:

Java Programming: Interfaces and Packages Vyacheslav Grebenyuk CTDE, AI dept., KhNURE

(С) ЦТДО, каф. Искусственного интеллекта, ХНУРЭ, Content Creating and Using Interfaces Creating and Using Packages

(С) ЦТДО, каф. Искусственного интеллекта, ХНУРЭ, What is interface An interface defines a protocol of behavior that can be implemented by any class anywhere in the class hierarchy it also defines a set of methods but does not implement them A class that implements the interface agrees to implement all the methods defined in the interface Definition: An interface is a named collection of method definitions, without implementations.

(С) ЦТДО, каф. Искусственного интеллекта, ХНУРЭ, How an interface differs from an abstract class An interface cannot implement any methods, whereas an abstract class can A class can implement many interfaces but can have only one superclass An interface is not part of the class hierarchy Unrelated classes can implement the same interface

(С) ЦТДО, каф. Искусственного интеллекта, ХНУРЭ, Defining an Interface The Interface Declaration

(С) ЦТДО, каф. Искусственного интеллекта, ХНУРЭ, The Interface Body contains method declarations for all the methods included in the interface All methods declared in an interface are implicitly public and abstract An interface can contain constant declarations in addition to method declarations ( public, static, and final )

(С) ЦТДО, каф. Искусственного интеллекта, ХНУРЭ, Implementing an Interface By Convention: The implements clause follows the extends clause, if it exists public class StockApplet extends Applet implements StockWatcher {

(С) ЦТДО, каф. Искусственного интеллекта, ХНУРЭ, Using an Interface as a Type public class StockMonitor { public void watchStock(StockWatcher watcher, TickerSymbol tickerSymbol, BigDecimal delta) {... }

(С) ЦТДО, каф. Искусственного интеллекта, ХНУРЭ, Warning! Interfaces Cannot Grow public interface StockWatcher { void valueChanged(TickerSymbol tickerSymbol, BigDecimal newValue); void currentValue(TickerSymbol tickerSymbol, BigDecimal newValue); } Instead do next: public interface StockTracker extends StockWatcher { void currentValue(TickerSymbol tickerSymbol, BigDecimal newValue); }

(С) ЦТДО, каф. Искусственного интеллекта, ХНУРЭ, Creating and Using Packages To make types easier to find and use, to avoid naming conflicts, and to control access, programmers bundle groups of related types into packages Definition: A package is a collection of related types providing access protection and name space management. Note that types refers to classes, interfaces, enums, and annotations

(С) ЦТДО, каф. Искусственного интеллекта, ХНУРЭ, Imaginable application //in the Graphic.java file public abstract class Graphic {... } //in the Circle.java file public class Circle extends Graphic implements Draggable {... } //in the Rectangle.java file public class Rectangle extends Graphic implements Draggable {... } //in the Draggable.java file public interface Draggable {... }

(С) ЦТДО, каф. Искусственного интеллекта, ХНУРЭ, Reasons for bundling classes in a package You and other programmers can easily determine that these types are related You and other programmers know where to find types that can provide graphics-related functions The names of your types won't conflict with the type names in other packages because the package creates a new namespace You can allow types within the package to have unrestricted access to one another yet still restrict access for types outside the package

(С) ЦТДО, каф. Искусственного интеллекта, ХНУРЭ, Creating a Package To create a package, put a type (class, interface, enum, or annotation) in it To do this, put a package statement at the top of the source file in which the type is defined Remember! Only public package members are accessible from outside of the package

(С) ЦТДО, каф. Искусственного интеллекта, ХНУРЭ, Naming a Package By Convention: Companies use their reversed Internet domain name in their package names (for example, com.company.package). Name collisions that occur within a single company need to be handled by convention within that company, perhaps by including the region or the project name after the company name (for example, com.company.region.package)

(С) ЦТДО, каф. Искусственного интеллекта, ХНУРЭ, Naming a Package Domain namePackage name clipart-open.orgorg.clipart_open free.fonts.intint_.fonts.free poetry.7days.comcom._7days.poetry

(С) ЦТДО, каф. Искусственного интеллекта, ХНУРЭ, Using Package Members Refer to the member by its long (qualified) name Import the package member Import the member's entire package

(С) ЦТДО, каф. Искусственного интеллекта, ХНУРЭ, Managing Source and Class Files class name graphics.Rectangle pathname to file graphics\Rectangle.java

(С) ЦТДО, каф. Искусственного интеллекта, ХНУРЭ, Classes files Like a.java file, a.class file should also be in a series of directories that reflect the package name However, it does not have to be in the same directory as its source

(С) ЦТДО, каф. Искусственного интеллекта, ХНУРЭ, Class path Both the compiler and the JVM search for classes in each directory or JAR file listed in your class path Definition: A class path is an ordered list of directories or JAR files in which to search for class files.