Search Tutorials


JBoss Drools Interview Questions with explanations | JavaInUse



Drools Interview Questions


In this post we will look at Drools Interview questions. Examples are provided with explanation.

Q: What is Drools?
A:
Drools is a Business Rules Management System (BRMS) solution. Using this framework users define rules that specify what action needs to be done when a particular condition is met.It extends and implements the Rete Pattern matching algorithm. In projects its usually used to define Business Rules. Business rules are composed of facts and conditional statements.
Detailed explanation of Drools with examples are given in this post.

Q: Why use Drools and not other programming languages ?
A:
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.

Q: What is meant by KIE?
A:
KIE stands for Knowledge is everything. It stands for Knowledge is everything. From Drools 6.0 onwards a new approach is used to create a Knowledge Base and a Knowledge Session. Knowledge base is an interface that manages a set of rules and processes. The main task of the knowledge base is to store and re-use rules because creation of rules is very expensive.Rules are contained inside the package org.drools.KnowledgeBase. These are commonly referred to as knowledge definitions or knowledge. Knowledge base provides methods for creating a Session.
Drools KIE hello world example.
Q:What are Decision Tables? Have you used it?
A:
Drools Decision Tables are excel based decision tables. The main advantage of Drools is that the logic can also be changed by a non technical person. But if we look at the .drl file, any modification will also require technical knowledge. As the .drl becomes more complicated the more difficult it will become for non technical persons like Business Analysts. Also frequent changes to the drools file is cumbersome.Hence this format, decision tables, is a very good option to use where something is going to be changed frequently by non-programmers.
Drools Decision Table example

Q:What is JBoss Enterprise BRMS?
A:
JBoss Enterprise BRMS is the reasoning engine for policy and rule developments for business. It also manages access and changes.

Q:What is JBoss Enterprise BRMS?
A:
JBoss Enterprise BRMS is the reasoning engine for policy and rule developments for business. It also manages access and changes.

Q:What is the productized version of Drools?
A:
JBoss Enterprise BRMS is the productized version of Drools and it has enterprise level support.

Q:What is meant by accumulate in DRL Drools?
A:
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())
The accumulate is explained in post-
Understanding accumulate in Drools using Simple Example

Q:What is meant by Drools Stateful vs Stateless Knowledge Session?
A:
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.
Differences with examples are there in post-
Difference between Stateful and Stateless session

Q:How is Backward chaining implemented in Drools?
A:
In Backward Chaining we first take a decision and then check if the decision is true or no by backtracking through sequence of events. For example if i want to find out if a particular student has passed or not? Then i will take a decision that the student has passed. Then analyze the data by backtracking through the sequence of analysis of data. Accordingly its decided if the decision is correct or not. Based on requirement either of the two approaches can be used. Sometimes the combination of both forward and backward chaining is also used. Backward chaining is often referred to as derivation queries and drools implements it with query construct. Further simple example can be found in this post-Backward chaining using Drools
Q:Which Drools attributes have you used?
A:
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.
These attributes are explained in post-
Understanding attributes salience, update statement and no-loop using Simple Example

Q:What are the different execution control statements in drools?
A:
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.
These execution control statements are explained in post-
Q:Have you integrated Drools with other frameworks?
A:
Yes have used Drools with Spring Framework. Drools Tutorials- Integration with Spring

Understanding Execution Control in Drools using Simple Example
Top Java Data Structures and Algorithm Interview Questions 
JBoss Drools Hello World JBoss Drools Hello World-Stateful Knowledge Session using KieSession JBoss Drools- Understanding Drools Decision Table using Simple Example Understand Drools Stateful vs Stateless Knowledge Session Drools Tutorials- Backward Chaining simple example Drools Tutorials- Understanding attributes salience, update statement and no-loop using Simple Example Drools Tutorials- Understanding Execution Control in Drools using Simple Example Drools-Main Menu.