Wednesday 24 July 2013

What is a Global Temporary Table in Oracle?



Global Temporary Table:
The oracle gives the advantage of creating the session specific tables known as Global temporary table.
They are same as the other tables in oracle except that they are exclusive for every session means that the data in temporary table is private to the session (i.e. each session can see and modify its own data). The LOCK statement has no effect on a temporary table because each session has its own private data.
A TRUNCATE statement issued on a session-specific temporary table truncates data in its own session.
It does not truncate the data of other sessions that are using the same table.

Syntax for creating Global Temporary Table:
·         Session Level Global Temporary Table:-
    Create global temporary table temp_table (column1  NUMBER,column2  NUMBER)
    on commit preserve rows

·         Transaction Level Global Temporary Table:-
    Create global temporary table temp_table (column1  NUMBER,column2  NUMBER)
     on commit delete rows;


The ON COMMIT DELETE ROWS clause indicates that the data should be deleted at the end of the transaction.
The ON COMMIT PRESERVE ROWS clause indicates that rows should be preserved until the end of the session.


Summary:

·         You can create indexes for temporary tables using the CREATE INDEX statement. Indexes created on temporary tables are also temporary, and the data in the index has the same session or transaction scope as the data in the temporary table.
·         You can create views that access both temporary and permanent tables.
·         You can also create triggers on temporary tables.
·         You can perform DDL statements (ALTER TABLE, DROP TABLE, CREATE INDEX, and so on) on a temporary table only when no session is currently bound to it. A session gets bound to a temporary table when an INSERT is performed on it. The session gets unbound by a TRUNCATE, at session termination, or by doing a COMMIT or ABORT for a transaction-specific temporary table.

Tuesday 23 July 2013

What is the difference between Checked and Unchecked Exception in Java?



Checked Exception: - All the exceptions which required to be catches and handled at the compile time otherwise a compilation error will be given are known as the checked exception. All checked exception is direct sub Class of Exception but not inherit RuntimeException.
Checked Exception are helpful in ensuring that programmer provide recovery strategy or at least handle the scenario gracefully which can fail the program execution.

Type of checked Exception:-
Following are some Examples of Checked Exception:

1.       IOException
2.       SQLException
3.       DataAccessException
4.       ClassNotFoundException
5.       InvocationTargetException

Advantages and Disadvantages of Checked Exception:-

1.       They help to execute the program by handling some known failure situations.
2.       In long programs, we can location and type of error by handling the proper exceptions.
3.       They are useful in writing the log files for a program.
4.       They make the code complex and less readable

Unchecked Exception:-
All the exceptions whose handling cannot be handled at compile time are known as the Unchecked Exceptions. They mostly arise due to programming errors like accessing method of a null object, accessing element outside an array boundary.  Unchecked Exceptions are direct sub Class of RuntimeException.

Types of Unchecked Exception:-
Here are few examples of Unchecked Exception:

1.       NullPointerException
2.       ArrayIndexOutOfBound
3.       IllegalArgumentException
4.       IllegalStateException


Some Important points:
1. Both Checked and Unchecked Exception are handled using keyword try, catch and finally.
2. In terms of Functionality Checked and Unchecked Exception are same.
3. Checked Exception handling verified during compile time.
4. Unchecked Exception are mostly programming errors
5. JDK7 provides improved Exception handling code with catching multiple Exception in one catch block and reduce amount of boiler plate code required for exception handling in Java.

Monday 22 July 2013

What is the difference between GET and POST method in java?


Get and Post are both the method of HTML form element and they are used to transfer data with the request when the submit button is pressed as:
 

<form action="firstServlet" method="get">     

         <table>

            <tr> <td>

                 <input type="Text" name="UsrName"/>

            </td> </tr>

            <tr><td>

                 <input type="Text" name="pswd"/>

           </td> </tr>

            <tr><td>

                 <input type="submit" name="submit" value="Submit"/>

           </td></tr>

        </table>

</form>

In the above code we have two text box’s  user name and password and one submit button, When we click on the submit button after putting values in the user name and password boxes the control will transfer to the “firstServlet” servlet with the user name and password entered.

The main differences between GET and POST method are as follow.

 

GET

POST

Get request contents are visible in URL

Post request contents are embedded in the body of HTTP request

Get method can only contain data up to 255k

NO such limit for post method

Get request can be cached

Post request contents are not a part of URL so they cannot be cached

Get requests are usually faster than post requests

They are slower than get because they need some extra time to encapsulate in the body of request

Get is a by default method of HTML form element

Post method need be specified for use

Get request can only contain the text data

Post can contain text as well as binary data

 

What is Assertion in Java?




According to Sun, we can use assertion to test our assumption about programs. That means it validates our program!
In another words we can say that assertions ensures the program validity by catching exceptions and logical errors. They can be stated as comments to guide the programmer. Assertions are of two types:

1.       Preconditions: Preconditions are the assertions which invokes when a method is invoked.
2.       Postconditions:  Postconditions are the assertions which invokes after a method finishes. 
Where to use Assertions?
We can use assertions in java to make it more understanding and user friendly, because assertions can be used while defining preconditions and post conditions of the program.

Example of AssertionExample.java

import java.util.Scanner;

public class AssertionExample
  {
 public static void main( String args[] )
  {
  Scanner scanner = new Scanner( System.in );

  System.out.print( "Enter a number between 0 and 20: " );
  int value = scanner.nextInt();
  assert( value >= 0 && value <= 20 ):
  "Invalid number: " + value;
  System.out.printf( "You have entered %d\n", value );
 }
  }

 Before running above example enable  the assertion at your environment with following command.
java -ea AssertionExample