<?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/"
	>

<channel>
	<title>TechieDrill &#187; method</title>
	<atom:link href="http://techiedrill.com/tag/method/feed/" rel="self" type="application/rss+xml" />
	<link>http://techiedrill.com</link>
	<description>Your World Of Technical Tutorials</description>
	<lastBuildDate>Tue, 10 Aug 2010 20:39:11 +0000</lastBuildDate>
	<generator>http://wordpress.org/?v=2.8.5</generator>
	<language>en</language>
	<sy:updatePeriod>hourly</sy:updatePeriod>
	<sy:updateFrequency>1</sy:updateFrequency>
			<item>
		<title>Understanding Java Static block/variables/method</title>
		<link>http://techiedrill.com/2009/11/understanding-java-static-blockvariablesmethod/</link>
		<comments>http://techiedrill.com/2009/11/understanding-java-static-blockvariablesmethod/#comments</comments>
		<pubDate>Fri, 20 Nov 2009 18:18:51 +0000</pubDate>
		<dc:creator>karnamrajesh</dc:creator>
				<category><![CDATA[Java]]></category>
		<category><![CDATA[block]]></category>
		<category><![CDATA[method]]></category>
		<category><![CDATA[methods]]></category>
		<category><![CDATA[static]]></category>
		<category><![CDATA[variable]]></category>
		<category><![CDATA[Variables]]></category>

		<guid isPermaLink="false">http://techiedrill.com/?p=433</guid>
		<description><![CDATA[lass UseStatic
{
 static int a=3;
 static int b;
 static void meth(int x)
 {
 System.out.println(&#8221;x: &#8220;+x);
 System.out.println(&#8221;a: &#8220;+a);
 System.out.println(&#8221;b: &#8220;+b);
 }
 static
 {
 System.out.println(&#8221;static block initialized: &#8220;);
 b=a*4;
 }
 public static void main(String [] args)
 {
 meth(42);
 }
}
Static block/variables/methods are very powerful in java.
When we say static it is static throughout the application. If you declare [...]]]></description>
			<content:encoded><![CDATA[<div id="_mcePaste" style="position: absolute; left: -10000px; top: 0px; width: 1px; height: 1px; overflow-x: hidden; overflow-y: hidden;"><em>lass UseStatic</em></div>
<div id="_mcePaste" style="position: absolute; left: -10000px; top: 0px; width: 1px; height: 1px; overflow-x: hidden; overflow-y: hidden;"><em>{</em></div>
<div id="_mcePaste" style="position: absolute; left: -10000px; top: 0px; width: 1px; height: 1px; overflow-x: hidden; overflow-y: hidden;"><span style="white-space: pre;"><em> </em></span><em>static int a=3;</em></div>
<div id="_mcePaste" style="position: absolute; left: -10000px; top: 0px; width: 1px; height: 1px; overflow-x: hidden; overflow-y: hidden;"><span style="white-space: pre;"><em> </em></span><em>static int b;</em></div>
<div id="_mcePaste" style="position: absolute; left: -10000px; top: 0px; width: 1px; height: 1px; overflow-x: hidden; overflow-y: hidden;"><span style="white-space: pre;"><em> </em></span><em>static void meth(int x)</em></div>
<div id="_mcePaste" style="position: absolute; left: -10000px; top: 0px; width: 1px; height: 1px; overflow-x: hidden; overflow-y: hidden;"><span style="white-space: pre;"><em> </em></span><em>{</em></div>
<div id="_mcePaste" style="position: absolute; left: -10000px; top: 0px; width: 1px; height: 1px; overflow-x: hidden; overflow-y: hidden;"><span style="white-space: pre;"><em> </em></span><em>System.out.println(&#8221;x: &#8220;+x);</em></div>
<div id="_mcePaste" style="position: absolute; left: -10000px; top: 0px; width: 1px; height: 1px; overflow-x: hidden; overflow-y: hidden;"><span style="white-space: pre;"><em> </em></span><em>System.out.println(&#8221;a: &#8220;+a);</em></div>
<div id="_mcePaste" style="position: absolute; left: -10000px; top: 0px; width: 1px; height: 1px; overflow-x: hidden; overflow-y: hidden;"><span style="white-space: pre;"><em> </em></span><em>System.out.println(&#8221;b: &#8220;+b);</em></div>
<div id="_mcePaste" style="position: absolute; left: -10000px; top: 0px; width: 1px; height: 1px; overflow-x: hidden; overflow-y: hidden;"><span style="white-space: pre;"><em> </em></span><em>}</em></div>
<div id="_mcePaste" style="position: absolute; left: -10000px; top: 0px; width: 1px; height: 1px; overflow-x: hidden; overflow-y: hidden;"><span style="white-space: pre;"><em> </em></span><em>static</em></div>
<div id="_mcePaste" style="position: absolute; left: -10000px; top: 0px; width: 1px; height: 1px; overflow-x: hidden; overflow-y: hidden;"><span style="white-space: pre;"><em> </em></span><em>{</em></div>
<div id="_mcePaste" style="position: absolute; left: -10000px; top: 0px; width: 1px; height: 1px; overflow-x: hidden; overflow-y: hidden;"><span style="white-space: pre;"><em> </em></span><em>System.out.println(&#8221;static block initialized: &#8220;);</em></div>
<div id="_mcePaste" style="position: absolute; left: -10000px; top: 0px; width: 1px; height: 1px; overflow-x: hidden; overflow-y: hidden;"><span style="white-space: pre;"><em> </em></span><em>b=a*4;</em></div>
<div id="_mcePaste" style="position: absolute; left: -10000px; top: 0px; width: 1px; height: 1px; overflow-x: hidden; overflow-y: hidden;"><span style="white-space: pre;"><em> </em></span><em>}</em></div>
<div id="_mcePaste" style="position: absolute; left: -10000px; top: 0px; width: 1px; height: 1px; overflow-x: hidden; overflow-y: hidden;"><span style="white-space: pre;"><em> </em></span><em>public static void main(String [] args)</em></div>
<div id="_mcePaste" style="position: absolute; left: -10000px; top: 0px; width: 1px; height: 1px; overflow-x: hidden; overflow-y: hidden;"><span style="white-space: pre;"><em> </em></span><em>{</em></div>
<div id="_mcePaste" style="position: absolute; left: -10000px; top: 0px; width: 1px; height: 1px; overflow-x: hidden; overflow-y: hidden;"><span style="white-space: pre;"><em> </em></span><em>meth(42);</em></div>
<div id="_mcePaste" style="position: absolute; left: -10000px; top: 0px; width: 1px; height: 1px; overflow-x: hidden; overflow-y: hidden;"><span style="white-space: pre;"><em> </em></span><em>}</em></div>
<div id="_mcePaste" style="position: absolute; left: -10000px; top: 0px; width: 1px; height: 1px; overflow-x: hidden; overflow-y: hidden;"><em>}</em></div>
<p><strong>Static block/variables/methods are very powerful in java.</strong></p>
<p>When we say static it is static throughout the application. If you declare a static variable in a stand-alone application, the life of the variable will be throughout the end of the application but in the case of the web application, static variable  has life till the web server is stopped.</p>
<p>Static variables are executed at first the program runs. Next the static block is executed. Static methods are executed when a call is raised.</p>
<p><em>Note: Static methods can call only static methods. To call non-static methods instance of the class should be created</em></p>
<p><strong>Refer below code for better understanding</strong></p>
<p><em>class UseStatic</em></p>
<p><em>{</em></p>
<p><span style="white-space:pre"><em> </em></span><em>static int a=3;</em></p>
<p><span style="white-space:pre"><em> </em></span><em>static int b;</em></p>
<p><em><br />
</em></p>
<p><span style="white-space:pre"><em> </em></span><em>static void meth(int x)</em></p>
<p><span style="white-space:pre"><em> </em></span><em>{</em></p>
<p><span style="white-space:pre"><em> </em></span><em>System.out.println(&#8221;x: &#8220;+x);</em></p>
<p><span style="white-space:pre"><em> </em></span><em>System.out.println(&#8221;a: &#8220;+a);</em></p>
<p><span style="white-space:pre"><em> </em></span><em>System.out.println(&#8221;b: &#8220;+b);</em></p>
<p><span style="white-space:pre"><em> </em></span><em>}</em></p>
<p><span style="white-space:pre"><em> </em></span><em>static</em></p>
<p><span style="white-space:pre"><em> </em></span><em>{</em></p>
<p><span style="white-space:pre"><em> </em></span><em>System.out.println(&#8221;static block initialized: &#8220;);</em></p>
<p><span style="white-space:pre"><em> </em></span><em>b=a*4;</em></p>
<p><span style="white-space:pre"><em> </em></span><em>}</em></p>
<p><span style="white-space:pre"><em> </em></span><em>public static void main(String [] args)</em></p>
<p><span style="white-space:pre"><em> </em></span><em>{</em></p>
<p><span style="white-space:pre"><em> </em></span><em>meth(42);</em></p>
<p><span style="white-space:pre"><em> </em></span><em>}</em></p>
<p><em>}</em></p>
]]></content:encoded>
			<wfw:commentRss>http://techiedrill.com/2009/11/understanding-java-static-blockvariablesmethod/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
	</channel>
</rss>
