Learn Java and Programming through articles, code examples, and tutorials for developers of all levels.
Java 8 Stream + FlatMap Example for Beginners | How to flat a list of list in Java?
How to get and set Value of a text field using jQuery? Example Tutorial
23 Design Patterns Java Developers Should know
1. Abstract Factory Design Pattern
Abstract Factory is a creational Design Pattern, which is used to control the creation of Objects.
2. Adapter design pattern
The Adapter is a structural design pattern; it is used to maintain the structure of classes in object-oriented programs like Java applications.
3. Bridge Design Pattern
The bridge is also a structural design pattern
4. Builder Design Pattern
The Builder is another creational design pattern in Java.
5. Chain of Responsibility Pattern
Chain of Responsibility is a behavioral pattern from Gang of Four. It avoids coupling the sender of a request to its receiver by giving more than one object a chance to handle the request. You actually have a chain of receiving objects, starting from lower level to higher level, request move along the chain until an object handles it.
6. Command Design Pattern
The Command Pattern is also a behavioral design pattern and uses to control the behavior of an object or set of objects in a program. The command object is used to encapsulate a request, thus allows you to parameterize clients with different requests, queue, or log requests, and also support undo sort of functionality. As the name suggests, it is used to execute commands e.g., buttons on the remote control.
7. Composite Design Pattern
Composite pattern is another structural design pattern
8. Decorator Design Pattern
Decorator is also a structural pattern
9. Facade Design Pattern
The Facade is another structure design pattern for Java developers.
10. Factory Method Design Pattern
Like Abstract Factory, this is also a creational design pattern, provides a better way to create an instance of objects in Java or any other object-oriented programming language.
11. Flyweight Design Pattern
It's a structural pattern
12. Interpreter Design Pattern
13. Iterator Design Pattern
14. Mediator Design Pattern
15. Memento Design Pattern
16. Prototype Design Pattern
17. Proxy Design Pattern
18. Observer Design Pattern
19. Singleton Design Pattern
20. State Design Pattern
21. Strategy Design Pattern
22. Template Method Design Pattern
23. Visitor Design Pattern
And here is the big diagram which shows the relationship among different object-oriented design patterns:

