Friday, June 19, 2015

How to improve your career as a developer ??

Three broad areas that you could focus on to improve your career as a
developer. Code is the most important, because this is the basic skill for a developer. But the other two, which we named Community and Think Differently, can’t be left behind. They are the things that will help you break
through the boundaries of your career. Spending some weekly practice time in those three areas will help you become a better developer. It will make
you a more complete professional, and enable you to go after new opportunities.
All this helps you boost your career and find new paths. And the suggestions we present here are not hard things to do, nor time consuming.You can squeeze them into your busy day.Code: Open Source Software We have already seen that to be good at coding, you must practice a lot. But even with practice, how do you know if you’re writing good code or bad code? We still have not
reached the point of having a practical and noncontroversial way of measuring code quality. Code quality is still most of the time a qualitative,
rather than quantitative, subject. You can’t say for sure if your code is good, but you can always recognize better or worse code. To make sure
you’re on the right path to becoming a better developer, your best bet is to assess your progress against other developers’ code. In the software world, the way to watch others perform is by looking at their software,
and the source code they wrote. That allows us to study it, experiment with it, and even improve it. But for that,we need access to the source code of great developers. This is the beauty of open source: It’s freely available
for you to study and compare with your own code. You can find a huge variety of different projects on GitHub and Bitbucket, ranging from small to enterprise-level projects.  You can learn new techniques, and you can explore different points of view. You can be awed by great code and learn what not to do from developers who are not accomplished. Want to explore different ways of testing code? Dig into open source projects and see how other developers do it. Don’t know the proper way of doing logging
in your systems? Get an open source project you use that provides great logging information and learn to do it the same way. Contributing to open source enables you to practice some skills that maybe you don’t (or can’t) use in your daily work. Many of us are limited at work to creating traditional
enterprise systems with create, read, update, and delete (CRUD) features. But in our spare time, we can choose any open source project that sparks our interest to learn or contribute to. Sometimes even at work, we can take a
relevant open source tool or library and fix a bug or implement a new feature. It certainly is exciting, and it helps us to think outside the box.

Monday, May 18, 2015

Convert ArrayList to JsonArray

Java code to convert a data list into json array
 
import java.util.ArrayList;
import java.util.List;
import com.google.gson.Gson;
import com.google.gson.GsonBuilder;
import com.google.gson.JsonArray;

class Data{
    int id;
    String name;
   
    public Data(int id, String name){
        this.id = id;
        this.name = name;
    }
   
    public int getId() {
        return id;
    }
    public void setId(int id) {
        this.id = id;
    }
    public String getName() {
        return name;
    }
    public void setName(String name) {
        this.name = name;
    }
}

public class LISTTEST {
    public static void main(String[] args) {
   
    List dataList = new ArrayList<Data>();
    dataList.add(new Data(1,"One"));
    dataList.add(new Data(2,"Two"));
   
    Gson gson = new GsonBuilder().create();
    JsonArray myCustomArray = gson.toJsonTree(dataList).getAsJsonArray();
   
    System.out.println(myCustomArray);
   
    }
}


OUTPUT

[{"id":1,"name":"One"},{"id":2,"name":"Two"}]

Tuesday, April 28, 2015

COLORWALLS APP

COLORWALLS a beautiful colorful app.
Make your Andorid's Wallpapers Colorful.
Get it Free here : https://play.google.com/store/apps/details?id=com.raj.colorwalls
you will like it. Try it.









STRUTS2 VISITOR VALIDATOR COMPLETE EXAMLE




Login.jsp

<%@ page language="java" contentType="text/html; charset=ISO-8859-1" pageEncoding="ISO-8859-1"%>
<%@ taglib uri="/struts-tags" prefix="s"%>
<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=ISO-8859-1">
<title>Login</title>
<style>
    .errorMessage{
        color:red;
        font-size: 11px;
        text-align:right;
    }
</style>
</head>
<body>
    <center>
        <s:form action="loginAction" method="post" validate="true" >
            <s:textfield     name="user[0].username" label="Username"    />
            <s:textfield     name="user[0].password" label="Password"    />
            <s:textfield      name="mobileNumber" label="Mobile Number"    />          
            <s:submit/>
        </s:form>
    </center>
</body>
</html>

LoginAction.java

import java.util.List;

import mod.User;

import com.opensymphony.xwork2.ActionSupport;
import com.opensymphony.xwork2.validator.annotations.VisitorFieldValidator;

public class LoginAction extends ActionSupport{
   
    private String mobileNumber;
    private List<User> user;
   
    public String getMobileNumber() {
        return mobileNumber;
    }
   
    public void setMobileNumber(String mobileNumber) {
        this.mobileNumber = mobileNumber;
    }
   
    @VisitorFieldValidator(message = "Userssss")
    public List<User> getUser() {
        return user;
    }

    public void setUser(List<User> user) {
        this.user = user;
    }
}
 

LoginAction-validation.xml
 
