Posts

Showing posts with the label Code-Review

Java - Best Practice - FAQ

1] Here  myListConsistOfSQL is the List<String> which consist of SQL scripts for execution PreparedStatement ps=null; try{          conn=getMyDBConnection(); for(String sql: myListConsistOfSQL) {          ps = conn.prepareStatement(sql);          ps.addBatch();          ps.executeBatch();     } } Catch(Exception e) {     throw new e; } finally {     if(ps!=null) {          ps.close();      }    if(conn!=null) {         conn.close();     } } 2] Map object to print the key and values using for each loop myDataMap.forEach((key, value) -> log.info("Details:: " + key + ":" + value)); myDataList.forEach(msg -> log.info(msg)); 3] Logger message utility class to hold details in list import java.util.ArrayList; import java.util.List; public class MessagesUtil { ...

Best Practices of Code Review

Project and filename should be self explanatory like PaymentService Remove unwanted import/using packages statement (use specific lib, don't use * until unless it require) Sort all the import/using statement properly Don't ignore warning in your project (Address it all and remove), force zero warning before production check in Code consistency, reusability and readability Do extra care for NULL all the times and put check to handle NULLpointException handler Remove unwanted dead/un-used code like variable not being used in application Naming convention Write proper exception handling (try, catch & finally) Properly use access specifier based on architecture (public, protected & private) Self documenting code/comments in your code You can use lot of readymade tools available like FindBug, SonarCube etc.