Think with java
-
Upload
arif-rahman -
Category
Technology
-
view
148 -
download
0
Transcript of Think with java
![Page 1: Think with java](https://reader035.fdocuments.us/reader035/viewer/2022081604/58843c1a1a28ab39538b76a5/html5/thumbnails/1.jpg)
Think With Java Mapping Real World Object with Java
![Page 2: Think with java](https://reader035.fdocuments.us/reader035/viewer/2022081604/58843c1a1a28ab39538b76a5/html5/thumbnails/2.jpg)
A Society ( Group of families)
![Page 3: Think with java](https://reader035.fdocuments.us/reader035/viewer/2022081604/58843c1a1a28ab39538b76a5/html5/thumbnails/3.jpg)
A Society ( Group of families)Everything in the World is an Object (Society, Family, Human, Cat, Dog, Car, River)
A society is a group of families.Families are collections of Family member.
Each Family member is Human or Non Human.
Each family member has some responsibilities (Activity) and they have their own properties.
Family members are interconnected to each other.
![Page 4: Think with java](https://reader035.fdocuments.us/reader035/viewer/2022081604/58843c1a1a28ab39538b76a5/html5/thumbnails/4.jpg)
A Society ( Group of families)Each member is a human or non human.Human beings are persons.Each Human has common behavior comes from Animal.
Each family member uses their guardians vehicle or their own.
Each and every Human being has their own Address.
![Page 5: Think with java](https://reader035.fdocuments.us/reader035/viewer/2022081604/58843c1a1a28ab39538b76a5/html5/thumbnails/5.jpg)
Humans(Objects) Behavior
Object is an entity which has State: determined by the values of its properties.
Behavior: determined by how an object performs an activity.
![Page 6: Think with java](https://reader035.fdocuments.us/reader035/viewer/2022081604/58843c1a1a28ab39538b76a5/html5/thumbnails/6.jpg)
Humans(Objects) Properties & Behavior/ActivityEvery human(Male / Female / Other) has common properties and also they have their Behavior.
Properties: Name, Head, Hands, Hair, Eyes(color , size), Nose, Address.
Behavior: Walking, Running, Playing, Gaining Knowledge, Talking.
![Page 7: Think with java](https://reader035.fdocuments.us/reader035/viewer/2022081604/58843c1a1a28ab39538b76a5/html5/thumbnails/7.jpg)
Map Now the Real World Objects
![Page 8: Think with java](https://reader035.fdocuments.us/reader035/viewer/2022081604/58843c1a1a28ab39538b76a5/html5/thumbnails/8.jpg)
Java Class or Java BeanA simple Object instance container.It has some properties and behavior.So we can map our real world objects through Java .
Properties: nationalId, name, Address, vehicle,
PassportInfo, Occupation
Behavior: Walking, Running, Shopping,
Talking, Cycling,Driving
![Page 9: Think with java](https://reader035.fdocuments.us/reader035/viewer/2022081604/58843c1a1a28ab39538b76a5/html5/thumbnails/9.jpg)
Access Modifier in java for properties and behaviorPublic: A declaration that is accessible to all classes with keyword “public”
Private: A declaration that is accessible only to the class in which it is declared with “private”.
![Page 10: Think with java](https://reader035.fdocuments.us/reader035/viewer/2022081604/58843c1a1a28ab39538b76a5/html5/thumbnails/10.jpg)
Access Modifier in java for properties and behavior
![Page 11: Think with java](https://reader035.fdocuments.us/reader035/viewer/2022081604/58843c1a1a28ab39538b76a5/html5/thumbnails/11.jpg)
Java OOP feature(Abstraction)
Customer should know to buy something
BillingStaff should know products pricing and to generate bill.
Administrator should product sell and to buy new products to gain business goal and to manage everything in the system.
ABSTRACTION: concept of identifying the essential details to be known and ignoring the non-essential details from the perspective of the end user.
Retail Shop Scenario
![Page 12: Think with java](https://reader035.fdocuments.us/reader035/viewer/2022081604/58843c1a1a28ab39538b76a5/html5/thumbnails/12.jpg)
A simple Shopping Scenarioof Abstraction
![Page 13: Think with java](https://reader035.fdocuments.us/reader035/viewer/2022081604/58843c1a1a28ab39538b76a5/html5/thumbnails/13.jpg)
EncapsulationThe Student don’t have to know the calculation mechanism of Calculator.
He/she just know its use of button. ENCAPSULATION: concept of hiding the
internal details and providing a simple interface to the end user which ensures that the system can be used without having to know how it works.
![Page 14: Think with java](https://reader035.fdocuments.us/reader035/viewer/2022081604/58843c1a1a28ab39538b76a5/html5/thumbnails/14.jpg)
A Calculator Scenarioof Encapsulation
![Page 15: Think with java](https://reader035.fdocuments.us/reader035/viewer/2022081604/58843c1a1a28ab39538b76a5/html5/thumbnails/15.jpg)
InheritanceEach Human have some common behavior of Animal.
Every family members are human or non-human(Cat or dog).
Each Regular or Privileged Customer have common Properties.
![Page 16: Think with java](https://reader035.fdocuments.us/reader035/viewer/2022081604/58843c1a1a28ab39538b76a5/html5/thumbnails/16.jpg)
Different Inheritance
![Page 17: Think with java](https://reader035.fdocuments.us/reader035/viewer/2022081604/58843c1a1a28ab39538b76a5/html5/thumbnails/17.jpg)
Inheritance
Allows to define the generalized and specialized characteristics and behavior. Multiple Inheritance
![Page 18: Think with java](https://reader035.fdocuments.us/reader035/viewer/2022081604/58843c1a1a28ab39538b76a5/html5/thumbnails/18.jpg)
Inheritance
Allows to define the generalized and specialized characteristics and behavior.
Multi level Inheritance
![Page 19: Think with java](https://reader035.fdocuments.us/reader035/viewer/2022081604/58843c1a1a28ab39538b76a5/html5/thumbnails/19.jpg)
Polymorphism Let us revisit the payment activity in the retail
shop Paymlent of bill can be done in two modes Cash(Calculation includes VAT) totalAmount = purchaseAmount + VAT Credit Card(Calculation includes processing
charge and VAT) totalAmount = purchaseAmount + VAT+
processingCharge POLYMORPHISM: concept which allows on
objecct/operation to behave differently in different situations.
So ? Now it is payment(processingCharge) or payment()?
![Page 20: Think with java](https://reader035.fdocuments.us/reader035/viewer/2022081604/58843c1a1a28ab39538b76a5/html5/thumbnails/20.jpg)
PolymorphismPolymorphism is the capability of a method to do different things based on the object that it is acting upon
Following concepts demonstrate different types of polymorphism in java.
1) Method Overloading
2) Method Overriding
![Page 21: Think with java](https://reader035.fdocuments.us/reader035/viewer/2022081604/58843c1a1a28ab39538b76a5/html5/thumbnails/21.jpg)
Static Binding vs Dynamic Bindingdifference between static and dynamic binding in Java.
Static binding happens at compile-time while dynamic binding happens at runtime.
Binding of private, static and final methods always happen at compile time since these methods cannot be overridden. Binding of overridden methods happen at runtime.
Java uses static binding for overloaded methods and dynamic binding for overridden methods.
![Page 22: Think with java](https://reader035.fdocuments.us/reader035/viewer/2022081604/58843c1a1a28ab39538b76a5/html5/thumbnails/22.jpg)
Dynamic Polymorphism(dynamic binding) example
![Page 23: Think with java](https://reader035.fdocuments.us/reader035/viewer/2022081604/58843c1a1a28ab39538b76a5/html5/thumbnails/23.jpg)
Abstract class & abstract Method
If you declare an abstract method (discussed below) in a class then you must declare the class abstract as well. you can’t have abstract method in a non-abstract class.
![Page 24: Think with java](https://reader035.fdocuments.us/reader035/viewer/2022081604/58843c1a1a28ab39538b76a5/html5/thumbnails/24.jpg)
What is an interface
Interface looks like class but it is not a class. An interface can have methods and variables just like the class but the methods declared in interface are by default abstract (only method signature, no body). Also, the variables declared in an interface are public, static & final by default.
** java programming language does not support multiple inheritance (we can do this through Interface)
![Page 25: Think with java](https://reader035.fdocuments.us/reader035/viewer/2022081604/58843c1a1a28ab39538b76a5/html5/thumbnails/25.jpg)
Interface and abstractInterface provides complete abstraction as none of its methods can have body. On the other hand, abstract class provides partial abstraction as it can have abstract and concrete(methods with body) methods both.
![Page 26: Think with java](https://reader035.fdocuments.us/reader035/viewer/2022081604/58843c1a1a28ab39538b76a5/html5/thumbnails/26.jpg)
Use of Interface
![Page 27: Think with java](https://reader035.fdocuments.us/reader035/viewer/2022081604/58843c1a1a28ab39538b76a5/html5/thumbnails/27.jpg)
Use of Interface with “abstract” keyword
![Page 28: Think with java](https://reader035.fdocuments.us/reader035/viewer/2022081604/58843c1a1a28ab39538b76a5/html5/thumbnails/28.jpg)
Relationship in Java classes
Is A (Inheritance)Has A (Aggregation) Tightly coupledUses (Association) Loosely coupled
![Page 29: Think with java](https://reader035.fdocuments.us/reader035/viewer/2022081604/58843c1a1a28ab39538b76a5/html5/thumbnails/29.jpg)
Relationship in Java classes
![Page 30: Think with java](https://reader035.fdocuments.us/reader035/viewer/2022081604/58843c1a1a28ab39538b76a5/html5/thumbnails/30.jpg)
What next. . . . . . ORM = Object Relational MappingORM Providers : JPA, Hibernate, Spring, OFBiz
MVC = Model View ControllerMVC provider : JSF, Hibernate, Spring, OFBiz etc.
![Page 31: Think with java](https://reader035.fdocuments.us/reader035/viewer/2022081604/58843c1a1a28ab39538b76a5/html5/thumbnails/31.jpg)
A Strong Tool : Collection Framework
To work with data in the local machine or memory must use the collection framework.
Collections--> Set, List, ArrayList, Map, LinkedHashMap
![Page 32: Think with java](https://reader035.fdocuments.us/reader035/viewer/2022081604/58843c1a1a28ab39538b76a5/html5/thumbnails/32.jpg)
Collection Framework overview.
![Page 33: Think with java](https://reader035.fdocuments.us/reader035/viewer/2022081604/58843c1a1a28ab39538b76a5/html5/thumbnails/33.jpg)
Collections Example
![Page 34: Think with java](https://reader035.fdocuments.us/reader035/viewer/2022081604/58843c1a1a28ab39538b76a5/html5/thumbnails/34.jpg)
Questions & Answers Fun with Java :)
![Page 35: Think with java](https://reader035.fdocuments.us/reader035/viewer/2022081604/58843c1a1a28ab39538b76a5/html5/thumbnails/35.jpg)
Thanks to all…Md. Arifur RahmanJunior Software Engineer,Newgen Technology Limited, Bangladesh.