Users\Yucca\Documents\NetBeansProjects\SCJD\src\suncertify\db>j
Contractor.java
tractor.java:28: as of release 1.4, 'assert' is a keyword, and
s an identifier
e -source 1.3 or lower to use 'assert' as an identifier)
assert MAGIC_COOKIE == new DBExtract().getMagic() :"agic cooki

In addition I am a bit confused on if the following is a good use of assertions

I also wish to kow if I have the right idea behing the DBExtract class in that it will be ok in the SCJD exam and therfore in RL too. My theory was that such a class has no programming logic and therefore It constructed when assertions are enabled.

SCJP 6.0, SCJD (400/400), SCBCD for JEE 5, SCWCD 1.4 I do videos for development at
http://www.youtube.com/user/thejartender?feature=mhee
I am probably the only developer ever to have had an orange sized brain tumor in my brain while learning development!!

what's the purpose using those assertions because that's not clear to me? you make an assert for checking the magic cookie, what are you trying to achieve with that check?

if i run your code and select a data-file with another magic cookie, what do you expect to happen? if you want user to be notified that he selected a wrong data-file and give him another try to select data file. when you use asserts, an assertionerror is thrown (which you are not intended to catch). if i run your program without enabling them, i don't know what will happen on the code you posted

in my code: i open file, check the magic cookie and if it's not the same i throw an DatabaseException (a runtime exception) with message "data file invalid" which i then can catch and give the user the opportunity to choose some other file

Roel De Nijs wrote:what's the purpose using those assertions because that's not clear to me? you make an assert for checking the magic cookie, what are you trying to achieve with that check?

if i run your code and select a data-file with another magic cookie, what do you expect to happen? if you want user to be notified that he selected a wrong data-file and give him another try to select data file. when you use asserts, an assertionerror is thrown (which you are not intended to catch). if i run your program without enabling them, i don't know what will happen on the code you posted

in my code: i open file, check the magic cookie and if it's not the same i throw an DatabaseException (a runtime exception) with message "data file invalid" which i then can catch and give the user the opportunity to choose some other file

I do an assertion test because I hardcoded it and I wish to show how i came up with the number for the magic cookie. Also the main reason is when I read the value that gives the record length from the database I never hardcode it. Instead I declare a constant that gets set to the sum of all the lengths and I thaught it may be a good idea to show through assertions that the record length returned by reading the bytes == 182 == (total sum of fiels lengths)

Well I don't think that using an assertion would be a great idea to validate the magic cookie value.

But what I can see is that you are not using asserts inside a block, maybe you can change your code a little bit and add braces to surround the assertion code ("{ assert bla bla bla.}") in that way I believe it will compile.

I dont validate my magic cookie and the crux of this question entails the other value read from the database that gives me the length of the records. The value which == 182 so I can hardcode it and then use it to read records from the datatbase. Further I can instead choose to hard code it by adding all the lengths of the fields together which also equals 182. I have chosen not to hardcode it to 182 and instead initialise it with them sum of the field lengths and in return was going to include in my line comment that this value can also be read from the database.

I was going to show this through and assertion something like this...

I guess I am being to eager and trying to doo too much but its due to me not knowing if the exam assesor is gonna want to see how I got the record_length number from the database.

you have a file-description of the file you must be able to read. so if you add in comment "read from file according to file description" i think that 'll do. in your choices.txt you can add an item why you choose for hard-coded values and not have a more dynamic approach. anyway i would avoid the use of assertions for doing that kind of things and only use them for e.g. validating the parameter-values of a private method (i don't use them at all)