Using assert()

hello
Where m i wrong in using assert()
In both outputs it print out: True Number,True Number
class assertion
void take(int a)
      assert(a>5);
      System.out.println("True Number");
  public static void main(String[] args)
     assertion obj=new assertion();
      obj.take(1);
      obj.take(20);
}

Java-Manoj wrote:
kajbj wrote:
(Use the -ea vm argument)Ok, I got it, but the argument vm is not required.
Sorry. That I caused confusion. -ea is the vm argument, there's a difference between vm arguments and application arguments.

Similar Messages

  • How to use assert with wireless toolkit?

    Hi,
    I am trying to find out how to use assert with wireless toolkit. I have found that I need to pass "-source 1.4" to the java compiler. But I can't find any documentation on how to do it.
    I'm using J2ME Wireless Toolkit 2.2.
    thanks
    Ludde

    Here's a quote from an article on Java World at http://www.javaworld.com/javaworld/jw-11-2001/jw-1109-assert.html
    "To support the new assertion facility in J2SE 1.4, the Java platform adds the keyword assert to the language, an AssertionError class, and a few additional methods to java.lang.ClassLoader."
    So I really think it's part of 1.4.

  • How to Use " ASSERT ID " , in the programm and what is the use of it?

    Hi,
    friends,
    I wanted to write a program (TEST CASE) by using ASSERT ID . But i got the description (Hint) like what iam mentioning below:
    *" Detects uses of ASSERT ID and flags cases where there is code to be executed after the command. In production environments ASSERTS are disabled, as a rule, therefore this code gets to be executed. "
    So, let me know the Use of this key word with some example .
    Thanks & Regards,
    P.N.Kumar

    Hi,
         Please look for F1 on this keyword. Also look at "Checkpoints".
         Check this link.
         http://help.sap.com/erp2005_ehp_02/helpdata/EN/9b/b1b64104e52f31e10000000a155106/frameset.htm
    Regards,
    Srini.

  • Using assert or exception?

    I have been struggling with the methodology of using assertions for some time
    now and would like to have an objective viewpoint. It primarily has to
    do with the use of assertions for pre-conditions.
    Let's say we have some class, for demonstration purpose only, as this one:
    public class MyClass {
        private final String str;
        public MyClass(String str)
            this.str = str;
        private int getLength(String x, String y)
            return x.length() + y.length();
        public int getTotalLength(String x)
            return  getLength(str, x);
    }Let's say I want to make sure that the classes methods and constructor is not
    called with any null parameter. Of course I will get a NullPointerException
    eventually automatically anyway, but let's say I want to know as soon
    as possible to something is wrong. Or maybe I am dealing with a complicated
    class in which it is not so clear yet.
    Anyway the Sun Java documentation says the following:
    http://java.sun.com/j2se/1.4.2/docs/guide/lang/assert.html#preconditions
    "Do not use assertions to check the parameters of a public method."
    Instead it should throw some particular exception. In this case a
    NullPointerException in the MyClass constructor if the str parameter is
    null. Conventation say that assertion can be used for private methods
    however, such as the getLength method.
    I always try to keep my classes relatively small. So often I feel no desire
    to include assertions in private methods to check parameters if I can
    already see that the parameters are checked in the public methods.
    So in this case why add assertions in getLength if I can already clearly
    see that the parameters have been checked in the MyClass constructor and
    the getTotalLength method?
    Maybe I am wrong, but I am afraid that using such rigurous parameter testing
    in every public method might influence performance too much, because in
    contrary of assertions these normal checks are done always. I cannot
    remove these normal checks, because that would mean it could trigger
    an assertion in one of the private methods, and I could as well move
    the assertions from the private to the public methods.
    What I don't feel comfortable about is this big distinction between
    assertions and run-time exceptions. Why not use assertions in
    public methods for parameter testing? They are just exceptions
    too anyway. And they have the benefit of not impacting performance
    for production environments.
    There is an article about challenging the Sun Assert convention here.
    http://www.javaworld.com/javaworld/jw-12-2001/jw-1214-assert-p2.html
    I would like you to read it and give your objective opinion. Weighing
    the positive and negative implications of it and tell me what you
    think and why.

    I don't have the time to read that article. IMO
    assertions are to be used to validate the state of
    your instance and its internal works.So you do not think that assertions should be used for any pre-conditions of parameters?
    They are not
    exceptions, by the way. Failure will result in an
    AssertionError.Yes, I should have said errors or throwables.
    It's quite overkill IMO to use those for the
    validation of parameters provided by someone else.Why? Isn't it overkill to impact the performance by
    using run-time exceptions instead of assertions?
    If
    your API declares the legit value range of an
    argument, a NullPointerException for null and an
    IllegalArgumentException for values outside bounds,
    that gives me more flexibility to react and handle
    error states (it could be user input - null would
    mean there's a bug, out of bounds would mean I have
    to ask the user again) than merely firing of a "big"
    assertion error.But the whole idea of pre-conditions is that the method never must be called with invalid values. Your example might make sense for some class close to the front-end, but most classes are deep inside everything and have no idea what to do with a NullPointerException or IllegalArgumentException at that point. I would let a facade near the front-end deal with invalid user input and explicitly prevent the invalid input progress deeper inside my code.
    The article I linked goed deeper in about why it is a good idea to give a "big" assertion error at that point.
    There's probably no hard or objective rule when you
    should use what anyway, otherwise, there wouldn't be
    different opinions in this matter. If you're looking
    for one, you'll most likely not find it.I have certain ideas about assertions and I would like to know if these ideas are reasonable. Especially because they go against the Sun convention and I usually am a follower of standards.

  • Debugging using assertions

    hello,
    is there any java game developer here using assert function
    i had read the article and still don't know how to use it properly
    it said that assert is the best way for debugging
    until now i only use the conventional System.out.println for debugging
    (do not know how to use any debugger tool)
    i'll be very grateful if someone can explain how to use it,
    cos i have been through many difficulties using System.out.println to find bugs in my infinitive game loop
    thanxx a million

    Using assertions:
    - you put expressions in your code like
    assert(val > 0);
    or
    assert (val > 0):"variable val too low";
    - you must use java 1.4 or later and compile with javac -source 1.4
    - you must run with java -enableassertions
    - if the assertion condition is not true an AssertionError is thrown
    You should only use assertions to check conditions resulting from you code's execution, never conditions arising out of user input or parameters passed to public methods.
    When your code is run without the -enableassertions the assert statements become no-ops.
    Hope this helps.

  • Using Assert EOI vs EOI on EOS

    given the ability to enable all the various EOS/EOI options in my application...
    If I'm allowing assert EOI on matching EOS for ibeos, should I also still allow Assert EOI through ibeot?
    Are the two ever used together as a 'fallback' measure or does the EOI on EOS 'overwrite' EOI through EOT?

    ceetee wrote:
    given the ability to enable all the various EOS/EOI options in my application...
    If I'm allowing assert EOI on matching EOS for ibeos, should I also still allow Assert EOI through ibeot?
    Are the two ever used together as a 'fallback' measure or does the EOI on EOS 'overwrite' EOI through EOT?
    They are separate.
    ibeot tells NI-488.2 to assert the EOI line with the last byte in the buffer.
    ibeos (with your options) tells NI-488.2 to assert the EOI line whenever it is sending a byte across the bus that matches the EOS character.
    If the last byte is the EOS character, both mechanisms will assert EOI. I generally recommend using ibeot and make sure that the EOS character is the last byte in the buffer. The times that ibeos is good if you need to send a string like "abc\ndef\nghi\n" where abc, def, and ghi are all commands to the device and you need them to be different messages, each with EOI asserted. Then, ibeos will assert EOI with the \n and the device will not know that you did all three in one ibwrt call (vs. ibwrt "abc\n", ibwrt "def\n", and ibwrt "ghi\n"). This is not typically a use case. It is more likely a use case for a non-controller application that was originally serial based and you are porting it to GPIB and don't want to change the host app that did terminate read requests on \n. However, as a controller app it has limited functionally. However, it it fits your use case, feel free to use it!

  • How to use assert about jdk1.4

    I write a Test java file to test the assert statement but fail to compile.
    public class Test{
    public static void main(String args[]){
    int i = new Integer(args[0]).intValue();
    assert true;
    if(i%3==0){
    System.out.println("good");
    }else if(i%3==1){
    System.out.println("better");
    }else{
    System.out.println("best");
    What's the problem, and how to fix it?
    Thanks!

    you need to tell pass the compiler the -source 1.4 flag to get it
    compile a class with assert.
    see here
    http://java.sun.com/j2se/1.4.1/docs/guide/lang/assert.html#compiling

  • Using Assert id

    Hi  ABAP guru's,
    In this scenario,
    data: w_c1(3) type c,
          w_c2 type i,
          zemp1 like table of zemp.
    field-symbols <fs> type zemp.
    select * from zemp into table zemp1.
    read table zemp1 with key empno = '1' assigning <fs>.
    assert id AAB_DEMO condition sy-subrc = 0.
    w_c1 = <fs>-empno.
    write w_c1.
    Here AAB_DEMO is check group created in SAAB transaction inactive mode.         
    if sy-subrc ne 0. is it possible to run this program without getting any runtime error?
    Thanks in advance.
    Prasad G.V.K

    Check the weather the field-symbol is assigned or not before accessing it.
    select * from zemp into table zemp1.
    read table zemp1 with key empno = '1' assigning <fs>.
    assert id AAB_DEMO condition sy-subrc = 0.
    check <fs> is assigned.  " << check assigned status of the <FS>
    w_c1 = <fs>-empno.
    write w_c1.
    Regards,
    Naimesh Patel

  • Why assertion instead of if statement ?  Which is better to use ?

    Why assertion instead of if statement ? Which is better to use ?

    Never assertion instead of if statement. The two have fundamentally different intents. Using assert to control program flow is a bad idea

  • ASA WebVPN. How do you restrict access to users in an AD group using LDAP?

    Hi All,
    I am trying to configure separate WebVPN connection profiles to give different portal bookmark contents to users based on their AD group membership.  This has been very difficult, even though I beleive it should be easy.
    The login page of teh ASA by default has a dropdown to allow default users to access the default portal and the SSL VPN client connection.
    There are two other portals that I would like to restrict access to based on AD group membership.  I have set these up to be selected by URL.
    The biggest problem is, I have no way of knowing how to go about this.  The AAA LDAP options show a group membership search, which I have configured, but I cannot say "Profile X is restricted to AD group CarpetBaggers", so that if soneone that is NOT a carpetbagger tries to log in, it fails.
    I can only do an all or nothing scenario.
    It would be nice to use Dynamic Access Policies to do this, and I have created a few, but they do NOT seem to work when the drop down aliases or URLs are in use.  So how do I go about using them in this scenario?  Turning off the aliases or URLs is not really an option right now.
    Scenario 1 would work the best for me.  Restrict access to profiles/groups based on AD group membership using LDAP.
    Scenario 2 would be an ideal longer term solution.
    Any thoughts, ideas or assitance would be greatly appreciated.
    Cheers

    This is exactly what i was looking for, and Nelson is correct.  When you enter the DAP configuration for a profile click on "Advanced" and there is the option to create a logical expression.  The guide (ther is a button to access this) is really helpful, with a couple of examples.  This is what i used:
    assert(function()
       if ( (type(aaa.ldap.distinguishedName) == "string") and
            (string.find(aaa.ldap.distinguishedName, "OU=Users") ~= nil) )
    then
           return true
       end
       return false
    end)()
    from the debug dap you can see what Users relates to;
    DAP_TRACE: Username: MyUsername, aaa.ldap.distinguishedName = CN=Mr B,OU=Users,OU=Site ******,DC=CH,DC=Mycompany,DC=com
    My admin account fails to get me in to the same profile:
    DAP_TRACE: dap_add_to_lua_tree:aaa["ldap"]["distinguishedName"]="CN=Admin Mr B,OU=Admin Users,OU=Site *****,DC=CH,DC=Mycompany,DC=com"
    Thanks
    Andrew

  • Assert error!! how to solve that problem?

    Hi,
    when i use an assert after the compilation , the error is:
    C:\CLASSES>javac Assertion.java
    Assertion.java:11: as of release 1.4, 'assert' is a keyword, and may not be used as an identifier
    (try -source 1.3 or lower to use 'assert' as an identifier)
    public static void assert(boolean expression, String why) {
    ^
    1 error
    The tutorial says: In order for Code Sample 1(Doesn't matter) to compile, use -source 1.3 because assert is a keyword as of J2SE 1.4.
    what is the source 1.3 ?? where and what the hell is that?? LOL =))
    thanks!

    i understand and i don't understand.
    lol
    thats possible for someone who is using xemacs but someone who is using Eclipse or JCreator how do i do that?
    if u don't want to answer that question could u put an assertion in this code, for example : asser -> if the num < = 0 !
    here is the code:
    import java.io.*;
    public class Capicua {
         public static void main (String[] args) throws Exception {
              int digit, num;
              int inverted = 0;
              int x;     
                   BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
                   System.out.print(" Insert number: ");
                   num=Integer.parseInt(br.readLine().trim());
                   Assertion.assert(num <= 0, "Number can't be shorter or equals to zero!"); <--- how do i put an assert here? ( with the "do - while" its easy, but and with the asserts?
                   x=num;
                   while(num > 0) {
                   digit = num % 10;
                   num = num /10;
                   inverted = inverted * 10 + digit;
                   System.out.println("inverted = " + inverted);
                        if(inverted == x) {
                             System.out.println("Capicua");
                        }else{
                             System.out.println("not a capicau");
    }

  • Assertion in oracle sql developer

    Hello all
    im using oracle sql developer and oracle11g , how can i use assertion for my tables? i searched in internet but there were no useful information
    thank u in advance
    best,
    david

    >
    I think something like this: we use a primary key which is in another table, it should be included there,this is not assertion in oracle?
    >
    No. That is a foreign key constraint.
    There are other types of constraints that you CAN use on tables such as check constraints.
    See the 'Constraint' section in the SQL Language Doc
    http://docs.oracle.com/cd/B28359_01/server.111/b28286/clauses002.htm
    >
    constraintPurpose
    Use a constraint to define an integrity constraint—a rule that restricts the values in a database. Oracle Database lets you create six types of constraints and lets you declare them in two ways.
    The six types of integrity constraint are described briefly here and more fully in "Semantics":
    A NOT NULL constraint prohibits a database value from being null.
    A unique constraint prohibits multiple rows from having the same value in the same column or combination of columns but allows some values to be null.
    A primary key constraint combines a NOT NULL constraint and a unique constraint in a single declaration. It prohibits multiple rows from having the same value in the same column or combination of columns and prohibits values from being null.
    A foreign key constraint requires values in one table to match values in another table.
    A check constraint requires a value in the database to comply with a specified condition.
    A REF column by definition references an object in another object type or in a relational table. A REF constraint lets you further describe the relationship between the REF column and the object it references.
    >
    And see 'Managing Integrity Constraints' in the DBA Guide
    http://docs.oracle.com/cd/B28359_01/server.111/b28310/general005.htm

  • Running Business Rules with Decision Service using WebDav

    Hello everybody, I have a problem when I change a rule from Rules Author.
    I have the following scenario:
    Machine1 - I have Oracle Soa Suite 10 and I have defined a rule set using Rules Author pointing to a WebDav repository on Machine2
    Machine2 - I have define my WebDav repository, it contains the rule "amountToPay > 100"
    Machine3 - I have a deploy of a BPEL process using a Decision Service and Decide Activity elements pointing to my WebDav repository
    When I test my BPEL process it works correctly, but after I change the rule in Rules Author (on machine1) to "amountToPay > 200" the next invocations of BPEL process still evaluating the rule "amountToPay > 100" and doesn't evaluates my last changes on the rule, and I need to redeploy my BPEL process so that it takes the new changes on the repository.
    I am using Assert facts, execute rule set, retrieve results, and reset the session operation pattern in decision service and assertExecuteWatchStateless in invoke activity. I tried using assertExecuteWatchStateful as well but there was no difference in the result, any idea of that?
    Does the BPEL process needs to be redeployed?
    What can I do so that my rules take effect?
    I've searched for documentation but I couldn't find any solution.
    Thanks in advance.
    Luciano
    Message was edited by:
    user606994

    Hi,
    I am new to Oracle Fusion and working on Business Rules.
    Can you please tell me the changes need to be done in the sample java application to connect to the webDAV repository(carrental example which they have given in user guide)?
    Thanks in advance.
    I am using 10.1.3.1 version.

  • J2SE 1.4 assertion facility

    I'm trying to test drive the new assertion facility in J2SE 1.4 but can't get even a simple example to work:
    public class Foo
         public void m1( int value )
              assert 0 <= value;
              System.out.println( "OK" );
         public static void main( String[] args )
              Foo foo = new Foo();
              System.out.print( "foo.m1( 1 ): " );
              foo.m1( 1 );
              System.out.print( "foo.m1( -1 ): " );
              foo.m1( -1 );
    Code fails with the following error:
    Foo.java:5: Invalid expression statement.
    assert 0 <= value;
    The compiler fails to recognize the 'assert' keyword - when I change code to:
    boolean b = true;
    assert b;
    the error is:
    Foo.java:7: Class assert not found.
    assert b;
    So, it thinks I'm defining a variable b of type assert rather than recognizing the keyword 'assert'!
    I've doing all this in the new J2SE 1.4 - I do have other versions of the JDK on my machine, but am pretty sure I'm compiling against the right one - when I type 'java -version' on command line I get:
    java version "1.4.0"
    Java(TM) 2 Runtime Environment, Standard Edition (build 1.4.0-b92)
    Java HotSpot(TM) Client VM (build 1.4.0-b92, mixed mode)
    Anyone any ideas?
    Thanks,
    Alan

    what bs. post-condition type assertions typically
    "validate the internal state of the receiver".
    pre-condition type assertains are typically used to
    validate the state of arguments passed in.
    Pre-condition type asserts define the "contract" a
    caller must agree to prior to calling. It's very
    simple, and very effective.No, you shouldn't use assertions to test pre-conditions. The pre-conditions should always be checked, not just in debug mode. Otherwise, the program could behave differently in debug and release modes, and that would be very undesirable!

  • Assert that repaint operations occur in proper thread

    Seems to me like one of the most common errors made during Swing development is the modification of components from the wrong thread. I'd like to see assertions used to verify that updates occur within the event-dispatching thread. Is there some architectural or historical reason for not doing this (within the core API)? Nonbelievers could just disable assertions for the requisite packages, right? Far as I can tell, Sun only uses assertions to validate the internal consistency of its code. Anything that a third party can screw up will be caught in some other way (or not caught at all). I appreciate that life could be more confusing if core code runs differently based on assertion enablement. Still, I think that forgoing checks leads to errors and explicit checks (i.e. "if (problemExpr) throw new RuntimeException();") might cost too many cycles. I guess that the real question is whether assertions should be used to catch your client's mistakes as well as your own. If so, isn't Swing threading a worthy candidate for such a check?

    I think that they probably could, but it seems to me that implementing that check is something that would introduce overhead that would not be desirable in an app where you do the right thing in the first place.
    And it's not always the case that certain methods involved must always be done on the event dispatch thread. There are exceptions to the rule, so it would have to be very carefully thought out where these assertions would go.

Maybe you are looking for