<?xml version="1.0" encoding="UTF-8"?><rss version="2.0"
	xmlns:content="http://purl.org/rss/1.0/modules/content/"
	xmlns:wfw="http://wellformedweb.org/CommentAPI/"
	xmlns:dc="http://purl.org/dc/elements/1.1/"
	xmlns:atom="http://www.w3.org/2005/Atom"
	xmlns:sy="http://purl.org/rss/1.0/modules/syndication/"
	xmlns:slash="http://purl.org/rss/1.0/modules/slash/"
	xmlns:creativeCommons="http://backend.userland.com/creativeCommonsRssModule"
>

<channel>
	<title>heap | Psyops Prime</title>
	<atom:link href="https://psyopsprime.com/tag/heap/feed/" rel="self" type="application/rss+xml" />
	<link>https://psyopsprime.com</link>
	<description>An Idea Log</description>
	<lastBuildDate>Thu, 23 Mar 2017 15:58:39 +0000</lastBuildDate>
	<language>en-US</language>
	<sy:updatePeriod>
	hourly	</sy:updatePeriod>
	<sy:updateFrequency>
	1	</sy:updateFrequency>
	<generator>https://wordpress.org/?v=7.0</generator>
	<creativeCommons:license>https://creativecommons.org/licenses/by-nc-nd/4.0/</creativeCommons:license>
<site xmlns="com-wordpress:feed-additions:1">99640787</site>	<item>
		<title>Software Engineering Journey: On The Heap</title>
		<link>https://psyopsprime.com/education/software-engineering-journey-on-the-heap/?utm_source=rss&#038;utm_medium=rss&#038;utm_campaign=software-engineering-journey-on-the-heap</link>
					<comments>https://psyopsprime.com/education/software-engineering-journey-on-the-heap/#respond</comments>
		
		<dc:creator><![CDATA[admin]]></dc:creator>
		<pubDate>Tue, 07 Mar 2017 11:28:44 +0000</pubDate>
				<category><![CDATA[Education]]></category>
		<category><![CDATA[Reviews]]></category>
		<category><![CDATA[Technology]]></category>
		<category><![CDATA[Dynamic memory allocation]]></category>
		<category><![CDATA[heap]]></category>
		<category><![CDATA[object-oriented programming]]></category>
		<category><![CDATA[Stack]]></category>
		<guid isPermaLink="false">http://psyopsprime.com/?p=1505</guid>

					<description><![CDATA[<p>Conceiving ideas has never been a big deal. Especially in our times, with the advent of computers and the things that have been made possible</p>
The post <a href="https://psyopsprime.com/education/software-engineering-journey-on-the-heap/">Software Engineering Journey: On The Heap</a> first appeared on <a href="https://psyopsprime.com">Psyops Prime</a>.]]></description>
										<content:encoded><![CDATA[<p style="text-align: justify;">Conceiving ideas has never been a big deal. Especially in our times, with the advent of computers and the things that have been made possible with them, thinking about novel ideas has become commonplace. Moreover, we have valuable tools for thinking about ideas and their materialization.  Nowadays we can develop for any idea</p>
<p style="text-align: justify;">Think about a problem that you have conceived an idea about and you want to develop a real product out of it. Object oriented paradigm provides us with a great set of thinking tools about how to implement ideas. According to this, you have to figure out the objects which make up your desired product or artifact to make your problem modular. You then get ways and techniques to develop an object-oriented design. Once you have done that, you have to implement that design into working software. The thing I am chanting the most these days is to highlight a roadmap from the conception of ideas to their object-oriented design and finally to working software. In this vein, the thing the idea I really like to shout about is to divide your implementation phase into two parts. The first is to derive skeleton code from the design. Once that&#8217;s done, the only thing remains is to implement the methods of objects. If that is done right, what you get is working software for the project you dreamed, provided that you also designed it well. The design is important than anything else, as everything depends on that.</p>
<p style="text-align: justify;">There are other important things too. You have to gather requirements well. You have to conduct all sorts of tests. You have to prepare documentation. And implementing methods nicely and accurately is also required.</p>
<p style="text-align: justify;">Implementation can be mind boggling if we don&#8217;t get a few things right in our heads. And this series of articles, that I am presenting as a journey through the labyrinth of Software engineering issues, is in its essence a reflection on issues pertaining to implementation.</p>
<p style="text-align: justify;">In my previous article, I reasoned about the fact that all <a href="http://psyopsprime.com/education/software-engineering-journey-implementing-methods/" target="_blank">dynamic memory allocation</a> is done on the heap. It would also be nice to know that all user-defined objects are normally allocated memory dynamically. If you read my last post, there are two things about object instantiation that must be understood. One is to instantiate the object itself, which is given a place to reside on the heap. The other is to assign the address of that object to a variable of the same type, that resides on the stack.</p>
<p style="text-align: justify;">But what about an object lies on the heap? This is an important question, the answer of which should be understood. And if understood properly, this will make you an astute programmer. You may as well become a speed-programmer and go out to win so many programming championships.</p>
<p style="text-align: justify;">In order to understand the answer to this question, we need to understand a few things about classes and objects. Well, but we all know a few things about classes and objects, don&#8217;t we? A class has a few fields and a bunch of methods. The fields determine the state the class is in at any moment in time. The methods influence the behavior of the class. This is the basic common knowledge that we acquire in the first chapter of almost every well-written text on object-oriented programming.</p>
<p style="text-align: justify;">However, we don&#8217;t learn a few simple things readily due to one reason or the other. And our programming acumen suffers badly due to this lack of understanding. One among them is the question about object instantiation. How are objects instantiated? If you understand the answer to this question, you will develop a lot of clarity as a programmer.</p>
<p style="text-align: justify;">So when we do something like &#8216;Data data= new Data();&#8217;, what really happens? I reflected on a few issues in my last post. You must read that first and continue from here. So in a statement like above, the runtime environment of Java (remember I said that I am talking about everything from the vantage point of Java) creates a new object of type Data using the class Data. What do I mean by that?</p>
<p style="text-align: justify;">What that really means is that when we run a program that is creating an object of type &#8216;Data&#8217;, the program loads the bytecode of the class into the memory. That bytecode is present in a Data.class file that you created while creating Data.java. The region of memory where the program is exactly loaded is called method area. It has all the compiled code of all the classes.</p>
<p style="text-align: justify;">The moment you create an object dynamically, it is created on the heap. For all of its fields&#8217;, their values are stored in the respective blocks on the heap. All of the field names, method names and their bodies are still located in the method area. I want to emphasize here that the heap only contains values for the fields. These values can be changed by changed or accessed by having a reference to this object and the field names, which are present in the method area. When you try to access a method of this object, it is loaded from the method area to an appropriate place on the stack. From there it starts executing.</p>
<p style="text-align: justify;">You already know the rest of the stuff about execution. Especially, since you have been reading the previous article on how dynamic memory works, nothing should be a big deal for you.</p>
<p><small><a style="text-decoration: none;" title="Image inserted by the ImageInject WordPress plugin" href="http://wpinject.com/" rel="nofollow">Photo</a> by <a href="http://www.flickr.com/photos/68023315@N00/16912811263" target="_blank">Polyrus</a> <a title="Attribution-NoDerivs License" href="http://creativecommons.org/licenses/by-nd/2.0/" target="_blank" rel="nofollow"><img data-recalc-dims="1" decoding="async" src="https://i0.wp.com/psyopsprime.com/wp-content/plugins/wp-inject/images/cc.png?w=750" /></a></small></p>The post <a href="https://psyopsprime.com/education/software-engineering-journey-on-the-heap/">Software Engineering Journey: On The Heap</a> first appeared on <a href="https://psyopsprime.com">Psyops Prime</a>.]]></content:encoded>
					
					<wfw:commentRss>https://psyopsprime.com/education/software-engineering-journey-on-the-heap/feed/</wfw:commentRss>
			<slash:comments>0</slash:comments>
		
		
				<creativeCommons:license>https://creativecommons.org/licenses/by-nc-nd/4.0/</creativeCommons:license>
