Monday, 10 September 2018

How to display duplicate characters in given a string using java

package com.java.collections;

import java.util.HashMap;
import java.util.Iterator;

public class DuplicateCharacters {
   
    static void findDuplicateCharacters(String str) {
       
        HashMap<Character, Integer> hm = new HashMap<>();
       
        for(int i=0; i<str.length();i++)
        {
            char c = str.charAt(i);
           
            if(hm.get(c)!=null)
            {
                hm.put(c, hm.get(c)+1);
            }
            else
            {
                hm.put(c, 1);
            }
                       
        }
           //System.out.println(hm);
        Iterator<Character> c = hm.keySet().iterator();
        while(c.hasNext())
        {
            char temp = c.next();
            if(hm.get(temp)>1)
            {
                System.out.println("the Character " + temp + " appeared " + hm.get(temp) + " times");
            }
        }
    }

    public static void main(String[] args) {
       
        findDuplicateCharacters("i i am am java java and and");

    }

}

How to find duplicate words in a given sentence or in a string using java

package com.java.collections;

import java.util.HashMap;
import java.util.Iterator;

public class DuplicateString {
   
    static void findDuplicateWord(String str) {
       
        HashMap<String, Integer> hm = new HashMap<>();
       
        String[] s = str.split(" ");
       
        for(String tempString : s)
        {
            if(hm.get(tempString)!=null)
            {
                hm.put(tempString, hm.get(tempString)+1);
            }
            else
            {
                hm.put(tempString, 1);
            }
           
        }
         //   System.out.println(hm);
        Iterator<String> tempString = hm.keySet().iterator();
        while(tempString.hasNext())
        {
            String temp = tempString.next();
            if(hm.get(temp)>1)
            {
                System.out.println("the word " + temp + " appeared " + hm.get(temp) + " times");
            }
        }
    }

    public static void main(String[] args) {
       
        findDuplicateWord("i i am am java java and and");

    }

}

Sunday, 9 September 2018

Spring Basics Part-1

Basics of Spring:
1.What is Spring?
A.Spring   is a light weight framework. It is one of the most popular open source framework
    for developing enterprise applications.

2.What is Spring Framework?
A.The Spring Framework is an application framework and inversion of control container for the
    Java Platform.
    The Spring framework comprises several modules such as IOC, AOP, DAO, Context, ORM,
    WEB MVC etc.


3.What are main Advantages of Spring Framework?
A.
  1. Spring is a light weight framework and It minimally invasive development with POJO.
  2. Spring achieves the loose coupling through dependency injection and interface based programming.
  3. Spring supports declarative programming through aspects and common conventions.
  4. Boiler Plate Redution through aspects and templates.


Tuesday, 4 September 2018

How to write a sql to get user and sysdate details or to audit db in oracle


CREATE OR REPLACE TRIGGER NEW_TRIGGER_NAME BEFORE UPDATE OR DELETE
ON <TABLE_NAME>
DECLARE
usr_name varchar2(60);
time_stamp date := sysdate;
the_sql varchar2(3005);

BEGIN
usr_name := sys_context('userenv' 'os_user');
the_sql := substr ( sys_context('userenv' 'current_sql'), 1, 3000);

insert into table_audit values ('QAA',usr_name, time_stamp, the_sql);

EXCEPTION
WHEN OTHERS
THEN
-- Consider logging the error and then re-raise
RAISE;
END;

How to find the current OS user using oracle sql

select sys_context( 'userenv', 'os_user' ) from dual;