Wednesday, 27 September 2017

How to implement custom ArrayList in java?

package Inter;

import java.util.Arrays;
import java.util.Iterator;

/**
 *
 * @author chinmaykumar.t
 */
public class CustomArrayList {

    private int size = 0;
    Object[] objArr = null;

    public CustomArrayList() {
        objArr = new Object[10];
    }

    public Object get(int index) {
        if (index < size) {
            return objArr[index];
        } else {
            throw new ArrayIndexOutOfBoundsException();
        }
    }

    public void add(Object obj) {
        if (objArr.length - size <= 5) {
            increaseListSize();
        }
        objArr[size++] = obj;
    }

    public Object remove(int index) {
        if (index < size) {
            Object object = objArr[index];
            objArr[index] = null;
            int temp = index;
            while (temp < size) {
                objArr[temp] = objArr[temp + 1];
                temp++;
            }
            size--;
            return object;
        } else {
            throw new ArrayIndexOutOfBoundsException();
        }

    }

    public void increaseListSize() {
        objArr = Arrays.copyOf(objArr, objArr.length * 2);
        System.out.println("\nNew length: " + objArr.length);

    }

    public int size() {
        return size;
    }
   
    public static void main(String[] args) {
        CustomArrayList arrayList=new  CustomArrayList();
        arrayList.add("chinmay");
        arrayList.add("kumar");
        arrayList.add("tripathy");
        System.out.println(""+arrayList.toString());
        System.out.println(""+arrayList.get(0));
        System.out.println(""+arrayList.remove(1));
        System.out.println(""+arrayList.size());
         for(int i=0;i<arrayList.size();i++){
            System.out.print(arrayList.get(i)+" ");
        }
    }
}

Monday, 4 September 2017

Use of data types Money and Smallmoney in RDBMS(Sql Server)

Money and Smallmoney: -

These are the data types to store the monetary or currency values in the data type. Money data type stores the 8 bytes and Smallmoney data type stores the 4 bytes. These data types are capable to store the ten-thousandth of the monetary unit. For example:- cents and dollars etc. 6) Int, bigint, smallint and tinyint:- These data types can also stores the exact values of the number. int data type is the primary integer data type in the SQL Server. We can use the bigint data type in place of the int and small int if the records are too much in the given table. But if the data is keep increasing in the table then we can change the data type of the monetary column into bigint from tinyint, smallint and int. The use of the different data type from the int family is used as per the requirements which are different all the time. For Metadata/ Base tables may be able to use the tinyint and smallint but for the transaction tables we can go for the int and bigint data types.

Wednesday, 26 July 2017

How to know the running monitor in Cron job ?


How to  know the running monitor in Cron job and edit the monitor path and how to save ?


=>Login and type below command:
crontab -e

=>For comment one monitor
Press Esc then type "i" means Insert mode.
Add # before the monitor
e.g
#*/5 * * * *  '/apps/472/monitor/notificationmonitor.sh' > /apps/472/monitor/notificationcron.txt

=>To  save the changes
press ESC  then type  :wq!   

*Here "wq!" means write and quit.

=> Simply to quit from current window without changes
press Esc and type :q!




How to do digital clock in java script ?

Sample code for displaying time in java script

function displayTime() {
            var ob = new Date();
            var year = ob.getFullYear();
            var month = ob.getMonth() + 1;
            var date = ob.getDate();
            var hours = ob.getHours();
            var minutes = ob.getMinutes();
            var seconds = ob.getSeconds();
            var indicator = "AM";
            if (hours >= 12) {
                indicator = "PM";
            }
            if (hours > 12) {
                hours = hours - 12;
            }
            if (month <= 9) {
                month = "0" + month;
            }
            if (date <= 9) {
                date = "0" + date;
            }
            if (hours <= 9) {
                hours = "0" + hours;
            }
            if (minutes <= 9) {
                minutes = "0" + minutes;
            }
            if (seconds <= 9) {
                seconds = "0" + seconds;
            }
            var completeDate = date + "-" + month + "-" + year + " " + hours + ":" + minutes + ":" + seconds + " " + indicator;
            document.getElementById("divDisplayTime").innerHTML = completeDate;
        }// End of displayTime() function
        setInterval("displayTime()", 1000);


**Note:
Declare one div by giving the id "divDisplayTime".

Monday, 10 July 2017

How to extend java memory ?

Small info on Memory increase in java.

By using the command Xms and Xmx ,we can increase the java memory .

The flag Xmx specifies the maximum memory allocation pool for a Java Virtual Machine (JVM), while Xms specifies the initial memory allocation pool.

This means that your JVM will be started with Xms amount of memory and will be able to use a maximum of Xmx amount of memory. For example, starting a JVM like below will start it with 256MB of memory, and will allow the process to use up to 2048MB of memory:

java -Xmx2048m -Xms256m
The memory flag can also be specified in multiple sizes, such as kilobytes, megabytes, and so on.

-Xmx1024k
-Xmx512m
-Xmx8g
The Xms flag has no default value, and Xmx typically has a default value of 256MB. A common use for these flags is when you encounter a java.lang.OutOfMemoryError.


To aovoid "java.lang.OutOfMemoryError: PermGen space” error,have to use "-XX:MaxPermSize=256m"  .

*Here k-KB,m-MB,g-GB

*If we are using any IDE(Netbean or Eclipse) then have to add in VM optios for core application.

*For Web application have to add stanalone.conf(Wildfly server bin folder) and catlina.sh or catlina.bat (tomcat bin folder) like below :


JAVA_OPTS="-Xms64m -Xmx512m -XX:MaxPermSize=256m                   

Friday, 10 March 2017

How to change MySql Password

MySQL 5.7.6 and later:
ALTER USER 'root'@'localhost' IDENTIFIED BY 'MyNewPass';
MySQL 5.7.5 and earlier:
SET PASSWORD FOR 'root'@'localhost' = PASSWORD('MyNewPass');