Friday, 27 November 2015

PL/SQL

Exception handling
Sample
  EXCEPTION
                     WHEN OTHERS THEN  
                      dbms_output.put_line('we get exception'||sqlcode);
                      dbms_output.put_line('we get exception'||sqlerrm);
                      dbms_output.put_line('we get exception');

Tuesday, 20 October 2015

Connect to Oracle mails through Mobile

Hi friends,

I have seen many of my friends searching for stbeehive and chat configuration.

Following are the few simple steps to enable you to check mail and chat from your mobile with your oracle id:
1.For enabling chat in your android mobile first download "IM+" app from android market. After downloading, open the app and click on Add Account and enter the details as given below:
login: abcd@oracle.com
password: your oracle password
host: stbeehive.oracle.com
Port: 5223
Priority: 5
Resource: IM+ Android
Check "Use old-style SSL"
and then save.
Now you can chat with any of your colleagues at oracle

2.For enabling stbeehive mail in your android mobile first download "K-9 Mail" app from android market. After downloading, open the application and click on add account and following are the details:
email address: abc@oracle.com
Password: your oracle password
click on Manual Setup and click IMAP and enter following details:
username:abc@oracle.com (append oracle.com at the end)
IMAP server: stbeehive.oracle.com
security type: SSL(if available)
Auth type: PLAIN
Port: 993
and click "Next".
You will get another screen asking for Outgoing server settings. Enter the following details:
SMTP server: stbeehive.oracle.com
Security Type: SSL(if available)
Port: 465
Leave other details as it is and click "Next".
Enter the "Account options" as you want and click "Next".

Now you will be able to receive stbeehive mails and even reply back to those mails from your android mobile.

Enjoy!!!

Wednesday, 22 April 2015

Mobile(Tips and Tricks)

For android OS
 If u want your custome ringtones then you have to make a folder in internal sdcard .. Which sholud be named "media" inside it create another folder naming "audio" n inside it "ringtones" .
Name exactly as it has been quoted .. The ringtone you want u can save it in ringtone folder ...

Friday, 10 April 2015

Comparator And Comparable

Comparator vs Comparable
ParameterComparableComparator
Sorting logicSorting logic must be in same class whose objects are being sorted. Hence this is called natural ordering of objectsSorting logic is in separate class. Hence we can write different sorting based on different attributes of objects to be sorted. E.g. Sorting using id,name etc.
ImplementationClass whose objects to be sorted must implement this interface.e.g Country class needs to implement comparable to collection of country object by idClass whose objects to be sorted do not need to implement this interface.Some other class can implement this interface. E.g.-CountrySortByIdComparator class can implement Comparator interface to sort collection of country object by id

Sorting method
int compareTo(Object o1)
This method compares this object with o1 object and returns a integer.Its value has following meaning
1. positive – this object is greater than o1
2. zero – this object equals to o1
3. negative – this object is less than o1
int compare(Object o1,Object o2)
This method compares o1 and o2 objects. and returns a integer.Its value has following meaning.
1. positive – o1 is greater than o2
2. zero – o1 equals to o2
3. negative – o1 is less than o1
Calling methodCollections.sort(List)
Here objects will be sorted on the basis of CompareTo method
Collections.sort(List, Comparator)
Here objects will be sorted on the basis of Compare method in Comparator
PackageJava.lang.ComparableJava.util.Comparator

Print Friendly Version of this pagePrint Get a PDF version of this webpagePDF

Thursday, 5 March 2015

Programs

1.Word count in Java?
public class WordCount{

  public static void main(String[] args) {
    String s = "Count the No of words in the given String. String given is ";
    String array[] = s.split(" ");
    List<String> arrayList = Arrays.asList(array);
    Map<String, Integer> map = new HashMap<String, Integer>();
    for (String string : arrayList) {
      if (map.get(string) == null)
        map.put(string, 1);
      else
        map.put(string, map.get(string) + 1);
    }
    System.out.println("Word Count = " + map);
  }
}
O/P:
Word Count = {of=1, is=1, Count=1, given=2, words=1, String=1, String.=1, the=2, No=1, in=1}

2.How to find the duplicate number in the given integer array?
Conditions : the given string should be in sequence from 1 to n(only one number should be duplicated) .
 public class DuplicateNumber{

  public static void main(String[] args) {
    int[] i = { 1, 2, 3, 4, 5, 6, 6, 7, 8 };
    Arrays.sort(i);
    int sum = 0;
    for (int j = 0; j < i.length; j++) {
      sum = sum + i[j];
    }
    int max = i[i.length - 1];
    int total = max * (max + 1) / 2;
    int miss = total - sum;
    System.out.println(Math.abs(miss));
  }
}
O/P:
The duplicated number is : 6

