Saturday, January 21, 2012

Collection to Array of Objects

Sometimes we need to convert collection of objects to array of objects.To do so java provide a easy to use method toArray which provides  bridge between collections and older APIs that expect arrays on input.

For example : suppose bookCollection  is a Collection and we can convert it to a new Object type array as :

Object bookObjectArray [] = bookCollection.toArray();

If bookCollection contains only specific type object such as String then we may want to convert the collection to String array . And we can do that as :

String bookStringArray [] = bookCollection.toArray(new String[0]) ; 

{suppose bookCollection contain only one String }





 

Java Collection Framework Overview

Collection framework introduced in java from java 2 platform . A collection is a group of objects that represent a group of objects. Those who are familiar with C++ STL , it will be easy to understand for them as a beginner . But it's not tough concept to grab for new learner.

As a java application developer one can got some advantages with collection framework :
  • Programming effort reduction by providing useful data structures and algorithm.
  • Increase application performance.
  • Provides interoperability between unrelated APIs
  • Reduces the effort required to learn APIs
  • Reduces the effort required to design and implement APIs
  • Fosters software reuse
The collections framework consists of:
  • Collection Interfaces
  • General-purpose Implementations
  • Legacy Implementations
  • Special-purpose Implementations
  • Concurrent Implementations
  • Wrapper Implementations
  • Convenience Implementations
  • Abstract Implementations
  • Algorithms
  • Infrastructure
  • Array Utilities
There are fourteen collection interfaces.
The most basic interface is Collection. These interfaces extend Collection: Set, List, SortedSet, NavigableSet, Queue, Deque, BlockingQueue and BlockingDeque. The other collection interfaces, Map, SortedMap, NavigableMap, ConcurrentMap and ConcurrentNavigableMap do not extend Collection, as they represent mappings rather than true collections. However, these interfaces contain collection-view operations, which allow them to be manipulated as collections. (ref: http://docs.oracle.com/javase/6/docs/technotes/guides/collections/overview.html)

Collection Implementations



Implementations
Hash Table Resizable Array Balanced Tree Linked List Hash Table + Linked List
Interfaces Set HashSet
TreeSet
LinkedHashSet
List
ArrayList
LinkedList
Deque
ArrayDeque
LinkedList
Map HashMap
TreeMap
LinkedHashMap



Friday, January 20, 2012

Garbage Collection and JAVA

Introduction :
Garbage collection is an amazing feature of java. Application developer use java for different kind of application ranging form small to complex enterprise software application. So demand of garbage collection is different based on nature of java application. Java HotSpot™ virtual machine implementation (Java HotSpot™ VM) provides multiple garbage collectors, each designed to satisfy different requirements.

Question is when the choice of garbage collector is a big issue . Most of the case it is not too important. But in case of large application its tightly related to performance issue.

Performance issue of java powered application is tightly related to the proper combination of three parameter namely :

  • garbage collector,
  • heap size,
  • and runtime compiler

Available Garbage Collector :
Java HotSpot VM includes three different collectors, each with different performance characteristics.

  1. The serial collector
  2. The parallel collector
  3. The concurrent collector
Selecting a Garbage Collector :
1. If the application has a small data set (up to approximately 100MB), then serial collector is ok: and we can select it as by : -XX:+UseSerialGC. If the application will be run on a single processor and there are no pause time requirements, then
    • let the VM select the collector, or
    • select the serial collector with -XX:+UseSerialGC.
  1. If (a) peak application performance is the first priority and (b) there are no pause time requirements or pauses of one second or longer are acceptable, then
    • let the VM select the collector, or
    • select the parallel collector with -XX:+UseParallelGC and (optionally) enable parallel compaction with -XX:+UseParallelOldGC.
  2. If response time is more important than overall throughput and garbage collection pauses must be kept shorter than approximately one second, then
    • select the concurrent collector with -XX:+UseConcMarkSweepGC. If only one or two processors are available, consider using incremental mode, described below.

Tuesday, January 03, 2012

Install Apache Web Server From Source


For complete installation documentation, see [ht]docs/manual/install.html or

http://httpd.apache.org/docs/2.2/install.html
 
 Step One : Download  *.tar.gz file from the following link:

 http://mirrors.ispros.com.bd/apache//httpd/httpd-2.2.21.tar.gz

Step Two : Issue following command
$ ./configure --prefix=PREFIX

Step Three : Issue the following command
$ make

Step Four : Issue the following command (need to be root user)
$ make install

Step Five : Issue the following command
$ PREFIX/bin/apachectl start

Step Six : Now open browser and test that apache2 is running by writing the url  : http://localhost

Thta's all.



Find List of Installed Package In Debian

Package management and listing installed package in debian is a regular task to us.And simple linux command can help us to find list of packages which are installed.


To find is php is installed we can use :

dpkg --get-selections | grep php


libapache2-mod-php5                             install
php-geshi                                                 install
php5                                                         install
php5-cli                                                     install
php5-common                                           install
php5-ldap                                                 install
php5-mysql                                               install



To find is python is installed we can use :

dpkg --get-selections | grep python



gimp-python                                     install
ipython                                         install
python                                          install
python-4suite-doc                               install
python-4suite-xml                               install
python-apt                                      install
python-beagle                                   install
python-brlapi                                   install
python-cairo                                    install
python-central                                  install
python-cups                                     install
python-cupsutils                                install
python-dbus                                     install
python-dev                                      install
python-dulwich                                  install
python-eggtrayicon                              install
python-elementtree                              install
python-fpconst                                  install
python-gdata                                    install
python-gdbm                                     install
python-glade2                                   install
python-gmenu                                    install

----------

-----

And to list all installed package under debian we can simply use :

dpkg --get-selections