assertion example

What will happen if you attempt to compile following code with JDK1.4 with assertions enabled

public class Bbridge{
    int iRunningTotal=0;
    public static void main(String argv[]){
        Bbridge bb = new Bbridge();
        bb.go(argv[0]);
    }  
    public void go(String s){
        int i = Integer.parseInt(s);
        setRunningTotal(i);            
        assert (iRunningTotal > 0): getRunningTotal();
    }
    public String getRunningTotal(){
        return "Value of iRunningTotal "+iRunningTotal;
    }
    public int setRunningTotal(int i){
        iRunningTotal+=i;
        return iRunningTotal;
    }
}
1) Compile time error, getRunningTotal does not return a boolean
2) Compile time error malformed assert statement
3) Compilation and no output given a command parameter of 1
4) Compilation and assert error given a command parameter of 0

I was trying above example from link

http://www.jchq.net/certkey/0205certkey.htm

did not understand how to run and get output while running in eclipse ide.How to enable assertion and run this example.

I was trying to understand the output.


 Any links, ideas, resources,sample code highly appreciated. thanks in advance.
LVL 7
gudii9Asked:
Who is Participating?

[Product update] Infrastructure Analysis Tool is now available with Business Accounts.Learn More

x
I wear a lot of hats...

"The solutions and answers provided on Experts Exchange have been extremely helpful to me over the last few years. I wear a lot of hats - Developer, Database Administrator, Help Desk, etc., so I know a lot of things but not a lot about one thing. Experts Exchange gives me answers from people who do know a lot about one thing, in a easy to use platform." -Todd S.

Mick BarryJava DeveloperCommented:
you can do it globally

http://www.cs.utexas.edu/~scottm/cs307/handouts/Eclipse%20Help/EclipseIntroduction.html#assertions

or specify the -ea option in the vm option in the Run configuration

Experts Exchange Solution brought to you by

Your issues matter to us.

Facing a tech roadblock? Get the help and guidance you need from experienced professionals who care. Ask your question anytime, anywhere, with no hassle.

Start your 7-day free trial
gudii9Author Commented:
i eanbled

>>>Under the Default VM Arguments: field type in -ea . This is a switch to enable assertions when Eclipse compiles you Java code.

ran the program getting like


>>>Exception in thread "main" java.lang.ArrayIndexOutOfBoundsException: 0
      at com.vaannila.student.Bbridge.main(Bbridge.java:6)

please advise
Mick BarryJava DeveloperCommented:
the program is expecting input on the command line
Become a CompTIA Certified Healthcare IT Tech

This course will help prep you to earn the CompTIA Healthcare IT Technician certification showing that you have the knowledge and skills needed to succeed in installing, managing, and troubleshooting IT systems in medical and clinical settings.

gudii9Author Commented:
i am running through eclipse ide. How can i pass command line input through eclipse. please advise
Mick BarryJava DeveloperCommented:
specify it in the run configuration
gudii9Author Commented:
ok
It's more than this solution.Get answers and train to solve all your tech problems - anytime, anywhere.Try it for free Edge Out The Competitionfor your dream job with proven skills and certifications.Get started today Stand Outas the employee with proven skills.Start learning today for free Move Your Career Forwardwith certification training in the latest technologies.Start your trial today
Java

From novice to tech pro — start learning today.