Showing posts with label Java Coding Cares. Show all posts
Showing posts with label Java Coding Cares. Show all posts

Monday, October 27, 2014

Java Coding Care4 : Avoid Null Pointer Exception

Topic : Avoid Null Pointer Exception

Advantage
Code Execution will be liberal and better. Functionality break chances will be reduced.

Example

1)
if ("check me".equals(param)) // Do like this
{
// some code
}

2)
String str = (param == null) ? "NA" : param;

3)

Use String.valueOf() Rather than toString()

4)
Object object =null;
String.valueOf(object); /// is OK
String.valueOf(null); // throws Exception

Use collections default to get the empty objects of respected data struture
List<String> list = Collections.EMPTY_LIST;
Set<String> set = Collections.EMPTY_SET;
Map<String,String> map = Collections.EMPTY_MAP;

knownObject.equals(unknownObject)

Monday, October 20, 2014

Java Coding Care3: Use DBSPY for Database related issue tracking

Topic : DB SPY

log4jdbc SPY should be use for DB related issue Tracking/Logs

Advantage
It is useful to SPY / DEBUG database related issue tracking. It generates all kind of user
required logs


Libs Required
log4j-1.2.16.jar
log4jdbc4-1.2.jar
log4j-over-slf4j-1.7.5.jar
slf4j-api.jar"
slf4j-jdk14.jar"
slf4j-log4j12-1.7.5.jar"
slf4j-simple-1.7.5.jar"

ojdbc6-11.0.2.0.jar"

Example
import java.sql.Connection;
import java.sql.DriverManager;
import java.sql.PreparedStatement;

public class SpyEngine {

public static void main(String[] rk) {

try {

  Class.forName("net.sf.log4jdbc.DriverSpy");
Connection conn = DriverManager.getConnection( "jdbc:log4jdbc:oracle:thin:@192.168.8.87:1521:rajdb", "rajusername", "rajpassword");

PreparedStatement prStmt = conn.prepareStatement("select * from tbdata");
prStmt.execute();
prStmt.close();

  conn.close();
 
} catch (Exception e) {
System.out.println("Error: " + e);

}
}

Sunday, October 19, 2014

Java Coding Care2 : Prepare TLD in jsp

Topic : TLD (Tag Library Descriptor)

Prepare TLD in jsp for some common features and tags

Example
Need /Use the custom prepared TLD tag. For some common code we can
prepare custom TLD tags (i.e Logo, specifc conditional statements)


Advantage
No dependency on others tags

Java Coding Care1: Use Declaration in JSP

Topic : Declaration in JSP
Always try to use Declaration in JSP page

Example
Need to Use declarations in jsp instead of SCRIPLET for common global
variables
.i.e <%! String path="......"; %>


Advantage

Each time a service method is being called then Variable declaration will be discarded if we will declaration. It declares variable in global scope of a generated servlet for that particular jsp.

Scrum and Scrum master

Scrum  Scrum is a framework which helps a team to work together.  It is like a rugby team (the scrum name comes from rugby game). Scrum enco...