how to create a custom datatype in java? -
i want create custom datatype in java,for example datatype email , having following method isvalidate(string email),isemailexist(string email),getdomain(string email), id(string email),just integer class in java.
integer class , can initialise object of integer class follows:
integer = 100;
i created class email , want initialise follows email e = "sam";
how can perform functionality in email class.
import java.util.stringtokenizer; import java.util.regex.matcher; import java.util.regex.pattern;public class email { private string email; public email(string email) { this.email=email; }
email() { } public boolean isvalid(string email) {
string lasttoken = null; pattern p = pattern.compile(".+@.+\.[a-z]+"); // match given string pattern matcher m = p.matcher(email); // check whether match found boolean matchfound = m.matches(); stringtokenizer st = new stringtokenizer(email, "."); while (st.hasmoretokens()) { lasttoken = st.nexttoken(); }
if (matchfound && lasttoken.length() >= 2 && email.length() - 1 != lasttoken.length()) {
return true;
} else return false;
}
public string tostring() { return email; }
}
thanks
create email class. java 101; book or free tutorial of java language started.
Comments
Post a Comment