You must have encountered the WAT! meme somewhere on the web. The idea is simple - you present some aspect of a language to a group of programmers, demonstrate how stupid it is on the basis of what it does, and finish off with a WAT!
And a big laugh.
String cost = UI.getCost();
First off you have had a small laugh at the use of String and Int. But your audience now falls about laughing when you show the error message that results from trying to compute the tax. WAT! you have to convert the user input from "100" to 100 how stupid is that! After that you can all have a really good laugh when it is revealed that, even after converting the String to an Integer:
float tax = Integer.parseInt(cost)*0.1;
it still doesn't work! Yes Java has two types of floating point data and 0.1 is a double, not a float!
You can continue in this way making Java or any other class-based, strongly-typed language seem broken in hilarious ways. For example functions that return "void" - what's a void, is it an object, can you smoke it?
Then you can put together an example where a function needs to be passed to another function - only to discover that it can't be done. WAT! functions can't be defined outside of an object... you can't pass a function argument! Java is only just getting round to adding lambda expressions?! And so on...
The point is that this is more a clash of cultures than a proof that anyone's language is laughable.
And please don''t try telling me why Java does things in the way that it does - this isn't about the merits, or otherwise, of strong typing, class-based objects or functions as second class citizens. This is about how any language can seem extreme in its approach if you don't share the understanding and motivation of the language. I don't really think that any of the WAT! examples of Java are funny and I don't think the approach is unreasonable, but I do want you to try and imagine that this isn't the only possible way and programmers from other persuasions could, and do, find Java's approach less than natural and far from logical.
Strong typing isn't the only way to do things, neither is a class-based type hierarchy the only approach to objects. It is important that we find out about different ways of organizing what we do, and if things seem strange and even silly - remember they might be just different.
To be informed about new articles on I Programmer, install the I Programmer Toolbar, subscribe to the RSS feed, follow us on, Twitter, Facebook, Google+ or Linkedin, or sign up for our weekly newsletter.