<!DOCTYPE validators PUBLIC "-//Apache Struts//XWork Validator 1.0.2//EN" "http://struts.apache.org/dtds/xwork-validator-1.0.2.dtd">
   
<validators>
   
    <field name="mobileNumber"  >
        <field-validator type="requiredstring" short-circuit="true" >
            <message>Empty Mobile Number !</message>            
        </field-validator>
    </field>
   
</validators> 

User.java

package mod;

public class User {
   
    private String username;
    private String password;
    /**
     * @return the username
     */
    public String getUsername() {
        return username;
    }
    /**
     * @param username the username to set
     */
    public void setUsername(String username) {
        this.username = username;
    }
    /**
     * @return the password
     */
    public String getPassword() {
        return password;
    }
    /**
     * @param password the password to set
     */
   
    public void setPassword(String password) {
        this.password = password;
    }
}
 
welcome.jsp

<%@ page language="java" contentType="text/html; charset=ISO-8859-1"
    pageEncoding="ISO-8859-1"%>
<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=ISO-8859-1">
<title>Insert title here</title>
</head>
<body>
    WELCOME TO CUSTOM VALIDATION DEMO PROJECT
</body>
</html>

Thanks
Keep Visiting. Be happy :)





Thursday, March 19, 2015

STRUTS2 CUSTOM VALIDATORS DEMO CODE EXAMPLE

GreaterThanZeroValidator.java

import com.opensymphony.xwork2.validator.ValidationException;
import com.opensymphony.xwork2.validator.validators.FieldValidatorSupport;

public class GreaterThanZeroValidator extends FieldValidatorSupport {

    @Override
    public void validate(Object object) throws ValidationException {

String fieldName = getFieldName();
Integer fieldValue = (Integer) getFieldValue(fieldName, object);

if (fieldValue != null && fieldValue <=0 ) {
   addFieldError(fieldName, object);
}  
    }
    
}

Validators.xml (also put all default validator in this file)

<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE validators PUBLIC
        "-//Apache Struts//XWork Validator Definition 1.0//EN"
        "http://struts.apache.org/dtds/xwork-validator-definition-1.0.dtd">

<validators>
    <validator name="required" class="com.opensymphony.xwork2.validator.validators.RequiredFieldValidator"/>
    <validator name="requiredstring" class="com.opensymphony.xwork2.validator.validators.RequiredStringValidator"/>
    <validator name="int" class="com.opensymphony.xwork2.validator.validators.IntRangeFieldValidator"/>
    <validator name="long" class="com.opensymphony.xwork2.validator.validators.LongRangeFieldValidator"/>
    <validator name="short" class="com.opensymphony.xwork2.validator.validators.ShortRangeFieldValidator"/>
    <validator name="double" class="com.opensymphony.xwork2.validator.validators.DoubleRangeFieldValidator"/>
    <validator name="date" class="com.opensymphony.xwork2.validator.validators.DateRangeFieldValidator"/>
    <validator name="expression" class="com.opensymphony.xwork2.validator.validators.ExpressionValidator"/>
    <validator name="fieldexpression" class="com.opensymphony.xwork2.validator.validators.FieldExpressionValidator"/>
    <validator name="email" class="com.opensymphony.xwork2.validator.validators.EmailValidator"/>
    <validator name="url" class="com.opensymphony.xwork2.validator.validators.URLValidator"/>
    <validator name="visitor" class="com.opensymphony.xwork2.validator.validators.VisitorFieldValidator"/>
    <validator name="conversion" class="com.opensymphony.xwork2.validator.validators.ConversionErrorFieldValidator"/>
    <validator name="stringlength" class="com.opensymphony.xwork2.validator.validators.StringLengthFieldValidator"/>
    <validator name="regex" class="com.opensymphony.xwork2.validator.validators.RegexFieldValidator"/>
    <validator name="conditionalvisitor" class="com.opensymphony.xwork2.validator.validators.ConditionalVisitorFieldValidator"/>

    <validator name="greaterThanZero" class="com.validator.GreaterThanZeroValidator" />

</validators>

ABCAction-validation.xml
<!DOCTYPE validators PUBLIC "-//Apache Struts//XWork Validator 1.0.2//EN" "http://struts.apache.org/dtds/xwork-validator-1.0.2.dtd">

<validators>

<field name="pkgData.validityPeriod" >
<field-validator type="greaterThanZero" short-circuit="true">
<message>${getText("error.greaterthanzero", {getText("pkg.validityperiod")})}</message>         </field-validator>
<field>

ABCAction.java

public class ABCAction extends ActionSupport implements   ServletRequestAware{

private static final long serialVersionUID = 1L;
private static final String MODULE  = PkgCTRL.class.getSimpleName();
private static final String PACKAGE = " Package ";

private PkgData pkgData = new PkgData();
.......
.......
.......
.......

}

LIBS (keep the required libs only)

validators.xml file location (means it should come in classpath)

helpful link : 

http://struts.apache.org/docs/validation.html#Validation-RegisteringValidators
(read above link content fully with patience )

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...