SlideShare une entreprise Scribd logo
1  sur  21
Télécharger pour lire hors ligne
Object	
  Orientated	
  Programming	
  with	
  
                   Java	
  
               Jussi	
  Pohjolainen	
  
   Tampere	
  University	
  of	
  Applied	
  Sciences	
  
Object	
  Orientated	
  Concepts
                                           	
  
•    Class	
  
•    Object	
  
•    Inheritance	
  
•    Constructors	
  
•    Abstract	
  class	
  
•    Interface	
  
•    Polymorphism	
  
Class
                                            	
  
class Student {
   private String name;
   public Student(String name) {
      this.name = name;
   }
   public void setName(String name) {
      this.name = name
   }
   public void getName() {
      return name;
   }
}
CreaAng	
  objects
                                 	
  
Student jack = new Student(“Jack”);
Student bill = new Student(“Bill”);
System.out.println( jack.getName() );
System.out.println( bill.getName() );
Reference?	
  
Student jack = new Student(“Jack”);
Student bill = jack;
jack.setName(“Lisa”);
// What is the output?
System.out.println(bill.getName());
Reference	
  
•  In	
  Java,	
  every	
  object	
  is	
  passed	
  by	
  reference	
  
•  If	
  you	
  want	
  to	
  clone	
  a	
  object,	
  you	
  use	
  special	
  
   techniques	
  (later	
  on	
  the	
  material)	
  
Inheritance	
  
class Person {
   private String name;
  ...
}

class Student extends Person {
   private int id;
   ...
}
Constructors
                                        	
  
class Person {
   private String name;
   public Person() {
     System.out.println(“Person”);
   }
}
class Student extends Person {
   private int id;
   public Student() {
     System.out.println(“Student”);
   }
}
// What is the output?
Student s = new Student();
Default	
  Constructor
                                       	
  
•  If	
  programmer	
  does	
  not	
  define	
  a	
  constructor,	
  Java	
  
   creates	
  a	
  default	
  constructor:	
  
    class Person {
    }
    =>
    class Person {
       public Person() {
         super();
       }
    }
Default	
  Constructor
                                      	
  
class Person {
   private String name;
   public Person() {
    System.out.println(“Person”);
   }
}
class Student extends Person {
   private int id;
}
// What is the output?
Student s = new Student();
Default	
  Constructor	
  Problem	
  
class Person {
   private String name;
   public Person(String name) {
    System.out.println(“Person”);
   }
}
class Student extends Person {
   private int id;
}
// What is the output?
Student s = new Student();
Abstract	
  Class
                                         	
  
•  You	
  cannot	
  create	
  a	
  object	
  from	
  abstract	
  class	
  
•  Abstract	
  class	
  may	
  contain	
  abstract	
  method	
  
•  Abstract	
  method	
  is	
  a	
  method	
  declaraAon	
  which	
  
   must	
  be	
  implemented	
  in	
  inherited	
  classes	
  
Abstract	
  Class
                                      	
  
abstract class Graphic {
   abstract double calculateSurfaceArea();
}
class Circle extends Graphic {
   private int radius;
   double calculateSurfaceArea() {
    ...
   }
}
Abstract	
  Class
                                      	
  
abstract class A {
   abstract void m();
}
abstract class B extends A {
   // What is the implementation of the class B?
}
Interface	
  
•  Interface	
  is	
  a	
  abstract	
  class	
  that	
  contain	
  only	
  
   abstract	
  methods	
  
•  Interface	
  can	
  contain	
  also	
  public	
  staAc	
  final	
  
   variables	
  
•  Class	
  can	
  inherit	
  only	
  one	
  class,	
  but	
  it	
  can	
  
   implement	
  many	
  interfaces	
  
Interface	
  
interface class A {
   public void m();
}

class B implements A {
   public void m() {
    ...
   }
}
Polymorphism	
  
•  Declaring	
  a	
  object:	
  
     –  Graphic c;!
•  IniAalizing	
  the	
  object:	
  
     –  c = new Graphic();!
•  This	
  is	
  also	
  possible:	
  
     –  c = new Circle();!
     –  c = new Rect();!
•  If	
  Circle and	
  Rect are	
  inherited	
  from	
  Graphic!
Polymorphism	
  
class Polymorphism {
   public static void main(String [] args) {
    // What are the possible objects to be passed?
    method(??)
   }
   public static void method(Graphic c) {
    ...
   }
}
Polymorphism	
  
