A Technology Blog About Code Development, Architecture, Operating System, Hardware, Tips and Tutorials for Developers.

Saturday, October 22, 2016

hashcode() Best Practice

9:38:00 PM Posted by Satish No comments
A good hash function tends to produce unequal hash codes for unequal objects. Ideally, a hash function should distribute any reasonable collection of unequal instances uniformly across all possible hash values. Achieving this would be ideal, but can be complex. Luckily the following rules made this easy: 1. Store some constant non zero value, say, 17, in an int variable called result. 2. For each...

Wednesday, October 19, 2016

ReflectionUtils.doWithFields()

6:47:00 PM Posted by Satish No comments
Spring has a nice Utility class ReflectionUtils that does just that: it defines a method to loop over all fields of all super classes with a callback: ReflectionUtils.doWithFields() Documentation: Invoke the given callback on all fields in the target class, going up the class hierarchy to get all declared fields. Parameters: - clazz - the target class to analyze - fc - the callback to invoke...

Wednesday, October 5, 2016

Custom Maven Plugin

7:30:00 PM Posted by Satish , No comments
When you write a custom plugin, you are going to be writing a series of Mojos (goals). Every Mojo is a single Java class which contains a series of annotations that tell Maven how to generate the Plugin descriptor. Before you can start writing Mojo classes, you will need to create Maven project with the appropriate packaging and POM. To create a plugin project, you should use the Maven Archetype...

Tuesday, September 20, 2016

Evaluate PreFix Expression

1:25:00 PM Posted by Satish , 1 comment
We have already written algorithm to convert infix expression to post fix expression. You can refer my previous post for the same. As we have already having a prefix expression and that is well known to computer, let's directly jump on to the algorithm. Algorithm: Reverse the expression. Tokenize the expression depending on the delemeter. Perform the following operations on each token. If...

Evaluate Post Fix Expression

1:15:00 PM Posted by Satish , No comments
We have already written algorithm to convert infix expression to post fix expression. You can refer my previous post for the same. As we have already having a post fix expression and that is well known to computer, let's directly jump on to the algorithm. Algorithm: Tokenize the expression depending on the delemeter. Perform the following operations on each token. If token is operand, push the...

Evaluate a mathematics expression in java

12:13:00 PM Posted by Satish No comments
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters. Learn more about bidirectional Unicode characters Show hidden characters ...

Infix to Prefix

11:26:00 AM Posted by Satish , No comments
In my previous post we evaluated the algorithm to convert a prefix expression to post fix expression. Infix to Post fix algorithm is going to be handy for writing the algorithm of Infix to Prefix. We just need few additional steps to do so. But before jumping on to the solution for computer program, let's first solve it in a mathematical way.  Before just jumping on to the algorithm and...

Infix to Post Fix

10:11:00 AM Posted by Satish , No comments
Before just jumping on to the algorithm and implementation, let's start slow. I am going to convert a infix expression first in a traditional mathematical way and then will derive the algorithm using computer language. Let me start with a simple example. Order Of Operation  Parenthesis - ( ) { } [ ]  Exponent (Right to left) Multiplication and Division (Left to Right) Addition...