Tuesday, July 30, 2013

How to retrieve distinct pair of values from the given list of integers where the sum of each pair equals to given input value.

How to retrieve distinct pair of values from the given list of integers where the sum of each pair equals to given input value.


Example

Input : 9,2,5,4,6,-9
Output : 9,2 & 5,6



How to declare and initialize ArrayList in One line using Java


// Declare & Initilize Integer ArrayList in java
List<Integer> arr = new ArrayList<Integer>(Arrays.asList(9,2,5,4,6,-9))

// Using Arrays
int[] arr2 = new int[]{9,2,5,4,6,-9};


Wednesday, July 24, 2013

Tuesday, July 23, 2013

SQL Queries on Joins


// Get All deparments where corresponding employee first name is blank

SELECT dep.department_name,
  emp.first_name
FROM DEPARTMENTS dep
LEFT OUTER JOIN EMPLOYEES emp
ON dep.department_id  =emp.department_id where emp.first_name is null


// To get first column associated value in Oracle. Ir rownum =2, then returns first two values of first_name
select first_name from employees where rownum <=1


// Connect to database using sql command prompt

conn hr/hr;

// Below query substring the city column values from 1 to 4 characters and returns using MID() function
SELECT MID(City,1,4) AS ShortCity
FROM Customers;

// Returns length of each first_name column using LEN() function
SELECT LEN(first_name) FROM employees;

// Returns current system date using NOW() function
SELECT first_name,  Now() AS PerDate

FROM employees;

Different SQL JOINs

Before we continue with examples, we will list the types the different SQL JOINs you can use:
  • INNER JOIN: Returns all rows when there is at least one match in BOTH tables
  • LEFT JOIN: Return all rows from the left table, and the matched rows from the right table
  • RIGHT JOIN: Return all rows from the right table, and the matched rows from the left table
  • FULL JOIN: Return all rows when there is a match in ONE of the tables

How to Sort List programatically without using any in built functions in Java


   // Sort list of integers in descending order.
    private static List<Integer> sortList(List<Integer> pList){
        int temp;
        if(pList != null && pList.size() > 0){
            for(int i=0;i<pList.size();i++){
                for(int j=i+1;j<pList.size();j++){
                    if(pList.get(j) > pList.get(i)){
                        temp = pList.get(i);
                        pList.set(i,pList.get(j));
                        pList.set(j,temp);
                    }
                }
            }
        }
        return pList;
    }

Test

// Initialize and assign values
List<Integer> list1 =Arrays.asList(2,5,23,-1,-5,0,4);
// Invoke above sortList() method.


- How to merge two lists in a sorted order ?

// Initialize & assign two lists
List<Integer> list1 =Arrays.asList(2,5,23,-1,-5,0,4);
List<Integer> list2 =Arrays.asList(23,15,323,-51,-65,0,47);
 
// Add the second list to first list
list1.addAll(list2);
// Invoke above sortList() method by passing merged list i.e list1.

Monday, July 22, 2013

Left outer join example with three tables along with case





SELECT tab1.tb1_a,
       CASE WHEN tab3.tb3_a IS NOT NULL THEN tb3_b
            ELSE 'No city for him yet'
       END AS City,
tab2.*, tab3.*
FROM tab1
LEFT OUTER JOIN tab2 ON    tab1.tb1_a = tab2.tb2_a
LEFT OUTER JOIN tab3 ON    tab2.tb2_b = tab3.tb3_a
where tb2_b = (select max(tb2_b)
                 from tab2 t22
                where t22.tb2_a = tb1_a)
or    tb2_b is null
order by 1

Sunday, July 21, 2013

Unix Useful commands in Fusion Development Environment.

How to Identify the access level to specific file/directory in UNIX ?

To identify what are the access permissions to specific file or directory for a logged in user in UNIX environment, Follow below steps

- Login to unix box
- Issue command : ls -la
- You will notice all the list of files/directories as shown below screenshot,

- First character specifies whether it is file or directory, If it is directory, it will show as 'd' otherwise just emply
- Next three characters represents access permissions to logged in user, r - read, w - write, x - execute
- Next three characters represents access permissions to the group (i.e appigroup)
- Last three characters represents access permissions to anybody, empty means no access.



-  Issue below commands to give access to Group(g), Owner(o) & Others (a) as below

chmod rw+o TMP - Give read write permissions to owner for 'TMP' directory/file name
chmod rwx-a TMP - Remove read,write, execute permissions on 'TMP' directory/file for others
chmod 700 TMP - Give read,write, execute permissions on 'TMP' directory/file to owner , and no access to others & group

Useful UNIX commands

- To convert dos based file to unix
   i. Create temporary file first eg : temp.xml
   ii. temp.xml << dos2unix build.xml
  This will convert build.xml ( which is based on window/dos OS) to temp.xml
- hostname - Print the host name
- ssh uxunt540 - connect to uxunt540 unix box
- To give a sudo access to specific user
                sudo su - <userName>
-To Copy a existing file
               cp <sourceFileName> <targetFileName>
- To Grep for specific content in a current directory
              ps -ef | grep 'Fortune Minds'       - This will search for 'Fortune Minds' string in all the directories and files in a current present working directory
- To know the present working directory
            pwd
- To find out specific file content or forlder
           whereis <FortuneMinds>    - This will find out files/folders which contains 'Fortune Minds' and list out all the findings.
-  To Edit a specific file
              vi FortuneMinds.txt
              Press 'I'
              Modify the file
              Esc,Shift+:, wq! 
- To backup a directory
             mv <source_folder_Name>  <target_folder_Name>
- To run any shell script
             ./startWebLogic.sh & - startWebLogic shell script will run in background.







Friday, July 19, 2013

How to perform search against Collect of Custom Objects in Java ?



How to perform search against Collect of Custom Objects in Java ?

Usecase : Identify whether the given EmploeeDTO associated last name exists in the List<EmployeDTO> or not.

- Create EmployeeDTO class and override equals() method as shown below.
- Invoke List.Contains() operation by passing the Custom DTO object, this will invoke internally equals() method and returns true if there are any matching EmployeeDTO matches with the given Object last name.

How to Import existing application in Eclipse ?



File -> Import -> General -> Existing Projects into workspace -> Browse -> <Choose Application folder> --> Finish

Wednesday, July 17, 2013

How to create Deployment Profiles (JAR, EAR & WAR) using Jdeveloper


Packaging Applications using Jdeveloper

How to create Deployment Profiles (JAR, EAR & WAR) using Jdeveloper

JAR files are Java Archives, JAR files are bundled with all java classes that end in .jar, If you want to allow other applications to access your java classes, then create JAR file and add them into class path.

WAR files are Web Application Archives. WAR files are JAR files that end in .war and are used to package and deploy web components into web containers. They can contain HTML documents, servlets, JSPs, or even applet class files. WAR archives also contain an XML file called a deployment descriptor that describes the components. This file is normally called web.xml.


An EAR file is an Enterprise Archive and is used to package modules of a J2EE application. An EAR file is a JAR file that ends in .ear and can contain JAR and WAR files in addition to any other file required by the module. EAR archives also contain a file describing their contents—called an application descriptor, typically, application.xml.

Jdeveloper allows to create these files very simple manner.

Creating JAR file using Jdeveloper

- Right click on any Java project, Project Properties, You will see below window.

- Choose 'Deployment' on left hand side menu, Click on 'New' button, Choose 'JAR File' from 'Archive Type' list of values , Give appropriate name for the JAR file, Click on Ok button

- Here give the JAR file path where you want to create, Click on 'Ok' in following steps.

- After creating Deployment profile, then next step is to create the JAR file using the above created deployment profile
- Right click on the Java project (where JAR deployment profile created) , Choose Deploy , Then select the deployment profile created in above step, then choose 'Ok' in following steps, After successful compilation Jeveloper will create JAR file at the specified location.. You will see a message as shown in below screen shot.

WAR Deployment Profile

Right click on the web project, Follow all the above steps, Choose 'WAR File' while creating deployment profile and rest of the steps are same as mentioned above.

EAR Deployment Profile

Right click on the application, Follow all the above steps, Choose 'EAR File' while creating deployment profile, rest of the steps are same as mentioned above.


Tuesday, July 9, 2013

How to translate from one language to another language


If you have a requirement to support internationalization (Multi Lingual ) support, You need to translate english to rest of the languages..Below google translator is much useful tool to translate from english to any other language.


http://translate.google.com/?tl=fr#auto/fr/Logout

Friday, July 5, 2013

Multi threading example using Java

Multi Threading example in java

It is very common requirement to implement multi threading in large scale applications to improve the throughput of response,

Below screenshot demonstrates how to crate a thread, and process the given List of values


Below java class demonstrates, how to perform multi threading.

Monday, July 1, 2013

How to use VarArgs in Java


Variable Arguments(Varargs) :  varargs allows a method to accept zero or more arguments, No need to specify how many number of arguments will be passed to a method.

Syntax : access_specifier return_type method_name(data_type... variable_name){}

Below example demonstrate two methods with varargs.