interface R {
   ...
}
class Polymorphism {
   public static void main(String [] args) {
    // What are the possible objects to be passed?
    method(??)
   }
   public static void method(R r) {
    ...
   }
}
Cloning	
  
class Person implements Cloneable {
   private name;
   public Person(String name) {
    this.name = name;
   }
   public Object clone() {
    return new Person(this.name);
   }
}
Person a = new Person(“jack”);
Person b = a.clone();
Equals
                                 	
  
// What happens here?
Student jack1 = new Student(“Jack”);
Student jack2 = new Student(“Jack”);
System.out.println( jack1 == jack2 ); // true or false?
System.out.println( jack1.equals(jack2) ); // ?

Contenu connexe

Tendances

ITFT-Classes and object in java
ITFT-Classes and object in javaITFT-Classes and object in java
ITFT-Classes and object in javaAtul Sehdev
 
Pi j3.2 polymorphism
Pi j3.2 polymorphismPi j3.2 polymorphism
Pi j3.2 polymorphismmcollison
 
Class and object in C++
Class and object in C++Class and object in C++
Class and object in C++rprajat007
 
Best Core Java Training In Bangalore
Best Core Java Training In BangaloreBest Core Java Training In Bangalore
Best Core Java Training In Bangalorerajkamaltibacademy
 
‫Object Oriented Programming_Lecture 3
‫Object Oriented Programming_Lecture 3‫Object Oriented Programming_Lecture 3
‫Object Oriented Programming_Lecture 3Mahmoud Alfarra
 
Lect 1-class and object
Lect 1-class and objectLect 1-class and object
Lect 1-class and objectFajar Baskoro
 
Chapter 02: Classes Objects and Methods Java by Tushar B Kute
Chapter 02: Classes Objects and Methods Java by Tushar B KuteChapter 02: Classes Objects and Methods Java by Tushar B Kute
Chapter 02: Classes Objects and Methods Java by Tushar B KuteTushar B Kute
 
Object and Classes in Java
Object and Classes in JavaObject and Classes in Java
Object and Classes in Javabackdoor
 
Lect 1-java object-classes
Lect 1-java object-classesLect 1-java object-classes
Lect 1-java object-classesFajar Baskoro
 
Object Oriented Programming with Java
Object Oriented Programming with JavaObject Oriented Programming with Java
Object Oriented Programming with JavaJussi Pohjolainen
 
[OOP - Lec 09,10,11] Class Members & their Accessing
[OOP - Lec 09,10,11] Class Members & their Accessing[OOP - Lec 09,10,11] Class Members & their Accessing
[OOP - Lec 09,10,11] Class Members & their AccessingMuhammad Hammad Waseem
 
Pi j2.3 objects
Pi j2.3 objectsPi j2.3 objects
Pi j2.3 objectsmcollison
 
Java OOP Programming language (Part 5) - Inheritance
Java OOP Programming language (Part 5) - InheritanceJava OOP Programming language (Part 5) - Inheritance
Java OOP Programming language (Part 5) - InheritanceOUM SAOKOSAL
 
Java OOP Programming language (Part 3) - Class and Object
Java OOP Programming language (Part 3) - Class and ObjectJava OOP Programming language (Part 3) - Class and Object
Java OOP Programming language (Part 3) - Class and ObjectOUM SAOKOSAL
 

Tendances (20)

ITFT-Classes and object in java
ITFT-Classes and object in javaITFT-Classes and object in java
ITFT-Classes and object in java
 
Pi j3.2 polymorphism
Pi j3.2 polymorphismPi j3.2 polymorphism
Pi j3.2 polymorphism
 
Class and object in C++
Class and object in C++Class and object in C++
Class and object in C++
 
Best Core Java Training In Bangalore
Best Core Java Training In BangaloreBest Core Java Training In Bangalore
Best Core Java Training In Bangalore
 
‫Object Oriented Programming_Lecture 3
‫Object Oriented Programming_Lecture 3‫Object Oriented Programming_Lecture 3
‫Object Oriented Programming_Lecture 3
 
Classes and objects
Classes and objectsClasses and objects
Classes and objects
 
Core java
Core javaCore java
Core java
 
Lect 1-class and object
Lect 1-class and objectLect 1-class and object
Lect 1-class and object
 
Chapter 02: Classes Objects and Methods Java by Tushar B Kute
Chapter 02: Classes Objects and Methods Java by Tushar B KuteChapter 02: Classes Objects and Methods Java by Tushar B Kute
Chapter 02: Classes Objects and Methods Java by Tushar B Kute
 
Class or Object
Class or ObjectClass or Object
Class or Object
 
Object and class
Object and classObject and class
Object and class
 
Classes and objects in java
Classes and objects in javaClasses and objects in java
Classes and objects in java
 
Object and Classes in Java
Object and Classes in JavaObject and Classes in Java
Object and Classes in Java
 
Classes&objects
Classes&objectsClasses&objects
Classes&objects
 
Lect 1-java object-classes
Lect 1-java object-classesLect 1-java object-classes
Lect 1-java object-classes
 
Object Oriented Programming with Java
Object Oriented Programming with JavaObject Oriented Programming with Java
Object Oriented Programming with Java
 
[OOP - Lec 09,10,11] Class Members & their Accessing
[OOP - Lec 09,10,11] Class Members & their Accessing[OOP - Lec 09,10,11] Class Members & their Accessing
[OOP - Lec 09,10,11] Class Members & their Accessing
 
Pi j2.3 objects
Pi j2.3 objectsPi j2.3 objects
Pi j2.3 objects
 
Java OOP Programming language (Part 5) - Inheritance
Java OOP Programming language (Part 5) - InheritanceJava OOP Programming language (Part 5) - Inheritance
Java OOP Programming language (Part 5) - Inheritance
 
Java OOP Programming language (Part 3) - Class and Object
Java OOP Programming language (Part 3) - Class and ObjectJava OOP Programming language (Part 3) - Class and Object
Java OOP Programming language (Part 3) - Class and Object
 

En vedette

Design Pattern lecture 1
Design Pattern lecture 1Design Pattern lecture 1
Design Pattern lecture 1Julie Iskander
 
Object oriented fundamentals_in_java
Object oriented fundamentals_in_javaObject oriented fundamentals_in_java
Object oriented fundamentals_in_javaSelf
 
Introduction to OO, Java and Eclipse/WebSphere
Introduction to OO, Java and Eclipse/WebSphereIntroduction to OO, Java and Eclipse/WebSphere
Introduction to OO, Java and Eclipse/WebSphereeLink Business Innovations
 
Unified modelling language (UML)
Unified modelling language (UML)Unified modelling language (UML)
Unified modelling language (UML)Hirra Sultan
 
OOP programming
OOP programmingOOP programming
OOP programminganhdbh
 
OO Development 3 - Models And UML
OO Development 3 - Models And UMLOO Development 3 - Models And UML
OO Development 3 - Models And UMLRandy Connolly
 
Module 3 Object Oriented Data Models Object Oriented notations
Module 3  Object Oriented Data Models Object Oriented notationsModule 3  Object Oriented Data Models Object Oriented notations
Module 3 Object Oriented Data Models Object Oriented notationsTaher Barodawala
 
What does OOP stand for?
What does OOP stand for?What does OOP stand for?
What does OOP stand for?Colin Riley
 
Java 103 intro to java data structures
Java 103   intro to java data structuresJava 103   intro to java data structures
Java 103 intro to java data structuresagorolabs
 
Object Oriented Design in Software Engineering SE12
Object Oriented Design in Software Engineering SE12Object Oriented Design in Software Engineering SE12
Object Oriented Design in Software Engineering SE12koolkampus
 
Objects & OO Thinking for Java
Objects & OO Thinking for JavaObjects & OO Thinking for Java
Objects & OO Thinking for JavaJeff Sonstein
 

En vedette (17)

Design Pattern lecture 1
Design Pattern lecture 1Design Pattern lecture 1
Design Pattern lecture 1
 
Applying OO Concepts
Applying OO ConceptsApplying OO Concepts
Applying OO Concepts
 
JavaYDL15
JavaYDL15JavaYDL15
JavaYDL15
 
Itt1 sd uml and oo
Itt1 sd uml and ooItt1 sd uml and oo
Itt1 sd uml and oo
 
Object oriented fundamentals_in_java
Object oriented fundamentals_in_javaObject oriented fundamentals_in_java
Object oriented fundamentals_in_java
 
OO & UML
OO & UMLOO & UML
OO & UML
 
Introduction to OO, Java and Eclipse/WebSphere
Introduction to OO, Java and Eclipse/WebSphereIntroduction to OO, Java and Eclipse/WebSphere
Introduction to OO, Java and Eclipse/WebSphere
 
Unified modelling language (UML)
Unified modelling language (UML)Unified modelling language (UML)
Unified modelling language (UML)
 
OOP programming
OOP programmingOOP programming
OOP programming
 
OO Development 3 - Models And UML
OO Development 3 - Models And UMLOO Development 3 - Models And UML
OO Development 3 - Models And UML
 
Module 3 Object Oriented Data Models Object Oriented notations
Module 3  Object Oriented Data Models Object Oriented notationsModule 3  Object Oriented Data Models Object Oriented notations
Module 3 Object Oriented Data Models Object Oriented notations
 
Packaes & interfaces
Packaes & interfacesPackaes & interfaces
Packaes & interfaces
 
What does OOP stand for?
What does OOP stand for?What does OOP stand for?
What does OOP stand for?
 
Uml
UmlUml
Uml
 
Java 103 intro to java data structures
Java 103   intro to java data structuresJava 103   intro to java data structures
Java 103 intro to java data structures
 
Object Oriented Design in Software Engineering SE12
Object Oriented Design in Software Engineering SE12Object Oriented Design in Software Engineering SE12
Object Oriented Design in Software Engineering SE12
 
Objects & OO Thinking for Java
Objects & OO Thinking for JavaObjects & OO Thinking for Java
Objects & OO Thinking for Java
 

Similaire à Java OO Revisited

Similaire à Java OO Revisited (20)

Object-oriented Basics
Object-oriented BasicsObject-oriented Basics
Object-oriented Basics
 
Java Concepts
Java ConceptsJava Concepts
Java Concepts
 
Core Java
Core JavaCore Java
Core Java
 
Core java concepts
Core java concepts Core java concepts
Core java concepts
 
Inheritance.pptx
Inheritance.pptxInheritance.pptx
Inheritance.pptx
 
11slide.ppt
11slide.ppt11slide.ppt
11slide.ppt
 
Java Methods
Java MethodsJava Methods
Java Methods
 
11slide
11slide11slide
11slide
 
OOPs & Inheritance Notes
OOPs & Inheritance NotesOOPs & Inheritance Notes
OOPs & Inheritance Notes
 
Corejava Training in Bangalore Tutorial
Corejava Training in Bangalore TutorialCorejava Training in Bangalore Tutorial
Corejava Training in Bangalore Tutorial
 
C h 04 oop_inheritance
C h 04 oop_inheritanceC h 04 oop_inheritance
C h 04 oop_inheritance
 
Hello. Im currently working on the last section to my assignment a.pdf
Hello. Im currently working on the last section to my assignment a.pdfHello. Im currently working on the last section to my assignment a.pdf
Hello. Im currently working on the last section to my assignment a.pdf
 
Java Programming - 04 object oriented in java
Java Programming - 04 object oriented in javaJava Programming - 04 object oriented in java
Java Programming - 04 object oriented in java
 
OOP Lab Report.docx
OOP Lab Report.docxOOP Lab Report.docx
OOP Lab Report.docx
 
8 polymorphism
8 polymorphism8 polymorphism
8 polymorphism
 
Defining classes-and-objects-1.0
Defining classes-and-objects-1.0Defining classes-and-objects-1.0
Defining classes-and-objects-1.0
 
Chapter 6 OOP (Revision)
Chapter 6 OOP (Revision)Chapter 6 OOP (Revision)
Chapter 6 OOP (Revision)
 
Sonu wiziq
Sonu wiziqSonu wiziq
Sonu wiziq
 
core java
core javacore java
core java
 
Core Java Concepts
Core Java ConceptsCore Java Concepts
Core Java Concepts
 

Plus de Jussi Pohjolainen

libGDX: Screens, Fonts and Preferences
libGDX: Screens, Fonts and PreferenceslibGDX: Screens, Fonts and Preferences
libGDX: Screens, Fonts and PreferencesJussi Pohjolainen
 
libGDX: User Input and Frame by Frame Animation
libGDX: User Input and Frame by Frame AnimationlibGDX: User Input and Frame by Frame Animation
libGDX: User Input and Frame by Frame AnimationJussi Pohjolainen
 
Intro to Building Android Games using libGDX
Intro to Building Android Games using libGDXIntro to Building Android Games using libGDX
Intro to Building Android Games using libGDXJussi Pohjolainen
 
Advanced JavaScript Development
Advanced JavaScript DevelopmentAdvanced JavaScript Development
Advanced JavaScript DevelopmentJussi Pohjolainen
 
libGDX: Simple Frame Animation
libGDX: Simple Frame AnimationlibGDX: Simple Frame Animation
libGDX: Simple Frame AnimationJussi Pohjolainen
 
