Tuesday, 5 August 2014

Difference Between Bitwise operator and Short-circuit operator

Bit-wise operator :-


  •  In Bit wise operator both argument   
     are evaluated. 

  •  It work with both integral ans Boolean.                                 

  •  Relatively performance is slow.


Short-circuit operator :-


  • In Short-circuit operator 2nd  argument  evaluation is optional

  • It work with only Boolean type only.   

  • Relatively performance is fast


note:

&-operator ---> if both argument are true then only result is true otherwise false
 

|  -operator   ---> if at least one argument is false then result is false otherwise true

In Short-circuit operator

T && T  --

In this case the 1st argument is true then only 2nd argument is evaluated
           if 1st argument is false then 2nd argument is not evaluated.

Saturday, 2 August 2014

Rownum and Row-id Feature of Oracle Database



Rownum:

  • Rownum is pseudo column and behave like table column.
  •  It having temporary value.
  •  It assign number  to each row in table at time of selection.
rownum has value < ,<= value it can't worked with > value

Row-id:


when we are inserting data into table Oracle server automatically generates an unique 
identification number for identifying record uniquely.



The Main Difference between Rownum and Row-id is
Rownum is temporary values where Row-id having fixed valued it cannot changed.

Some Example:


SQL> select * from t1;

       SNO NAME       ADDRESS
---------- ---------- ----------
         1 kunal      nagar
        21 sachin     parbhani
        11 vabhaiv    satara
        44 jags       daund

SQL> select * from t1 minus (select * from t1 where rownum <=(select count(*)-1 from t1));

       SNO NAME       ADDRESS
---------- ---------- ----------
        44 jags       daund

SQL> select * from t1 minus (select * from t1 where rownum <=(select count(*)-2 from t1));

       SNO NAME       ADDRESS
---------- ---------- ----------
        11 vabhaiv    satara
        44 jags       daund


SQL> select rowid,rownum,sno,name from t1;

ROWID                  ROWNUM        SNO NAME
------------------ ---------- ---------- ----------
AAARC0AAEAAAAA/AAA          1          1 kunal
AAARC0AAEAAAAA/AAB          2         21 sachin
AAARC0AAEAAAAA/AAC          3         11 vabhaiv
AAARC0AAEAAAAA/AAD          4         44 jags

SQL>



Tuesday, 22 July 2014

Difference between length and length()...????

ans:-

length:-

  • -It is final variable applicable for arrays .
  • -It is used to calculate length of array.


length():-

  • -It is final method of String class.
  • -It is applicable for String.
  • -It is used to calculate number of char present in String.
  • -It's return type is integer.

Monday, 14 July 2014

Is there is any way to stop execution of finally block

yes ,we can stop execution of finally block but condition is that control must entered into the finally block
finally block is executed only when control entered into try block so we need write code in try block to stop execution of finally block

//Simple example to Demonstrate above concept without stoping execution of finally block:


public class MainAppp {

/**
* @param args
*/
public static void main(String[] args) {
// TODO Auto-generated method stub
     try
     {
    System.out.println("IN THE TRY BLOCK");
     }
     finally
     {
    System.out.println("IN THE FINALLY BLOCK");
     }

}

}

O/P
IN THE TRY BLOCK
IN THE FINALLY BLOCK

//Simple Example To Stop Finally block Execution




public class MainAppp {

/**
* @param args
*/
public static void main(String[] args) {
// TODO Auto-generated method stub
     try
     {
    System.out.println("IN THE TRY BLOCK");
     System.exit(0);
     }
     finally
     {
    System.out.println("IN THE FINALLY BLOCK");
     }
}

}

O/P:
IN THE TRY BLOCK

Explanation
System.exit(0):
0--- indicate status code  it means normal termination
nonzero--indicate abnormal termination.


Monday, 16 June 2014

How to print without main method

There is example that demonstrate above concept


public class Mainapp {

/**
* @param args
*/

static
{
System.out.println("hi...");
System.exit(0);
}

}


O/P:

hi...

this is one of the important question ask in interviews...
plz go through it..

Tuesday, 14 January 2014

Properties Class

We can used Property Class object to represent key-value pair were both key -value are of String type only.

In our program if there is anything which is change frequently(like database username ,password) never recommended to hard code in java program because of every change in java program we have to recompile,run  & deploy of application and even sometimes we may required to restart the server sometime these may cause business impact on client .

such type of variable(that may change frequently) we have to declare in file with extension .properties
The main advantage if there is any change in properties file  to reflect that change just redployment is enough ,which may not create business impact on client.  

Simple program to demonstrate Properties class :

//propertiesDemo.java

import java.io.*;
import java.util.*;
class propertiesDemo
{
    public static void main(String[] args) throws Exception
    {
        //System.out.println("Hello World!");
   
    Properties p=new Properties();
    FileInputStream f=new FileInputStream("kunal.properties");
    p.load(f);
    System.out.println(p);
    p.setProperty("kunu","1111");
    p.setProperty("courase","java") ;
    FileOutputStream f1=new FileOutputStream("kunal.properties");
    p.store(f1,"updates")
 }
}

//kunal.properties

#updates
#Tue Jan 14 19:44:12 IST 2014
user=scott
name=kunal
kunu=1111
courase=java
duration=four
pwd=tiger


Output:
c:\ocjp>JAVA propertiesDemo
{user=scott, name=kunal, kunu=1111, courase=java, duration=four, pwd=tiger}


in java program if we set property explicitly it also refelct in properties file and also
if we add any new property in kunal.properties it also refelect in console without compiling the java program.

Monday, 13 January 2014

Limitations of Arrays:

Arrays are fixed in size:

Once we create an array ,there is no chance of increasing or decreasing the size based on our requirement .

To used arrays concept compulsory ,we should know the size in advance,which may not be possible always.

Arrays concept is not implemented based on some data structure hence ready made method support is not available for arrays ,so for every requirement,programmer is responsible to write the code.