Page 18 of 55 FirstFirst ... 8161718192028 ... LastLast
Results 341 to 360 of 1093

Thread: Quiz Time

  1. #341
    Eranga's Avatar
    Eranga is offline Moderator
    Join Date
    Jul 2007
    Location
    Colombo, Sri Lanka
    Posts
    11,372
    Blog Entries
    1
    Rep Power
    20

  2. #342
    serjant's Avatar
    serjant is offline Senior Member
    Join Date
    Jun 2008
    Location
    Ukraine,Zaporozhye
    Posts
    487
    Rep Power
    7

    Default

    I had already seen somewhere this question,lol
    the output:
    Java Code:
    Value is

  3. #343
    Eranga's Avatar
    Eranga is offline Moderator
    Join Date
    Jul 2007
    Location
    Colombo, Sri Lanka
    Posts
    11,372
    Blog Entries
    1
    Rep Power
    20

    Default

    Hmm, I'm not sure weather I've post such a similar quiz here before. Anyway, your answer is not correct lol. Is anyone here wants to try.

  4. #344
    serjant's Avatar
    serjant is offline Senior Member
    Join Date
    Jun 2008
    Location
    Ukraine,Zaporozhye
    Posts
    487
    Rep Power
    7

    Default

    Shit,that means no gift for me!It happens very often when i fall with the failure with such simple questions.
    Last edited by serjant; 10-17-2008 at 06:17 AM.

  5. #345
    Eranga's Avatar
    Eranga is offline Moderator
    Join Date
    Jul 2007
    Location
    Colombo, Sri Lanka
    Posts
    11,372
    Blog Entries
    1
    Rep Power
    20

    Default

    So you feel sad, because this is simple question but you miss it in hurry. Is it? Actually that is not much tricky question.

  6. #346
    serjant's Avatar
    serjant is offline Senior Member
    Join Date
    Jun 2008
    Location
    Ukraine,Zaporozhye
    Posts
    487
    Rep Power
    7

    Default

    The code compiles successfully. In this code the optional value for the ternary operator, 9.0(a double) and 9(an int), are of different types. The result of a ternary operator must be determined at the compile time, and here the type chosen using the rules of promotion for binary operands is double. Since the result is a double the output value is printed in a floating point format. The choice of which value to be printed is made on the basis of the result of the comparison "x>4" which results in false, hence the variable "x" takes the second of the two possible values, which is 9, but because the result type is promoted to double the output value is actually written as 9.0, rather than the more obvious 9.

  7. #347
    Eranga's Avatar
    Eranga is offline Moderator
    Join Date
    Jul 2007
    Location
    Colombo, Sri Lanka
    Posts
    11,372
    Blog Entries
    1
    Rep Power
    20

    Default

    That's cool lol, Nice explanation. I wonder why newbies not involve in this thread. Lots of thing to learn to everyone from here. I'll post your gift pal.

  8. #348
    DevzAbhi's Avatar
    DevzAbhi is offline Member
    Join Date
    Jul 2008
    Posts
    67
    Rep Power
    0

    Default

    Tease your brains .. can you run java class without main method ... hint .. i am not talking about applet.

  9. #349
    masijade is offline Senior Member
    Join Date
    Jun 2008
    Posts
    2,571
    Rep Power
    9

    Default

    A static block. Now do it with causing an exception.

    Edit: I meant (obviously) without, not with, causing an exception.

    Edit Again: And, Eranga, I'm sorry I edited this after your post, if you had thought I meant something else.
    Last edited by masijade; 10-24-2008 at 03:11 PM.

  10. #350
    Eranga's Avatar
    Eranga is offline Moderator
    Join Date
    Jul 2007
    Location
    Colombo, Sri Lanka
    Posts
    11,372
    Blog Entries
    1
    Rep Power
    20

    Default

    I think you can't.

    Edit for masijade: lol what actually I meant is that you cannot run a Java class without a main method.
    Last edited by Eranga; 10-24-2008 at 03:17 PM.

  11. #351
    masijade is offline Senior Member
    Join Date
    Jun 2008
    Posts
    2,571
    Rep Power
    9

    Default

    Add "System.exit(0);" as the last line of the static block.

  12. #352
    Eranga's Avatar
    Eranga is offline Moderator
    Join Date
    Jul 2007
    Location
    Colombo, Sri Lanka
    Posts
    11,372
    Blog Entries
    1
    Rep Power
    20

    Default

    Quote Originally Posted by masijade View Post
    Add "System.exit(0);" as the last line of the static block.
    lol, can you explain this little more. I'm confusing, is this not related on what I've answered before.

  13. #353
    Nicholas Jordan's Avatar
    Nicholas Jordan is offline Senior Member
    Join Date
    Jun 2008
    Location
    Southwest
    Posts
    1,018
    Rep Power
    8

    Cool newbies, oh the fun!

    Quote Originally Posted by Eranga View Post
    .....I wonder why newbies not involve in this thread. Lots of thing to learn to everyone from here....
    Wenbo Mao discusses a relevant aspect of that in the Crypto book I cited yesterday ( in other thread )

    DevzAbhi's postition does not contain sufficient information, but I think it has something to do with reflection. I have seen something that is supposed to do that but not well informed on class loader and how it actually works. Should be possible to 'bust in' somehow using class loader using Modern Cryptography. masijade's usually clear responses show the avenue in: wording of the question cannot be done certainly and adroitly in an even semi-portable way. I do not think it is a newbie issue, it is the mind of the mechanic vis-a-vis linguists.
    Introduction to Programming Using Java.
    Cybercartography: A new theoretical construct proposed by D.R. Fraser Taylor

  14. #354
    georgemc is offline Senior Member
    Join Date
    Sep 2008
    Posts
    135
    Rep Power
    0

    Default

    Quote Originally Posted by Eranga View Post
    lol, can you explain this little more. I'm confusing, is this not related on what I've answered before.
    You can abuse a static block to start a program without a main method. Because the class has to be loaded before the runtime can look up a main method, your static block has already kicked proceedings off before the runtime realises there is no main method. Of course, you get a NoSuchMethodError, but by telling the runtime to exit with a (0) the error is presumably suppressed. Sneaky but useless, except for winning bar bets with fellow geeks

  15. #355
    Eranga's Avatar
    Eranga is offline Moderator
    Join Date
    Jul 2007
    Location
    Colombo, Sri Lanka
    Posts
    11,372
    Blog Entries
    1
    Rep Power
    20

    Default

    Oh my goad, how did I miss that point. :( It's really poor decision I've made on a question. Thanks for pointing me pal.

  16. #356
    masijade is offline Senior Member
    Join Date
    Jun 2008
    Posts
    2,571
    Rep Power
    9

    Default

    Quote Originally Posted by georgemc View Post
    You can abuse a static block to start a program without a main method. Because the class has to be loaded before the runtime can look up a main method, your static block has already kicked proceedings off before the runtime realises there is no main method. Of course, you get a NoSuchMethodError, but by telling the runtime to exit with a (0) the error is presumably suppressed. Sneaky but useless, except for winning bar bets with fellow geeks
    ;)

    All too true.

  17. #357
    Supamagier is offline Senior Member
    Join Date
    Aug 2008
    Posts
    384
    Rep Power
    7

    Default

    Wow, that's one hell of an explanation, but I think I get it. ;)
    I die a little on the inside...
    Every time I get shot.

  18. #358
    georgemc is offline Senior Member
    Join Date
    Sep 2008
    Posts
    135
    Rep Power
    0

    Default

    What does this code do?

    Java Code:
    public class Puzzle {
    	public static void main(String[] args) {
    		String test = "000D 003B";
    		if (false) // test will get changed to \u000D \u003B
    		{
    			System.out.println(test);
    		}
    	}
    }

  19. #359
    xcallmejudasx's Avatar
    xcallmejudasx is offline Senior Member
    Join Date
    Oct 2008
    Location
    Houston, TX & Flint, MI
    Posts
    609
    Rep Power
    6

    Default

    I seem to be confused. you have if (false), but there is no boolean value being tested. I think it won't output anything.
    Last edited by xcallmejudasx; 10-24-2008 at 10:17 PM. Reason: That test was tons of fail. Wipe it from your memory

  20. #360
    georgemc is offline Senior Member
    Join Date
    Sep 2008
    Posts
    135
    Rep Power
    0

    Default

    Quote Originally Posted by xcallmejudasx View Post
    I seem to be confused. you have if (false), but there is no boolean value being tested. I think it won't output anything.
    The confusion is the point! Compile and run the code, exactly as posted.

Page 18 of 55 FirstFirst ... 8161718192028 ... LastLast

Similar Threads

  1. Hello, first time here.
    By ludragon in forum Introductions
    Replies: 2
    Last Post: 01-03-2008, 05:03 AM
  2. Help pls with a quiz
    By saytri in forum New To Java
    Replies: 3
    Last Post: 12-23-2007, 06:09 AM
  3. Time method
    By carderne in forum New To Java
    Replies: 5
    Last Post: 11-05-2007, 09:34 AM
  4. DataObject with the time given by me
    By garinapavan in forum New To Java
    Replies: 2
    Last Post: 08-07-2007, 06:33 PM

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •