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;

Friday, 3 August 2018

How to get rid off blank line in csv file using oracle sql or sql plus

SET NEWPGE NONE

The above command add in the sql script so that the blank line will get rid of from the  csv output file

Tuesday, 31 July 2018

Data Anonymisation

Data anonymization:
It  is a type of information sanitization whose intent is privacy protection. It is the process of either encrypting or removing personally identifiable information from data sets, so that the people whom the data describe remain anonymous.

Friday, 27 July 2018

Monthly data Extraction Logic using Oracle SQL

The following logic is used to get data from Database for monthly data extraction

For example if you want employee attendance data from DB for monthly then logic will be like shown in below

Select  Emp_attendance from Employee where Emp_attendance between add_months(trunc(sysdate,'mm'),-1) and last_day(add_months(trunc(sysdate,'mm'),-1)) ;

You can cross check whether the logic is getting correct dates or not by firing the below queries in sql developer or any tool you used to execute the queris

The below query will give you the first day date of  last month:
select add_months(trunc(sysdate,'mm'),-1) from dual;

The below query will give you the last day date of  last month:
select last_day(add_months(trunc(sysdate,'mm'),-1)) from DUAL;

Thursday, 5 July 2018

Java program to check the given two strings in an Array are anagrams or not

package learning;

import java.util.Arrays;

public class Anagram {

    public static void main(String[] args) {

        String[] s = new String[]{"raw", "aar"};
   
         char[] s0 = s[0].toLowerCase().toCharArray();
       
         char[] s1 = s[1].toLowerCase().toCharArray();

         Arrays.sort(s0);

         Arrays.sort(s1);
        
         if(Arrays.equals(s0, s1)) {
             System.out.println("The given two words in the array are anagrams");
       
        }
         else {
             System.out.println("The given two words are not anagrams");
         }

    }

}

Wednesday, 4 July 2018

Finding the possibility of Adding two numbers in an given array and finding the number which we give at runtime in java

package learning;

import java.util.Scanner;

public class FindingNoOfPossibilitiesOfAddingTwoNumbersInAnArray {

    public static void main(String[] args) {

        Scanner sc = new Scanner(System.in);

        int s[] = { 1, 2, 3, 4, 5 };
        int a = s.length;
        System.out.println("Enter your number");

        int b = sc.nextInt();

        for (int i = 0; i < a; i++) {

            if (s[i] < a) {

                for (int x = a; x > i; x--) {
                    if (s[i] + s[x - 1] == b) {
                        System.out.println("s[i] is :"+s[i]);
                        System.out.println("s[x-1] is :"+s[x-1]);
                        System.out.println("The possible sum of two numbers is "+(s[i] + s[x - 1]));
                    }
                }
            }

        }

    }

}

Thursday, 31 May 2018

Websphere Basics

Questions & Answers
1. What is master repository?

A. Deployment manager contains the MASTER configuration and application files.
   All updates to the configuration files should go through the deployment manager.

2. What about IHS?

A. IHS (IBM HTTP Server) is one of the web servers.
   It serves the static content only and it takes up only http requests.

3. What about plug-in?

A. Plug-in is one of the modules it is interface between application server and web server,
   the plug-in process receives the request from the client first.
   If the request is for dynamic content,
   the plug-in diverts the request to the websphere application server.
   If the request is for static content,
   the plug-in forwards it to the Http server.

4. What is SSL?

A. ssl(secure socket layer) is a protocol for providing encrypted data communications between two processes.

5. What is the difference between web server and application server?

A. Application Server: takes care of Security, Transaction, Multithreading, Resource pooling,
   load balancing, clustering, performance, highly availability, scalability, etc.
   Exposes business logic to client applications through various protocols, possibly including HTTP.
   Supports deployment of .war and .ear files Application server = web server + EJB container.


6. Diff b/w weblogic and websphere?

A. Both BEA Weblogic and IBM’s WebSphere provide J2EE based application servers which are competitors.
   WebSphere leverages more on connectivity issues with MQ and legacy systems with strong dominance in J2EE.