Saturday, 29 November 2014

What is the Different between Struts 1.x and Struts 2.x

Struts 1.x
Struts 2.x
In struts 1.x front controller is ActionServlet
In 2.x front controller is FilterDispatcher
In struts 1.x we have RequestProcessor class
In 2.x we have Interceptors instead RequestProcessor
In struts 1.x we have multiple tag libraries like, html, logic, bean..etc
In 2.x we do not have multiple libraries, instead we have single library which includes all tags
In struts 1.x the configuration file name can be [any name].xml and we used to place in web-inf folder
In 2.x the configuration file must be struts.xml only and this must be in classes folder
In struts 1.x we have form beans and Action classes separately
In 2.x form bean, Action classes are combinedly given as Action class only
In struts 1.x properties file must be configured in struts-config.xml
But in 2.x we need to configure our resource bundle(s) in struts.properties file
In struts 1.x we have programmatic and declarative validations only
In 2.x we have annotations support too along with programmatic and declarative validations

Functional Differences.
In struts 1.x declarative validations are done by using validation frame work
In 2.x, declarative validations are done by using xwork2 frame work by webwork the reason being, its support valuations through Annotations
·         In struts 1.x an Action class is a single ton class, so Action class object is not a thread safe, as a programmer we need to make it as thread safe by applying synchronization
o    In 2.x an Action class object will be created for each request, so it is by default thread safe, so we no need to take care about safety issues here
In struts 1.x we have only jsp as a view technology
In 2.x we have support of multiple view technologies like velocity, Free marker, jasper reports, jsp, etc
In struts 1.x Action class is having servlet dependency, because in execute() method accepts req, res parameter right
In 2.x Action class doesn’t have any servlet dependency, because its execute() method doesn’t accepts any parameters, however we can access all servlet objects with dependency injection 

Friday, 28 November 2014

What is different between optimistic locking and pessimistic locking?


What is the Reflection Api in Java?

Java Reflection makes it possible to inspect classes, interfaces, fields and methods at runtime, without knowing the names of the classes, methods etc. at compile time. It is also possible to instantiate new objects, invoke methods and get/set field values using reflection.

What is Locale Class in Java?

The java.util.Locale class object represents a specific geographical, political, or cultural region. .Following are the important points about Locale:
  • An operation that requires a Locale to perform its task is called locale-sensitive and uses the Locale to form information for the user.
  • Locale is a mechanism for identifying objects, not a container for the objects themselves.
     
  • For example, the AroundTheWorld program uses three Locale objects: one for the United States, one for France, and one for French Canada. These Locale objects do not contain the population, literacy rate, or any other AroundTheWorld specific data. The application-specific data is contained in resource bundles. The program uses a Locale object to identify what the current locale is and to decide which resource bundle to use to construct its display.  
  •  
  • Class Declaration:
    public final class Locale
       extends Object
          implements Cloneable, Serializable

Saturday, 15 November 2014

Java Program for Given int value to Reverse

import java.util.Scanner;
 
class ReverseNumber
{
   public static void main(String args[])
   {
      int n, reverse = 0;
 
      System.out.println("Enter the number to reverse");
      Scanner in = new Scanner(System.in);
      n = in.nextInt();
 
      while( n != 0 )
      {
          reverse = reverse * 10;
          reverse = reverse + n%10;
          n = n/10;
      }
 
      System.out.println("Reverse of entered number is "+reverse);
   }
}

Friday, 14 November 2014

JAVA Projects - Core Java Spring MVC Hibernate Servlets JSP'S

Servlets, JSP and Oracle Database Simple Login and Registration Example : 

Create the Table : Like Follwing
CREATE TABLE Registeruser(name varchar(25),password varchar(25),email varchar(25),phoneno number(10),address varchar(25));

JSP Pages:
index.jsp

Wednesday, 5 November 2014

Method Overriding with Constructors

In method Overriding If sub class having default constructor then must super class having default constructor otherwise we will get exception. To avoid these problem means we can't write the default constructor in super class then we can write the sub class super() method by passing argument.

 class Main
{
Main(){
System.out.println("i am from super class");
}
Main(int a){
System.out.println("i am from super constructor class");
}

public void m1()
{
System.out.println("i am from Main class");
}
}
public class Meth_ovr extends Main{
Meth_ovr(){
//super(9); If not write the super class constructor
System.out.println("i am from sub contructor");
}

public void m1()
{
System.out.println("i am from sub class");
}
public void m2()
{
System.out.println("i am from m2 class");
}
public static void main(String[] args) {

Meth_ovr m=new Meth_ovr();
m.m1();
//Main mr= new Main();
//mr1.m1();
Main mr1= new Main();
mr1.m1();
}

}

What is differences between functions and procedures in Java?

Sr.No.User Defined FunctionStored Procedure
1 Function must return a value.Stored Procedure may or not return values.
2Will allow only Select statements, it will not allow us to use DML statements.Can have select statements as well as DML statements such as insert, update, delete and so on
3 It will allow only input parameters, doesn't support output parameters.It can have both input and output parameters.
4It will not allow us to use try-catch blocks.For exception handling we can use try catch blocks.
5Transactions are not allowed within functions.Can use transactions within Stored Procedures.
6We can use only table variables, it will not allow using temporary tables.Can use both table variables as well as temporary table in it.
7Stored Procedures can't be called from a function.Stored Procedures can call functions.
8 Functions can be called from a select statement.Procedures can't be called from Select/Where/Having and so on statements. Execute/Exec statement can be used to call/execute Stored Procedure.
9A UDF can be used in join clause as a result set.Procedures can't be used in Join clause