Tuesday, 29 September 2015

ant build: failed saying "can't find symbol" for few classes

Mistake I had made was
1. I had altered my and build.xml,
2. In the build.xml, the test target was before compile :), so since the class file is not yet generated, how can JVM load it.

ant compile issue : warning: [options] bootstrap class path not set in conjunction with 1.6

During the ant build I was facing this issue.

It caused because I had two JDK in my system, 1.6 and 1.7.

I used 1.6 in eclipse as JRE during coding but I was using cmd line for ant build.

In the command line java -version displaying JAVA_HOME as 1.7.

Solution:
Just change the JAVA_HOME via "System environment" in window or equivalent in other OS.

Open New cmd promt.

Sunday, 27 September 2015

JAVA : fibonacci with tail recursive

I recently learnt about tail recursion. I understand, many programming language compilers perform[Current java doesn't] s, code optimization when it finds a recursive method a "Tail recursive".
My understanding of TR : Compiler, does not create new stack frame(instead replace with older call's stack frame) when there is no further operation to be performed after the call has returned

With mycurrent understanding of TR, I think below is a "Tail recursive", because I am not doing any further operation, after the recursive method is returned


suppose totalSeriesLenght = 10.
public void generateFibonacciSeries(int totalSeriesLenght) {
    int firstNum = 0;
    int secondNum = 1;
    printNextFibonacciNumber(firstNum, secondNum,totalSeriesLenght);
}

public void  printNextFibonacciNumber(int fiboOne , int fiboTwo,int totalSeriesLenght) {
    if(totalSeriesLenght >= 1) {
        System.out.print(fiboOne + ",");
        int fiboNext = fiboOne + fiboTwo;           
        totalSeriesLenght --;
        printNextFibonacciNumber(fiboTwo, fiboNext,totalSeriesLenght);
    }
}