[Draft] Training Guide ‐ OOP in Java - vinhtbkit/bkit-kb GitHub Wiki
OOP (Object-Oriented Programming) is also known as OOPs (Object-Oriented Programming System).
In Java programming, the OOP is an important concept.
Object-oriented programming aims to implement real-world entities like inheritance, hiding, polymorphism, etc. in programming. The main aim of OOP is to bind together the data and the functions that operate on them so that no other part of the code can access this data except that function.
Target: the trainee will understand the OOP in Java and can apply it to convert the real-world object to a class in Java.
Expected Duration: maximum 24 hours of training and working on exercises.
Qualification criteria:
- The trainee must understand the OOP concepts in Java: Class, Object, Inheritance, Polymorphism, Abstraction, Encapsulation.
- Knowledge about the pillars of OOPs.
- Modifiers in Java and their scopes.
REQUIRED
:
What is OOP? References:
OOPs in Java:
References:
- https://www.geeksforgeeks.org/object-oriented-programming-oops-concept-in-java/
- https://www.javatpoint.com/java-oops-concepts
- https://www.w3schools.com/java/java_oop.asp
- https://www.geeksforgeeks.org/java-not-purely-object-oriented-language/?ref=lbp
REQUIRED
:
Class References:
- https://www.w3schools.com/java/java_classes.asp
- https://www.geeksforgeeks.org/classes-objects-java/?ref=lbp
REQUIRED
:
Object References:
- https://www.w3schools.com/java/java_classes.asp
- https://www.geeksforgeeks.org/classes-objects-java/?ref=lbp
REQUIRED
:
Constructors References:
- https://www.w3schools.com/java/java_constructors.asp
- https://www.geeksforgeeks.org/constructors-in-java/?ref=lbp
REQUIRED
:
Attributes References:
REQUIRED
:
Methods References:
- https://www.w3schools.com/java/java_class_methods.asp
- https://www.geeksforgeeks.org/methods-in-java/?ref=lbp
REQUIRED
:
Modifiers References:
- https://www.geeksforgeeks.org/access-modifiers-java/?ref=lbp
- https://www.w3schools.com/java/java_modifiers.asp
REQUIRED
:
Inheritance References:
- https://www.geeksforgeeks.org/inheritance-in-java/?ref=lbp
- https://www.w3schools.com/java/java_inheritance.asp
REQUIRED
:
Polymorphism - Compile-time Polymorphism
- Runtime Polymorphism
References:
- https://www.geeksforgeeks.org/polymorphism-in-java/?ref=lbp
- https://www.w3schools.com/java/java_polymorphism.asp
REQUIRED
:
Abstraction References:
- https://www.geeksforgeeks.org/abstraction-in-java-2/?ref=lbp
- https://www.w3schools.com/java/java_abstract.asp
- https://www.w3schools.com/java/java_interface.asp
REQUIRED
:
Encapsulation References:
- https://www.geeksforgeeks.org/encapsulation-in-java/?ref=lbp
- https://www.w3schools.com/java/java_encapsulation.asp
Quizzes:
- What are the pillars of the OOP concept? Explain the meaning of each pillar.
- Why Do We Need Java Inheritance? And How to Use Inheritance in Java?
- Why Do We Need Java Abstraction? Distinguish Encapsulation vs Abstraction. Difference between Interface class vs Abstract class in Java.
- What are method overloading and method override? Differences.
- How many constructors a class can have?
- If we do not define a modifier for a method, attribute,... What is a default? And its scopes?
- Why Java not is a purely object-oriented language?
- Could you explain the difference between OOP and POP (Procedural Oriented Programming) and Object-based programming?
- What is the purpose of
getters
andsetters
in a class? Why don't we just usepublic
fields?
Assignments:
Requires:
Knowledge about OOPs in Java, Java Syntax
Exercise:
We have three shapes: Circle, Rectangle, and Square. Each object type has general information below:
- color
- is filled or not
FYI, to calculate the area and/or perimeter for:
- Circle: we need a radius
- Rectangle: we need a width and height
- Square: we need a side
Requirements:
- Write a Java program that model above shapes. You should be using
Interface
and/orAbstract Class
to model theShape
. - Each
Shape
implementation should contain methods to get area, perimeter - The
color
andfilled
attribute should make sense to each other. Ex: filled should be true when color is set, if color is null filled should be false. - Write a toString method to display the shape information: color, filled, radius/width-height/side
- Then write some tests by yourself to check the working of these classes:
- Write utility methods to get the shape having max area from an array of shapes
Example:
Shape s1 = new Circle(3.5, "red", false);
System.out.println(s1);
System.out.println(s1.getArea());
System.out.println(s1.getPerimeter());
System.out.println(s1.getColor());
System.out.println(s1.isFilled()); // expect should be true
System.out.println(s1.toString()); // Example format: "Circle: {color: red, filled: true, radius: 3.5}"
Circle c1 = (Circle) s1; // cast to Circle
System.out.println(c1);
System.out.println(c1.getArea());
System.out.println(c1.getPerimeter());
System.out.println(c1.getColor());
System.out.println(c1.isFilled());
System.out.println(c1.getRadius());
// Question:
Shape s2 = (Shape) c1; // Can I cast a circle to a Shape? Why?