Results 1 to 4 of 4

Thread: assert

  1. #1
    Junior Member
    Join Date
    Aug 2009


    what are the uses of assert keyword?

  2. #2
    Expert Member
    Join Date
    May 2009

    Re: assert

    Quote Originally Posted by Sarje View Post
    what are the uses of assert keyword?
    Hi Sarje,

    An assertion is a statement in the JavaTM programming language that enables you to test your assumptions about your program.

    For example, if you write a method that calculates the speed of a particle, you might assert that the calculated speed is less than the speed of light.

    The assertion statement has two forms.

    a) assert Expression1 ;

    b)assert Expression1 : Expression2 ;

    Expression1 is a boolean expression., Expression2 is an expression that has a value

    Use this version of the assert statement to provide a detail message for the AssertionError.

    The system passes the value of Expression2 to the appropriate AssertionError constructor, which uses the string representation of the value as the error's detail message.

    Thanks & Regards,

  3. #3
    Expert Member
    Join Date
    Mar 2012

    Re: assert

    The assert keyword replaces the if block and automatically throws the AssertionError on failure.It is also used to validate certain expressions and should be used only in critical situations.

  4. #4
    Junior Member
    Join Date
    Aug 2012

    Re: assert

    assert is a keyword added in Java version 1.4.
    assert tests the programmer's assumption during development without writing exception handlers for an exception

  5.  Sponsored Ads


Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
About us
Applying for a job can be a stressful and frustrating experience, especially for someone who has never done it before. Considering that you are competing for the position with a at least a dozen other applicants, it is imperative that you thoroughly prepare for the job interview, in order to stand a good chance of getting hired. That's where GeekInterview can help.