<post-id xmlns="com-wordpress:feed-additions:1">1505</post-id>	</item>
		<item>
		<title>Software Engineering Journey: Implementing Methods</title>
		<link>https://psyopsprime.com/education/software-engineering-journey-implementing-methods/?utm_source=rss&#038;utm_medium=rss&#038;utm_campaign=software-engineering-journey-implementing-methods</link>
					<comments>https://psyopsprime.com/education/software-engineering-journey-implementing-methods/#respond</comments>
		
		<dc:creator><![CDATA[admin]]></dc:creator>
		<pubDate>Mon, 06 Mar 2017 10:14:17 +0000</pubDate>
				<category><![CDATA[Education]]></category>
		<category><![CDATA[Technology]]></category>
		<category><![CDATA[Dynamic memory allocation]]></category>
		<category><![CDATA[heap]]></category>
		<category><![CDATA[Java]]></category>
		<category><![CDATA[object-oriented programming]]></category>
		<category><![CDATA[software engineering]]></category>
		<guid isPermaLink="false">http://psyopsprime.com/?p=1501</guid>

					<description><![CDATA[<p>I reflected on how object-oriented design can be translated to skeleton code in my previous post. I concluded my discourse with the idea that once</p>
The post <a href="https://psyopsprime.com/education/software-engineering-journey-implementing-methods/">Software Engineering Journey: Implementing Methods</a> first appeared on <a href="https://psyopsprime.com">Psyops Prime</a>.]]></description>
										<content:encoded><![CDATA[<p style="text-align: justify;">I reflected on how <a href="http://psyopsprime.com/education/from-design-to-skeleton-code/" target="_blank">object-oriented design can be translated to skeleton code</a> in my previous post. I concluded my discourse with the idea that once skeleton code is generated, the only problem we are left with is to provide implementations of the bodies of the various methods of classes in the code. In this article, I shall be writing about this. My particular vantage point is to speak in terms of Java.</p>
<p style="text-align: justify;">The first thing that we need to understand is that how methods receive and return inputs and outputs (IO). This is very important. The working of a method can be broadly divided into two types of tasks. One is to handle IO. The other is to manipulate inputs to generate outputs. This article particularly reflects on the first part i.e. how a method deals with IO.</p>
<p style="text-align: justify;">To understand this, it will be very nice to remind ourselves that in Java all arguments to a method are passed by value. What this literally means is that if we have a variable &#8216;x&#8217; to which we have assigned a value of &#8216;6&#8217;, and if we pass this variable as an input argument to some method (e.g. insertX(x)), then its value (6) is passed to the method call insertX(x);.</p>
<p style="text-align: justify;">This is true about all sorts of method calls in Java, and all sorts of data types including primitive and abstract. But we need to understand a few more things about abstract or user-defined data types.</p>
<p style="text-align: justify;">Consider the following variable declaration in Java:</p>
<p style="text-align: justify;">int x=5;</p>
<p style="text-align: justify;">The above declaration creates a variable of type int and assigns it a value of 5. x goes on the stack.</p>
<p style="text-align: justify;">Now consider the following variable declaration:</p>
<p style="text-align: justify;">MyDataType data;</p>
<p style="text-align: justify;">The above declaration creates a variable of type MyDataType, which is essentially a user-defined data type. What is &#8216;data&#8217;? Well, data is a variable. Where is it located? It is located on the stack. What is its value? It hasn&#8217;t been assigned any value yet. How to assign a value to it? Following is the procedure for that.</p>
<p style="text-align: justify;">data= new MyDataType();</p>
<p style="text-align: justify;">What we have done above essentially is that we have created an object of type MyDataType (on the right-hand side of the expression). This object is allocated memory on heap since this is dynamic memory allocation (all dynamic memory allocation is done on the heap). The object does not have any name as such. However, it does have an address. And its address gets assigned to &#8216;data&#8217; (left-hand side of the expression).</p>
<p style="text-align: justify;">So the value of &#8216;data&#8217; now is the address of the newly created object of type MyDataType.</p>
<p style="text-align: justify;">Now, consider a method that accepts an object of type &#8216;MyDataType&#8217;. Let us consider the following method, for instance.</p>
<p style="text-align: justify;">public class Example{<br />
//<br />
//</p>
<p style="text-align: justify;">public MyDataType insertData(MyDataType data){<br />
//<br />
//<br />
return data;<br />
}<br />
}</p>
<p style="text-align: justify;">The method &#8216;insertData&#8217; accepts an argument of type &#8216;MyDataType&#8217;. It also returns an argument of type MyDataType.</p>
<p style="text-align: justify;">Now consider the following method call.</p>
<p style="text-align: justify;">MyDataType data2=insertData(data);</p>
<p style="text-align: justify;">where data is the variable mentioned and explained two paras above. Since Java is pass-by-value,  when we pass &#8216;data&#8217; to &#8216;insertData()&#8217;, essentially we are passing the value of &#8216;data&#8217; to the latter. But what is the value of &#8216;data&#8217;? Its value is the address of the object of type &#8216;MyDataType&#8217;, to which it is referring.</p>
<p style="text-align: justify;">So the crux of the story is that when you are passing arguments of user-defined data types to Java methods, you are not passing the objects as such. In stead of this, you are actually always passing references to those objects. The actual objects keep on lying on the heap. Their references, that are stored in variables of the same type that are on stack get passed to methods. Same is true about return values. Objects are never returned. Instead, their references are returned. Through the references, objects can be manipulated as they keep lying on the heap.</p>
<p style="text-align: justify;">This idea and its understanding can have a profound impact on your programming skills. Once you have developed skeleton code, the next thing you have to deal with is IO in methods. Once this is understood, rest of the stuff becomes easier to comprehend and implement.</p>
<p><small><a style="text-decoration: none;" title="Image inserted by the ImageInject WordPress plugin" href="http://wpinject.com/" rel="nofollow">Photo</a> by <a href="http://www.flickr.com/photos/11831132@N00/1570570246" target="_blank">Plutor</a> <a title="Attribution License" href="http://creativecommons.org/licenses/by/2.0/" target="_blank" rel="nofollow"><img data-recalc-dims="1" decoding="async" src="https://i0.wp.com/psyopsprime.com/wp-content/plugins/wp-inject/images/cc.png?w=750" /></a></small></p>The post <a href="https://psyopsprime.com/education/software-engineering-journey-implementing-methods/">Software Engineering Journey: Implementing Methods</a> first appeared on <a href="https://psyopsprime.com">Psyops Prime</a>.]]></content:encoded>
					
					<wfw:commentRss>https://psyopsprime.com/education/software-engineering-journey-implementing-methods/feed/</wfw:commentRss>
			<slash:comments>0</slash:comments>
		
		
				<creativeCommons:license>https://creativecommons.org/licenses/by-nc-nd/4.0/</creativeCommons:license>
<post-id xmlns="com-wordpress:feed-additions:1">1501</post-id>	</item>
	</channel>
</rss>
