Posts

Showing posts from 2012
Configuration Properties Properties Reference These are the portlet preference user guide       http://www.liferay.com/documentation/liferay-portal/6.1/user-guide/-/ai/configuring-liferay-s-properti-1

Get URL of Portlet By Passing Portlet ID

HttpServletRequest httpRequest = PortalUtil.getHttpServletRequest(portletRequest);                              httpRequest = PortalUtil.getOriginalServletRequest(httpRequest) long plid = PortalUtil.getPlidFromPortletId(themeDisplay.getScopeGroupId(), portletID);   PortletURL portletURL = PortletURLFactoryUtil.create(httpRequest ,portletId, plid ,PortletRequest.RENDER_PHASE);

Difference Between == & equals()

This is one of the frequently asked question in Interview. == always checks for reference equality.Means If  2 references points to same Object == gives you true equals() is a method available in java.lang.Object class and this method is overrided by many child class including String. Note:- If somebodys asks you,the differences between == and equals(),You should reverse question them for clearity,If he is talking about java.lang.Object.equals() or some other class equals() There is no difference between == and equals() of Object class. equals() of Object class internally uses == operator for comparing the object reference. source code of java.lang.Object class public class Object { public boolean equals(Object obj) {  return (this == obj);     } } equals() of String class checks if the string content is equal or not(case-sensitive) String s1=”hello”; String s2=”hello”; s1.equals(s2);//gives true. Since it is string pooling,only 1 object will  be created and shared b
void and Void void is a keyword which is used to specify the return type of a method.When a method return type is void,it means,the method is not going to return anything Void is a class with private constructor,Hence we cannot create the object of such class. What is the Use of Void class? It is use to know the return type of a method,via reflection api. Assume you have a Demo class with a show() method public class Demo { public void show(){} } Now Based on the return type(If return type is void do something) else do someother thing So the code to find out the return type is Class c1 =Demo.class.getMethod("show",null).getReturnType();  if(c1 == Void .TYPE) { //Some Business logic when return type is void } The complete program is VoidDemo.java import java.util.List; class Demo {     public void show()     {             } } public class VoidDemo {     public static void main(String[] args) throws NoSuchMethodException,SecurityExcept
Serializable Vs Externalizable Serialization       It is the technique using which we can save the state of the Object into files,or we can transfer the object from 1 jvm to another jvm. To Serialize the object,its class must implement Serializable interface.But Serializable interface  has some serious drawbacks1.Lets Assume the class Hierarchy Object->A->B->C->D    (child class) If you serialize the D class object,then all its superclass objects are also serialized(saved into file), which might be unnecessary sometimes.Not only the fields and properties are serialized,but also the class information,and their metadata is also serialized. 2.Assume Your class D has 100 fields/properties,out of which you are intrested to serialize only 5. Are you going to declare all other 95 fields as transient to avoid serialization?This is another issue. You really dont have any control on what you want to serialize and want you dont want to serialize. 3.You have serialized o