That's all on this list of object-oriented design Patterns, Java developers should know. In fact, this list of patterns is equally useful for any object-oriented programmer working on object-oriented languages like C++, Scala, or any other language.
These are also known as Gang Of Four (GOF) design pattern because it was first published in the GOF design pattern book. Just keep one thing in mind, design patterns are tried and tested solutions to some particular problem, but it doesn't mean you always need them.
In fact, if you are familiar with these patterns and know their intent and when to use them, you will automatically alert by your mind about places where you can use these patterns.
I always keep these patterns back of my mind, and while coding, I somehow know that, Ok, this is the place where I should use this pattern. I never use them pre-planned; in fact, they came at random while doing coding, testing, refactoring, and code review.
3 ways to sort a List in Java 8 and 11 - Example Tutorial
There are multiple ways to sort a list in Java 8, for example, you can get a stream from the List and then use the sorted() method of Stream class to sort a list like ArrayList, LinkedList, or Vector and then convert back it to List. Alternatively, you can use the Collections.sort() method to sort the list. There is also a sort() method added to the List class itself. The Collections.sort() method is an older one and it's available from JDK 1.0 itself but List.sort() is a new method added in Java 8. This method accepts a Comparator if you want to sort a List in a custom order, otherwise, you can pass null if you want to sort a List on the natural order of their elements.
How to use Spread operator and Rest parameter in JavaScript? Example Tutorial
Hello guys, if you are wondering what is Spread and Rest operator is in JavaScript are and how to use them in code then you have come to the right place. Earlier, I have shared some fundamental JavaScript concept tutorials like == vs === operator, hoisting, and destructuring, and in this JavaScirpt article, I am going to talk about Spread and Rest operators. JavaScript came out twenty-five years ago. Since then, it has changed a lot. First, it became the top programming language for client-side web development, and then with the emergence of Node.js, it also became the top player in server-side development.
What is Variable and Function Hoisting in JavaScript? Example Tutorial
Hoisting is a complex concept in JavaScript. Like other major programming languages, variables and functions are an important part of JavaScript. Being a dynamically typed programming language, the variable declaration does not require specifying variable types. JavaScript also supports functions. But there is a catch. When variables and functions are declared in JavaScript, a process called hoisting takes place, and if you don't know this important concept you may struggle reading and understanding code but don't worry. In this article, I will teach you what is hoisting in JavaScript and give you real-world examples of the function and variable hoisting to start with.
What is Destructuring in JavaScript? Example Tutorial
Arrays and objects play a very important role in programming. Every major programming language supports arrays and objects. Both arrays and objects are used to store data. The concept is simple but very powerful. JavaScript also supports arrays and objects. In fact, they are a very important part of modern JavaScript development. It does not matter if you are working on the frontend or backend, you are going to use arrays and objects. Over time, more and more features were added in JavaScript to make it easy to work with arrays and objects.
Difference between first level and second level cache in Hibernate
Difference between IN, OUT, and INOUT parameters in JDBC Stored Procedure? Answer
Hello guys, Java Database Connectivity, the JDBC API supports three types of parameters, I mean, IN, OUT, and INOUT. They are used to bind values into SQL statements. An IN parameter is the one whose value is unknown when the SQL statement is created and you bind values using various setXXX() method depending upon the type of column those IN parameter refers in SQL query. For example in SQL query, SELECT * from EMPLOYEE where EMP_ID=? if the EMP_ID is a VARCHAR column then you must call the setString() method to pass the value to the IN parameter.
How to create a custom tag in JSP? Steps and Example
You can create a custom tag in JSP either by implementing the SimpleTag interface or extending SimpleTagSupport class. Custom tags are introduced in JSP 2.0 in an effort to minimize Java code from JSP to keep them maintainable and allow page authors to work more in HTML or XML, like environment than writing Java codes. SimpleTag and SimpleTagSupport allow you to create a custom tag in JSP. It's easier to start with SimpleTagSupport class because it implements all methods of the SimpleTagSupport interface and if you are writing a basic tag then you just need to override the doTag() method of this class.
How to manager HTTP Session in JSP Servlet?
Since HTTP is a stateless protocol its not possible to identify that two separate HTTP request is coming from same client and HTTP session management handle that issue for us. By maintaining a session for each client at the Server side, we can serve the client better, for example, you can store authentication and authorization information in session to prevent authenticating client for each HTTP request like in an online banking system, a session is created when a user is successful authenticated and session is maintained at server untile clients logout or session times out. If you have to write such online banking system using Java and Java EE technologies like Servlet and JSP then main question arises is how to do session management in JSP?
There are mainly three ways to manage session in JSP applications 1) using hidden html fields 2) using Cookie and 3) using URL rewriting. In Cookie small piece of information is stored in client machine but User can turn off this option and may be there is case of browser not supporting cookies, on all those cases URL rewriting is the best option to manage session in JSP Servlet application. JSTL core tag library provides tag which can encode URL for managing session.
How to use lifecycle methods in functional components in React.js? useEffect() hook Example Tutorial
Hello guys, if you have been following my blogs then you know that I have launched a new series - React for Java developers and this is the 4th article on the series. Earlier, we have seen state management in React, Redux, and useState hooks example, and in this article, you will learn about how to use lifecycle methods in functional React components. Lifecycle methods are powerful features provided by React.js in the class-based components. Each of the lifecycle methods executes at a particular time during the lifecycle of a component.
What is Redux Thunk in React.js? Example tutorial
Hello folks, This is the 3 part of my React for Java developer series and in the past two articles we have been focusing on statement management in React and we have seen that how to use manage state using Redux and useState hooks. And, in this article, we will learn about Redux Thunk, another useful concept when it comes to statement in React.js. State management is one of the most important concepts in react. If you are a react developer, then you must have used state in your project. There is no react project without a state. The state is defined as an instance of a component. It is an object that controls the behavior of a component.
How to use JSTL tag libray in JSP pages?
JSTL stands for JavaServer pages Standard tag library, which was created to help JSP developer with common tasks e.g. iterating over Collection in JSP, printing values, encoding URLs etc. In order to use JSTL tags in JSP page you need to do things, first you need to add standard.jar and jstl.jar in your Web application's classpath. This you can do by putting these two jar files into WEB-INF/lib directory. Once you do this you need to import the JSTL tag library in your JSP page to use JSTL tags like out, foreach, or forTokens etc.
Can you Overload or Override main method in Java? Example
4 Examples of Stream.collect() method in Java 8
Difference between List and ArrayList Reference Variables in Java? Example Tutorial
How to Increasing Heap Size of Java application in JVM? Example Tutorial
How to access JSTL variable in Scriptlet?
You can access the JSTL variable inside the scriptlet by calling the getAttribute() method on pageContext, request, response, or session objects, depending upon which scope your JSTL variable was created. For example, if your JSTL variable is created on request scope, you can call request.getAttribute("count") to get value of a variable named count. A JSTL variable is a variable that is created using a set tag and belongs to a particular scope, by default they are created in page scope.