Prevent Negative numbers for Age without using client side validation.
Posted
by
Deepak
on Stack Overflow
See other posts from Stack Overflow
or by Deepak
Published on 2011-02-04T15:14:46Z
Indexed on
2011/02/04
15:25 UTC
Read the original article
Hit count: 204
java
Hi People, I have an issue in Core java. Consider the Employee class having an attribute called age.
class Employee{
private int age;
public void setAge(int age);
}
My question is how do i restrict/prevent setAge(int age) method such that it accepts only positive numbers and it should not allow negative numbers,
Note: This has to be done without using client side validation.how do i achieve it using Java/server side Validation only.The validation for age attribute should be handled such that no exception is thrown
© Stack Overflow or respective owner