Welcome to Java4u

A Single Place for all Java Resources

Looking for something?

Subscribe to this blog!

Receive the latest posts by email.

.Just enter your email below if you want to subscribe!


OAuth 2.0

OAuth 2.0 is an open authorization framework and mainly focuses on authorization flows fand secures access to many well-known web APIs.

Java 8 features

The key features of JDK 8 are Project Lambda (JSR 335), the Nashorn JavaScript Engine, a new Date and Time API (JSR 310), a set of Compact Profiles and the removal of the "permanent generation" from the HotSpot Java Virtual Machine (JVM). A complete list of the new features and capabilities of JDK 8 is available.

Lambda Expression

A lambda expression represents an anonymous function. It comprises of a set of parameters, a lambda operator (->) and a function body.


SOAP : Web service use XML messages that follow the Simple Object Access Protocol (SOAP) standard.
RESTful : Web service, often better integrated with HTTP than SOAP-based services are, do not require XML messages or WSDL service–API definitions.

Softwares Engineering / SDLC

Software engineers apply the principles of engineering to the design, development, maintenance, testing, and evaluation of the software and systems that make computers or anything containing software work.

Tuesday, November 25, 2014

E-Books : Design Patterns

Head First Design Pattern


 Click to Download or View


Monday, October 20, 2014

Software Engineering Videos

Saturday, October 18, 2014

E - Books : Spring

Spring in Action

 Click to Download or View


Struts 2 Videos

  • The struts 2 framework is used to develop MVC-based web application.
  • Struts 2 is the combination of webwork framework of opensymphony and struts 1.
                            Struts2 = Webwork + Struts1
  • The struts framework was initially created by Craig McClanahan and donated to Apache Foundation in May, 2000 and Struts 1.0 was released in June 2001.
  • The Struts 2 provides supports to POJO based actions, Validation Support, AJAX Support, Integration support to various frameworks such as Hibernate, Spring, Tiles etc, support to various result types such as Freemarker, Velocity, JSP etc.

Click on the links to Download or Watch

01 - Introduction To MVC
02 - Introduction to Struts 2
03 - Setting Up
04 - Writing a Struts 2 Application - Part 1
04 - Writing a Struts 2 Application - Part 2
05 - Understanding Namespaces
06 - A Tag And A Business Service
07 - The ValueStack

Tuesday, September 30, 2014

AngularJS : Introduction and Hello example

Angular JS is a JavaScript MVC framework created by Google that lets you build well structured, easily testable, and maintainable front-end applications that makes it easier to implement RIA web applications.

What is AngularJS?
AngularJS is based on the MVC pattern (Model View Control). Therefore AngularJS separates your RIA application into models, views and controllers.
The views are specified using HTML + AngularJS's own template language.
The models and controllers are specified via JavaScript objects and JavaScript functions.
Thus, the views are specified declaratively, as HTML normally , and the models and controllers are specified imperatively, as JavaScript normally is.
If you don't know the difference between declarative and imperative programming, don't worry. It is not important to know before learning AngularJS. Besides, it is pretty simple to find the definition on the web.

And Why Should I Use It?

  • If you haven’t tried AngularJS yet, you’re missing out. The framework consists of a tightly integrated toolset that will help you build well structured, rich client-side applications in a modular fashion—with less code and more flexibility.
  • AngularJS extends HTML by providing directives that add functionality to your markup and allow you to create powerful dynamic templates. You can also create your own directives, crafting reusable components that fill your needs and abstracting away all the DOM manipulation logic.
  • It also implements two-way data binding, connecting your HTML (views) to your JavaScript objects (models) seamlessly. In simple terms, this means that any update on your model will be immediately reflected in your view without the need for any DOM manipulation or event handling (e.g., with jQuery).
  • Angular provides services on top of XHR that dramatically simplify your code and allow you to abstract API calls into reusable services. With that, you can move your model and business logic to the front-end and build back-end agnostic web apps.
  • Finally, I love Angular because of its flexibility regarding server communication. Like most JavaScript MVC frameworks, it lets you work with any server-side technology as long as it can serve your app through a RESTful web API. But Angular also provides services on top of XHR that dramatically simplify your code and allow you to abstract API calls into reusable services. As a result, you can move your model and business logic to the front-end and build back-end agnostic web apps. In this post, we’ll do just that, one step at a time. 
Example : Hello , AngularJS 

Note  : The {{  }} are a declarative way of specifying data binding locations in the HTML. AngularJS will automatically update this text whenever the yourName property changes.

Watch another example

Monday, September 29, 2014

Hibernate Videos

  • Hibernate is an Object-Relational Mapping(ORM) solution for JAVA, providing a framework for mapping an object-oriented domain model to a traditional relational database.
  • It is a powerful, high performance Object-Relational Persistence and Query service for any Java Application.
  • Hibernate maps Java classes to database tables and from Java data types to SQL data types.
  • Hibernate sits between traditional Java objects and database server to handle all the work in persisting those objects based on the appropriate O/R mechanisms and patterns.

Click on the links to Download or Watch

01 - Setup
02 - Setup  
03 - Customize cfg.xml  
04 - Our First Class  
05 - Create table from Class  
06 - Schema Change  
07 - Insert record (object)  
08 - Chapter 1 Review 1  
09 - more annotations

