Graph of various Continuous density distributions


How To Install Apache Tomcat 8 on Ubuntu without using apt-get

Sometimes you would want to install the latest version of tomcat server but your using apt-get doesn’t work for you. I had to go this route when my IntelliJIDEA IDE didn’t like my apt-get way installed tomcat server.

Before trying below make sure you have java installed and system variable JAVA_HOME has been set properly.

Step 1 : Get the latest version of tomcat server

Note: Change the file url and file name based on what is latest available by looking into following URL:

Step 2 : Unzip tomcat installation files
tar xzvf apache-tomcat-8.0.0-RC10.tar.gz
sudo mv apache-tomcat-8.0.0-RC10 /usr/local
Step 3 : Setup system variable
nano ~/.bashrc

this will open up a text editor. Go to the end of the file (Alt+/) and add the following line:

export CATALINA_HOME=/usr/local/apache-tomcat-8.0.0-RC10

save and exit (Crlt+X and Y)

Step 4 : Load new configuration
. ~/.bashrc

Step 5 : Test your setup
Start tomcat server

sudo $CATALINA_HOME/bin/

Then open this URL in your browser


If everything is alright, you would see tomcat’s webapp GUI.

How to remove null reference in a Java List

If you have a list like below

List list = new ArrayList();


Following one liner will remove all the null enteries from list


C++ Vector Manipulation code example

Beginner level code example

Objective of the Code:
• To test a class and its functions.
• To create a vector.
• To modify the values of a given vector.
• To multiply the vector by a scalar.
• To find the dot product of two vectors.
• To find the cross product of two vectors.
• To count the number of vectors present in the main program.
• To display the vector in the form like [10 20 30…. ]

Algorithm Used:

• We initialize a vector containing an array: ‘coef’ to hold the coefficients of vectors, a variable ‘t_no’ to hold the name of positions of the components of the vectors and a static variable ‘no’ just to show the usage of a static members.
• As we require maximum three vectors to meet any of our stipulated goals, so we initialize only three instance (objects) of vector class. Numbers of vector in the program before cross or dot product operation will be 2, and after that operation it will be exactly 3.
• We have define different functions like
o Getdata (changes value of coef array)
o Extractdata (return value of coef array)
o Putdata (print values of coef array on screen)
o Scalar_multi(for scalar multiplication of two vectors)
to encapsulate the data by not directing accessing member variables.
• To find dot product of the two vectors we multiplied corresponding coefficients values and add them up.
• To find cross product of the two vectors we followed the standard vector multiplication formula and put the resultant values as coefficient of third vector.
• Cross or dot product will cause the creation of third vector.

All rights reserved (Copyrighted 2012)
One can reuse this code for non-commercial purposes.


#ifdef __cplusplus
  //Macro for "max" function:to find maximum of two arguments
  int max (int value1, int value2);        

  int max(int value1, int value2)
     return ( (value1 > value2) ? value1 : value2);

class vector
   //Direct access to this variable is not being allowed
   float coef[30];   
   static int no;
     int t_no;
     void getdata(float coef1)//Enters the elements of coef array
     float extract_data(int x)//Extract the elements of coef array
      return coef[x];

    void putdata()//Prints the contents of coef array
     cout<<"  [";
     for(int i=0;i>n1;
      cout<<"INVALID INPUT!!";
    cout<<"Coefficients of the first vector:-"<>coef1;

    cout<<"Please enter the Dimension for the Second vector:";
      cout<<"Dimension is too big!!";

    cout<<"Coefficients of the Second vector:-"<>coef1;

	  else if(ch1==2)

	   else if(ch1==2)
	    cout<(n1+n2)) cout<

How to setup Java and Eclipse for first time

The video illustrates how to download and install latest JDK and Eclipse software, and how to write a Hello World program using java.

If you are interested to know how to run a high memory application in eclipse , click here for important information on how to edit eclipse.ini

Black screen or cursor blinking when windows 7 starts in bootcamp

If somehow your Bootcamp windows installation on your macBook or iMac get corrupted and you see a black screen whenever you try to boot into Windows 7 32bit or 64bit.

