• Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

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

 
Yucca Nel
Ranch Hand
Posts: 147
IntelliJ IDE Java Ubuntu
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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.

 
Roel De Nijs
Sheriff
Posts: 10440
134
AngularJS Chrome Eclipse IDE Hibernate Java jQuery MySQL Database Spring Tomcat Server
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
 
Yucca Nel
Ranch Hand
Posts: 147
IntelliJ IDE Java Ubuntu
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Posts: 147
IntelliJ IDE Java Ubuntu
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Posts: 81
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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!
 
Yucca Nel
Ranch Hand
Posts: 147
IntelliJ IDE Java Ubuntu
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Posts: 81
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
In any case this code


should be



to compile as far as I know
 
Roel De Nijs
Sheriff
Posts: 10440
134
AngularJS Chrome Eclipse IDE Hibernate Java jQuery MySQL Database Spring Tomcat Server
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Posts: 8900
5
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
 
Yucca Nel
Ranch Hand
Posts: 147
IntelliJ IDE Java Ubuntu
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Sorry. Thanks for the great I hope the design patterns I ordered last week is as good. I cant wait
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic