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?
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.

objectsCommented:
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
0

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
0
objectsCommented:
the program is expecting input on the command line
0
Cloud Class® Course: Microsoft Office 2010

This course will introduce you to the interfaces and features of Microsoft Office 2010 Word, Excel, PowerPoint, Outlook, and Access. You will learn about the features that are shared between all products in the Office suite, as well as the new features that are product specific.

gudii9Author Commented:
i am running through eclipse ide. How can i pass command line input through eclipse. please advise
0
objectsCommented:
specify it in the run configuration
0
gudii9Author Commented:
ok
0
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.

Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.