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

XML Interview questions and answers for programmer

XML Interview questions and answers for programmer
---------------------------------------------------
What is XML ?
Difference between DTD and XML Schema?
What is Xpath ?
What is XSLT?
What is element and attribute in XML?
What is meaning of well formed XML ?
What is benefit of using XML ?
What is XML namespace? Why it's important?
Difference between DOM and SAX parser ?
What is a CDATA section in XML?
What is SOAP and how does it relate to XML?
What is XML data Binding ?
What is XML binding ? How to you bind XML document into Java objects?
What is XML Parsing? Which XML parsers have you used ?
What is difference between DOM and SAX parsers?
What is XPATH ? Can you run XPATh expression in Java ? How?
Does Java supports XSLT? How will you do XSLT transformation in Java?
How to write xsl stylesheet to remove an attribute from xml document?
Which Java open source library have you used for XML processing?
What is xml beans? have you used it?
Which packages are related to XML functionalities in Java?
What is difference between DTD and Schema?
What are xml namespaces? how do you resolve conflicts?
What are the issues you faced while doing XML processing in Java? 

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