• Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other Pie Elite all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Paul Clapham
  • Ron McLeod
  • paul wheaton
  • Devaka Cooray
Sheriffs:
  • Jeanne Boyarsky
  • Tim Cooke
  • Liutauras Vilda
Saloon Keepers:
  • Tim Moores
  • Tim Holloway
  • Stephan van Hulst
  • Carey Brown
  • Piet Souris
Bartenders:
  • salvin francis
  • Mikalai Zaikin
  • Himai Minh

Programmer jobs - Is this joke funny ?

 
Ranch Hand
Posts: 143
6
IntelliJ IDE Eclipse IDE Java
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
After getting a computer programming job, a guys asks "When are we going to get tickets/features for reversing strings, finding palindromes etc. " ?

PS - Many job interviews ask interviewees to solve such programming exercises, even though the job will actually be somewhat "simple" and won't involve developing new data structures or algorithms.
 
Sheriff
Posts: 7959
560
Mac OS X VI Editor BSD Linux
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
But if you can manage to reverse string, then you can do almost anything

Perhaps only 2% would say that's impossible. You can easily hire those
 
Rancher
Posts: 3851
50
  • Likes 2
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Well, let's not confuse inadvisable with impossible...

 
Liutauras Vilda
Sheriff
Posts: 7959
560
Mac OS X VI Editor BSD Linux
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator

Mike Simmons wrote:Well, let's not confuse inadvisable with impossible...


That at least should count as almost impossible

line 17 wrote:Exception in thread "main" java.lang.ClassCastException: [C cannot be cast to [B


And execution stops at this point. javac 1.8.0_231
 
Liutauras Vilda
Sheriff
Posts: 7959
560
Mac OS X VI Editor BSD Linux
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
That bit still giving you a headache:


But I'm keen to see a final version.
 
Bartender
Posts: 2854
150
Google Web Toolkit Eclipse IDE Java
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator

Liutauras Vilda wrote:...

line 17 wrote:Exception in thread "main" java.lang.ClassCastException: [C cannot be cast to [B

...


Use char[] instead of byte[] and it will work for you.
 
Liutauras Vilda
Sheriff
Posts: 7959
560
Mac OS X VI Editor BSD Linux
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator

salvin francis wrote:

Liutauras Vilda wrote:...

line 17 wrote:Exception in thread "main" java.lang.ClassCastException: [C cannot be cast to [B

...


Use char[] instead of byte[] and it will work for you.


Tried before you posted. It does, but does not not reverse.
 
Rancher
Posts: 184
7
Mac OS X IntelliJ IDE
  • Likes 1
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator

Liutauras Vilda wrote:But if you can manage to reverse string, then you can do almost anything



I can reverse a palindrome if I try really hard. Still, no job offers.
 
Marshal
Posts: 72686
317
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
I won a bottle of wine once for reversing a palindrome.
 
Saloon Keeper
Posts: 12914
281
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Amateurs. I once reversed a palindrome in my sleep.
 
Mike Simmons
Rancher
Posts: 3851
50
  • Likes 1
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Interesting.  My code works fine on Java 11 and 14 - I hadn't tried it on 8.  Guess they changed the internal implementation there.  And my hamfisted System.err.close() didn't help. . I'll see if I can post a more general version in a bit...

I did see that my posted code had an extra } at the end, which I have removed.  Other than that, it works fine on Java 11 and 14.
 
Liutauras Vilda
Sheriff
Posts: 7959
560
Mac OS X VI Editor BSD Linux
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator

Mike Simmons wrote:Well, let's not confuse inadvisable with impossible...


I think none of us have doubts about Mike's knowledge, especially me. But I got hooked on the code he showed. Actually couldn't even sleep well.

I know it didn't work on my machine, but, is that something JDK related or it doesn't work. I know we say Strings are immutable, and I know what kind of beast the reflection is, I also know it is better not to touch it, but still, just gotta know now, is it possible to mutate string?
Staff note (Liutauras Vilda) :

Mike, I didn't see your latest post when I posted this.

 
Mike Simmons
Rancher
Posts: 3851
50
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Here's a version that includes 1.8:
 
Liutauras Vilda
Sheriff
Posts: 7959
560
Mac OS X VI Editor BSD Linux
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
My hat is down.

Interesting though
on my own mechine producees reversed: javac 1.8.0_231
on my other machine procuces non reversed: javac 1.8.0_202
 
Liutauras Vilda
Sheriff
Posts: 7959
560
Mac OS X VI Editor BSD Linux
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Agh, got it!

When I change print statements to:

Then it does stop working. I know now, that I don't know Java
 
Mike Simmons
Rancher
Posts: 3851
50
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Comment out the System.err.close() - that was only there to disable a warning on Java 11+.  But it seriously gets in the way of error messages if something else goes wrong.
 
Mike Simmons
Rancher
Posts: 3851
50
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Actually, there's a simpler and more powerful version:
 
Saloon Keeper
Posts: 23552
161
Android Eclipse IDE Tomcat Server Redhat Java Linux
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
There's a whole lot more reversing going on than are dreamt of in your philosophy, Horatio.

Thanks. to Intel's dominance and in turn their lifting a page from DEC architecture, PCs were saddled with a bytewise-discontinuous order of storage for integral numbers in RAM (a/k/a "Little Endian"), which lead to the need for an operation known as "swabbing". Because if you wanted to talk to IBM's mainline products - and a great many other systems - you had to reverse the bytes.

Another common use for reversing byte ordering is in serialization/deserialization, and in particular in things like network communications.

A palindromic form might be used for an error-checking scheme.

So neither of those scenarios is all that unrealistic for a display of competence.
 
Consider Paul's rocket mass heater.
reply
    Bookmark Topic Watch Topic
  • New Topic