Welcome to the Java Programming Forums


The professional, friendly Java community. 21,500 members and growing!


The Java Programming Forums are a community of Java programmers from all around the World. Our members have a wide range of skills and they all have one thing in common: A passion to learn and code Java. We invite beginner Java programmers right through to Java professionals to post here and share your knowledge. Become a part of the community, help others, expand your knowledge of Java and enjoy talking with like minded people. Registration is quick and best of all free. We look forward to meeting you.


>> REGISTER NOW TO START POSTING


Members have full access to the forums. Advertisements are removed for registered users.

Results 1 to 4 of 4

Thread: Valid Java, compile

  1. #1
    Junior Member
    Join Date
    Nov 2012
    Location
    London
    Posts
    8
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Default Valid Java, compile

    Hey I have this question in my assignment and I can't see why it would compile, so confused...any help with this question?

    The following code excerpt is valid Java

    if (b = check ()){
    System.out.println("All is OK.");
    }

    What can you infer about 'check()' and 'b'?
    The syntax for an if-expression is if(boolean expression).
    However
    b = check() appears to be an assignment expression. Explain why
    if (b = check()) does in fact compile.

    Would appreciate any help with this guys it has got me stumped.


  2. #2
    Crazy Cat Lady KevinWorkman's Avatar
    Join Date
    Oct 2010
    Location
    Washington, DC
    Posts
    5,424
    My Mood
    Hungover
    Thanks
    144
    Thanked 636 Times in 540 Posts

    Default Re: Valid Java, compile

    Hint: What does the assignment operator return? Might have to do some googling or putting together some test programs to figure it out.
    Useful links: How to Ask Questions the Smart Way | Use Code Tags | Java Tutorials
    Static Void Games - Play indie games, learn from game tutorials and source code, upload your own games!

  3. #3
    Junior Member
    Join Date
    Nov 2012
    Location
    London
    Posts
    8
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Default Re: Valid Java, compile

    How do I put a test program together for that? I am literally starting level and so un confident with Java

  4. #4
    Crazy Cat Lady KevinWorkman's Avatar
    Join Date
    Oct 2010
    Location
    Washington, DC
    Posts
    5,424
    My Mood
    Hungover
    Thanks
    144
    Thanked 636 Times in 540 Posts

    Default Re: Valid Java, compile

    How about using a print statement? Something like this:

    System.out.println(b = check());

    Now, what if the variable is an int? A String? Something else? What happens then?
    Useful links: How to Ask Questions the Smart Way | Use Code Tags | Java Tutorials
    Static Void Games - Play indie games, learn from game tutorials and source code, upload your own games!

Similar Threads

  1. Java 2D Example compile error
    By weziw in forum Java SE APIs
    Replies: 1
    Last Post: April 2nd, 2012, 07:57 AM
  2. how to compile your .java files
    By wilcomega in forum Java Theory & Questions
    Replies: 6
    Last Post: November 16th, 2011, 03:38 AM
  3. Java Program to Check whether a Expression is Valid using Stack
    By rainbow9 in forum What's Wrong With My Code?
    Replies: 1
    Last Post: November 12th, 2011, 02:11 AM
  4. how to compile java and import it as package
    By clementnas in forum What's Wrong With My Code?
    Replies: 2
    Last Post: July 19th, 2011, 05:53 AM
  5. [SOLVED] help in java i cant compile this
    By timeline in forum What's Wrong With My Code?
    Replies: 5
    Last Post: April 15th, 2010, 02:11 PM