Skip to main content


Showing posts from September, 2014

Indexing and Searching with Apache Lucene 4.7 with Example

This article is about Indexing and Searching documents with Apache Lucene version 4.7. Before jumping to example and explanation, let's see what Apache Lucene is. Introduction to Apache Lucene Lucene is a high-performance, scalable information retrieval (IR) library. IR refers to the process of searching for documents, information within documents, or metadata about documents. Lucene lets you add searching capabilities to your application. [ ref. Apache Lucene in Action Second edition covers Apache Lucene v3.0 ] The main reason for popularity of Lucene is its simplicity. You don't require in-depth knowledge of indexing and searching process to get started with Lucene. You can start with learning handful of classes which actually do the indexing and searching for Lucene. The latest version released is 4.7 and books are only available for v3.0. Important note Lucene is not ready-to-use application like file-search program, web-crawler or search engine. It is a software t

Design patterns - Abstract Factory with Java Example

Introduction Abstract Factory design pattern comes under creational design pattern. It is also called factory of factories . It provides a way to encapsulate a group of factories which have common behaviour or theme without specifying which underlying concrete objects are created. It is one level of abstraction higher than Factory pattern. In Factory Design Pattern , we get instance of one of several sub-classes whereas in Abstract Factory Design pattern we get instance of one of several factories which then get instance of one of several sub-classes . Implementation We are going to create Factories for Import and Export. We have one producer class ImportExportFactoryProducer which produces the factory based on type i,e. if instance of ImportFactory is required or ExportStrategy is required which then initialize the concrete classes for ImportStrategy or ExportStrategy . 1. AbstractFactoryTest class package com . gauravbytes . test ; import com.gauravbytes ._impor

Serialization in Java with example

What is Serialization? Serialization is the process of encoding an object to byte stream and reverse of it is called deserialization.It is platform independent process which means you can serialize the object in one JVM and can transport the object over network and / or store it in filesystem and then deserialize it in other or on same JVM. Class needs to implements marker interface Serializable in order to make their object to be eligible for Serialization. fields with transient and/or static modifiers are not serialized by regular serialization process. ObjectInputStream and ObjectOutputStream are high level stream classes which have methods to serialize and de-serialize Java objects. ObjectOutputStream class has many write methods but the method that is usually used method is: public final void writeObject ( Object obj ) throws IOException ObjectInputStream class has many read methods but the method that is usually used method is: public final Object read