Wednesday, June 27, 2012

Why Runtime Exceptions are Not Checked?

The runtime exception classes (RuntimeException and its subclasses) are
exempted from compile-time checking because, in the judgment of the designers
of the Java programming language, having to declare such exceptions would not
aid significantly in establishing the correctness of programs. Many of the operations and constructs of the Java programming language can result in runtime
exceptions. The information available to a compiler, and the level of analysis the
compiler performs, are usually not sufficient to establish that such run-time exceptions
cannot occur, even though this may be obvious to the programmer. Requiring
such exception classes to be declared would simply be an irritation to
programmers.
For example, certain code might implement a circular data structure that, by
construction, can never involve null references; the programmer can then be
certain that a NullPointerException cannot occur, but it would be difficult for a
compiler to prove it.

Tuesday, June 12, 2012

Alphanumeric validation check using Regex


String value = "Pankaj Singh 1952";
Pattern pattern = Pattern.compile("[a-zA-Z][a-zA-Z0-9 ]*");
Matcher matcher = pattern.matcher(value);
boolean flag = matcher.matches();

if (flag) {
System.out.println("correct value");
} else {
System.out.println("incorrect value");
}

Email Check Using Java Regex


String email = "pankaj.singh@yahoo.co.in";

Pattern p = Pattern
.compile("[a-z][a-z_.0-9]*@[a-z0-9]*[.]{0,1}[a-z0-9]{1,3}.[a-z]{2,3}$");

Matcher m = p.matcher(email);

boolean b = m.matches();
if (b == true) {
System.out.println("Valid Email ID");
} else {
System.out.println("InValid Email ID");
}

Spring Boot Config Server and Config Client.

 In Spring cloud config we can externalise our configuration files to some repository like GIT HUT, Amazon S3 etc. Benefit of externalising ...