Page Count

Wednesday, December 16, 2015

Project or Build Version Numbers

In Software world, every project/product release has one version number associated with it to identify on which version of code base it has.

Usually every project/product release has its version as follows.

(Major).(Minor).(Maintenance/Enhancements).(Build Number)

Major - If the release has Major changes in Project/Product then we need to increment this number by 1
Minor -   If the release has Minor changes in Project/Product then we need to increment this number by 1
Maintenance - If the release has Bug fixes or Small Enhancements then we need to increase this number by 1.

Build Number :  Every time when we deliver build (latest code) to the QA to test, then we need to increase by 1.

Partial Builds: If only some of the modules in the project modified and if those modules only delivered to QA means, it is called as partial builds. And this will be noted as build number along with alphabets.


E.G of Build Numbers.

Current Version of Project is 4.0.0.0 (4 Major Releases)
If Minor Project got released in next release. then it would be 4.1.0.0

After 4.1, some bug fixes got released, then it would be 4.1.1

For doing above we have delivered 4 builds to QA before Production  release then
version would be

4.1.1.1
4.1.1.2
4.1.1.3
4.1.1.4

Final release would be 4.1.1

E.G of Partial Build Numbers:

4.1.1.1
4.1.1.1a
4.1.1.1b
4.1.1.1c

4.1.1.2
4.1.1.2a

4.1.1.3
4.1.1.3a
4.1.1.3b

4.1.1.4






 

Linux Useful Commands with examples

To know the IP address
-----------
hostname -i (ip addres)
hostname -s (short name)
hostname -d (domain name)
hostname -v (host name with domain name)


To know the port number and running processes
netstat -ano | findstr 80

If the file is huge in size and to see the file content we can use
less <file name>
e.g. less service.log

Searching  matching pattern in file
grep '<matching text>' <file name>
e.g. grep 'Exception' service.log

To grep the text from .gz files
gzgrep '<matching text>' <gz file name>
e.g. gzgrep 'Exception' service.log.gz

ps -eaf | grep java
ps aus | grep java

tail -f <file Name> (auto updated last few lines)
tail -100 logfile.log  (last 100 lines)

ls -a  (hidden files)
ls -lrt (Sort the files by time stamp)

kill -9 <Process ID>   (get Process ID using ps -eaf | grep <process name>)
e.g. kill -9 30102

ClassNotFoundException vs NoClassDefFoundError

Both ClassNotFoundException and NoClassDefFoundError errors will be occurred  when the required Class not present in the Class path.
   
ClassNotFoundException
   
ClassNotFoundException is an Exception got arized when trying load class using
forName() method in class Class.
findSystemClass method in class ClassLoader .
loadClass method in class ClassLoader.

e.g. Class.forName("oracle.jdbc.driver.OracleDriver")
if the OracleDriver class file is not present in the Class path, then we will end up with this ClassNotFounException

NoClassDefFoundError

NoClassDefFoundError is an Error thrown at Runtime, when the Class is present during the compile time and not present during Runtime of the Code, then we will end up with this NoClassDefFoundError.

1. When required Class is not available at Runtime available only in compile time.
2.Since NoClassDefFoundError error is an Subclass of LinkageError, it will occur when one of the     Dependent of the jar not present in class path.
3. When the Static initialization of Class failed then it triggers java.lang.ExceptionInInitializerError
 which also leads to this Error.

e.g.  Exception in thread "main" java.lang.NoClassDefFoundError

Tuesday, December 15, 2015

Content Extracting From 'CLOB' type Columns in SQL Querries

Extracting XML node value from CLOB  column in data base.

Syntax

ExtractValue(xml_fragment, xpath_expression)

Query Syntax

Select Extractvalue(XMLtype('<column name>'),'<XML node path>')
From <table list>
Where <conditions>

Example

Select Extractvalue(Xmltype(emp_xml), '/employees/empployee/emp_number')
From employee 
where  Status='A';

Updating a XML node value from CLOB  column in data base.

Syntax


UpdateXML(xml_target, xpath_expr, new_xml)

Query Syntax