libGDX: Simple Frame Animation
libGDX: Simple Frame AnimationlibGDX: Simple Frame Animation
libGDX: Simple Frame AnimationJussi Pohjolainen
 
Implementing a Simple Game using libGDX
Implementing a Simple Game using libGDXImplementing a Simple Game using libGDX
Implementing a Simple Game using libGDXJussi Pohjolainen
 
Building Android games using LibGDX
Building Android games using LibGDXBuilding Android games using LibGDX
Building Android games using LibGDXJussi Pohjolainen
 
Creating Asha Games: Game Pausing, Orientation, Sensors and Gestures
Creating Asha Games: Game Pausing, Orientation, Sensors and GesturesCreating Asha Games: Game Pausing, Orientation, Sensors and Gestures
Creating Asha Games: Game Pausing, Orientation, Sensors and GesturesJussi Pohjolainen
 
Creating Games for Asha - platform
Creating Games for Asha - platformCreating Games for Asha - platform
Creating Games for Asha - platformJussi Pohjolainen
 

Plus de Jussi Pohjolainen (20)

Moved to Speakerdeck
Moved to SpeakerdeckMoved to Speakerdeck
Moved to Speakerdeck
 
Java Web Services
Java Web ServicesJava Web Services
Java Web Services
 
Box2D and libGDX
Box2D and libGDXBox2D and libGDX
Box2D and libGDX
 
libGDX: Screens, Fonts and Preferences
libGDX: Screens, Fonts and PreferenceslibGDX: Screens, Fonts and Preferences
libGDX: Screens, Fonts and Preferences
 
libGDX: Tiled Maps
libGDX: Tiled MapslibGDX: Tiled Maps
libGDX: Tiled Maps
 
libGDX: User Input and Frame by Frame Animation
libGDX: User Input and Frame by Frame AnimationlibGDX: User Input and Frame by Frame Animation
libGDX: User Input and Frame by Frame Animation
 
Intro to Building Android Games using libGDX
Intro to Building Android Games using libGDXIntro to Building Android Games using libGDX
Intro to Building Android Games using libGDX
 
Advanced JavaScript Development
Advanced JavaScript DevelopmentAdvanced JavaScript Development
Advanced JavaScript Development
 
Introduction to JavaScript
Introduction to JavaScriptIntroduction to JavaScript
Introduction to JavaScript
 
Introduction to AngularJS
Introduction to AngularJSIntroduction to AngularJS
Introduction to AngularJS
 
libGDX: Scene2D
libGDX: Scene2DlibGDX: Scene2D
libGDX: Scene2D
 
libGDX: Simple Frame Animation
libGDX: Simple Frame AnimationlibGDX: Simple Frame Animation
libGDX: Simple Frame Animation
 
libGDX: Simple Frame Animation
libGDX: Simple Frame AnimationlibGDX: Simple Frame Animation
libGDX: Simple Frame Animation
 
libGDX: User Input
libGDX: User InputlibGDX: User Input
libGDX: User Input
 
Implementing a Simple Game using libGDX
Implementing a Simple Game using libGDXImplementing a Simple Game using libGDX
Implementing a Simple Game using libGDX
 
Building Android games using LibGDX
Building Android games using LibGDXBuilding Android games using LibGDX
Building Android games using LibGDX
 
Android Threading
Android ThreadingAndroid Threading
Android Threading
 
Creating Asha Games: Game Pausing, Orientation, Sensors and Gestures
Creating Asha Games: Game Pausing, Orientation, Sensors and GesturesCreating Asha Games: Game Pausing, Orientation, Sensors and Gestures
Creating Asha Games: Game Pausing, Orientation, Sensors and Gestures
 
Creating Games for Asha - platform
Creating Games for Asha - platformCreating Games for Asha - platform
Creating Games for Asha - platform
 
Intro to Asha UI
Intro to Asha UIIntro to Asha UI
Intro to Asha UI
 

Dernier

Bun (KitWorks Team Study 노별마루 발표 2024.4.22)
Bun (KitWorks Team Study 노별마루 발표 2024.4.22)Bun (KitWorks Team Study 노별마루 발표 2024.4.22)
Bun (KitWorks Team Study 노별마루 발표 2024.4.22)Wonjun Hwang
 
"Debugging python applications inside k8s environment", Andrii Soldatenko
"Debugging python applications inside k8s environment", Andrii Soldatenko"Debugging python applications inside k8s environment", Andrii Soldatenko
"Debugging python applications inside k8s environment", Andrii SoldatenkoFwdays
 
