Top Drools Interview Questions and Answers (2021)
In this post, questions from Drools Interviews will be answered for Experienced and Freshers. We're trying to share our experience and learn how to help you make progress in your career.
Drools Tutorial :
- What is Drool?
- What is the Drool Rule Engine?
- Architecture of Drools
- What is Drool Rule?
- How do you write drools rules?
- How to integrate Drools Rule in Spring Boot Application?
- How do you call one rule from another rule in drools?
- Why to use Drools Rule Engine?
- What are Disadvantages of Rules Engine?
- What is Backward vs. Forward Chaining?
- Which Algorithm does Drools uses by default?
- What is Pattern Matching Method in Drools?
- What is Rete Algorithm?
- What is meant by Knowledge is Everything or KIE?
- What does Drools Guvnor and Drools Expert mean?
- What is the purpose of the $ symbol before the variables?
- What is Drools Stateful vs Stateless Knowledge Session?
Q: What is Drool?
Drools is a free and open source project licenced under the Apache License 2.0 and it is compatible with any JVM and available in Maven Central Repository also.
Drools is a BRMS (Business Rules Management System). It includes a Business Rules Engine (BRE), a web authoring and rules management framework (Drools Workbench), complete runtime support for Decision Model and Notation (DMN) models at Conformance level 3, and a core development Eclipse IDE plugin.
It is written in 100% pure Java, runs on any JVM and is available in the Maven Central repository too. The Drools assists you in separating and reasoning over logic and data in business processes. It has a forward and backward chaining inference-based drools rules engine that supports forward and backward chaining.
Learn more from Drools Overview - Architecture
Q: What is the Drool Rule Engine?
- Drools is a Rule Engine or a Production Rule System that implements an Expert System using a rule-based approach. Expert systems are information-based systems that process acquired knowledge into a knowledge base that can be used for reasoning.
- A Production Rule System is Turing complete, with a focus on knowledge representation to express propositional and first order logic in a concise, non-ambiguous and declarative manner.
- The brain of a Production Rules System is an Inference Engine that is able to expand to a large number of rules and facts.
- A Production Rule is a two-part structure that uses first-order logic for reasoning over knowledge representation.
- A Rule Engine allows you to specify "What to Do" rather than "How to Do It".
Q: Explain the Architecture of Drools?
The working of Drools architecture is as follows:
Production MemoryThe Rules are stored in the Production Memory/Rule Base.
Pattern MatchingThe process of matching the new or existing facts against production rules is called pattern matching, which is performed by the Rule engine.
Working MemoryThe facts that the Inference Engine matches against are kept in the Working Memory.
AgendaA system with a large number of rules and facts which result in several rules being valid for the same fact assertion; these rules are said to be in conflict. The Agenda manages the execution order of these conflicting rules using a Conflict Resolution strategy.
Take a look at our suggested post on Java :
Q: What is Drool Rule?
A DRL Rule File (.drl)DRL (Drools Rule Language) rules are business rules that you define directly in .drl text files. A DRL file can contain one or more rules that define at minimum the rule conditions (when) and actions (then). The DRL designer in Business Central provides syntax highlighting for Java, DRL, and XML.
rule "name" attributes when <conditions> then <actions> end
Q:How do you write drools rules?
- Package - Every Rule starts with a package name. The package represents as a namespace for Rules.
- Import statement - Whatever facts you want to apply the rule on, those facts needs to be imported.
- Rule Definition - It consists of the Rule Name, the condition, and the Consequence.
Q:How to integrate Drools Rule in Spring Boot Application?
Q:How do you call one rule from another rule in drools?
We can't call a Rule from another Rule, that's the answer. Drools compares incoming data/facts to the Rules, and if the data satisfies the Rule's requirements, it is saved in an Agenda. It's likely that different rules would fit the same data or facts, so it stores matching facts in an Agenda.
Q: Why use Drools Rule Engine?
Below are the few Advantages of using Drools Rule Engine:
- Declarative Programming: A Rule Engine allows you to specify "What to Do" rather than "How to Do It".
- Logic and Data Separation: Your data is in your domain objects, the logic is in the rules.
- Speed and Scalability: The Rete algorithm,the Leaps algorithm, and their descendants such as Drools' ReteOO, provide very efficient ways of matching rule patterns to your domain object data.
- Centralization of Knowledge: You create a repository of knowledge (a knowledge base) which is executable by using rules.
- Tool Integration: Tools like Eclipse (and, in the future, Web-based user interfaces) make it possible to edit and manage rules while receiving instant input, validation, and content assistance. There are also auditing and debugging tools available.
- Explanation Facility: Rule systems effectively provide a "explanation facility" by logging the decisions made by the rule engine as well as the reasons for those decisions.
- Understandable Rules: You can set yourself up to write rules that are very similar to natural language by developing object models and, optionally, Domain Specific Languages that model your problem domain.
Q: What are Disadvantages of Rules Engine?
Here are some downsides of using a rules engine:
- Developers must put in a lot of work to learn this programming process.
- The rule engine is not a safe way to troubleshoot problems.
- One must understand how the rule engine works to consumes more memory.
- For a complex branching, a large number of rules exist.
- Rules can change over time and will take effect when the code is updated.
Q: What is Backward vs. Forward Chaining?
There are two methods of execution for a rule system:
To begin, with forward chaining, we begin to analyze data and make our way towards a specific conclusion/decision.
For example, If you want to know who the top five students out of 100 were for a specific exam. Here we will take the data and then based on the analysis decide the results. This is forward chaining
We first take a decision and then check if the decision is true or not by backtracking through sequence of events or facts.
For example, If I want to know if a specific student has passed or not?
Then I'll take a decision that student has passed without first analyzing. Here, directly we decide the result and then back track to evaluate with data processing chain and as a result, determine whether or not the decision is right.
When comparing forward chaining and backward chaining, the first one can be represented as "data-driven" (data as input), while the backward chaining can be described as "event(or goal)-driven" (goals as inputs).
Q: Which Algorithm does Drools uses by default?
The algorithm mostly used by Drools is the Rete Algorithm.
Q: What is Pattern Matching Method in Drools?
Pattern Matching, which is done by the Inference Engine, is the process of matching new or existing facts against Production Rules.
Algorithms used for Pattern Matching are:
Q: What is Rete Algorithm?
The Drools Rete implementation is known as ReteOO, and it denotes that Drools has improved and optimised the Rete algorithm for object-oriented systems.It uses node sharing to minimise or remove particular types of redundancy. While performing joins between different fact types, it stores partial matches.
Q: What is meant by Knowledge is Everything or KIE?
Knowledge Is Everything (KIE) https://www.kiegroup.org/ is an umbrella project that was created to put together all of our relevant technology under one roof. It also serves as a popular hub for all of our projects.
KIE is made up of the following projects, all of which are linked and provide a comprehensive set of business automation and management solutions:
DroolsDrools is a business rule management system with an inference-based rules engine (forward-chaining and backward-chaining) that allows for quick and accurate evaluation of business rules as well as complex event processing. A rule engine is also a key component in the creation of an expert system, which is a computer system that mimics the decision-making abilities of a human expert.
jBPMjBPM is a versatile Business Process Management suite that allows you to model your business goals by describing the steps that must be executed in order to achieve them.
OptaPlannerOptaPlanner is a problem solver that optimizes use cases such as employee rostering, vehicle routing, task assignment and cloud optimization.
Drools WorkbenchDrools Workbench is a full featured web application for the visual composition of custom business rules and processes.
UberFireUberFire is a web based workbench framework inspired by Eclipse Rich Client Platform.
Q: What does Drools Guvnor and Drools Expert mean?
Drools Guvnor is the Business Rules Manager and Drools Expert is the Business Rules Engine.
Q: What is the purpose of the $ symbol before the variables?
The aim of using the $ symbol before variables is to distinguish between variables in POJO classes and variables in Rules.
Q: What is Drools Stateful vs Stateless Knowledge Session?
A stateless session can be called like a function, with data passed in and results returned.
Stateful sessions last longer and allow for iterative improvements over time.
The rule engine is unaware of any changes in the facts when executing rules.
The rule engine is aware of any changes in the facts when executing rules.
To release the session, the dispose() method is called automatically.
To prevent memory leaks, the dispose() method should be used to release the session.
Any changes in the facts when executing rules are not communicated to the rule engine, so if a rule is changed, there will be no subsequent re-activation of rules.
Since all changes in facts are available to the rule engine, modifying a rule for a specific fact will re-activate all rules and fire the rules that are based on the changed fact.