Click here to Skip to main content
15,914,371 members
Home / Discussions / Java
   

Java

 
Questionjava database Pin
Member 82109845-Jul-12 5:17
Member 82109845-Jul-12 5:17 
AnswerRe: java database Pin
jschell5-Jul-12 6:20
jschell5-Jul-12 6:20 
QuestionProvider Pin
JimAce5-Jul-12 0:53
JimAce5-Jul-12 0:53 
AnswerRe: Provider Pin
TorstenH.5-Jul-12 1:19
TorstenH.5-Jul-12 1:19 
GeneralRe: Provider Pin
JimAce5-Jul-12 4:12
JimAce5-Jul-12 4:12 
QuestionElegant validation? Pin
Neo101014-Jul-12 4:33
Neo101014-Jul-12 4:33 
AnswerRe: Elegant validation? Pin
Richard MacCutchan4-Jul-12 5:06
mveRichard MacCutchan4-Jul-12 5:06 
AnswerRe: Elegant validation? Pin
TorstenH.4-Jul-12 22:46
TorstenH.4-Jul-12 22:46 
Is this entered from a GUI or is this object coming from some API?

For a GUI you can also use a GUI sided validation. You can e.g. use a KeyListener and validate the entered value right away.

For an API side validation I would suggest a Validation Layer which has to be passed before the data is used.

Your code - as Richard already stated - is a bit mixed up. Here is a valid suggestion:

C#
private void doCheck() {
   if (name != null && name != "") { // always check first for null
      for (String year : years) { // years only need to be checked when name was ok
         if (year != null && year != "" ) {
            try{
                int i = Integer.parseInt(year);
                // you can check if the number has a valid value here 
                // (e.g. between 1900 and 2012 (now-18 for adult check)
            }
            catch(Exception oException){
                /* not a valid number */   
            }
          }
      }
      for (String studyChoice : studyChoices) {
         if (studyChoice!=null && studyChoice != ""){
            /*Check for valid study course here - I suggest an Enum for the fixed range of valid values*/
         }
      }
   }
   else{ /*not even a valid name is given*/ }
}

regards Torsten
When I'm not working

Questionlocation-awareness simulation project Pin
simbarashe gumbo28-Jun-12 3:41
simbarashe gumbo28-Jun-12 3:41 
AnswerRe: location-awareness simulation project Pin
Peter_in_278028-Jun-12 3:48
professionalPeter_in_278028-Jun-12 3:48 
AnswerRe: location-awareness simulation project Pin
TorstenH.28-Jun-12 19:03
TorstenH.28-Jun-12 19:03 
AnswerRe: location-awareness simulation project Pin
CodingLover2-Jul-12 15:54
CodingLover2-Jul-12 15:54 
AnswerRe: location-awareness simulation project Pin
Paul Conrad2-Jul-12 17:50
professionalPaul Conrad2-Jul-12 17:50 
Questionto open an excel file and write Pin
prithaa27-Jun-12 21:50
prithaa27-Jun-12 21:50 
GeneralRe: to open an excel file and write Pin
Richard MacCutchan27-Jun-12 22:31
mveRichard MacCutchan27-Jun-12 22:31 
GeneralRe: to open an excel file and write Pin
prithaa27-Jun-12 23:05
prithaa27-Jun-12 23:05 
GeneralRe: to open an excel file and write Pin
Richard MacCutchan27-Jun-12 23:22
mveRichard MacCutchan27-Jun-12 23:22 
GeneralRe: to open an excel file and write Pin
prithaa27-Jun-12 23:33
prithaa27-Jun-12 23:33 
GeneralRe: to open an excel file and write Pin
Richard MacCutchan28-Jun-12 0:09
mveRichard MacCutchan28-Jun-12 0:09 
GeneralRe: to open an excel file and write Pin
prithaa28-Jun-12 20:21
prithaa28-Jun-12 20:21 
GeneralRe: to open an excel file and write Pin
Anil Kumar 2328-Jun-12 22:12
Anil Kumar 2328-Jun-12 22:12 
GeneralRe: to open an excel file and write Pin
Richard MacCutchan28-Jun-12 22:19
mveRichard MacCutchan28-Jun-12 22:19 
GeneralRe: to open an excel file and write Pin
prithaa29-Jun-12 0:04
prithaa29-Jun-12 0:04 
GeneralRe: to open an excel file and write Pin
Richard MacCutchan29-Jun-12 0:12
mveRichard MacCutchan29-Jun-12 0:12 
GeneralRe: to open an excel file and write Pin
prithaa29-Jun-12 3:01
prithaa29-Jun-12 3:01 

General General    News News    Suggestion Suggestion    Question Question    Bug Bug    Answer Answer    Joke Joke    Praise Praise    Rant Rant    Admin Admin   

Use Ctrl+Left/Right to switch messages, Ctrl+Up/Down to switch threads, Ctrl+Shift+Left/Right to switch pages.