Training state-of-the-art general text embedding
Training state-of-the-art general text embeddingTraining state-of-the-art general text embedding
Training state-of-the-art general text embeddingZilliz
 
Streamlining Python Development: A Guide to a Modern Project Setup
Streamlining Python Development: A Guide to a Modern Project SetupStreamlining Python Development: A Guide to a Modern Project Setup
Streamlining Python Development: A Guide to a Modern Project SetupFlorian Wilhelm
 
Developer Data Modeling Mistakes: From Postgres to NoSQL
Developer Data Modeling Mistakes: From Postgres to NoSQLDeveloper Data Modeling Mistakes: From Postgres to NoSQL
Developer Data Modeling Mistakes: From Postgres to NoSQLScyllaDB
 
DevEX - reference for building teams, processes, and platforms
DevEX - reference for building teams, processes, and platformsDevEX - reference for building teams, processes, and platforms
DevEX - reference for building teams, processes, and platformsSergiu Bodiu
 
DevoxxFR 2024 Reproducible Builds with Apache Maven
DevoxxFR 2024 Reproducible Builds with Apache MavenDevoxxFR 2024 Reproducible Builds with Apache Maven
DevoxxFR 2024 Reproducible Builds with Apache MavenHervé Boutemy
 
Are Multi-Cloud and Serverless Good or Bad?
Are Multi-Cloud and Serverless Good or Bad?Are Multi-Cloud and Serverless Good or Bad?
Are Multi-Cloud and Serverless Good or Bad?Mattias Andersson
 
"ML in Production",Oleksandr Bagan
"ML in Production",Oleksandr Bagan"ML in Production",Oleksandr Bagan
"ML in Production",Oleksandr BaganFwdays
 
The Future of Software Development - Devin AI Innovative Approach.pdf
The Future of Software Development - Devin AI Innovative Approach.pdfThe Future of Software Development - Devin AI Innovative Approach.pdf
The Future of Software Development - Devin AI Innovative Approach.pdfSeasiaInfotech2
 
Kotlin Multiplatform & Compose Multiplatform - Starter kit for pragmatics
Kotlin Multiplatform & Compose Multiplatform - Starter kit for pragmaticsKotlin Multiplatform & Compose Multiplatform - Starter kit for pragmatics
Kotlin Multiplatform & Compose Multiplatform - Starter kit for pragmaticscarlostorres15106
 
My INSURER PTE LTD - Insurtech Innovation Award 2024
My INSURER PTE LTD - Insurtech Innovation Award 2024My INSURER PTE LTD - Insurtech Innovation Award 2024
My INSURER PTE LTD - Insurtech Innovation Award 2024The Digital Insurer
 
Transcript: New from BookNet Canada for 2024: BNC CataList - Tech Forum 2024
Transcript: New from BookNet Canada for 2024: BNC CataList - Tech Forum 2024Transcript: New from BookNet Canada for 2024: BNC CataList - Tech Forum 2024
Transcript: New from BookNet Canada for 2024: BNC CataList - Tech Forum 2024BookNet Canada
 
Vertex AI Gemini Prompt Engineering Tips
Vertex AI Gemini Prompt Engineering TipsVertex AI Gemini Prompt Engineering Tips
Vertex AI Gemini Prompt Engineering TipsMiki Katsuragi
 
Nell’iperspazio con Rocket: il Framework Web di Rust!
Nell’iperspazio con Rocket: il Framework Web di Rust!Nell’iperspazio con Rocket: il Framework Web di Rust!
Nell’iperspazio con Rocket: il Framework Web di Rust!Commit University
 
WordPress Websites for Engineers: Elevate Your Brand
WordPress Websites for Engineers: Elevate Your BrandWordPress Websites for Engineers: Elevate Your Brand
WordPress Websites for Engineers: Elevate Your Brandgvaughan
 
SIP trunking in Janus @ Kamailio World 2024
SIP trunking in Janus @ Kamailio World 2024SIP trunking in Janus @ Kamailio World 2024
SIP trunking in Janus @ Kamailio World 2024Lorenzo Miniero
 
What's New in Teams Calling, Meetings and Devices March 2024
What's New in Teams Calling, Meetings and Devices March 2024What's New in Teams Calling, Meetings and Devices March 2024
What's New in Teams Calling, Meetings and Devices March 2024Stephanie Beckett
 
Unraveling Multimodality with Large Language Models.pdf
Unraveling Multimodality with Large Language Models.pdfUnraveling Multimodality with Large Language Models.pdf
Unraveling Multimodality with Large Language Models.pdfAlex Barbosa Coqueiro
 

