File APIs for Java Developers
Manipulate DOC, XLS, PPT, PDF and many others from your application.
The moose likes Programmer Certification (SCJP/OCPJP) and the fly likes Assertions related Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login
JavaRanch » Java Forums » Certification » Programmer Certification (SCJP/OCPJP)
Bookmark "Assertions related" Watch "Assertions related" New topic

Assertions related

achayya matta
Ranch Hand

Joined: Oct 27, 2005
Posts: 111
hai ranchers
i am presenly using jdk 1.4.2_03.
Can anyone tell me how to compile and run programs?
thanks in advance.
Mausam M Kakkad
Ranch Hand

Joined: Oct 27, 2005
Posts: 40

OK, in your version you can run programs with Assertions enabled.

For compiling your program to support "assert" as keyord, you can compile it as

CMD_Prompt>>javac -source 1.4 //this thing has been added in 1.4 only

for running the program you have to enable the assertion(by default it is disabled). You can enable that for your class as following.

CMD_Prompt>> java -ea classname

This is the most basic syntax for this command. There are various possibilities for enabling/disabling assertions for particular class, package, systemclass etc.

Hope it will help,

Krishna Latha Grandhi
Ranch Hand

Joined: Nov 08, 2005
Posts: 110
Assertions are disabled by default. To compile with assertions enabled, you need to use the source 1.4 flag:

javac -source 1.4

To enable assertions at runtime, use the -enableassertions or -ea flags.

For selective disabling of assertions at runtime, use the -da or -disableassertions flags.

For enabling assertions in the system classes, use the -esa or -dsa flags.
Assertions can also be enabled or disabled on a package basis.

Hope this will help
Venkat KG

Joined: Nov 13, 2005
Posts: 10
Hi Ashok,

In General, Assertions are enabled only if you turn on it explicitly.By default they are not enable.

Use '-ea' to enable assertions.

achayya matta
Ranch Hand

Joined: Oct 27, 2005
Posts: 111
thank u very much guys
I agree. Here's the link:
subject: Assertions related
It's not a secret anymore!