Win a copy of Transfer Learning for Natural Language Processing (MEAP) this week in the Artificial Intelligence and Machine Learning forum!
  • 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 all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Tim Cooke
  • Paul Clapham
  • Devaka Cooray
  • Bear Bibeault
Sheriffs:
  • Junilu Lacar
  • Knute Snortum
  • Liutauras Vilda
Saloon Keepers:
  • Ron McLeod
  • Stephan van Hulst
  • Tim Moores
  • Tim Holloway
  • Piet Souris
Bartenders:
  • salvin francis
  • Carey Brown
  • Frits Walraven

Programmer jobs - Is this joke funny ?

 
Ranch Foreman
Posts: 141
5
IntelliJ IDE Eclipse IDE Java
  • Mark post as helpful
  • send pies
  • 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: 7602
521
Mac OS X VI Editor BSD Linux
  • Mark post as helpful
  • send pies
  • 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: 3504
37
  • Likes 2
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Well, let's not confuse inadvisable with impossible...

 
Liutauras Vilda
Sheriff
Posts: 7602
521
Mac OS X VI Editor BSD Linux
  • Mark post as helpful
  • send pies
  • 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: 7602
521
Mac OS X VI Editor BSD Linux
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
That bit still giving you a headache:


But I'm keen to see a final version.
 
Bartender
Posts: 2550
120
Google Web Toolkit Eclipse IDE Java
  • Mark post as helpful
  • send pies
  • 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: 7602
521
Mac OS X VI Editor BSD Linux
  • Mark post as helpful
  • send pies
  • 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: 142
7
  • Likes 1
  • Mark post as helpful
  • send pies
  • 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: 68909
275
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I won a bottle of wine once for reversing a palindrome.
 
Saloon Keeper
Posts: 11882
253
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Amateurs. I once reversed a palindrome in my sleep.
 
Mike Simmons
Rancher
Posts: 3504
37
  • Likes 1
  • Mark post as helpful
  • send pies
  • 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: 7602
521
Mac OS X VI Editor BSD Linux
  • Mark post as helpful
  • send pies
  • 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: 3504
37
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Here's a version that includes 1.8:
 
Liutauras Vilda
Sheriff
Posts: 7602
521
Mac OS X VI Editor BSD Linux
  • Mark post as helpful
  • send pies
  • 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: 7602
521
Mac OS X VI Editor BSD Linux
  • Mark post as helpful
  • send pies
  • 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: 3504
37
  • Mark post as helpful
  • send pies
  • 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: 3504
37
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Actually, there's a simpler and more powerful version:
 
Saloon Keeper
Posts: 21966
149
Android Eclipse IDE Tomcat Server Redhat Java Linux
  • Mark post as helpful
  • send pies
  • 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.
 
I don't like that guy. The tiny ad agrees with me.
Two software engineers solve most of the world's problems in one K&R sized book
https://coderanch.com/wiki/718759/books/Building-World-Backyard-Paul-Wheaton
    Bookmark Topic Watch Topic
  • New Topic