Dernier (20)

Bun (KitWorks Team Study 노별마루 발표 2024.4.22)
Bun (KitWorks Team Study 노별마루 발표 2024.4.22)Bun (KitWorks Team Study 노별마루 발표 2024.4.22)
Bun (KitWorks Team Study 노별마루 발표 2024.4.22)
 
"Debugging python applications inside k8s environment", Andrii Soldatenko
"Debugging python applications inside k8s environment", Andrii Soldatenko"Debugging python applications inside k8s environment", Andrii Soldatenko
"Debugging python applications inside k8s environment", Andrii Soldatenko
 
Training state-of-the-art general text embedding
Training state-of-the-art general text embeddingTraining state-of-the-art general text embedding
Training state-of-the-art general text embedding
 
Streamlining Python Development: A Guide to a Modern Project Setup
Streamlining Python Development: A Guide to a Modern Project SetupStreamlining Python Development: A Guide to a Modern Project Setup
Streamlining Python Development: A Guide to a Modern Project Setup
 
Developer Data Modeling Mistakes: From Postgres to NoSQL
Developer Data Modeling Mistakes: From Postgres to NoSQLDeveloper Data Modeling Mistakes: From Postgres to NoSQL
Developer Data Modeling Mistakes: From Postgres to NoSQL
 
DevEX - reference for building teams, processes, and platforms
DevEX - reference for building teams, processes, and platformsDevEX - reference for building teams, processes, and platforms
DevEX - reference for building teams, processes, and platforms
 
DevoxxFR 2024 Reproducible Builds with Apache Maven
DevoxxFR 2024 Reproducible Builds with Apache MavenDevoxxFR 2024 Reproducible Builds with Apache Maven
DevoxxFR 2024 Reproducible Builds with Apache Maven
 
Are Multi-Cloud and Serverless Good or Bad?
Are Multi-Cloud and Serverless Good or Bad?Are Multi-Cloud and Serverless Good or Bad?
Are Multi-Cloud and Serverless Good or Bad?
 
"ML in Production",Oleksandr Bagan
"ML in Production",Oleksandr Bagan"ML in Production",Oleksandr Bagan
"ML in Production",Oleksandr Bagan
 
The Future of Software Development - Devin AI Innovative Approach.pdf
The Future of Software Development - Devin AI Innovative Approach.pdfThe Future of Software Development - Devin AI Innovative Approach.pdf
The Future of Software Development - Devin AI Innovative Approach.pdf
 
Kotlin Multiplatform & Compose Multiplatform - Starter kit for pragmatics
Kotlin Multiplatform & Compose Multiplatform - Starter kit for pragmaticsKotlin Multiplatform & Compose Multiplatform - Starter kit for pragmatics
Kotlin Multiplatform & Compose Multiplatform - Starter kit for pragmatics
 
My INSURER PTE LTD - Insurtech Innovation Award 2024
My INSURER PTE LTD - Insurtech Innovation Award 2024My INSURER PTE LTD - Insurtech Innovation Award 2024
My INSURER PTE LTD - Insurtech Innovation Award 2024
 
Transcript: New from BookNet Canada for 2024: BNC CataList - Tech Forum 2024
Transcript: New from BookNet Canada for 2024: BNC CataList - Tech Forum 2024Transcript: New from BookNet Canada for 2024: BNC CataList - Tech Forum 2024
Transcript: New from BookNet Canada for 2024: BNC CataList - Tech Forum 2024
 
Vertex AI Gemini Prompt Engineering Tips
Vertex AI Gemini Prompt Engineering TipsVertex AI Gemini Prompt Engineering Tips
Vertex AI Gemini Prompt Engineering Tips
 
Nell’iperspazio con Rocket: il Framework Web di Rust!
Nell’iperspazio con Rocket: il Framework Web di Rust!Nell’iperspazio con Rocket: il Framework Web di Rust!
Nell’iperspazio con Rocket: il Framework Web di Rust!
 
WordPress Websites for Engineers: Elevate Your Brand
WordPress Websites for Engineers: Elevate Your BrandWordPress Websites for Engineers: Elevate Your Brand
WordPress Websites for Engineers: Elevate Your Brand
 
E-Vehicle_Hacking_by_Parul Sharma_null_owasp.pptx
E-Vehicle_Hacking_by_Parul Sharma_null_owasp.pptxE-Vehicle_Hacking_by_Parul Sharma_null_owasp.pptx
E-Vehicle_Hacking_by_Parul Sharma_null_owasp.pptx
 
