File APIs for Java Developers
Manipulate DOC, XLS, PPT, PDF and many others from your application.
http://aspose.com/file-tools
The moose likes Programmer Certification (SCJP/OCPJP) and the fly likes Enabling Assertions Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login


Win a copy of Murach's Java Servlets and JSP this week in the Servlets forum!
JavaRanch » Java Forums » Certification » Programmer Certification (SCJP/OCPJP)
Bookmark "Enabling Assertions" Watch "Enabling Assertions" New topic
Author

Enabling Assertions

Prateek Rawal
Ranch Hand

Joined: Dec 19, 2009
Posts: 90
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?



Waiting for enlightenment....
Deepak Bala
Bartender

Joined: Feb 24, 2006
Posts: 6661
    
    5

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.


SCJP 6 articles - SCJP 5/6 mock exams - More SCJP Mocks
Prateek Rawal
Ranch Hand

Joined: Dec 19, 2009
Posts: 90
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

Joined: Sep 12, 2009
Posts: 316
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.


SCJP 6.0 96%

(Connecting the Dots ....)
Prateek Rawal
Ranch Hand

Joined: Dec 19, 2009
Posts: 90
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

Joined: Sep 12, 2009
Posts: 316
In myclass too and all classes use by myclass, effectively, except system classes
Prateek Rawal
Ranch Hand

Joined: Dec 19, 2009
Posts: 90
Is it??

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

I will rely upon your suggestion, thanks buddy!!!
Deepak Bala
Bartender

Joined: Feb 24, 2006
Posts: 6661
    
    5

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

Joined: Dec 19, 2009
Posts: 90
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

Joined: Sep 12, 2009
Posts: 316
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

Joined: Dec 19, 2009
Posts: 90
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

Joined: Sep 12, 2009
Posts: 316
"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

Joined: Dec 19, 2009
Posts: 90
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

Joined: Dec 19, 2009
Posts: 90
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

Joined: Sep 12, 2009
Posts: 316
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

Joined: Sep 12, 2009
Posts: 316
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....
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: Enabling Assertions
 
Similar Threads
Assertions related
Flowcontrole with an assertion
Enabling or disabling assertions
Assertions
How to turn on assert in TextPad ?