Gadgets

Saturday, 12 March 2016

Hibernate web application with CRUD operations using eclipse IDE

Hibernate CRUD operations in Eclipse

Here we have hibernate web application with CRUD operations using eclipse IDE and using Netbeans IDE 
Here I have created a registration form and servlet to insert data into database, and same as I done operations retrieve, update, and delete.
You need to follow the below steps to create hibernate application:
1.      Create the Dynamic web project
2.      Load the required jar files
3.      Create the persistent class
4.      Create the mapping file for persistent class
5.      Create the configuration file
6.      Create the classes that store, retrieve, update, and delete.
7.      Run the application

It is very simple to understand, don’t feel like it is hard and programs are so long.

Read also: 

Wednesday, 9 March 2016

java program for super keyword

Write a java program to given the example for “super” keyword.


super() is used to invoke super class constructors and super keyword is refer super class members.
in this program i did show the difference with and without super keyword.
by using super keyword we can access parent class properties.

public class SuperTest {
       int number=10;
       SuperTest(){
        System.out.println("parent class constructor ");
       }     
}
class Test extends SuperTest{    
       int number=20;      
       Test(){
              super();
              System.out.println("using super keyword :" +super.number);
              System.out.println("with out using super keyword :" +number);
       }     
       public static void main(String[] args) {
              Test obj=new Test();      
       }
}

OUTPUT:

/*
parent class constructor
using super keyword :10
with out using super keyword :20
*/

Tuesday, 8 March 2016

java program for static variables, methods, and blocks.

Write a java program to demonstrate static variables, methods, and blocks.

We can access static variables, blocks, and methods without creating object as shown in the below program.
JVM first check for the main method and after checking the main method it will execute static block after that execute remaining code.
public class StaticTest {
       static int id=1214; 
       static{
              String name="narendar";
              System.out.println("static block "+name);
       }
       static void display(){
              String group="CSIT";
              System.out.println("static method "+group);
       }     
       public static void main(String[] args) {
              System.out.println("static variable "+id);
              display();          
       }
}

Output:

/*
static block narendar
static variable 1214
static method CSIT

*/

java program for exception handling mechanism

 Write a java program that describes the exception handling mechanism.

To handle exception we use try, catch, finally block. In try block we write risky code. If any exception will occur in try block, that exception handle in catch block. Try block will execute if exception is occur or not.
In this program we will get ArithmeticException in try block, we are handling that exception in catch block.
We will get output catch-finally block instead of try block.
public class ExceptionTest {
       public static void main(String[] args)
       {
              try
              {
                     int a=10;
                     int b=0;
                     int c=a/b;
                     System.out.println(c);
              }
              catch(ArithmeticException ae)
              {
                     System.out.println(10);                 
              }
              finally
              {
                     System.out.println("finally");
              }            
       }
}

OUTPUT:

/*
10
Finally
*/

Example for command line arguments

Write a java program give example for command line arguments.

public class CammandTest {
       public static void main(String[] args) {
              System.out.println(args[0]);
              System.out.println(args[1]);
              System.out.println(args[0]+args[1]);
       }
}

OUTPUT:

/* D:\Java>java CammandTest javathub blogspot
javathub
blogspot
javathubblogspot*/

Monday, 7 March 2016

Default values of all primitive data types

Write a java program to display default value of all primitive data types of java.

Default Values of all primitive data types:


Data Type
Default Value
byte
0
short
0
int
0
long
0L
float
0.0f
double
0.0d
char
‘u0000’
String
null
boolean
false

public class DefaultValue {
       byte b;
       short s;
       int i;
       long l;
       float f;
       double d;
       char ch;
       String str;
       boolean flag;      
       public static void main(String[] args) {             
              DefaultValue dv=new DefaultValue();
              System.out.println("byte value : " +dv.b);
              System.out.println("short value : " +dv.s);
              System.out.println("int value : " +dv.i);
              System.out.println("long value : " +dv.l);
              System.out.println("float value : " +dv.f);
              System.out.println("double value : " +dv.d);
              System.out.println("char value : " +dv.ch);
              System.out.println("String value : " +dv.str);
              System.out.println("boolean value : " +dv.flag);
       }
}

OUTPUT:

byte value : 0
short value : 0
int value : 0
long value : 0
float value : 0.0
double value : 0.0
char value :
String value : null
boolean value : false
we get blank space for char data type 

Saturday, 5 March 2016

Store the details into database using spring framework

Store the details in database using spring framework

 

Steps to create spring MVC web application:

1.      Load the required jar file.
2.      Create the request page to give input.
3.      Create the Controller class.
4.      Create the web.xml file.
5.      Create the spring configuration xml file.
6.      Create output page
7.      Run the project.

Friday, 4 March 2016

Spring MVC Login application

Spring MVC Login application

In this page, I have given spring MVC login application step by step.


Steps to create spring MVC web application:

1.      Load the required jar file.
2.      Create the request page to give input.
3.      Create the Controller class.
4.      Create the web.xml file.
5.      Create the spring configuration xml file.
6.      Create output page
7.      Run the project.

spring MVC web application

First spring MVC web application

In this page, I have given first spring MVC web application step by step.
 In this spring MVC web application we will get the output message on the web browser along with input field as shown in the bellow.


Steps to create spring MVC web application:


Note: load the jar files in lib folder also
1.      Load the required jar file.
2.      Create the request page to give input.
3.      Create the Controller class.
4.      Create the web.xml file.
5.      Create the spring configuration xml file.
6.      Run the project.