SIP trunking in Janus @ Kamailio World 2024
SIP trunking in Janus @ Kamailio World 2024SIP trunking in Janus @ Kamailio World 2024
SIP trunking in Janus @ Kamailio World 2024
 
What's New in Teams Calling, Meetings and Devices March 2024
What's New in Teams Calling, Meetings and Devices March 2024What's New in Teams Calling, Meetings and Devices March 2024
What's New in Teams Calling, Meetings and Devices March 2024
 
Unraveling Multimodality with Large Language Models.pdf
Unraveling Multimodality with Large Language Models.pdfUnraveling Multimodality with Large Language Models.pdf
Unraveling Multimodality with Large Language Models.pdf
 

Java OO Revisited

  • 1. Object  Orientated  Programming  with   Java   Jussi  Pohjolainen   Tampere  University  of  Applied  Sciences  
  • 2. Object  Orientated  Concepts   •  Class   •  Object   •  Inheritance   •  Constructors   •  Abstract  class   •  Interface   •  Polymorphism  
  • 3. Class   class Student { private String name; public Student(String name) { this.name = name; } public void setName(String name) { this.name = name } public void getName() { return name; } }
  • 4. CreaAng  objects   Student jack = new Student(“Jack”); Student bill = new Student(“Bill”); System.out.println( jack.getName() ); System.out.println( bill.getName() );
  • 5. Reference?   Student jack = new Student(“Jack”); Student bill = jack; jack.setName(“Lisa”); // What is the output? System.out.println(bill.getName());
  • 6. Reference   •  In  Java,  every  object  is  passed  by  reference   •  If  you  want  to  clone  a  object,  you  use  special   techniques  (later  on  the  material)  
  • 7. Inheritance   class Person { private String name; ... } class Student extends Person { private int id; ... }
  • 8. Constructors   class Person { private String name; public Person() { System.out.println(“Person”); } } class Student extends Person { private int id; public Student() { System.out.println(“Student”); } } // What is the output? Student s = new Student();
  • 9. Default  Constructor   •  If  programmer  does  not  define  a  constructor,  Java   creates  a  default  constructor:   class Person { } => class Person { public Person() { super(); } }
  • 10. Default  Constructor   class Person { private String name; public Person() { System.out.println(“Person”); } } class Student extends Person { private int id; } // What is the output? Student s = new Student();
  • 11. Default  Constructor  Problem   class Person { private String name; public Person(String name) { System.out.println(“Person”); } } class Student extends Person { private int id; } // What is the output? Student s = new Student();
  • 12. Abstract  Class   •  You  cannot  create  a  object  from  abstract  class   •  Abstract  class  may  contain  abstract  method   •  Abstract  method  is  a  method  declaraAon  which   must  be  implemented  in  inherited  classes  
  • 13. Abstract  Class   abstract class Graphic { abstract double calculateSurfaceArea(); } class Circle extends Graphic { private int radius; double calculateSurfaceArea() { ... } }
  • 14. Abstract  Class   abstract class A { abstract void m(); } abstract class B extends A { // What is the implementation of the class B? }
  • 15. Interface   •  Interface  is  a  abstract  class  that  contain  only   abstract  methods   •  Interface  can  contain  also  public  staAc  final   variables   •  Class  can  inherit  only  one  class,  but  it  can   implement  many  interfaces  
  • 16. Interface   interface class A { public void m(); } class B implements A { public void m() { ... } }
  • 17. Polymorphism   •  Declaring  a  object:   –  Graphic c;! •  IniAalizing  the  object:   –  c = new Graphic();! •  This  is  also  possible:   –  c = new Circle();! –  c = new Rect();! •  If  Circle and  Rect are  inherited  from  Graphic!
  • 18. Polymorphism   class Polymorphism { public static void main(String [] args) { // What are the possible objects to be passed? method(??) } public static void method(Graphic c) { ... } }
  • 19. Polymorphism   interface R { ... } class Polymorphism { public static void main(String [] args) { // What are the possible objects to be passed? method(??) } public static void method(R r) { ... } }
  • 20. Cloning   class Person implements Cloneable { private name; public Person(String name) { this.name = name; } public Object clone() { return new Person(this.name); } } Person a = new Person(“jack”); Person b = a.clone();
  • 21. Equals   // What happens here? Student jack1 = new Student(“Jack”); Student jack2 = new Student(“Jack”); System.out.println( jack1 == jack2 ); // true or false? System.out.println( jack1.equals(jack2) ); // ?