Advertisement
Help Keep Boards Alive. Support us by going ad free today. See here: https://subscriptions.boards.ie/.
If we do not hit our goal we will be forced to close the site.

Current status: https://keepboardsalive.com/

Annual subs are best for most impact. If you are still undecided on going Ad Free - you can also donate using the Paypal Donate option. All contribution helps. Thank you.
https://www.boards.ie/group/1878-subscribers-forum

Private Group for paid up members of Boards.ie. Join the club.

Confused about a Java question

  • 23-07-2010 03:32PM
    #1
    Registered Users, Registered Users 2 Posts: 1,559 ✭✭✭


    Topic title: The assertion mechanism in Java
    Suppose you want to enable assertions for a class named "DemoApp" that is located in the C:\Java\samples directory. The class references various system classes that need to be tested. Which command would you use to enable assertions for the class?

    Choose an option.

    1: C:\>java -ea Java.samples.DemoApp
    2: C:\>java -ea Java.samples.DemoApp...
    3: C:\>java -esa -ea DemoApp
    4: C:\>java -esa -ea:Java.samples.DemoApp

    Now I thought the correct answer would be option 4 but apparently the correct answer is option 3.
    The question doesn't state that the class is an application.
    I don't understand how that can be correct could it be a mistake?
    This is from a Java course.
    Can someone help me understand this?


Comments

  • Registered Users, Registered Users 2, Paid Member Posts: 2,032 ✭✭✭lynchie


    Answer 4 would be correct if the full package name of DemoApp was Java.samples.DemoApp but as they stated that the class was just called "DemoApp" then answer 3 is correct.

    But.. and somebody else correct me if Im wrong, but technically the answer is none of them as answer 3 would give a ClassNotFoundException as running the command from c:\> like the answers given above would need -cp c:\java\samples added to it?


  • Registered Users, Registered Users 2 Posts: 1,922 ✭✭✭ronivek


    The assumption here is that C:\Java\samples is contained in the Java classpath environment variable I guess. Not that I'm advocating this type of question as being a good gauge of someones ability to do anything other than memorise command line arguments you'll likely never use; I suppose it might highlight if you understand the classpath mechanism enough to arrive at the right answer.


Advertisement