Skip to main content

Most Common mistakes in Java Coding.

1. Copy & Paste

Its one of the most powerful tool and technique in the typical programmer. But at the same time its too dangerous that you ought to forgot the code according to you requirements. So always be cautious about what piece of code you are copying. Read at least two to three times to avoid the tricky for fishy things while your unit testing.

2. Exception Catch Block.

Always give priority to write some thing useful and meaning full statements in the exception catch block.It really worth when you troubling shooting the issues. Never leave this block with empty or sop's. And always throw the exception to the calling method.

3. String operations

Since String is immutable object, when you do any operation on string that results a new object. So after you do any modifications on String and do assign the string some object and use it.

4. Null pointers

Don't perform the operations on objects without checking the Object null condition. And while checking the null condition always provide 'null' key word as the first operand. e.g. if(null != object) . Especially while printing any calling any methods on an object.

5. Result Set next() operation.

Be in mindful that when ever you call resultset.next() operation cursor moves from one row to its next row.




Comments

Popular posts from this blog

Self Signed Certificates Vs Signed Certificates (CA Certificates)

Certificates Certificates basically two categories. Self Signed Certificates  - will create by self CA Certificates  - will be  provided by Third party vendor with robust algorithms Depends on the location of installing the certificate these are two types 1. Public Key Certificates (Client Side) 2. Private Key Certificates (Server Side) Self Signed Certificates   If any one is using self signed certificates in their applications they have to make sure both server side and client side certificates are in sync. Other wise we should be ready to face SSLHandShake Exceptions. These will be preferable mostly for lower environments not for production. CA certificates  If you install CA certificates on server side, client side certificates are installed automatically whenever they access the server. So in production for CA certificates there is no need to install the client side certificates. We can generate a Self Signed Certificate using Java Key tool JAVA_HOME/bi...

Spring Reactive Stack

Finding Second Highest element in an Array

package com.sbs.java8.praticse; public class SecondHightestClass { public static void main(String[] args) { final Integer[] intArray = { 10, 2, 36, 7, 29, 30, 100, 20, 90, 83, 87 }; final int n = intArray.length; int sortPointer = intArray.length; for (int m = n; m > (n - sortPointer); m--) { for (int i = 0; i < n - 1; i++) { int j = i + 1; if (intArray[i] > intArray[j]) { int temp = intArray[i]; intArray[i] = intArray[j]; intArray[j] = temp; } } sortPointer--; } System.out.println(intArray[n - 2]); } }