Thursday 16 October 2014

SHORTCUT TO CONVERT LOWERCASE TO UPPERCASE IN ECLIPSE MAC AND WINDOWS

SHORTCUT TO CONVERT LOWER CASE TO UPPER CASE IN ECLIPSE MAC AND WINDOWS:


TO LOWER CASE IN MAC: CMD+SHIFT+Y
TO UPPER CASE IN MAC: CMD+SHIFT+X

TO LOWER CASE IN WINDOWS: CTRL+SHIFT+Y
TO UPPER CASE IN WINDOWS: CTRL+SHIFT+X

Saturday 25 May 2013

Alternate to google Adsense ?


InfoLinks

Alternate to google Adsense - infolinks


Infolinks is the great alternative to Google Adsense. They provide the adds in four ways i.e. "in text","in search", "in tag", "in frame".

Pros:


  1. Their approval process is easy.
  2. Higher CTR(Click Through Ratio). The in text infolinks adds are embedded with in the content, hence the visitors are more probable click on the add.
  3. Industry and infolinks claims that they share maximum revenue to the publisher.
  4. The "in text" adds does not require any additional real estate and reachability to the vistor is aslo more.


Cons:


  1. CPC(Cost Per Click) is very less. The traffic should be more to your website to make decent amount of revenue.
  2. Non US traffic to your site would almost generate no money from infolinks.
  3. Adds from infolinks are too heavy and crowded on the website, which might cause annoyance to your website visitors.

Chitika






It is an another alternate to Google Adsense. But is a low paying advertisement provider. From my personal experience, i had 100 US clicks per day but the ecpm was always $0.
Chitika pays their publishers according to CPM and PPC systems. Hence you can earn for both ad clicks as well as unique impressions

Pros:


  1. Chitika is claiming that they are having the ad network worlwide. Which means, you can earn the from the non US vistors as well.
  2. They have the minimum payout of $10 via paypal and $50 payout by cheque.
  3. The Chitika adds can be placed in conjunction with google adsense. Chitika respects the Google adsense policies.
  4. They provide adds based on the search keyword, because of that the adds by Chitika is relavant to the user.

Cons:





Monday 25 June 2012

Oracle telephonic interview qustions


  1. What is two phase commit?
  2. How can you ensure the message durability in JMS topic as like in JMS queue?
  3. Difference between DataSource and Drivermanger?
  4. In a stateless session bean, 5 messages are posted to the JMS queue, while processing the messages if one had thrown an exception , how can you roll back the whole transaction?
  5. Few questions(versioning etc...) on Optimistic concurrency control in JPA.

The above questions that i had mentioned are the typical questions that i faced.

Thursday 19 April 2012

Customize the serialization process

According to me, there are 3 ways to  customize the serialization.
  1. Using transient keyword
  2. Defining readObject() and writeObject() method in the class to be serialized.
  3. Using the Externalizable interface.

1. Using transient keyword :

Let me demonstrate the use of transient keyword with the example. Look at the below code snippet.


import java.io.Serializable;
public class ThreadCls implements Serializable{

 private static final long serialVersionUID = -1730623665577892203L;
 private Thread thread;
 private Integer someData;
 
 public ThreadCls() {
  thread = new Thread();
  someData = 129;
 }
 
}

The java.land.Thread class is not implementing Serializable interface.Hence, the ThreadCls class throws an exception when this class is being serialized.
But indeed, the ThreadCls has to be serialized for us. We can achieve it by informing the JVM to not look at the instance variable "thread" during the serialization process. We can do that by designating the "transient" keyword to the "thread" instance variable.

import java.io.Serializable;
public class ThreadCls implements Serializable{

 private static final long serialVersionUID = -1730623665577892203L;
 private transient Thread thread;
 private Integer someData;
 
 public ThreadCls() {
  thread = new Thread();
  someData = 129;
 }
 
}

During the serialization of ThreadCls instance, the "transient" designated "thread" instance variable will not be serialized. During the de-serialization, the "transient" designated instance variable will be assigned with its default value.

