Monday, October 16, 2017

10 points about JPA Entity Class for Hibernate Java developers.

JPA Entity class is in core of JPA specification and its one of the most important thing a Java developer should know, while working with JPA implementations like Hibernate. Many Java programmers either not aware of these rules and best practices or doesn't pay enough attention while creating JPA entity class to end up with same mistakes e.g. equals and hashcode not working, issues with access type etc. This motivates me to hund down and write these rules


The entity class must have a no-arg constructor. It may have other constructors as well. The no-arg constructor must be public or protected.
The entity class must a be top-level class. An enum or interface must not not be designated as an entity.
The entity class must not be final. No methods or persistent instance variables of the entity class may be final.
If an entity instance is to be passed by value as a detached object (e.g., through a remote interface), the entity class must implement the Serializable interface.
Both abstract and concrete classes can be entities. Entities may extend non-entity classes as well as entity classes, and non-entity classes may extend entity classes.

http://stackoverflow.com/questions/6033905/create-the-perfect-jpa-entity

Further Learning
Introduction To Hibernate
Spring with JPA and Hibernate
Introduction to Spring MVC
Java Web Fundamentals by Kevin Jones

Sunday, September 10, 2017

XPath Example in Java

10 Example of XPATH
------------------------
package test;

import java.io.IOException;
import javax.xml.parsers.DocumentBuilder;
import javax.xml.parsers.DocumentBuilderFactory;
import javax.xml.parsers.ParserConfigurationException;
import javax.xml.xpath.XPath;
import javax.xml.xpath.XPathConstants;
import javax.xml.xpath.XPathExpression;
import javax.xml.xpath.XPathExpressionException;
import javax.xml.xpath.XPathFactory;
import org.w3c.dom.Document;
import org.w3c.dom.NodeList;
import org.xml.sax.SAXException;

/**
  * Simple Java program to execute XPATH expression and retrieve value from XML documents
  */
public class XPathExample {

    public static void main(String[] args){
        try {
            DocumentBuilderFactory domFactory = DocumentBuilderFactory.newInstance();
            domFactory.setNamespaceAware(true);
         
            DocumentBuilder builder = domFactory.newDocumentBuilder();
            Document doc = builder.parse("Books.xml");
         
         
            XPath xpath = XPathFactory.newInstance().newXPath();
         
            XPathExpression expr = xpath.compile("bookstore/book[@category='COOKING']/title/text() | bookstore/book[@category='WEB']/title/text()");

         
            Object result = expr.evaluate(doc, XPathConstants.NODESET);
         
         
            NodeList nodes = (NodeList) result;
            System.out.println("Result: " + nodes);
            for (int i = 0; i < nodes.getLength(); i++) {
                System.out.println(nodes.item(i).getNodeValue());
            }
         
        }catch (XPathExpressionException ex) {
            ex.printStackTrace();
        } catch (SAXException ex) {
            ex.printStackTrace();
        } catch (IOException ex) {
            ex.printStackTrace();
        } catch (ParserConfigurationException ex) {
            ex.printStackTrace();
        }
    }
}

That's all about how to use XPath in Java. 

Sunday, April 30, 2017

Top 10 Reasons to do Java Certification like OCPJP and OCAJP



1. To Learn Java Better


2. Hiring advantages


3. To do well on Java written test

4. To do well on Java interviews


5. To Earn more - better Packages

6. To get Recognized in your team and company

7. To gain confidence in your Java skill


8. Add some weight in your CV

9. Learning opportunity

10. Upgrading your Java skills