Try following steps:
1. Put the Windows 7 installation disc in the disc drive, and then start your computer.
2. Hold down Option key till all available disks are displayed and select DVD. Press a key when you are prompted.
3. Select a language, a time, a currency, a keyboard or an input method, and then 4. click Next.
5. Click Repair your computer.
6. Click the operating system that you want to repair, and then click Next.
7.In the System Recovery Options dialog box, click Command Prompt.

8. Type
Bootrec.exe /FixMbr
Bootrec.exe /FixBoot
Bootrec.exe /RebuildBcd

Press ENTER after each command.

9. Restart your computer.

Sort a Map by its value

Below is a method which takes input as an unsorted map and returns a sorted one.
The task is accomplished by creating an anonymous java class.

For example: if original map is


The returned map would look like


public static > Map sortByValues(final Map map)
		Comparator valueComparator = new Comparator() {
			public int compare(K k1, K k2)
					int compare = map.get(k2).compareTo(map.get(k1));
					if (compare == 0)
						return 1;
					else return compare;
		Map sortedByValues = new TreeMap(valueComparator);
		return sortedByValues;

Let me know if you have a question.

Regular expressions for valid IP version 4 and IP version 6 addresses

This uses java.util.regex.Pattern

Regular Expressions are

Pattern IPV4_PATTERN = Pattern.compile("^(25[0-5]|2[0-4]\\d|[0-1]?\\d?\\d)(\\.(25[0-5]|2[0-4]\\d|[0-1]?\\d?\\d)){3}$");
Pattern IPV6_PATTERN= Pattern.compile("^(?:[0-9a-fA-F]{1,4}:){7}[0-9a-fA-F]{1,4}$");
Pattern IPV6_HEX_COMPRESSED_PATTERN	= Pattern.compile("^((?:[0-9A-Fa-f]{1,4}(?::[0-9A-Fa-f]{1,4})*)?)::((?:[0-9A-Fa-f]{1,4}(?::[0-9A-Fa-f]{1,4})*)?)$");

Here is a demo

public static void main(String args[])
 String exampleIP="";
 System.out.println("Is it a valid IP?:"+IPV4_PATTERN.matcher(exampleIP).matches()); 


Let me know if you have any questions.

Why use Hibernate Framework

Hibernate is concerned with helping your application to achieve persistence. So what is persistence? Persistence simply means that we would like our application’s data to outlive the applications process. In Java terms, we would like the state of (some of) our objects to live beyond the scope of the JVM so that the same state is available later.

Relational Databases
Specifically, Hibernate is concerned with data persistence as it applies to relational databases (RDBMS). In the world of Object-Oriented applications, there is often a discussion about using an object database (ODBMS) as opposed to a RDBMS. We are not going to explore that discussion here. Suffice it to say that RDBMS remain a very popular persistence mechanism and will so for the foreseeable future.

The Object-Relational Impedence Mismatch
‘Object-Relational Impedence Mismatch’ (sometimes called the ‘paradigm mismatch’) is just a fancy way of saying that object models and relational models do not work very well together. RDBMSs represent data in a tabular format (a spreadsheet is a good visualization for those not familiar with RDBMSs), whereas object-oriented languages, such as Java, represent it as an interconnected graph of objects. Loading and storing graphs of objects using a tabular relational database exposes us to 5 mismatch problems…

1. Granularity
Sometimes you will have an object model which has more classes than the number of corresponding tables in the database (we says the object model is more granular than the relational model). Take for example the notion of an Address…

2. Subtypes (inheritance)
Inheritance is a natural paradigm in object-oriented programming languages. However, RDBMSs do not define anything similar on the whole (yes some databases do have subtype support but it is completely non-standardized)…

3. Identity
A RDBMS defines exactly one notion of ‘sameness’: the primary key. Java, however, defines both object identity (a==b) and object equality (a.equals(b)).

4. Associations
Associations are represented as unidirectional references in Object Oriented languages whereas RDBMSs use the notion of foreign keys. If you need bidirectional relationships in Java, you must define the association twice.

Likewise, you cannot determine the multiplicity of a relationship by looking at the object domain model.

5. Data navigation
The way you access data in Java is fundamentally different than the way you do it in a relational database. In Java, you navigate from one association to an other walking the object network.

This is not an efficient way of retrieving data from a relational database. You typically want to minimize the number of SQL queries and thus load several entities via JOINs and select the targeted entities before you start walking the object network.

Benefits of using Hibernate:

Natural Programming Model: Hibernate lets you develop persistent classes following natural Object-oriented idioms including inheritance, polymorphism, association, composition, and the Java collections framework.

Transparent Persistence: Hibernate requires no interfaces or base classes for persistent classes and enables any class or data structure to be persistent. Furthermore, Hibernate enables faster build procedures since it does not introduce build-time source or byte code generation or processing.

High Performance: Hibernate supports lazy initialization, many fetching strategies, and optimistic locking with automatic versioning and time stamping. Hibernate requires no special database tables or fields and generates much of the SQL at system initialization time instead of runtime. Hibernate consistently offers superior performance over straight JDBC coding.

Reliability and Scalability: Hibernate is well known for its excellent stability and quality, proven by the acceptance and use by tens of thousands of Java developers. Hibernate was designed to work in an application server cluster and deliver a highly scalable architecture. Hibernate scales well in any environment: Use it to drive your in-house Intranet that serves hundreds of users or for mission-critical applications that serve hundreds of thousands.

Extensibility: Hibernate is highly customizable and extensible.
Comprehensive Query Facilities: Including support for Hibernate Query Language (HQL), Java Persistence Query Language (JPAQL), Criteria queries, and “native SQL” queries; all of which can be scrolled and paginated to suit your exact performance needs.

Features of Hibernate

Hibernate 3.0 provides three full-featured query facilities: Hibernate Query Language, the newly enhanced Hibernate Criteria Query API, and enhanced support for queries expressed in the native SQL dialect of the database.

Filters for working with temporal (historical), regional or permissioned data.

Enhanced Criteria query API: with full support for projection/aggregation and subselects.

Runtime performance monitoring: via JMX or local Java API, including a second-level cache browser.

Eclipse support, including a suite of Eclipse plug-ins for working with Hibernate 3.0, including mapping editor, interactive query prototyping, schema reverse engineering tool.

Hibernate is Free under LGPL: Hibernate can be used to develop/package and distribute the applications for free.

Hibernate is Scalable: Hibernate is very performant and due to its dual-layer architecture can be used in the clustered environments.

Less Development Time: Hibernate reduces the development timings as it supports inheritance, polymorphism, composition and the Java Collection framework.

Automatic Key Generation: Hibernate supports the automatic generation of primary key for your.

JDK 1.5 Enhancements: The new JDK has been released as a preview earlier this year and we expect a slow migration to the new 1.5 platform throughout 2004. While Hibernate3 still runs perfectly with JDK 1.2, Hibernate3 will make use of some new JDK features. JSR 175 annotations, for example, are a perfect fit for Hibernate metadata and we will embrace them aggressively. We will also support Java generics, which basically boils down to allowing type safe collections.

EJB3-style persistence operations: EJB3 defines the create() and merge() operations, which are slightly different to Hibernate’s saveOrUpdate() and saveOrUpdateCopy() operations. Hibernate3 will support all four operations as methods of the Session interface.

Hibernate XML binding enables data to be represented as XML and POJOs interchangeably.

The EJB3 draft specification support for POJO persistence and annotations.

Above text is taken from and

How to get Exception Stacktrace to String

If you ever wanted to execute something like:


Then you have come to the right place.


will return a string which would contain stacktrace. Later, you can log that in a DB or in a file or just print on console.

    public String getStringStackTrace(Throwable t)
            StringWriter sw = new StringWriter();
            PrintWriter pw = new PrintWriter(sw, true);
            return sw.toString();

Here is one usage example:


public class Test {

	public static void main(String args[])

					throw new RuntimeException("Test getStringStrackTrace");
				} catch (Exception e)



java.lang.RuntimeException: Test getStringStrackTrace
	at com.trgr.cobalt.performance.integrationtests.Test.main(