Posts

Showing posts from March, 2016

Potter Metaphor.

Image
Any Computer Language can be defined in terms of its Vocabulary and it's Grammar. A Language's grammar specifies the rules of composition of its fundamental elements. When you start learning a language most of the introductory material focuses on the vocabulary and the grammar. When you achieve a satisfactory level of proficiency in the vocabulary and the grammar, you feel that you know the language. As you are aware that in languages like English, knowing vocabulary and grammar doesn't guarantee your ability to write an essay or a poem. Similarly knowing vocabulary and grammar of a computer programming language doesn't guarantee your ability to develop software in it. You have to master several other skills before you start developing a software. To clarify this to a new programmer, I use a metaphor called Potter Metaphor.  A Potter starts with raw materials like mud, water, colours etc and with the use of his wheel creates pots. A potter who claims that he is a potter …

Why Java Objects only on Heap?

Image
Background
Last month I had asked a Java related question to all my students on a facebook post.
Why is it that in Java, Objects are always to be allocated on heap? Why is dynamic allocation the only option in the toolbox of a Java developer while creating objects?
It was a very interesting discussion on facebook. Many participants, my students and otherwise gave good arguments in defense of the Java Language Design. One of the arguments that came out shining, was that of the possibility of unsafe allocations on Stack Frame. Special thanks to Ted Lum, Chetan Parmar, Nishant Verma, Vaibhav Desai, Tusharkumar Thomar, Vimal Sakhiya, Clair Roma Henry, Subham Gadi, Makarand Bhosle, Prasad Kowli and Nirav Kothari for their participation and valuable arguments.Let me now, put forward my perception on why Java Language Designers would have taken such a decision.
The following content in this article assumes that the reader is aware of memory models and life cycles of various types of variables i…