Lecture 14 - Course Revision
Lecture 14 - Course Revision
International University
School of Computer Science and Engineering
Course Revision
(IT069IU)
🌐 leduytanit.com 1
Previously,
3
Lecture 1
Intro to OOP
4
Lecture 1 - Intro to OOP
- What are Programming Paradigms?
- What is Object Oriented Programming (OOP) ?
- Why should we learn Java?
- OOP Concepts
- Class
- Object
- Encapsulation with Access Modifier
- Abstraction
- Inheritance
- Composition
- What are JDK, JRE, JVM? How these works together?
5
Programming Paradigms
- Different approaches to build solutions to specific problems.
- Most programming languages belong to one paradigm.
- Two most popular programming paradigms:
- Procedural Programming
- Object-Oriented Programming
6
Java is still the king of job market in Vietnam
Windows
Developers JVM
Java Runtime MacOS
develops (JDK) Environment JVM
(JRE)
Runs
Java source compile (JDK) Java class files
(*.class) - Java JVM Linux
files (*.java) 9
bytecode
10
Lecture 2 - Intro to Java
- Different Java Platforms
- Our choice of JDK
- The best IDE selections
- Create the first Java programs
- Compile and Run with commands or on IntelliJ
- Java data types:
- Primitive
- Non-primitive (reference types)
- Variable
- Operators
11
Our first Java Program
MyFirstJavaProgram.java
12
Data Types
- Java is statically typed and also a strongly typed language.
- There are two categories of data types:
- Primitive data types (8)
- Non-primitive data types (reference type)
13
Operators
All the Java operators can be divided into the following groups −
• Arithmetic Operators: * / % + -
• Relational Operators: < > <= >= == != instanceof
• Bitwise Operators: & ^ |
• Logical Operators: && || !
• Assignment Operators: = += -= *= /=
• Ternary operator: ? :
14
Lecture 3
Intro to Classes & Objects in Java
15
Lecture 3 - Intro to Classes & Objects in Java
- Useful Classes
- Scanner
- Read input string with nextLine(), next()
- Read input number with nextDouble()
- String
- Display string with print(), println(), printf()
- Math
- pow(), max(), random()
- Primitive vs Reference
- Class
- Attributes
- Method with Parameters
- Getters and Setters Methods
- Access Modifiers (Public & Private)
- Constructor with Parameters
- UML Diagram
- Object
- Create objects from class with keyword new
- Call methods with input arguments
- Bank account application example
16
Scanner Class: Reading Inputs
- API documentation (http://docs.oracle.com/javase/7/docs/api/java/util/Scanner.html)
- To use Scanner class, remember to import java.util.Scanner
- Can read from different input sources: input keyboards, files, …
- Can convert inputs to different type of data types: string, byte, short, int, float, double, …
17
String Class: Representation in Text
- API documentation (http://docs.oracle.com/javase/7/docs/api/java/lang/String.html)
18
Math Class: Performing Computation
- API documentation (http://docs.oracle.com/javase/7/docs/api/java/lang/Math.html)
- 2 class attributes:
- E
- PI
19
Primitives vs References
Primitive types are basic Java types
- int, long, double, boolean, char, short, byte, float.
- A variable stores the actual value of that type.
20
PRNG Applications
Monte Carlo Simulation
21
Homework: 649 Lotto Lottery!
- A lottery ticket is $4.
- A ticket having 6 different numbers (from 1 to 49) (Can be repeated)
- On a Saturday, they draw the lottery, and the winning numbers are:
23
Lecture 4 - Control Flow Statement & Overloading
- Casting types.
- Control flow statements:
- Decision making statements:
- If
- If…else
- Switch
- Loop statements:
- While
- Do while
- For
- Jump statements:
- Break statement
- Continue statement
- Static Keyword
- Static Method
- Static Variable
- Overloading
- Method Overloading
- Constructor Overloading
- Final Keyword 24
- Constant Variable
Casting among types
- Convert one data type to another data type.
25
If Statement
- Three types of decision making statements:
- if statement:
- Performs an action, if a condition is true; skips it, if false.
- Single-selection statement—selects or ignores a single action (or
group of actions).
- if…else statement:
- Performs an action if a condition is true and performs a different
action if the condition is false.
- Double-selection statement—selects between two different actions
(or groups of actions).
- switch statement
- Performs one of several actions, based on the value of an expression.
- Multiple-selection statement—selects among many different actions
(or groups of actions).
26
Control & Loop Flow Diagram
27
Here is an UML of Lottery Game Example
28
Lecture 5
Array & ArrayList
29
Lecture 5 - Array & ArrayList
- Increment and Decrement Operators
- Scope of Declarations
- this keyword
- Array:
- Declare and Create Array
- Loop through Array
- Pass Arrays to Methods
- Pass by Value vs Pass by Reference
- Multidimensional Arrays
- Class Arrays for helper methods
- ArrayList (Collections Class)
- Array vs ArrayList
30
- For example, the three assignment statements:
31
32
Array
- An array is a group of variables (called elements or components)
containing values of the same type.
- Arrays are objects, so they’re considered reference types.
34
ArrayList & Array Example
Output:
35
What do you do when you get stuck?
36
Lecture 6
Inheritance
37
Lecture 6 - Inheritance
- Inheritance:
- Definition and Examples
- Types of Inheritance
- UML Diagram
- Animal Inheritance Example
- Without Inheritance
- With Inheritance
- Method Overriding
- Constructors in Subclasses
- Keyword Super
- Method Overriding
- Keyword Super
- Access Modifier
- Protected
- Exercise for University Staff & Lecturer
38
Inheritance
- Inheritance is a way to reuse classes by expanding them
into more specific types of classes. Person
-Name
- Inheritance allows a child class (subclass) to inherit the -Age
attributes and the methods of a parent class (superclass).
+walk()
So a child class can do anything that the parent class +eat()
can do!
- A child class
- can have its own attributes and methods.
- A child class can customize methods that it inherits
from its parent class (method overriding)
- The short answer is, you should make everything as restricted as possible
(private over protected, and protected over public) while still allowing
things to get done.
- When it comes to deciding between public and private, it all comes down to
how widely used you expect the class to be. If you think a class is reusable
across many projects, then you might as well make it public from the
beginning.
41
Lecture 7
Polymorphism
42
Lecture 7 - Polymorphism
- Polymorphism
- Method overriding in Inheritance
- Zoo Example
- Abstraction
- Abstract Class
- Abstract Method
- Examples:
- Zoo Example
- Company Payroll Example
- Interface
- Interface in real life examples
- Upgrade Company Payroll with Invoices Example
- Abstract vs Interface vs Composition
43
Polymorphism
- Polymorphism literally means “many shapes”.
- The same method is called in different types of objects has different results.
- Enables you to “program in the general” rather than “program in the specific.”
- Polymorphism enables you to write programs that process objects of subclasses that share the
same superclass as if they’re all objects of the superclass; this can simplify programming.
Animal
-name
-age
+speak()
We want the subclasses to provide the implementation. Let’s look at the Circle and Rectangle classes:
49
Lecture 8 - Graphic User Interface (GUI)
- Mid-term Exam
- Possible Topics
- Format
- GUI in Java
- Swing Components
- Swing vs JavaFX vs AWT
- JOption-Panel (DialogBox)
- Java 2D API
- Java Coordinate System
- Draw Lines
- Draw Rectangles and Ovals
- Draw Colors
- Draw Polygons and Polylines
- Text Fields, Buttons and Menu Nagivations.
- Event Handler (Mouse & Keyboard)
- Layout:
- BorderLayout Frame & GridLayoutFrame 50
Sample GUI of Java’s Swing GUI APIs
51
https://mlapshin.com/index.php/projects/swingset3/
Color in Computer
52
Lecture 9
Generic Collections
53
Lecture 9 - Generic Collections
- Mid-term Exam Result
- Score Distribution
- Statistics
- Solutions
- Java Generic Collections
- Type-Wrapper Classes for Primitive Types
- Autoboxing vs Auto-unboxing
- List
- ArrayList
- Vector
- LinkedList
- Sets
- HashSet
- TreeSet
- Maps
- Hashtable
- HashMap
- TreeMaps
- HackerRank
- Introduction 54
- Coding Challenge
Collections
- Java Collections framework:
- Prebuilt data structures.
- A data structure is a particular way of organizing data so that it can be used effectively.
- Interfaces and Methods for manipulating those data structures.
- A collection is a data structure—actually, an object—that can hold references to other
objects.
- Usually, collections contain references to objects that are all of the same type.
55
56
Challenge Time!
Real Job Interview Question: Ransom Note
https://www.hackerrank.com/challenges/ctci-ransom-note/problem
Hint: you should use HashMap.
57
Lecture 10
Generic Class
58
Lecture 10 - Generic Class
- Generic
- Generic Class
- Bounded type parameters
- Generic Method
59
The Problem
60
To create object/instance of Generic class
- Create a new generic class with a type placeholder T:
- Use that generic class to create an object from it and specific what datatype
will be replace T.
61
Simple Generic Class Example
62
Problem
63
Solve it with Bound Type Parameters
Output:
64
Lecture 11
OO Design Principles (SOLID)
65
Lecture 11 - OO Design Principles (SOLID)
- Object Oriented Design Principles: SOLID
- S: Single responsibility
- O: Open/closed principle
- L: Liskov substitution principle
- I: Interface segregation principle
- D: Dependency inversion principle
66
SOLID Summary
67
Lecture 12
Design Pattern
68
Lecture 12 - Design Pattern
- Design Patterns:
- Creational
- Singleton
- Factory Method Factory Design Pattern
- Structural
- Behavioral
69
OOP Concepts vs OOP Principles vs Design Pattern
70
Types of Design Patterns
There are three categories of these patterns:
- Creational Patterns
- Focused on the way objects are created.
- Structural Patterns
- Focused on creating objects into larger structures which gives developers the
advantage to keep groups of children together and also abstract objects to
simplify applications.
- Behavioral Patterns
- Focused on combining algorithms and responsibilities together which concerned
with communication between objects.
71
Creational Design Pattern
These design patterns focused on the way objects are created:
- Abstract Factory (⭐⭐⭐): Lets you produce families of related objects without
specifying their concrete classes.
- Builder(⭐⭐⭐): Lets you construct complex objects step by step. The pattern
allows you to produce different types and representations of an object using the
same construction code.
- Factory Method(⭐⭐⭐): Provides an interface for creating objects in a superclass,
but allows subclasses to alter the type of objects that will be created.
- Prototype(⭐⭐): Lets you copy existing objects without making your code
dependent on their classes.
- Singleton(⭐⭐): Lets you ensure that a class has only one instance, while providing
a global access point to this instance. 72
Structural Design Pattern
These design patterns focused on creating objects into larger structures:
75
Factory Method: What?
- Factory Method is a creational design pattern that provides an interface
for creating objects in a superclass, but allows subclasses to alter the type
of objects that will be created.
76
Lecture 13
Web Scraping
77
Lecture 13 - Web Scraping
79
Web Component Overview
80
VNExpress Homepage Scraping Result
81
Italian Recipe Scrapping Homework
https://foodnetwork.co.uk/italian-family-dinners/
- Recipe title
- Short description
- Preparation time
- Cook time
- Number of serves
82
Our Challenge
- Let’s scrap one of the best manga websites, “MangaDoom”!
https://www.mngdoom.com/
83
Let’s pick a best manga to scrap them!
- “One Piece” is my favourite manga of all time! Let’s scrap the whole manga!
84
I'm a collector myself! Web Scraping is awesome!
85
Ultimate Challenge
- MangaSee is the only website which got the FULL-COLORED chapters of big
mangas like One Piece and Bleach!!!
- [Task] Can you figure out how to scrap either full-colored One Piece or Bleach?
- https://mangasee123.com/manga/One-Piece-Digital-Colored-Comics
- https://mangasee123.com/manga/Bleach-Color
86
One of The Best Manga Downloader Project
- https://github.com/riderkick/FMD
- The Free Manga Downloader is a free open source application written in Object
Pascal for managing and downloading manga from various websites.
- Based on what you have learned so far about web scraping, now you can actually
start to contribute to this open source project to help the Manga community!
87
Lecture 14
Final Lecture - Revision
88
Lecture 14 - Final Lecture - Today Revision
- Course revision:
- Go through topics we have learnt for each week
- Final exam format:
- Number of questions
- Topics
- Time
89
Final Exam Format
- Offline
- Open book (Lecture notes, books, … are allowed BUT NO
mobile phone, internet, google or laptop)
- 4 Questions, with topics could be related to:
- OO Concepts (keywords, ideas, …)
- Generic (Collections, Class)
- OO Design Principles (SOLID)
- Design Patterns
- 120 minutes
90
Final Game Project
- Your team present your project will be on the dates:
- For Mr. Nhân's Lab: Friday (10/06)
- For Mr. Tom's Lab: Saturday (11/06)
- Time for your presentation: 12 Minutes
- Could be break down into:
- 9 minutes presenting slides
- 3 minutes of live demo your game
- The lab instructor will ask some questions for 3-5
minutes after the presentation finishes.
- Marking Criteria for the final Project:
- 20% report (README file)
- 30% presentation
- 50% demo
- Link to register for your lab dates!
- Link for the requirement document!
91
Final Thought & Message
92
The Secret of Success: Get 1% Better Every Day
- The only idea is to improve slightly everyday! Learn something new everyday!
- Let’s prove this point:
93
94
What’s next for you?
95
What’s next for Tom?
Career tomCareer = new Career("PhD");
while (True) {
tomCareer.study();
tomCareer.teach();
tomCareer.work();
}
96
Thank you for listening!
“Always be learning!”
Tom Huynh
97