Oct 27, 2014

Internals of Stored Procedure - JDBC


This post is very useful to know about internals of Stored Procedure. JDBC is used for database operations in java and Stored procedures are used for eliminating overhead from Java. Internals of Stored-Procedure will cover all the concepts like What is Stored Procedure, What is procedure, When do people prefer Stored Procedure, Advantages and uses of Stored Procedure, Disadvantage or flaws of Stored Procedures, API of Stored Procedure, Types of Procedure etc…
Before knowing about Stored Procedure we should know about What is Procedure? Procedure is nothing, It is a only function or method of database. These database methods contains group of SQL statements. We create procedure using PL/SQL programming.
Stored Procedure is nothing but it is one of the most useful mechanism for creating procedure in the database and called by java program is known as Stored Procedure.
There is a one big question that When do we prefer using Stored-Procedure? The answer of this question is that whenever we want to get allowance, gross salary etc. from database, we don’t need to create any logic to calculate allowance, gross salary in the java program. We will just create a separate procedure for calculating the allowance and gross salary and will get the desired result in our java program.

Advantage of Stored Procedure-

     Using stored Procedure the processing of data at the back-end database would be faster.
   Overhead on the java program can be reduce.
Disadvantage of Stored Procedure-
  Each and every database contains its own syntax of creating procedure. So if we want to change the database it will create problems due to changed syntax of each database. In this case we will need to write procedures again.

Note- Stored Procedure are not supported in M.S. Access (A Microsoft’s Product).
java.sql.CallableStatement interface is the API of Stored Procedure in Java.

Types of Stored-Procedure’s

There are 4 types of procedures in java.

1. Zero Parameterized Procedure
2. In-Procedure
3. Out-Procedure
4. In-Out Procedure

Zero Parameterized Procedure:

Those procedure which doesn’t contains any parameter is called Zero Parameterized Procedure.

SQL> create or replace

2 procedure prc1

3 Is

4 Begin

5 Update abc1 set name='VIKAS' where id=101;

6 End prc1;

7 /

Procedure created.


1.It is just like a method of java which is parameterized but void return type.
2. like pass the 'idno' or any conditional data as a parameter..

SQL> r/

1 create or replace

2 procedure prc2(aa IN number)

3 Is

4 Begin

5 Update abc1 set name='VIKAS' where id=aa;

6* End prc2;

Procedure created.


It is just a method of java which is contains zero parameter return.... like max, min,
count, sum etc.

SQL> create or replace

2 procedure prc3(abc OUT number)

3 Is

4 Begin

5 Select count(id) into abc from abc1;

6 End prc3;

7 /

Procedure created

In-Out Procedure:

It is just a method of java which is parameterized as well as return type .... like max,
min, count etc.

SQL> create or replace

2 procedure prc4(x IN number,y OUT number)

3 Is

4 Begin

5 Select max(id) into y from abc1 where id>=x;

6 End prc4;

7 /

Procedure created.

Creating CallableStatement Object:

Following code is for oracle database-





FROM EmpMaster



Note: This post is covering all of the fundamentals of stored procedures and related topics. For more details on other related topics, please visit blog-archive.

Thank You

Oct 13, 2014

Internals of Java Interface

Interface Internals in JAVA

Little description of java internals about Interface: Some people say, Interface is used to implement the concept of Multiple Inheritance,but purpose of Interface is not implementing the concept of Multiple Inheritance in Java, although it looks like Multiple Inheritance.

Apart from this It is very important to know that why do we need Interface? The answer is that, If we know about the entity, but don't know about the behavior then we need Interface.
A very simple example of Interface is as follows-

interface Animal
   void eat ();
class Goat implements Animal
    Void eat ()
        System.out.println("Goat is eating grass");
class Dog implements Animal
       void eat()
         System.out.println("Dog is barking");

Some important points for Interface-
1. Interface is a contract.
2. Interface is a contract between service provider and service utilizer.
3. Interface is a keyword of Java.
4. Interface is a user defined data type.
5. Interface is a reference data type.
6. Interface is also structure of java, because it generate .class file. i.e byte code.
7. Interface is the collection of zero or more than zero abstract method and zero or more           than zero final variable.
8. Object of Interface cannot be created.
9. Interface is a pure abstract class, because it only contains abstract method, not any               concrete method. 
10. Interface is a pure SUPER class.

Characteristics of Interface-
1. Method of Interface by default is an abstract.
2. Each and every method of Interface by default declared as a 'public abstract'. If you don't declare Interface as a public abstract,then it is duty of Java Compiler to use 'public abstract' with each method Interface. If we use any other access specifier with Interface method then compile time error is generated.
3. Each and every variable of Interface must be declared as 'public static final', if you don't use then it is duty of Java Compiler to use 'public static final' with each variable of Interface.

Note- 'implements' keyword is used to implement the property of interface in the class.

Working with JAVA Interface

There are some variations which are as follows-

