🗊Презентация 4. Java OOP. 5. Abstract Classes

Нажмите для полного просмотра!
4. Java OOP. 5. Abstract Classes, слайд №14. Java OOP. 5. Abstract Classes, слайд №24. Java OOP. 5. Abstract Classes, слайд №34. Java OOP. 5. Abstract Classes, слайд №44. Java OOP. 5. Abstract Classes, слайд №54. Java OOP. 5. Abstract Classes, слайд №64. Java OOP. 5. Abstract Classes, слайд №74. Java OOP. 5. Abstract Classes, слайд №84. Java OOP. 5. Abstract Classes, слайд №94. Java OOP. 5. Abstract Classes, слайд №104. Java OOP. 5. Abstract Classes, слайд №114. Java OOP. 5. Abstract Classes, слайд №124. Java OOP. 5. Abstract Classes, слайд №134. Java OOP. 5. Abstract Classes, слайд №144. Java OOP. 5. Abstract Classes, слайд №154. Java OOP. 5. Abstract Classes, слайд №164. Java OOP. 5. Abstract Classes, слайд №174. Java OOP. 5. Abstract Classes, слайд №184. Java OOP. 5. Abstract Classes, слайд №194. Java OOP. 5. Abstract Classes, слайд №204. Java OOP. 5. Abstract Classes, слайд №214. Java OOP. 5. Abstract Classes, слайд №224. Java OOP. 5. Abstract Classes, слайд №234. Java OOP. 5. Abstract Classes, слайд №244. Java OOP. 5. Abstract Classes, слайд №254. Java OOP. 5. Abstract Classes, слайд №264. Java OOP. 5. Abstract Classes, слайд №274. Java OOP. 5. Abstract Classes, слайд №284. Java OOP. 5. Abstract Classes, слайд №294. Java OOP. 5. Abstract Classes, слайд №304. Java OOP. 5. Abstract Classes, слайд №314. Java OOP. 5. Abstract Classes, слайд №32

Содержание

Вы можете ознакомиться и скачать презентацию на тему 4. Java OOP. 5. Abstract Classes. Доклад-сообщение содержит 32 слайдов. Презентации для любого класса можно скачать бесплатно. Если материал и наш сайт презентаций Mypresentation Вам понравились – поделитесь им с друзьями с помощью социальных кнопок и добавьте в закладки в своем браузере.

Слайды и текст этой презентации


Слайд 1





4. Java OOP 
5. Abstract Classes. Interfaces
Описание слайда:
4. Java OOP 5. Abstract Classes. Interfaces

Слайд 2





Abstract Classes
An abstract class is a class that is declared abstract
Abstract classes cannot be instantiated, but they can be subclassed
Описание слайда:
Abstract Classes An abstract class is a class that is declared abstract Abstract classes cannot be instantiated, but they can be subclassed

Слайд 3





Abstract Methods 
An abstract method is a method that is declared without an implementation:
abstract void moveTo(double deltaX, double deltaY); 
If a class includes abstract methods, the class itself must be declared abstract
Описание слайда:
Abstract Methods An abstract method is a method that is declared without an implementation: abstract void moveTo(double deltaX, double deltaY); If a class includes abstract methods, the class itself must be declared abstract

Слайд 4





An Abstract Classes II
A subclass of an abstract class usually provides implementations for all of the abstract methods in its parent class
If it does not, the subclass must also be declared abstract
Abstract classes can contain fields and implemented methods (partial implementation)
An abstract class may have static fields and static methods. You can use these static members with a class reference as you would with any other class
Описание слайда:
An Abstract Classes II A subclass of an abstract class usually provides implementations for all of the abstract methods in its parent class If it does not, the subclass must also be declared abstract Abstract classes can contain fields and implemented methods (partial implementation) An abstract class may have static fields and static methods. You can use these static members with a class reference as you would with any other class

Слайд 5





Example: Abstract DepoBase Class
Modify 442InterestSum project using DepoBase as an abstract class.
Описание слайда:
Example: Abstract DepoBase Class Modify 442InterestSum project using DepoBase as an abstract class.

Слайд 6





Example: Abstract DepoBase Class
See 451AbstractDepo project for the full text
Описание слайда:
Example: Abstract DepoBase Class See 451AbstractDepo project for the full text

Слайд 7





How to Create and Use Library
To create depo library:
Right click on the app package -> Export -> Java -> JAR file -> Next
JAR file = depo.jar
Finish 
How you can use depo.jar library:
Create new project 451aAbstractDepo
Right click on the project name -> Build Path 
   -> Configure Build Path
Go to Library tab -> Add External JARs -> find and click on depo.jar -> Open -> Ok
Описание слайда:
How to Create and Use Library To create depo library: Right click on the app package -> Export -> Java -> JAR file -> Next JAR file = depo.jar Finish How you can use depo.jar library: Create new project 451aAbstractDepo Right click on the project name -> Build Path -> Configure Build Path Go to Library tab -> Add External JARs -> find and click on depo.jar -> Open -> Ok

Слайд 8





