Skip to main content

Posts

Deep Cloning In Java

I have already mentioned about cloning in my previous post and also the types of cloning in java i.e. 1. Shallow cloning and 2. Deep cloning We have already seen what is shallow cloning, how to use it and the example to demonstrate it in my previous post you can read about it here . In this post we will discuss about deep cloning in java. Deep cloning basically refers to creating an exact copy of an object that means if we have a object class Person() {  String name;  Address address; //rest of the code } class Address () {  String state;  String city; //rest of the code } Now if I create a deep clone of the object "Person" then it will also create a new object of the "Address" and not a reference. Just to verify you can try making changes to the new "Address" object and then see if you still having the same value in the main object. That will be different if not then something is wrong. For creating a Deep clone you can use ei...

Shallow cloning in Java

Cloning basically refers to creating an identical copy of an existing object.  The term  clone  is derived from  κλών , the Greek word for "twig, branch", referring to the process whereby a new plant can be created from a twig. The word 'Cloning' in java refers to the same meaning. When we say we have created a clone object in java we mean we have created a new object with identical values in the object. There are two type of cloning in java as below : 1. Shallow cloning 2. Deep cloning Since this article is about shallow cloning will give description about that only and will include about the deep cloning in my next post. Shallow cloning : So shallow cloning is nothing but creating a clone of the object but not in detail. Now what does that mean? It means that if you have a object with referenced object in your main object then shallow cloning will not clone them, it will just clone the attribute of the main object.  Let's take an example : ...

Multiple Instances of GTalk

How to use Gtalk on Windows with multiple Gmail accounts? Here is the solution... I was using a chat messenger which use to support multiple messenger but after using it for some time I realized that my machine has become unresponsive :P. So I decided to come back to my old lovely GTalk but the only problem is we can not have multiple instance of  'The GTalk'. So I searched for an solution and luckily I found one. Step I Create a shortcut for gtalk and let's keep it on desktop. Step II Now right click on the shortcut icon and select 'Properties'. Step III In Shortcut tab the value for 'Target' will be something like "C:\Users\Home\AppData\Roaming\Google\Google Talk\googletalk.exe" /startmenu (The above value will change according to your gtalk location but they will be quite similar) Now change this value to "C:\Users\Amol\AppData\Roaming\Google\Google Talk\googletalk.exe" /startmenu /nomutex i.e. add "/nomutex...

Create Table in Liquibase

For creating table using liquibase you can use below code and add it in your liquibase file. <createTable tableName=“employee”>      <column name="id" type="int">      <constraints primaryKey="true" nullable="false"/>   </column>      <column name="first_name" type="varchar(255)"/>   <column name="last_name" type="varchar(255)"/>   <column name="username" type="varchar(255)">      <constraints unique="true" nullable="false"/>   </column> </createTable> The use is pretty simple it's the way it looks : Tag: <createTable></createTable> This is an opening/ending tag for creating a table. These tags will enclose column sub tags which will define columns for the table. Attribute:   tableName : Name of the table which you want to create. (This is a mandatory   ...

Couldn't execute 'show fields from `association`'

Encountered this error while taking mysql dump mysqldump: Couldn't execute 'show fields from `association`': Can't create/write to file '/tmp/#sql_647f_0.MYI' (Errcode: 2) (1) Reason : Can’t find tmp location to save it’s files OS :  centos Solution : Step I Open my.cnf (in this case it was at the location /etc/my.cnf). Step II Under [mysqld] add one more parameterad as : tmpdir=/var/tmp that solved the problem Usually mysql uses /tmp or /var/tmp or /usr/tmp for storing it’s variable but if it doesn’t then try the above method.

Failed to connect to remote VM. Connection refused.

Encountered this error while trying to debug my project. IDE: Eclipse Server: Jboss Error:  Failed to connect to remote VM. Connection refused. Reason : When we install JBoss server the debug option is disabled by default. Solution : Go to ur jboss directory “<directory>/bin” and edit run.bat. Search for: rem set JAVA_OPTS = -Xdebug -Xrunjdwp:transport=dt_socket, address=8787, server=y, suspend=y %JAVA_OPTS% ‘rem’ in above statement shows that this line is comments. So remove ‘rem’ and set suspend=n.

Carnivorous Island from "Life of PI"

Yann Martel described about an floating carnivorous Island for symbolizing that something seemingly good in life can turn out to be harmful, so we should keep going with our journey of life... About the carnivorous Island from movie. In the movie 'Life of PI' after PI struggles to live in the pacific with the Bengal tiger suddenly one morning Pi  found himself at a Island. After spending so many days in the middle of the sea he found himself very lucky to find a Island. After spending some time he thought might be this was the end of his suffering and he can spend rest of his life at that island. He makes h is bed on a tree and sleeps there, in the middle of the night he wakes up and find that there were dead fish in the fresh water where he took swim in the day time. While trying to understand the mystery he plucks a fruit from the same tree and peel it off and finds a human tooth inside that fruit and then he realize that it was an carnivorous Island. The...