2. Defining readObject() and writeObject() method : 

In a Serializable implemented class, if readObject and writeObject are defined, then the JVM would execute these methods for serialization and de-serialization of the objects respectively.
These methods can be defined with any access specifier, the JVM can execute these methods.In order to maintain the integrity of the class these methods can be defined as private. By this, the sub classes does not have the chance to override.

These methods can be used for seizing the serialization of the class which acquired the serialization property through its super classes.

3. Using the Externalizable interface : 

It is covered in the different blog post.

What is serialVersionUID?

In order to understand the use of serialVersionUID, you must have an understanding of serialization in java. You can find the article about it at serialization in java.

serialVersionUID is used for version control in the serialization.

In the serialization process, if the class does not have the serialVersionUID JVM generates one by considering the instance variable and other factors of the class. If any filed in the class is modified or deleted or added then the serialVersionUID generated by the JVM is different from the one that generated earlier.

For instance, an object is persisted on flat file for long duration. During that time, the has been modified by adding a new instance variable. If we try to deserialize the object from the file system it throws java.io.InvalidClassException because the serialVersionUID of the object in the file system is different from the one in the JVM for that class. As a developer, we expect the JVM to assign a default value for the newly added variable and deserialize the remaining object.

This can be achieved by explicitly defining the serialVersionUID in the class. We must ensure to not change the this variable value once it is defined. By this we can avoid serialization process to throw java.io.InvalidClassException even though the class definition is changed.

static final long serialVersionUID = 10275539472837495L;

Simple way to generate it is by using the Eclipse IDE. Once your class implements the Serializable interface, Eclipse start giving the warnings to generate the SerialVersionUID. You can click on the warnings and chose the compiler generated to generate the SerialVersionUID.







Or you can use the utility comes along with the JDK called serialver.

Wednesday 18 April 2012

Serialization in Java

What is Serialization?


It is the process of converting the object state to the sequence of bytes. The serialization is used for transferring an object from on JVM to another or for storing the data into a file system etc...
It is widely used for replicating an object in one JVM machine to another JVM machine.

When Serialization is useful?


Transferring an object from JVM to JVM : When you are making the remote calls from client to server either through RMI or EJB, the parameter objects passed in method call must be serialized. These objects, which are on the client, are replicated on the server.


Storing an object in the file system:
When you would like to persist the object in flat file system, the object which needs to be persisted in the file system has to be serialized. So that, the object can converted into the stream of bytes to store it in the file system.

How to Serialize an Object/Class?

Class is a blue print of the object. If you want to let an object to serialize, The java.io.Serializable class must be implemented by the class. This is a marker interface. It does not have any methods to implement. If any of the super class or interface is implementing the Serializable interface then your class need not implement it again as because those properties might have already acquired by your class with inheritance.

Must know in Serialization: 


  1. All instance variables in the class must be Serializable. If any instance variable not implementing Serializable interface wold through an exception during the Serialization process.
  2.  The static variables are not serialized. Serialization is the process of replicating the instance. Here the static variables are not copied because, the static variables are per class. It is of no use and not valid to copy a static variable from one JVM to another. Think over it.
  3. The instance variable designated with "transient" keyword are not serialized. The transient keyword is used, when a particular instance variable don't want to be serialized along with holding instance because that instance variable is not implementing the Serializable interface etc..
  4. Most of the pre defined java classes are serialized such as Collections, String and arrays etc...
  5. Serialization does not care about the access modifiers. All the instance variables,except designated with transient, will be serialized.

How an object is serialized (internal steps of Serialization process):

  1. Meta data of the JVM,such as JVM version etc..., will be wrote initially in byte stream. This data is called as magic data.
  2. Meta data of the class,such as length of the class,name of the class and serialVersionUID(More about serialVersionUID can be found at What is serialVersionUID? ) etc..,, which is associated with this instance will be wrote into the byte stream.
  3. It recursively writes out the meta data of its super class till the object class.
  4. Once the meta data information is wrote, it start writing the actual content of the instance start from the instance variables super class to the associated class of the instance variable.