Showing posts with label Java. Show all posts
Showing posts with label Java. Show all posts

22 July, 2016

Sharepoint REST API call



Guys, I am sure this snippet will help you a lot when you do sharepoint REST integration to read files

05 September, 2015

Test Web Service With SOAP UI

Hello Friends,

I know many of you will be familiar with SOAP UI tool which is available to test SOAP as well as REST web services.


17 October, 2014

Escape HTML using JSTL

Hello Friends,

If you are using JSTL to display HTML data in your application then you can escape HTML 2 ways in JSTL:

1) Using <c:out> tag
<c:out value="${specialCharString or HTML}" escapeXml="true"/>

2) Using EL Function

${fn:escapeXml("<i> This is jignesh vachhani")} 

Hope this will be useful somewhere.

If you want to use Liferay API then you can simply use

HTMLUtil.escape(String HTMLString)


Show/Display HTML tag in jsp

${fn:escapeXml(fn:replace(fn:replace(fn:replace("<div><p>This is jignesh testing</p></div>",'"','&quot;'),'<','&lt;'),'>','&gt;'))}

22 August, 2014

Find Duplicate Records MySQL Query

Hi All

I know that this is not related Liferay but i came across this useful thing during my development where you can find duplicate record from table and can delete if you need.

SELECT tablename.name FROM tablename
INNER JOIN (SELECT name FROM tablename
GROUP BY name HAVING count(name) > 1) dup_record ON tablename.name = dup_record.name



20 August, 2014

Read Files From Folder

Hi All,

You can use below code to read files from specific folders :

import java.io.File;
public class Test {
    /**
     * @param args
     */  
public static void listFilesForFolder(File folder) {
       
        for (File fileEntry : folder.listFiles()) {
            if (fileEntry.isDirectory()) {
                listFilesForFolder(fileEntry);
            } else {
               
                System.out.println(fileEntry.getName());
            }
        }
        System.out.println("Total :" +folder.listFiles().length);
    }

07 August, 2014

Malicious code vulnerability - Java Programming

Malicious code vulnerability - Field is a mutable array
Malicious code vulnerability - Field is a mutable Hashtable
Malicious code vulnerability - Field isn't final and can't be protected from malicious code
Malicious code vulnerability - Field isn't final but should be
Malicious code vulnerability - Field should be both final and package protected

Performance - Java Programming

Performance - Could be refactored into a named static inner class
Performance - Could be refactored into a static inner class
Performance - Explicit garbage collection; extremely dubious except in benchmarking code
Performance - Huge string constants is duplicated across multiple class files
Performance - Inefficient use of keySet iterator instead of entrySet iterator
Performance - Maps and sets of URLs can be performance hogs
Performance - Method allocates a boxed primitive just to call toString
Performance - Method allocates an object, only to get the class object

Avoid - Java Programming

Avoid Array Loops
Avoid Assert As Identifier
Avoid Calling Finalize
Avoid Catching NPE
Avoid Catching Throwable
Avoid Decimal Literals In Big Decimal Constructor
Avoid Duplicate Literals
Avoid Enum As Identifier
Avoid Instanceof Checks In Catch Clause
Avoid Print Stack Trace
Avoid Rethrowing Exception
Avoid Throwing Null Pointer Exception
Avoid Throwing Raw Exception Types

Bad practice - Java Programming

Bad practice - Abstract class defines covariant compareTo() method
Bad practice - Abstract class defines covariant equals() method
Bad practice - Certain swing methods needs to be invoked in Swing thread
Bad practice - Check for sign of bitwise operation
Bad practice - Class defines clone() but doesn't implement Cloneable
Bad practice - Class defines compareTo(...) and uses Object.equals()
Bad practice - Class defines equals() and uses Object.hashCode()

30 July, 2014

OOP Principles For The Java Designer

Here are some useful information which should be familiar with all the java programmers/designers :

1. DRY


DRY stands for Don’t Repeat Yourself, which is pretty self explanatory. This means that you shouldn’t be duplicating your code in a program. If a code fragment is appearing in two places, then you would do well to turn it into a method instead of writing the entire fragment again. Lack of duplication helps in easy maintenance of the code.


2. Encapsulation


Whether your project gets bought over or whether you work on it yourself, your code will always change. So, it is good to encapsulate the part of the code that you think will be changed. This makes you code easy to maintain and test.



24 July, 2014

JVM Structure & YourKit Tool

As a java programmer, we should have at least basic knowledge of JVM and how it stores values.

The JVM memory consists of the following segments,
  • Heap Memory :  Storage for Java objects
  • Non-Heap Memory : Used by Java to store loaded classes and other meta-data
  • Other :  JVM internal structures, loaded profiler agent code and data, etc.

05 March, 2014

Custom Comparator in Java

import java.util.Arrays;
import java.util.Collections;
import java.util.Comparator;
import java.util.List;

/**
 * @author Jignesh Vachhani
 *
 */

10 December, 2013

See lucene Index

Hi
I have found out the way where you can actually look at the index files and figure out what are fields in index of Lucene.  

01 August, 2013

oData

oData is a protocol based on AtomPub and REST.OData builds on core protocols like HTTP and commonly accepted methodologies like REST. It’s designed to define the standard way of communication to a web service.

19 March, 2013

HashMap sorting

I know this is not related to Liferay... But it can be useful to you guys for java programming...
As we know that hash map doesnt allow duplicate value with the same key name... But if you want to sort the map by values instead of key, below is the code which can be useful...

17 August, 2012

Detect word and convert in URL

Guys,

I know this is not related to Liferay but might be useful in somewhere,
where you need to detect some words and convert it into URL then it would be helpful.

22 July, 2011

Mail API

Hello Java Folks,

We are using mail sending functionlaity in most of the web applications.
So have a look on below java class which can help you to send the mail using JAVA API.

14 July, 2011

Inter portlet communication (IPC)

Hello Everyone,
Here is the flow of IPC



Here below are the steps to follow for IPC :

12 July, 2011

Convert List to JsonArray

Might be you won't be aware that you can't use existing portal *JsonSerializer.java class in Liferay plugin portlets. So if you want to get JsonArray response of existing liferay service then you can use below code :

import net.sf.json.JSONArray;

List myList = UserLocalserviceUtil.getUsers();
JSONArray jsonArray = JSONArray.fromObject(MyList);

08 July, 2011

WSRP

WSRP : Most useful world if you are using portlet standards.

so you wanna get introduce with WSRP ???? Just follow me and my this link .

This article represents vary nice details of WSRP.

If it really helpful ? just say Thanks to me for finding this article for you :)

Cheers !!!!!!!!!!

Popular Posts

Featured Post

Liferay 7.3 compatibility matrix

Compatibility Matrix Liferay's general policy is to test Liferay Portal CE against newer major releases of operating systems, open s...