10 - Auto Generate Primary key 
11 - One class to Two tables
12 - Two classes to One table 
13 - Compound Primary Key 
14 - Inheritance Mapping
15 - One to One Mapping 
16 - One to One Bi-directional
17 - One to Many Mapping  
18 - Many to Many Mapping

Thursday, July 3, 2014

Unmarshalling and Marshalling

Unmarshalling is the process of binding the XML document using JAXB compiler and generating mapping java classes then constructing the instances with values available in XML document.

Marshalling is the reverse process of it. First we construct the instances and then write a XML document using the constructed instances.

In both the cases, we need create POJO classes first. If we have the XML schema that can be used to generate those classes using a JAXB binding compiler. If the XML schema is not available, then we should manually code those POJOs. Only then we can do Marshalling or Unmarshalling in an application.

Marshalling and Unmarshalling can be done with other sources. That means, the XML need not be in file form. It can be a InputStream object, a URL, a DOM node, SAXSource.

To Unmarshal 
  1. Create POJOs or bind the schema and generate the classes.
  2. Create a JAXBContext object. (javax.xml.bind.JAXBContext)
  3. Create an Unmarshaller object. (javax.xml.bind.Unmarshaller)
  4. Call the unmarshal method.
  5. Use the get methods available in schema-genearated classes to access the values.
To Marshal
Marshalling provides a client application the ability to convert a JAXB-derived Java object tree back into XML data. By default, the Marshaller uses UTF-8 encoding when generating XML data. Client applications are not required to validate the Java content tree before marshalling. There is also no requirement that the Java content tree be valid with respect to its original schema to marshal it back into XML data

  1. Create POJOs or bind the schema and generate the classes.
  2. Create the content tree by using set methods.
  3. Create a JAXBContext object. (javax.xml.bind.JAXBContext)
  4. Create a Marshaller object. (javax.xml.bind.Marshaller)
  5. Call the marshal method to persist the created content tree as XML document. 
It is the process of verifying that an XML document meets all the constraints expressed in the schema. JAXB 1.0 provided validation at unmarshal time and also enabled on-demand validation on a JAXB content tree. JAXB 2.0 only allows validation at unmarshal and marshal time.

Advantages :
  1. JAXB requires a DTD.
  2. Using JAXB ensures the validity of your XML.
  3. A JAXB parser is actually faster than a generic SAX parser.
  4. A tree created by JAXB is smaller than a DOM tree.
  5. It’s much easier to use a JAXB tree for application-specific code.
  6. You can modify the tree and save it as XML.
  1. JAXB requires a DTD.
  2. Hence, you cannot use JAXB to process generic XML (for example, if you are writing an XML editor or other tool).
  3. You must do additional work up front to tell JAXB what kind of tree you want it to construct.
  4. But this more than pays for itself by simplifying your application. 

JAXB : Architecture & Binding Process

XML Schema : An XML schema is a definition file for a XML document & uses XML syntax to describe the relationships among elements, attributes and entities in an XML document. It maintains the rule/syntax for a XML document. An XML document need not always have a schema. While using JAXB XML schema is not a mandatory requirement. Process can start with java pojo classes. But it is convenient to have associated XML schema so that we can use a binding compiler and generate the java classes.

Binding Customizations : By default, the JAXB binding compiler binds Java classes and packages to a source XML schema based on rules. In most cases, the default binding rules are sufficient to generate a robust set of schema-derived classes from a wide range of schemas.

Binding Compiler : The JAXB binding compiler is the core of the JAXB processing model. Its function is to transform, or bind, a source XML schema to a set of JAXB content classes in the Java programming language.

Implementation of javax.xml.bind
: The JAXB binding framework implementation is a runtime API that provides interfaces for unmarshalling, marshalling, and validating XML content in a Java application. The binding framework comprises interfaces in the javax.xml.bind package.

Schema-Derived Classes: These are the schema-derived classes generated by the binding JAXB compiler. The specific classes will vary depending on the input schema.

Java Application : In the context of JAXB, a Java application is a client application that uses the JAXB binding framework to unmarshal XML data, validate and modify Java content objects, and marshal Java content back to XML data.

XML Input Documents: XML content that is unmarshalled as input to the JAXB binding framework -- that is, an XML instance document, from which a Java representation in the form of a content tree is generated.

XML Output Documents : XML content that is marshalled out to an XML document. In JAXB, marshalling involves parsing an XML content object tree and writing out an XML document that is an accurate representation of the original XML document, and is valid with respect the source schema.

Binding Process :
Generate classes: An XML schema is used as input to the JAXB binding compiler to generate JAXB classes based on that schema.

Compile classes
: All of the generated classes, source files, and application code must be compiled.

UnMarshal: XML documents written according to the constraints in the source schema are unmarshalled by the JAXB binding framework.

Note : JAXB also supports unmarshalling XML data from sources other than files/documents, such as DOM nodes, string buffers, SAX Sources, and so forth.

Generate content tree: The unmarshalling process generates a content tree of data objects instantiated from the generated JAXB classes; this content tree represents the structure and content of the source XML documents.

Validate (optional) : The unmarshalling process optionally involves validation of the source XML documents before generating the content tree. Note that if you modify the content tree in Step 6, below, you can also use the JAXB Validate operation to validate the changes before marshalling the content back to an XML document.

Process content : The client application can modify the XML data represented by the Java content tree by means of interfaces generated by the binding compiler.

Marshal : The processed content tree is marshalled out to one or more XML output documents. The content may be validated before marshalling.