Win a copy of Re-engineering Legacy Software this week in the Refactoring forum
or Docker in Action in the Cloud/Virtualization forum!
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

Enabling Assertions

 
Prateek Rawal
Ranch Hand
Posts: 90
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
We know that java command is used to run or interpret a class file..........

Thus java is always used in context of a particular program or class file.

Now, K & B tells us by this line:


to enable assertions in general,
however as java is written a file must be interpreted i.e. it should be something like:


However, java -ea also runs,

but what does that mean?

Does it mean that assertions are enabled in general, means now whatever program is being interpreted, assertions will be enabled for all of them and you need not enable them explicitly everytime you run the file(unless you close the command prompt)?

Similar case is with :
it means enabling assertions and disabling assertions for System classes, but the point is enabling assertions for whom?


 
Deepak Bala
Bartender
Posts: 6663
5
Firefox Browser Linux MyEclipse IDE
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
java -ea also runs,


I am not sure I understand. Runs what ? Unless you specify a class name to execute, java will not execute anything.
 
Prateek Rawal
Ranch Hand
Posts: 90
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
java -ea also runs,


By run i mean that the above command get executed, there is no message displaying "UnKnown Command" or something........

and as you said:
Runs what ? Unless you specify a class name to execute


i have the exact query that if java -ea meaning enabling assertions, whom are they enabled for?

 
Sahil Kapoor
Ranch Hand
Posts: 316
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Prateek , it just gives information about -ea switch and would not enable anything
You have to use -ea with class name having main method to tell JVM that run main method of given class and enable assertions of all the classes used by my class but not System classes.

 
Prateek Rawal
Ranch Hand
Posts: 90
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Okay, so ClassName is must, but when you said:
that run main method of given class and enable assertions of all the classes used by my class but not System classes.


it means enable assertions of all the classes used by myclass or enables all the assertions in myclass???
I think it means the later one but you might have wrongly written it???
 
Sahil Kapoor
Ranch Hand
Posts: 316
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
In myclass too and all classes use by myclass, effectively, except system classes
 
Prateek Rawal
Ranch Hand
Posts: 90
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Is it??

K & B doesn't specify it.....weird

I will rely upon your suggestion, thanks buddy!!!
 
Deepak Bala
Bartender
Posts: 6663
5
Firefox Browser Linux MyEclipse IDE
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
K & B doesn't specify it.....weird


Sure ? I remember that it was mentioned in the book. Perhaps it is hiding in a corner
 
Prateek Rawal
Ranch Hand
Posts: 90
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
What about this?

Does it mean enable assertions(again, for whom?) and disable it for JavaFile and all the classes used by it?
This sounds contradictory.........
 
Sahil Kapoor
Ranch Hand
Posts: 316
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Ooppss you made me confuse too....

Finally it means......

1) Enable assertions in general for all classes except System classes.

2) Disable assertions in the class JavaFile ONLY !!!

Actually i also wrote ,effectively, But just forget it and i think you rely on this !!!

 
Prateek Rawal
Ranch Hand
Posts: 90
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Means earlier you told java -ea JavaFile means enable assertions for JavaFile and all the classes used by JavaFile,,,,was that wrong? Please Clarify....

Also as you said
java -ea -da:JavaFile

means enable assertions for all classes(except system classes), that again raises the question for which class? as we haven't mentioned it explicitly in the java command....

if the above command serves no purpose, and if at all if we need to enable assertion for a particular class, we need to do it while running the class using java....then why are these commands for, i seriously don't understand...useless commands,adding confusion!!!

What a mess man.....i'm fed up
 
Sahil Kapoor
Ranch Hand
Posts: 316
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
"Ha ha ha" ==> Seems frustrated from java semantics.....Sometimes i also do......But we are users of Java and we have to comply with Java Rules !!!
May be if you would design something, you may design it in abetter way.



Let me try to explain it again....

when you say

java -ea -da:Prateek <some class having main method>

You say, enable assertions in general but disable it for Prateek class ONLY. What does this mean is , hey compiler during execution of my current application...if you find any class other than
Prateek, and it has assertion statements, then do execute them as well , but please do not execute it for Prateek class ( as he is already frustrated and can Blast )

Cheers!!!


 
Prateek Rawal
Ranch Hand
Posts: 90
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
He he.....

Thanks for the reply(and even more thanks for the funny one :P)

so, writing is not meaningful although legal(weird Java Rules), it becomes meaningful only when we write:


Right, na?

Hey, i'm frustated accepted, but i'm not gonna blast man :P

 
Prateek Rawal
Ranch Hand
Posts: 90
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Your Post
This has been posted by you but i guess the result of the discussion is still awaiting....

I'm certainly surprised to see option (2) in your answer, why do you think it happenned? Have you figured it out yet

The question says:

it means enable assertions for net.example.LaunchTranslator, and for all the classes except those in com package and its subpackages....

but dot.com.Boom is definitely in the com package, then why so?
 
Sahil Kapoor
Ranch Hand
Posts: 316
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Ya while i was answering your reply....i was also having doubt related to Assertions but it was different from you....It was related to packages....
Still not answered what did i asked there ???
 
Sahil Kapoor
Ranch Hand
Posts: 316
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
According to ankit......it disables assertions from packages starting from com...... .
After thsi i really want to write something in hindi...because i can only release my frustration in HINDI !!! but public etiquetes is restricting me....
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic