Class
Object
– Earth is a software application where human and other thing is software objects.For creating object we need to create a human class. Humans have basic behaviors as well as some basic attributes age height inches etc.
Java variables, Array, 2d array Method Different method invoking and return type Class
– Class is actually a blueprint/specification/design
– A class can create as many as objects it needs to create Object
– Earth is a software application where human and other thing is software objects.For creating object we need to create a human class
– Objects do particular behavior in a class
– Object exist only in application runtime actually when application is running
– Objects have identity,state and behavior
– this keyword – it represent current object Instance Constructor – The costructor is a special method with the same name as the class and it’s used to instantiate objects from that class
– Every class has a by default constructor if we don’t put it manually
– The constructor is special method containing instructions for object creation. it can be said it is so called birth method. It has instructions for how the object will be born when the application starts up Static keyword Stack and heap memory Garbage collection Object oriented Programming = better organizing of code, it is a way to organize our code from multiple files by creating objects Local variable Reference variable Instance variable Inheritance
– Inheritance is the approach to get/transfer behaviour of one class to another
– We use extends keyword for inheriting, in inheritance we inherit from parent class which known as base class and the class which needs inheritation is known as child class or sub class/derived class
– super keyword it extract constructor and it’s variable from parent class but reverse is not possible Overrides
– Same method name with different purpose
– Same method name in parent class but in child class the method name is same but with different purpose
– Overrides means replace
– Override is not a good idea sometimes so we go for interface Interfaces
– Interface is a contract with a class. The class needs to implements that method of the interface according to contract
– Interface has a method which does not need body, so it is just only to define, it is called as abstract method
– one parent class
– We use implements keyword while putting interface in a class Abstract class
– When you don’t need all methods to invoke you can use abstract method, you can not make object from abstract class. Abstract method needs to be in abstract class. We use abstract keyword for both method and object to define abstract class and methods
– you can only extend abstract class but can not instantiate abstract class
– We can define abstract class as a type while creating object
Polymorphism
Loops Exception Handling
Collection Framework Wrapper class Threading Concurrency Database
Jshell Functional Interfaces Lambda expressions
-Lambda helps us to use separate from associated object
– it can run without class
– We need to use lot of interfaces for this
Streams
Ei bold kora jayga diye project banaye banaye clear korte hobe
Italic kora jaygagula motamuti clear asey In Sha Allah, Alhamdulillah
The source is : Imtiaz Ahmed’s complete Java course
Master Object Oriented Design in Java course note
Association: It defines relationship between classes, it defines how the software will behave
Dependency Association: For example from code:
1
2
3
4
5
publicclassDriver{
publicvoiddrive(Vehicle raceCar){
raceCar.accelerate();
}
}
A driver receives a vehicle reference only as driver then only he can drive or accelerate
Composition: A particular object . It imply ownership
for example in this code:
1
2
3
4
5
6
7
8
9
10
11
12
packageLesson_1;
publicclassVehicle1{
Engine myEngine;//c
publicvehicle(Engine anEngine){
myEngine=anEngine;
}
publicvoidoperateVehicle(){
myEngine.start();
}
}
Aggregation Association: It does not imply ownership
1
2
3
4
5
6
7
8
publicclassSchoolLanguageDepartment{
SpanishCourse spanish;
FrenchCourse french;
HindiCourse hindi;
BanglaCourse bangla;
}
Here Department to SpanishCourse relation is composite
But Course to Student relationship is not composite because it does not imply ownership a student can take many courses or not
1
2
3
4
5
publicclassHistoryCourse{
Student[]registeredStudent;
}
We find this relationship from above diagram, the block diamond and white diamond is the part of UML diagram
Overview of software design:
For example: Hospital Employee Management System Task of the software:
Hire and Terminate Employees
Print Reports(XML,CSV Formats)
Problem Statement:
Current status of the software
Tips for design:
– You must draw design in paper or whiteboard don’t go to code directly
– Don’t overdesign or overdraw
– We have to develop iteratively but early steps should be kept simple
– Class names should be nouns based on their intention
Single Responsibility Priniciple(SRP): Not all the things in the same class
Don’t repeat yourself(DRY):
Arrow sign always describe that it is depends on that dependency class:
DAO=Data Access Object
Single Responsibility Principle Special Notes:
A class should have only one single reason to change
Open closed principle sayings about class design:
Classes should be open for extension but closed for modification.
Open Closed Principle and Strategy pattern:
Software modules should be open for extension and closed for modification
In development lifecycle software requirements needs to be constantly pour in. If developed need to change the already made codes the design is fragile. Fragile means broken.
So open closed principle save engineers from fragile design
instanceof operator we used here in the code:
HotelManagementSystem class:
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
packageOpenClosedPrinciple;
publicclassHospitalManagement{
publicvoidcallUpon(Employee employee){
if(employee instanceofNurse){
checkVitalSigns();
drawBlood();
cleanPatientArea();
}elseif(employee instanceofDoctor){
prescribeMedicine();
diagnosePatients();
}
}
//Nurses
privatevoidcheckVitalSigns(){
System.out.println("Checking Vitals");
}
privatevoiddrawBlood(){
System.out.println("drawing blood");
}
privatevoidcleanPatientArea(){
System.out.println("cleaning patient Area");
}
//Doctors
publicvoidprescribeMedicine(){
System.out.println("Prescribed Medicine");
}
publicvoiddiagnosePatients(){
System.out.println("Diagnose Patient");
}
}
Here it is like a junk drawer
So we will make it changes because it is violating OCP principle. This chamging process is known as Strategy pattern. So let’s do it.
We could also do it with interface class except abstract class
Example after applying Strategy pattern:
Nurse.java
We depend on something in driving like car is stopping by traffic light
Imagine a life every car has different mechanism
Violation of Dependency Inversion Principle
When higher level modules depend on lower level ones succeptible to change Dangers of coupling: Tight coupling :
Well design software has single responsibility
This method says high level modules should not depend on lowlevel modules. It should depend on abstractions
Abstract classes and Interfaces don’t change as often as concrete classes/ derivatives
Cohesion means related things together.
This code I tried to run in class inside class but did not worked. Then I downloaded course code and run worked then again I tried to do with my directory structure then it worked.
Quizes from OOP course:
Q1:
Q2: The Dependency Inversion Principle states
Interfaces and abstract classes change far less often the concrete derivatives. Concrete classes should depend on Interfaces and abstract classes because they change less often and are higher level modules
Q3: In general the dependency inversion principle states that code should only depend on things that don’t change often
True Liskov Substitution Principle: Subtypes must be substitutable for their basetypes
This is a ISA relationship, Nurse and Doctor depends on Employee class. Employee class is Abstract class
When it is adding a substitute teacher who does not work as like a teacher it violates the LISKOV pronciple as per this line of definition: Subtypes must be substitutable for their basetypes
So we changed to a new UML which does not violate LISKOV principle and did the code.
New UML:
Question 1:
The Liskov Substitution principle states, that child classes should not be substitutable in place of their parents.
Interface Segregation Principle:
Fat class is a class which has too many responsibilities.
From Quiz: Main Kotha about Interface Segregation Principle:
This principle does not have to do with the number of dependencies that may exist in an application. The principle simply states that modules should not have dependencies on code they do not use.
If a module does not use functionality from another module, there is no reason to have a direct dependency between them. There should be an abstraction in between to segregate the 2 modules
Dependency Injection:
When the application is not running there is no object because onbject only available in runtime, you will find only some classes
Tight Coupling:
Cohesion:
A very popular dependency injection implementation is spring framework bundled with spring container.
Dependency injection is
Dependency Injection Using Spring: Observer Pattern: The observer pattern is a software design pattern in which an object, called the subject, maintains a list of its dependents, called observers, and notifies them automatically of any state changes, usually by calling one of their methods.
One basic UML diagram from wikipedia:
Created one for the course:
Builder Pattern:
When there is so many constructors and tough to handle it. Example codes with some bugs. Will do the solution later.
code example:
user.java
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
import java.lang.module.ModuleDescriptor;
publicclassUser{
privateStringuserName;//Required
privateStringemailAddress;//Required
privateStringfirstName;//Optional
privateStringlastName;//Optional
privateintphoneNumber;//Optional
privateStringaddress;//Optional
publicUser(Builder builder){
this.userName=builder.userName;
this.emailAddress=builder.emailAddress;
this.firstName=builder.firstName;
this.phoneNumber=builder.phoneNumber;
this.address=builder.address;
}
@Override
publicStringtoString(){
return"User{"+
"userName='"+userName+'\''+
", emailAddress='"+emailAddress+'\''+
", firstName='"+firstName+'\''+
", lastName='"+lastName+'\''+
", phoneNumber="+phoneNumber+
", address='"+address+'\''+
'}';
}
publicstaticclassBuilder{
privateStringuserName;//Required
privateStringemailAddress;//Required
privateStringfirstName;//Optional
privateStringlastName;//Optional
privateintphoneNumber;//Optional
privateStringaddress;//Optional
publicBuilder(StringuserName,Stringemail){
this.userName=userName;
this.emailAddress=email;
}
publicBuilder firstName(Stringvalue){
this.firstName=value;
returnthis;
}
publicBuilder lastName(Stringvalue){
this.lastName=value;
returnthis;
}
publicUser build(){
returnnewUser(this);
}
}
}
app.java
1
2
3
4
5
6
7
8
publicclassApp{
publicstaticvoidmain(String[]args){
User websiteUser=newUser.Builder("bobMax","[email protected]").firstName("bob").lastName("max").build();
The books which you have mentioned are a very good background when it comes to Java language. The problem with being a “backend developer” is that usually even if you don’t work on frontend you are still expected to know basics of frontend stuff.
When I’m interviewing a backend developer or rather web developer with focus on backend, I expect him to know:
Framework which we use which is Spring 3-4
Database: SQL and JPQL
Knowledge of HTML
Some familiarity with CSS
Familiarity with JavaScript and JQuery (not expert level)
Knowledge how web works: Get and post requests, rest services, json, sessions
When it comes to frameworks most popular one are Spring and Java EE6, of course there are much more but if company is using something less commonly known they less expect you to know it.
Basically if you can write from scratch a simple to-do list application all by yourself, you are ok to be junior level web dev.
In this 4th semster in Computer Science and Engineering in my university i am learning OOP(Object Oriented Programming) with Java..Here I will share with you what i have learned . 🙂
Software Engineer | Polyglot Programmer | Gym Lover | Cyclist | Algorithm Addict | Programming and Research enthusiast | Life Long Passionate Learner | Love CSE, Backend and Data
Hi, thanks for your interest on my blog 🙂 I am Syed Ahmed Zaki, from Germany. This is my blog “Zakilive.Com” for sharing my knowledge and passion with you all.
I was born in a beautiful country of south asia named Bangladesh. I am a Computer Science and Engineering graduate and currently doing my post graduation in Germany. I am passionate, dedicated, hardworking about my tasks and fond of Algorithms, Competitive Programming, Mathematics, Research in data science(Machine Learning, AI, NLP, Deep Learning), bioinformatics and IoT. I also love software engineering. In software development field I prefer Web Application Engineering.
In my bachelor study life, I tried to participate in several programming contests(online, onsite, intra etc.) and passed some time in ACM training class for sharpening my logical skills. As an ordinary people it was little bit tough for me alongside with academic pressure, thesis and research paper writing but I love challenges so I always tried to push my limits though still I need to improve a lot in everything but I always trust in this quote “Hard work beats talent”. That quote I have learned from my life through bodybuilding of 6 years since 2012 and after losing 33 KG fat in 4 months from 101 KG I developed my fit physique, so I respectfully believe in this sentence and relate this with CSE field. I also love to learn from my failures. I hate excuses while working professionally and I love trying to finish my work with perfection till the last moment before deadline.
I also love to explore and play with new technologies and try to implement it with innovative ideas. In my bachelor university life, I always tried to learn from the basics of Computer Science. So, I have tried to gather Networking to Database Knowledge, OS fundamentals to OOP etc. all fundamental core basics in my skillset in a practical approach.
Alongside with developing some web applications in core php and laravel framework I have also tried to build games with unity3d game engine, built 2 android apps, experimented machine learning with python, data mining with WEKA, AI chatbot, IoT based weather station and some more project works for my undergraduate courses. As I am language and platform agnostic, I enjoyed and learned a lot from all of these works. I also love teamwork. Alongside software engineering and different extra curricular activities I also love teaching. I am also proficient at working with linux and windows based OSes and I feel so lucky if I get chance to contribute in opensource projects. In my linkedin profile you will find more details about me.
However, I am actually a knowledge seeker and life long passionate learner who tries to make his weakness as strength, I was a serious student of all the courses in CS academia that can solve real life problems as I love to explore knowledge in a crafted manner. I love to study books, blogs or whatever philosophically solve my curiosity. For that, I maintain a good collection of various technological, scientific and philosophical books in my small library. Knowledge sharing, analytical thinking, practice and passing the passion of mine with you is one of my motivations for running this blog. I practice to hone my skills with trying to improve my programming and developing skillset day by day and what I learn, I never forget to share here for you.
In my free time I love to do cycling or gym or play racing games in my android phone or watch animated movies and also love to promote positive, fit and healthy lifestyle among people.
Currently I am working with Java technologies. If you have any opportunity/business to work with me or any other query kindly say just hi to me at my mail: [email protected]
Caution and Tips:
First, Try To Understand the Problem Statement. Second, Solve Code with Pen and Paper. Third, Then Write code and submit in the OJ to justify test cases. Fourth, If failed to AC then optimize your code to the better version. Fifth, After failed in 3rd time see my solution. Understnad the logic and implement by your own.
Please, don’t just copy-paste the code. It will kill your creativity 🙂