Top 27 Java Liferay Interview Questions You Must Prepare 23.Jul.2024

Q1. How Do You Perform Junit Tests On Your Portlet?

Junit tests are there to check the code mainly by providing the value of any method input parameter, how the method would work and gives the values.

public class MyEmployeeTest {
 ClassPathXmlApplicationContext context = new ClassPathXmlApplicationContext(
 public void testMyMethod() {
  UserService employeeService = (UserService) context.getBean("userService");
  //Provide the user Id as 101581
  User user = storeService.findUserByUserId(1234);
  //get the employee
  Set employee = user.getEmployeesForUserId();
  System.out.println("Employee Name : "+employee.getName());

Q2. What Is A Portlet Lifecycle?

Following is the portlet lifecycle: 

init(): It mainly initializes the portlet.

render(): It takes the HTML output to User Interface. It mainly render the view in term of JSP/HTML code and show into the respective portlet.

Destroy: This method takes care of releasing the portlet resources.

Q3. How Can I Configure Liferay To Use Email Address As User Name Instead Of Screen Name?

We can set this from control panel -> portal settings -> Authentication -> LDAP -> How do users authenticate?. Here we can select whatever we require from email address,screen name or user ID. At the time of LDAP authentication, we need to provide the required LDAP mappings which basically reads all the details related to users and usergroups from LDAP directory and import into Liferay portal. At the time of this connection with third party we need to give the required field like authentication should be by email address or screen name or user ID.

Q4. How To Setup A Liferay Cluster From Scratch?

We need to setup below properties in our is for one instance represented by 1p, same properties we need to add for second instance also represented by 2p) and some required IP addresses.

#cluster configurations - these settings are for cluster
#other settings for cluster

Q5. What Is A Portlet?

Liferay portal comes with different portlets by default. These portlets are nothing but different small applications running in the instance(portal). Portlets are pluggable software components that are managed in a web portal. 

In general words you can call them as different catalogues as portlets produce fragments of markup code that are aggregated into a portal. So a portal page is displayed as a collection of portlet, thease multiple small applications together making a page of the site and these all pages together makes one community or enterprise portal. Hence a portlet (or collection of portlets) resembles a web-based application that is hosted in a portal. 

Portlet is a small application to fulfill the requirement of certain domain. Inter portlet communication is supported under Liferay portal. Portlet support hot deployment feature of Liferay Portal.

Q6. How To Configure Liferay To Use A Jndi Jdbc Datasource Instead Of Internal C3p0 Connection Pool?

We need to do the entry of perticular resource with some certain parameter like name, factory, driverclassname, url of database, uaername and password.

Below is the entry of resource where JDBC datasource is configured.


Below is the entry of resource where c3p0.ComboPooledDataSource is configured.

    driverClass="com.mysql.jdbc.Driver"    jdbcUrl="jdbc:mysql:///?useUnicode=true&characterEncoding=UTF-8&useFastDateParsing=false&noAccessToProcedureBodies=true"

Q7. What Is File? How This Can Be Configured And Used In Liferay?

Liferay Portal comes with default configurations that are stored in file. You can use file to override the values in file. 

This allows you a clean way to keep your own copy of configurations that can be used outside the portal at the same time you can easily upgrade the portal.

Q8. How Can You Customize Liferay Search Feature? What Are The Apis To Do It?

We can customize Liferay Search feature, depends upon our requirement by below two ways.

Hook : If changes are required as per the view side like we need to change the search result form view then we can write the Hook to customize it.

EXT : If changes are required as per the core functionality like we need to change the search query term, we can implement EXT.

Q9. What Is A Liferay Theme? What Are The Advantages Of Using Them?

Liferay themes are the way to customize look and feel of a liferay portal page. The themes are extendable components that can be deployed separately on a portal and each page on the portal can choose a different theme (if required).

Themes are really powerful way to run multiple websites from a single portal. You can host multiple websites on a single liferay portal with totally different look and feel. This allows you to be unique at the same time save a lot resources on website hosting. 

A lot of companies use liferay for creating multiple unique websites with the help of extraordinary themes that can be easily developed. 

Themes are also available from marketplace.

For developing on our own, we have option of using VM pages(Velocity templates). Liferay provides the feature to deploy the different themes into the portal same like portlets war files. So number of themes we can be deployed into Liferay portal and we can further select those themes for user interface as per the requirement of end user for different site or organization pages.

Q10. What Is Inter-portlet Communication? Why Is It Required To Use Jsr Style Inter-portlet Communication?

Sometimes we have the requirement where we need to establish communication in between two portlets for example any action done in one portlet redirecting the end user to other portlet where some kind of result is displaying as per action done on first portlet. 

So in this use case we have to use liferay inter-portlet communication mechanism which serve the action performed by end user in one portlet and provide the result to the second portlet where the action result needs to be displayed. We can say that it works on striker-catcher mechanism. 

JSR style inter portlet communication ensures that your portlets are going to work on any other JSR compliant portal server. If you use a liferay specific way to communicate between portlets than you may not be able to deploy and run the same portlet war on another JSR compliant portal (e.g. Apache Pluto)

Q11. How To Support Internationalization (i18n) On Liferay Portlets? How Do You Support Multiple Languages Without Writing Java Code In Liferay?

We can support internationalization (i18n) on Liferay portlets and through out this whole Liferay portal. We need to provide whatever language we need to support into LIferay portal. This is mainly reads the regions number and provide the available language like en_US(english), SG(singapore), zh_CN(simple chinease), zh_TW(traditional chinease), ja_JP(Japanease). 

In the same way to provide support of multiple languages without writing java code in Liferay, we can use Locales this through out the portal,

portlet, hooks and themes. This entry we can provide into same which Liferay portal would read and provide all the trlation accordingly.


If we are writing some custom messages in out code then we need to provide the below property files also as per the called language and using of Locales would convert it accordingly. We can use LocaleUtil in our code which will convert the certain message given in language files. 

For example we want the assetCategory title in multi languages then we need to use this assetCategory.getTitle(locale). So here whatever locale we have mentioned earlier would be in action and pick the given title name from certain locale related file.

Q12. How To Customize The Behavior Of Liferay Default Out Of The Box Portlets (e.g. Document View, Calendar, Blog, Wiki Etc) ?

If we need any customization, related to JSP and UI then we can implement this using Hooks. Liferay portal comes with a bundle where all the default built in portlets exist.

If any customixation required in the core level classes then it can be done through EXT for example LDAP users and user groups import modification. but here in EXT, restart would be required.

Q13. How Can I Configure Two Different Domain Names (e.g. And On Liferay?

At the time of creation of any site we need to provide domain names which further take it as site domain name. We need to provide the certain domain name as required through the control panel of liferay portal. Single instance of Liferay Portal supports hosting of two or more domain names via communities(sites). 

When we will go to control panel -> Site settings -> we can provide the site URL, details like site(community) description, membership type, active status and virtual host.

Q14. How Can You Integrate Liferay With An External Content Management System (e.g. Alfresco)?

Liferay passes user credentials through CMIS to the alfresco in order to connect. To enable this in liferay, we need to enter following below property in which will allow liferay to store password in session.

Also one more thing we need to take into consideration is that Liferay passes logged in user's credentials to CMIS Repository (whihc is alfresco

here) as described above. What this me is that userid/password in liferay must match userid/password in Alfresco. Alfresco by default uses a loginid (which is similar to screen-name in liferay) to authenticate user. So we need to make liferay also authenticate using screen name by making following entry into

So we need to start Liferay. Login as administrator and go to control panel. we need to go to Document and Media which will bring up a screen where we need to click on Add -> New Repository. this will bring one screen where we basically provide connection details to connect to Alfresco like below.

Name: Give any name you want to give to your repository view in liferay. For example, I will give Alfresco repository name.

Description: A brief description about it. 

Repository Type: We can connect either using AtomPub or using web services. 

AtomPub URL: This will be the CMIS repository URL where our alfresco is running. In our case, it's would be http://localhost:8080/alfresco/service/api/cmis (Note: In case of Alfresco 4.0, it will be http://host:port/alfresco/cmisatom).

Repository ID: It is basically used to connect to a specific repository incase we have multiple repositories available. If we do not enter a repositoryId, then it will just look for the first repository using the given parameters and set it to that.

Q15. How Will You Configure A Portlet That Can Be Added Multiple Times On A Portal Page?

One property is there in portlet.xml which is as follows:


by using the value true and false we can configure a portler that can be added multiple times on a portal page.


Q16. What Is A Liferay Portal Instance?

Liferay portal ships with the one liferay portal tomcat bundle which is up and running in any server with certain database settings. We can have more than one liferay instances running from one database.

Liferay Portal allows you to run more than one portal instance on a single server. The Portal Instances page of the control panel lets you manage these instances. Data for each portal instance are kept separate. All portal data, however, is kept in the same database.

Each portal instance requires its own domain name. Liferay will direct users to the proper portal instance based on this domain name. So before you configure an instance, we need to configure its domain name in our network first. When we are ready to add an instance, click the Instances tab - > Add button.

It will be prompted for four fields and a check box:

Web ID: A general convention is to use the domain name for this. It’s a user-generated ID for the instance.

Virtual Host: Put the domain name you configured in your network here. When users are directed to your Liferay server via this domain name, Liferay will then be able to send them to the proper portal instance.

Mail Domain: Enter the domain name for the mail host for this instance. Liferay will use this to send email notifications from the portal.

Max Users: Enter the maximum numbers of user accounts you would like your portal instance to support.

Active: Use this check box to choose whether to create an active or an inactive portal instance.

Now we need to click Save. Now navigate to the portal using new domain name. We will see that looks like a clean install of Liferay. This is our new portal instance which can now be up and running.

Q17. What Is The Difference Between View Mode And Edit Mode Of Portlets?

The modes of a portlet are typically related to the types of operations a user can perform on the portlet. A view mode is where users are allowed to do read only operations, whereas in edit mode user can add/update the data in the portlet. 

Each portlet mode has a method which handles it:


These methods will contain mainly our "traffic directing" logic, which are responsible to decide what view the user wants to see.

Once the view has been determined, we will forward on to methods which actually implement that view.

For standard portlet view modes have two views:

  • The default view which shows the list of items.
  • The form, where users will mainly do the add and edit action.
  • In this where end user can edit the particular item, is called edit mode of portlet.

Q18. How To Set The Display Category Of A Custom Built Liferay Portlet ?

We can set the display category like below mentioned liferay-display.xml. Suppose we have developed one portlet where portlet ID we have provided. We need to enter the custom built liferay portlet into certain category like name "category.cms", "category.collaboration" etc.

By doing this custom built liferay portlet would come in required category by clicking the add application feature of liferay as there would be many of portlets under different categories. So below tag we need to enter for the entry of a portlet into certain category.

<category name="category.cms">
<portlet id="20" />

Q19. Which One Is Best To Start In A Clean Setup?

Liferay bundle with tomcat app server is the best one to start in a clean setup.

Q20. What Is The Difference Between Hook, Ext And Portlet?

Liferay provides 3 ways to extend the functionality of a Liferay portal. Each of the way fits is good for different needs.


Liferay portal comes with a bundle where all the default built in portlets exist. Typically if any customization required in terms of JSP (UI) and portal properties. We need to go by Hook implementation. Hook is supported by hot deployment. Liferay documentation suggests that - Whenever possible, hooks should be used in place of Ext plugins, as they are hot-deployable and more forward compatible.

Some common scenarios that require the use of a hook are: 

  • When you have to perform a custom action on portal startup
  • When you have to perform a custom action on user login
  • When you need to overwrite or extend portal JSPs
  • When you need to modify portal properties
  • When you need to replace a portal service with your own implementation.


Liferay EXT Plugins are the most powerful way to extend the portal functionality. If any customization required in the core level classes then it can be done through EXT for example LDAP users and user groups import modification. but here in EXT, restart would be required.

EXT Plugins should be used only in case the portal functionality can not be extended using Portlet of Hooks. The EXT plugins are complex to develop and may cause maintenance issues in case you are trying to upgrade.

From liferay documents, The main use cases in which an Ext plugin may be used are:

  • Customizations to (that is not supported by Hook Plugins)
  • Customizing and making changes to the Struts Actions for portal
  • Customizations of the Liferay be declared in Liferay's Spring files
  • Adding JSPs that are referenced from portal properties that can only be changed from an ext plugin (be sure to check if the property can be modified from a hook plugin before doing this)
  • Direct overwriting of a class (not recommended unless it's strictly necessary)


Portlets are the most common and easiest way to extend and provide a custom functionality for a liferay portal. This is a small application to fulfill the requirement of certain domain. It is basically a bunch of code(Java Files, JSP, CSS, Java Scripts etc.). Portlet is supported by hot deployment.

Liferay also has a marketplace where a lot of useful portlets are available for download and these portlets can contributed by anyone in the world. We recently contributed a Speed reading portlet and a My IP Address portlet in this marketplace for free use by liferay community. 

Q21. How To Use Aui In Liferay? What Are The Advantages Of Using It In Liferay Instead Of Jquery Or Some Other Js Library?

AlloyUI (AUI) is Liferay's open-source javascript library. It is built on Yahoo User Interface (YUI) and has support for a variety of advanced javascript functions specifically designed for portlets. As it is Liferay provided JS library here no need to merge this code. It is designed to take advantage of and incorporate patterns from the best libraries to make building robust and flexible web applications.

It is a JavaScript library, a CSS framework, a set of HTML recipes and a taglib library, all combined to empower developers across multi-skilled teams deliver rich and dynamic applications. Only we need to add certain tag library like below in order to use Liferay Alloy UI libraries. 

So further we can use these all form and fields like below in our JSP code.
    <aui:input name="Name" size="45" />

Q22. What Is A Liferay Portal?

In general, a web portal represents a web application that provides a single point of access to variety of information. 

Functionality of a portal can extended very easily by creating custom applications that can run inside a portal. These applications are called portlets. 

For running portlets you need application server that can run a portlet container spec (JSR168 or JSR286). There are dozens of free and enterprise portal products available. 

Liferay portal is an open source portal and below are the benefits of using Liferay portal: 

  • Content management system(Documents, Articles).
  • 2-stage,3-stage workflows and publishing.
  • Social networking. 4)Sites and organization basis pages.
  • Integration with third party like LDAP, Solr, SSO(CAS, Siteminder).
  • Portlets realted to Wiki's, News, Finance, Social, Workflow, Collaboration.
  • Compatible with different Operating systems, databases and APP servers.
  • Compatible with UI technologies and web services.
  • Compatible with different scripts like PHP, Ruby, Grails, Python.
  • Suppport of hot deployment feature.

Q23. What Jsr Version Liferay Implements? Why Jsr Compatibility Is Important While Choosing A Portal?

JSR is a "Java Specification Request". Liferay Portal is developed to adhere to JSR 168 and JSR 286 specifications. 

This specification is created by committee of JEE portal vendors. This specification is designed to achieve interoperability between different portals and portlets.

Liferay supports mainly below JSRs: 

JSR-168(Portlet 1.0) 
JSR-286(Portlet 2.0) 
JSR-127(JSF 1.0) 
JSR-314(JSF 2.0) 

Why these standards are defined?

These standards are defined for the benefit of portal users (end customers). Before these standards were born, portal customer were required to use one portal and there was no easy way to switch between different portal vendors. Earlier portal were very vendor specific and all functionality were developed using proprietary API, technology and programming techniques. The JSR 168 and JSR 286 standards have defined the way portlets can be developed that will help users in long run. 

Benefits of Following JSR Standards:

Following these standards will ensure that there is no vendor lock in. However this can be guaranteed only when the portlets are developed sticking to the standards.

Q24. What Are The Advantages Of Using Tomcat Bundle Of Liferay Against Other App Servers (e.g. Jboss, Glassfish Or Others)?

It is possible to use Liferay with Liferay IDE with other then tomcat server bundles but there are some features or benefits that will not be available:

Native eclipse server adapter that supports launching and debugging.

Deployment via add/remove modules wizard would not be available.

Auto redeployment based on changes to project resources.

Q25. What Is Liferay Service Builder? Is There Any Alternative To Use Service Builder? What Are The Advantages And Disadvantages Of Using It?

Liferay service builder is basically used to create the service layers for any business logic implementation. From developer point of view it is very helpfull as it used to create all the service layers automatic. Suppose we want to develop a portlet, for this we need to write all the required implementation classes, utility cleasses and other required classes. Service builder is used to create all these classes for developer, where they can add their business logic further and process the data and render the output to view as per the requirement. 

As per the advantage, this service builder will create whole structure of the service layers for developer mainly. It really helps them to write the code and their logic in service builder created model implementations and service implementation classes. These classes comes with normal CRUD (create, update and delete)operations. For developer, no need to add anything extra as whole service and utility layers are already got created by service builder. It really speed up the developement process.

Service builder requires service.xml which is having some of the required entries. Each of the entry is basically called entity, which is having it's primary key fields with some other required fields. If we want to implement order and finder method, we can implement it by using this service.xml. 

Each entity creates table into liferay configured database with the given column names and their types. We can create service.xml related local-service and remote-service by setting them value as "true". When we would run this build-service like below, this would create all the service layers(implementation, utility etc.) where developer can write their required business logic further. Creation of all the service-classes would be done by the build.xml, we need to build-services using this xml file into Ant view of IDE.

Q26. How To Use Ldap Authentication With Liferay?

LDAP is lightweight directory access protocol that is most commonly used for authentication and authorization of users. LDAP mainly consists users and usergroups of any organization with certain serach filter like DN entries. In the control panel of liferay we have option to provide the LDAP settings so that portal can contact the third party like LDAP and fetch the required users and groups as per given mappings.

For example Active directory is a LDAP implementation which can store users. Liferay support integration of any LDAP implementation through its admin control panel. 

We need to provide the settings in control panel - > portal settings -> LDAP

This will require LDAP URL, username, password, users search filters mappings, groups search filters mapping etc.

Q27. How To Use Jquery In Liferay?

We need to provide the entry like below in our JSP files. So that it can read the provided java script path very easily and we can use jQuery accordingly.

<script type="text/javascript" src="<%=themeDisplay.getPathThemeCss()%>/../js/jquery-1.7.2.min.js"></script>