1. One Interface extends another Interface

interface I1

interface I2 extends I1

2.one interface can extends zero or more than zero interface.

interface I1

interface I2

interface I3
interface I4 extends I1,I2,I3

3.one interface cannot extends/implement any class.

4.one class extends only one class and implements zero or more than zero interface.

class H

class J extends H implements I1,I2,I3,I4

Keywords used with Interface

1. public
2. abstract
3. default(by default)
4. strictfp
5. public abstract/abstract public

Oct 11, 2014

Types of Final Variable in Java

Final Variable

Before knowing types of final variable you should know What is a Final Variable? Final variable is a variable which  is declared using final keyword before it. For example,

Class Tst
   int final var1 = 10; // var1 is declared as final variable...

There are two very important related to Final Variables that are-

1. Final Variable's value never changes.

2. Final variable must be declared during declaration time.

Now, we will discuss about Types of Final variable.
There are following types of final variables-

1. Final Instance Variable
2. Final Static Variable
3. Final Local Variable
4. Final Block Level Variable
5. Final Parameterized Variable

1. Final Instance Variable -  Those variables which are declared as Final Instance i.e. Final                                                 Instance Variable.

2. Final Static Variable -       Those variables which are declared as Final Static i.e. Final                                                     Static Variable.

3. Final Local Variable -        Those variables which are declared as Final Local i.e. Final                                                     Local Variables.
Note-  Final variable may or may not be initialized at declaration time.

4. Final Block Level Variable-  Those variables which are declared as Final block level i.e.                                                 Final Block Level Variable.

5. Final Parameterized Variable-  Those variables which are declared as Final parameter                                                   in method  i.e. known as Final Parameterized  Variable. 
Note-    'final' is the one of the unique access modifier in java ,that can be use inside method or method parameter.

List of all keywords and reserved words in java

Java Keywords

What is a keyword? Keyword is a special word/reserved word which is already defined in the compiler. We can not use keywords in our program for declaring any variable or program name or in other declarations. Keywords definition is defined in the compiler.
For example, If you try to declare a variable with name 'try' that is not possible as 'try' is a keyword in java language. See following example.
  class Testpgm
    int try; //this variable can not be declared....
    public static void main(String[] args) 
       //class code....  
Below is lists of all Java keywords-
There are 53 keywords in java.
1. 48 special words.
2. 3 special words.
3. 2 unused words.

2 unused keywords
1. goto
2. const

3 reserve words
1. null
2. true
3. false

48 special words

keywords for flow control
1. if
2. else
3. do
4. while
5. for
6. return
7. switch
8. case
9. continue

keywords for Exception Handling

keywords for Access specifier

keywords for Access modifier

keywords for classes 

keywords for object 
36.instance of

Keywords for data type 

What does Java Compiler do

Job of Java Compiler

Before knowing What does Java Compiler do or Job of Java Compiler, You should know What is a compiler? Compiler is a collection of predefined programs which convert source code into machine understandable code. In case of Java Compiler source code is not converted into machine code directly, It is first converted into Byte code then translated into machine code by JVM. But other compiler directly convert source code into machine code. For ex- 'C' Compiler.
Due to this feature of Java, It is a Platform Independent Language. Java has both the Compiler and Interpreter. Compiler converts source code into byte code and the Interpreted i.e. JVM converts byte code into machine code.

Job of Java Compiler-

1. Java Compiler loads source code from Hard Disk to RAM.
2. Java Compiler converts source code into Intermediate code if source code is syntactically     correct.
3. Generate Byte Code i.e.  .Class file.

Note-  By default Byte code is saved into current working directory.

Oct 10, 2014

Internal mechanism of Platform Independent Language

Platform Independence means that no dependency on Platform. Here Platform mean is environment.We will know here Internal mechanism of Platform Independent Language. Learning Java is too easy but understanding it some what difficult. Any one can create programs on java but very few people know the Internal mechanism of java concepts. In this post we are going to discuss about Internal mechanism of Platform Independent Language. As we are discussing on Java and Java is also a Platform Independent Language. So I will explain Internal meaning of Platform Independence and What is the meaning of Platform Independent Language?
First of all think only one thing  that can you execute java program made in windows environment on Unix environment or vice versa? If you are unable to answer, I tell you. 'Yes' we can execute java program in any environment. For this only one thing is needed that is called JVM. Java's most powerful feature is that program written in java can we run on any platform. This powerful feature of java makes it a Platform Independent Language. Java is able to do this by JVM. JVM stands for JAVA VIRTUAL MACHINE. JVM is the interpreter that  translates java byte code into machine code.Due to this programs are executed on any machine. 
So, Platform Independent Language means, the language that does not depend on any platform. Program written on that language can be run any where on any platform. Program made on Platform Independent Languages are called as Platform Independent Programs. We can explain Platform Independent Programs as the programs which are created and compile on one particular machine and are able to execute any where i.e. on any O.S.