Results 1 to 16 of 16

Thread: Quick Java help

  1. #1
    fold fold fold!
    Join Date
    Nov 2008
    Posts
    511
    Thanks
    25
    Thanked
    32 times in 25 posts
    • shbris's system
      • CPU:
      • 1600x
      • Memory:
      • 16GB
      • Storage:
      • various ssd's
      • Graphics card(s):
      • gtx 1060 6gb
      • Case:
      • mini itx
      • Operating System:
      • Windows 10
      • Internet:
      • 100/10

    Quick Java help

    What value will be printed?

    public class TryToImcrement {
    ........... public static void main(String[] args) {
    .....................................int j=0;
    .....................................for (int i=0; i < 100; i++) {
    ................................................j = j++;
    ........................................}
    .......................}
    }

  2. #2
    cat /dev/null streetster's Avatar
    Join Date
    Jul 2003
    Location
    London
    Posts
    4,138
    Thanks
    119
    Thanked
    100 times in 82 posts
    • streetster's system
      • Motherboard:
      • Asus P7P55D-E
      • CPU:
      • Intel i5 750 2.67 @ 4.0Ghz
      • Memory:
      • 4GB Corsair XMS DDR3
      • Storage:
      • 2x1TB Drives [RAID0]
      • Graphics card(s):
      • 2xSapphire HD 4870 512MB CrossFireX
      • PSU:
      • Corsair HX520W
      • Case:
      • Coolermaster Black Widow
      • Operating System:
      • Windows 7 x64
      • Monitor(s):
      • DELL U2311
      • Internet:
      • Virgin 50Mb

    Re: Quick Java help

    nothing... there's no System.out.println(j); statement?

    j++ is the same as j=j+1, it's saying j=(j=j+1)... so seems unintuitive.

    I would have though j is 100 at the end though as the for loop will have gone around 100 times. 0->99.

  3. #3
    Not a good person scaryjim's Avatar
    Join Date
    Jan 2009
    Location
    Gateshead
    Posts
    15,196
    Thanks
    1,230
    Thanked
    2,291 times in 1,874 posts
    • scaryjim's system
      • Motherboard:
      • Dell Inspiron
      • CPU:
      • Core i5 8250U
      • Memory:
      • 2x 4GB DDR4 2666
      • Storage:
      • 128GB M.2 SSD + 1TB HDD
      • Graphics card(s):
      • Radeon R5 230
      • PSU:
      • Battery/Dell brick
      • Case:
      • Dell Inspiron 5570
      • Operating System:
      • Windows 10
      • Monitor(s):
      • 15" 1080p laptop panel

    Re: Quick Java help

    I assume this is a class problem to see if you understand the difference between j++ and ++j? Or perhaps even just how increment operators are handled as part of a statement.

    I have to admit I've tested it - my first inclination would be that j would remain as 0 but I wasn't 100% sure. I ran the code in javascript (having it print out the result at each iteration) and sure enough j remains 0. I guess the question for you at that point is to work out why

  4. #4
    cat /dev/null streetster's Avatar
    Join Date
    Jul 2003
    Location
    London
    Posts
    4,138
    Thanks
    119
    Thanked
    100 times in 82 posts
    • streetster's system
      • Motherboard:
      • Asus P7P55D-E
      • CPU:
      • Intel i5 750 2.67 @ 4.0Ghz
      • Memory:
      • 4GB Corsair XMS DDR3
      • Storage:
      • 2x1TB Drives [RAID0]
      • Graphics card(s):
      • 2xSapphire HD 4870 512MB CrossFireX
      • PSU:
      • Corsair HX520W
      • Case:
      • Coolermaster Black Widow
      • Operating System:
      • Windows 7 x64
      • Monitor(s):
      • DELL U2311
      • Internet:
      • Virgin 50Mb

    Re: Quick Java help

    /me needs to go back to school...

    Fired up Eclipse...

    j++ => 100
    ++j => 100
    j = j++ = 0

    Aha... An explanation
    Last edited by streetster; 08-02-2012 at 02:01 PM.

  5. #5
    Not a good person scaryjim's Avatar
    Join Date
    Jan 2009
    Location
    Gateshead
    Posts
    15,196
    Thanks
    1,230
    Thanked
    2,291 times in 1,874 posts
    • scaryjim's system
      • Motherboard:
      • Dell Inspiron
      • CPU:
      • Core i5 8250U
      • Memory:
      • 2x 4GB DDR4 2666
      • Storage:
      • 128GB M.2 SSD + 1TB HDD
      • Graphics card(s):
      • Radeon R5 230
      • PSU:
      • Battery/Dell brick
      • Case:
      • Dell Inspiron 5570
      • Operating System:
      • Windows 10
      • Monitor(s):
      • 15" 1080p laptop panel

    Re: Quick Java help

    I assume that shbris has been set this task to demonstrate that use precrement / increment / decrement operators as parts of expressions can produce unexpected results! Either that or he's testing our knowledge for some reason!? So, shbris, do I get the job (I need a new one atm... ).


    As as aside, using 'j = ++j' instead of 'j = j++' will produce the results you might otherwise expect.

  6. #6
    fold fold fold!
    Join Date
    Nov 2008
    Posts
    511
    Thanks
    25
    Thanked
    32 times in 25 posts
    • shbris's system
      • CPU:
      • 1600x
      • Memory:
      • 16GB
      • Storage:
      • various ssd's
      • Graphics card(s):
      • gtx 1060 6gb
      • Case:
      • mini itx
      • Operating System:
      • Windows 10
      • Internet:
      • 100/10

    Re: Quick Java help

    haha thanks all
    was an example question for an interview preparation thingy, my Java is seriously ****ty.
    any recommended books or materials to get up to scratch?

    and scaryjim, i am also between jobs, hence my trying to improve my CV with a few extras and preparations

  7. #7
    Senior Member
    Join Date
    Apr 2006
    Posts
    231
    Thanks
    7
    Thanked
    10 times in 9 posts
    • d032sh's system
      • Motherboard:
      • Asus P5b-e
      • CPU:
      • E4300 @ 3GHz
      • Memory:
      • 4GB OCZ Platinum
      • Storage:
      • ~4TB
      • Graphics card(s):
      • 8800GTS 640MB
      • PSU:
      • Corsair HX620
      • Case:
      • Akasa Eclipse 62
      • Operating System:
      • Win 7

    Re: Quick Java help

    My experience with Java technical interviews is that the same old questions get rolled out over and over again. There are a few web sites with lists of the sort of things that do get asked time and time again (Can you tell me the difference between an abstract class and an interface, between a hashtable and a hashmap etc. etc.). Given the frequency of such questions though it's good to use these as a starting point because chances are you will get asked them at some point.

    On the other hand when I conduct interviews I try very hard to not ask any questions which rely too much on knowledge, obviously I want a developer to have a good grasp of the language but asking questions about arcane classes in the API which you would just look up the 1 time in a million where you actually wanted to use them doesn't really show me that a developer understands the language or is a good problem solver... far more important skills in programming IMO.

  8. Received thanks from:

    scaryjim (08-02-2012)

  9. #8
    Not a good person scaryjim's Avatar
    Join Date
    Jan 2009
    Location
    Gateshead
    Posts
    15,196
    Thanks
    1,230
    Thanked
    2,291 times in 1,874 posts
    • scaryjim's system
      • Motherboard:
      • Dell Inspiron
      • CPU:
      • Core i5 8250U
      • Memory:
      • 2x 4GB DDR4 2666
      • Storage:
      • 128GB M.2 SSD + 1TB HDD
      • Graphics card(s):
      • Radeon R5 230
      • PSU:
      • Battery/Dell brick
      • Case:
      • Dell Inspiron 5570
      • Operating System:
      • Windows 10
      • Monitor(s):
      • 15" 1080p laptop panel

    Re: Quick Java help

    Quote Originally Posted by shbris View Post
    was an example question for an interview preparation thingy
    If I went to a job interview and that was part of their test, I think I'd walk away again! It looks more like an academic question (i.e. it should be followed by "discuss this result"!) or something someone would post to stack overflow for a laugh

    Quote Originally Posted by shbris View Post
    any recommended books or materials to get up to scratch?
    I learned Java at uni, so I've not had any direct experience of learning from books, but I personally tend to gravitate to the SAMS Teach Yourself... series when I want to learn something new. However I don't think a book would help you for the above question, which is frankly just obscure...

    Quote Originally Posted by shbris View Post
    i am also between jobs, hence my trying to improve my CV with a few extras and preparations
    Ah, unlucky. I'm not quite in that position yet, but I'm pretty sure my contract won't get renewed next time it's up (end of March), so I need to get hunting properly. If you're looking to do more coding work and try a variety of languages, you could always try to find someone who'll do code reviews with you - i.e. you write some code to do a particular thing, then sit down with an experienced coder who'll talk you through the good and bad bits of your code. Probably easier to learn that way than try to do it all from books/websites/etc.

  10. #9
    Not a good person scaryjim's Avatar
    Join Date
    Jan 2009
    Location
    Gateshead
    Posts
    15,196
    Thanks
    1,230
    Thanked
    2,291 times in 1,874 posts
    • scaryjim's system
      • Motherboard:
      • Dell Inspiron
      • CPU:
      • Core i5 8250U
      • Memory:
      • 2x 4GB DDR4 2666
      • Storage:
      • 128GB M.2 SSD + 1TB HDD
      • Graphics card(s):
      • Radeon R5 230
      • PSU:
      • Battery/Dell brick
      • Case:
      • Dell Inspiron 5570
      • Operating System:
      • Windows 10
      • Monitor(s):
      • 15" 1080p laptop panel

    Re: Quick Java help

    Quote Originally Posted by d032sh View Post
    On the other hand when I conduct interviews I try very hard to not ask any questions which rely too much on knowledge, obviously I want a developer to have a good grasp of the language but asking questions about arcane classes in the API which you would just look up the 1 time in a million where you actually wanted to use them doesn't really show me that a developer understands the language or is a good problem solver... far more important skills in programming IMO.
    Good to hear there are still some people who know how to recruit - I'd much rather have a good programmer with no knowledge of a specific language / framework than a bad coder with 10 years experience! Last time I was involved in recruitment my boss rejected the only candidate who managed a reasonable job of the interview test, because when he was (without notice!) asked to demonstrate a website he'd worked on recently, wasn't able to because his recent projects were all internal / sensitive.

    I consider my boss very lucky to have not been pulled up on that particular set of interviews... if I'd been a candidate I would've complained bitterly...

  11. #10
    Senior Member
    Join Date
    Apr 2006
    Posts
    231
    Thanks
    7
    Thanked
    10 times in 9 posts
    • d032sh's system
      • Motherboard:
      • Asus P5b-e
      • CPU:
      • E4300 @ 3GHz
      • Memory:
      • 4GB OCZ Platinum
      • Storage:
      • ~4TB
      • Graphics card(s):
      • 8800GTS 640MB
      • PSU:
      • Corsair HX620
      • Case:
      • Akasa Eclipse 62
      • Operating System:
      • Win 7

    Re: Quick Java help

    Quote Originally Posted by scaryjim View Post
    Good to hear there are still some people who know how to recruit - I'd much rather have a good programmer with no knowledge of a specific language / framework than a bad coder with 10 years experience! Last time I was involved in recruitment my boss rejected the only candidate who managed a reasonable job of the interview test, because when he was (without notice!) asked to demonstrate a website he'd worked on recently, wasn't able to because his recent projects were all internal / sensitive.

    I consider my boss very lucky to have not been pulled up on that particular set of interviews... if I'd been a candidate I would've complained bitterly...
    Hiring good people is a tricky business, I'm often amazed at the lack of understanding some people have come in with after seemingly having a good CV. I really would rather train someone bright with no prior programming experience than some of the 'experienced' people I've had in.

    Perhaps it's a good thing your contract is up, I'm not sure I could cope with your boss!

  12. #11
    Not a good person scaryjim's Avatar
    Join Date
    Jan 2009
    Location
    Gateshead
    Posts
    15,196
    Thanks
    1,230
    Thanked
    2,291 times in 1,874 posts
    • scaryjim's system
      • Motherboard:
      • Dell Inspiron
      • CPU:
      • Core i5 8250U
      • Memory:
      • 2x 4GB DDR4 2666
      • Storage:
      • 128GB M.2 SSD + 1TB HDD
      • Graphics card(s):
      • Radeon R5 230
      • PSU:
      • Battery/Dell brick
      • Case:
      • Dell Inspiron 5570
      • Operating System:
      • Windows 10
      • Monitor(s):
      • 15" 1080p laptop panel

    Re: Quick Java help

    Quote Originally Posted by d032sh View Post
    ... I'm not sure I could cope with your boss!
    When I was still in school a friend observed that I must have the patience of a saint to cope with my then-girlfriend. Apparently it's a trait I have maintained over the years - although my patienced has finally worn out with this one and I'm definitely moving on in April, come what may...

  13. #12
    Seething Cauldron of Hatred TheAnimus's Avatar
    Join Date
    Aug 2005
    Posts
    17,164
    Thanks
    803
    Thanked
    2,152 times in 1,408 posts

    Re: Quick Java help

    Quote Originally Posted by scaryjim View Post
    If I went to a job interview and that was part of their test, I think I'd walk away again! It looks more like an academic question (i.e. it should be followed by "discuss this result"!) or something someone would post to stack overflow for a laugh
    The only correct answer at that point is surely along the lines of:

    "You let someone write something like that during a code review?"

    Whenever looking at these things, remember these things get executed in a linear fashion, no matter how high level we make the language.

    I also often use brackets, it helps me think how it gets broken down like so

    i = (i++);

    makes in my head it quite clear that i++ is evaluated. The result of that evaluation is then assigned to i.

    as i++ unlike ++i, returns the ORIGINAL result, it doesn't matter that I is temporarily incremented, its going to get the old value put in there.

    Too many people at interview try to show how clever they are with puzzles and the like. Its pathetic. Myself I normally ask people a series of questions, go on a journey of the technology, I normally want to here what they think is bad, what they don't like. Programming doesn't have a series of right awnsers, its why most good pratice guides are a collection of don'ts, those that are a collection of do's normally find themselves out moded quite quickly.

    That's not to say thou I won't show them an example of the oldie "access to modified closure" in Resharper lingo or similar, but I don't ever give paper tests. Quite a few brilliant devs I know would be thrown by not having the code formatted the way their IDEs settings have it.

    A grade people hire A grade people, B grade hire C, C grade people put coding tests in interviews. A grade people know from 5 minutes of just talking.
    throw new ArgumentException (String, String, Exception)

  14. #13
    Not a good person scaryjim's Avatar
    Join Date
    Jan 2009
    Location
    Gateshead
    Posts
    15,196
    Thanks
    1,230
    Thanked
    2,291 times in 1,874 posts
    • scaryjim's system
      • Motherboard:
      • Dell Inspiron
      • CPU:
      • Core i5 8250U
      • Memory:
      • 2x 4GB DDR4 2666
      • Storage:
      • 128GB M.2 SSD + 1TB HDD
      • Graphics card(s):
      • Radeon R5 230
      • PSU:
      • Battery/Dell brick
      • Case:
      • Dell Inspiron 5570
      • Operating System:
      • Windows 10
      • Monitor(s):
      • 15" 1080p laptop panel

    Re: Quick Java help

    Interesting thoughts TA. I wrote a technical test for the last set of interviews at our place, but it was "here's some HTML / js / CSS, find the mistakes and explain which bits don't meet web standards" followed by "outline a script to process the response to the form, use any language you like or pseudocode".

    The point with a test like that, though, is not to test coding ability, but to see if they can a) spot obvious mistakes in the languages they'll use frequently (i.e. they'll be able to debug code quickly), b) to see if they can logically follow a process like putting form data into a db and if they understand handling publicly entered data (pretty important in a web dev environment ) and most importantly c) to see how well they manage their time. Only one candidate even started the second half of the test in the allotted time.

    Personally, I'd be very suspicious of an interview for a programming job that *doesn't* include some form of technical test, whether that's a sit down writing test or some technical questions in the interview. An interview is meant to test my ability to do a job, and if that job is programming there's only so much you can learn from asking questions face to face...

  15. #14
    Seething Cauldron of Hatred TheAnimus's Avatar
    Join Date
    Aug 2005
    Posts
    17,164
    Thanks
    803
    Thanked
    2,152 times in 1,408 posts

    Re: Quick Java help

    Quote Originally Posted by scaryjim View Post
    Personally, I'd be very suspicious of an interview for a programming job that *doesn't* include some form of technical test, whether that's a sit down writing test or some technical questions in the interview. An interview is meant to test my ability to do a job, and if that job is programming there's only so much you can learn from asking questions face to face...
    Why my achievements before speak for themselves, the test would be an expensive use of my time.

    Also why is that? Because I've spent DAYS, and I mean DAYS configuring Visual Studio, Resharper, nDepends, Snoop custom build, etc. You want me to run without any of that?

    Or worse yet you want me to read code, on paper. Really? How the hell do I shift+ctrl+alt F7?

    Or am I not meant to be dependent on those things?

    The other thing is most programmers haven't had the same experiances, the same things you'd expect them to have learnt from, if someone has spent a while on middle tier high performance stuff I'll want them to talk about lock less structures, pros and cons, in the .Net platform if they failed to mention that the ReaderWriterLock is bugged, and you should use the ReaderWriterLockSlim always instead (or Richters say) they would fail. Any idiot can write some code. Tbh any idiot can solve these simple puzzels like the one above. Or like the one discussed in this blog I was reading a moment ago:
    http://blog.jetbrains.com/kotlin/201...java/#more-247

    I'll do coding tests, but only if the problem is interesting. If someone asks me to do something on say updating numbers like a real time FX view in WPF, I'll be talking to them the whole time about issues such as Dprops vs INotifyProperty changed, virtualising issues. The code I'd write would merely show I'm able to cobble something together in 30 mins that puts numbers on a screen. Not that I'd make something scalable, performant with thought spent on such decisions. (Also there is no 'right' awnser for that example with propdp vs reflection!).
    throw new ArgumentException (String, String, Exception)

  16. #15
    Member
    Join Date
    Jan 2010
    Location
    Luton
    Posts
    195
    Thanks
    30
    Thanked
    21 times in 18 posts
    • The_Wheelhouse's system
      • Motherboard:
      • Gigabyte GA-X58A-UD3R
      • CPU:
      • Intel i7 930
      • Memory:
      • 6GB
      • Storage:
      • 1TB F3
      • Graphics card(s):
      • XFX Radeon HD 5830
      • PSU:
      • XFX 650W XXX Edition
      • Case:
      • Haf 922
      • Operating System:
      • Windows 7 Home Premium 64bit
      • Monitor(s):
      • 21.5" Dell
      • Internet:
      • Virgin

    Re: Quick Java help

    Quote Originally Posted by shbris View Post
    any recommended books or materials to get up to scratch?
    This might help http://www.cl.cam.ac.uk/teaching/111...materials.html

    Join the HEXUS Folding@home Team!!

  17. #16
    p5-
    p5- is offline
    Member
    Join Date
    Jul 2003
    Location
    London, UK
    Posts
    101
    Thanks
    1
    Thanked
    5 times in 5 posts

    Re: Quick Java help

    Really interesting stuff in this thread. I've been a developer for only 3 1/2 years now. It's only taken that amount of experience to realise some of the things that have been already said here.

    Have to admit that I'd have my suspicions about having a test like that in an interview. The danger for me would be the uncertainty of the reliance on the test for the job. Perhaps the test itself reflects the level of creativity in the work involved. Unfortunately it may be one of those cases where you need to take the job to find out Purely from the perspective of having to work in a job where the manager believes in a bias on knowledge is important enough to test for it, assuming the manager knows what they're doing of course . Echos what TheAnimus said!

Thread Information

Users Browsing this Thread

There are currently 1 users browsing this thread. (0 members and 1 guests)

Posting Permissions

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