Monday, 28 September 2015

Save it

 Many developer thinks to include their classes inside rt.jar to solve classpath related problems, but that is a bad idea. You should never be messing with rt.jar, it contains class files which is trusted by JVM and loaded without stringent security check it does for other class files.

 Modulo/reminder(%)

 is used to calculate reminder.
 is used to calculate last digit.
 is used to calculate even/odd number.


 String binaryString = Integer.toBinaryString(number)
String octalString = Integer.toOctalString(number);
String hexString = Integer.toHexString(number);
binaryString = Integer.toString(number,2);
octalString = Integer.toString(number,8);
hexString = Integer.toString(number,16);

public static int binaryToDecimal(int number) {
        int decimal = 0;
        int binary = number;
        int power = 0;

        while (binary != 0) {
            int lastDigit = binary % 10;
            decimal += lastDigit * Math.pow(2, power);
            power++;
            binary = binary / 10;
        }
        return decimal;
    }


public static int reverse(int number){
        int reverse = 0;
        int remainder = 0;
        do{
            remainder = number%10;
            reverse = reverse*10 + remainder;
            number = number/10;
         
        }while(number > 0);
     
        return reverse;
    }

How Substring can cause memory leak in Java,
Why String is immutable in Java
Storing password in character array clearly mitigates security risk of stealing password.

Integer.parseInt() method will throw NumberFormatException if String provided is not a proper number.

StringBuilder - 1.5

No comments:

Post a Comment