Showing posts with label Tech Tips. Show all posts

"Covariant return" in Java : Changing return type of a overridden methods...  

Posted by ChEthAn in

Java 1.5 come up with a feature of changing the return type of an overridden method in a subclass this is known as covariant return.

Here I had given an example, how we can override the method of super class with a covariant return in sub class.

/************************************************/
package org.sample;

public class SuperClass {

public SuperClass sampleMethod (int count){
System.out.println("I am in Super class");
return new SuperClass();
}
}
/************************************************/
package org.sample;

public class SubClass extends SuperClass {
public SuperClass sampleMethod (int count) {
System.out.println("I am in Sub class");
return new SuperClass();
}
/**
* @param args
*/
public static void main(String[] args) {
SuperClass sc = new SubClass();
sc.sampleMethod (5);
}
}

/************************************************/
When we run "SubClass" class, we will get output as
I am in Sub class

This shows that we can change the return type of the overriding method only if the new return type is a subtype of the declared return type. And another thing we have to keep in mind is, this Covariant return type is possible only in java 1.5 and in advance version.

Lucene by default can index only first 10000 words...  

Posted by ChEthAn in


In my last project I was using Lucene for indexing and searching the documents. For parsing of documents I was using external libraries like PDFBox, POI and J-Tidy, which first parse the document and extract the data out of it then lucene was adding that extracted text to index.

But while searching, I wasn't able to search certain words which were at the bottom of the document. Almost for a day I was not able to find any reason for that.

Finally I came to know that By default Lucene can index only first 10000 words. So thats why I wasn't able to search few words. As there wont be any error's, it is difficult for User/developers to know about real problem.

So in order to index whole document you have to set the max_field_length of IndexWriter explicitly otherwise by default lucene will index only 10,000 words.

Sample Code Snippet :-

private static final int MAX_FIELD_LENGTH = 100000;//user configurable(By default 10000)

IndexWriter indexWriter = new IndexWriter(LUCENE_DIR,new StandardAnalyzer(),false);
indexWriter.setMaxFieldLength(MAX_FIELD_LENGTH);

WordPress via Fantastico :- "You can not install more than one script in the root directory of a domain"  

Posted by ChEthAn in

Few people have come across problem stating "You can not install more than one script in the root directory of a domain" while installing WordPress via Fantastico.
Even though WordPress was uninstalled and there were no installation files/directories present in that. Then also user was not able to install New WordPress via Fantastico.

Can you guess the reason for it?

Simple issue but which is very fundamental, people must know it.


Steps for fixing the issue:

Verification step: Check User's root directory i.e public_html directory under the user home directory for any present installation related files or directories.If you get any installation related file or directory then delete that and try to install it again.

In case there is no installation related file or directory then ........? ?
Go to hidden directory ".fantasticodata" inside user's home directory and check the the entry inside "installed_in_root.php".

If culprit was like this:


$installed_in_root["3091111.com"] = 1;
?>


Then change it to


$installed_in_root["3091111.com"] = 0;
?>

And then try to install New WordPress. This time you are able to install it properly :)