Skip to main content

how to setup/configure hibernate ORM in your spring project

This article is for how to setup/configure hibernate ORM in your spring project.
Add below maven dependency in pom.xml <dependency> <groupId>org.hibernate</groupId> <artifactId>hibernate-core</artifactId> <version>4.0.1.Final</version> </dependency> <dependency> <groupId>org.hibernate</groupId> <artifactId>hibernate-validator</artifactId>

autoboxing and unboxing in java

autoboxing and unboxing in java –


autoboxing and unboxing concepts is related to primitive data types and its wrapper classes. If any wrapper class holds the value of its primitive data type called boxing. And if any primitive data type holds the objects of its wrapper class called unboxing.

autoboxing and unboxing in java is two types :
1) Implicit Auto boxing.
2) Explicit boxing.
3) Implicit unboxing.
4) Explicit unboxing.


Implicit Auto boxing –


J2SE 5 was added autoboxing. Autoboxing is internal process where primitive data type automatically encapsulated within their wrapper classes. So there is no need to wrap primitive data type to its wrapper classes. There is really very helpful with in collection framework. Because collections framework allows objects instead of primitive data type.

Example :-

Integer intObj = 786; // Autoboxing
List listObj = new ArrayList();
listObj.add(786); // Autoboxing
listObj.add(787); // Autoboxing

So in this line there is no need to make an object and then explicitly encapsulate the value.


Explicit boxing –


Before J2SE 5, autoboxing was not present then developers was use explicit boxing.

Example –
List listObj = new ArrayList();
listObj.add(new Integer(786)); // Explicit boxing
listObj.add(new Integer(787)); // Explicit boxing


Implicit unboxing (Auto-unboxing) –


J2SE 5 was added unboxing. unboxing is internal process where wrapper classes objects directly converted to primitive data type automatically. So there is no need to convert manually to primitive data types.

Example –
Integer intObj = 786; // Autoboxing
Int intvariable = intObj;
//or
List listObj = new ArrayList();
listObj.add(new Integer(786)); // Explicit boxing
listObj.add(new Integer(787)); // Explicit boxing
int x = listObj.get(0);   //Implicit unboxing
int y = listObj.get(1);   //Implicit unboxing


Explicit unboxing –


Before J2SE 5 , developers was do explicitly unboxing.

Example –
Integer intObj = 786; // Autoboxing
Int intvariable = intObj.intValue();   // Explicit unboxing
//or
List listObj = new ArrayList();
listObj.add(new Integer(786));      // Explicit boxing
listObj.add(new Integer(787));      // Explicit boxing
int x = new Integer(listObj.get(0)).intValue(); // Explicit unboxing
int y = new Integer(listObj.get(1)).intValue(); // Explicit unboxing

Comments

  1. Hi,
    Autoboxing is a great feature provided by JAVA5 but using it blindly may result in very subtle problem which will take hours and hours to
    debug and find. to read more see the link
    What is the problem while using '==' in autoboxing world in Java 5 ?

    Thanks
    Javin

    ReplyDelete

Post a Comment

Popular posts from this blog

What is NBioBSP Java Library?

The NBioBSP Java Library (NBioBSPJNI.jar) is designed to support developers using JAVA
environment.
NBioBSP Java Library based Java Native Interface Technology that facilitates easily integration of
NBioBSP by developers using Java development.
The NBioBSP Java Library also uses NBioBSP.dll and provides higher level of interfaces.
NBioBSP Java Library supports almost all NBioBSP functions.

Only valid for NBioBSP.dll version 4.781 or higher.
Only valid for JDK version 1.5.0_20 or higher.





File list :-

■ NBioBSPJNI.jar
This is the java library of the eNBSP SDK.

■ NBioBSPJNI.dll
It implements all java native interfaces. It use with the windows platform.

■ NBioBSPJNI.so
It implements all java native interfaces. It use with the Linux platform.

Draw arrow line example

Draw arrow line example - 
Its a complete example

import java.awt.*;
import java.awt.geom.*;
import javax.swing.*;

public class Test
{
public static void main (String args[])
{
SwingUtilities.invokeLater ( new Runnable () {
Test arrows = new Test();


public void run () {
JFrame frame = new JFrame ( "Arrows" );

frame.add ( new JPanel() {
public void paintComponent ( Graphics g ) {
arrows.draw ( ( Graphics2D ) g, getWidth(), getHeight() );
}
}
, BorderLayout.CENTER );

frame.setSize ( 800, 400 );
frame.setDefaultCloseOperation ( JFrame.EXIT_ON_CLOSE );
frame.setVisible ( true );
}
} );
}

interface Arrow {
void draw ( Graphics2D g );
}

Arrow[] arrows = { new LineArrow(), new CurvedArrow() };

void draw ( Graphics2D g, int width, int height )
{
g.setRenderingHint ( RenderingHints.KEY_ANTIALIASING, RenderingHints.VALUE_ANTIALIAS_ON );

g.setColor ( Color.WHITE );
g.fillRect ( 0, 0, width, height );

for ( Arrow arrow : arrows ) {
g.setColor ( Color.ORANGE );
g.fillRect ( 350, 20, 20, 2…

Capture image from webcam java code, examples

import java.applet.Applet;
import java.awt.BorderLayout;
import java.awt.Component;
import java.awt.Dimension;
import java.awt.Frame;
import java.awt.Graphics;
import java.awt.Graphics2D;
import java.awt.Image;
import java.awt.Panel;
import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;
import java.awt.event.WindowAdapter;
import java.awt.event.WindowEvent;
import java.awt.image.BufferedImage;
import java.io.FileOutputStream;
import java.net.MalformedURLException;
import java.net.URL;

import javax.media.Buffer;
import javax.media.CaptureDeviceInfo;
import javax.media.CaptureDeviceManager;
import javax.media.Manager;
import javax.media.MediaLocator;
import javax.media.Player;
import javax.media.control.FrameGrabbingControl;
import javax.media.format.VideoFormat;
import javax.media.util.BufferToImage;
import javax.swing.JButton;
import javax.swing.JComponent;

import com.sun.image.codec.jpeg.JPEGCodec;
import com.sun.image.codec.jpeg.JPEGEncodeParam;
import com.sun.ima…