Update table_name Set column_name=Updatexml(Xmltype('<column name>'),'<XML node path>','<Replacing XMLvalue'>).getclobval
From <table list>
Where <conditions>;

Example

Initial value /employees/empployee/emp_name/text() = Bhargava

Update employe Set emp_name = Updatexml(Xmltype(emp_xml), '/employees/empployee/emp_name/text()','Bhargava Surimenu')
where  emp_no=1207;

Comparator Vs Comarable

Comparable Interface

Comparable is an interface in java, which has only comparTo (Object Obj) method in it.
This is used to sort the user defined objects on specific member field.


When Comparable is preferred.

1. Having provision of modifying the User defined object to implement the Comparable interface. (Third party jar class objects doesn't have provision to modify).
2. Have a requirement to sort the User defined object by one Member field in their natural sorting order.
3. Comparable provides only one Sorting for an Object.

Our String and Wrapper Classes like Integer, Double, Long, BigDecimal etc. are override this compareTo method by implementing the Comparable Interface.


For example,
To sort the Bank Accounts  based on the amount it contains.

1. Create Account pojo with all the member fields including amount.
2. Implement the Account pojo with Comparable interface.
3. Override the compareTo(Object obj) method from Comparable interface. (Refer following code snippet)

Account POJO

package com.sbs.sort;

import java.math.BigDecimal;

public class Account implements Comparable<Account>{

    private BigDecimal ammount;
    private Long accountNumber;
    private String accountHolderName;
   
    public Account(BigDecimal ammount, Long accountNumber,
            String accountHolderName) {
        super();
        this.ammount = ammount;
        this.accountNumber = accountNumber;
        this.accountHolderName = accountHolderName;
    }

    public BigDecimal getAmmount() {
        return ammount;
    }

    public void setAmmount(BigDecimal ammount) {
        this.ammount = ammount;
    }

    public Long getAccountNumber() {
        return accountNumber;
    }

    public void setAccountNumber(Long accountNumber) {
        this.accountNumber = accountNumber;
    }

    public String getAccountHolderName() {
        return accountHolderName;
    }

    public void setAccountHolderName(String accountHolderName) {
        this.accountHolderName = accountHolderName;
    }

    @Override
    public int compareTo(Account o) {
        return this.ammount.compareTo(o.getAmmount());
    }
}

ComparableSortTest 

package com.sbs.sort;

import java.math.BigDecimal;
import java.util.ArrayList;
import java.util.Collections;
import java.util.List;

public class ComparableSortTest {

    public ComparableSortTest() {
    }
    public static List<Account> accountsList = new ArrayList<Account>();
   
    static
    {
        accountsList.add(new Account(new BigDecimal("200000"),10010l,"Bhargava Surimenu"));
        accountsList.add(new Account(new BigDecimal("20000"),100102l,"Satya Surimenu"));
        accountsList.add(new Account(new BigDecimal("100000"),100104l,"Hemachandra Surimenu"));
        accountsList.add(new Account(new BigDecimal("600000"),100106l,"Neha Surimenu"));
        accountsList.add(new Account(new BigDecimal("30000"),100108l,"Veeru Surimenu"));
        accountsList.add(new Account(new BigDecimal("700000"),100109l,"Venky Surimenu"));
    }
   
    public static void main(String[] args) {
       
        System.out.println("----- Accounts List Before Sort ------");
        System.out.println("Account   "+"Ammount");
        for(Account account:accountsList)
            System.out.println(account.getAccountNumber()+"   "+
                    account.getAmmount());
       
        //Sort
        Collections.sort(accountsList);
       
        System.out.println("----- Accounts List After Sorting ------");
       
        System.out.println("Account   "+"Ammount");
            for(Account sAccount:accountsList)
                System.out.println(sAccount.getAccountNumber()+"   "+
                        sAccount.getAmmount());
    }
}



Comparator Interface

Comparator is an interface in java, which has only compare(Object Obj) method in it.
This is used to sort the user defined objects on specific member field.


When Comparator is preferred.

1. Having no provision of modifying the User defined object
(Third party jar class objects doesn't have provision to modify).
2. Have a requirement to sort the User defined objects by various member fields in their natural sorting order.
3. Comparator interface provides multiple comparators (Sortings)for an Object.


For example,
To sort the Employee based on the employee number it contains.

1. Create Employee pojo with all the member fields including amount.
2. Create a Employe Comparator and Implement the with Comparator interface.
3. Override the compare(Object obj) method from Comparator interface. (Refer following code snippet).
4. Pass the employee Comparator as argument to the Sort method.

Employee 

package com.sbs.sort;

import java.math.BigDecimal;


public class Employee {

    public Employee() {
       
    }

   
    public Employee(String name,String number, BigDecimal salary) {
        super();
        this.name = name;
        this.number = number;
        this.salary = salary;
    }


    private String name;
    private String number;
    private BigDecimal salary;
   
   
    public String getName() {
        return name;
    }
    public void setName(String name) {
        this.name = name;
    }
   
    public String getNumber() {
        return number;
    }
    public void setNumber(String number) {
        this.number = number;
    }
    public BigDecimal getSalary() {
        return salary;
    }
    public void setSalary(BigDecimal salary) {
        this.salary = salary;
    }
   
   
}

EmpComparator 

package com.sbs.sort;

import java.util.Comparator;

public class EmpComparator implements Comparator<Employee>{

     public EmpComparator() {
       
    }

    @Override
    public int compare(Employee emp1, Employee emp2) {
        return (emp1).getNumber().compareTo(emp2.getNumber());
    }
}


ComparatorSortTest
 
package com.sbs.sort;

import java.math.BigDecimal;
import java.util.ArrayList;
import java.util.Collections;
import java.util.List;

public class ComparatorSortTest {

    public ComparatorSortTest() {
       
    }
   
    public static List<Employee> employeeList = new ArrayList<Employee>();
    static
    {   
       
        employeeList.add(new Employee("Bhargava Surimenu","SBS101",new BigDecimal("1000")));
        employeeList.add(new Employee("Satya Surimenu","SBS108",new BigDecimal("2000")));
        employeeList.add(new Employee("Hemachandra Surimenu","SBS106",new BigDecimal("6000")));
        employeeList.add(new Employee("Satya Surimenu","SBS105",new BigDecimal("7000")));
        employeeList.add(new Employee("Neha Surimenu","SBS107",new BigDecimal("8000")));
        employeeList.add(new Employee("Veeru Surimenu","SBS102",new BigDecimal("3000")));
        employeeList.add(new Employee("Venky Surimenu","SBS104",new BigDecimal("1000")));
       
    }
   
    public static void main(String[] args) {
       
        System.out.println("----- Employees List Before Sort ------");
        System.out.println("Number   "+"Name");
        for(Employee emp:employeeList)
            System.out.println(emp.getNumber()+"   "+
                    emp.getName());
       
        //Passing EmpComparator as argument
        Collections.sort(employeeList,new EmpComparator());
       
        System.out.println("----- Employees List After Sorting ------");
       
        System.out.println("Number   "+"Name");
        for(Employee emp:employeeList)
            System.out.println(emp.getNumber()+"   "+
                    emp.getName());
    }
}

Thursday, December 3, 2015

"immutability" Nature of an Object

Immutability.

A Java object is considered to be immutable when its state (properties and contents) cannot change after it is created.

Use of immutable objects is widely accepted as a sound strategy for creating simple, reliable code. Immutable objects are particularly useful in concurrent applications. Since they cannot change state, they cannot be corrupted by thread interference or observed in an inconsistent state. java.lang.String and java.lang.Integer classes are the Examples of immutable

Immutable objects are simple to use test and construct.
Immutable objects are thread-safe by default.
Immutable objects are good Map keys and Set elements (Since state of these objects must not change while stored in a collection). This is the reason most of the times we prefer String objects as Key in many Map Collection objects.
Immutable objects do not require an implementation of clone.
Immutable objects allow hashCode to use lazy initialization, and to cache its return value.


To create a object immutable

Need to make the class final and all its member final so that once objects gets crated no one can modify its state.
Or
By making member as non final but private and not modifying them except in constructor. Also its NOT necessary to have all the properties final since you can achieve same functionality by making member as non final but private and not modifying them except in constructor.