Understanding Sass Basics With Practical Examples

Sass stands for Syntactically Awesome Stylesheets. It is a CSS pre-processor that makes it easier to work with CSS, reduce repetition, and save time. This will help to style your pages easily with…

Smartphone

独家优惠奖金 100% 高达 1 BTC + 180 免费旋转




Our Devoxx Java Puzzler

We tried this out on some developers before the event, and they found it challenging. And from the conversations we had at Devoxx, developers there also found it challenging. While at the booth I grabbed Mark Reinhold, Chief Architect of the Java Platform (here with me using our photobooth at Devoxx with a nice fishing marina he selected as our background), and it took him a few minutes to get a valid (and indeed the simplest) solution — mainly because he was thinking of esoteric answers before he finally said “oh, it’s trivial!”

Mark Reinhold, Chief Architect of the Java Platform on the right, with Java Champion Jack Shirazi

The simplest answer we were expecting was to define your own class called System in the same package as the PrintGoodbye class, and include that in the classpath eg

Yes, as simple as that. When I pointed this out to most developers, I could see them metaphorically facepalm themselves.

We had many suggestions of using very esoteric options like editing the compiled bytecode to replace the string “hello” with “goodbye” or redefine the Unicode charset to have “hello” come out as “goodbye” and point the JVM at those. I don’t know if these would work, but no one provided a workable set of instructions to try them out so there weren’t any of those entries for me to test.

We also had people suggesting defining a String class in the same package as the PrintGoodbye class, and this seems like it should work similarly to the System class definition above. But it doesn’t. Because the Java language specification requires the JVM entrypoint to be a quite specific signature:

and if you create your own String class in the expedia.puzzler package, the PrintGoodbye class uses that String class instead in the main() method including for the parameter. That changes the main() signature and consequently that main() is no longer recognized by the JVM as a valid entrypoint for the program. It does compile, but if you try to run that solution you would get an error “Error: Main method not found …”. So it’s an incorrect answer.

We also had several solutions redefining the line.separator -Dline.separator=”\b\b\b\b\b\bgoodbye\n”. I thought that was quite clever. But sadly it didn’t work. I ran it and the output was “hello\b\b\b\b\b\bgoodbye\n”. It might have worked on some system command lines, but I tried all solutions in a Linux shell and a Windows command prompt, and it didn’t work on either for me.

Finally we had technically correct solutions that you might not consider useful, but they did work when I tested them so we considered them correct and entered them in the prize draw. These were three types:

which did actually work on both my test shells (the “hello” is just dumped by the echo command; both the pipe and the echo command work on both Windows and Unix. A similar solution using a redirect instead of pipe didn’t work because /dev/null doesn’t work on Windows).

It was fun creating the puzzler, fun discussing it with the developers at Devoxx and fun looking at the solutions suggested. All in all, a fun experience.

Add a comment

Related posts:

La rete ai tempi del Coronavirus

La pandemia da Covid-19 ha portato a fissare delle norme sulla circolazione. Fino a qualche settimana fa, gli spostamenti erano solo permessi in caso di emergenza, per ragioni lavorative, di salute e…

You Cannot Live an Unconventional Life with Conventional Thinking

Conventional wisdom is generally accepted as what’s “right” and what should be followed if you want to live a good life. Think of anything and there’s probably a list of preconceived conventional…

O mundo mudou

A guerra e o seu final anunciavam relações mais livres com o sexo, era cada vez mais visível uma disponibilidade maior do mercado em absorver as mulheres, e já se falava, entre paredes, da presença…