Drools Interview Questions and Answers

1.What is Drool?

Ans: Drools is the Business Rule Management System (BRMS) provided by the JBoss Community for implementing complex applications with automatic behaviors based on rules. The framework is essentially based on an extension of the Rete pattern-matching algorithm.

2. Why use Drools and not other programming languages ?

Ans: The rules logic can be done in a programming language like Java .Consider a Jewellery shop which needs to maintain business logic of calculating discount based on the type of Jewellery. But such rules may change daily and need to be updated regularly in our code which is not good. Also we will always require a Developer for making such changes. So its a good practice to define this logic as rules in a Business Rule Management System. If tomorrow the discount is to be changed this can be done even by a non technical person.

3.What are Drool Workbench, Expert, and Fusion?

Ans: Drools Workbench is the web user interface for authoring and management. Drools Expert is the business rule engine and Drools Fusion is the complex event processing feature.

4. What is meant by accumulate in DRL Drools?

Ans: Accumulate is conditional element that was introduced in Drools version 4.0. It is used to iterate over the list of objects and help validation of data in Java operation.

Ex. accumulate (Counter() ; $cnt : count())

5.What is Drool flow?

Ans: Drool flow provides workflow capabilities to the drool platform. Workflow describes the order of steps that need to be executed. Drool flow allows users to execute and monitor their business logic.

6. What is meant by accumulate in DRL Drools?

Ans: Accumulate is conditional element that was introduced in Drools version 4.0. It is used to iterate over the list of objects and help validation of data in Java operation.

ex. accumulate (Counter() ; $cnt : count())

7.What is meant by Drools Stateful vs Stateless Knowledge Session?

Ans: Stateless session that forms the simplest use case, not utilizing inference. A stateless session can be called like a function, passing it some data and then receiving some results back. Stateful sessions are longer lived and allow iterative changes over time.

Stateless Session

  • Any changes in the facts while executing rules is not made aware to the rule engine.
  • dispose() method is called automatically to release the session.
  • Any changes in the facts while executing rules is not made aware to the rule engine so if any rule is modified no other re-activation of rules will take place.

Stateful Session

  • Any changes in the facts while executing rules is made aware to the rule engine.
  • dispose() method should be called to release the session to avoid memory leaks.
  • As any changes in facts is available to the rule engine so if a rule is modified for a particular fact, this change will re-activate all the rules and fire the rules that are build on modified fact.

8.Which Drools attributes have you used?

Ans: Have used following attributes-

  • Salience is a prioritization value. Drools uses it in order figure out which drool to fire first when it is the case that the constraints for more than one rule are satisfied.
  • Using update makes the rules engine aware that a fact has been modified. This may cause other depending rules to get fired again.In some scenarios as shown below it cause indefinite looping.
  • Indefinite looping can be avoided using the no-loop attribute as shown in below example.

9. What are the different execution control statements in drools?

Ans: If your KieBase defines multiple rules and if you want to selectively execute a subset of them, Drools provides several features to accomplish that.

  • agenda-group:This is an optional keyword. It can be assigned for all rules. If not assigned to any agenda group, the rule by default belongs to ‘main’ agenda.
  • ruleflow-group: This behaves exactly similar to agenda-group, except that it is generally used for rules used from jBPM process flows.
  • activation-group is a reserved keyword in drools drl file. There can be a single rule or multiple rules that can belong to a particular activation-group. Rules that belong to activation-group fire in similar fashion to “if..else if..else” block in java. In an activation group only one rule can fire at a time.

10.What is the standard supported by Drool?

Ans: Drool supports JSR-94 standards for the business rule engine. It also supports enterprise framework for construction, enforcement, as well as maintenance of business policies.

Go through the Drool Video to get clear understanding of Drool.

11.What is meant by Drools Planner?

Ans: Drools Planner or automated planning optimizes the process including the NP-hard planning problems.

12. What is the purpose of dialect in Drools?

Ans: Dialect or mve1 points to the Getter and Setters of the variables of plain old Java objects (POJO). Dialect “java” is used for writing Java code in the rules.

13. What is the restriction in using Java code?

Ans: User cannot use Java code inside “when” part of the rules. However, it can be use in the “then” part.

14.What is provided by Drools?

Ans: Drools provides core Business Rules Engine (BRE) and Web Authoring and Rules Management Application (Drools Workbench) as well as the Eclipse IDE plugin for core developments.

15.How do we implement backward chaining in Drools?

Ans: In background chaining, the first user takes a decision and then checks whether the decision is true or not by tracking the sequence of events. It is also referred to as derivation queries and drools implements that through query construct.

16.What is the use of dialect in Drools?

Ans: Dialect is used to write Java code in the rules and  points to the Getter and Setters of the variables of POJO (plain old Java objects) 

17. Why is the symbol “$” used in Drools before variables?

Ans: The symbol “$” is used before variables in Drools to make sure that there is a difference between variables of Rules and the POJO class.

18.What is the global variable in Drools?

Ans: The global variable in Drools is the keyword. Global is the variable used in Drool and is visible in all rules inside the DRL file.

19.. How should the global variable be used in DRL file?

Ans: Global variables can be used extremely carefully in DRL file. Changes in global variable are not modified in working memory and hence care in handling them is required.

20.What is meant by Drools Recursive Rules?

Ans: A Fibonacci series is the most common example of recursion in Drools. In the Drools the implementation is carried out using the insert and modifies keywords.

21. What are the most important parts of Recursion in Drools?

Ans: The three most important parts of in the process of implementation of recursive rules in Drools are inserting keywords in ‘then’ part, not keyword used in ‘when’ part, and ‘breaking condition’.