Interfaces
An interface is a reference type, similar to a class, that can contain only constants, method signatures, and nested types
There are no method bodies
Interfaces cannot be instantiated—they can only be implemented by classes or extended by other interfaces
Описание слайда:
Interfaces An interface is a reference type, similar to a class, that can contain only constants, method signatures, and nested types There are no method bodies Interfaces cannot be instantiated—they can only be implemented by classes or extended by other interfaces

Слайд 9





Defining an Interface
An interface declaration consists of: 
modifiers 
the keyword interface 
the interface name 
a comma-separated list of parent interfaces (if any) 
the interface body
An interface can extend any number of interfaces
Описание слайда:
Defining an Interface An interface declaration consists of: modifiers the keyword interface the interface name a comma-separated list of parent interfaces (if any) the interface body An interface can extend any number of interfaces

Слайд 10





Interface Definition Example
public interface GroupedInterface extends
	 Interface1, Interface2, Interface3 {    
		 // constant declarations    
		double E = 2.718282;     
		// method signatures    
	void doSomething (int i, double x);    
		int doSomethingElse(String s);
}
Описание слайда:
Interface Definition Example public interface GroupedInterface extends Interface1, Interface2, Interface3 {  // constant declarations double E = 2.718282; // method signatures void doSomething (int i, double x); int doSomethingElse(String s); }

Слайд 11





The Interface Body
The interface body contains method declarations for all the methods included in the interface
A method declaration within an interface is followed by a semicolon, but no braces
All methods declared in an interface are implicitly public
An interface can contain constant declarations in addition to method declarations
All constant values defined in an interface are implicitly public, static, and final
Описание слайда:
The Interface Body The interface body contains method declarations for all the methods included in the interface A method declaration within an interface is followed by a semicolon, but no braces All methods declared in an interface are implicitly public An interface can contain constant declarations in addition to method declarations All constant values defined in an interface are implicitly public, static, and final

Слайд 12





Use an Interface
To use an interface, you write a class that implements the interface
When an instantiable class implements an interface, it provides a method body for each of the methods declared in the interface
public class OperateBMW760i implements GroupedInterface { 
 . . . . 
}
Описание слайда:
Use an Interface To use an interface, you write a class that implements the interface When an instantiable class implements an interface, it provides a method body for each of the methods declared in the interface public class OperateBMW760i implements GroupedInterface {  . . . . }

Слайд 13





Interfaces and Multiple Inheritance
In Java, a class can inherit from only one class but it can implement more than one interface
This means that if a variable is declared to be the type of an interface, its value can reference any object that is instantiated from any class that implements the interface
Описание слайда:
Interfaces and Multiple Inheritance In Java, a class can inherit from only one class but it can implement more than one interface This means that if a variable is declared to be the type of an interface, its value can reference any object that is instantiated from any class that implements the interface

Слайд 14





Using an Interface as a Type
You can use interface names anywhere you can use any other data type name
If you define a reference variable whose type is an interface, any object you assign to it must be an instance of a class that implements the interface
Описание слайда:
Using an Interface as a Type You can use interface names anywhere you can use any other data type name If you define a reference variable whose type is an interface, any object you assign to it must be an instance of a class that implements the interface

Слайд 15





Exercise: InterestInterface
Modify 442InterestSum project using interface
Описание слайда:
Exercise: InterestInterface Modify 442InterestSum project using interface

Слайд 16





Exercise: InterestInterface
See 452InterfaceDepo project for the full text
Описание слайда:
Exercise: InterestInterface See 452InterfaceDepo project for the full text

Слайд 17





Cloning (1 of 2)
Use clone() method to get independent object instead of object’s assignment
clone() method can make only a field-by-
	field copy
Cloning is correct if a class contains only primitive fields or references to immutable objects
“Deep” cloning is necessary otherwise
Описание слайда:
Cloning (1 of 2) Use clone() method to get independent object instead of object’s assignment clone() method can make only a field-by- field copy Cloning is correct if a class contains only primitive fields or references to immutable objects “Deep” cloning is necessary otherwise

Слайд 18





Cloning (2 of 2)
The clone method is a protected method of Object, which means that your code cannot simply call it
To make clone method accessible a class must:
Implement the Cloneable interface
Redefine the clone method with the public access modifier.
Описание слайда:
Cloning (2 of 2) The clone method is a protected method of Object, which means that your code cannot simply call it To make clone method accessible a class must: Implement the Cloneable interface Redefine the clone method with the public access modifier.

Слайд 19





Deep Cloning
To make a deep copy, you have clone the mutable instance fields in the redefined clone method
Описание слайда:
Deep Cloning To make a deep copy, you have clone the mutable instance fields in the redefined clone method

Слайд 20





Example: DepoBase Cloning
public abstract class DepoBase implements Cloneable{
   .   .   .   .   .   .
	public DepoBase clone() throws 				CloneNotSupportedException{
		DepoBase cln = (DepoBase)super.clone();
		cln.startDate = (Date)startDate.clone();
		return cln;
	}
   .   .   .   .   .   .
}
Описание слайда:
Example: DepoBase Cloning public abstract class DepoBase implements Cloneable{ . . . . . . public DepoBase clone() throws CloneNotSupportedException{ DepoBase cln = (DepoBase)super.clone(); cln.startDate = (Date)startDate.clone(); return cln; } . . . . . . }

Слайд 21





Interfaces in Java SE 8
The interface body can contain:
abstract methods (followed by a semicolon, but no braces – it does not contain an implementation
default methods (are defined with the default modifier)
static methods (with the static keyword)
constant declarations
Описание слайда:
Interfaces in Java SE 8 The interface body can contain: abstract methods (followed by a semicolon, but no braces – it does not contain an implementation default methods (are defined with the default modifier) static methods (with the static keyword) constant declarations

Слайд 22





Interface Default Methods
You specify that a method definition in an interface is a default method with the default keyword at the beginning of the method signature 
Default method defines a default implementation 
Default methods enable you to add new functionality to the interfaces of your libraries and ensure binary compatibility with code written for older versions of those interfaces 
Any class that implements the interface with default method will have this method already defined
Описание слайда:
Interface Default Methods You specify that a method definition in an interface is a default method with the default keyword at the beginning of the method signature Default method defines a default implementation Default methods enable you to add new functionality to the interfaces of your libraries and ensure binary compatibility with code written for older versions of those interfaces Any class that implements the interface with default method will have this method already defined

Слайд 23





Exercise: Default Method
Modify 452InterfaceDepo project:
Remove abstract DepoBase class
Add calculateInterest method as default method of the InterestInterface
Описание слайда:
Exercise: Default Method Modify 452InterfaceDepo project: Remove abstract DepoBase class Add calculateInterest method as default method of the InterestInterface

Слайд 24





Exercise: Default Method
See 453DefaultMethod project for the full text
Описание слайда:
Exercise: Default Method See 453DefaultMethod project for the full text

Слайд 25





Functional Interfaces
A functional interface is any interface that contains only one abstract method 
A functional interface may contain one or more default methods or static methods
The abstract method of a functional interface can be implemented with help of lambda expression
Описание слайда:
Functional Interfaces A functional interface is any interface that contains only one abstract method A functional interface may contain one or more default methods or static methods The abstract method of a functional interface can be implemented with help of lambda expression

Слайд 26





Lambda Expression
A lambda expression looks a lot like a method declaration
You can consider lambda expressions as anonymous methods—methods without a name
Описание слайда:
Lambda Expression A lambda expression looks a lot like a method declaration You can consider lambda expressions as anonymous methods—methods without a name

Слайд 27





Example of Lambda Expression I
public class Calculator { 
	interface IntegerMath { 
		int operation(int a, int b); 
	} 
	public int operateBinary(int a, int b, 			IntegerMath op) { 
		return op.operation(a, b); 
	}
Описание слайда:
Example of Lambda Expression I public class Calculator { interface IntegerMath { int operation(int a, int b); } public int operateBinary(int a, int b, IntegerMath op) { return op.operation(a, b); }

Слайд 28





Example of Lambda Expression II
   public static void main(String... args) {  
      Calculator myApp = new Calculator();  
      IntegerMath addition = (a, b) -> a + b; 
      IntegerMath subtraction = (a, b) -> a - b;  
      System.out.println("40 + 2 = " + 
         myApp.operateBinary(40, 2, addition)); 
      System.out.println("20 - 10 = " + 
         myApp.operateBinary(20, 10, subtraction)); 
   } 
}
Описание слайда:
Example of Lambda Expression II public static void main(String... args) { Calculator myApp = new Calculator(); IntegerMath addition = (a, b) -> a + b; IntegerMath subtraction = (a, b) -> a - b; System.out.println("40 + 2 = " + myApp.operateBinary(40, 2, addition)); System.out.println("20 - 10 = " + myApp.operateBinary(20, 10, subtraction)); } }

Слайд 29





Example of Lambda Expression
See 454LambdaCalulator for the full text
Описание слайда:
Example of Lambda Expression See 454LambdaCalulator for the full text

Слайд 30





Lambda Expression Syntax I
A lambda expression consists of the following: 
a comma-separated list of formal parameters enclosed in parentheses
the arrow token, ->
a body, which consists of a single expression or a statement block
Описание слайда:
Lambda Expression Syntax I A lambda expression consists of the following: a comma-separated list of formal parameters enclosed in parentheses the arrow token, -> a body, which consists of a single expression or a statement block

Слайд 31





Lambda Expression Syntax II
You can omit the data type of the parameters in a lambda expression 
You can omit the parentheses if there is only one parameter 
If you specify a single expression, then the Java runtime evaluates the expression and then returns its value
Alternatively, you must enclose statements in braces {}
Описание слайда:
Lambda Expression Syntax II You can omit the data type of the parameters in a lambda expression You can omit the parentheses if there is only one parameter If you specify a single expression, then the Java runtime evaluates the expression and then returns its value Alternatively, you must enclose statements in braces {}

Слайд 32





Manuals
http://docs.oracle.com/javase/tutorial/java/IandI/index.html
Описание слайда:
Manuals http://docs.oracle.com/javase/tutorial/java/IandI/index.html



Похожие презентации
Mypresentation.ru
Загрузить презентацию