Category Archives: Programming

Java – Replace First Occurrence of String without Regular Expression

Java – Replace First Occurrence of String without Regular Expression

           The String class in Java has a method replaceFirst(String regex, String replacement) which replaces first occurrence of given regular expression with given replacement string. If you want to replace first occurrence of any given string (with Regular Expression), use the following code. Sample Code: package test; import java.util.regex.Pattern; public class test{… Read More »

Send EMail (GMail/Google Mail) using Java Mail API

Send EMail (GMail/Google Mail) using Java Mail API

           This article details on how to send mail (GMail/Google Mail) using Java API. Google by default does not allow any 3rd party applications to access GMail account from any programming language. Google provide an option to turn on Less secure apps to get access from external applications. The following program works if… Read More »

Execute Raw Elasticsearch Query using Transport Client – Java API

Execute Raw Elasticsearch Query using Transport Client – Java API

           The following sample program details on how to execute raw Elasticsearch query using Transport Client (Java API).  Maven Dependencies: <dependencies> <dependency> <groupId>org.elasticsearch</groupId> <artifactId>elasticsearch</artifactId> <version>1.5.0</version> </dependency> <dependency> <groupId>org.json</groupId> <artifactId>json</artifactId> <version>20140107</version> </dependency> </dependencies>            Add the above MAVAN dependencies to the POM file or add the JARs specified in… Read More »