aspose file tools*
The moose likes Developer Certification (SCJD/OCMJD) and the fly likes I really need help. Assertions wont compile with source 1.4 flag and more... Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login
JavaRanch » Java Forums » Certification » Developer Certification (SCJD/OCMJD)
Bookmark "I really need help. Assertions wont compile with source 1.4 flag and more..." Watch "I really need help. Assertions wont compile with source 1.4 flag and more..." New topic
Author

I really need help. Assertions wont compile with source 1.4 flag and more...

Yucca Nel
Ranch Hand

Joined: Nov 20, 2008
Posts: 147

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

^
tractor.java:28: ';' expected
assert MAGIC_COOKIE == new DBExtract().getMagic() :"agic cooki

^
tractor.java:28: invalid method declaration; return type requir
assert MAGIC_COOKIE == new DBExtract().getMagic() :"agic cooki

^
tractor.java:28: ';' expected
assert MAGIC_COOKIE == new DBExtract().getMagic() :"agic cooki

^
rrors

Users\Yucca\Documents\NetBeansProjects\SCJD\src\suncertify\db>


And yet I am compiling with the flags?

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!!
Roel De Nijs
Bartender

Joined: Jul 19, 2004
Posts: 5599
    
  15

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


SCJA, SCJP (1.4 | 5.0 | 6.0), SCJD
http://www.javaroe.be/
Yucca Nel
Ranch Hand

Joined: Nov 20, 2008
Posts: 147

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)
Yucca Nel
Ranch Hand

Joined: Nov 20, 2008
Posts: 147

The point is
1) Is this undesirable
2) Can I hardcode my magic cookie without showing the exam assesors how I got the number
Ulises Pulido
Ranch Hand

Joined: Jul 24, 2008
Posts: 81
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.


Regards!


SCJP 5.0, SCWCD 5.0, SCBCD 5.0, SCJD, SCEA in progress
www.ulisespulido.com
Yucca Nel
Ranch Hand

Joined: Nov 20, 2008
Posts: 147

No you miss understand...

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.

Regards
Yucca
Ulises Pulido
Ranch Hand

Joined: Jul 24, 2008
Posts: 81
In any case this code


should be



to compile as far as I know
Roel De Nijs
Bartender

Joined: Jul 19, 2004
Posts: 5599
    
  15

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)

good luck
Roel
Bert Bates
author
Sheriff

Joined: Oct 14, 2002
Posts: 8883
    
    5
this thread has meandered a bit, but if I'd caught it earlier I would have moved it to the intermediate forum - just fyi.

Bert


Spot false dilemmas now, ask me how!
(If you're not on the edge, you're taking up too much room.)
Yucca Nel
Ranch Hand

Joined: Nov 20, 2008
Posts: 147

Sorry. Thanks for the great I hope the design patterns I ordered last week is as good. I cant wait
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: I really need help. Assertions wont compile with source 1.4 flag and more...