1 / 21

Программирование на Java: Концепция ООП

Программирование на Java: Концепция ООП. Вячеслав Гребенюк ЦТДО, каф. ИИ, ХНУРЭ. Content. intro. what an object is what a class is how objects and classes are related how objects communicate by using messages. What Is an Object?. Everything around you are objects

urbain
Download Presentation

Программирование на 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. Программирование на Java: Концепция ООП Вячеслав Гребенюк ЦТДО, каф. ИИ, ХНУРЭ

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

  3. intro • what an object is • what a class is • how objects and classes are related • how objects communicate by using messages (С) ЦТДО, каф. Искусственного интеллекта, ХНУРЭ, 2006

  4. What Is an Object? • Everything around you are objects • Real-world objects share two characteristics: state and behavior • Software objects: variable and method Definition: An object is a software bundle of variables and related methods. (С) ЦТДО, каф. Искусственного интеллекта, ХНУРЭ, 2006

  5. What Is an Object? (С) ЦТДО, каф. Искусственного интеллекта, ХНУРЭ, 2006

  6. First principle of OOP • Encapsulation – packaging an object's variables within the protective custody of its methods • Two major benefits to software developers: • Modularity • Information-hiding (С) ЦТДО, каф. Искусственного интеллекта, ХНУРЭ, 2006

  7. What Is a Message? (С) ЦТДО, каф. Искусственного интеллекта, ХНУРЭ, 2006

  8. Two important benefits of messages • An object's behavior is expressed through its methods, so (aside from direct variable access) message passing supports all possible interactions between objects. • Objects don't need to be in the same process or even on the same machine to send messages back and forth and receive messages from each other. (С) ЦТДО, каф. Искусственного интеллекта, ХНУРЭ, 2006

  9. What Is a Class? • Object is an instance of the class of objects • A software blueprint for objects is called a class Definition: A class is a blueprint that defines the variables and the methods common to all objects of a certain kind. (С) ЦТДО, каф. Искусственного интеллекта, ХНУРЭ, 2006

  10. The bicycle class (С) ЦТДО, каф. Искусственного интеллекта, ХНУРЭ, 2006

  11. Class variable and methods (С) ЦТДО, каф. Искусственного интеллекта, ХНУРЭ, 2006

  12. What Is Inheritance? (С) ЦТДО, каф. Искусственного интеллекта, ХНУРЭ, 2006

  13. What Is Inheritance? • Superclass • Subclasses • Inherits • Override • Class hierarchy • The Object class is at the top of class hierarchy (С) ЦТДО, каф. Искусственного интеллекта, ХНУРЭ, 2006

  14. Benefits of inheritance • Reuse the code in the superclass many times • Abstract classes that define common behaviors (С) ЦТДО, каф. Искусственного интеллекта, ХНУРЭ, 2006

  15. What Is an Interface? • Interface is a type • Like a class, an interface defines methods • Unlike a class, an interface never implements methods • Classes that implement the interface implement the methods defined by its • A class can implement multiple interfaces (С) ЦТДО, каф. Искусственного интеллекта, ХНУРЭ, 2006

  16. Language Basics • public class BasicsDemo { public static void main(String[] args) { int sum = 0; for (int current = 1; current <= 10; current++) { sum += current; } System.out.println("Sum = " + sum); }} (С) ЦТДО, каф. Искусственного интеллекта, ХНУРЭ, 2006

  17. Variables • Definition: A variable is an item of data named by an identifier • Variable declaration:type name; (С) ЦТДО, каф. Искусственного интеллекта, ХНУРЭ, 2006

  18. Variables example • public class MaxVariablesDemo { public static void main(String args[]) { //integers byte largestByte = Byte.MAX_VALUE; short largestShort = Short.MAX_VALUE; int largestInteger = Integer.MAX_VALUE; long largestLong = Long.MAX_VALUE; //real numbers float largestFloat = Float.MAX_VALUE; double largestDouble = Double.MAX_VALUE; //other primitive types char aChar = 'S'; boolean aBoolean = true; • //Display them all. System.out.println("The largest byte value is “+ largestByte + "."); System.out.println("The largest short value is “+ largestShort + "."); (С) ЦТДО, каф. Искусственного интеллекта, ХНУРЭ, 2006

  19. Variables example cont. • System.out.println("The largest integer value is “ + largestInteger + "."); System.out.println("The largest long value is “ + largestLong + "."); System.out.println("The largest float value is “ + largestFloat + "."); System.out.println("The largest double value is “ + largestDouble + "."); if (Character.isUpperCase(aChar)) { System.out.println("The character " + aChar + " is uppercase."); } else { System.out.println("The character " + aChar + " is lowercase."); } System.out.println("The value of aBoolean is “ + aBoolean + "."); }} (С) ЦТДО, каф. Искусственного интеллекта, ХНУРЭ, 2006

  20. Variables example results • The largest byte value is 127. • The largest short value is 32767. • The largest integer value is 2147483647. • The largest long value is 9223372036854775807. • The largest float value is 3.4028235E38. • The largest double value is 1.7976931348623157E308. • The character S is uppercase. • The value of aBoolean is true. (С) ЦТДО, каф. Искусственного интеллекта, ХНУРЭ, 2006

  21. More about variables • Data Types • Variable Names • Scope • Variable Initialization • Final Variables (С) ЦТДО, каф. Искусственного интеллекта, ХНУРЭ, 2006

More Related