3. Find the count of letters in the file?
public class CountofLettersString {
  public static void main(String[] args) {
    String str = "CHINNA";
    Map<Character, Integer> wordSet = new HashMap<Character, Integer>();
    Map<Character, Integer> letterCount = new HashMap<Character, Integer>();
    System.out.println("Through String");
    printletterCount(str, letterCount);
    System.out.println("Character" + "-->Count");
    for (Character ch : letterCount.keySet()) {
      System.out.println(ch + "\t--> " + letterCount.get(ch));
    }
    letterCount.clear();
    readthefile(wordSet, letterCount);
    System.out.println("Through File");
    System.out.println("Character" + "-->Count");
    for (Character ch : letterCount.keySet()) {
      System.out.println(ch + "\t--> " + letterCount.get(ch));
    }
  }

  public static void readthefile(Map<Character, Integer> wordSet, Map<Character, Integer> letterCount) {
    Scanner wordFile = null;
    String word;
    try {
      wordFile = new Scanner(new FileReader("words.txt"));
    }
    catch (FileNotFoundException e) {
      e.printStackTrace();
    }
    while (wordFile.hasNext()) {
      word = wordFile.next();
      printletterCount(word, letterCount);
    }
  }

  public static void printletterCount(String str, Map<Character, Integer> letterCount) {
    if (str != null) {
      for (Character c : str.toCharArray()) {
        if (c.isSpaceChar(c)) {
          continue;
        }
        Integer count1 = letterCount.get(c);
        int newCount = (count1 == null ? 1 : count1 + 1);
        letterCount.put(c, newCount);
      }
    }
  }
}
O/P:
Through String
Character-->Count

A    --> 1
C    --> 1
N    --> 2
H    --> 1
I    --> 1
Through File
Character-->Count

A    --> 1
C    --> 1
N    --> 2
H    --> 1
I    --> 1

4.convert string to number without using Parse method?
public class MyStringToNumber {
  public static int convert_String_To_Number(String numStr) {
    char ch[] = numStr.toCharArray();
    int sum = 0;
    int zeroAscii = '0';// Converts the char to int
    for (char c : ch) {
      int tmpAscii = (int) c;// converts the every character of an arry to int
      sum = (sum * 10) + (tmpAscii - zeroAscii);
    }
    return sum;
  }
  public static void main(String[] args) {
    System.out.println("\"3256\" == " + convert_String_To_Number(",jzxcb"));
  }
}


Print Friendly Version of this pagePrint Get a PDF version of this webpagePDF

Thursday, 20 November 2014

Pass By Value In Java



We have
int x= 10;
String y = “Word”;
Employee emp = new Employee();
Now the data store in Stack and Heap how means
Stack                                                                                              Heap
(Stores the primitive data type values )                                  (Stores the referenced objects data)


Now java supports only passbyValue();
Not the passbyReference();
How means
For primitive data types the data stored in Stack as shown above. While accessing the data it send the data as copy of value.
For referenced object related will be store in Heap as shown above. While accessing the data it sends the objects data as copy of reference value.

Diff between copy of value and copy of reference value
EX:
import java.util.ArrayList;
import java.util.List;
public class PassByValue {
  public static void addList(List  l){
    l.add("1");
    l.add("6");
  }
  public static void addInt(int xx){
    xx = 1000;
  }
  public static void main(String[] args) {
            List list = new ArrayList();
            addList(list);
            System.out.println("List Size : "+list.size());
            int x =10;
            addInt(x);
            System.out.println("Integer Value of X : "+x);  
  }
}
O/P:
List Size : 2
Integer Value of X : 10

 

System.out.println(x); it print value as 10 only because the copyofxValue has changed from 10 to 1000. But not the original value of x.

 
 



System.out.println(list.size()); it prints as 2. Because both list and l are referred to the same object reference value i.e, 0X10. So if we change the data structure of list in addList() method that is also reflected in main() method.

Other main Concept is in Strings

String constant pool(SCP)

Before going to this SCP(String Constant Pool) lemme say difference between
1) String s= new String (“hello”);   and
2) String s=”hello”;
In the first case two obects will be created. one in heap and the other in SCP.(s will always refer to heap object but not to SCP)
In the second case only one object will be created in SCP and s will always refer to the object in SCP.
Object creation in SCP is always optional, first JVM checks if there is any obect present with the required content , if exists then will use the same else create new object. i.e SCP do not allow duplicate objects.
GC(garbage collector) is not allowed to enter SCP. But when ever JVM shutdown, automatically SCP area gets flushes out.
The main adv of this approach is memory utilaization will be improved hence the perforamnce improves.(Coz object creation is lil costly in java.)
 
 
Print Friendly Version of this pagePrint Get a PDF version of this webpagePDF

Simplest way to display Server Time in JSP using js

THE BELOW CODE WORKS ONLY IN JSP : <html> <body > <table width="95%" border="1" cellpadding="1...