<?xml version="1.0" encoding="UTF-8" standalone="no"?><rss xmlns:atom="http://www.w3.org/2005/Atom" xmlns:blogger="http://schemas.google.com/blogger/2008" xmlns:gd="http://schemas.google.com/g/2005" xmlns:georss="http://www.georss.org/georss" xmlns:itunes="http://www.itunes.com/dtds/podcast-1.0.dtd" xmlns:openSearch="http://a9.com/-/spec/opensearchrss/1.0/" xmlns:thr="http://purl.org/syndication/thread/1.0" version="2.0"><channel><atom:id>tag:blogger.com,1999:blog-3082064622906880860</atom:id><lastBuildDate>Thu, 19 Dec 2024 03:30:36 +0000</lastBuildDate><category>break</category><category>Java</category><category>continue</category><category>aggregation</category><category>association</category><category>composition</category><category>inheritance</category><category>local variables</category><category>6 usage of this keyword</category><category>Building blocks of .NET</category><category>CLR</category><category>CLS</category><category>CTS</category><category>Command line argument</category><category>DateTime</category><category>Hello world</category><category>Introduction to c#</category><category>System.Environment</category><category>System.console</category><category>TImeSpan</category><category>about java</category><category>abstraction</category><category>class</category><category>constructor</category><category>control statement</category><category>copy constructor</category><category>datatype</category><category>default</category><category>difference between local and instance variable</category><category>difference of static in c++ and Java</category><category>encapsulation</category><category>for</category><category>for loop</category><category>formating numbers</category><category>history of java</category><category>how to?</category><category>if - else</category><category>if-else if</category><category>infinite for loop</category><category>jdk</category><category>jre</category><category>jvm</category><category>keyword</category><category>live change editor</category><category>members of datatype</category><category>method. method overloading</category><category>object</category><category>oops</category><category>oops concept</category><category>polymorphism</category><category>setup java</category><category>static import</category><category>static keyword</category><category>switch statement</category><category>this</category><category>while loop</category><category>why main method is static?</category><title>Tangled JAVA elaborately</title><description></description><link>http://tangled-java.blogspot.com/</link><managingEditor>noreply@blogger.com (Anonymous)</managingEditor><generator>Blogger</generator><openSearch:totalResults>28</openSearch:totalResults><openSearch:startIndex>1</openSearch:startIndex><openSearch:itemsPerPage>25</openSearch:itemsPerPage><language>en-us</language><itunes:explicit>no</itunes:explicit><itunes:subtitle/><itunes:category text="Education"><itunes:category text="Higher Education"/></itunes:category><itunes:owner><itunes:email>noreply@blogger.com</itunes:email></itunes:owner><item><guid isPermaLink="false">tag:blogger.com,1999:blog-3082064622906880860.post-2045447654236718291</guid><pubDate>Thu, 14 Dec 2017 10:25:00 +0000</pubDate><atom:updated>2017-12-14T02:25:52.492-08:00</atom:updated><category domain="http://www.blogger.com/atom/ns#">DateTime</category><category domain="http://www.blogger.com/atom/ns#">members of datatype</category><category domain="http://www.blogger.com/atom/ns#">TImeSpan</category><title>Members of datatype and DateTime, TimeSpan</title><description>&lt;div dir="ltr" style="text-align: left;" trbidi="on"&gt;
&lt;html&gt;
&lt;head&gt;
 &lt;title&gt;&lt;/title&gt;
&lt;style&gt; 
strong{ color: #333; }
table {
    border-collapse: collapse;
    border-spacing: 0;
    width: 100%;
    border: 1px solid #ddd;
}

th, td {
    border: none;
    text-align: left;
    padding: 8px;
}

tr:nth-child(even){background-color: #f2f2f2}
@media only screen and (min-width: 800px){#dotnet{width: 20%; }}
&lt;/style&gt;
&lt;script type="text/javascript"&gt;
 /*! highlight.js v9.12.0 | BSD3 License | git.io/hljslicense */
!function(e){var n="object"==typeof window&amp;&amp;window||"object"==typeof self&amp;&amp;self;"undefined"!=typeof exports?e(exports):n&amp;&amp;(n.hljs=e({}),"function"==typeof define&amp;&amp;define.amd&amp;&amp;define([],function(){return n.hljs}))}(function(e){function n(e){return e.replace(/&amp;/g,"&amp;amp;").replace(/&lt;/g,"&amp;lt;").replace(/&gt;/g,"&amp;gt;")}function t(e){return e.nodeName.toLowerCase()}function r(e,n){var t=e&amp;&amp;e.exec(n);return t&amp;&amp;0===t.index}function a(e){return k.test(e)}function i(e){var n,t,r,i,o=e.className+" ";if(o+=e.parentNode?e.parentNode.className:"",t=B.exec(o))return w(t[1])?t[1]:"no-highlight";for(o=o.split(/\s+/),n=0,r=o.length;r&gt;n;n++)if(i=o[n],a(i)||w(i))return i}function o(e){var n,t={},r=Array.prototype.slice.call(arguments,1);for(n in e)t[n]=e[n];return r.forEach(function(e){for(n in e)t[n]=e[n]}),t}function u(e){var n=[];return function r(e,a){for(var i=e.firstChild;i;i=i.nextSibling)3===i.nodeType?a+=i.nodeValue.length:1===i.nodeType&amp;&amp;(n.push({event:"start",offset:a,node:i}),a=r(i,a),t(i).match(/br|hr|img|input/)||n.push({event:"stop",offset:a,node:i}));return a}(e,0),n}function c(e,r,a){function i(){return e.length&amp;&amp;r.length?e[0].offset!==r[0].offset?e[0].offset&lt;r[0].offset?e:r:"start"===r[0].event?e:r:e.length?e:r}function o(e){function r(e){return" "+e.nodeName+'="'+n(e.value).replace('"',"&amp;quot;")+'"'}s+="&lt;"+t(e)+E.map.call(e.attributes,r).join("")+"&gt;"}function u(e){s+="&lt;/"+t(e)+"&gt;"}function c(e){("start"===e.event?o:u)(e.node)}for(var l=0,s="",f=[];e.length||r.length;){var g=i();if(s+=n(a.substring(l,g[0].offset)),l=g[0].offset,g===e){f.reverse().forEach(u);do c(g.splice(0,1)[0]),g=i();while(g===e&amp;&amp;g.length&amp;&amp;g[0].offset===l);f.reverse().forEach(o)}else"start"===g[0].event?f.push(g[0].node):f.pop(),c(g.splice(0,1)[0])}return s+n(a.substr(l))}function l(e){return e.v&amp;&amp;!e.cached_variants&amp;&amp;(e.cached_variants=e.v.map(function(n){return o(e,{v:null},n)})),e.cached_variants||e.eW&amp;&amp;[o(e)]||[e]}function s(e){function n(e){return e&amp;&amp;e.source||e}function t(t,r){return new RegExp(n(t),"m"+(e.cI?"i":"")+(r?"g":""))}function r(a,i){if(!a.compiled){if(a.compiled=!0,a.k=a.k||a.bK,a.k){var o={},u=function(n,t){e.cI&amp;&amp;(t=t.toLowerCase()),t.split(" ").forEach(function(e){var t=e.split("|");o[t[0]]=[n,t[1]?Number(t[1]):1]})};"string"==typeof a.k?u("keyword",a.k):x(a.k).forEach(function(e){u(e,a.k[e])}),a.k=o}a.lR=t(a.l||/\w+/,!0),i&amp;&amp;(a.bK&amp;&amp;(a.b="\\b("+a.bK.split(" ").join("|")+")\\b"),a.b||(a.b=/\B|\b/),a.bR=t(a.b),a.e||a.eW||(a.e=/\B|\b/),a.e&amp;&amp;(a.eR=t(a.e)),a.tE=n(a.e)||"",a.eW&amp;&amp;i.tE&amp;&amp;(a.tE+=(a.e?"|":"")+i.tE)),a.i&amp;&amp;(a.iR=t(a.i)),null==a.r&amp;&amp;(a.r=1),a.c||(a.c=[]),a.c=Array.prototype.concat.apply([],a.c.map(function(e){return l("self"===e?a:e)})),a.c.forEach(function(e){r(e,a)}),a.starts&amp;&amp;r(a.starts,i);var c=a.c.map(function(e){return e.bK?"\\.?("+e.b+")\\.?":e.b}).concat([a.tE,a.i]).map(n).filter(Boolean);a.t=c.length?t(c.join("|"),!0):{exec:function(){return null}}}}r(e)}function f(e,t,a,i){function o(e,n){var t,a;for(t=0,a=n.c.length;a&gt;t;t++)if(r(n.c[t].bR,e))return n.c[t]}function u(e,n){if(r(e.eR,n)){for(;e.endsParent&amp;&amp;e.parent;)e=e.parent;return e}return e.eW?u(e.parent,n):void 0}function c(e,n){return!a&amp;&amp;r(n.iR,e)}function l(e,n){var t=N.cI?n[0].toLowerCase():n[0];return e.k.hasOwnProperty(t)&amp;&amp;e.k[t]}function p(e,n,t,r){var a=r?"":I.classPrefix,i='&lt;span class="'+a,o=t?"":C;return i+=e+'"&gt;',i+n+o}function h(){var e,t,r,a;if(!E.k)return n(k);for(a="",t=0,E.lR.lastIndex=0,r=E.lR.exec(k);r;)a+=n(k.substring(t,r.index)),e=l(E,r),e?(B+=e[1],a+=p(e[0],n(r[0]))):a+=n(r[0]),t=E.lR.lastIndex,r=E.lR.exec(k);return a+n(k.substr(t))}function d(){var e="string"==typeof E.sL;if(e&amp;&amp;!y[E.sL])return n(k);var t=e?f(E.sL,k,!0,x[E.sL]):g(k,E.sL.length?E.sL:void 0);return E.r&gt;0&amp;&amp;(B+=t.r),e&amp;&amp;(x[E.sL]=t.top),p(t.language,t.value,!1,!0)}function b(){L+=null!=E.sL?d():h(),k=""}function v(e){L+=e.cN?p(e.cN,"",!0):"",E=Object.create(e,{parent:{value:E}})}function m(e,n){if(k+=e,null==n)return b(),0;var t=o(n,E);if(t)return t.skip?k+=n:(t.eB&amp;&amp;(k+=n),b(),t.rB||t.eB||(k=n)),v(t,n),t.rB?0:n.length;var r=u(E,n);if(r){var a=E;a.skip?k+=n:(a.rE||a.eE||(k+=n),b(),a.eE&amp;&amp;(k=n));do E.cN&amp;&amp;(L+=C),E.skip||(B+=E.r),E=E.parent;while(E!==r.parent);return r.starts&amp;&amp;v(r.starts,""),a.rE?0:n.length}if(c(n,E))throw new Error('Illegal lexeme "'+n+'" for mode "'+(E.cN||"&lt;unnamed&gt;")+'"');return k+=n,n.length||1}var N=w(e);if(!N)throw new Error('Unknown language: "'+e+'"');s(N);var R,E=i||N,x={},L="";for(R=E;R!==N;R=R.parent)R.cN&amp;&amp;(L=p(R.cN,"",!0)+L);var k="",B=0;try{for(var M,j,O=0;;){if(E.t.lastIndex=O,M=E.t.exec(t),!M)break;j=m(t.substring(O,M.index),M[0]),O=M.index+j}for(m(t.substr(O)),R=E;R.parent;R=R.parent)R.cN&amp;&amp;(L+=C);return{r:B,value:L,language:e,top:E}}catch(T){if(T.message&amp;&amp;-1!==T.message.indexOf("Illegal"))return{r:0,value:n(t)};throw T}}function g(e,t){t=t||I.languages||x(y);var r={r:0,value:n(e)},a=r;return t.filter(w).forEach(function(n){var t=f(n,e,!1);t.language=n,t.r&gt;a.r&amp;&amp;(a=t),t.r&gt;r.r&amp;&amp;(a=r,r=t)}),a.language&amp;&amp;(r.second_best=a),r}function p(e){return I.tabReplace||I.useBR?e.replace(M,function(e,n){return I.useBR&amp;&amp;"\n"===e?"&lt;br&gt;":I.tabReplace?n.replace(/\t/g,I.tabReplace):""}):e}function h(e,n,t){var r=n?L[n]:t,a=[e.trim()];return e.match(/\bhljs\b/)||a.push("hljs"),-1===e.indexOf(r)&amp;&amp;a.push(r),a.join(" ").trim()}function d(e){var n,t,r,o,l,s=i(e);a(s)||(I.useBR?(n=document.createElementNS("http://www.w3.org/1999/xhtml","div"),n.innerHTML=e.innerHTML.replace(/\n/g,"").replace(/&lt;br[ \/]*&gt;/g,"\n")):n=e,l=n.textContent,r=s?f(s,l,!0):g(l),t=u(n),t.length&amp;&amp;(o=document.createElementNS("http://www.w3.org/1999/xhtml","div"),o.innerHTML=r.value,r.value=c(t,u(o),l)),r.value=p(r.value),e.innerHTML=r.value,e.className=h(e.className,s,r.language),e.result={language:r.language,re:r.r},r.second_best&amp;&amp;(e.second_best={language:r.second_best.language,re:r.second_best.r}))}function b(e){I=o(I,e)}function v(){if(!v.called){v.called=!0;var e=document.querySelectorAll("pre code");E.forEach.call(e,d)}}function m(){addEventListener("DOMContentLoaded",v,!1),addEventListener("load",v,!1)}function N(n,t){var r=y[n]=t(e);r.aliases&amp;&amp;r.aliases.forEach(function(e){L[e]=n})}function R(){return x(y)}function w(e){return e=(e||"").toLowerCase(),y[e]||y[L[e]]}var E=[],x=Object.keys,y={},L={},k=/^(no-?highlight|plain|text)$/i,B=/\blang(?:uage)?-([\w-]+)\b/i,M=/((^(&lt;[^&gt;]+&gt;|\t|)+|(?:\n)))/gm,C="&lt;/span&gt;",I={classPrefix:"hljs-",tabReplace:null,useBR:!1,languages:void 0};return e.highlight=f,e.highlightAuto=g,e.fixMarkup=p,e.highlightBlock=d,e.configure=b,e.initHighlighting=v,e.initHighlightingOnLoad=m,e.registerLanguage=N,e.listLanguages=R,e.getLanguage=w,e.inherit=o,e.IR="[a-zA-Z]\\w*",e.UIR="[a-zA-Z_]\\w*",e.NR="\\b\\d+(\\.\\d+)?",e.CNR="(-?)(\\b0[xX][a-fA-F0-9]+|(\\b\\d+(\\.\\d*)?|\\.\\d+)([eE][-+]?\\d+)?)",e.BNR="\\b(0b[01]+)",e.RSR="!|!=|!==|%|%=|&amp;|&amp;&amp;|&amp;=|\\*|\\*=|\\+|\\+=|,|-|-=|/=|/|:|;|&lt;&lt;|&lt;&lt;=|&lt;=|&lt;|===|==|=|&gt;&gt;&gt;=|&gt;&gt;=|&gt;=|&gt;&gt;&gt;|&gt;&gt;|&gt;|\\?|\\[|\\{|\\(|\\^|\\^=|\\||\\|=|\\|\\||~",e.BE={b:"\\\\[\\s\\S]",r:0},e.ASM={cN:"string",b:"'",e:"'",i:"\\n",c:[e.BE]},e.QSM={cN:"string",b:'"',e:'"',i:"\\n",c:[e.BE]},e.PWM={b:/\b(a|an|the|are|I'm|isn't|don't|doesn't|won't|but|just|should|pretty|simply|enough|gonna|going|wtf|so|such|will|you|your|they|like|more)\b/},e.C=function(n,t,r){var a=e.inherit({cN:"comment",b:n,e:t,c:[]},r||{});return a.c.push(e.PWM),a.c.push({cN:"doctag",b:"(?:TODO|FIXME|NOTE|BUG|XXX):",r:0}),a},e.CLCM=e.C("//","$"),e.CBCM=e.C("/\\*","\\*/"),e.HCM=e.C("#","$"),e.NM={cN:"number",b:e.NR,r:0},e.CNM={cN:"number",b:e.CNR,r:0},e.BNM={cN:"number",b:e.BNR,r:0},e.CSSNM={cN:"number",b:e.NR+"(%|em|ex|ch|rem|vw|vh|vmin|vmax|cm|mm|in|pt|pc|px|deg|grad|rad|turn|s|ms|Hz|kHz|dpi|dpcm|dppx)?",r:0},e.RM={cN:"regexp",b:/\//,e:/\/[gimuy]*/,i:/\n/,c:[e.BE,{b:/\[/,e:/\]/,r:0,c:[e.BE]}]},e.TM={cN:"title",b:e.IR,r:0},e.UTM={cN:"title",b:e.UIR,r:0},e.METHOD_GUARD={b:"\\.\\s*"+e.UIR,r:0},e});hljs.registerLanguage("java",function(e){var a="[À-ʸa-zA-Z_$][À-ʸa-zA-Z_$0-9]*",t=a+"(&lt;"+a+"(\\s*,\\s*"+a+")*&gt;)?",r="false synchronized int abstract float private char boolean static null if const for true while long strictfp finally protected import native final void enum else break transient catch instanceof byte super volatile case assert short package default double public try this switch continue throws protected public private module requires exports do",s="\\b(0[bB]([01]+[01_]+[01]+|[01]+)|0[xX]([a-fA-F0-9]+[a-fA-F0-9_]+[a-fA-F0-9]+|[a-fA-F0-9]+)|(([\\d]+[\\d_]+[\\d]+|[\\d]+)(\\.([\\d]+[\\d_]+[\\d]+|[\\d]+))?|\\.([\\d]+[\\d_]+[\\d]+|[\\d]+))([eE][-+]?\\d+)?)[lLfF]?",c={cN:"number",b:s,r:0};return{aliases:["jsp"],k:r,i:/&lt;\/|#/,c:[e.C("/\\*\\*","\\*/",{r:0,c:[{b:/\w+@/,r:0},{cN:"doctag",b:"@[A-Za-z]+"}]}),e.CLCM,e.CBCM,e.ASM,e.QSM,{cN:"class",bK:"class interface",e:/[{;=]/,eE:!0,k:"class interface",i:/[:"\[\]]/,c:[{bK:"extends implements"},e.UTM]},{bK:"new throw return else",r:0},{cN:"function",b:"("+t+"\\s+)+"+e.UIR+"\\s*\\(",rB:!0,e:/[{;=]/,eE:!0,k:r,c:[{b:e.UIR+"\\s*\\(",rB:!0,r:0,c:[e.UTM]},{cN:"params",b:/\(/,e:/\)/,k:r,r:0,c:[e.ASM,e.QSM,e.CNM,e.CBCM]},e.CLCM,e.CBCM]},c,{cN:"meta",b:"@[A-Za-z]+"}]}});
&lt;/script&gt;
&lt;script&gt;hljs.initHighlightingOnLoad();&lt;/script&gt;
&lt;/head&gt;
&lt;body onload="selectdotnet()"&gt;
&lt;div id="topics"&gt;&lt;/div&gt;
&lt;img src="https://blogger.googleusercontent.com/img/proxy/AVvXsEiFv-rPnZkgs0jexkl3m9JjFAGNoP1V8rTOgCtbWqFTgKAwQ70V6Q18rYBwRupk7wIXBcw67aqoxQbozpjPGMNdJGsGKVjg3b1k104S3IvKHlzJu3m9O824Ffv4-azvhJ3tDwnHplLw5dnvTiWw2kOyGg=w128-h128-p-k-no-nu" style="display: none;"/&gt;
&lt;!-- ####################################################################### --&gt;
In this article we will see members of C# datatypes.
&lt;h2&gt;Members of datatype&lt;/h2&gt;
&lt;h2&gt;Members of numerical datatype&lt;/h2&gt;
 Experimenting with the intrinsic C# data types, understand that the numerical types of .NET
support &lt;strong&gt;MaxValue&lt;/strong&gt; and &lt;strong&gt;MinValue&lt;/strong&gt; properties that provide information regarding the range a given type can
store. In addition to the MinValue/MaxValue properties, a given numerical system type may define further
useful members. For example, the &lt;strong&gt;System.Double&lt;/strong&gt; type allows you to obtain the values for &lt;strong&gt;epsilon&lt;/strong&gt; and
&lt;strong&gt;infinity&lt;/strong&gt; which might be of interest to those of you with a mathematical flare. 
&lt;br&gt;&lt;br&gt;
Lets understand that by a simple program:
&lt;h3&gt;Program&lt;/h3&gt;
&lt;pre&gt;
&lt;code class="java"&gt;
using System;

public class ConsoleApp
{
    public static void Main(string[] args)
    {
        Console.WriteLine("Members of numerical datatype:");
        Console.WriteLine("Max value of Int: {0}",int.MaxValue);
        Console.WriteLine("Min value of Int: {0}",int.MinValue);
        Console.WriteLine("Max value of Float: {0}", float.MaxValue);
        Console.WriteLine("Min value of Float: {0}", float.MinValue);
        Console.WriteLine("Max value of Double: {0}", double.MaxValue);
        Console.WriteLine("Min value of Double: {0}", double.MinValue);
        Console.WriteLine("Epsilon: {0}",double.Epsilon);
        Console.WriteLine("Positive infinity: {0}",double.PositiveInfinity);
        Console.WriteLine("Negative infinity: {0}",double.NegativeInfinity);
        Console.ReadLine();
    }
}
&lt;/code&gt;  
  &lt;a href="https://jdoodle.com/a/heC"&gt;&lt;button class="button"&gt;&lt;span&gt;Run &lt;/span&gt;&lt;/button&gt;&lt;/a&gt;
&lt;/pre&gt;

&lt;h3&gt;Output&lt;/h3&gt;
&lt;pre&gt;
&lt;code class="java"&gt;
Members of numerical datatype:
Max value of Int: 2147483647
Min value of Int: -2147483648
Max value of Float: 3.402823E+38
Min value of Float: -3.402823E+38
Max value of Double: 1.79769313486232E+308
Min value of Double: -1.79769313486232E+308
Epsilon: 4.94065645841247E-324
Positive infinity: Infinity
Negative infinity: -Infinity
&lt;/code&gt;  
&lt;/pre&gt;
&lt;h2&gt;Members of System.Boolean&lt;/h2&gt;
 Consider the &lt;strong&gt;System.Boolean&lt;/strong&gt; data type. The only valid assignment a C# bool can take is from
the &lt;strong&gt;set {true | false}&lt;/strong&gt;. Given this point, it should be clear that &lt;strong&gt;System.Boolean&lt;/strong&gt; does not support a
&lt;strong&gt;MinValue/MaxValue&lt;/strong&gt; property set but rather &lt;strong&gt;TrueString/FalseString&lt;/strong&gt; (which yields the string "True" or
"False", respectively). Here’s an example program:
&lt;h3&gt;Program&lt;/h3&gt;
&lt;pre&gt;
&lt;code class="java"&gt;
using System;

public class ConsoleApp
{
    public static void Main(string[] args)
    {
        //Members of System.Boolean
        Console.WriteLine("true string: {0}",bool.TrueString);
        //GetType() method returns datatype of variable
        Console.WriteLine("type of TrueString: {0}",bool.TrueString.GetType());
        Console.WriteLine("false string: {0}",bool.FalseString);
        Console.WriteLine("type of FalseString: {0}",bool.FalseString.GetType());
        Console.ReadLine();
    }
}
&lt;/code&gt;  
  &lt;a href="https://jdoodle.com/a/heH"&gt;&lt;button class="button"&gt;&lt;span&gt;Run &lt;/span&gt;&lt;/button&gt;&lt;/a&gt;
&lt;/pre&gt;

&lt;h3&gt;Output&lt;/h3&gt;
&lt;pre&gt;
&lt;code class="java"&gt;
true string: True
type of TrueString: System.String
false string: False
type of FalseString: System.String
&lt;/code&gt;  
&lt;/pre&gt;
&lt;h2&gt;Members of System.Char&lt;/h2&gt;
C# textual data is represented by the string and char keywords, which are simple shorthand notations for
System.String and System.Char, both of which are Unicode under the hood. As you might already know, a
string represents a contiguous set of characters (e.g., "Hello"), while the char can represent a single slot in
a string (e.g., 'H').&lt;br&gt;&lt;br&gt;
The System.Char type provides you with a great deal of functionality beyond the ability to hold a single
point of character data. Using the static methods of System.Char, you are able to determine whether a given
character is numerical, alphabetical, a point of punctuation, or whatnot. Consider the following program:
&lt;h3&gt;How to know that given character is digit or letter in C#?&lt;/h3&gt;
&lt;h3&gt;Program&lt;/h3&gt;
&lt;pre&gt;
&lt;code class="java"&gt;
using System;

public class ConsoleApp
{
    public static void Main(string[] args)
    {
        //Members of System.Char
        char MyChar = 'H';
        Console.WriteLine("Is MyChar digit? =&gt; {0}",char.IsDigit(MyChar));
        Console.WriteLine("Is MyChar letter? =&gt; {0}",char.IsLetter(MyChar));
        Console.ReadLine();
    }
}
&lt;/code&gt;  
  &lt;a href="https://jdoodle.com/a/heK"&gt;&lt;button class="button"&gt;&lt;span&gt;Run &lt;/span&gt;&lt;/button&gt;&lt;/a&gt;
&lt;/pre&gt;

&lt;h3&gt;Output&lt;/h3&gt;
&lt;pre&gt;
&lt;code class="java"&gt;
Is MyChar digit? =&gt; False
Is MyChar letter? =&gt; True
&lt;/code&gt;  
&lt;/pre&gt;
&lt;h2&gt;Parsing values from string data&lt;/h2&gt;
The .NET data types provide the ability to generate a variable of their underlying type given a textual
equivalent (e.g., parsing). This technique can be extremely helpful when you want to convert some user
input data (such as a selection from a GUI-based, drop-down list box) into a numerical value. Consider the
following parsing logic:
&lt;h3&gt;How to parse data from string to other datatype?&lt;/h3&gt;
&lt;h3&gt;Program&lt;/h3&gt;
&lt;pre&gt;
&lt;code class="java"&gt;
using System;

public class ConsoleApp
{
    public static void Main(string[] args)
    {
        //Parsing data from string
        //string to bool
        bool b = bool.Parse("True");
        Console.WriteLine("b: {0}",b);
        //string to double
        double d = double.Parse("96.656");
        Console.WriteLine("d: {0}",d);
        //string to int
        int i = int.Parse("987");
        Console.WriteLine("i: {0}",i);
        //string to char
        char c = char.Parse("c");
        Console.WriteLine("c: {0}",c);
        Console.ReadLine();
    }
}
&lt;/code&gt;  
  &lt;a href="https://jdoodle.com/a/heQ"&gt;&lt;button class="button"&gt;&lt;span&gt;Run &lt;/span&gt;&lt;/button&gt;&lt;/a&gt;
&lt;/pre&gt;

&lt;h3&gt;Output&lt;/h3&gt;
&lt;pre&gt;
&lt;code class="java"&gt;
b: True
d: 96.656
i: 987
c: c
&lt;/code&gt;  
&lt;/pre&gt;
&lt;h2&gt;System.DateTime&lt;/h2&gt;
The System namespace defines a few useful data types for which there are no C# keywords, such as the
&lt;strong&gt;DateTime&lt;/strong&gt; and &lt;strong&gt;TimeSpan&lt;/strong&gt; structures.
&lt;br&gt;&lt;br&gt;
The DateTime type contains data that represents a specific date &lt;strong&gt;(month, day, year)&lt;/strong&gt; and time value, both
of which may be formatted in a variety of ways using the supplied members. 
&lt;h3&gt;Find day of week from DateTime instance in C#&lt;/h3&gt;
&lt;pre&gt;
&lt;code class="java"&gt;
DateTime dt = new DateTime(1997,09,27);
Console.WriteLine("day is {0}",dt.DayOfWeek);
&lt;/code&gt;  
&lt;/pre&gt;
&lt;h3&gt;How to extract day, month or year from DateTime instance?&lt;/h3&gt;
&lt;pre&gt;
&lt;code class="java"&gt;
DateTime dt = new DateTime(1997,09,27);
Console.WriteLine("Day is {0}",dt.Day);
Console.WriteLine("month is {0}",dt.Month);
Console.WriteLine("year is {0}",dt.Year);
&lt;/code&gt;  
&lt;/pre&gt;
&lt;h3&gt;How to add day, month or year in DateTime instance?&lt;/h3&gt;
&lt;pre&gt;
&lt;code class="java"&gt;
DateTime dt = new DateTime(1997,09,27);
dt = dt.AddDays(2);
dt = dt.AddMonths(1);
dt = dt.AddYears(4);
&lt;/code&gt;  
&lt;/pre&gt;
&lt;h3&gt;Sample program of DateTime&lt;/h3&gt;
&lt;pre&gt;
&lt;code class="java"&gt;
using System;

public class ConsoleApp
{
    public static void Main(string[] args)
    {
        DateTime dt = new DateTime(1997,09,27);
        Console.WriteLine("day of week is {0}",dt.DayOfWeek);
        Console.WriteLine("day of year is {0}",dt.DayOfYear);
        Console.WriteLine("date is {0}",dt.Date);
        //Extract day, month, year form DateTime
        Console.WriteLine("Day is {0}",dt.Day);
        Console.WriteLine("month is {0}",dt.Month);
        Console.WriteLine("year is {0}",dt.Year);
        //Add day, month, year form DateTime
        dt = dt.AddDays(2);
        dt = dt.AddMonths(1);
        dt = dt.AddYears(4);
        Console.WriteLine("After adding date is: {0}",dt.Date);
        Console.WriteLine("Is day light saving time: {0}",dt.IsDaylightSavingTime());
        Console.ReadLine();

    }
}
&lt;/code&gt;  
  &lt;a href="https://jdoodle.com/a/hf9"&gt;&lt;button class="button"&gt;&lt;span&gt;Run &lt;/span&gt;&lt;/button&gt;&lt;/a&gt;
&lt;/pre&gt;

&lt;h3&gt;Output&lt;/h3&gt;
&lt;pre&gt;
&lt;code class="java"&gt;
day of week is Saturday
day of year is 270
date is 09/27/1997 00:00:00
Day is 27
month is 9
year is 1997
After adding date is: 10/29/2001 00:00:00
Is day light saving time: False
&lt;/code&gt;  
&lt;/pre&gt;
&lt;h3&gt;what is DayLightSavingTime() in C#?&lt;/h3&gt;
It ndicates whether this instance of System.DateTime is within the daylight saving
time range for the current time zone.
&lt;br&gt;&lt;br&gt;
It returns 
&lt;strong&gt;true&lt;/strong&gt; if the value of the System.DateTime.Kind property is System.DateTimeKind.Local
             or System.DateTimeKind.Unspecified and the value of this instance of System.DateTime
            is within the daylight saving time range for the local time zone; &lt;strong&gt;false&lt;/strong&gt; if System.DateTime.Kind
        is System.DateTimeKind.Utc.
To know more about what daylight saving time commonly know as DST go to&lt;a href="https://en.wikipedia.org/wiki/Daylight_saving_time"&gt;&lt;button&gt;Go&lt;/button&gt;&lt;/a&gt;
&lt;br&gt;
To know more about properties and methods of &lt;strong&gt;System.DateTime&lt;/strong&gt; go to:&lt;a href="https://msdn.microsoft.com/en-us/library/system.datetime(d=printer,v=vs.110).aspx?cs-save-lang=1&amp;cs-lang=csharp"&gt;&lt;button&gt;Go&lt;/button&gt;&lt;/a&gt;
&lt;h2&gt;System.TimeSpan&lt;/h2&gt;
The TimeSpan structure allows
you to easily define and transform units of time using various members.
&lt;h3&gt;How to add or subtract time is TimeSpan instance ?&lt;/h3&gt;
&lt;pre&gt;
&lt;code class="java"&gt;
TimeSpan ts = new TimeSpan(8, 15, 0);
//to add or subtract time in TimeSpan instance
Console.WriteLine(ts.Add(new TimeSpan(2,30,0)));
&lt;/code&gt;  
&lt;/pre&gt;
&lt;strong&gt;TimeSpan.Add()&lt;/strong&gt; and &lt;strong&gt;TimeSpan.Subtract()&lt;/strong&gt;:
returns A new object that represents the value of this instance plus/minus the value of ts.
&lt;h3&gt;How to extract hour, minute or second from TimeSpan instance ?&lt;/h3&gt;
&lt;pre&gt;
&lt;code class="java"&gt;
TimeSpan ts = new TimeSpan(8, 15, 0);
Console.WriteLine("Hour: {0}",ts.Hours);
Console.WriteLine("Minutes: {0}", ts.Minutes);
Console.WriteLine("Seconds: {0}", ts.Seconds);
&lt;/code&gt;  
&lt;/pre&gt;
&lt;h3&gt;Sample program of System.TimeSpan&lt;/h3&gt;
&lt;pre&gt;
&lt;code class="java"&gt;
using System;

public class ConsoleApp
{
    public static void Main(string[] args)
    {
        TimeSpan ts = new TimeSpan(8, 15, 0);
        //to add time in TimeSpan instance
        Console.WriteLine("After adding: {0}",ts.Add(new TimeSpan(2,30,0)));
        Console.WriteLine("After subtracting: {0}",ts.Subtract(new TimeSpan(1,23,45)));
        Console.WriteLine("Hour: {0}",ts.Hours);
        Console.WriteLine("Minutes: {0}", ts.Minutes);
        Console.WriteLine("Seconds: {0}", ts.Seconds);
        Console.ReadLine();
    }
}
&lt;/code&gt;  
  &lt;a href="https://jdoodle.com/a/hfp"&gt;&lt;button class="button"&gt;&lt;span&gt;Run &lt;/span&gt;&lt;/button&gt;&lt;/a&gt;
&lt;/pre&gt;

&lt;h3&gt;Output&lt;/h3&gt;
&lt;pre&gt;
&lt;code class="java"&gt;
After adding: 10:45:00
After subtracting: 06:51:15
Hour: 8
Minutes: 15
Seconds: 0
&lt;/code&gt;  
&lt;/pre&gt;
Programers who are from JAVA remember that DateTime and TimeSpan are &lt;strong&gt;structers&lt;/strong&gt; C# while in JAVA everything is class.
&lt;!-- ####################################################################### --&gt;
&lt;/body&gt;
&lt;/html&gt;&lt;/div&gt;
</description><link>http://tangled-java.blogspot.com/2017/12/members-of-datatype-and-datetime.html</link><author>noreply@blogger.com (Anonymous)</author><media:thumbnail xmlns:media="http://search.yahoo.com/mrss/" height="72" url="https://blogger.googleusercontent.com/img/proxy/AVvXsEiFv-rPnZkgs0jexkl3m9JjFAGNoP1V8rTOgCtbWqFTgKAwQ70V6Q18rYBwRupk7wIXBcw67aqoxQbozpjPGMNdJGsGKVjg3b1k104S3IvKHlzJu3m9O824Ffv4-azvhJ3tDwnHplLw5dnvTiWw2kOyGg=s72-w128-h128-c-p-k-no-nu" width="72"/><thr:total>0</thr:total></item><item><guid isPermaLink="false">tag:blogger.com,1999:blog-3082064622906880860.post-7374771199931846849</guid><pubDate>Wed, 13 Dec 2017 07:23:00 +0000</pubDate><atom:updated>2017-12-12T23:23:46.226-08:00</atom:updated><category domain="http://www.blogger.com/atom/ns#">datatype</category><category domain="http://www.blogger.com/atom/ns#">keyword</category><category domain="http://www.blogger.com/atom/ns#">local variables</category><title>Datatype and keyword</title><description>&lt;div dir="ltr" style="text-align: left;" trbidi="on"&gt;
&lt;html&gt;
&lt;head&gt;
 &lt;title&gt;&lt;/title&gt;
&lt;style&gt; 
strong{ color: #333; }
table {
    border-collapse: collapse;
    border-spacing: 0;
    width: 100%;
    border: 1px solid #ddd;
}

th, td {
    border: none;
    text-align: left;
    padding: 8px;
}

tr:nth-child(even){background-color: #f2f2f2}
@media only screen and (min-width: 800px){#dotnet{width: 20%; }}
&lt;/style&gt;
&lt;script type="text/javascript"&gt;
 /*! highlight.js v9.12.0 | BSD3 License | git.io/hljslicense */
!function(e){var n="object"==typeof window&amp;&amp;window||"object"==typeof self&amp;&amp;self;"undefined"!=typeof exports?e(exports):n&amp;&amp;(n.hljs=e({}),"function"==typeof define&amp;&amp;define.amd&amp;&amp;define([],function(){return n.hljs}))}(function(e){function n(e){return e.replace(/&amp;/g,"&amp;amp;").replace(/&lt;/g,"&amp;lt;").replace(/&gt;/g,"&amp;gt;")}function t(e){return e.nodeName.toLowerCase()}function r(e,n){var t=e&amp;&amp;e.exec(n);return t&amp;&amp;0===t.index}function a(e){return k.test(e)}function i(e){var n,t,r,i,o=e.className+" ";if(o+=e.parentNode?e.parentNode.className:"",t=B.exec(o))return w(t[1])?t[1]:"no-highlight";for(o=o.split(/\s+/),n=0,r=o.length;r&gt;n;n++)if(i=o[n],a(i)||w(i))return i}function o(e){var n,t={},r=Array.prototype.slice.call(arguments,1);for(n in e)t[n]=e[n];return r.forEach(function(e){for(n in e)t[n]=e[n]}),t}function u(e){var n=[];return function r(e,a){for(var i=e.firstChild;i;i=i.nextSibling)3===i.nodeType?a+=i.nodeValue.length:1===i.nodeType&amp;&amp;(n.push({event:"start",offset:a,node:i}),a=r(i,a),t(i).match(/br|hr|img|input/)||n.push({event:"stop",offset:a,node:i}));return a}(e,0),n}function c(e,r,a){function i(){return e.length&amp;&amp;r.length?e[0].offset!==r[0].offset?e[0].offset&lt;r[0].offset?e:r:"start"===r[0].event?e:r:e.length?e:r}function o(e){function r(e){return" "+e.nodeName+'="'+n(e.value).replace('"',"&amp;quot;")+'"'}s+="&lt;"+t(e)+E.map.call(e.attributes,r).join("")+"&gt;"}function u(e){s+="&lt;/"+t(e)+"&gt;"}function c(e){("start"===e.event?o:u)(e.node)}for(var l=0,s="",f=[];e.length||r.length;){var g=i();if(s+=n(a.substring(l,g[0].offset)),l=g[0].offset,g===e){f.reverse().forEach(u);do c(g.splice(0,1)[0]),g=i();while(g===e&amp;&amp;g.length&amp;&amp;g[0].offset===l);f.reverse().forEach(o)}else"start"===g[0].event?f.push(g[0].node):f.pop(),c(g.splice(0,1)[0])}return s+n(a.substr(l))}function l(e){return e.v&amp;&amp;!e.cached_variants&amp;&amp;(e.cached_variants=e.v.map(function(n){return o(e,{v:null},n)})),e.cached_variants||e.eW&amp;&amp;[o(e)]||[e]}function s(e){function n(e){return e&amp;&amp;e.source||e}function t(t,r){return new RegExp(n(t),"m"+(e.cI?"i":"")+(r?"g":""))}function r(a,i){if(!a.compiled){if(a.compiled=!0,a.k=a.k||a.bK,a.k){var o={},u=function(n,t){e.cI&amp;&amp;(t=t.toLowerCase()),t.split(" ").forEach(function(e){var t=e.split("|");o[t[0]]=[n,t[1]?Number(t[1]):1]})};"string"==typeof a.k?u("keyword",a.k):x(a.k).forEach(function(e){u(e,a.k[e])}),a.k=o}a.lR=t(a.l||/\w+/,!0),i&amp;&amp;(a.bK&amp;&amp;(a.b="\\b("+a.bK.split(" ").join("|")+")\\b"),a.b||(a.b=/\B|\b/),a.bR=t(a.b),a.e||a.eW||(a.e=/\B|\b/),a.e&amp;&amp;(a.eR=t(a.e)),a.tE=n(a.e)||"",a.eW&amp;&amp;i.tE&amp;&amp;(a.tE+=(a.e?"|":"")+i.tE)),a.i&amp;&amp;(a.iR=t(a.i)),null==a.r&amp;&amp;(a.r=1),a.c||(a.c=[]),a.c=Array.prototype.concat.apply([],a.c.map(function(e){return l("self"===e?a:e)})),a.c.forEach(function(e){r(e,a)}),a.starts&amp;&amp;r(a.starts,i);var c=a.c.map(function(e){return e.bK?"\\.?("+e.b+")\\.?":e.b}).concat([a.tE,a.i]).map(n).filter(Boolean);a.t=c.length?t(c.join("|"),!0):{exec:function(){return null}}}}r(e)}function f(e,t,a,i){function o(e,n){var t,a;for(t=0,a=n.c.length;a&gt;t;t++)if(r(n.c[t].bR,e))return n.c[t]}function u(e,n){if(r(e.eR,n)){for(;e.endsParent&amp;&amp;e.parent;)e=e.parent;return e}return e.eW?u(e.parent,n):void 0}function c(e,n){return!a&amp;&amp;r(n.iR,e)}function l(e,n){var t=N.cI?n[0].toLowerCase():n[0];return e.k.hasOwnProperty(t)&amp;&amp;e.k[t]}function p(e,n,t,r){var a=r?"":I.classPrefix,i='&lt;span class="'+a,o=t?"":C;return i+=e+'"&gt;',i+n+o}function h(){var e,t,r,a;if(!E.k)return n(k);for(a="",t=0,E.lR.lastIndex=0,r=E.lR.exec(k);r;)a+=n(k.substring(t,r.index)),e=l(E,r),e?(B+=e[1],a+=p(e[0],n(r[0]))):a+=n(r[0]),t=E.lR.lastIndex,r=E.lR.exec(k);return a+n(k.substr(t))}function d(){var e="string"==typeof E.sL;if(e&amp;&amp;!y[E.sL])return n(k);var t=e?f(E.sL,k,!0,x[E.sL]):g(k,E.sL.length?E.sL:void 0);return E.r&gt;0&amp;&amp;(B+=t.r),e&amp;&amp;(x[E.sL]=t.top),p(t.language,t.value,!1,!0)}function b(){L+=null!=E.sL?d():h(),k=""}function v(e){L+=e.cN?p(e.cN,"",!0):"",E=Object.create(e,{parent:{value:E}})}function m(e,n){if(k+=e,null==n)return b(),0;var t=o(n,E);if(t)return t.skip?k+=n:(t.eB&amp;&amp;(k+=n),b(),t.rB||t.eB||(k=n)),v(t,n),t.rB?0:n.length;var r=u(E,n);if(r){var a=E;a.skip?k+=n:(a.rE||a.eE||(k+=n),b(),a.eE&amp;&amp;(k=n));do E.cN&amp;&amp;(L+=C),E.skip||(B+=E.r),E=E.parent;while(E!==r.parent);return r.starts&amp;&amp;v(r.starts,""),a.rE?0:n.length}if(c(n,E))throw new Error('Illegal lexeme "'+n+'" for mode "'+(E.cN||"&lt;unnamed&gt;")+'"');return k+=n,n.length||1}var N=w(e);if(!N)throw new Error('Unknown language: "'+e+'"');s(N);var R,E=i||N,x={},L="";for(R=E;R!==N;R=R.parent)R.cN&amp;&amp;(L=p(R.cN,"",!0)+L);var k="",B=0;try{for(var M,j,O=0;;){if(E.t.lastIndex=O,M=E.t.exec(t),!M)break;j=m(t.substring(O,M.index),M[0]),O=M.index+j}for(m(t.substr(O)),R=E;R.parent;R=R.parent)R.cN&amp;&amp;(L+=C);return{r:B,value:L,language:e,top:E}}catch(T){if(T.message&amp;&amp;-1!==T.message.indexOf("Illegal"))return{r:0,value:n(t)};throw T}}function g(e,t){t=t||I.languages||x(y);var r={r:0,value:n(e)},a=r;return t.filter(w).forEach(function(n){var t=f(n,e,!1);t.language=n,t.r&gt;a.r&amp;&amp;(a=t),t.r&gt;r.r&amp;&amp;(a=r,r=t)}),a.language&amp;&amp;(r.second_best=a),r}function p(e){return I.tabReplace||I.useBR?e.replace(M,function(e,n){return I.useBR&amp;&amp;"\n"===e?"&lt;br&gt;":I.tabReplace?n.replace(/\t/g,I.tabReplace):""}):e}function h(e,n,t){var r=n?L[n]:t,a=[e.trim()];return e.match(/\bhljs\b/)||a.push("hljs"),-1===e.indexOf(r)&amp;&amp;a.push(r),a.join(" ").trim()}function d(e){var n,t,r,o,l,s=i(e);a(s)||(I.useBR?(n=document.createElementNS("http://www.w3.org/1999/xhtml","div"),n.innerHTML=e.innerHTML.replace(/\n/g,"").replace(/&lt;br[ \/]*&gt;/g,"\n")):n=e,l=n.textContent,r=s?f(s,l,!0):g(l),t=u(n),t.length&amp;&amp;(o=document.createElementNS("http://www.w3.org/1999/xhtml","div"),o.innerHTML=r.value,r.value=c(t,u(o),l)),r.value=p(r.value),e.innerHTML=r.value,e.className=h(e.className,s,r.language),e.result={language:r.language,re:r.r},r.second_best&amp;&amp;(e.second_best={language:r.second_best.language,re:r.second_best.r}))}function b(e){I=o(I,e)}function v(){if(!v.called){v.called=!0;var e=document.querySelectorAll("pre code");E.forEach.call(e,d)}}function m(){addEventListener("DOMContentLoaded",v,!1),addEventListener("load",v,!1)}function N(n,t){var r=y[n]=t(e);r.aliases&amp;&amp;r.aliases.forEach(function(e){L[e]=n})}function R(){return x(y)}function w(e){return e=(e||"").toLowerCase(),y[e]||y[L[e]]}var E=[],x=Object.keys,y={},L={},k=/^(no-?highlight|plain|text)$/i,B=/\blang(?:uage)?-([\w-]+)\b/i,M=/((^(&lt;[^&gt;]+&gt;|\t|)+|(?:\n)))/gm,C="&lt;/span&gt;",I={classPrefix:"hljs-",tabReplace:null,useBR:!1,languages:void 0};return e.highlight=f,e.highlightAuto=g,e.fixMarkup=p,e.highlightBlock=d,e.configure=b,e.initHighlighting=v,e.initHighlightingOnLoad=m,e.registerLanguage=N,e.listLanguages=R,e.getLanguage=w,e.inherit=o,e.IR="[a-zA-Z]\\w*",e.UIR="[a-zA-Z_]\\w*",e.NR="\\b\\d+(\\.\\d+)?",e.CNR="(-?)(\\b0[xX][a-fA-F0-9]+|(\\b\\d+(\\.\\d*)?|\\.\\d+)([eE][-+]?\\d+)?)",e.BNR="\\b(0b[01]+)",e.RSR="!|!=|!==|%|%=|&amp;|&amp;&amp;|&amp;=|\\*|\\*=|\\+|\\+=|,|-|-=|/=|/|:|;|&lt;&lt;|&lt;&lt;=|&lt;=|&lt;|===|==|=|&gt;&gt;&gt;=|&gt;&gt;=|&gt;=|&gt;&gt;&gt;|&gt;&gt;|&gt;|\\?|\\[|\\{|\\(|\\^|\\^=|\\||\\|=|\\|\\||~",e.BE={b:"\\\\[\\s\\S]",r:0},e.ASM={cN:"string",b:"'",e:"'",i:"\\n",c:[e.BE]},e.QSM={cN:"string",b:'"',e:'"',i:"\\n",c:[e.BE]},e.PWM={b:/\b(a|an|the|are|I'm|isn't|don't|doesn't|won't|but|just|should|pretty|simply|enough|gonna|going|wtf|so|such|will|you|your|they|like|more)\b/},e.C=function(n,t,r){var a=e.inherit({cN:"comment",b:n,e:t,c:[]},r||{});return a.c.push(e.PWM),a.c.push({cN:"doctag",b:"(?:TODO|FIXME|NOTE|BUG|XXX):",r:0}),a},e.CLCM=e.C("//","$"),e.CBCM=e.C("/\\*","\\*/"),e.HCM=e.C("#","$"),e.NM={cN:"number",b:e.NR,r:0},e.CNM={cN:"number",b:e.CNR,r:0},e.BNM={cN:"number",b:e.BNR,r:0},e.CSSNM={cN:"number",b:e.NR+"(%|em|ex|ch|rem|vw|vh|vmin|vmax|cm|mm|in|pt|pc|px|deg|grad|rad|turn|s|ms|Hz|kHz|dpi|dpcm|dppx)?",r:0},e.RM={cN:"regexp",b:/\//,e:/\/[gimuy]*/,i:/\n/,c:[e.BE,{b:/\[/,e:/\]/,r:0,c:[e.BE]}]},e.TM={cN:"title",b:e.IR,r:0},e.UTM={cN:"title",b:e.UIR,r:0},e.METHOD_GUARD={b:"\\.\\s*"+e.UIR,r:0},e});hljs.registerLanguage("java",function(e){var a="[À-ʸa-zA-Z_$][À-ʸa-zA-Z_$0-9]*",t=a+"(&lt;"+a+"(\\s*,\\s*"+a+")*&gt;)?",r="false synchronized int abstract float private char boolean static null if const for true while long strictfp finally protected import native final void enum else break transient catch instanceof byte super volatile case assert short package default double public try this switch continue throws protected public private module requires exports do",s="\\b(0[bB]([01]+[01_]+[01]+|[01]+)|0[xX]([a-fA-F0-9]+[a-fA-F0-9_]+[a-fA-F0-9]+|[a-fA-F0-9]+)|(([\\d]+[\\d_]+[\\d]+|[\\d]+)(\\.([\\d]+[\\d_]+[\\d]+|[\\d]+))?|\\.([\\d]+[\\d_]+[\\d]+|[\\d]+))([eE][-+]?\\d+)?)[lLfF]?",c={cN:"number",b:s,r:0};return{aliases:["jsp"],k:r,i:/&lt;\/|#/,c:[e.C("/\\*\\*","\\*/",{r:0,c:[{b:/\w+@/,r:0},{cN:"doctag",b:"@[A-Za-z]+"}]}),e.CLCM,e.CBCM,e.ASM,e.QSM,{cN:"class",bK:"class interface",e:/[{;=]/,eE:!0,k:"class interface",i:/[:"\[\]]/,c:[{bK:"extends implements"},e.UTM]},{bK:"new throw return else",r:0},{cN:"function",b:"("+t+"\\s+)+"+e.UIR+"\\s*\\(",rB:!0,e:/[{;=]/,eE:!0,k:r,c:[{b:e.UIR+"\\s*\\(",rB:!0,r:0,c:[e.UTM]},{cN:"params",b:/\(/,e:/\)/,k:r,r:0,c:[e.ASM,e.QSM,e.CNM,e.CBCM]},e.CLCM,e.CBCM]},c,{cN:"meta",b:"@[A-Za-z]+"}]}});
&lt;/script&gt;
&lt;script&gt;hljs.initHighlightingOnLoad();&lt;/script&gt;
&lt;/head&gt;
&lt;body onload="selectdotnet()"&gt;
&lt;div id="topics"&gt;&lt;/div&gt;
&lt;img src="https://blogger.googleusercontent.com/img/proxy/AVvXsEiFv-rPnZkgs0jexkl3m9JjFAGNoP1V8rTOgCtbWqFTgKAwQ70V6Q18rYBwRupk7wIXBcw67aqoxQbozpjPGMNdJGsGKVjg3b1k104S3IvKHlzJu3m9O824Ffv4-azvhJ3tDwnHplLw5dnvTiWw2kOyGg=w128-h128-p-k-no-nu" style="display: none;"/&gt;
&lt;!-- ####################################################################### --&gt;
Like any programming language, C# defines keywords for fundamental data types, which are used to
represent local variables, class data member variables, method return values, and parameters. Unlike
other programming languages, however, these keywords are much more than simple compiler- recognized
tokens. Rather, the C# data type keywords are actually shorthand notations for full-blown types in the System
namespace. &lt;br&gt;&lt;br&gt;
Table lists each system data type, its range, the corresponding C# keyword, and the type’s
compliance with the common language specification (CLS).
&lt;table&gt;
    &lt;tr&gt;
        &lt;th&gt;C# keyword&lt;/th&gt;
        &lt;th&gt;System type&lt;/th&gt;
        &lt;th&gt;Range&lt;/th&gt;
        &lt;th&gt;Meaning&lt;/th&gt;
        &lt;th&gt;CLS complaint?&lt;/th&gt;
    &lt;/tr&gt;
    &lt;tr&gt;
        &lt;td&gt;bool&lt;/td&gt;
        &lt;td&gt;System.Boolean&lt;/td&gt;
        &lt;td&gt;true or false&lt;/td&gt;
        &lt;td&gt;Represents truth or falsity&lt;/td&gt;
        &lt;td&gt;Yes&lt;/td&gt;
    &lt;/tr&gt;
    &lt;tr&gt;
        &lt;td&gt;sbyte&lt;/td&gt;
        &lt;td&gt;System.SByte&lt;/td&gt;
        &lt;td&gt;-128 to 127&lt;/td&gt;
        &lt;td&gt;signed 8-bit number&lt;/td&gt;
        &lt;td&gt;No&lt;/td&gt;
    &lt;/tr&gt;
    &lt;tr&gt;
        &lt;td&gt;byte&lt;/td&gt;
        &lt;td&gt;System.Byte&lt;/td&gt;
        &lt;td&gt;0 to 255&lt;/td&gt;
        &lt;td&gt;Unsigned 8-bit number&lt;/td&gt;
        &lt;td&gt;Yes&lt;/td&gt;
    &lt;/tr&gt;
    &lt;tr&gt;
        &lt;td&gt;short&lt;/td&gt;
        &lt;td&gt;System.Int16&lt;/td&gt;
        &lt;td&gt;-32768 to 32767&lt;/td&gt;
        &lt;td&gt;signed 16-bit number&lt;/td&gt;
        &lt;td&gt;Yes&lt;/td&gt;
    &lt;/tr&gt;
    &lt;tr&gt;
        &lt;td&gt;ushort&lt;/td&gt;
        &lt;td&gt;System.UInt16&lt;/td&gt;
        &lt;td&gt;0 to 65535&lt;/td&gt;
        &lt;td&gt;Unsigned 16-bit number&lt;/td&gt;
        &lt;td&gt;No&lt;/td&gt;
    &lt;/tr&gt;
    &lt;tr&gt;
        &lt;td&gt;int&lt;/td&gt;
        &lt;td&gt;System.Int32&lt;/td&gt;
        &lt;td&gt;–2,147,483,648 to 2,147,483,647&lt;/td&gt;
        &lt;td&gt;Signed 32-bit number&lt;/td&gt;
        &lt;td&gt;Yes&lt;/td&gt;
    &lt;/tr&gt;
    &lt;tr&gt;
        &lt;td&gt;uint&lt;/td&gt;
        &lt;td&gt;System.UInt32 &lt;/td&gt;
        &lt;td&gt;0 to 4,294,967,295&lt;/td&gt;
        &lt;td&gt;Unsigned 32-bit number&lt;/td&gt;
        &lt;td&gt;No&lt;/td&gt;
    &lt;/tr&gt;
    &lt;tr&gt;
        &lt;td&gt;long&lt;/td&gt;
        &lt;td&gt;System.Int64&lt;/td&gt;
        &lt;td&gt;–9,223,372,036,854,775,
808 to
9,223,372,036,854,775,807&lt;/td&gt;
        &lt;td&gt;Signed 64-bit to number&lt;/td&gt;
        &lt;td&gt;Yes&lt;/td&gt;
    &lt;/tr&gt;
    &lt;tr&gt;
        &lt;td&gt;ulong&lt;/td&gt;
        &lt;td&gt;System.UInt64&lt;/td&gt;
        &lt;td&gt;0 to 18,446,744,073,709,551,615&lt;/td&gt;
        &lt;td&gt;Unsigned 64-bit number&lt;/td&gt;
        &lt;td&gt;No&lt;/td&gt;
    &lt;/tr&gt;
    &lt;tr&gt;
        &lt;td&gt;char&lt;/td&gt;
        &lt;td&gt;System.Char&lt;/td&gt;
        &lt;td&gt;U+0000 to U+ffff&lt;/td&gt;
        &lt;td&gt;Single 16-bit Unicode
character&lt;/td&gt;
        &lt;td&gt;Yes&lt;/td&gt;
    &lt;/tr&gt;
    &lt;tr&gt;
        &lt;td&gt;float&lt;/td&gt;
        &lt;td&gt;System.Single&lt;/td&gt;
        &lt;td&gt;-3.4 10&lt;sup&gt;38&lt;/sup&gt; to +3.4 10&lt;sup&gt;38&lt;/sup&gt;&lt;/td&gt;
        &lt;td&gt;32-bit floating-point
number&lt;/td&gt;
        &lt;td&gt;Yes&lt;/td&gt;
    &lt;/tr&gt;
    &lt;tr&gt;
        &lt;td&gt;double&lt;/td&gt;
        &lt;td&gt;System.Double&lt;/td&gt;
        &lt;td&gt;±5.0 10&lt;sup&gt;–324&lt;/sup&gt; to ±1.7 10&lt;sup&gt;308&lt;/sup&gt;&lt;/td&gt;
        &lt;td&gt;64-bit floating-point
number&lt;/td&gt;
        &lt;td&gt;Yes&lt;/td&gt;
    &lt;/tr&gt;
    &lt;tr&gt;
        &lt;td&gt;decimal&lt;/td&gt;
        &lt;td&gt;System.Decimal&lt;/td&gt;
        &lt;td&gt;(-7.9 x 10&lt;sup&gt;28&lt;/sup&gt; to 7.9 x 10&lt;sup&gt;28&lt;/sup&gt;)/(10&lt;sup&gt;0 to 28&lt;/sup&gt;)&lt;/td&gt;
        &lt;td&gt;128-bit signed number&lt;/td&gt;
        &lt;td&gt;Yes&lt;/td&gt;
    &lt;/tr&gt;
    &lt;tr&gt;
        &lt;td&gt;string&lt;/td&gt;
        &lt;td&gt;System.String&lt;/td&gt;
        &lt;td&gt;Limited by system memory&lt;/td&gt;
        &lt;td&gt;Represents a set of
Unicode characters&lt;/td&gt;
        &lt;td&gt;Yes&lt;/td&gt;
    &lt;/tr&gt;
    &lt;tr&gt;
        &lt;td&gt;object&lt;/td&gt;
        &lt;td&gt;System.Object&lt;/td&gt;
        &lt;td&gt;Can store any data type in an
object variable&lt;/td&gt;
        &lt;td&gt;The base class of all types
in the .NET universe&lt;/td&gt;
        &lt;td&gt;Yes&lt;/td&gt;
    &lt;/tr&gt;
&lt;/table&gt;
&lt;div id="imp"&gt;CLS-compliant .NET code can be used by any managed programming
language. If you expose non–CLS-compliant data from your programs, other .NET languages might not be able
to make use of it.&lt;/div&gt;
&lt;h2&gt;Variable declaration and initialization&lt;/h2&gt;
When you are declaring a local variable (e.g., a variable within a member scope), you do so by specifying
the data type followed by the variable’s name. 
&lt;h3&gt;Syntax&lt;/h3&gt;
&lt;pre&gt;
&lt;code class="java"&gt;
datatype var_name;
&lt;/code&gt;  
&lt;/pre&gt;
&lt;h3&gt;Example&lt;/h3&gt;
&lt;pre&gt;
&lt;code class="java"&gt;
static void  Localvariable()
{
    int MyInt;
    double MyDouble;
    string MyString;
}
&lt;/code&gt;  
&lt;/pre&gt;
Be aware that it is a compiler error to make use of a local variable before assigning an initial value. Given
this, it is good practice to assign an initial value to your local data points at the time of declaration. You may
do so on a single line 
&lt;pre&gt;
&lt;code class="java"&gt;
static void  Localvariable()
{
    //datatype varName =  initialValue
    int MyInt = 0;
    double MyDouble = 10;
    string MyString = "my string";
}
&lt;/code&gt;  
&lt;/pre&gt;
or by separating the declaration and assignment into two code statements.
&lt;pre&gt;
&lt;code class="java"&gt;
static void  Localvariable()
{
    //datatype varName;
    //varName = initialValue;
    int MyInt;
    Myint = 0;
    string MyString;
    MyString = "my string";
}
&lt;/code&gt;
&lt;/pre&gt;
It is also permissible to declare multiple variables of the same underlying type on a single line of code,
as in the following three bool variables:
&lt;pre&gt;
&lt;code class="java"&gt;
static void  Localvariable()
{
    bool b1 = true, b2 = false, b3 = false;
}
&lt;/code&gt;
&lt;/pre&gt;
Since the C# &lt;strong&gt;bool&lt;/strong&gt; keyword is simply a shorthand notation for the &lt;strong&gt;System.Boolean&lt;/strong&gt; structure, it is also
possible to allocate any data type using its full name (of course, the same point holds true for any C# data
type keyword). Here is the final implementation, which illustrates various ways
to declare a local variable:
&lt;pre&gt;
&lt;code class="java"&gt;
static void  Localvariable()
{
    System.Boolean b1 = true;
    System.String str = "system string";
}   
&lt;/code&gt;
&lt;/pre&gt;
&lt;h2&gt;Example program of local variable&lt;/h2&gt;
&lt;h3&gt;Program&lt;/h3&gt;
&lt;pre&gt;
&lt;code class="java"&gt;
using System;

public class ConsoleApp
{
    public static void Main(string[] args)
    {
        Localvariable();
        Console.ReadLine();
    }

    static void  Localvariable()
    {
        //datatype varName
        int MyInt;
        double MyDouble;
        string MyString;
        //varName = initialValue
        MyInt = 5;
        MyDouble = 30;
        MyString = "my string";
        System.Boolean b1 = true;
        System.String str = "system string";
        Console.WriteLine("int: {0}",MyInt);
        Console.WriteLine("bool: {0}", b1);
        Console.WriteLine("string: {0}",str);
    }
}
&lt;/code&gt;  
  &lt;a href="https://jdoodle.com/a/h8e"&gt;&lt;button class="button"&gt;&lt;span&gt;Run &lt;/span&gt;&lt;/button&gt;&lt;/a&gt;
&lt;/pre&gt;

&lt;h3&gt;Output&lt;/h3&gt;
&lt;pre&gt;
&lt;code class="java"&gt;
int: 5
bool: True
string: system string
&lt;/code&gt;  
&lt;/pre&gt;
&lt;h2&gt;Intrinsic datatype and the &lt;strong&gt;new&lt;/strong&gt; operator&lt;/h2&gt;
All intrinsic data types support what is known as a default constructor. This feature allows
you to create a variable using the &lt;strong&gt;new&lt;/strong&gt; keyword, which automatically sets the variable to its default value.
&lt;br&gt;&lt;br&gt;
bool variables are set to false.
&lt;ul&gt;
&lt;li&gt;Numeric data is set to 0 (or 0.0 in the case of floating-point data types).&lt;/li&gt;
&lt;li&gt;char variables are set to a single empty character.&lt;/li&gt;
&lt;li&gt;Object references (including strings) are set to null.&lt;/li&gt;
&lt;/ul&gt;
It is more cumbersome to use the &lt;strong&gt;new&lt;/strong&gt; keyword when creating a basic data type variable. 
&lt;h3&gt;Program&lt;/h3&gt;
&lt;pre&gt;
&lt;code class="java"&gt;
using System;

public class ConsoleApp
{
    public static void Main(string[] args)
    {
        WithNew();
        Console.ReadLine();
    }

    static void  WithNew()
    {
        //create variable using new
        bool b = new bool();
        Console.WriteLine(b);
        int i = new int();
        Console.WriteLine(i);
        object o = new object();
        Console.WriteLine(o);
    }
}
&lt;/code&gt;  
  &lt;a href="https://jdoodle.com/a/h8k"&gt;&lt;button class="button"&gt;&lt;span&gt;Run &lt;/span&gt;&lt;/button&gt;&lt;/a&gt;
&lt;/pre&gt;

&lt;h3&gt;Output&lt;/h3&gt;
&lt;pre&gt;
&lt;code class="java"&gt;
False
0
System.Object
&lt;/code&gt;  
&lt;/pre&gt;
&lt;h2&gt;Datatype class hierarchy&lt;/h2&gt;
It is interesting to note that even the primitive .NET data types are arranged in a class hierarchy. 
The relationship between these core system types can be understood with below image:
This hierarchy based on inhatitance concept. If you are new to inheritance see the inharitance article of c#.
&lt;div class="separator" style="clear: both; text-align: center;"&gt;&lt;a href="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEgIpoQw0ug0jueAmPigVpDcy10y0pN4MIM3Y1SstALR0yTMawxoZa_hibQbv3LRSwXkUrOu8jrLzeG1aVKnDY1GWdtUqU3DzL3oT01iEu7TSb7c06kYj0x-dKgbbR4vwPHY6WIpVPaGXuQ/s1600/Capture2.PNG" imageanchor="1" style="margin-left: 1em; margin-right: 1em;"&gt;&lt;img border="0" src="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEgIpoQw0ug0jueAmPigVpDcy10y0pN4MIM3Y1SstALR0yTMawxoZa_hibQbv3LRSwXkUrOu8jrLzeG1aVKnDY1GWdtUqU3DzL3oT01iEu7TSb7c06kYj0x-dKgbbR4vwPHY6WIpVPaGXuQ/s640/Capture2.PNG" width="640" height="627" data-original-width="549" data-original-height="538" /&gt;&lt;/a&gt;&lt;/div&gt;
Notice that each type ultimately derives from System.Object.

&lt;!-- ####################################################################### --&gt;
&lt;/body&gt;
&lt;/html&gt;&lt;/div&gt;
</description><link>http://tangled-java.blogspot.com/2017/12/datatype-and-keyword.html</link><author>noreply@blogger.com (Anonymous)</author><media:thumbnail xmlns:media="http://search.yahoo.com/mrss/" height="72" url="https://blogger.googleusercontent.com/img/proxy/AVvXsEiFv-rPnZkgs0jexkl3m9JjFAGNoP1V8rTOgCtbWqFTgKAwQ70V6Q18rYBwRupk7wIXBcw67aqoxQbozpjPGMNdJGsGKVjg3b1k104S3IvKHlzJu3m9O824Ffv4-azvhJ3tDwnHplLw5dnvTiWw2kOyGg=s72-w128-h128-c-p-k-no-nu" width="72"/><thr:total>1</thr:total></item><item><guid isPermaLink="false">tag:blogger.com,1999:blog-3082064622906880860.post-3749332344180005559</guid><pubDate>Tue, 12 Dec 2017 18:02:00 +0000</pubDate><atom:updated>2017-12-12T10:02:19.536-08:00</atom:updated><category domain="http://www.blogger.com/atom/ns#">formating numbers</category><category domain="http://www.blogger.com/atom/ns#">System.console</category><title>System.Console</title><description>&lt;div dir="ltr" style="text-align: left;" trbidi="on"&gt;
&lt;html&gt;
&lt;head&gt;
 &lt;title&gt;&lt;/title&gt;
&lt;style&gt; 
strong{ color: #333; }
table {
    border-collapse: collapse;
    border-spacing: 0;
    width: 100%;
    border: 1px solid #ddd;
}

th, td {
    border: none;
    text-align: left;
    padding: 8px;
}

tr:nth-child(even){background-color: #f2f2f2}
@media only screen and (min-width: 800px){#dotnet{width: 20%; }}
&lt;/style&gt;
&lt;script type="text/javascript"&gt;
 /*! highlight.js v9.12.0 | BSD3 License | git.io/hljslicense */
!function(e){var n="object"==typeof window&amp;&amp;window||"object"==typeof self&amp;&amp;self;"undefined"!=typeof exports?e(exports):n&amp;&amp;(n.hljs=e({}),"function"==typeof define&amp;&amp;define.amd&amp;&amp;define([],function(){return n.hljs}))}(function(e){function n(e){return e.replace(/&amp;/g,"&amp;amp;").replace(/&lt;/g,"&amp;lt;").replace(/&gt;/g,"&amp;gt;")}function t(e){return e.nodeName.toLowerCase()}function r(e,n){var t=e&amp;&amp;e.exec(n);return t&amp;&amp;0===t.index}function a(e){return k.test(e)}function i(e){var n,t,r,i,o=e.className+" ";if(o+=e.parentNode?e.parentNode.className:"",t=B.exec(o))return w(t[1])?t[1]:"no-highlight";for(o=o.split(/\s+/),n=0,r=o.length;r&gt;n;n++)if(i=o[n],a(i)||w(i))return i}function o(e){var n,t={},r=Array.prototype.slice.call(arguments,1);for(n in e)t[n]=e[n];return r.forEach(function(e){for(n in e)t[n]=e[n]}),t}function u(e){var n=[];return function r(e,a){for(var i=e.firstChild;i;i=i.nextSibling)3===i.nodeType?a+=i.nodeValue.length:1===i.nodeType&amp;&amp;(n.push({event:"start",offset:a,node:i}),a=r(i,a),t(i).match(/br|hr|img|input/)||n.push({event:"stop",offset:a,node:i}));return a}(e,0),n}function c(e,r,a){function i(){return e.length&amp;&amp;r.length?e[0].offset!==r[0].offset?e[0].offset&lt;r[0].offset?e:r:"start"===r[0].event?e:r:e.length?e:r}function o(e){function r(e){return" "+e.nodeName+'="'+n(e.value).replace('"',"&amp;quot;")+'"'}s+="&lt;"+t(e)+E.map.call(e.attributes,r).join("")+"&gt;"}function u(e){s+="&lt;/"+t(e)+"&gt;"}function c(e){("start"===e.event?o:u)(e.node)}for(var l=0,s="",f=[];e.length||r.length;){var g=i();if(s+=n(a.substring(l,g[0].offset)),l=g[0].offset,g===e){f.reverse().forEach(u);do c(g.splice(0,1)[0]),g=i();while(g===e&amp;&amp;g.length&amp;&amp;g[0].offset===l);f.reverse().forEach(o)}else"start"===g[0].event?f.push(g[0].node):f.pop(),c(g.splice(0,1)[0])}return s+n(a.substr(l))}function l(e){return e.v&amp;&amp;!e.cached_variants&amp;&amp;(e.cached_variants=e.v.map(function(n){return o(e,{v:null},n)})),e.cached_variants||e.eW&amp;&amp;[o(e)]||[e]}function s(e){function n(e){return e&amp;&amp;e.source||e}function t(t,r){return new RegExp(n(t),"m"+(e.cI?"i":"")+(r?"g":""))}function r(a,i){if(!a.compiled){if(a.compiled=!0,a.k=a.k||a.bK,a.k){var o={},u=function(n,t){e.cI&amp;&amp;(t=t.toLowerCase()),t.split(" ").forEach(function(e){var t=e.split("|");o[t[0]]=[n,t[1]?Number(t[1]):1]})};"string"==typeof a.k?u("keyword",a.k):x(a.k).forEach(function(e){u(e,a.k[e])}),a.k=o}a.lR=t(a.l||/\w+/,!0),i&amp;&amp;(a.bK&amp;&amp;(a.b="\\b("+a.bK.split(" ").join("|")+")\\b"),a.b||(a.b=/\B|\b/),a.bR=t(a.b),a.e||a.eW||(a.e=/\B|\b/),a.e&amp;&amp;(a.eR=t(a.e)),a.tE=n(a.e)||"",a.eW&amp;&amp;i.tE&amp;&amp;(a.tE+=(a.e?"|":"")+i.tE)),a.i&amp;&amp;(a.iR=t(a.i)),null==a.r&amp;&amp;(a.r=1),a.c||(a.c=[]),a.c=Array.prototype.concat.apply([],a.c.map(function(e){return l("self"===e?a:e)})),a.c.forEach(function(e){r(e,a)}),a.starts&amp;&amp;r(a.starts,i);var c=a.c.map(function(e){return e.bK?"\\.?("+e.b+")\\.?":e.b}).concat([a.tE,a.i]).map(n).filter(Boolean);a.t=c.length?t(c.join("|"),!0):{exec:function(){return null}}}}r(e)}function f(e,t,a,i){function o(e,n){var t,a;for(t=0,a=n.c.length;a&gt;t;t++)if(r(n.c[t].bR,e))return n.c[t]}function u(e,n){if(r(e.eR,n)){for(;e.endsParent&amp;&amp;e.parent;)e=e.parent;return e}return e.eW?u(e.parent,n):void 0}function c(e,n){return!a&amp;&amp;r(n.iR,e)}function l(e,n){var t=N.cI?n[0].toLowerCase():n[0];return e.k.hasOwnProperty(t)&amp;&amp;e.k[t]}function p(e,n,t,r){var a=r?"":I.classPrefix,i='&lt;span class="'+a,o=t?"":C;return i+=e+'"&gt;',i+n+o}function h(){var e,t,r,a;if(!E.k)return n(k);for(a="",t=0,E.lR.lastIndex=0,r=E.lR.exec(k);r;)a+=n(k.substring(t,r.index)),e=l(E,r),e?(B+=e[1],a+=p(e[0],n(r[0]))):a+=n(r[0]),t=E.lR.lastIndex,r=E.lR.exec(k);return a+n(k.substr(t))}function d(){var e="string"==typeof E.sL;if(e&amp;&amp;!y[E.sL])return n(k);var t=e?f(E.sL,k,!0,x[E.sL]):g(k,E.sL.length?E.sL:void 0);return E.r&gt;0&amp;&amp;(B+=t.r),e&amp;&amp;(x[E.sL]=t.top),p(t.language,t.value,!1,!0)}function b(){L+=null!=E.sL?d():h(),k=""}function v(e){L+=e.cN?p(e.cN,"",!0):"",E=Object.create(e,{parent:{value:E}})}function m(e,n){if(k+=e,null==n)return b(),0;var t=o(n,E);if(t)return t.skip?k+=n:(t.eB&amp;&amp;(k+=n),b(),t.rB||t.eB||(k=n)),v(t,n),t.rB?0:n.length;var r=u(E,n);if(r){var a=E;a.skip?k+=n:(a.rE||a.eE||(k+=n),b(),a.eE&amp;&amp;(k=n));do E.cN&amp;&amp;(L+=C),E.skip||(B+=E.r),E=E.parent;while(E!==r.parent);return r.starts&amp;&amp;v(r.starts,""),a.rE?0:n.length}if(c(n,E))throw new Error('Illegal lexeme "'+n+'" for mode "'+(E.cN||"&lt;unnamed&gt;")+'"');return k+=n,n.length||1}var N=w(e);if(!N)throw new Error('Unknown language: "'+e+'"');s(N);var R,E=i||N,x={},L="";for(R=E;R!==N;R=R.parent)R.cN&amp;&amp;(L=p(R.cN,"",!0)+L);var k="",B=0;try{for(var M,j,O=0;;){if(E.t.lastIndex=O,M=E.t.exec(t),!M)break;j=m(t.substring(O,M.index),M[0]),O=M.index+j}for(m(t.substr(O)),R=E;R.parent;R=R.parent)R.cN&amp;&amp;(L+=C);return{r:B,value:L,language:e,top:E}}catch(T){if(T.message&amp;&amp;-1!==T.message.indexOf("Illegal"))return{r:0,value:n(t)};throw T}}function g(e,t){t=t||I.languages||x(y);var r={r:0,value:n(e)},a=r;return t.filter(w).forEach(function(n){var t=f(n,e,!1);t.language=n,t.r&gt;a.r&amp;&amp;(a=t),t.r&gt;r.r&amp;&amp;(a=r,r=t)}),a.language&amp;&amp;(r.second_best=a),r}function p(e){return I.tabReplace||I.useBR?e.replace(M,function(e,n){return I.useBR&amp;&amp;"\n"===e?"&lt;br&gt;":I.tabReplace?n.replace(/\t/g,I.tabReplace):""}):e}function h(e,n,t){var r=n?L[n]:t,a=[e.trim()];return e.match(/\bhljs\b/)||a.push("hljs"),-1===e.indexOf(r)&amp;&amp;a.push(r),a.join(" ").trim()}function d(e){var n,t,r,o,l,s=i(e);a(s)||(I.useBR?(n=document.createElementNS("http://www.w3.org/1999/xhtml","div"),n.innerHTML=e.innerHTML.replace(/\n/g,"").replace(/&lt;br[ \/]*&gt;/g,"\n")):n=e,l=n.textContent,r=s?f(s,l,!0):g(l),t=u(n),t.length&amp;&amp;(o=document.createElementNS("http://www.w3.org/1999/xhtml","div"),o.innerHTML=r.value,r.value=c(t,u(o),l)),r.value=p(r.value),e.innerHTML=r.value,e.className=h(e.className,s,r.language),e.result={language:r.language,re:r.r},r.second_best&amp;&amp;(e.second_best={language:r.second_best.language,re:r.second_best.r}))}function b(e){I=o(I,e)}function v(){if(!v.called){v.called=!0;var e=document.querySelectorAll("pre code");E.forEach.call(e,d)}}function m(){addEventListener("DOMContentLoaded",v,!1),addEventListener("load",v,!1)}function N(n,t){var r=y[n]=t(e);r.aliases&amp;&amp;r.aliases.forEach(function(e){L[e]=n})}function R(){return x(y)}function w(e){return e=(e||"").toLowerCase(),y[e]||y[L[e]]}var E=[],x=Object.keys,y={},L={},k=/^(no-?highlight|plain|text)$/i,B=/\blang(?:uage)?-([\w-]+)\b/i,M=/((^(&lt;[^&gt;]+&gt;|\t|)+|(?:\n)))/gm,C="&lt;/span&gt;",I={classPrefix:"hljs-",tabReplace:null,useBR:!1,languages:void 0};return e.highlight=f,e.highlightAuto=g,e.fixMarkup=p,e.highlightBlock=d,e.configure=b,e.initHighlighting=v,e.initHighlightingOnLoad=m,e.registerLanguage=N,e.listLanguages=R,e.getLanguage=w,e.inherit=o,e.IR="[a-zA-Z]\\w*",e.UIR="[a-zA-Z_]\\w*",e.NR="\\b\\d+(\\.\\d+)?",e.CNR="(-?)(\\b0[xX][a-fA-F0-9]+|(\\b\\d+(\\.\\d*)?|\\.\\d+)([eE][-+]?\\d+)?)",e.BNR="\\b(0b[01]+)",e.RSR="!|!=|!==|%|%=|&amp;|&amp;&amp;|&amp;=|\\*|\\*=|\\+|\\+=|,|-|-=|/=|/|:|;|&lt;&lt;|&lt;&lt;=|&lt;=|&lt;|===|==|=|&gt;&gt;&gt;=|&gt;&gt;=|&gt;=|&gt;&gt;&gt;|&gt;&gt;|&gt;|\\?|\\[|\\{|\\(|\\^|\\^=|\\||\\|=|\\|\\||~",e.BE={b:"\\\\[\\s\\S]",r:0},e.ASM={cN:"string",b:"'",e:"'",i:"\\n",c:[e.BE]},e.QSM={cN:"string",b:'"',e:'"',i:"\\n",c:[e.BE]},e.PWM={b:/\b(a|an|the|are|I'm|isn't|don't|doesn't|won't|but|just|should|pretty|simply|enough|gonna|going|wtf|so|such|will|you|your|they|like|more)\b/},e.C=function(n,t,r){var a=e.inherit({cN:"comment",b:n,e:t,c:[]},r||{});return a.c.push(e.PWM),a.c.push({cN:"doctag",b:"(?:TODO|FIXME|NOTE|BUG|XXX):",r:0}),a},e.CLCM=e.C("//","$"),e.CBCM=e.C("/\\*","\\*/"),e.HCM=e.C("#","$"),e.NM={cN:"number",b:e.NR,r:0},e.CNM={cN:"number",b:e.CNR,r:0},e.BNM={cN:"number",b:e.BNR,r:0},e.CSSNM={cN:"number",b:e.NR+"(%|em|ex|ch|rem|vw|vh|vmin|vmax|cm|mm|in|pt|pc|px|deg|grad|rad|turn|s|ms|Hz|kHz|dpi|dpcm|dppx)?",r:0},e.RM={cN:"regexp",b:/\//,e:/\/[gimuy]*/,i:/\n/,c:[e.BE,{b:/\[/,e:/\]/,r:0,c:[e.BE]}]},e.TM={cN:"title",b:e.IR,r:0},e.UTM={cN:"title",b:e.UIR,r:0},e.METHOD_GUARD={b:"\\.\\s*"+e.UIR,r:0},e});hljs.registerLanguage("java",function(e){var a="[À-ʸa-zA-Z_$][À-ʸa-zA-Z_$0-9]*",t=a+"(&lt;"+a+"(\\s*,\\s*"+a+")*&gt;)?",r="false synchronized int abstract float private char boolean static null if const for true while long strictfp finally protected import native final void enum else break transient catch instanceof byte super volatile case assert short package default double public try this switch continue throws protected public private module requires exports do",s="\\b(0[bB]([01]+[01_]+[01]+|[01]+)|0[xX]([a-fA-F0-9]+[a-fA-F0-9_]+[a-fA-F0-9]+|[a-fA-F0-9]+)|(([\\d]+[\\d_]+[\\d]+|[\\d]+)(\\.([\\d]+[\\d_]+[\\d]+|[\\d]+))?|\\.([\\d]+[\\d_]+[\\d]+|[\\d]+))([eE][-+]?\\d+)?)[lLfF]?",c={cN:"number",b:s,r:0};return{aliases:["jsp"],k:r,i:/&lt;\/|#/,c:[e.C("/\\*\\*","\\*/",{r:0,c:[{b:/\w+@/,r:0},{cN:"doctag",b:"@[A-Za-z]+"}]}),e.CLCM,e.CBCM,e.ASM,e.QSM,{cN:"class",bK:"class interface",e:/[{;=]/,eE:!0,k:"class interface",i:/[:"\[\]]/,c:[{bK:"extends implements"},e.UTM]},{bK:"new throw return else",r:0},{cN:"function",b:"("+t+"\\s+)+"+e.UIR+"\\s*\\(",rB:!0,e:/[{;=]/,eE:!0,k:r,c:[{b:e.UIR+"\\s*\\(",rB:!0,r:0,c:[e.UTM]},{cN:"params",b:/\(/,e:/\)/,k:r,r:0,c:[e.ASM,e.QSM,e.CNM,e.CBCM]},e.CLCM,e.CBCM]},c,{cN:"meta",b:"@[A-Za-z]+"}]}});
&lt;/script&gt;
&lt;script&gt;hljs.initHighlightingOnLoad();&lt;/script&gt;
&lt;/head&gt;
&lt;body onload="selectdotnet()"&gt;
&lt;div id="topics"&gt;&lt;/div&gt;
&lt;img src="https://blogger.googleusercontent.com/img/proxy/AVvXsEiFv-rPnZkgs0jexkl3m9JjFAGNoP1V8rTOgCtbWqFTgKAwQ70V6Q18rYBwRupk7wIXBcw67aqoxQbozpjPGMNdJGsGKVjg3b1k104S3IvKHlzJu3m9O824Ffv4-azvhJ3tDwnHplLw5dnvTiWw2kOyGg=w128-h128-p-k-no-nu" style="display: none;"/&gt;
&lt;!-- ####################################################################### --&gt;
It is true that a console user interface (CUI) may not be
as enticing as a graphical user interface (GUI) or web application, restricting the early examples to console
programs will allow you to keep focused on the syntax of C# and the core aspects of the .NET platform, rather
than dealing with the complexities of building desktop GUIs or web sites.As its name implies, the Console class encapsulates &lt;strong&gt;input, output, and error-stream&lt;/strong&gt; manipulations
for console-based applications.
&lt;br&gt;&lt;br&gt;
 As you can see in below table the &lt;strong&gt;Console&lt;/strong&gt; class does provide some members that can spice up a simple command-line
application, such as the ability to change background and foreground colors and issue beep noises
in a variety of frequencies.
&lt;h2&gt;Members of System.Console&lt;/h2&gt;
&lt;table&gt;
    &lt;tr&gt;
        &lt;th&gt;Member&lt;/th&gt;
        &lt;th&gt;Meaning&lt;/th&gt;
    &lt;/tr&gt;
    &lt;tr&gt;
        &lt;td&gt;Beep() &lt;/td&gt;
        &lt;td&gt;This method forces the console to emit a beep of a specified frequency and
duration.&lt;/td&gt;
    &lt;/tr&gt;
    &lt;tr&gt;
        &lt;td&gt;BackgroundColor,ForegroundColor&lt;/td&gt;
        &lt;td&gt;These properties set the background/foreground colors for the current output.They may be assigned any member of the ConsoleColor enumeration.&lt;/td&gt;
    &lt;/tr&gt;
    &lt;tr&gt;
        &lt;td&gt;BufferHeight,BufferWidth&lt;/td&gt;
        &lt;td&gt;These properties control the height/width of the console’s buffer area&lt;/td&gt;
    &lt;/tr&gt;
    &lt;tr&gt;
        &lt;td&gt;Title&lt;/td&gt;
        &lt;td&gt;This property gets or sets the title of the current console.&lt;/td&gt;
    &lt;/tr&gt;
    &lt;tr&gt;
        &lt;td&gt;WindowHeight, WindowWidth, WindowTop, WindowLeft&lt;/td&gt;
        &lt;td&gt;These properties control the dimensions of the console in relation to the
established buffer.&lt;/td&gt;
    &lt;/tr&gt;
    &lt;tr&gt;
        &lt;td&gt;Clear()&lt;/td&gt;
        &lt;td&gt;This method clears the established buffer and console display area.&lt;/td&gt;
    &lt;/tr&gt;
&lt;/table&gt;&lt;br&gt;
&lt;h2&gt;Basic Input-Output&lt;/h2&gt;
In addition to the members in above Table, the &lt;strong&gt;Console&lt;/strong&gt; type defines a set of methods to capture input and
output, all of which are static and are, therefore, called by prefixing the name of the class (Console) to the
method name. As you know, &lt;strong&gt;WriteLine()&lt;/strong&gt; pumps a text string &lt;strong&gt;(including a carriage return)&lt;/strong&gt; to the output
stream. The &lt;strong&gt;Write()&lt;/strong&gt; method pumps text to the output stream without a carriage return. &lt;strong&gt;ReadLine()&lt;/strong&gt; allows
you to receive information from the input stream up until the Enter key is pressed, while &lt;strong&gt;Read()&lt;/strong&gt; is used to
capture a single character from the input stream.
&lt;br&gt;&lt;br&gt;
Create a new Console Application project to understand basic I/O using the Console class and update your Main() method to call a helper method named GetInfo().Implement this method within the Program class with logic that prompts the user for some bits of
information and echoes each item to the standard output stream. For example, you could ask the user for a
name and age which will be treated as a text value for simplicity, rather than the expected numerical value
for now.
&lt;h3&gt;Program&lt;/h3&gt;
&lt;pre&gt;
&lt;code class="java"&gt;
using System;

public class ConsoleApp
{
    public static void Main(string[] args)
    {
        GetInfo();
        Console.ReadLine();
    }

    static void GetInfo()
    {
        //read the data and store it in variable age and name
        Console.Write("Enter your name: ");
        string name = Console.ReadLine();
        Console.Write("Enter your age: ");
        string age = Console.ReadLine();

        //chnages the console color 
        ConsoleColor PrevColor = Console.BackgroundColor;
        Console.BackgroundColor = ConsoleColor.Red;

        Console.WriteLine("Name: {0}", name);
        Console.WriteLine("Age: {0}", age);

        //changes the console color again
        Console.BackgroundColor = ConsoleColor.Black;
    }
}
&lt;/code&gt;  
  &lt;a href="https://jdoodle.com/a/gR1"&gt;&lt;button class="button"&gt;&lt;span&gt;Run &lt;/span&gt;&lt;/button&gt;&lt;/a&gt;
&lt;/pre&gt;

&lt;h3&gt;Output&lt;/h3&gt;
&lt;pre&gt;
&lt;code class="java"&gt;
Enter your name: Hansraj
Enter your age: 20
&lt;span style="background-color: red;"&gt;Name: Hansraj&lt;/span&gt;
&lt;span style="background-color: red;"&gt;Age: 20&lt;/span&gt;
&lt;/code&gt;  
&lt;/pre&gt;
&lt;div id="imp"&gt;
Visual Studio supports a number of “code snippets” that will insert code once activated. The cw code
snippet is quite useful. In that it will automatically expand to Console.
WriteLine()! To test this for yourself, type in cw somewhere within your Main() method and hit the Tab key
twice. sadly, there is no code snippet for Console.ReadLine()). To see all code snippets, right-click in a C# code file and choose the Insert Snippet menu option.
&lt;/div&gt;
&lt;h2&gt;Formatting Console output&lt;/h2&gt;
You might have noticed numerous occurrences of tokens such as &lt;strong&gt;{0}&lt;/strong&gt;
and &lt;strong&gt;{1}&lt;/strong&gt; embedded within various string literals. The .NET platform supports a style of string formatting
slightly akin to the printf() statement of C. Simply put, when you are defining a string literal that contains
segments of data whose value is not known until runtime, you are able to specify a placeholder within
the literal using this curly-bracket syntax. At runtime, the values passed into Console.WriteLine() are
substituted for each placeholder.
The first parameter to WriteLine() represents a string literal that contains optional placeholders
designated by {0}, {1}, {2}, and so forth. Be aware that the first ordinal number of a curly-bracket
placeholder always begins with 0. The remaining parameters to WriteLine() are simply the values to be
inserted into the respective placeholders.
&lt;br&gt;&lt;br&gt;
 If you have more uniquely numbered curly-bracket placeholders than fill arguments, you will receive
a format exception at runtime. However, if you have more fill arguments than placeholders, the unused fill
arguments are ignored.
&lt;br&gt;&lt;br&gt;
It is permissible for a given placeholder to repeat within a given string. For example
&lt;h3&gt;Program&lt;/h3&gt;
&lt;pre&gt;
&lt;code class="java"&gt;
using System;

public class ConsoleApp
{
    public static void Main(string[] args)
    {
        Console.WriteLine("{0}? I love {0}, I love to code in {0}", ".NET");
        Console.ReadLine();
    }
}
&lt;/code&gt;  
  &lt;a href="https://jdoodle.com/a/gR3"&gt;&lt;button class="button"&gt;&lt;span&gt;Run &lt;/span&gt;&lt;/button&gt;&lt;/a&gt;
&lt;/pre&gt;

&lt;h3&gt;Output&lt;/h3&gt;
&lt;pre&gt;
&lt;code class="java"&gt;
.NET? I love .NET, I love to code in .NET
&lt;/code&gt;  
&lt;/pre&gt;
Also, know that it is possible to position each placeholder in any location within a string literal, and it
need not follow an increasing sequence. For example,
&lt;h3&gt;Program&lt;/h3&gt;
&lt;pre&gt;
&lt;code class="java"&gt;
using System;

public class ConsoleApp
{
    public static void Main(string[] args)
    {
        Console.WriteLine("I am {1}.My age is {0}",20,"Hansraj");
        Console.ReadLine();
    }
}
&lt;/code&gt;  
  &lt;a href="https://jdoodle.com/a/gR4"&gt;&lt;button class="button"&gt;&lt;span&gt;Run &lt;/span&gt;&lt;/button&gt;&lt;/a&gt;
&lt;/pre&gt;

&lt;h3&gt;Output&lt;/h3&gt;
&lt;pre&gt;
&lt;code class="java"&gt;
I am Hansraj.My age is 20
&lt;/code&gt;  
&lt;/pre&gt;
&lt;h2&gt;Formatting numerical data in C#&lt;/h2&gt;
If you require more elaborate formatting for numerical data, each placeholder can optionally contain
various format characters.Various format characters are given below:
&lt;table&gt;
    &lt;tr&gt;
        &lt;th&gt;Format character&lt;/th&gt;
        &lt;th&gt;Meaning&lt;/th&gt;
    &lt;/tr&gt;
    &lt;tr&gt;
        &lt;td&gt;C or C&lt;/td&gt;
        &lt;td&gt;Used to format currency. By default, the flag will prefix the local cultural
symbol (a dollar sign [$] for U.S. English)
&lt;/td&gt;
    &lt;/tr&gt;
    &lt;tr&gt;
        &lt;td&gt;D or d&lt;/td&gt;
        &lt;td&gt;Used to format decimal numbers. This flag may also specify the minimum
number of digits used to pad the value&lt;/td&gt;
    &lt;/tr&gt;
    &lt;tr&gt;
        &lt;td&gt;E or e&lt;/td&gt;
        &lt;td&gt;Used for exponential notation. Casing controls whether the exponential
constant is uppercase (E) or lowercase (e)&lt;/td&gt;
    &lt;/tr&gt;
    &lt;tr&gt;
        &lt;td&gt;F or f&lt;/td&gt;
        &lt;td&gt;Used for fixed-point formatting. This flag may also specify the minimum
number of digits used to pad the value&lt;/td&gt;
    &lt;/tr&gt;
    &lt;tr&gt;
        &lt;td&gt;G or g&lt;/td&gt;
        &lt;td&gt;Stands for general. This character can be used to format a number to fixed or
exponential format&lt;/td&gt;
    &lt;/tr&gt;
    &lt;tr&gt;
        &lt;td&gt;N or n&lt;/td&gt;
        &lt;td&gt;Used for basic numerical formatting (with commas)&lt;/td&gt;
    &lt;/tr&gt;
    &lt;tr&gt;
        &lt;td&gt;X or x&lt;/td&gt;
        &lt;td&gt;Used for hexadecimal formatting. If you use an uppercase X, your hex format
will also contain uppercase characters&lt;/td&gt;
    &lt;/tr&gt;
&lt;/table&gt;
&lt;h3&gt;Program&lt;/h3&gt;
&lt;pre&gt;
&lt;code class="java"&gt;
using System;

public class ConsoleApp
{
    public static void Main(string[] args)
    {
        Console.WriteLine("Currency format: {0:c}", 1000);
        Console.WriteLine("Decimal format: {0:d6}", 9999);
        Console.WriteLine("Exponential upper: {0:E}", 9999);
        Console.WriteLine("Exponential lower: {0:e}", 9999);
        Console.WriteLine("Fixed point: {0:f3}",9999.12345);
        Console.WriteLine("Genralformat: {0:g3}",9999.12345);
        Console.WriteLine("Hex format upper: {0:X}",9999);
        Console.WriteLine("Hex format lower: {0:x}",9999);
        Console.ReadLine();
    }
}
&lt;/code&gt;  
  &lt;a href="https://jdoodle.com/a/h54"&gt;&lt;button class="button"&gt;&lt;span&gt;Run &lt;/span&gt;&lt;/button&gt;&lt;/a&gt;
&lt;/pre&gt;

&lt;h3&gt;Output&lt;/h3&gt;
&lt;pre&gt;
&lt;code class="java"&gt;
Currency format: ¤1,000.00
Decimal format: 009999
Exponential upper: 9.999000E+003
Exponential lower: 9.999000e+003
Fixed point: 9999.123
Genralformat: 1e+04
Hex format upper: 270F
Hex format lower: 270f
&lt;/code&gt;  
&lt;/pre&gt;
 Be aware that the use of the .NET string formatting characters is not limited to console
programs. This same formatting syntax can be used when calling the static string.Format() method. This
can be helpful when you need to compose textual data at runtime for use in any application type (e.g.,
desktop GUI app, ASP.NET web app, and so forth).&lt;br&gt;&lt;br&gt;
The string.Format() method returns a new string object, which is formatted according to the
provided flags. After this point, you are free to use the textual data as you see fit. For example, assume you are
building a graphical WPF desktop application and need to format a string for display in a message box. The
following code illustrates how to do so, but be aware that this code will not compile until you reference the
&lt;strong&gt;PresentationFramework.dll&lt;/strong&gt; assembly.
&lt;br&gt;&lt;br&gt;
To reference &lt;strong&gt;PresentationFramework.dll&lt;/strong&gt; click on &lt;strong&gt;Project&lt;/strong&gt;&amp;gt;&lt;strong&gt;Add reference..&lt;/strong&gt;&amp;gt;choose the library which you want to add in your program&lt;br&gt;&lt;br&gt;
For now add &lt;strong&gt;PresentationFramework.dll&lt;/strong&gt; in your program.
&lt;h3&gt;Program&lt;/h3&gt;
&lt;pre&gt;
&lt;code class="java"&gt;
using System;

public class ConsoleApp
{
    public static void Main(string[] args)
    {
        //use string.Format() to format string literal
        string msg = string.Format("Hex value of 9999 is {0:f}",9999);
        /*You need to reference PresentationFramework.dll 
         * in order to compile this line of code! */
        System.Windows.MessageBox.Show(msg);
    }
}
&lt;/code&gt;  
  &lt;a href=""&gt;&lt;button class="button"&gt;&lt;span&gt;Run &lt;/span&gt;&lt;/button&gt;&lt;/a&gt;
&lt;/pre&gt;

To see the output copy this program in visual studio.Don't forget to add &lt;strong&gt;PresentationFramework.dll&lt;/strong&gt; library and run the program.
&lt;!-- ####################################################################### --&gt;
&lt;/body&gt;
&lt;/html&gt;&lt;/div&gt;
</description><link>http://tangled-java.blogspot.com/2017/12/systemconsole.html</link><author>noreply@blogger.com (Anonymous)</author><media:thumbnail xmlns:media="http://search.yahoo.com/mrss/" height="72" url="https://blogger.googleusercontent.com/img/proxy/AVvXsEiFv-rPnZkgs0jexkl3m9JjFAGNoP1V8rTOgCtbWqFTgKAwQ70V6Q18rYBwRupk7wIXBcw67aqoxQbozpjPGMNdJGsGKVjg3b1k104S3IvKHlzJu3m9O824Ffv4-azvhJ3tDwnHplLw5dnvTiWw2kOyGg=s72-w128-h128-c-p-k-no-nu" width="72"/><thr:total>0</thr:total></item><item><guid isPermaLink="false">tag:blogger.com,1999:blog-3082064622906880860.post-3723657457206740655</guid><pubDate>Sun, 10 Dec 2017 16:27:00 +0000</pubDate><atom:updated>2017-12-10T08:42:15.582-08:00</atom:updated><category domain="http://www.blogger.com/atom/ns#">System.Environment</category><title>System.Environment</title><description>&lt;div dir="ltr" style="text-align: left;" trbidi="on"&gt;
&lt;html&gt;
&lt;head&gt;
 &lt;title&gt;&lt;/title&gt;
&lt;style&gt; 
strong{ color: white; }
table {
    border-collapse: collapse;
    border-spacing: 0;
    width: 100%;
    border: 1px solid #ddd;
}

th, td {
    border: none;
    text-align: left;
    padding: 8px;
}

tr:nth-child(even){background-color: #f2f2f2; color: #333;}
@media only screen and (min-width: 800px){#dotnet{width: 20%; }}
&lt;/style&gt;
&lt;script type="text/javascript"&gt;
 /*! highlight.js v9.12.0 | BSD3 License | git.io/hljslicense */
!function(e){var n="object"==typeof window&amp;&amp;window||"object"==typeof self&amp;&amp;self;"undefined"!=typeof exports?e(exports):n&amp;&amp;(n.hljs=e({}),"function"==typeof define&amp;&amp;define.amd&amp;&amp;define([],function(){return n.hljs}))}(function(e){function n(e){return e.replace(/&amp;/g,"&amp;amp;").replace(/&lt;/g,"&amp;lt;").replace(/&gt;/g,"&amp;gt;")}function t(e){return e.nodeName.toLowerCase()}function r(e,n){var t=e&amp;&amp;e.exec(n);return t&amp;&amp;0===t.index}function a(e){return k.test(e)}function i(e){var n,t,r,i,o=e.className+" ";if(o+=e.parentNode?e.parentNode.className:"",t=B.exec(o))return w(t[1])?t[1]:"no-highlight";for(o=o.split(/\s+/),n=0,r=o.length;r&gt;n;n++)if(i=o[n],a(i)||w(i))return i}function o(e){var n,t={},r=Array.prototype.slice.call(arguments,1);for(n in e)t[n]=e[n];return r.forEach(function(e){for(n in e)t[n]=e[n]}),t}function u(e){var n=[];return function r(e,a){for(var i=e.firstChild;i;i=i.nextSibling)3===i.nodeType?a+=i.nodeValue.length:1===i.nodeType&amp;&amp;(n.push({event:"start",offset:a,node:i}),a=r(i,a),t(i).match(/br|hr|img|input/)||n.push({event:"stop",offset:a,node:i}));return a}(e,0),n}function c(e,r,a){function i(){return e.length&amp;&amp;r.length?e[0].offset!==r[0].offset?e[0].offset&lt;r[0].offset?e:r:"start"===r[0].event?e:r:e.length?e:r}function o(e){function r(e){return" "+e.nodeName+'="'+n(e.value).replace('"',"&amp;quot;")+'"'}s+="&lt;"+t(e)+E.map.call(e.attributes,r).join("")+"&gt;"}function u(e){s+="&lt;/"+t(e)+"&gt;"}function c(e){("start"===e.event?o:u)(e.node)}for(var l=0,s="",f=[];e.length||r.length;){var g=i();if(s+=n(a.substring(l,g[0].offset)),l=g[0].offset,g===e){f.reverse().forEach(u);do c(g.splice(0,1)[0]),g=i();while(g===e&amp;&amp;g.length&amp;&amp;g[0].offset===l);f.reverse().forEach(o)}else"start"===g[0].event?f.push(g[0].node):f.pop(),c(g.splice(0,1)[0])}return s+n(a.substr(l))}function l(e){return e.v&amp;&amp;!e.cached_variants&amp;&amp;(e.cached_variants=e.v.map(function(n){return o(e,{v:null},n)})),e.cached_variants||e.eW&amp;&amp;[o(e)]||[e]}function s(e){function n(e){return e&amp;&amp;e.source||e}function t(t,r){return new RegExp(n(t),"m"+(e.cI?"i":"")+(r?"g":""))}function r(a,i){if(!a.compiled){if(a.compiled=!0,a.k=a.k||a.bK,a.k){var o={},u=function(n,t){e.cI&amp;&amp;(t=t.toLowerCase()),t.split(" ").forEach(function(e){var t=e.split("|");o[t[0]]=[n,t[1]?Number(t[1]):1]})};"string"==typeof a.k?u("keyword",a.k):x(a.k).forEach(function(e){u(e,a.k[e])}),a.k=o}a.lR=t(a.l||/\w+/,!0),i&amp;&amp;(a.bK&amp;&amp;(a.b="\\b("+a.bK.split(" ").join("|")+")\\b"),a.b||(a.b=/\B|\b/),a.bR=t(a.b),a.e||a.eW||(a.e=/\B|\b/),a.e&amp;&amp;(a.eR=t(a.e)),a.tE=n(a.e)||"",a.eW&amp;&amp;i.tE&amp;&amp;(a.tE+=(a.e?"|":"")+i.tE)),a.i&amp;&amp;(a.iR=t(a.i)),null==a.r&amp;&amp;(a.r=1),a.c||(a.c=[]),a.c=Array.prototype.concat.apply([],a.c.map(function(e){return l("self"===e?a:e)})),a.c.forEach(function(e){r(e,a)}),a.starts&amp;&amp;r(a.starts,i);var c=a.c.map(function(e){return e.bK?"\\.?("+e.b+")\\.?":e.b}).concat([a.tE,a.i]).map(n).filter(Boolean);a.t=c.length?t(c.join("|"),!0):{exec:function(){return null}}}}r(e)}function f(e,t,a,i){function o(e,n){var t,a;for(t=0,a=n.c.length;a&gt;t;t++)if(r(n.c[t].bR,e))return n.c[t]}function u(e,n){if(r(e.eR,n)){for(;e.endsParent&amp;&amp;e.parent;)e=e.parent;return e}return e.eW?u(e.parent,n):void 0}function c(e,n){return!a&amp;&amp;r(n.iR,e)}function l(e,n){var t=N.cI?n[0].toLowerCase():n[0];return e.k.hasOwnProperty(t)&amp;&amp;e.k[t]}function p(e,n,t,r){var a=r?"":I.classPrefix,i='&lt;span class="'+a,o=t?"":C;return i+=e+'"&gt;',i+n+o}function h(){var e,t,r,a;if(!E.k)return n(k);for(a="",t=0,E.lR.lastIndex=0,r=E.lR.exec(k);r;)a+=n(k.substring(t,r.index)),e=l(E,r),e?(B+=e[1],a+=p(e[0],n(r[0]))):a+=n(r[0]),t=E.lR.lastIndex,r=E.lR.exec(k);return a+n(k.substr(t))}function d(){var e="string"==typeof E.sL;if(e&amp;&amp;!y[E.sL])return n(k);var t=e?f(E.sL,k,!0,x[E.sL]):g(k,E.sL.length?E.sL:void 0);return E.r&gt;0&amp;&amp;(B+=t.r),e&amp;&amp;(x[E.sL]=t.top),p(t.language,t.value,!1,!0)}function b(){L+=null!=E.sL?d():h(),k=""}function v(e){L+=e.cN?p(e.cN,"",!0):"",E=Object.create(e,{parent:{value:E}})}function m(e,n){if(k+=e,null==n)return b(),0;var t=o(n,E);if(t)return t.skip?k+=n:(t.eB&amp;&amp;(k+=n),b(),t.rB||t.eB||(k=n)),v(t,n),t.rB?0:n.length;var r=u(E,n);if(r){var a=E;a.skip?k+=n:(a.rE||a.eE||(k+=n),b(),a.eE&amp;&amp;(k=n));do E.cN&amp;&amp;(L+=C),E.skip||(B+=E.r),E=E.parent;while(E!==r.parent);return r.starts&amp;&amp;v(r.starts,""),a.rE?0:n.length}if(c(n,E))throw new Error('Illegal lexeme "'+n+'" for mode "'+(E.cN||"&lt;unnamed&gt;")+'"');return k+=n,n.length||1}var N=w(e);if(!N)throw new Error('Unknown language: "'+e+'"');s(N);var R,E=i||N,x={},L="";for(R=E;R!==N;R=R.parent)R.cN&amp;&amp;(L=p(R.cN,"",!0)+L);var k="",B=0;try{for(var M,j,O=0;;){if(E.t.lastIndex=O,M=E.t.exec(t),!M)break;j=m(t.substring(O,M.index),M[0]),O=M.index+j}for(m(t.substr(O)),R=E;R.parent;R=R.parent)R.cN&amp;&amp;(L+=C);return{r:B,value:L,language:e,top:E}}catch(T){if(T.message&amp;&amp;-1!==T.message.indexOf("Illegal"))return{r:0,value:n(t)};throw T}}function g(e,t){t=t||I.languages||x(y);var r={r:0,value:n(e)},a=r;return t.filter(w).forEach(function(n){var t=f(n,e,!1);t.language=n,t.r&gt;a.r&amp;&amp;(a=t),t.r&gt;r.r&amp;&amp;(a=r,r=t)}),a.language&amp;&amp;(r.second_best=a),r}function p(e){return I.tabReplace||I.useBR?e.replace(M,function(e,n){return I.useBR&amp;&amp;"\n"===e?"&lt;br&gt;":I.tabReplace?n.replace(/\t/g,I.tabReplace):""}):e}function h(e,n,t){var r=n?L[n]:t,a=[e.trim()];return e.match(/\bhljs\b/)||a.push("hljs"),-1===e.indexOf(r)&amp;&amp;a.push(r),a.join(" ").trim()}function d(e){var n,t,r,o,l,s=i(e);a(s)||(I.useBR?(n=document.createElementNS("http://www.w3.org/1999/xhtml","div"),n.innerHTML=e.innerHTML.replace(/\n/g,"").replace(/&lt;br[ \/]*&gt;/g,"\n")):n=e,l=n.textContent,r=s?f(s,l,!0):g(l),t=u(n),t.length&amp;&amp;(o=document.createElementNS("http://www.w3.org/1999/xhtml","div"),o.innerHTML=r.value,r.value=c(t,u(o),l)),r.value=p(r.value),e.innerHTML=r.value,e.className=h(e.className,s,r.language),e.result={language:r.language,re:r.r},r.second_best&amp;&amp;(e.second_best={language:r.second_best.language,re:r.second_best.r}))}function b(e){I=o(I,e)}function v(){if(!v.called){v.called=!0;var e=document.querySelectorAll("pre code");E.forEach.call(e,d)}}function m(){addEventListener("DOMContentLoaded",v,!1),addEventListener("load",v,!1)}function N(n,t){var r=y[n]=t(e);r.aliases&amp;&amp;r.aliases.forEach(function(e){L[e]=n})}function R(){return x(y)}function w(e){return e=(e||"").toLowerCase(),y[e]||y[L[e]]}var E=[],x=Object.keys,y={},L={},k=/^(no-?highlight|plain|text)$/i,B=/\blang(?:uage)?-([\w-]+)\b/i,M=/((^(&lt;[^&gt;]+&gt;|\t|)+|(?:\n)))/gm,C="&lt;/span&gt;",I={classPrefix:"hljs-",tabReplace:null,useBR:!1,languages:void 0};return e.highlight=f,e.highlightAuto=g,e.fixMarkup=p,e.highlightBlock=d,e.configure=b,e.initHighlighting=v,e.initHighlightingOnLoad=m,e.registerLanguage=N,e.listLanguages=R,e.getLanguage=w,e.inherit=o,e.IR="[a-zA-Z]\\w*",e.UIR="[a-zA-Z_]\\w*",e.NR="\\b\\d+(\\.\\d+)?",e.CNR="(-?)(\\b0[xX][a-fA-F0-9]+|(\\b\\d+(\\.\\d*)?|\\.\\d+)([eE][-+]?\\d+)?)",e.BNR="\\b(0b[01]+)",e.RSR="!|!=|!==|%|%=|&amp;|&amp;&amp;|&amp;=|\\*|\\*=|\\+|\\+=|,|-|-=|/=|/|:|;|&lt;&lt;|&lt;&lt;=|&lt;=|&lt;|===|==|=|&gt;&gt;&gt;=|&gt;&gt;=|&gt;=|&gt;&gt;&gt;|&gt;&gt;|&gt;|\\?|\\[|\\{|\\(|\\^|\\^=|\\||\\|=|\\|\\||~",e.BE={b:"\\\\[\\s\\S]",r:0},e.ASM={cN:"string",b:"'",e:"'",i:"\\n",c:[e.BE]},e.QSM={cN:"string",b:'"',e:'"',i:"\\n",c:[e.BE]},e.PWM={b:/\b(a|an|the|are|I'm|isn't|don't|doesn't|won't|but|just|should|pretty|simply|enough|gonna|going|wtf|so|such|will|you|your|they|like|more)\b/},e.C=function(n,t,r){var a=e.inherit({cN:"comment",b:n,e:t,c:[]},r||{});return a.c.push(e.PWM),a.c.push({cN:"doctag",b:"(?:TODO|FIXME|NOTE|BUG|XXX):",r:0}),a},e.CLCM=e.C("//","$"),e.CBCM=e.C("/\\*","\\*/"),e.HCM=e.C("#","$"),e.NM={cN:"number",b:e.NR,r:0},e.CNM={cN:"number",b:e.CNR,r:0},e.BNM={cN:"number",b:e.BNR,r:0},e.CSSNM={cN:"number",b:e.NR+"(%|em|ex|ch|rem|vw|vh|vmin|vmax|cm|mm|in|pt|pc|px|deg|grad|rad|turn|s|ms|Hz|kHz|dpi|dpcm|dppx)?",r:0},e.RM={cN:"regexp",b:/\//,e:/\/[gimuy]*/,i:/\n/,c:[e.BE,{b:/\[/,e:/\]/,r:0,c:[e.BE]}]},e.TM={cN:"title",b:e.IR,r:0},e.UTM={cN:"title",b:e.UIR,r:0},e.METHOD_GUARD={b:"\\.\\s*"+e.UIR,r:0},e});hljs.registerLanguage("java",function(e){var a="[À-ʸa-zA-Z_$][À-ʸa-zA-Z_$0-9]*",t=a+"(&lt;"+a+"(\\s*,\\s*"+a+")*&gt;)?",r="false synchronized int abstract float private char boolean static null if const for true while long strictfp finally protected import native final void enum else break transient catch instanceof byte super volatile case assert short package default double public try this switch continue throws protected public private module requires exports do",s="\\b(0[bB]([01]+[01_]+[01]+|[01]+)|0[xX]([a-fA-F0-9]+[a-fA-F0-9_]+[a-fA-F0-9]+|[a-fA-F0-9]+)|(([\\d]+[\\d_]+[\\d]+|[\\d]+)(\\.([\\d]+[\\d_]+[\\d]+|[\\d]+))?|\\.([\\d]+[\\d_]+[\\d]+|[\\d]+))([eE][-+]?\\d+)?)[lLfF]?",c={cN:"number",b:s,r:0};return{aliases:["jsp"],k:r,i:/&lt;\/|#/,c:[e.C("/\\*\\*","\\*/",{r:0,c:[{b:/\w+@/,r:0},{cN:"doctag",b:"@[A-Za-z]+"}]}),e.CLCM,e.CBCM,e.ASM,e.QSM,{cN:"class",bK:"class interface",e:/[{;=]/,eE:!0,k:"class interface",i:/[:"\[\]]/,c:[{bK:"extends implements"},e.UTM]},{bK:"new throw return else",r:0},{cN:"function",b:"("+t+"\\s+)+"+e.UIR+"\\s*\\(",rB:!0,e:/[{;=]/,eE:!0,k:r,c:[{b:e.UIR+"\\s*\\(",rB:!0,r:0,c:[e.UTM]},{cN:"params",b:/\(/,e:/\)/,k:r,r:0,c:[e.ASM,e.QSM,e.CNM,e.CBCM]},e.CLCM,e.CBCM]},c,{cN:"meta",b:"@[A-Za-z]+"}]}});
&lt;/script&gt;
&lt;script&gt;hljs.initHighlightingOnLoad();&lt;/script&gt;
&lt;/head&gt;
&lt;body onload="selectdotnet()"&gt;
&lt;div id="topics"&gt;&lt;/div&gt;
&lt;img src="https://blogger.googleusercontent.com/img/proxy/AVvXsEiFv-rPnZkgs0jexkl3m9JjFAGNoP1V8rTOgCtbWqFTgKAwQ70V6Q18rYBwRupk7wIXBcw67aqoxQbozpjPGMNdJGsGKVjg3b1k104S3IvKHlzJu3m9O824Ffv4-azvhJ3tDwnHplLw5dnvTiWw2kOyGg=w128-h128-p-k-no-nu" style="display: none;"/&gt;
&lt;!-- ####################################################################### --&gt;
&lt;strong&gt;Environment&lt;/strong&gt; class allows you to obtain a number of details regarding the operating system currently
hosting your .NET application using various static members. To illustrate the usefulness of System.Environment,
update your Main() method to call a helper method named &lt;strong&gt;EnvironmentDetails()&lt;/strong&gt;.
&lt;br&gt;&lt;br&gt;
&lt;table&gt;
 &lt;tr&gt;
  &lt;th&gt;Properties&lt;/th&gt;
  &lt;th&gt;Meaning&lt;/th&gt;
 &lt;/tr&gt;
 &lt;tr&gt;
  &lt;td&gt;ExitCode&lt;/td&gt;
  &lt;td&gt;Gets or sets the exit code for the application&lt;/td&gt;
 &lt;/tr&gt;
 &lt;tr&gt;
  &lt;td&gt;Is64BitOperatingSystem&lt;/td&gt;
  &lt;td&gt;Returns a bool to represent whether the host machine is running a 64-bit OS&lt;/td&gt;
 &lt;/tr&gt;
 &lt;tr&gt;
  &lt;td&gt;MachineName&lt;/td&gt;
  &lt;td&gt;Gets the name of the current machine&lt;/td&gt;
 &lt;/tr&gt;
 &lt;tr&gt;
  &lt;td&gt;NewLine&lt;/td&gt;
  &lt;td&gt;Gets the newline symbol for the current environment&lt;/td&gt;
 &lt;/tr&gt;
 &lt;tr&gt;
  &lt;td&gt;SystemDirectory&lt;/td&gt;
  &lt;td&gt;Returns the full path to the system directory&lt;/td&gt;
 &lt;/tr&gt;
 &lt;tr&gt;
  &lt;td&gt;UserName&lt;/td&gt;
  &lt;td&gt;Returns the name of the user that started this application&lt;/td&gt;
 &lt;/tr&gt;
 &lt;tr&gt;
  &lt;td&gt;Version&lt;/td&gt;
  &lt;td&gt;Returns a Version object that represents the version of the .NET platform
&lt;/td&gt;
 &lt;/tr&gt;
&lt;/table&gt;
&lt;br&gt;&lt;br&gt;
Create &lt;strong&gt;EnvironmentDetails()&lt;/strong&gt; method in class under Main() method and call this method in Main() method.

&lt;h3&gt;Program&lt;/h3&gt;
&lt;pre&gt;
 &lt;code class="csharp java"&gt;
using System;

public class ConsoleApp
{
    public static void Main(string[] args)
    {
        //implement this method in this class
        EnvironmentDetails();
        Console.ReadLine();
    }

    static void EnvironmentDetails()
    {
        //prints current OS version
        Console.WriteLine("OS version: {0}", Environment.OSVersion);
        //prints all the drives of current machine
        foreach (string drive in Environment.GetLogicalDrives())
        {
            Console.WriteLine("drive {0}", drive);
        }
        //prints no of processor in current machine
        Console.WriteLine("No of processors: {0}", Environment.ProcessorCount);
        //prints current .NET version in which program is running
        Console.WriteLine(".NET version: {0}", Environment.Version);
        //Gets or sets the exit code for the application
        Console.WriteLine("exit code: {0}", Environment.ExitCode);
        //Returns a bool to represent whether the host machine is running a 64-bit OS
        Console.WriteLine("64 bit? : {0}", Environment.Is64BitOperatingSystem);
        //Gets the name of the current machine
        Console.WriteLine("Machine name: {0}", Environment.MachineName);
        //Gets the newline symbol for the current environment
        Console.WriteLine("New line symbol: {0}", Environment.NewLine);
        //Returns the full path to the system directory
        Console.WriteLine("System directory : {0}", Environment.SystemDirectory);
        //Returns the name of the user that started this application
        Console.WriteLine("Username : {0}", Environment.UserName);
    }
}
 &lt;/code&gt;
 &lt;a href="https://jdoodle.com/a/gQ9"&gt;&lt;button class="button"&gt;&lt;span&gt;Run &lt;/span&gt;&lt;/button&gt;&lt;/a&gt;
&lt;/pre&gt;
&lt;h3&gt;Output&lt;/h3&gt;
&lt;pre&gt;
&lt;code class="java"&gt;
OS version: Unix 4.8.0.41
drive /
drive /usr/lib/cache
drive /etc/resolv.conf
drive /etc/hostname
drive /etc/hosts
No of processors: 2
.NET version: 4.0.30319.42000
exit code: 0
64 bit? : True
Machine name: jdoodle
New line symbol: 

System directory : 
Username : root
&lt;/code&gt;  
&lt;/pre&gt;
&lt;!-- ####################################################################### --&gt;
&lt;/body&gt;
&lt;/html&gt;&lt;/div&gt;
</description><link>http://tangled-java.blogspot.com/2017/12/systemenvironment.html</link><author>noreply@blogger.com (Anonymous)</author><media:thumbnail xmlns:media="http://search.yahoo.com/mrss/" height="72" url="https://blogger.googleusercontent.com/img/proxy/AVvXsEiFv-rPnZkgs0jexkl3m9JjFAGNoP1V8rTOgCtbWqFTgKAwQ70V6Q18rYBwRupk7wIXBcw67aqoxQbozpjPGMNdJGsGKVjg3b1k104S3IvKHlzJu3m9O824Ffv4-azvhJ3tDwnHplLw5dnvTiWw2kOyGg=s72-w128-h128-c-p-k-no-nu" width="72"/><thr:total>0</thr:total></item><item><guid isPermaLink="false">tag:blogger.com,1999:blog-3082064622906880860.post-2215857788317279343</guid><pubDate>Sun, 10 Dec 2017 14:54:00 +0000</pubDate><atom:updated>2017-12-10T06:57:18.736-08:00</atom:updated><category domain="http://www.blogger.com/atom/ns#">how to?</category><category domain="http://www.blogger.com/atom/ns#">live change editor</category><title>How to make editor with live changes of HTML, CSS and JS?</title><description>&lt;!DOCTYPE html&gt;
&lt;html&gt;
&lt;head&gt;
 &lt;title&gt;&lt;/title&gt;
&lt;script type="text/javascript" src="https://highlightjs.org/static/highlight.pack.js"&gt;&lt;/script&gt;
&lt;script&gt;hljs.initHighlightingOnLoad();&lt;/script&gt;
&lt;/head&gt;
&lt;body onload='selecthowto()'&gt;
&lt;img src="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEguBPVvTn-QeqCUBP68vGg8oFyOqerIlule4QAhSxxWbnVFKce8MOw7kblcLZmFTOXQ2XEv6s-cB2HXAvMaGqQx-AoxsUTBAcXR86X7jU8VhxYoUd77gKjb_NNxv7vSajlfMJNGnijqpmM/h120/green-question-mark-icon-png-clipart-13.png" style="display: none;"/&gt;
Have you heard about Text editor with live changes of HTML , CSS and JAVASCRIPT ?
&lt;br&gt;&lt;br&gt;
Get a real-time connection to your output. Make changes to CSS and HTML and JS you'll instantly see those changes on screen. 
&lt;br&gt;&lt;br&gt;
Number of that kind of editors are available online.
&lt;br&gt;&lt;br&gt;
In this article we will see how it works ?
&lt;br&gt;&lt;br&gt;
code is given below:
&lt;h3&gt;HTML&lt;/h3&gt;
&lt;pre&gt;
 &lt;code class="xml"&gt;
&amp;lt;table&amp;gt;
 &amp;lt;tr&amp;gt;
  &amp;lt;td&amp;gt;
   &amp;lt;pre id="html" class="content" contenteditable&amp;gt;
    
   &amp;lt;/pre&amp;gt;
  &amp;lt;/td&amp;gt;
  &amp;lt;td rowspan="3" id="Output"&amp;gt;
   &amp;lt;iframe id="output"&amp;gt;&amp;lt;/iframe&amp;gt;
  &amp;lt;/td&amp;gt;
 &amp;lt;/tr&amp;gt;
 &amp;lt;tr&amp;gt;
  &amp;lt;td&amp;gt;
   &amp;lt;pre id="css" class="content" contenteditable&amp;gt;
   
   &amp;lt;/pre&amp;gt;
  &amp;lt;/td&amp;gt;
 &amp;lt;/tr&amp;gt;
 &amp;lt;tr&amp;gt;
  &amp;lt;td&amp;gt;
   &amp;lt;pre id="js" class="content" contenteditable&amp;gt;

   &amp;lt;/pre&amp;gt;
  &amp;lt;/td&amp;gt;
 &amp;lt;/tr&amp;gt;
&amp;lt;/table&amp;gt;
 &lt;/code&gt;
&lt;/pre&gt;
&lt;h3&gt;CSS&lt;/h3&gt;
&lt;pre&gt;
 &lt;code class="css"&gt;
pre::before{
 font-size: 16px;
 content: attr(id);
 position: absolute;
 top: 0;
 background-color: #333;
 padding: 10px;
 left: 0;
 right: 0;
 color: #ccc;
 text-transform: uppercase;
 display: block;
 margin: 0 0 15px 0;
 font-weight: bold;
}
html,body,table,iframe{
 border:0;
 height:100%;
 margin:0;
 padding:0;
 width:100%;
}
iframe{
 min-width: 50%;
 position: fixed;
}
td{
 border:2px solid black;
 height:33.33%;
 padding:36px 5px 5px 5px;
 position:relative;
 vertical-align:top;
 width:50%;
 font-family: monospace;
 font-size: 17px;
 max-width: 50%;
}
pre{
 max-height: 100%;
 max-width: 100%;
 overflow: auto;
 margin-top: -0.5px;
 white-space: pre-wrap; 
}
 &lt;/code&gt;
&lt;/pre&gt;
&lt;h3&gt;JAVASCRIPT&lt;/h3&gt;
&lt;pre&gt;
 &lt;code class="javascript" id="JAVASCRIPT"&gt;
window.onload=function(){
 var html=document.getElementById("html"),
  css=document.getElementById("css"),
  js=document.getElementById("js"),
  output=document.getElementById("output"),
  working=false,
  fill=function(){
   if(working){
    return false;
   }
   working=true;
   var document=output.contentDocument,
    style=document.createElement("style"),
    script=document.createElement("script");
   document.body.innerHTML=html.textContent;
   style.innerHTML=css.textContent.replace(/\s/g,"");
   script.innerHTML=js.textContent;
   document.body.appendChild(style);
   document.body.appendChild(script);
   working=false;
  };
 html.onkeyup=fill;
 css.onkeyup=fill;
 js.onkeyup=fill;
}
 &lt;/code&gt;
&lt;/pre&gt;
see output of this code:
&lt;a href="http://han2709.blogspot.in/2017/12/web-editor-prebeforetdbefore-font-size.html"&gt;&lt;button&gt;Click here&lt;/button&gt;&lt;/a&gt;
Type some code in HTML CSS and JS box in this output and see live preview.
&lt;/body&gt;
&lt;/html&gt;</description><link>http://tangled-java.blogspot.com/2017/12/how-to-make-editor-with-live-changes-of.html</link><author>noreply@blogger.com (Anonymous)</author><media:thumbnail xmlns:media="http://search.yahoo.com/mrss/" height="72" url="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEguBPVvTn-QeqCUBP68vGg8oFyOqerIlule4QAhSxxWbnVFKce8MOw7kblcLZmFTOXQ2XEv6s-cB2HXAvMaGqQx-AoxsUTBAcXR86X7jU8VhxYoUd77gKjb_NNxv7vSajlfMJNGnijqpmM/s72-h120-c/green-question-mark-icon-png-clipart-13.png" width="72"/><thr:total>0</thr:total></item><item><guid isPermaLink="false">tag:blogger.com,1999:blog-3082064622906880860.post-4581944447716966447</guid><pubDate>Sat, 09 Dec 2017 18:30:00 +0000</pubDate><atom:updated>2017-12-09T10:42:31.371-08:00</atom:updated><category domain="http://www.blogger.com/atom/ns#">Command line argument</category><title>Command line argument</title><description>&lt;div dir="ltr" style="text-align: left;" trbidi="on"&gt;
&lt;html&gt;
&lt;head&gt;
 &lt;title&gt;&lt;/title&gt;
&lt;style&gt; strong{ color: white; }
@media only screen and (min-width: 800px){#dotnet{width: 20%; }}
&lt;/style&gt;
&lt;script type="text/javascript"&gt;
 /*! highlight.js v9.12.0 | BSD3 License | git.io/hljslicense */
!function(e){var n="object"==typeof window&amp;&amp;window||"object"==typeof self&amp;&amp;self;"undefined"!=typeof exports?e(exports):n&amp;&amp;(n.hljs=e({}),"function"==typeof define&amp;&amp;define.amd&amp;&amp;define([],function(){return n.hljs}))}(function(e){function n(e){return e.replace(/&amp;/g,"&amp;amp;").replace(/&lt;/g,"&amp;lt;").replace(/&gt;/g,"&amp;gt;")}function t(e){return e.nodeName.toLowerCase()}function r(e,n){var t=e&amp;&amp;e.exec(n);return t&amp;&amp;0===t.index}function a(e){return k.test(e)}function i(e){var n,t,r,i,o=e.className+" ";if(o+=e.parentNode?e.parentNode.className:"",t=B.exec(o))return w(t[1])?t[1]:"no-highlight";for(o=o.split(/\s+/),n=0,r=o.length;r&gt;n;n++)if(i=o[n],a(i)||w(i))return i}function o(e){var n,t={},r=Array.prototype.slice.call(arguments,1);for(n in e)t[n]=e[n];return r.forEach(function(e){for(n in e)t[n]=e[n]}),t}function u(e){var n=[];return function r(e,a){for(var i=e.firstChild;i;i=i.nextSibling)3===i.nodeType?a+=i.nodeValue.length:1===i.nodeType&amp;&amp;(n.push({event:"start",offset:a,node:i}),a=r(i,a),t(i).match(/br|hr|img|input/)||n.push({event:"stop",offset:a,node:i}));return a}(e,0),n}function c(e,r,a){function i(){return e.length&amp;&amp;r.length?e[0].offset!==r[0].offset?e[0].offset&lt;r[0].offset?e:r:"start"===r[0].event?e:r:e.length?e:r}function o(e){function r(e){return" "+e.nodeName+'="'+n(e.value).replace('"',"&amp;quot;")+'"'}s+="&lt;"+t(e)+E.map.call(e.attributes,r).join("")+"&gt;"}function u(e){s+="&lt;/"+t(e)+"&gt;"}function c(e){("start"===e.event?o:u)(e.node)}for(var l=0,s="",f=[];e.length||r.length;){var g=i();if(s+=n(a.substring(l,g[0].offset)),l=g[0].offset,g===e){f.reverse().forEach(u);do c(g.splice(0,1)[0]),g=i();while(g===e&amp;&amp;g.length&amp;&amp;g[0].offset===l);f.reverse().forEach(o)}else"start"===g[0].event?f.push(g[0].node):f.pop(),c(g.splice(0,1)[0])}return s+n(a.substr(l))}function l(e){return e.v&amp;&amp;!e.cached_variants&amp;&amp;(e.cached_variants=e.v.map(function(n){return o(e,{v:null},n)})),e.cached_variants||e.eW&amp;&amp;[o(e)]||[e]}function s(e){function n(e){return e&amp;&amp;e.source||e}function t(t,r){return new RegExp(n(t),"m"+(e.cI?"i":"")+(r?"g":""))}function r(a,i){if(!a.compiled){if(a.compiled=!0,a.k=a.k||a.bK,a.k){var o={},u=function(n,t){e.cI&amp;&amp;(t=t.toLowerCase()),t.split(" ").forEach(function(e){var t=e.split("|");o[t[0]]=[n,t[1]?Number(t[1]):1]})};"string"==typeof a.k?u("keyword",a.k):x(a.k).forEach(function(e){u(e,a.k[e])}),a.k=o}a.lR=t(a.l||/\w+/,!0),i&amp;&amp;(a.bK&amp;&amp;(a.b="\\b("+a.bK.split(" ").join("|")+")\\b"),a.b||(a.b=/\B|\b/),a.bR=t(a.b),a.e||a.eW||(a.e=/\B|\b/),a.e&amp;&amp;(a.eR=t(a.e)),a.tE=n(a.e)||"",a.eW&amp;&amp;i.tE&amp;&amp;(a.tE+=(a.e?"|":"")+i.tE)),a.i&amp;&amp;(a.iR=t(a.i)),null==a.r&amp;&amp;(a.r=1),a.c||(a.c=[]),a.c=Array.prototype.concat.apply([],a.c.map(function(e){return l("self"===e?a:e)})),a.c.forEach(function(e){r(e,a)}),a.starts&amp;&amp;r(a.starts,i);var c=a.c.map(function(e){return e.bK?"\\.?("+e.b+")\\.?":e.b}).concat([a.tE,a.i]).map(n).filter(Boolean);a.t=c.length?t(c.join("|"),!0):{exec:function(){return null}}}}r(e)}function f(e,t,a,i){function o(e,n){var t,a;for(t=0,a=n.c.length;a&gt;t;t++)if(r(n.c[t].bR,e))return n.c[t]}function u(e,n){if(r(e.eR,n)){for(;e.endsParent&amp;&amp;e.parent;)e=e.parent;return e}return e.eW?u(e.parent,n):void 0}function c(e,n){return!a&amp;&amp;r(n.iR,e)}function l(e,n){var t=N.cI?n[0].toLowerCase():n[0];return e.k.hasOwnProperty(t)&amp;&amp;e.k[t]}function p(e,n,t,r){var a=r?"":I.classPrefix,i='&lt;span class="'+a,o=t?"":C;return i+=e+'"&gt;',i+n+o}function h(){var e,t,r,a;if(!E.k)return n(k);for(a="",t=0,E.lR.lastIndex=0,r=E.lR.exec(k);r;)a+=n(k.substring(t,r.index)),e=l(E,r),e?(B+=e[1],a+=p(e[0],n(r[0]))):a+=n(r[0]),t=E.lR.lastIndex,r=E.lR.exec(k);return a+n(k.substr(t))}function d(){var e="string"==typeof E.sL;if(e&amp;&amp;!y[E.sL])return n(k);var t=e?f(E.sL,k,!0,x[E.sL]):g(k,E.sL.length?E.sL:void 0);return E.r&gt;0&amp;&amp;(B+=t.r),e&amp;&amp;(x[E.sL]=t.top),p(t.language,t.value,!1,!0)}function b(){L+=null!=E.sL?d():h(),k=""}function v(e){L+=e.cN?p(e.cN,"",!0):"",E=Object.create(e,{parent:{value:E}})}function m(e,n){if(k+=e,null==n)return b(),0;var t=o(n,E);if(t)return t.skip?k+=n:(t.eB&amp;&amp;(k+=n),b(),t.rB||t.eB||(k=n)),v(t,n),t.rB?0:n.length;var r=u(E,n);if(r){var a=E;a.skip?k+=n:(a.rE||a.eE||(k+=n),b(),a.eE&amp;&amp;(k=n));do E.cN&amp;&amp;(L+=C),E.skip||(B+=E.r),E=E.parent;while(E!==r.parent);return r.starts&amp;&amp;v(r.starts,""),a.rE?0:n.length}if(c(n,E))throw new Error('Illegal lexeme "'+n+'" for mode "'+(E.cN||"&lt;unnamed&gt;")+'"');return k+=n,n.length||1}var N=w(e);if(!N)throw new Error('Unknown language: "'+e+'"');s(N);var R,E=i||N,x={},L="";for(R=E;R!==N;R=R.parent)R.cN&amp;&amp;(L=p(R.cN,"",!0)+L);var k="",B=0;try{for(var M,j,O=0;;){if(E.t.lastIndex=O,M=E.t.exec(t),!M)break;j=m(t.substring(O,M.index),M[0]),O=M.index+j}for(m(t.substr(O)),R=E;R.parent;R=R.parent)R.cN&amp;&amp;(L+=C);return{r:B,value:L,language:e,top:E}}catch(T){if(T.message&amp;&amp;-1!==T.message.indexOf("Illegal"))return{r:0,value:n(t)};throw T}}function g(e,t){t=t||I.languages||x(y);var r={r:0,value:n(e)},a=r;return t.filter(w).forEach(function(n){var t=f(n,e,!1);t.language=n,t.r&gt;a.r&amp;&amp;(a=t),t.r&gt;r.r&amp;&amp;(a=r,r=t)}),a.language&amp;&amp;(r.second_best=a),r}function p(e){return I.tabReplace||I.useBR?e.replace(M,function(e,n){return I.useBR&amp;&amp;"\n"===e?"&lt;br&gt;":I.tabReplace?n.replace(/\t/g,I.tabReplace):""}):e}function h(e,n,t){var r=n?L[n]:t,a=[e.trim()];return e.match(/\bhljs\b/)||a.push("hljs"),-1===e.indexOf(r)&amp;&amp;a.push(r),a.join(" ").trim()}function d(e){var n,t,r,o,l,s=i(e);a(s)||(I.useBR?(n=document.createElementNS("http://www.w3.org/1999/xhtml","div"),n.innerHTML=e.innerHTML.replace(/\n/g,"").replace(/&lt;br[ \/]*&gt;/g,"\n")):n=e,l=n.textContent,r=s?f(s,l,!0):g(l),t=u(n),t.length&amp;&amp;(o=document.createElementNS("http://www.w3.org/1999/xhtml","div"),o.innerHTML=r.value,r.value=c(t,u(o),l)),r.value=p(r.value),e.innerHTML=r.value,e.className=h(e.className,s,r.language),e.result={language:r.language,re:r.r},r.second_best&amp;&amp;(e.second_best={language:r.second_best.language,re:r.second_best.r}))}function b(e){I=o(I,e)}function v(){if(!v.called){v.called=!0;var e=document.querySelectorAll("pre code");E.forEach.call(e,d)}}function m(){addEventListener("DOMContentLoaded",v,!1),addEventListener("load",v,!1)}function N(n,t){var r=y[n]=t(e);r.aliases&amp;&amp;r.aliases.forEach(function(e){L[e]=n})}function R(){return x(y)}function w(e){return e=(e||"").toLowerCase(),y[e]||y[L[e]]}var E=[],x=Object.keys,y={},L={},k=/^(no-?highlight|plain|text)$/i,B=/\blang(?:uage)?-([\w-]+)\b/i,M=/((^(&lt;[^&gt;]+&gt;|\t|)+|(?:\n)))/gm,C="&lt;/span&gt;",I={classPrefix:"hljs-",tabReplace:null,useBR:!1,languages:void 0};return e.highlight=f,e.highlightAuto=g,e.fixMarkup=p,e.highlightBlock=d,e.configure=b,e.initHighlighting=v,e.initHighlightingOnLoad=m,e.registerLanguage=N,e.listLanguages=R,e.getLanguage=w,e.inherit=o,e.IR="[a-zA-Z]\\w*",e.UIR="[a-zA-Z_]\\w*",e.NR="\\b\\d+(\\.\\d+)?",e.CNR="(-?)(\\b0[xX][a-fA-F0-9]+|(\\b\\d+(\\.\\d*)?|\\.\\d+)([eE][-+]?\\d+)?)",e.BNR="\\b(0b[01]+)",e.RSR="!|!=|!==|%|%=|&amp;|&amp;&amp;|&amp;=|\\*|\\*=|\\+|\\+=|,|-|-=|/=|/|:|;|&lt;&lt;|&lt;&lt;=|&lt;=|&lt;|===|==|=|&gt;&gt;&gt;=|&gt;&gt;=|&gt;=|&gt;&gt;&gt;|&gt;&gt;|&gt;|\\?|\\[|\\{|\\(|\\^|\\^=|\\||\\|=|\\|\\||~",e.BE={b:"\\\\[\\s\\S]",r:0},e.ASM={cN:"string",b:"'",e:"'",i:"\\n",c:[e.BE]},e.QSM={cN:"string",b:'"',e:'"',i:"\\n",c:[e.BE]},e.PWM={b:/\b(a|an|the|are|I'm|isn't|don't|doesn't|won't|but|just|should|pretty|simply|enough|gonna|going|wtf|so|such|will|you|your|they|like|more)\b/},e.C=function(n,t,r){var a=e.inherit({cN:"comment",b:n,e:t,c:[]},r||{});return a.c.push(e.PWM),a.c.push({cN:"doctag",b:"(?:TODO|FIXME|NOTE|BUG|XXX):",r:0}),a},e.CLCM=e.C("//","$"),e.CBCM=e.C("/\\*","\\*/"),e.HCM=e.C("#","$"),e.NM={cN:"number",b:e.NR,r:0},e.CNM={cN:"number",b:e.CNR,r:0},e.BNM={cN:"number",b:e.BNR,r:0},e.CSSNM={cN:"number",b:e.NR+"(%|em|ex|ch|rem|vw|vh|vmin|vmax|cm|mm|in|pt|pc|px|deg|grad|rad|turn|s|ms|Hz|kHz|dpi|dpcm|dppx)?",r:0},e.RM={cN:"regexp",b:/\//,e:/\/[gimuy]*/,i:/\n/,c:[e.BE,{b:/\[/,e:/\]/,r:0,c:[e.BE]}]},e.TM={cN:"title",b:e.IR,r:0},e.UTM={cN:"title",b:e.UIR,r:0},e.METHOD_GUARD={b:"\\.\\s*"+e.UIR,r:0},e});hljs.registerLanguage("java",function(e){var a="[À-ʸa-zA-Z_$][À-ʸa-zA-Z_$0-9]*",t=a+"(&lt;"+a+"(\\s*,\\s*"+a+")*&gt;)?",r="false synchronized int abstract float private char boolean static null if const for true while long strictfp finally protected import native final void enum else break transient catch instanceof byte super volatile case assert short package default double public try this switch continue throws protected public private module requires exports do",s="\\b(0[bB]([01]+[01_]+[01]+|[01]+)|0[xX]([a-fA-F0-9]+[a-fA-F0-9_]+[a-fA-F0-9]+|[a-fA-F0-9]+)|(([\\d]+[\\d_]+[\\d]+|[\\d]+)(\\.([\\d]+[\\d_]+[\\d]+|[\\d]+))?|\\.([\\d]+[\\d_]+[\\d]+|[\\d]+))([eE][-+]?\\d+)?)[lLfF]?",c={cN:"number",b:s,r:0};return{aliases:["jsp"],k:r,i:/&lt;\/|#/,c:[e.C("/\\*\\*","\\*/",{r:0,c:[{b:/\w+@/,r:0},{cN:"doctag",b:"@[A-Za-z]+"}]}),e.CLCM,e.CBCM,e.ASM,e.QSM,{cN:"class",bK:"class interface",e:/[{;=]/,eE:!0,k:"class interface",i:/[:"\[\]]/,c:[{bK:"extends implements"},e.UTM]},{bK:"new throw return else",r:0},{cN:"function",b:"("+t+"\\s+)+"+e.UIR+"\\s*\\(",rB:!0,e:/[{;=]/,eE:!0,k:r,c:[{b:e.UIR+"\\s*\\(",rB:!0,r:0,c:[e.UTM]},{cN:"params",b:/\(/,e:/\)/,k:r,r:0,c:[e.ASM,e.QSM,e.CNM,e.CBCM]},e.CLCM,e.CBCM]},c,{cN:"meta",b:"@[A-Za-z]+"}]}});
&lt;/script&gt;
&lt;script&gt;hljs.initHighlightingOnLoad();&lt;/script&gt;
&lt;/head&gt;
&lt;body onload="selectdotnet()"&gt;
&lt;div id="topics"&gt;&lt;/div&gt;
&lt;img src="https://blogger.googleusercontent.com/img/proxy/AVvXsEiFv-rPnZkgs0jexkl3m9JjFAGNoP1V8rTOgCtbWqFTgKAwQ70V6Q18rYBwRupk7wIXBcw67aqoxQbozpjPGMNdJGsGKVjg3b1k104S3IvKHlzJu3m9O824Ffv4-azvhJ3tDwnHplLw5dnvTiWw2kOyGg=w128-h128-p-k-no-nu" style="display: none;"/&gt;
&lt;!-- ####################################################################### --&gt;
With the first introduction post of C# you can understand the return value of the &lt;strong&gt;Main()&lt;/strong&gt; method, let’s examine the incoming array of string data. Assume that you now want to update your application to process any possible command-line
parameters. One way to do so is using a C# for loop. We will see for loop in C# in later article.
&lt;h2&gt;Accessing command line arguments with for loop&lt;/h2&gt;
&lt;h3&gt;Program&lt;/h3&gt;
&lt;pre&gt;
&lt;code class="java"&gt;
using System;

public class CLA
{
    public static void Main(string[] args)
    {
        //this loop prints any number of given command line arguments
        for(int i=0; i&amp;lt;args.Length; i++)
        {
            Console.WriteLine("arg-" + i + " = " + args[i]);
        }
    }
}&lt;br&gt;
&lt;/code&gt;  
&lt;/pre&gt;

&lt;h3&gt;Output&lt;/h3&gt;
&lt;pre&gt;
&lt;code class="java"&gt;
F:\Code\Algorithm&gt;csc CLA.cs

F:\Code\Algorithm&gt;CLA tangled java elaborately
arg-0 = tangled
arg-1 = java
arg-2 = elaborately
&lt;/code&gt;  
&lt;/pre&gt;

&lt;h3&gt;Explanation&lt;/h3&gt;
Here, you are checking to see whether the array of strings contains some number of items
using the &lt;strong&gt;Length&lt;/strong&gt; property of &lt;strong&gt;System.Array&lt;/strong&gt;. As you’ll see in later article, all C# arrays actually alias the
&lt;strong&gt;System.Array&lt;/strong&gt; class and, therefore, share a common set of members. As you loop over each item in
the array, its value is printed to the console window. Supplying the arguments at the command line is
equally simple, as shown in output above.
&lt;h2&gt;Accessing command line arguments with foreach loop&lt;/h2&gt;
As an alternative to the standard for loop, you may iterate over an incoming string array using the C#
foreach keyword. Here is sample usage :
&lt;h3&gt;Program&lt;/h3&gt;
&lt;pre&gt;
&lt;code class="java"&gt;
using System;

public class CLA
{
    public static void Main(string[] args)
    {
        //you don't need to specify length property of array when using foreach loop
        foreach (string arg in args)
        {
            Console.WriteLine("Arg: {0}",arg);
        }
    }
}
&lt;/code&gt;  
&lt;/pre&gt;

&lt;h3&gt;Output&lt;/h3&gt;
&lt;pre&gt;
&lt;code class="java"&gt;
F:\Code\Algorithm&gt;csc CLA.cs

F:\Code\Algorithm&gt;CLA tangled java elaborately
Arg: tangled
Arg: java
Arg: elaborately
&lt;/code&gt;  
&lt;/pre&gt;

&lt;h2&gt;Accessing command line arguments with GetCommandLineArgs()&lt;/h2&gt;
You are also able to access command-line arguments using the static &lt;strong&gt;GetCommandLineArgs()&lt;/strong&gt;
method of the &lt;strong&gt;System.Environment&lt;/strong&gt; type. The return value of this method is an array of strings. The first
index identifies the name of the application itself, while the remaining elements in the array contain the
individual command-line arguments. Note that when using this approach, it is no longer necessary to define
Main() as taking a string array as the input parameter, although there is no harm in doing so.

&lt;h3&gt;Program&lt;/h3&gt;
&lt;pre&gt;
&lt;code class="java"&gt;
using System;

public class CLA
{
    public static void Main()
    {
        //command line arguments are stored in string typed array args
        string[] args = Environment.GetCommandLineArgs();
        //remember when using this method in output first argument is always filename
        foreach(string arg in args)
        {
            Console.WriteLine("Args: {0}",arg);
        }
    }
}
&lt;/code&gt;  
&lt;/pre&gt;

&lt;h3&gt;Output&lt;/h3&gt;
&lt;pre&gt;
&lt;code class="java"&gt;
F:\Code\Algorithm&gt;csc CLA.cs

F:\Code\Algorithm&gt;CLA tangled java elaborately
Args: CLA
Args: tangled
Args: java
Args: elaborately
&lt;/code&gt;  
&lt;/pre&gt;

&lt;h3&gt;Explanation&lt;/h3&gt;
It is up to you to determine which command-line arguments your program will respond
to (if any) and how they must be formatted.
&lt;h2&gt;Specifying Command-Line Arguments with Visual Studio&lt;/h2&gt;
During the development cycle, you might want to specify possible command-line flags
for testing purposes. To do so with Visual Studio, double-click the Properties icon in Solution Explorer and
select the Debug tab on the left side. From there, specify values using the command-line arguments text box
and save your changes.&lt;br&gt;
&lt;div class="separator" style="clear: both; text-align: center;"&gt;&lt;a href="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEgru7F7zR0v4kCX8E2s2nRMqwXm4iJ0OJru57_MALVKZ_FQuLpVV1YXuarJLrkr9L5D1x8pUkkBYj0mGYVlI36JtZUl3Nm3exRFdlZCvly_IE1ygzU5yrSn9MrwlLFZajkMkICz0nnZnIk/s1600/Screenshot+%2528275%2529.png" imageanchor="1" style="margin-left: 1em; margin-right: 1em;"&gt;&lt;img border="0" src="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEgru7F7zR0v4kCX8E2s2nRMqwXm4iJ0OJru57_MALVKZ_FQuLpVV1YXuarJLrkr9L5D1x8pUkkBYj0mGYVlI36JtZUl3Nm3exRFdlZCvly_IE1ygzU5yrSn9MrwlLFZajkMkICz0nnZnIk/s1600/Screenshot+%2528275%2529.png" data-original-width="1366" data-original-height="768" /&gt;&lt;/a&gt;&lt;/div&gt;
&lt;h3&gt;Program&lt;/h3&gt;
&lt;pre&gt;
&lt;code class="java"&gt;
using System;

public class ConsoleApp
{  
    public static void Main(string[] args)
    {
        for(int i=0; i&amp;lt;args.Length; i++)
        {
            Console.WriteLine("Arg-{0} = {1}",i,args[i]);
        }
        Console.ReadLine();
    }
}
&lt;/code&gt;  
&lt;/pre&gt;

&lt;h3&gt;Output&lt;/h3&gt;
&lt;pre&gt;
&lt;code class="java"&gt;
Arg-0 = tangled
Arg-1 = java
Arg-2 = elaborately
&lt;/code&gt;  
&lt;/pre&gt;
&lt;!-- ####################################################################### --&gt;
&lt;/body&gt;
&lt;/html&gt;&lt;/div&gt;
</description><link>http://tangled-java.blogspot.com/2017/12/command-line-argument.html</link><author>noreply@blogger.com (Anonymous)</author><media:thumbnail xmlns:media="http://search.yahoo.com/mrss/" height="72" url="https://blogger.googleusercontent.com/img/proxy/AVvXsEiFv-rPnZkgs0jexkl3m9JjFAGNoP1V8rTOgCtbWqFTgKAwQ70V6Q18rYBwRupk7wIXBcw67aqoxQbozpjPGMNdJGsGKVjg3b1k104S3IvKHlzJu3m9O824Ffv4-azvhJ3tDwnHplLw5dnvTiWw2kOyGg=s72-w128-h128-c-p-k-no-nu" width="72"/><thr:total>0</thr:total></item><item><guid isPermaLink="false">tag:blogger.com,1999:blog-3082064622906880860.post-1925691682306764086</guid><pubDate>Fri, 08 Dec 2017 15:59:00 +0000</pubDate><atom:updated>2017-12-12T04:12:41.049-08:00</atom:updated><category domain="http://www.blogger.com/atom/ns#">Building blocks of .NET</category><category domain="http://www.blogger.com/atom/ns#">CLR</category><category domain="http://www.blogger.com/atom/ns#">CLS</category><category domain="http://www.blogger.com/atom/ns#">CTS</category><title>Building blocks of .NET</title><description>&lt;div dir="ltr" style="text-align: left;" trbidi="on"&gt;
&lt;html&gt;
&lt;head&gt;
 &lt;title&gt;&lt;/title&gt;
&lt;style&gt; strong{ color: white; }
@media only screen and (min-width: 800px){#dotnet{ width:20%; }}
&lt;/style&gt;
&lt;script type="text/javascript"&gt;
 /*! highlight.js v9.12.0 | BSD3 License | git.io/hljslicense */
!function(e){var n="object"==typeof window&amp;&amp;window||"object"==typeof self&amp;&amp;self;"undefined"!=typeof exports?e(exports):n&amp;&amp;(n.hljs=e({}),"function"==typeof define&amp;&amp;define.amd&amp;&amp;define([],function(){return n.hljs}))}(function(e){function n(e){return e.replace(/&amp;/g,"&amp;amp;").replace(/&lt;/g,"&amp;lt;").replace(/&gt;/g,"&amp;gt;")}function t(e){return e.nodeName.toLowerCase()}function r(e,n){var t=e&amp;&amp;e.exec(n);return t&amp;&amp;0===t.index}function a(e){return k.test(e)}function i(e){var n,t,r,i,o=e.className+" ";if(o+=e.parentNode?e.parentNode.className:"",t=B.exec(o))return w(t[1])?t[1]:"no-highlight";for(o=o.split(/\s+/),n=0,r=o.length;r&gt;n;n++)if(i=o[n],a(i)||w(i))return i}function o(e){var n,t={},r=Array.prototype.slice.call(arguments,1);for(n in e)t[n]=e[n];return r.forEach(function(e){for(n in e)t[n]=e[n]}),t}function u(e){var n=[];return function r(e,a){for(var i=e.firstChild;i;i=i.nextSibling)3===i.nodeType?a+=i.nodeValue.length:1===i.nodeType&amp;&amp;(n.push({event:"start",offset:a,node:i}),a=r(i,a),t(i).match(/br|hr|img|input/)||n.push({event:"stop",offset:a,node:i}));return a}(e,0),n}function c(e,r,a){function i(){return e.length&amp;&amp;r.length?e[0].offset!==r[0].offset?e[0].offset&lt;r[0].offset?e:r:"start"===r[0].event?e:r:e.length?e:r}function o(e){function r(e){return" "+e.nodeName+'="'+n(e.value).replace('"',"&amp;quot;")+'"'}s+="&lt;"+t(e)+E.map.call(e.attributes,r).join("")+"&gt;"}function u(e){s+="&lt;/"+t(e)+"&gt;"}function c(e){("start"===e.event?o:u)(e.node)}for(var l=0,s="",f=[];e.length||r.length;){var g=i();if(s+=n(a.substring(l,g[0].offset)),l=g[0].offset,g===e){f.reverse().forEach(u);do c(g.splice(0,1)[0]),g=i();while(g===e&amp;&amp;g.length&amp;&amp;g[0].offset===l);f.reverse().forEach(o)}else"start"===g[0].event?f.push(g[0].node):f.pop(),c(g.splice(0,1)[0])}return s+n(a.substr(l))}function l(e){return e.v&amp;&amp;!e.cached_variants&amp;&amp;(e.cached_variants=e.v.map(function(n){return o(e,{v:null},n)})),e.cached_variants||e.eW&amp;&amp;[o(e)]||[e]}function s(e){function n(e){return e&amp;&amp;e.source||e}function t(t,r){return new RegExp(n(t),"m"+(e.cI?"i":"")+(r?"g":""))}function r(a,i){if(!a.compiled){if(a.compiled=!0,a.k=a.k||a.bK,a.k){var o={},u=function(n,t){e.cI&amp;&amp;(t=t.toLowerCase()),t.split(" ").forEach(function(e){var t=e.split("|");o[t[0]]=[n,t[1]?Number(t[1]):1]})};"string"==typeof a.k?u("keyword",a.k):x(a.k).forEach(function(e){u(e,a.k[e])}),a.k=o}a.lR=t(a.l||/\w+/,!0),i&amp;&amp;(a.bK&amp;&amp;(a.b="\\b("+a.bK.split(" ").join("|")+")\\b"),a.b||(a.b=/\B|\b/),a.bR=t(a.b),a.e||a.eW||(a.e=/\B|\b/),a.e&amp;&amp;(a.eR=t(a.e)),a.tE=n(a.e)||"",a.eW&amp;&amp;i.tE&amp;&amp;(a.tE+=(a.e?"|":"")+i.tE)),a.i&amp;&amp;(a.iR=t(a.i)),null==a.r&amp;&amp;(a.r=1),a.c||(a.c=[]),a.c=Array.prototype.concat.apply([],a.c.map(function(e){return l("self"===e?a:e)})),a.c.forEach(function(e){r(e,a)}),a.starts&amp;&amp;r(a.starts,i);var c=a.c.map(function(e){return e.bK?"\\.?("+e.b+")\\.?":e.b}).concat([a.tE,a.i]).map(n).filter(Boolean);a.t=c.length?t(c.join("|"),!0):{exec:function(){return null}}}}r(e)}function f(e,t,a,i){function o(e,n){var t,a;for(t=0,a=n.c.length;a&gt;t;t++)if(r(n.c[t].bR,e))return n.c[t]}function u(e,n){if(r(e.eR,n)){for(;e.endsParent&amp;&amp;e.parent;)e=e.parent;return e}return e.eW?u(e.parent,n):void 0}function c(e,n){return!a&amp;&amp;r(n.iR,e)}function l(e,n){var t=N.cI?n[0].toLowerCase():n[0];return e.k.hasOwnProperty(t)&amp;&amp;e.k[t]}function p(e,n,t,r){var a=r?"":I.classPrefix,i='&lt;span class="'+a,o=t?"":C;return i+=e+'"&gt;',i+n+o}function h(){var e,t,r,a;if(!E.k)return n(k);for(a="",t=0,E.lR.lastIndex=0,r=E.lR.exec(k);r;)a+=n(k.substring(t,r.index)),e=l(E,r),e?(B+=e[1],a+=p(e[0],n(r[0]))):a+=n(r[0]),t=E.lR.lastIndex,r=E.lR.exec(k);return a+n(k.substr(t))}function d(){var e="string"==typeof E.sL;if(e&amp;&amp;!y[E.sL])return n(k);var t=e?f(E.sL,k,!0,x[E.sL]):g(k,E.sL.length?E.sL:void 0);return E.r&gt;0&amp;&amp;(B+=t.r),e&amp;&amp;(x[E.sL]=t.top),p(t.language,t.value,!1,!0)}function b(){L+=null!=E.sL?d():h(),k=""}function v(e){L+=e.cN?p(e.cN,"",!0):"",E=Object.create(e,{parent:{value:E}})}function m(e,n){if(k+=e,null==n)return b(),0;var t=o(n,E);if(t)return t.skip?k+=n:(t.eB&amp;&amp;(k+=n),b(),t.rB||t.eB||(k=n)),v(t,n),t.rB?0:n.length;var r=u(E,n);if(r){var a=E;a.skip?k+=n:(a.rE||a.eE||(k+=n),b(),a.eE&amp;&amp;(k=n));do E.cN&amp;&amp;(L+=C),E.skip||(B+=E.r),E=E.parent;while(E!==r.parent);return r.starts&amp;&amp;v(r.starts,""),a.rE?0:n.length}if(c(n,E))throw new Error('Illegal lexeme "'+n+'" for mode "'+(E.cN||"&lt;unnamed&gt;")+'"');return k+=n,n.length||1}var N=w(e);if(!N)throw new Error('Unknown language: "'+e+'"');s(N);var R,E=i||N,x={},L="";for(R=E;R!==N;R=R.parent)R.cN&amp;&amp;(L=p(R.cN,"",!0)+L);var k="",B=0;try{for(var M,j,O=0;;){if(E.t.lastIndex=O,M=E.t.exec(t),!M)break;j=m(t.substring(O,M.index),M[0]),O=M.index+j}for(m(t.substr(O)),R=E;R.parent;R=R.parent)R.cN&amp;&amp;(L+=C);return{r:B,value:L,language:e,top:E}}catch(T){if(T.message&amp;&amp;-1!==T.message.indexOf("Illegal"))return{r:0,value:n(t)};throw T}}function g(e,t){t=t||I.languages||x(y);var r={r:0,value:n(e)},a=r;return t.filter(w).forEach(function(n){var t=f(n,e,!1);t.language=n,t.r&gt;a.r&amp;&amp;(a=t),t.r&gt;r.r&amp;&amp;(a=r,r=t)}),a.language&amp;&amp;(r.second_best=a),r}function p(e){return I.tabReplace||I.useBR?e.replace(M,function(e,n){return I.useBR&amp;&amp;"\n"===e?"&lt;br&gt;":I.tabReplace?n.replace(/\t/g,I.tabReplace):""}):e}function h(e,n,t){var r=n?L[n]:t,a=[e.trim()];return e.match(/\bhljs\b/)||a.push("hljs"),-1===e.indexOf(r)&amp;&amp;a.push(r),a.join(" ").trim()}function d(e){var n,t,r,o,l,s=i(e);a(s)||(I.useBR?(n=document.createElementNS("http://www.w3.org/1999/xhtml","div"),n.innerHTML=e.innerHTML.replace(/\n/g,"").replace(/&lt;br[ \/]*&gt;/g,"\n")):n=e,l=n.textContent,r=s?f(s,l,!0):g(l),t=u(n),t.length&amp;&amp;(o=document.createElementNS("http://www.w3.org/1999/xhtml","div"),o.innerHTML=r.value,r.value=c(t,u(o),l)),r.value=p(r.value),e.innerHTML=r.value,e.className=h(e.className,s,r.language),e.result={language:r.language,re:r.r},r.second_best&amp;&amp;(e.second_best={language:r.second_best.language,re:r.second_best.r}))}function b(e){I=o(I,e)}function v(){if(!v.called){v.called=!0;var e=document.querySelectorAll("pre code");E.forEach.call(e,d)}}function m(){addEventListener("DOMContentLoaded",v,!1),addEventListener("load",v,!1)}function N(n,t){var r=y[n]=t(e);r.aliases&amp;&amp;r.aliases.forEach(function(e){L[e]=n})}function R(){return x(y)}function w(e){return e=(e||"").toLowerCase(),y[e]||y[L[e]]}var E=[],x=Object.keys,y={},L={},k=/^(no-?highlight|plain|text)$/i,B=/\blang(?:uage)?-([\w-]+)\b/i,M=/((^(&lt;[^&gt;]+&gt;|\t|)+|(?:\n)))/gm,C="&lt;/span&gt;",I={classPrefix:"hljs-",tabReplace:null,useBR:!1,languages:void 0};return e.highlight=f,e.highlightAuto=g,e.fixMarkup=p,e.highlightBlock=d,e.configure=b,e.initHighlighting=v,e.initHighlightingOnLoad=m,e.registerLanguage=N,e.listLanguages=R,e.getLanguage=w,e.inherit=o,e.IR="[a-zA-Z]\\w*",e.UIR="[a-zA-Z_]\\w*",e.NR="\\b\\d+(\\.\\d+)?",e.CNR="(-?)(\\b0[xX][a-fA-F0-9]+|(\\b\\d+(\\.\\d*)?|\\.\\d+)([eE][-+]?\\d+)?)",e.BNR="\\b(0b[01]+)",e.RSR="!|!=|!==|%|%=|&amp;|&amp;&amp;|&amp;=|\\*|\\*=|\\+|\\+=|,|-|-=|/=|/|:|;|&lt;&lt;|&lt;&lt;=|&lt;=|&lt;|===|==|=|&gt;&gt;&gt;=|&gt;&gt;=|&gt;=|&gt;&gt;&gt;|&gt;&gt;|&gt;|\\?|\\[|\\{|\\(|\\^|\\^=|\\||\\|=|\\|\\||~",e.BE={b:"\\\\[\\s\\S]",r:0},e.ASM={cN:"string",b:"'",e:"'",i:"\\n",c:[e.BE]},e.QSM={cN:"string",b:'"',e:'"',i:"\\n",c:[e.BE]},e.PWM={b:/\b(a|an|the|are|I'm|isn't|don't|doesn't|won't|but|just|should|pretty|simply|enough|gonna|going|wtf|so|such|will|you|your|they|like|more)\b/},e.C=function(n,t,r){var a=e.inherit({cN:"comment",b:n,e:t,c:[]},r||{});return a.c.push(e.PWM),a.c.push({cN:"doctag",b:"(?:TODO|FIXME|NOTE|BUG|XXX):",r:0}),a},e.CLCM=e.C("//","$"),e.CBCM=e.C("/\\*","\\*/"),e.HCM=e.C("#","$"),e.NM={cN:"number",b:e.NR,r:0},e.CNM={cN:"number",b:e.CNR,r:0},e.BNM={cN:"number",b:e.BNR,r:0},e.CSSNM={cN:"number",b:e.NR+"(%|em|ex|ch|rem|vw|vh|vmin|vmax|cm|mm|in|pt|pc|px|deg|grad|rad|turn|s|ms|Hz|kHz|dpi|dpcm|dppx)?",r:0},e.RM={cN:"regexp",b:/\//,e:/\/[gimuy]*/,i:/\n/,c:[e.BE,{b:/\[/,e:/\]/,r:0,c:[e.BE]}]},e.TM={cN:"title",b:e.IR,r:0},e.UTM={cN:"title",b:e.UIR,r:0},e.METHOD_GUARD={b:"\\.\\s*"+e.UIR,r:0},e});hljs.registerLanguage("java",function(e){var a="[À-ʸa-zA-Z_$][À-ʸa-zA-Z_$0-9]*",t=a+"(&lt;"+a+"(\\s*,\\s*"+a+")*&gt;)?",r="false synchronized int abstract float private char boolean static null if const for true while long strictfp finally protected import native final void enum else break transient catch instanceof byte super volatile case assert short package default double public try this switch continue throws protected public private module requires exports do",s="\\b(0[bB]([01]+[01_]+[01]+|[01]+)|0[xX]([a-fA-F0-9]+[a-fA-F0-9_]+[a-fA-F0-9]+|[a-fA-F0-9]+)|(([\\d]+[\\d_]+[\\d]+|[\\d]+)(\\.([\\d]+[\\d_]+[\\d]+|[\\d]+))?|\\.([\\d]+[\\d_]+[\\d]+|[\\d]+))([eE][-+]?\\d+)?)[lLfF]?",c={cN:"number",b:s,r:0};return{aliases:["jsp"],k:r,i:/&lt;\/|#/,c:[e.C("/\\*\\*","\\*/",{r:0,c:[{b:/\w+@/,r:0},{cN:"doctag",b:"@[A-Za-z]+"}]}),e.CLCM,e.CBCM,e.ASM,e.QSM,{cN:"class",bK:"class interface",e:/[{;=]/,eE:!0,k:"class interface",i:/[:"\[\]]/,c:[{bK:"extends implements"},e.UTM]},{bK:"new throw return else",r:0},{cN:"function",b:"("+t+"\\s+)+"+e.UIR+"\\s*\\(",rB:!0,e:/[{;=]/,eE:!0,k:r,c:[{b:e.UIR+"\\s*\\(",rB:!0,r:0,c:[e.UTM]},{cN:"params",b:/\(/,e:/\)/,k:r,r:0,c:[e.ASM,e.QSM,e.CNM,e.CBCM]},e.CLCM,e.CBCM]},c,{cN:"meta",b:"@[A-Za-z]+"}]}});
&lt;/script&gt;
&lt;script&gt;hljs.initHighlightingOnLoad();&lt;/script&gt;
&lt;/head&gt;
&lt;body onload="selectdotnet()"&gt;
&lt;div id="topics"&gt;&lt;/div&gt;
&lt;img src="https://cdn.auth0.com/blog/native-csharp/logo.png" style="display: none;"/&gt;
&lt;!-- ####################################################################### --&gt;
In this article we view three key (and interrelated)
topics that make it all possible:&lt;strong&gt; the CLR, CTS, and CLS&lt;/strong&gt;. 
&lt;h2&gt;Common Language Runtime&lt;/h2&gt;
From a programmer’s point of view, .NET can be understood as a runtime environment and a comprehensive base class library. The runtime layer is properly
referred to as the &lt;strong&gt;Common Language Runtime&lt;/strong&gt;, or CLR. The primary role of the CLR is to locate, load, and
manage .NET objects on your behalf. The CLR also takes care of a number of low-level details such as
memory management, application hosting, coordinating threads, and performing basic security checks
(among other low-level details).
&lt;h2&gt;Common Type System&lt;/h2&gt;
Another building block of the .NET platform is the &lt;strong&gt;Common Type System&lt;/strong&gt;, or CTS. The CTS specification
fully describes all possible data types and all programming constructs supported by the runtime, specifies
how these entities can interact with each other, and details how they are represented in the .NET metadata
format.
&lt;h2&gt;Common Language Specification&lt;/h2&gt;
Understand that a given .NET-aware language might not support every feature defined by the CTS. The
&lt;strong&gt;Common Language Specification&lt;/strong&gt;, or CLS, is a related specification that defines a subset of common types
and programming constructs that all .NET programming languages can agree on. Thus, if you build .NET
types that expose only CLS-compliant features, you can rest assured that all .NET-aware languages can
consume them. Conversely, if you make use of a data type or programming construct that is outside of the bounds of the CLS, you cannot guarantee that every .NET programming language can interact with your
.NET code library. Thankfully, as you will see later, it is simple to tell your C# compiler to
check all of your code for CLS compliance.
&lt;h2&gt;Role of the base class libraries&lt;/h2&gt;
In addition to the CLR, CTS, and CLS specifications, the .NET platform provides a base class library that
is available to all .NET programming languages. Not only does this base class library encapsulate various
primitives such as threads, file input/output (I/O), graphical rendering systems, and interaction with various
external hardware devices, but it also provides support for a number of services required by most real-world
applications.&lt;br&gt;&lt;br&gt;
The base class libraries define types that can be used to build any type of software application. For example,
you can use ASP.NET to build web sites and REST services, WCF to build distributed systems, WPF to build
desktop GUI applications, and so forth. As well, the base class libraries provide types to interact with XML
documents, the directory and file system on a given computer, communicate with a relational databases
(via ADO.NET), and so forth. From a high level, you can visualize the relationship between the CLR, CTS,
CLS, and the base class library, as shown in image:
&lt;img src=""/&gt;
&lt;h2&gt;What's new in C#?&lt;/h2&gt;
C# is a programming language whose core syntax looks very similar to the syntax of Java. However, calling
C# a Java clone is inaccurate. In reality, both C# and Java are members of the C family of programming
languages (e.g., C, Objective C, C++) and, therefore, share a similar syntax.
The truth of the matter is that many of C#’s syntactic constructs are modeled after various aspects of
Visual Basic (VB) and C++. For example, like VB, C# supports the notion of class properties (as opposed
to traditional getter and setter methods) and optional parameters. Like C++, C# allows you to overload
operators, as well as create structures, enumerations, and callback functions (via delegates).
Moreover, as you work through this text, you will quickly see that C# supports a number of features
traditionally found in various functional languages such as lambda expressions
and anonymous types. Furthermore, with the advent of Language Integrated Query (LINQ), C# supports a
number of constructs that make it quite unique in the programming landscape. Nevertheless, the bulk of C#
is indeed influenced by C-based languages.&lt;br&gt;&lt;br&gt;
Because C# is a hybrid of numerous languages, the result is a product that is as syntactically clean
(if not cleaner) as Java, is about as simple as VB, and provides just about as much power and flexibility as
C++. Here is a partial list of core C# features that are found in all versions of the language:
&lt;ul&gt;
&lt;li&gt;  No pointers required! C# programs typically have no need for direct pointer
manipulation (although you are free to drop down to that level if absolutely
necessary).&lt;/li&gt;
&lt;li&gt;  Automatic memory management through garbage collection. Given this, C# does not
support a delete keyword.&lt;/li&gt;
&lt;li&gt; Formal syntactic constructs for classes, interfaces, structures, enumerations,
and delegates.&lt;/li&gt;
&lt;li&gt;The C++-like ability to overload operators for a custom type, without the complexity.&lt;/li&gt;
&lt;li&gt;Support for attribute-based programming. This brand of development allows you
to annotate types and their members to further qualify their behavior. For example,
if you mark a method with the Obsolete attribute, programmers will see your
custom warning message print out if they attempt to make use of the decorated
member.&lt;/li&gt;
&lt;/ul&gt;

With the release of .NET 2.0 (circa 2005), the C# programming language was updated to support
numerous new bells and whistles, most notability the following:
&lt;ul&gt;
&lt;li&gt;The ability to build generic types and generic members. Using generics, you are able
to build efficient and type-safe code that defines numerous placeholders specified at
the time you interact with the generic item.&lt;/li&gt;
&lt;li&gt;Support for anonymous methods, which allow you to supply an inline function
anywhere a delegate type is required.&lt;/li&gt;
&lt;li&gt;The ability to define a single type across multiple code files (or if necessary, as an inmemory
representation) using the partial keyword,&lt;/li&gt;
&lt;/ul&gt;
&lt;ul&gt;
.NET 3.5 (released circa 2008) added even more functionality to the C# programming language,
including the following features:
&lt;li&gt;Support for strongly typed queries (e.g., LINQ) used to interact with various forms of
data.&lt;/li&gt;
&lt;li&gt;Support for anonymous types that allow you to model the structure of a type (rather
than its behavior) on the fly in code.&lt;/li&gt;
&lt;li&gt;The ability to extend the functionality of an existing type (without subclassing) using
extension methods.&lt;/li&gt;
&lt;li&gt; Inclusion of a lambda operator (=&gt;), which even further simplifies working with .NET
delegate types.&lt;/li&gt;
&lt;li&gt; A new object initialization syntax, which allows you to set property values at the time
of object creation.&lt;/li&gt;
&lt;/ul&gt;
.NET 4.0 (released in 2010) updated C# yet again with a handful of features.
&lt;ul&gt;
&lt;li&gt;Support for optional method parameters, as well as named method arguments.&lt;/li&gt;
&lt;li&gt;Support for dynamic lookup of members at runtime via the dynamic keyword.this provides a unified approach to invoking members on
the fly, regardless of which framework the member implemented (COM, IronRuby,
IronPython, or via .NET reflection services).&lt;/li&gt;
&lt;li&gt;Working with generic types is much more intuitive, given that you can easily map
generic data to and from general System.Object collections via covariance and
contravariance.&lt;/li&gt;
&lt;/ul&gt;
With the release of .NET 4.5, C# received a pair of new keywords (async and await), which greatly
simplify multithreaded and asynchronous programming. If you have worked with previous versions of
C#, you might recall that calling methods via secondary threads required a fair amount of cryptic code
and the use of various .NET namespaces. Given that C# now supports language keywords that handle this
complexity for you, the process of calling methods asynchronously is almost as easy as calling a method in a
synchronous manner.
This brings us to the current version of C# and .NET 4.6, which introduces a number of minor features
that help streamline your codebase. You will see a number of details as you go through; however,
here is a quick rundown of some of the new features found in C#:
&lt;ul&gt;
&lt;li&gt;Inline initialization for automatic properties as well as support for read-only
automatic properties&lt;/li&gt;
&lt;li&gt;Single-line method implementations using the C# lambda operator&lt;/li&gt;
&lt;li&gt;Support of “static imports” to provide direct access to static members within a
namespace&lt;/li&gt;
&lt;li&gt;A null conditional operator, which helps check for null parameters in a method
implementation&lt;/li&gt;
&lt;li&gt;A new string formatting syntax termed string interpolation&lt;/li&gt;
&lt;li&gt;The ability to filter exceptions using the new &lt;strong&gt;when&lt;/strong&gt; keyword&lt;/li&gt;
&lt;/ul&gt;
&lt;h2&gt;Colourful console program in C#&lt;/h2&gt;
&lt;h3&gt;Program&lt;/h3&gt;
&lt;pre&gt;
&lt;code class="java"&gt;
using System;

namespace csharp
{
    public class ConsoleApp
    {  
        public static void Main(string[] args)
        {
            Console.Title = "My Application";
            Console.ForegroundColor = ConsoleColor.Red;
            Console.BackgroundColor = ConsoleColor.Gray;
            Console.WriteLine("Colourful learning");
            Console.ReadKey();
        }
    }
}
&lt;/code&gt;  
  &lt;a href="https://jdoodle.com/a/h2W"&gt;&lt;button class="button"&gt;&lt;span&gt;Run &lt;/span&gt;&lt;/button&gt;&lt;/a&gt;
&lt;/pre&gt;
&lt;h3&gt;Output&lt;/h3&gt;
&lt;pre&gt;
&lt;code class="java"&gt;
&lt;p style="background-color: gray; color: red; display: inline;"&gt;Colourful learning&lt;/p&gt;
&lt;/code&gt;  
&lt;/pre&gt;
&lt;!-- ####################################################################### --&gt;
&lt;/body&gt;
&lt;/html&gt;&lt;/div&gt;
</description><link>http://tangled-java.blogspot.com/2017/12/building-blocks-of-net.html</link><author>noreply@blogger.com (Anonymous)</author><thr:total>0</thr:total></item><item><guid isPermaLink="false">tag:blogger.com,1999:blog-3082064622906880860.post-5694230092138674548</guid><pubDate>Wed, 06 Dec 2017 06:00:00 +0000</pubDate><atom:updated>2017-12-12T04:06:50.154-08:00</atom:updated><category domain="http://www.blogger.com/atom/ns#">Introduction to c#</category><title>Introduction to c#</title><description>&lt;div dir="ltr" style="text-align: left;" trbidi="on"&gt;
&lt;html&gt;
&lt;head&gt;
 &lt;title&gt;&lt;/title&gt;
&lt;style&gt; strong{ color: white; }
@media only screen and (min-width: 800px){
#dotnet{width: 20%; }
&lt;/style&gt;
&lt;script type="text/javascript"&gt;
 /*! highlight.js v9.12.0 | BSD3 License | git.io/hljslicense */
!function(e){var n="object"==typeof window&amp;&amp;window||"object"==typeof self&amp;&amp;self;"undefined"!=typeof exports?e(exports):n&amp;&amp;(n.hljs=e({}),"function"==typeof define&amp;&amp;define.amd&amp;&amp;define([],function(){return n.hljs}))}(function(e){function n(e){return e.replace(/&amp;/g,"&amp;amp;").replace(/&lt;/g,"&amp;lt;").replace(/&gt;/g,"&amp;gt;")}function t(e){return e.nodeName.toLowerCase()}function r(e,n){var t=e&amp;&amp;e.exec(n);return t&amp;&amp;0===t.index}function a(e){return k.test(e)}function i(e){var n,t,r,i,o=e.className+" ";if(o+=e.parentNode?e.parentNode.className:"",t=B.exec(o))return w(t[1])?t[1]:"no-highlight";for(o=o.split(/\s+/),n=0,r=o.length;r&gt;n;n++)if(i=o[n],a(i)||w(i))return i}function o(e){var n,t={},r=Array.prototype.slice.call(arguments,1);for(n in e)t[n]=e[n];return r.forEach(function(e){for(n in e)t[n]=e[n]}),t}function u(e){var n=[];return function r(e,a){for(var i=e.firstChild;i;i=i.nextSibling)3===i.nodeType?a+=i.nodeValue.length:1===i.nodeType&amp;&amp;(n.push({event:"start",offset:a,node:i}),a=r(i,a),t(i).match(/br|hr|img|input/)||n.push({event:"stop",offset:a,node:i}));return a}(e,0),n}function c(e,r,a){function i(){return e.length&amp;&amp;r.length?e[0].offset!==r[0].offset?e[0].offset&lt;r[0].offset?e:r:"start"===r[0].event?e:r:e.length?e:r}function o(e){function r(e){return" "+e.nodeName+'="'+n(e.value).replace('"',"&amp;quot;")+'"'}s+="&lt;"+t(e)+E.map.call(e.attributes,r).join("")+"&gt;"}function u(e){s+="&lt;/"+t(e)+"&gt;"}function c(e){("start"===e.event?o:u)(e.node)}for(var l=0,s="",f=[];e.length||r.length;){var g=i();if(s+=n(a.substring(l,g[0].offset)),l=g[0].offset,g===e){f.reverse().forEach(u);do c(g.splice(0,1)[0]),g=i();while(g===e&amp;&amp;g.length&amp;&amp;g[0].offset===l);f.reverse().forEach(o)}else"start"===g[0].event?f.push(g[0].node):f.pop(),c(g.splice(0,1)[0])}return s+n(a.substr(l))}function l(e){return e.v&amp;&amp;!e.cached_variants&amp;&amp;(e.cached_variants=e.v.map(function(n){return o(e,{v:null},n)})),e.cached_variants||e.eW&amp;&amp;[o(e)]||[e]}function s(e){function n(e){return e&amp;&amp;e.source||e}function t(t,r){return new RegExp(n(t),"m"+(e.cI?"i":"")+(r?"g":""))}function r(a,i){if(!a.compiled){if(a.compiled=!0,a.k=a.k||a.bK,a.k){var o={},u=function(n,t){e.cI&amp;&amp;(t=t.toLowerCase()),t.split(" ").forEach(function(e){var t=e.split("|");o[t[0]]=[n,t[1]?Number(t[1]):1]})};"string"==typeof a.k?u("keyword",a.k):x(a.k).forEach(function(e){u(e,a.k[e])}),a.k=o}a.lR=t(a.l||/\w+/,!0),i&amp;&amp;(a.bK&amp;&amp;(a.b="\\b("+a.bK.split(" ").join("|")+")\\b"),a.b||(a.b=/\B|\b/),a.bR=t(a.b),a.e||a.eW||(a.e=/\B|\b/),a.e&amp;&amp;(a.eR=t(a.e)),a.tE=n(a.e)||"",a.eW&amp;&amp;i.tE&amp;&amp;(a.tE+=(a.e?"|":"")+i.tE)),a.i&amp;&amp;(a.iR=t(a.i)),null==a.r&amp;&amp;(a.r=1),a.c||(a.c=[]),a.c=Array.prototype.concat.apply([],a.c.map(function(e){return l("self"===e?a:e)})),a.c.forEach(function(e){r(e,a)}),a.starts&amp;&amp;r(a.starts,i);var c=a.c.map(function(e){return e.bK?"\\.?("+e.b+")\\.?":e.b}).concat([a.tE,a.i]).map(n).filter(Boolean);a.t=c.length?t(c.join("|"),!0):{exec:function(){return null}}}}r(e)}function f(e,t,a,i){function o(e,n){var t,a;for(t=0,a=n.c.length;a&gt;t;t++)if(r(n.c[t].bR,e))return n.c[t]}function u(e,n){if(r(e.eR,n)){for(;e.endsParent&amp;&amp;e.parent;)e=e.parent;return e}return e.eW?u(e.parent,n):void 0}function c(e,n){return!a&amp;&amp;r(n.iR,e)}function l(e,n){var t=N.cI?n[0].toLowerCase():n[0];return e.k.hasOwnProperty(t)&amp;&amp;e.k[t]}function p(e,n,t,r){var a=r?"":I.classPrefix,i='&lt;span class="'+a,o=t?"":C;return i+=e+'"&gt;',i+n+o}function h(){var e,t,r,a;if(!E.k)return n(k);for(a="",t=0,E.lR.lastIndex=0,r=E.lR.exec(k);r;)a+=n(k.substring(t,r.index)),e=l(E,r),e?(B+=e[1],a+=p(e[0],n(r[0]))):a+=n(r[0]),t=E.lR.lastIndex,r=E.lR.exec(k);return a+n(k.substr(t))}function d(){var e="string"==typeof E.sL;if(e&amp;&amp;!y[E.sL])return n(k);var t=e?f(E.sL,k,!0,x[E.sL]):g(k,E.sL.length?E.sL:void 0);return E.r&gt;0&amp;&amp;(B+=t.r),e&amp;&amp;(x[E.sL]=t.top),p(t.language,t.value,!1,!0)}function b(){L+=null!=E.sL?d():h(),k=""}function v(e){L+=e.cN?p(e.cN,"",!0):"",E=Object.create(e,{parent:{value:E}})}function m(e,n){if(k+=e,null==n)return b(),0;var t=o(n,E);if(t)return t.skip?k+=n:(t.eB&amp;&amp;(k+=n),b(),t.rB||t.eB||(k=n)),v(t,n),t.rB?0:n.length;var r=u(E,n);if(r){var a=E;a.skip?k+=n:(a.rE||a.eE||(k+=n),b(),a.eE&amp;&amp;(k=n));do E.cN&amp;&amp;(L+=C),E.skip||(B+=E.r),E=E.parent;while(E!==r.parent);return r.starts&amp;&amp;v(r.starts,""),a.rE?0:n.length}if(c(n,E))throw new Error('Illegal lexeme "'+n+'" for mode "'+(E.cN||"&lt;unnamed&gt;")+'"');return k+=n,n.length||1}var N=w(e);if(!N)throw new Error('Unknown language: "'+e+'"');s(N);var R,E=i||N,x={},L="";for(R=E;R!==N;R=R.parent)R.cN&amp;&amp;(L=p(R.cN,"",!0)+L);var k="",B=0;try{for(var M,j,O=0;;){if(E.t.lastIndex=O,M=E.t.exec(t),!M)break;j=m(t.substring(O,M.index),M[0]),O=M.index+j}for(m(t.substr(O)),R=E;R.parent;R=R.parent)R.cN&amp;&amp;(L+=C);return{r:B,value:L,language:e,top:E}}catch(T){if(T.message&amp;&amp;-1!==T.message.indexOf("Illegal"))return{r:0,value:n(t)};throw T}}function g(e,t){t=t||I.languages||x(y);var r={r:0,value:n(e)},a=r;return t.filter(w).forEach(function(n){var t=f(n,e,!1);t.language=n,t.r&gt;a.r&amp;&amp;(a=t),t.r&gt;r.r&amp;&amp;(a=r,r=t)}),a.language&amp;&amp;(r.second_best=a),r}function p(e){return I.tabReplace||I.useBR?e.replace(M,function(e,n){return I.useBR&amp;&amp;"\n"===e?"&lt;br&gt;":I.tabReplace?n.replace(/\t/g,I.tabReplace):""}):e}function h(e,n,t){var r=n?L[n]:t,a=[e.trim()];return e.match(/\bhljs\b/)||a.push("hljs"),-1===e.indexOf(r)&amp;&amp;a.push(r),a.join(" ").trim()}function d(e){var n,t,r,o,l,s=i(e);a(s)||(I.useBR?(n=document.createElementNS("http://www.w3.org/1999/xhtml","div"),n.innerHTML=e.innerHTML.replace(/\n/g,"").replace(/&lt;br[ \/]*&gt;/g,"\n")):n=e,l=n.textContent,r=s?f(s,l,!0):g(l),t=u(n),t.length&amp;&amp;(o=document.createElementNS("http://www.w3.org/1999/xhtml","div"),o.innerHTML=r.value,r.value=c(t,u(o),l)),r.value=p(r.value),e.innerHTML=r.value,e.className=h(e.className,s,r.language),e.result={language:r.language,re:r.r},r.second_best&amp;&amp;(e.second_best={language:r.second_best.language,re:r.second_best.r}))}function b(e){I=o(I,e)}function v(){if(!v.called){v.called=!0;var e=document.querySelectorAll("pre code");E.forEach.call(e,d)}}function m(){addEventListener("DOMContentLoaded",v,!1),addEventListener("load",v,!1)}function N(n,t){var r=y[n]=t(e);r.aliases&amp;&amp;r.aliases.forEach(function(e){L[e]=n})}function R(){return x(y)}function w(e){return e=(e||"").toLowerCase(),y[e]||y[L[e]]}var E=[],x=Object.keys,y={},L={},k=/^(no-?highlight|plain|text)$/i,B=/\blang(?:uage)?-([\w-]+)\b/i,M=/((^(&lt;[^&gt;]+&gt;|\t|)+|(?:\n)))/gm,C="&lt;/span&gt;",I={classPrefix:"hljs-",tabReplace:null,useBR:!1,languages:void 0};return e.highlight=f,e.highlightAuto=g,e.fixMarkup=p,e.highlightBlock=d,e.configure=b,e.initHighlighting=v,e.initHighlightingOnLoad=m,e.registerLanguage=N,e.listLanguages=R,e.getLanguage=w,e.inherit=o,e.IR="[a-zA-Z]\\w*",e.UIR="[a-zA-Z_]\\w*",e.NR="\\b\\d+(\\.\\d+)?",e.CNR="(-?)(\\b0[xX][a-fA-F0-9]+|(\\b\\d+(\\.\\d*)?|\\.\\d+)([eE][-+]?\\d+)?)",e.BNR="\\b(0b[01]+)",e.RSR="!|!=|!==|%|%=|&amp;|&amp;&amp;|&amp;=|\\*|\\*=|\\+|\\+=|,|-|-=|/=|/|:|;|&lt;&lt;|&lt;&lt;=|&lt;=|&lt;|===|==|=|&gt;&gt;&gt;=|&gt;&gt;=|&gt;=|&gt;&gt;&gt;|&gt;&gt;|&gt;|\\?|\\[|\\{|\\(|\\^|\\^=|\\||\\|=|\\|\\||~",e.BE={b:"\\\\[\\s\\S]",r:0},e.ASM={cN:"string",b:"'",e:"'",i:"\\n",c:[e.BE]},e.QSM={cN:"string",b:'"',e:'"',i:"\\n",c:[e.BE]},e.PWM={b:/\b(a|an|the|are|I'm|isn't|don't|doesn't|won't|but|just|should|pretty|simply|enough|gonna|going|wtf|so|such|will|you|your|they|like|more)\b/},e.C=function(n,t,r){var a=e.inherit({cN:"comment",b:n,e:t,c:[]},r||{});return a.c.push(e.PWM),a.c.push({cN:"doctag",b:"(?:TODO|FIXME|NOTE|BUG|XXX):",r:0}),a},e.CLCM=e.C("//","$"),e.CBCM=e.C("/\\*","\\*/"),e.HCM=e.C("#","$"),e.NM={cN:"number",b:e.NR,r:0},e.CNM={cN:"number",b:e.CNR,r:0},e.BNM={cN:"number",b:e.BNR,r:0},e.CSSNM={cN:"number",b:e.NR+"(%|em|ex|ch|rem|vw|vh|vmin|vmax|cm|mm|in|pt|pc|px|deg|grad|rad|turn|s|ms|Hz|kHz|dpi|dpcm|dppx)?",r:0},e.RM={cN:"regexp",b:/\//,e:/\/[gimuy]*/,i:/\n/,c:[e.BE,{b:/\[/,e:/\]/,r:0,c:[e.BE]}]},e.TM={cN:"title",b:e.IR,r:0},e.UTM={cN:"title",b:e.UIR,r:0},e.METHOD_GUARD={b:"\\.\\s*"+e.UIR,r:0},e});hljs.registerLanguage("java",function(e){var a="[À-ʸa-zA-Z_$][À-ʸa-zA-Z_$0-9]*",t=a+"(&lt;"+a+"(\\s*,\\s*"+a+")*&gt;)?",r="false synchronized int abstract float private char boolean static null if const for true while long strictfp finally protected import native final void enum else break transient catch instanceof byte super volatile case assert short package default double public try this switch continue throws protected public private module requires exports do",s="\\b(0[bB]([01]+[01_]+[01]+|[01]+)|0[xX]([a-fA-F0-9]+[a-fA-F0-9_]+[a-fA-F0-9]+|[a-fA-F0-9]+)|(([\\d]+[\\d_]+[\\d]+|[\\d]+)(\\.([\\d]+[\\d_]+[\\d]+|[\\d]+))?|\\.([\\d]+[\\d_]+[\\d]+|[\\d]+))([eE][-+]?\\d+)?)[lLfF]?",c={cN:"number",b:s,r:0};return{aliases:["jsp"],k:r,i:/&lt;\/|#/,c:[e.C("/\\*\\*","\\*/",{r:0,c:[{b:/\w+@/,r:0},{cN:"doctag",b:"@[A-Za-z]+"}]}),e.CLCM,e.CBCM,e.ASM,e.QSM,{cN:"class",bK:"class interface",e:/[{;=]/,eE:!0,k:"class interface",i:/[:"\[\]]/,c:[{bK:"extends implements"},e.UTM]},{bK:"new throw return else",r:0},{cN:"function",b:"("+t+"\\s+)+"+e.UIR+"\\s*\\(",rB:!0,e:/[{;=]/,eE:!0,k:r,c:[{b:e.UIR+"\\s*\\(",rB:!0,r:0,c:[e.UTM]},{cN:"params",b:/\(/,e:/\)/,k:r,r:0,c:[e.ASM,e.QSM,e.CNM,e.CBCM]},e.CLCM,e.CBCM]},c,{cN:"meta",b:"@[A-Za-z]+"}]}});
&lt;/script&gt;
&lt;script&gt;hljs.initHighlightingOnLoad();&lt;/script&gt;
&lt;/head&gt;
&lt;body onload="selectdotnet()"&gt;
&lt;div id="topics"&gt;&lt;/div&gt;
&lt;img src="https://cdn.auth0.com/blog/native-csharp/logo.png" style="display: none;"/&gt;
&lt;!-- ####################################################################### --&gt;
C# is an elegant and type-safe object-oriented language that enables developers to build a variety of secure and robust applications that run on the .NET Framework. You can use C# to create Windows client applications, XML Web services, distributed components, client-server applications, database applications, and much, much more. Visual C# provides an advanced code editor, convenient user interface designers, integrated debugger, and many other tools to make it easier to develop applications based on the C# language and the .NET Framework.

&lt;h2&gt;C# Language&lt;/h2&gt;
C# syntax is highly expressive, yet it is also simple and easy to learn. The curly-brace syntax of C# will be instantly recognizable to anyone familiar with C, C++ or Java. Developers who know any of these languages are typically able to begin to work productively in C# within a very short time. C# syntax simplifies many of the complexities of C++ and provides powerful features such as nullable value types, enumerations, delegates, lambda expressions and direct memory access, which are not found in Java. C# supports generic methods and types, which provide increased type safety and performance, and iterators, which enable implementers of collection classes to define custom iteration behaviors that are simple to use by client code. Language-Integrated Query (LINQ) expressions make the strongly-typed query a first-class language construct. &lt;br&gt;&lt;br&gt;
As an object-oriented language, C# supports the concepts of encapsulation, inheritance, and polymorphism. All variables and methods, including the Main method, the application's entry point, are encapsulated within class definitions. A class may inherit directly from one parent class, but it may implement any number of interfaces. Methods that override virtual methods in a parent class require the override keyword as a way to avoid accidental redefinition. In C#, a struct is like a lightweight class; it is a stack-allocated type that can implement interfaces but does not support inheritance.&lt;br&gt;&lt;br&gt;
In addition to these basic object-oriented principles, C# makes it easy to develop software components through several innovative language constructs, including the following:&lt;br&gt;&lt;br&gt;
Encapsulated method signatures called delegates, which enable type-safe event notifications.
Properties, which serve as accessors for private member variables.
Attributes, which provide declarative metadata about types at run time.&lt;br&gt;&lt;br&gt;
Language-Integrated Query (LINQ) which provides built-in query capabilities across a variety of data sources.
If you have to interact with other Windows software such as COM objects or native Win32 DLLs, you can do this in C# through a process called "Interop." Interop enables C# programs to do almost anything that a native C++ application can do. C# even supports pointers and the concept of "unsafe" code for those cases in which direct memory access is absolutely critical.&lt;br&gt;&lt;br&gt;
The C# build process is simple compared to C and C++ and more flexible than in Java. There are no separate header files, and no requirement that methods and types be declared in a particular order. A C# source file may define any number of classes, structs, interfaces, and events.&lt;br&gt;&lt;br&gt;

&lt;h2&gt;.NET Framework Platform Architecture&lt;/h2&gt;
C# programs run on the .NET Framework, an integral component of Windows that includes a virtual execution system called the &lt;strong&gt;common language runtime&lt;/strong&gt; (CLR) and a unified set of class libraries. The CLR is the commercial implementation by Microsoft of the common language infrastructure (CLI), an international standard that is the basis for creating execution and development environments in which languages and libraries work together seamlessly.&lt;br&gt;&lt;br&gt;
Source code written in C# is compiled into an intermediate language (IL) that conforms to the CLI specification. The IL code and resources, such as bitmaps and strings, are stored on disk in an executable file called an assembly, typically with an extension of .exe or .dll. An assembly contains a manifest that provides information about the assembly's types, version, culture, and security requirements.&lt;br&gt;&lt;br&gt;
When the C# program is executed, the assembly is loaded into the CLR, which might take various actions based on the information in the manifest. Then, if the security requirements are met, the CLR performs just in time (JIT) compilation to convert the IL code to native machine instructions. The CLR also provides other services related to automatic garbage collection, exception handling, and resource management. Code that is executed by the CLR is sometimes referred to as "managed code," in contrast to "unmanaged code" which is compiled into native machine language that targets a specific system. The following diagram illustrates the compile-time and run-time relationships of C# source code files, the .NET Framework class libraries, assemblies, and the CLR.&lt;br&gt;&lt;br&gt;
&lt;img src="https://docs.microsoft.com/en-us/dotnet/csharp/getting-started/media/netarchitecture.png" align="center"/&gt;
&lt;h2&gt;From C# source code to machine execution&lt;/h2&gt;
Language interoperability is a key feature of the .NET Framework. Because the IL code produced by the C# compiler conforms to the Common Type Specification (CTS), IL code generated from C# can interact with code that was generated from the .NET versions of Visual Basic, Visual C++, or any of more than 20 other CTS-compliant languages. A single assembly may contain multiple modules written in different .NET languages, and the types can reference each other just as if they were written in the same language.
In addition to the run time services, the .NET Framework also includes an extensive library of over 4000 classes organized into namespaces that provide a wide variety of useful functionality for everything from file input and output to string manipulation to XML parsing, to Windows Forms controls. The typical C# application uses the .NET Framework class library extensively to handle common "plumbing" chores.

&lt;h2&gt;hello world program in C#&lt;/h2&gt;
&lt;ol&gt;
&lt;li&gt;Start Visual Studio.&lt;/li&gt;
&lt;li&gt;On the menu bar, choose File, New, Project.&lt;/li&gt;
&lt;li&gt;The New Project dialog box opens.&lt;/li&gt;
&lt;li&gt;Expand Installed, expand Templates, expand Visual C#, and then choose Console Application.&lt;/li&gt;
&lt;li&gt;In the Name box, specify a name for your project, and then choose the OK button.&lt;/li&gt;
&lt;li&gt;The new project appears in Solution Explorer.&lt;/li&gt;
&lt;li&gt;If Program.cs isn't open in the Code Editor, open the shortcut menu for Program.cs in Solution Explorer, and then choose View Code.&lt;/li&gt;
&lt;/ol&gt;

&lt;h3&gt;Program&lt;/h3&gt;
&lt;pre&gt;
&lt;code class="java"&gt;
//C# hello world program
using System;

namespace Hello_World
{
    class Hello
    {
        static void Main()
        {
            Console.WriteLine("Hello World");
            //keep the console window open
            Console.ReadKey();
        }
    }
}
&lt;/code&gt;  
  &lt;a href="https://jdoodle.com/a/h2T"&gt;&lt;button class="button"&gt;&lt;span&gt;Run &lt;/span&gt;&lt;/button&gt;&lt;/a&gt;
&lt;/pre&gt;

&lt;h3&gt;Output&lt;/h3&gt;
&lt;pre&gt;
&lt;code class="java"&gt;
Hello World
&lt;/code&gt;  
&lt;/pre&gt;
&lt;h3&gt;Explanation&lt;/h3&gt;
The first line contains a comment. The characters &lt;strong&gt;//&lt;/strong&gt; convert the rest of the line to a comment.
&lt;pre&gt;
&lt;code class="java"&gt;
//C# hello world program
&lt;/code&gt;  
&lt;/pre&gt;
You can also comment out a block of text by enclosing it between the &lt;strong&gt;/*&lt;/strong&gt; and &lt;strong&gt;*/&lt;/strong&gt; characters.
&lt;h2&gt;Main method&lt;/h2&gt;A C# console application must contain a Main method, in which control starts and ends. The &lt;strong&gt;Main&lt;/strong&gt; method is where you create objects and execute other methods.
The Main method is a static method that resides inside a class or a struct. In the previous "Hello World" example, it resides in a class named Hello. You can declare the Main method in one of the following ways:
1.It can return &lt;strong&gt;void&lt;/strong&gt;.
&lt;pre&gt;
&lt;code class="java"&gt;
static void Main()
{
    //...
}
&lt;/code&gt;  
&lt;/pre&gt;
2.It can also return an &lt;strong&gt;integer&lt;/strong&gt;.
&lt;pre&gt;
&lt;code class="java"&gt;
static int Main()
{
    //...
    return 0;
}
&lt;/code&gt;  
&lt;/pre&gt;
3.With either of the return types, it can take arguments.
&lt;pre&gt;
&lt;code class="java"&gt;
static void Main(string[] args)
{
    //...
}
&lt;/code&gt;  
&lt;/pre&gt;
&lt;strong&gt;OR&lt;/strong&gt;
&lt;pre&gt;
&lt;code class="java"&gt;
static int Main(string[] args)
{
    //...
    return 0;
}
&lt;/code&gt;  
&lt;/pre&gt;
The parameter of the Main method, args, is a string array that contains the command-line arguments used to invoke the program. Unlike in C++, the array does not include the name of the executable (exe) file.
&lt;br&gt;&lt;br&gt;
The call to ReadKey at the end of the Main method prevents the console window from closing before you have a chance to read the output.&lt;br&gt;&lt;br&gt;
C# programs generally use the input/output services provided by the run-time library of the .NET Framework. The statement &lt;strong&gt;System.Console.WriteLine("Hello World!");&lt;/strong&gt; uses the WriteLine method. This is one of the output methods of the Console class in the run-time library. It displays its string parameter on the standard output stream followed by a new line. Other Console methods are available for different input and output operations. If you include the &lt;strong&gt;using System;&lt;/strong&gt; directive at the beginning of the program, you can directly use the System classes and methods without fully qualifying them. For example, you can call &lt;strong&gt;Console.WriteLine&lt;/strong&gt; instead of &lt;strong&gt;System.Console.WriteLine&lt;/strong&gt;

&lt;h2&gt;Command-Line Compilation and Execution&lt;/h2&gt;
You can compile the "Hello World!" program by using the command line instead of the Visual Studio Integrated Development Environment (IDE).
&lt;strong&gt;To compile and run from a command prompt&lt;/strong&gt;
&lt;ol&gt;
&lt;li&gt;Paste the code , and then save the file as a text file. Name the file &lt;strong&gt;Hello.cs&lt;/strong&gt;. C# source code files use the extension &lt;strong&gt;.cs&lt;/strong&gt;.&lt;/li&gt;
&lt;li&gt;Perform one of the following steps to open a command-prompt window:
In Windows 10, on the Start menu, search for Developer Command Prompt, and then tap or choose Developer Command Prompt for VS 2017.&lt;br&gt;&lt;br&gt;
A Developer Command Prompt window appears.&lt;/li&gt;
&lt;li&gt;In the command-prompt window, navigate to the folder that contains your Hello.cs file.
Enter the following command to compile Hello.cs.&lt;/li&gt;
&lt;strong&gt;csc Hello.cs&lt;/strong&gt;
&lt;li&gt;If your program has no compilation errors, an executable file that is named Hello.exe is created.
In the command-prompt window, enter the following command to run the program:&lt;/li&gt;
&lt;strong&gt;Hello&lt;/strong&gt;
&lt;/ol&gt;
&lt;!-- ####################################################################### --&gt;
&lt;/body&gt;
&lt;/html&gt;&lt;/div&gt;
</description><link>http://tangled-java.blogspot.com/2017/12/introduction-to-c.html</link><author>noreply@blogger.com (Anonymous)</author><thr:total>0</thr:total></item><item><guid isPermaLink="false">tag:blogger.com,1999:blog-3082064622906880860.post-9077323349607046697</guid><pubDate>Tue, 05 Dec 2017 16:28:00 +0000</pubDate><atom:updated>2017-12-05T08:31:38.725-08:00</atom:updated><category domain="http://www.blogger.com/atom/ns#">aggregation</category><category domain="http://www.blogger.com/atom/ns#">association</category><category domain="http://www.blogger.com/atom/ns#">composition</category><title>Association, Aggregation &amp; Composition, </title><description>&lt;div dir="ltr" style="text-align: left;" trbidi="on"&gt;
&lt;html&gt;
&lt;head&gt;
 &lt;title&gt;&lt;/title&gt;
&lt;style&gt; strong{ color: white; }&lt;/style&gt;
&lt;script type="text/javascript"&gt;
 /*! highlight.js v9.12.0 | BSD3 License | git.io/hljslicense */
!function(e){var n="object"==typeof window&amp;&amp;window||"object"==typeof self&amp;&amp;self;"undefined"!=typeof exports?e(exports):n&amp;&amp;(n.hljs=e({}),"function"==typeof define&amp;&amp;define.amd&amp;&amp;define([],function(){return n.hljs}))}(function(e){function n(e){return e.replace(/&amp;/g,"&amp;amp;").replace(/&lt;/g,"&amp;lt;").replace(/&gt;/g,"&amp;gt;")}function t(e){return e.nodeName.toLowerCase()}function r(e,n){var t=e&amp;&amp;e.exec(n);return t&amp;&amp;0===t.index}function a(e){return k.test(e)}function i(e){var n,t,r,i,o=e.className+" ";if(o+=e.parentNode?e.parentNode.className:"",t=B.exec(o))return w(t[1])?t[1]:"no-highlight";for(o=o.split(/\s+/),n=0,r=o.length;r&gt;n;n++)if(i=o[n],a(i)||w(i))return i}function o(e){var n,t={},r=Array.prototype.slice.call(arguments,1);for(n in e)t[n]=e[n];return r.forEach(function(e){for(n in e)t[n]=e[n]}),t}function u(e){var n=[];return function r(e,a){for(var i=e.firstChild;i;i=i.nextSibling)3===i.nodeType?a+=i.nodeValue.length:1===i.nodeType&amp;&amp;(n.push({event:"start",offset:a,node:i}),a=r(i,a),t(i).match(/br|hr|img|input/)||n.push({event:"stop",offset:a,node:i}));return a}(e,0),n}function c(e,r,a){function i(){return e.length&amp;&amp;r.length?e[0].offset!==r[0].offset?e[0].offset&lt;r[0].offset?e:r:"start"===r[0].event?e:r:e.length?e:r}function o(e){function r(e){return" "+e.nodeName+'="'+n(e.value).replace('"',"&amp;quot;")+'"'}s+="&lt;"+t(e)+E.map.call(e.attributes,r).join("")+"&gt;"}function u(e){s+="&lt;/"+t(e)+"&gt;"}function c(e){("start"===e.event?o:u)(e.node)}for(var l=0,s="",f=[];e.length||r.length;){var g=i();if(s+=n(a.substring(l,g[0].offset)),l=g[0].offset,g===e){f.reverse().forEach(u);do c(g.splice(0,1)[0]),g=i();while(g===e&amp;&amp;g.length&amp;&amp;g[0].offset===l);f.reverse().forEach(o)}else"start"===g[0].event?f.push(g[0].node):f.pop(),c(g.splice(0,1)[0])}return s+n(a.substr(l))}function l(e){return e.v&amp;&amp;!e.cached_variants&amp;&amp;(e.cached_variants=e.v.map(function(n){return o(e,{v:null},n)})),e.cached_variants||e.eW&amp;&amp;[o(e)]||[e]}function s(e){function n(e){return e&amp;&amp;e.source||e}function t(t,r){return new RegExp(n(t),"m"+(e.cI?"i":"")+(r?"g":""))}function r(a,i){if(!a.compiled){if(a.compiled=!0,a.k=a.k||a.bK,a.k){var o={},u=function(n,t){e.cI&amp;&amp;(t=t.toLowerCase()),t.split(" ").forEach(function(e){var t=e.split("|");o[t[0]]=[n,t[1]?Number(t[1]):1]})};"string"==typeof a.k?u("keyword",a.k):x(a.k).forEach(function(e){u(e,a.k[e])}),a.k=o}a.lR=t(a.l||/\w+/,!0),i&amp;&amp;(a.bK&amp;&amp;(a.b="\\b("+a.bK.split(" ").join("|")+")\\b"),a.b||(a.b=/\B|\b/),a.bR=t(a.b),a.e||a.eW||(a.e=/\B|\b/),a.e&amp;&amp;(a.eR=t(a.e)),a.tE=n(a.e)||"",a.eW&amp;&amp;i.tE&amp;&amp;(a.tE+=(a.e?"|":"")+i.tE)),a.i&amp;&amp;(a.iR=t(a.i)),null==a.r&amp;&amp;(a.r=1),a.c||(a.c=[]),a.c=Array.prototype.concat.apply([],a.c.map(function(e){return l("self"===e?a:e)})),a.c.forEach(function(e){r(e,a)}),a.starts&amp;&amp;r(a.starts,i);var c=a.c.map(function(e){return e.bK?"\\.?("+e.b+")\\.?":e.b}).concat([a.tE,a.i]).map(n).filter(Boolean);a.t=c.length?t(c.join("|"),!0):{exec:function(){return null}}}}r(e)}function f(e,t,a,i){function o(e,n){var t,a;for(t=0,a=n.c.length;a&gt;t;t++)if(r(n.c[t].bR,e))return n.c[t]}function u(e,n){if(r(e.eR,n)){for(;e.endsParent&amp;&amp;e.parent;)e=e.parent;return e}return e.eW?u(e.parent,n):void 0}function c(e,n){return!a&amp;&amp;r(n.iR,e)}function l(e,n){var t=N.cI?n[0].toLowerCase():n[0];return e.k.hasOwnProperty(t)&amp;&amp;e.k[t]}function p(e,n,t,r){var a=r?"":I.classPrefix,i='&lt;span class="'+a,o=t?"":C;return i+=e+'"&gt;',i+n+o}function h(){var e,t,r,a;if(!E.k)return n(k);for(a="",t=0,E.lR.lastIndex=0,r=E.lR.exec(k);r;)a+=n(k.substring(t,r.index)),e=l(E,r),e?(B+=e[1],a+=p(e[0],n(r[0]))):a+=n(r[0]),t=E.lR.lastIndex,r=E.lR.exec(k);return a+n(k.substr(t))}function d(){var e="string"==typeof E.sL;if(e&amp;&amp;!y[E.sL])return n(k);var t=e?f(E.sL,k,!0,x[E.sL]):g(k,E.sL.length?E.sL:void 0);return E.r&gt;0&amp;&amp;(B+=t.r),e&amp;&amp;(x[E.sL]=t.top),p(t.language,t.value,!1,!0)}function b(){L+=null!=E.sL?d():h(),k=""}function v(e){L+=e.cN?p(e.cN,"",!0):"",E=Object.create(e,{parent:{value:E}})}function m(e,n){if(k+=e,null==n)return b(),0;var t=o(n,E);if(t)return t.skip?k+=n:(t.eB&amp;&amp;(k+=n),b(),t.rB||t.eB||(k=n)),v(t,n),t.rB?0:n.length;var r=u(E,n);if(r){var a=E;a.skip?k+=n:(a.rE||a.eE||(k+=n),b(),a.eE&amp;&amp;(k=n));do E.cN&amp;&amp;(L+=C),E.skip||(B+=E.r),E=E.parent;while(E!==r.parent);return r.starts&amp;&amp;v(r.starts,""),a.rE?0:n.length}if(c(n,E))throw new Error('Illegal lexeme "'+n+'" for mode "'+(E.cN||"&lt;unnamed&gt;")+'"');return k+=n,n.length||1}var N=w(e);if(!N)throw new Error('Unknown language: "'+e+'"');s(N);var R,E=i||N,x={},L="";for(R=E;R!==N;R=R.parent)R.cN&amp;&amp;(L=p(R.cN,"",!0)+L);var k="",B=0;try{for(var M,j,O=0;;){if(E.t.lastIndex=O,M=E.t.exec(t),!M)break;j=m(t.substring(O,M.index),M[0]),O=M.index+j}for(m(t.substr(O)),R=E;R.parent;R=R.parent)R.cN&amp;&amp;(L+=C);return{r:B,value:L,language:e,top:E}}catch(T){if(T.message&amp;&amp;-1!==T.message.indexOf("Illegal"))return{r:0,value:n(t)};throw T}}function g(e,t){t=t||I.languages||x(y);var r={r:0,value:n(e)},a=r;return t.filter(w).forEach(function(n){var t=f(n,e,!1);t.language=n,t.r&gt;a.r&amp;&amp;(a=t),t.r&gt;r.r&amp;&amp;(a=r,r=t)}),a.language&amp;&amp;(r.second_best=a),r}function p(e){return I.tabReplace||I.useBR?e.replace(M,function(e,n){return I.useBR&amp;&amp;"\n"===e?"&lt;br&gt;":I.tabReplace?n.replace(/\t/g,I.tabReplace):""}):e}function h(e,n,t){var r=n?L[n]:t,a=[e.trim()];return e.match(/\bhljs\b/)||a.push("hljs"),-1===e.indexOf(r)&amp;&amp;a.push(r),a.join(" ").trim()}function d(e){var n,t,r,o,l,s=i(e);a(s)||(I.useBR?(n=document.createElementNS("http://www.w3.org/1999/xhtml","div"),n.innerHTML=e.innerHTML.replace(/\n/g,"").replace(/&lt;br[ \/]*&gt;/g,"\n")):n=e,l=n.textContent,r=s?f(s,l,!0):g(l),t=u(n),t.length&amp;&amp;(o=document.createElementNS("http://www.w3.org/1999/xhtml","div"),o.innerHTML=r.value,r.value=c(t,u(o),l)),r.value=p(r.value),e.innerHTML=r.value,e.className=h(e.className,s,r.language),e.result={language:r.language,re:r.r},r.second_best&amp;&amp;(e.second_best={language:r.second_best.language,re:r.second_best.r}))}function b(e){I=o(I,e)}function v(){if(!v.called){v.called=!0;var e=document.querySelectorAll("pre code");E.forEach.call(e,d)}}function m(){addEventListener("DOMContentLoaded",v,!1),addEventListener("load",v,!1)}function N(n,t){var r=y[n]=t(e);r.aliases&amp;&amp;r.aliases.forEach(function(e){L[e]=n})}function R(){return x(y)}function w(e){return e=(e||"").toLowerCase(),y[e]||y[L[e]]}var E=[],x=Object.keys,y={},L={},k=/^(no-?highlight|plain|text)$/i,B=/\blang(?:uage)?-([\w-]+)\b/i,M=/((^(&lt;[^&gt;]+&gt;|\t|)+|(?:\n)))/gm,C="&lt;/span&gt;",I={classPrefix:"hljs-",tabReplace:null,useBR:!1,languages:void 0};return e.highlight=f,e.highlightAuto=g,e.fixMarkup=p,e.highlightBlock=d,e.configure=b,e.initHighlighting=v,e.initHighlightingOnLoad=m,e.registerLanguage=N,e.listLanguages=R,e.getLanguage=w,e.inherit=o,e.IR="[a-zA-Z]\\w*",e.UIR="[a-zA-Z_]\\w*",e.NR="\\b\\d+(\\.\\d+)?",e.CNR="(-?)(\\b0[xX][a-fA-F0-9]+|(\\b\\d+(\\.\\d*)?|\\.\\d+)([eE][-+]?\\d+)?)",e.BNR="\\b(0b[01]+)",e.RSR="!|!=|!==|%|%=|&amp;|&amp;&amp;|&amp;=|\\*|\\*=|\\+|\\+=|,|-|-=|/=|/|:|;|&lt;&lt;|&lt;&lt;=|&lt;=|&lt;|===|==|=|&gt;&gt;&gt;=|&gt;&gt;=|&gt;=|&gt;&gt;&gt;|&gt;&gt;|&gt;|\\?|\\[|\\{|\\(|\\^|\\^=|\\||\\|=|\\|\\||~",e.BE={b:"\\\\[\\s\\S]",r:0},e.ASM={cN:"string",b:"'",e:"'",i:"\\n",c:[e.BE]},e.QSM={cN:"string",b:'"',e:'"',i:"\\n",c:[e.BE]},e.PWM={b:/\b(a|an|the|are|I'm|isn't|don't|doesn't|won't|but|just|should|pretty|simply|enough|gonna|going|wtf|so|such|will|you|your|they|like|more)\b/},e.C=function(n,t,r){var a=e.inherit({cN:"comment",b:n,e:t,c:[]},r||{});return a.c.push(e.PWM),a.c.push({cN:"doctag",b:"(?:TODO|FIXME|NOTE|BUG|XXX):",r:0}),a},e.CLCM=e.C("//","$"),e.CBCM=e.C("/\\*","\\*/"),e.HCM=e.C("#","$"),e.NM={cN:"number",b:e.NR,r:0},e.CNM={cN:"number",b:e.CNR,r:0},e.BNM={cN:"number",b:e.BNR,r:0},e.CSSNM={cN:"number",b:e.NR+"(%|em|ex|ch|rem|vw|vh|vmin|vmax|cm|mm|in|pt|pc|px|deg|grad|rad|turn|s|ms|Hz|kHz|dpi|dpcm|dppx)?",r:0},e.RM={cN:"regexp",b:/\//,e:/\/[gimuy]*/,i:/\n/,c:[e.BE,{b:/\[/,e:/\]/,r:0,c:[e.BE]}]},e.TM={cN:"title",b:e.IR,r:0},e.UTM={cN:"title",b:e.UIR,r:0},e.METHOD_GUARD={b:"\\.\\s*"+e.UIR,r:0},e});hljs.registerLanguage("java",function(e){var a="[À-ʸa-zA-Z_$][À-ʸa-zA-Z_$0-9]*",t=a+"(&lt;"+a+"(\\s*,\\s*"+a+")*&gt;)?",r="false synchronized int abstract float private char boolean static null if const for true while long strictfp finally protected import native final void enum else break transient catch instanceof byte super volatile case assert short package default double public try this switch continue throws protected public private module requires exports do",s="\\b(0[bB]([01]+[01_]+[01]+|[01]+)|0[xX]([a-fA-F0-9]+[a-fA-F0-9_]+[a-fA-F0-9]+|[a-fA-F0-9]+)|(([\\d]+[\\d_]+[\\d]+|[\\d]+)(\\.([\\d]+[\\d_]+[\\d]+|[\\d]+))?|\\.([\\d]+[\\d_]+[\\d]+|[\\d]+))([eE][-+]?\\d+)?)[lLfF]?",c={cN:"number",b:s,r:0};return{aliases:["jsp"],k:r,i:/&lt;\/|#/,c:[e.C("/\\*\\*","\\*/",{r:0,c:[{b:/\w+@/,r:0},{cN:"doctag",b:"@[A-Za-z]+"}]}),e.CLCM,e.CBCM,e.ASM,e.QSM,{cN:"class",bK:"class interface",e:/[{;=]/,eE:!0,k:"class interface",i:/[:"\[\]]/,c:[{bK:"extends implements"},e.UTM]},{bK:"new throw return else",r:0},{cN:"function",b:"("+t+"\\s+)+"+e.UIR+"\\s*\\(",rB:!0,e:/[{;=]/,eE:!0,k:r,c:[{b:e.UIR+"\\s*\\(",rB:!0,r:0,c:[e.UTM]},{cN:"params",b:/\(/,e:/\)/,k:r,r:0,c:[e.ASM,e.QSM,e.CNM,e.CBCM]},e.CLCM,e.CBCM]},c,{cN:"meta",b:"@[A-Za-z]+"}]}});
&lt;/script&gt;
&lt;script&gt;hljs.initHighlightingOnLoad();&lt;/script&gt;
&lt;/head&gt;
&lt;body onload="selectjava()"&gt;
&lt;div id="topics"&gt;&lt;/div&gt;
&lt;img src="https://www.shareicon.net/download/2015/09/16/101886_java_512x512.png" style="display: none;"/&gt;
&lt;!-- ####################################################################### --&gt;
&lt;h2&gt;Association&lt;/h2&gt;
Association is relation between two separate classes which establishes through their Objects. Association can be one-to-one, one-to-many, many-to-one, many-to-many.
In Object-Oriented programming, an Object communicates to other Object to use functionality and services provided by that object. &lt;strong&gt;Composition&lt;/strong&gt; and &lt;strong&gt;Aggregation&lt;/strong&gt; are the two forms of association.


&lt;h3&gt;Program&lt;/h3&gt;
&lt;pre&gt;
&lt;code class="java"&gt;
//Java program to understand the concept of association
class School
{
    private String school_name;
    School(String school_name)
    {
        this.school_name = school_name;
    }
    public String getSchoolName()
    {
        return this.school_name;
    }
}

class Student
{
    private String student_name;
    Student(String student_name)
    {
        this.student_name = student_name;
    }
    public String getStudentName()
    {
        return this.student_name;
    }
}

public class Main
{
    public static void main(String args[])
    {
        School s = new School("Sarsvati Vidyalaya");
        Student st = new Student("Hansraj Rami");
        System.out.println(st.getStudentName() + " is student of " + s.getSchoolName());
        //school can have many number of students so it is one to many relationship
    }
}
&lt;/code&gt;  
  &lt;a href="https://onlinegdb.com/S17yf4NZG"&gt;&lt;button class="button"&gt;&lt;span&gt;Run &lt;/span&gt;&lt;/button&gt;&lt;/a&gt;
&lt;/pre&gt;

&lt;h3&gt;Output&lt;/h3&gt;
&lt;pre&gt;
&lt;code class="java"&gt;
Hansraj Rami is student of Sarsvati Vidyalaya
&lt;/code&gt;  
&lt;/pre&gt;

&lt;h3&gt;Explanation&lt;/h3&gt;
In above exmaple we have created two separate classes &lt;strong&gt;School&lt;/strong&gt; and &lt;strong&gt;Student&lt;/strong&gt;.
school can have many number students so it is one to many relationship.

&lt;h2&gt;Aggregation&lt;/h2&gt;
It is a special form of Association where:
&lt;ul&gt;
&lt;li&gt;It represents Has-A relationship.&lt;/li&gt;
&lt;li&gt;It is a unidirectional association i.e. a one way relationship. For example, school can have students but vice versa is not possible and thus unidirectional in nature.&lt;/li&gt;
&lt;li&gt;In Aggregation, both the entries can survive individually which means ending one entity will not effect the other entity&lt;/li&gt;
&lt;/ul&gt;

&lt;h3&gt;Program&lt;/h3&gt;
&lt;pre&gt;
&lt;code class="java"&gt;
//java program to understand the concept of composition
class Circle
{
    // aggregation
    Square_operation s;
    double PI = 3.14;
    double area(int radius)
    {
        s = new Square_operation();
        int r_sq = s.square(radius);
        return PI*r_sq;
    }
}

class Square_operation
{
    int square(int r)
    {
        return r*r;
    }
}

public class Main
{
    public static void main(String args[])
    {
        Circle c = new Circle();
        System.out.println(c.area(10));
    }
}
&lt;/code&gt;  
  &lt;a href="https://onlinegdb.com/BJWNKENWz"&gt;&lt;button class="button"&gt;&lt;span&gt;Run &lt;/span&gt;&lt;/button&gt;&lt;/a&gt;
&lt;/pre&gt;

&lt;h3&gt;Output&lt;/h3&gt;
&lt;pre&gt;
&lt;code class="java"&gt;
314.0
&lt;/code&gt;  
&lt;/pre&gt;

&lt;h3&gt;Explanation&lt;/h3&gt;
Consider above example, Circle object contains informations such as PI. It contains one more object named &lt;strong&gt;Square_operation&lt;/strong&gt;, which contains its own information such as radius.So, there is a &lt;strong&gt;HAS-A&lt;/strong&gt; relationship between class &lt;strong&gt;Circle&lt;/strong&gt; and &lt;strong&gt;Square_operation&lt;/strong&gt;.
&lt;h2&gt;Why and when do we use Aggregation?&lt;/h2&gt;
Code reuse is best achieved by aggregation.
Inheritance should be used only if the relationship &lt;strong&gt;IS-A&lt;/strong&gt; is maintained throughout the lifetime of the objects involved; otherwise, aggregation is the best choice.
&lt;h2&gt;Composition&lt;/h2&gt;
Composition is a restricted form of Aggregation in which two entities are highly dependent on each other.
&lt;ul&gt;
&lt;li&gt;It represents part-of relationship.&lt;/li&gt;
&lt;li&gt;In composition, both the entities are dependent on each other.&lt;/li&gt;
&lt;li&gt;When there is a composition between two entities, the composed object cannot exist without the other entity.&lt;/li&gt;
&lt;/ul&gt;

&lt;h3&gt;Program&lt;/h3&gt;
&lt;pre&gt;
&lt;code class="java"&gt;
//java program to understand the concept of composition
class Library
{
    //library can have no of books
    //book does not exist without library 
    // so there is strong relationship it is called composition
    Book b;
    Library(String bookname)
    {
        b = new Book(bookname);
        b.getBookInfo();
    }
}

class Book
{
    String bookname;

    Book(String bookname)
    {
        this.bookname = bookname;
    }

    public void getBookInfo()
    {
        System.out.println(bookname);
    }
}

public class Main
{
    public static void main(String args[])
    {
        Library l = new Library("Hemlet");
    }
}
&lt;/code&gt;  
  &lt;a href="https://onlinegdb.com/BkQL-BNWM"&gt;&lt;button class="button"&gt;&lt;span&gt;Run &lt;/span&gt;&lt;/button&gt;&lt;/a&gt;
&lt;/pre&gt;

&lt;h3&gt;Output&lt;/h3&gt;
&lt;pre&gt;
&lt;code class="java"&gt;
Hemlet
&lt;/code&gt;  
&lt;/pre&gt;

&lt;h3&gt;Explanation&lt;/h3&gt;
In above example a library can have no. of books on same or different subjects. So, If Library gets destroyed then All books within that particular library will be destroyed. i.e. book can not exist without library. That’s why it is composition.

&lt;h2&gt;Difference between Association, Aggregation and Composition&lt;/h2&gt;
In Object-oriented programming, one object is related to other to use functionality and service provided by that object. This relationship between two objects is known as the association in  object oriented general software design and depicted by an arrow in Unified Modelling language or UML. Both Composition and Aggregation are the form of association between two objects, but there is a subtle difference between composition and aggregation, which is also reflected by their UML notation. We refer association between two objects as Composition, when one class owns other class and other class can not meaningfully exist, when it's owner destroyed, for example, Human class is a composition of several body parts including Hand, Leg and Heart. When human object dies, all it's body part ceased to exist meaningfully, this is one example of Composition.&lt;br&gt;&lt;br&gt;

Programmers often confuse between Association, Composition and Aggregation in Object oriented design discussions, this confusion also makes the difference between Association, Composition and Aggregation one of the popular questions in Java Interviews, only after the difference between abstract class and interface .&lt;br&gt;&lt;br&gt;

Another example of Composition is Car and it's part e.g. engines, wheels etc. Individual parts of the car can not function when a car is destroyed.  While in the case of Aggregation, including object can exists without being part of the main object e.g. a Player which is part of a Team, can exist without a team and can become part of other teams as well.&lt;br&gt;&lt;br&gt;

Another example of Aggregation is Student in School class, when School closed, Student still exist and then can join another School or so.  In UML notation, a composition is denoted by a filled diamond, while aggregation is denoted by an empty diamond, which shows their obvious difference in terms of strength of the relationship.&lt;br&gt;&lt;br&gt;

The composition is stronger than Aggregation.  In Short, a relationship between two objects is referred as an association, and an association is known as composition when one object owns other while an association is known as aggregation when one object uses another object.&lt;br&gt;&lt;br&gt;
&lt;!-- ####################################################################### --&gt;
&lt;/body&gt;
&lt;/html&gt;&lt;/div&gt;
</description><link>http://tangled-java.blogspot.com/2017/12/association-aggregation-composition.html</link><author>noreply@blogger.com (Anonymous)</author><thr:total>0</thr:total></item><item><guid isPermaLink="false">tag:blogger.com,1999:blog-3082064622906880860.post-7528899338142279552</guid><pubDate>Sun, 03 Dec 2017 19:50:00 +0000</pubDate><atom:updated>2017-12-03T11:50:17.401-08:00</atom:updated><category domain="http://www.blogger.com/atom/ns#">inheritance</category><title>Inheritance</title><description>&lt;div dir="ltr" style="text-align: left;" trbidi="on"&gt;
&lt;html&gt;
&lt;head&gt;
 &lt;title&gt;&lt;/title&gt;
&lt;style&gt; strong{ color: white; }&lt;/style&gt;
&lt;script type="text/javascript"&gt;
 /*! highlight.js v9.12.0 | BSD3 License | git.io/hljslicense */
!function(e){var n="object"==typeof window&amp;&amp;window||"object"==typeof self&amp;&amp;self;"undefined"!=typeof exports?e(exports):n&amp;&amp;(n.hljs=e({}),"function"==typeof define&amp;&amp;define.amd&amp;&amp;define([],function(){return n.hljs}))}(function(e){function n(e){return e.replace(/&amp;/g,"&amp;amp;").replace(/&lt;/g,"&amp;lt;").replace(/&gt;/g,"&amp;gt;")}function t(e){return e.nodeName.toLowerCase()}function r(e,n){var t=e&amp;&amp;e.exec(n);return t&amp;&amp;0===t.index}function a(e){return k.test(e)}function i(e){var n,t,r,i,o=e.className+" ";if(o+=e.parentNode?e.parentNode.className:"",t=B.exec(o))return w(t[1])?t[1]:"no-highlight";for(o=o.split(/\s+/),n=0,r=o.length;r&gt;n;n++)if(i=o[n],a(i)||w(i))return i}function o(e){var n,t={},r=Array.prototype.slice.call(arguments,1);for(n in e)t[n]=e[n];return r.forEach(function(e){for(n in e)t[n]=e[n]}),t}function u(e){var n=[];return function r(e,a){for(var i=e.firstChild;i;i=i.nextSibling)3===i.nodeType?a+=i.nodeValue.length:1===i.nodeType&amp;&amp;(n.push({event:"start",offset:a,node:i}),a=r(i,a),t(i).match(/br|hr|img|input/)||n.push({event:"stop",offset:a,node:i}));return a}(e,0),n}function c(e,r,a){function i(){return e.length&amp;&amp;r.length?e[0].offset!==r[0].offset?e[0].offset&lt;r[0].offset?e:r:"start"===r[0].event?e:r:e.length?e:r}function o(e){function r(e){return" "+e.nodeName+'="'+n(e.value).replace('"',"&amp;quot;")+'"'}s+="&lt;"+t(e)+E.map.call(e.attributes,r).join("")+"&gt;"}function u(e){s+="&lt;/"+t(e)+"&gt;"}function c(e){("start"===e.event?o:u)(e.node)}for(var l=0,s="",f=[];e.length||r.length;){var g=i();if(s+=n(a.substring(l,g[0].offset)),l=g[0].offset,g===e){f.reverse().forEach(u);do c(g.splice(0,1)[0]),g=i();while(g===e&amp;&amp;g.length&amp;&amp;g[0].offset===l);f.reverse().forEach(o)}else"start"===g[0].event?f.push(g[0].node):f.pop(),c(g.splice(0,1)[0])}return s+n(a.substr(l))}function l(e){return e.v&amp;&amp;!e.cached_variants&amp;&amp;(e.cached_variants=e.v.map(function(n){return o(e,{v:null},n)})),e.cached_variants||e.eW&amp;&amp;[o(e)]||[e]}function s(e){function n(e){return e&amp;&amp;e.source||e}function t(t,r){return new RegExp(n(t),"m"+(e.cI?"i":"")+(r?"g":""))}function r(a,i){if(!a.compiled){if(a.compiled=!0,a.k=a.k||a.bK,a.k){var o={},u=function(n,t){e.cI&amp;&amp;(t=t.toLowerCase()),t.split(" ").forEach(function(e){var t=e.split("|");o[t[0]]=[n,t[1]?Number(t[1]):1]})};"string"==typeof a.k?u("keyword",a.k):x(a.k).forEach(function(e){u(e,a.k[e])}),a.k=o}a.lR=t(a.l||/\w+/,!0),i&amp;&amp;(a.bK&amp;&amp;(a.b="\\b("+a.bK.split(" ").join("|")+")\\b"),a.b||(a.b=/\B|\b/),a.bR=t(a.b),a.e||a.eW||(a.e=/\B|\b/),a.e&amp;&amp;(a.eR=t(a.e)),a.tE=n(a.e)||"",a.eW&amp;&amp;i.tE&amp;&amp;(a.tE+=(a.e?"|":"")+i.tE)),a.i&amp;&amp;(a.iR=t(a.i)),null==a.r&amp;&amp;(a.r=1),a.c||(a.c=[]),a.c=Array.prototype.concat.apply([],a.c.map(function(e){return l("self"===e?a:e)})),a.c.forEach(function(e){r(e,a)}),a.starts&amp;&amp;r(a.starts,i);var c=a.c.map(function(e){return e.bK?"\\.?("+e.b+")\\.?":e.b}).concat([a.tE,a.i]).map(n).filter(Boolean);a.t=c.length?t(c.join("|"),!0):{exec:function(){return null}}}}r(e)}function f(e,t,a,i){function o(e,n){var t,a;for(t=0,a=n.c.length;a&gt;t;t++)if(r(n.c[t].bR,e))return n.c[t]}function u(e,n){if(r(e.eR,n)){for(;e.endsParent&amp;&amp;e.parent;)e=e.parent;return e}return e.eW?u(e.parent,n):void 0}function c(e,n){return!a&amp;&amp;r(n.iR,e)}function l(e,n){var t=N.cI?n[0].toLowerCase():n[0];return e.k.hasOwnProperty(t)&amp;&amp;e.k[t]}function p(e,n,t,r){var a=r?"":I.classPrefix,i='&lt;span class="'+a,o=t?"":C;return i+=e+'"&gt;',i+n+o}function h(){var e,t,r,a;if(!E.k)return n(k);for(a="",t=0,E.lR.lastIndex=0,r=E.lR.exec(k);r;)a+=n(k.substring(t,r.index)),e=l(E,r),e?(B+=e[1],a+=p(e[0],n(r[0]))):a+=n(r[0]),t=E.lR.lastIndex,r=E.lR.exec(k);return a+n(k.substr(t))}function d(){var e="string"==typeof E.sL;if(e&amp;&amp;!y[E.sL])return n(k);var t=e?f(E.sL,k,!0,x[E.sL]):g(k,E.sL.length?E.sL:void 0);return E.r&gt;0&amp;&amp;(B+=t.r),e&amp;&amp;(x[E.sL]=t.top),p(t.language,t.value,!1,!0)}function b(){L+=null!=E.sL?d():h(),k=""}function v(e){L+=e.cN?p(e.cN,"",!0):"",E=Object.create(e,{parent:{value:E}})}function m(e,n){if(k+=e,null==n)return b(),0;var t=o(n,E);if(t)return t.skip?k+=n:(t.eB&amp;&amp;(k+=n),b(),t.rB||t.eB||(k=n)),v(t,n),t.rB?0:n.length;var r=u(E,n);if(r){var a=E;a.skip?k+=n:(a.rE||a.eE||(k+=n),b(),a.eE&amp;&amp;(k=n));do E.cN&amp;&amp;(L+=C),E.skip||(B+=E.r),E=E.parent;while(E!==r.parent);return r.starts&amp;&amp;v(r.starts,""),a.rE?0:n.length}if(c(n,E))throw new Error('Illegal lexeme "'+n+'" for mode "'+(E.cN||"&lt;unnamed&gt;")+'"');return k+=n,n.length||1}var N=w(e);if(!N)throw new Error('Unknown language: "'+e+'"');s(N);var R,E=i||N,x={},L="";for(R=E;R!==N;R=R.parent)R.cN&amp;&amp;(L=p(R.cN,"",!0)+L);var k="",B=0;try{for(var M,j,O=0;;){if(E.t.lastIndex=O,M=E.t.exec(t),!M)break;j=m(t.substring(O,M.index),M[0]),O=M.index+j}for(m(t.substr(O)),R=E;R.parent;R=R.parent)R.cN&amp;&amp;(L+=C);return{r:B,value:L,language:e,top:E}}catch(T){if(T.message&amp;&amp;-1!==T.message.indexOf("Illegal"))return{r:0,value:n(t)};throw T}}function g(e,t){t=t||I.languages||x(y);var r={r:0,value:n(e)},a=r;return t.filter(w).forEach(function(n){var t=f(n,e,!1);t.language=n,t.r&gt;a.r&amp;&amp;(a=t),t.r&gt;r.r&amp;&amp;(a=r,r=t)}),a.language&amp;&amp;(r.second_best=a),r}function p(e){return I.tabReplace||I.useBR?e.replace(M,function(e,n){return I.useBR&amp;&amp;"\n"===e?"&lt;br&gt;":I.tabReplace?n.replace(/\t/g,I.tabReplace):""}):e}function h(e,n,t){var r=n?L[n]:t,a=[e.trim()];return e.match(/\bhljs\b/)||a.push("hljs"),-1===e.indexOf(r)&amp;&amp;a.push(r),a.join(" ").trim()}function d(e){var n,t,r,o,l,s=i(e);a(s)||(I.useBR?(n=document.createElementNS("http://www.w3.org/1999/xhtml","div"),n.innerHTML=e.innerHTML.replace(/\n/g,"").replace(/&lt;br[ \/]*&gt;/g,"\n")):n=e,l=n.textContent,r=s?f(s,l,!0):g(l),t=u(n),t.length&amp;&amp;(o=document.createElementNS("http://www.w3.org/1999/xhtml","div"),o.innerHTML=r.value,r.value=c(t,u(o),l)),r.value=p(r.value),e.innerHTML=r.value,e.className=h(e.className,s,r.language),e.result={language:r.language,re:r.r},r.second_best&amp;&amp;(e.second_best={language:r.second_best.language,re:r.second_best.r}))}function b(e){I=o(I,e)}function v(){if(!v.called){v.called=!0;var e=document.querySelectorAll("pre code");E.forEach.call(e,d)}}function m(){addEventListener("DOMContentLoaded",v,!1),addEventListener("load",v,!1)}function N(n,t){var r=y[n]=t(e);r.aliases&amp;&amp;r.aliases.forEach(function(e){L[e]=n})}function R(){return x(y)}function w(e){return e=(e||"").toLowerCase(),y[e]||y[L[e]]}var E=[],x=Object.keys,y={},L={},k=/^(no-?highlight|plain|text)$/i,B=/\blang(?:uage)?-([\w-]+)\b/i,M=/((^(&lt;[^&gt;]+&gt;|\t|)+|(?:\n)))/gm,C="&lt;/span&gt;",I={classPrefix:"hljs-",tabReplace:null,useBR:!1,languages:void 0};return e.highlight=f,e.highlightAuto=g,e.fixMarkup=p,e.highlightBlock=d,e.configure=b,e.initHighlighting=v,e.initHighlightingOnLoad=m,e.registerLanguage=N,e.listLanguages=R,e.getLanguage=w,e.inherit=o,e.IR="[a-zA-Z]\\w*",e.UIR="[a-zA-Z_]\\w*",e.NR="\\b\\d+(\\.\\d+)?",e.CNR="(-?)(\\b0[xX][a-fA-F0-9]+|(\\b\\d+(\\.\\d*)?|\\.\\d+)([eE][-+]?\\d+)?)",e.BNR="\\b(0b[01]+)",e.RSR="!|!=|!==|%|%=|&amp;|&amp;&amp;|&amp;=|\\*|\\*=|\\+|\\+=|,|-|-=|/=|/|:|;|&lt;&lt;|&lt;&lt;=|&lt;=|&lt;|===|==|=|&gt;&gt;&gt;=|&gt;&gt;=|&gt;=|&gt;&gt;&gt;|&gt;&gt;|&gt;|\\?|\\[|\\{|\\(|\\^|\\^=|\\||\\|=|\\|\\||~",e.BE={b:"\\\\[\\s\\S]",r:0},e.ASM={cN:"string",b:"'",e:"'",i:"\\n",c:[e.BE]},e.QSM={cN:"string",b:'"',e:'"',i:"\\n",c:[e.BE]},e.PWM={b:/\b(a|an|the|are|I'm|isn't|don't|doesn't|won't|but|just|should|pretty|simply|enough|gonna|going|wtf|so|such|will|you|your|they|like|more)\b/},e.C=function(n,t,r){var a=e.inherit({cN:"comment",b:n,e:t,c:[]},r||{});return a.c.push(e.PWM),a.c.push({cN:"doctag",b:"(?:TODO|FIXME|NOTE|BUG|XXX):",r:0}),a},e.CLCM=e.C("//","$"),e.CBCM=e.C("/\\*","\\*/"),e.HCM=e.C("#","$"),e.NM={cN:"number",b:e.NR,r:0},e.CNM={cN:"number",b:e.CNR,r:0},e.BNM={cN:"number",b:e.BNR,r:0},e.CSSNM={cN:"number",b:e.NR+"(%|em|ex|ch|rem|vw|vh|vmin|vmax|cm|mm|in|pt|pc|px|deg|grad|rad|turn|s|ms|Hz|kHz|dpi|dpcm|dppx)?",r:0},e.RM={cN:"regexp",b:/\//,e:/\/[gimuy]*/,i:/\n/,c:[e.BE,{b:/\[/,e:/\]/,r:0,c:[e.BE]}]},e.TM={cN:"title",b:e.IR,r:0},e.UTM={cN:"title",b:e.UIR,r:0},e.METHOD_GUARD={b:"\\.\\s*"+e.UIR,r:0},e});hljs.registerLanguage("java",function(e){var a="[À-ʸa-zA-Z_$][À-ʸa-zA-Z_$0-9]*",t=a+"(&lt;"+a+"(\\s*,\\s*"+a+")*&gt;)?",r="false synchronized int abstract float private char boolean static null if const for true while long strictfp finally protected import native final void enum else break transient catch instanceof byte super volatile case assert short package default double public try this switch continue throws protected public private module requires exports do",s="\\b(0[bB]([01]+[01_]+[01]+|[01]+)|0[xX]([a-fA-F0-9]+[a-fA-F0-9_]+[a-fA-F0-9]+|[a-fA-F0-9]+)|(([\\d]+[\\d_]+[\\d]+|[\\d]+)(\\.([\\d]+[\\d_]+[\\d]+|[\\d]+))?|\\.([\\d]+[\\d_]+[\\d]+|[\\d]+))([eE][-+]?\\d+)?)[lLfF]?",c={cN:"number",b:s,r:0};return{aliases:["jsp"],k:r,i:/&lt;\/|#/,c:[e.C("/\\*\\*","\\*/",{r:0,c:[{b:/\w+@/,r:0},{cN:"doctag",b:"@[A-Za-z]+"}]}),e.CLCM,e.CBCM,e.ASM,e.QSM,{cN:"class",bK:"class interface",e:/[{;=]/,eE:!0,k:"class interface",i:/[:"\[\]]/,c:[{bK:"extends implements"},e.UTM]},{bK:"new throw return else",r:0},{cN:"function",b:"("+t+"\\s+)+"+e.UIR+"\\s*\\(",rB:!0,e:/[{;=]/,eE:!0,k:r,c:[{b:e.UIR+"\\s*\\(",rB:!0,r:0,c:[e.UTM]},{cN:"params",b:/\(/,e:/\)/,k:r,r:0,c:[e.ASM,e.QSM,e.CNM,e.CBCM]},e.CLCM,e.CBCM]},c,{cN:"meta",b:"@[A-Za-z]+"}]}});
&lt;/script&gt;
&lt;script&gt;hljs.initHighlightingOnLoad();&lt;/script&gt;
&lt;/head&gt;
&lt;body onload="selectjava()"&gt;
&lt;div id="topics"&gt;&lt;/div&gt;
&lt;!-- ####################################################################### --&gt;
&lt;h2&gt; Inheritance in Java&lt;/h2&gt;
Classes in Java exist in a hierarchy. A class in Java can be declared as a subclass of another class using the &lt;strong&gt;extends&lt;/strong&gt; keyword. A subclass inherits variables and methods from its superclass and can use them as if they were declared within the subclass itself:

&lt;h2&gt;Important terminology in inheritance&lt;/h2&gt;
&lt;strong&gt;Super Class:&lt;/strong&gt; The class whose features are inherited is known as super class(or a base class or a paren class).&lt;br&gt;&lt;br&gt;
&lt;strong&gt;Sub Class:&lt;/strong&gt; The class that inherits the other class is known as sub class(or a derived class, extended class, or child class). The subclass can add its own fields and methods in addition to the superclass fields and methods.&lt;br&gt;&lt;br&gt;
&lt;strong&gt;Reusability:&lt;/strong&gt; Inheritance supports the concept of “reusability”, i.e. when we want to create a new class and there is already a class that includes some of the code that we want, we can derive our new class from the existing class. By doing this, we are reusing the fields and methods of the existing class.&lt;br&gt;&lt;br&gt;

Inheritance represents the IS-A relationship, also known as parent-child relationship.The keyword used for inheritance is &lt;strong&gt;extends&lt;/strong&gt;.

&lt;h3&gt;Syntax&lt;/h3&gt;
&lt;pre&gt;
&lt;code class="java"&gt;
class derived-class extends base-class  
{  
   //methods and fields  
}  
&lt;/code&gt;  
&lt;/pre&gt;

The extends keyword indicates that you are making a new class that derives from an existing class. The meaning of "extends" is to increase the functionality.

&lt;h2&gt;Use of inheritance in Java&lt;/h2&gt;
1. For Method Overriding (so runtime polymorphism can be achieved).&lt;br&gt;&lt;br&gt;
2. For Code Reusability.&lt;br&gt;&lt;br&gt;

&lt;h3&gt;Program&lt;/h3&gt;
&lt;pre&gt;
&lt;code class="java"&gt;
class Animal
{
    int weight;
    String name;

    void walking()
    {
        System.out.println("Animal is walking");
    }
}

//extends the properties of superclass Animal
class Cat extends Animal
{
    
}

public class Main
{
    public static void main(String args[])
    {
        Cat c = new Cat();
        // Accessing variable of superclass with instance of subclass
        c.name = "minii";
        c.weight = 8;
        System.out.println("name = " + c.name + " weight = " + c.weight);
        // Accessing method of superclass with instance of subclass
        c.walking();
    }
}
&lt;/code&gt;  
  &lt;a href="https://onlinegdb.com/HkzltabbM"&gt;&lt;button class="button"&gt;&lt;span&gt;Run &lt;/span&gt;&lt;/button&gt;&lt;/a&gt;
&lt;/pre&gt;

&lt;h3&gt;Output&lt;/h3&gt;
&lt;pre&gt;
&lt;code class="java"&gt;
name = minii weight = 8
Animal is walking
&lt;/code&gt;  
&lt;/pre&gt;

&lt;h3&gt;Explanation&lt;/h3&gt;
As displayed in the above program, &lt;strong&gt;Cat&lt;/strong&gt; is the &lt;strong&gt;subclass&lt;/strong&gt; and &lt;strong&gt;Animal&lt;/strong&gt; is the &lt;strong&gt;superclass&lt;/strong&gt;. Relationship between two classes is &lt;strong&gt;Cat&lt;/strong&gt; IS-A &lt;strong&gt;Animal&lt;/strong&gt;.It means that Cat is a type of Animal.&lt;br&gt;&lt;br&gt;

In the above example, &lt;strong&gt;Cat&lt;/strong&gt; object can access the field and method of own class as well as of &lt;strong&gt;Animal&lt;/strong&gt; class i.e. code reusability.

&lt;h2&gt;Types of inheritance in Java&lt;/h2&gt;

Below are the different types of inheritance which is supported by Java.

1. &lt;strong&gt;Single Inheritance&lt;/strong&gt; : In single inheritance, subclasses inherit the features of one superclass. In image below, the class A serves as a base class for the derived class B.
&lt;h2&gt;Single inheritance example in Java&lt;/h2&gt;

&lt;h3&gt;Program&lt;/h3&gt;
&lt;pre&gt;
&lt;code class="java"&gt;
class Creature
{
    void eating()
    {
        System.out.println("Eating...");
    }
}

//extends the properties of superclass Creature
class Cat extends Creature
{
    void walking()
    {
        System.out.println("Walking...");
    }
}

public class Main
{
    public static void main(String args[])
    {
        Cat c = new Cat();
        // Accessing method of superclass with instance of subclass
        c.eating();
        c.walking();
    }
}
&lt;/code&gt;  
  &lt;a href="https://onlinegdb.com/SJSwRp-ZM"&gt;&lt;button class="button"&gt;&lt;span&gt;Run &lt;/span&gt;&lt;/button&gt;&lt;/a&gt;
&lt;/pre&gt;

&lt;h3&gt;Output&lt;/h3&gt;
&lt;pre&gt;
&lt;code class="java"&gt;
Eating...
Walking...
&lt;/code&gt;  
&lt;/pre&gt;
&lt;img src="https://www.javatpoint.com/images/core/typesofinheritance.jpg"&gt;&lt;br&gt;
2. &lt;strong&gt;Multilevel Inheritance&lt;/strong&gt; : In Multilevel Inheritance, a derived class will be inheriting a base class and as well as the derived class also act as the base class to other class. In below image, the class A serves as a base class for the derived class B, which in turn serves as a base class for the derived class C. In Java, a class cannot directly access the grandparent’s members.
&lt;h2&gt;Multlevel inheritance example in Java&lt;/h2&gt;

&lt;h3&gt;Program&lt;/h3&gt;
&lt;pre&gt;
&lt;code class="java"&gt;
class grand_parent
{
    void gp()
    {
        System.out.println("I am grand parent");
    }
}

//extends the properties of superclass grand_parent
class parent extends grand_parent
{
    void p()
    {
        System.out.println("I am parent");
    }
}

//extends the properties of superclass parent
class child extends parent
{
    void c()
    {
        System.out.println("I am child");
    }
}

public class Main
{
    public static void main(String args[])
    {
        child c = new child();
        // Accessing method of superclass with instance of subclass
        c.c();
        c.p();
        c.gp();
    }
}
&lt;/code&gt;  
  &lt;a href="https://onlinegdb.com/B1iWWR-bf"&gt;&lt;button class="button"&gt;&lt;span&gt;Run &lt;/span&gt;&lt;/button&gt;&lt;/a&gt;
&lt;/pre&gt;

&lt;h3&gt;Output&lt;/h3&gt;
&lt;pre&gt;
&lt;code class="java"&gt;
I am child
I am parent
I am grand parent
&lt;/code&gt;  
&lt;/pre&gt;


3. &lt;strong&gt;Hierarchical Inheritance&lt;/strong&gt; : In Hierarchical Inheritance, one class serves as a superclass (base class) for more than one sub class.In below image, the class A serves as a base class for the derived class B and C.

&lt;h3&gt;Program&lt;/h3&gt;
&lt;pre&gt;
&lt;code class="java"&gt;
class Creature
{
    void eating()
    {
        System.out.println("Eating...");
    }
}

//extends the properties of superclass Creature
class Cat extends Creature
{
    void walking()
    {
        System.out.println("Walking...");
    }
}

//extends the properties of superclass Creature
class crow extends Creature
{
    void flying()
    {
        System.out.println("Flying...");
    }
}

public class Main
{
    public static void main(String args[])
    {
        Cat c = new Cat();
        crow c2 = new crow();
        // Accessing method of superclass with instance of subclass
        c.eating();
        c.walking();
        c2.eating();
        c2.flying();
    }
}
&lt;/code&gt;  
  &lt;a href="https://onlinegdb.com/HkMQfRbWz"&gt;&lt;button class="button"&gt;&lt;span&gt;Run &lt;/span&gt;&lt;/button&gt;&lt;/a&gt;
&lt;/pre&gt;

&lt;h3&gt;Output&lt;/h3&gt;
&lt;pre&gt;
&lt;code class="java"&gt;
Eating...
Walking...
Eating...
Flying...
&lt;/code&gt;  
&lt;/pre&gt;


4. &lt;strong&gt;Multiple Inheritance (Through Interfaces)&lt;/strong&gt; : In Multiple inheritance ,one class can have more than one superclass and inherit features from all parent classes. &lt;strong&gt;Please note that Java does not support multiple inheritance with classes&lt;/strong&gt;. In java, we can achieve multiple inheritance only through &lt;strong&gt;Interfaces&lt;/strong&gt;. In image below, Class C is derived from interface A and B.

&lt;h2&gt;Why multiple inheritance is not supported in Java?&lt;/h2&gt;

To reduce the complexity and simplify the language, multiple inheritance is not supported in java.
Consider a scenario where A, B and C are three classes. The C class inherits A and B classes. If A and B classes have same method and you call it from child class object, there will be ambiguity to call method of A or B class.
Since compile time errors are better than runtime errors, java renders compile time error if you inherit 2 classes. So whether you have same method or different, there will be compile time error now.


&lt;h3&gt;Program&lt;/h3&gt;
&lt;pre&gt;
&lt;code class="java"&gt;
class Creature
{
    void eating()
    {
        System.out.println("Creature");
    }
}

class Animal
{
    void walking()
    {
        System.out.println("Animal");
    }
}

//for example purpose
class crow extends Creature,Animal
{
    void bird()
    {
        System.out.println("Animal and Creature");
    }
}

public class Main
{
    public static void main(String args[])
    {
    }
}
&lt;/code&gt;  
  &lt;a href="https://onlinegdb.com/Hk5sXA-Wz"&gt;&lt;button class="button"&gt;&lt;span&gt;Run &lt;/span&gt;&lt;/button&gt;&lt;/a&gt;
&lt;/pre&gt;

&lt;h3&gt;Output&lt;/h3&gt;
&lt;pre&gt;
&lt;code class="java"&gt;
compile time error occurs
&lt;/code&gt;  
&lt;/pre&gt;

5.&lt;strong&gt;Hybrid Inheritance(Through Interfaces)&lt;/strong&gt; : It is a mix of two or more of the above types of inheritance. Since java doesn’t support multiple inheritance with classes, the hybrid inheritance is also not possible with classes. In java, we can achieve hybrid inheritance only through Interfaces.

&lt;img src="https://www.javatpoint.com/images/core/multiple.jpg"&gt;

&lt;h2&gt;Important facts about inheritance in Java&lt;/h2&gt;

&lt;strong&gt;Default superclass:&lt;/strong&gt; Except Object class, which has no superclass, every class has one and only one direct superclass (single inheritance). In the absence of any other explicit superclass, every class is implicitly a subclass of Object class.&lt;br&gt;&lt;br&gt;
&lt;strong&gt;Superclass can only be one:&lt;/strong&gt; A superclass can have any number of subclasses. But a subclass can have only one superclass. This is because Java does not support multiple inheritance with classes. Although with interfaces, multiple inheritance is supported by java.&lt;br&gt;&lt;br&gt;
&lt;strong&gt;Inheriting Constructors:&lt;/strong&gt; A subclass inherits all the members (fields, methods, and nested classes) from its superclass. Constructors are not members, so they are not inherited by subclasses, but the constructor of the superclass can be invoked from the subclass.&lt;br&gt;&lt;br&gt;
&lt;strong&gt;Private member inheritance:&lt;/strong&gt; A subclass does not inherit the private members of its parent class. However, if the superclass has public or protected methods(like getters and setters) for accessing its private fields, these can also be used by the subclass.&lt;br&gt;&lt;br&gt;
&lt;!-- ####################################################################### --&gt;
&lt;/body&gt;
&lt;/html&gt;&lt;/div&gt;
</description><link>http://tangled-java.blogspot.com/2017/12/inheritance.html</link><author>noreply@blogger.com (Anonymous)</author><thr:total>0</thr:total></item><item><guid isPermaLink="false">tag:blogger.com,1999:blog-3082064622906880860.post-8496565129768976966</guid><pubDate>Sat, 02 Dec 2017 18:10:00 +0000</pubDate><atom:updated>2017-12-02T10:10:39.350-08:00</atom:updated><category domain="http://www.blogger.com/atom/ns#">difference of static in c++ and Java</category><category domain="http://www.blogger.com/atom/ns#">static keyword</category><category domain="http://www.blogger.com/atom/ns#">why main method is static?</category><title>static keyword in Java</title><description>&lt;div dir="ltr" style="text-align: left;" trbidi="on"&gt;
&lt;html&gt;
&lt;head&gt;
 &lt;title&gt;&lt;/title&gt;
&lt;style&gt; strong{ color: white; }&lt;/style&gt;
&lt;script type="text/javascript"&gt;
 /*! highlight.js v9.12.0 | BSD3 License | git.io/hljslicense */
!function(e){var n="object"==typeof window&amp;&amp;window||"object"==typeof self&amp;&amp;self;"undefined"!=typeof exports?e(exports):n&amp;&amp;(n.hljs=e({}),"function"==typeof define&amp;&amp;define.amd&amp;&amp;define([],function(){return n.hljs}))}(function(e){function n(e){return e.replace(/&amp;/g,"&amp;amp;").replace(/&lt;/g,"&amp;lt;").replace(/&gt;/g,"&amp;gt;")}function t(e){return e.nodeName.toLowerCase()}function r(e,n){var t=e&amp;&amp;e.exec(n);return t&amp;&amp;0===t.index}function a(e){return k.test(e)}function i(e){var n,t,r,i,o=e.className+" ";if(o+=e.parentNode?e.parentNode.className:"",t=B.exec(o))return w(t[1])?t[1]:"no-highlight";for(o=o.split(/\s+/),n=0,r=o.length;r&gt;n;n++)if(i=o[n],a(i)||w(i))return i}function o(e){var n,t={},r=Array.prototype.slice.call(arguments,1);for(n in e)t[n]=e[n];return r.forEach(function(e){for(n in e)t[n]=e[n]}),t}function u(e){var n=[];return function r(e,a){for(var i=e.firstChild;i;i=i.nextSibling)3===i.nodeType?a+=i.nodeValue.length:1===i.nodeType&amp;&amp;(n.push({event:"start",offset:a,node:i}),a=r(i,a),t(i).match(/br|hr|img|input/)||n.push({event:"stop",offset:a,node:i}));return a}(e,0),n}function c(e,r,a){function i(){return e.length&amp;&amp;r.length?e[0].offset!==r[0].offset?e[0].offset&lt;r[0].offset?e:r:"start"===r[0].event?e:r:e.length?e:r}function o(e){function r(e){return" "+e.nodeName+'="'+n(e.value).replace('"',"&amp;quot;")+'"'}s+="&lt;"+t(e)+E.map.call(e.attributes,r).join("")+"&gt;"}function u(e){s+="&lt;/"+t(e)+"&gt;"}function c(e){("start"===e.event?o:u)(e.node)}for(var l=0,s="",f=[];e.length||r.length;){var g=i();if(s+=n(a.substring(l,g[0].offset)),l=g[0].offset,g===e){f.reverse().forEach(u);do c(g.splice(0,1)[0]),g=i();while(g===e&amp;&amp;g.length&amp;&amp;g[0].offset===l);f.reverse().forEach(o)}else"start"===g[0].event?f.push(g[0].node):f.pop(),c(g.splice(0,1)[0])}return s+n(a.substr(l))}function l(e){return e.v&amp;&amp;!e.cached_variants&amp;&amp;(e.cached_variants=e.v.map(function(n){return o(e,{v:null},n)})),e.cached_variants||e.eW&amp;&amp;[o(e)]||[e]}function s(e){function n(e){return e&amp;&amp;e.source||e}function t(t,r){return new RegExp(n(t),"m"+(e.cI?"i":"")+(r?"g":""))}function r(a,i){if(!a.compiled){if(a.compiled=!0,a.k=a.k||a.bK,a.k){var o={},u=function(n,t){e.cI&amp;&amp;(t=t.toLowerCase()),t.split(" ").forEach(function(e){var t=e.split("|");o[t[0]]=[n,t[1]?Number(t[1]):1]})};"string"==typeof a.k?u("keyword",a.k):x(a.k).forEach(function(e){u(e,a.k[e])}),a.k=o}a.lR=t(a.l||/\w+/,!0),i&amp;&amp;(a.bK&amp;&amp;(a.b="\\b("+a.bK.split(" ").join("|")+")\\b"),a.b||(a.b=/\B|\b/),a.bR=t(a.b),a.e||a.eW||(a.e=/\B|\b/),a.e&amp;&amp;(a.eR=t(a.e)),a.tE=n(a.e)||"",a.eW&amp;&amp;i.tE&amp;&amp;(a.tE+=(a.e?"|":"")+i.tE)),a.i&amp;&amp;(a.iR=t(a.i)),null==a.r&amp;&amp;(a.r=1),a.c||(a.c=[]),a.c=Array.prototype.concat.apply([],a.c.map(function(e){return l("self"===e?a:e)})),a.c.forEach(function(e){r(e,a)}),a.starts&amp;&amp;r(a.starts,i);var c=a.c.map(function(e){return e.bK?"\\.?("+e.b+")\\.?":e.b}).concat([a.tE,a.i]).map(n).filter(Boolean);a.t=c.length?t(c.join("|"),!0):{exec:function(){return null}}}}r(e)}function f(e,t,a,i){function o(e,n){var t,a;for(t=0,a=n.c.length;a&gt;t;t++)if(r(n.c[t].bR,e))return n.c[t]}function u(e,n){if(r(e.eR,n)){for(;e.endsParent&amp;&amp;e.parent;)e=e.parent;return e}return e.eW?u(e.parent,n):void 0}function c(e,n){return!a&amp;&amp;r(n.iR,e)}function l(e,n){var t=N.cI?n[0].toLowerCase():n[0];return e.k.hasOwnProperty(t)&amp;&amp;e.k[t]}function p(e,n,t,r){var a=r?"":I.classPrefix,i='&lt;span class="'+a,o=t?"":C;return i+=e+'"&gt;',i+n+o}function h(){var e,t,r,a;if(!E.k)return n(k);for(a="",t=0,E.lR.lastIndex=0,r=E.lR.exec(k);r;)a+=n(k.substring(t,r.index)),e=l(E,r),e?(B+=e[1],a+=p(e[0],n(r[0]))):a+=n(r[0]),t=E.lR.lastIndex,r=E.lR.exec(k);return a+n(k.substr(t))}function d(){var e="string"==typeof E.sL;if(e&amp;&amp;!y[E.sL])return n(k);var t=e?f(E.sL,k,!0,x[E.sL]):g(k,E.sL.length?E.sL:void 0);return E.r&gt;0&amp;&amp;(B+=t.r),e&amp;&amp;(x[E.sL]=t.top),p(t.language,t.value,!1,!0)}function b(){L+=null!=E.sL?d():h(),k=""}function v(e){L+=e.cN?p(e.cN,"",!0):"",E=Object.create(e,{parent:{value:E}})}function m(e,n){if(k+=e,null==n)return b(),0;var t=o(n,E);if(t)return t.skip?k+=n:(t.eB&amp;&amp;(k+=n),b(),t.rB||t.eB||(k=n)),v(t,n),t.rB?0:n.length;var r=u(E,n);if(r){var a=E;a.skip?k+=n:(a.rE||a.eE||(k+=n),b(),a.eE&amp;&amp;(k=n));do E.cN&amp;&amp;(L+=C),E.skip||(B+=E.r),E=E.parent;while(E!==r.parent);return r.starts&amp;&amp;v(r.starts,""),a.rE?0:n.length}if(c(n,E))throw new Error('Illegal lexeme "'+n+'" for mode "'+(E.cN||"&lt;unnamed&gt;")+'"');return k+=n,n.length||1}var N=w(e);if(!N)throw new Error('Unknown language: "'+e+'"');s(N);var R,E=i||N,x={},L="";for(R=E;R!==N;R=R.parent)R.cN&amp;&amp;(L=p(R.cN,"",!0)+L);var k="",B=0;try{for(var M,j,O=0;;){if(E.t.lastIndex=O,M=E.t.exec(t),!M)break;j=m(t.substring(O,M.index),M[0]),O=M.index+j}for(m(t.substr(O)),R=E;R.parent;R=R.parent)R.cN&amp;&amp;(L+=C);return{r:B,value:L,language:e,top:E}}catch(T){if(T.message&amp;&amp;-1!==T.message.indexOf("Illegal"))return{r:0,value:n(t)};throw T}}function g(e,t){t=t||I.languages||x(y);var r={r:0,value:n(e)},a=r;return t.filter(w).forEach(function(n){var t=f(n,e,!1);t.language=n,t.r&gt;a.r&amp;&amp;(a=t),t.r&gt;r.r&amp;&amp;(a=r,r=t)}),a.language&amp;&amp;(r.second_best=a),r}function p(e){return I.tabReplace||I.useBR?e.replace(M,function(e,n){return I.useBR&amp;&amp;"\n"===e?"&lt;br&gt;":I.tabReplace?n.replace(/\t/g,I.tabReplace):""}):e}function h(e,n,t){var r=n?L[n]:t,a=[e.trim()];return e.match(/\bhljs\b/)||a.push("hljs"),-1===e.indexOf(r)&amp;&amp;a.push(r),a.join(" ").trim()}function d(e){var n,t,r,o,l,s=i(e);a(s)||(I.useBR?(n=document.createElementNS("http://www.w3.org/1999/xhtml","div"),n.innerHTML=e.innerHTML.replace(/\n/g,"").replace(/&lt;br[ \/]*&gt;/g,"\n")):n=e,l=n.textContent,r=s?f(s,l,!0):g(l),t=u(n),t.length&amp;&amp;(o=document.createElementNS("http://www.w3.org/1999/xhtml","div"),o.innerHTML=r.value,r.value=c(t,u(o),l)),r.value=p(r.value),e.innerHTML=r.value,e.className=h(e.className,s,r.language),e.result={language:r.language,re:r.r},r.second_best&amp;&amp;(e.second_best={language:r.second_best.language,re:r.second_best.r}))}function b(e){I=o(I,e)}function v(){if(!v.called){v.called=!0;var e=document.querySelectorAll("pre code");E.forEach.call(e,d)}}function m(){addEventListener("DOMContentLoaded",v,!1),addEventListener("load",v,!1)}function N(n,t){var r=y[n]=t(e);r.aliases&amp;&amp;r.aliases.forEach(function(e){L[e]=n})}function R(){return x(y)}function w(e){return e=(e||"").toLowerCase(),y[e]||y[L[e]]}var E=[],x=Object.keys,y={},L={},k=/^(no-?highlight|plain|text)$/i,B=/\blang(?:uage)?-([\w-]+)\b/i,M=/((^(&lt;[^&gt;]+&gt;|\t|)+|(?:\n)))/gm,C="&lt;/span&gt;",I={classPrefix:"hljs-",tabReplace:null,useBR:!1,languages:void 0};return e.highlight=f,e.highlightAuto=g,e.fixMarkup=p,e.highlightBlock=d,e.configure=b,e.initHighlighting=v,e.initHighlightingOnLoad=m,e.registerLanguage=N,e.listLanguages=R,e.getLanguage=w,e.inherit=o,e.IR="[a-zA-Z]\\w*",e.UIR="[a-zA-Z_]\\w*",e.NR="\\b\\d+(\\.\\d+)?",e.CNR="(-?)(\\b0[xX][a-fA-F0-9]+|(\\b\\d+(\\.\\d*)?|\\.\\d+)([eE][-+]?\\d+)?)",e.BNR="\\b(0b[01]+)",e.RSR="!|!=|!==|%|%=|&amp;|&amp;&amp;|&amp;=|\\*|\\*=|\\+|\\+=|,|-|-=|/=|/|:|;|&lt;&lt;|&lt;&lt;=|&lt;=|&lt;|===|==|=|&gt;&gt;&gt;=|&gt;&gt;=|&gt;=|&gt;&gt;&gt;|&gt;&gt;|&gt;|\\?|\\[|\\{|\\(|\\^|\\^=|\\||\\|=|\\|\\||~",e.BE={b:"\\\\[\\s\\S]",r:0},e.ASM={cN:"string",b:"'",e:"'",i:"\\n",c:[e.BE]},e.QSM={cN:"string",b:'"',e:'"',i:"\\n",c:[e.BE]},e.PWM={b:/\b(a|an|the|are|I'm|isn't|don't|doesn't|won't|but|just|should|pretty|simply|enough|gonna|going|wtf|so|such|will|you|your|they|like|more)\b/},e.C=function(n,t,r){var a=e.inherit({cN:"comment",b:n,e:t,c:[]},r||{});return a.c.push(e.PWM),a.c.push({cN:"doctag",b:"(?:TODO|FIXME|NOTE|BUG|XXX):",r:0}),a},e.CLCM=e.C("//","$"),e.CBCM=e.C("/\\*","\\*/"),e.HCM=e.C("#","$"),e.NM={cN:"number",b:e.NR,r:0},e.CNM={cN:"number",b:e.CNR,r:0},e.BNM={cN:"number",b:e.BNR,r:0},e.CSSNM={cN:"number",b:e.NR+"(%|em|ex|ch|rem|vw|vh|vmin|vmax|cm|mm|in|pt|pc|px|deg|grad|rad|turn|s|ms|Hz|kHz|dpi|dpcm|dppx)?",r:0},e.RM={cN:"regexp",b:/\//,e:/\/[gimuy]*/,i:/\n/,c:[e.BE,{b:/\[/,e:/\]/,r:0,c:[e.BE]}]},e.TM={cN:"title",b:e.IR,r:0},e.UTM={cN:"title",b:e.UIR,r:0},e.METHOD_GUARD={b:"\\.\\s*"+e.UIR,r:0},e});hljs.registerLanguage("java",function(e){var a="[À-ʸa-zA-Z_$][À-ʸa-zA-Z_$0-9]*",t=a+"(&lt;"+a+"(\\s*,\\s*"+a+")*&gt;)?",r="false synchronized int abstract float private char boolean static null if const for true while long strictfp finally protected import native final void enum else break transient catch instanceof byte super volatile case assert short package default double public try this switch continue throws protected public private module requires exports do",s="\\b(0[bB]([01]+[01_]+[01]+|[01]+)|0[xX]([a-fA-F0-9]+[a-fA-F0-9_]+[a-fA-F0-9]+|[a-fA-F0-9]+)|(([\\d]+[\\d_]+[\\d]+|[\\d]+)(\\.([\\d]+[\\d_]+[\\d]+|[\\d]+))?|\\.([\\d]+[\\d_]+[\\d]+|[\\d]+))([eE][-+]?\\d+)?)[lLfF]?",c={cN:"number",b:s,r:0};return{aliases:["jsp"],k:r,i:/&lt;\/|#/,c:[e.C("/\\*\\*","\\*/",{r:0,c:[{b:/\w+@/,r:0},{cN:"doctag",b:"@[A-Za-z]+"}]}),e.CLCM,e.CBCM,e.ASM,e.QSM,{cN:"class",bK:"class interface",e:/[{;=]/,eE:!0,k:"class interface",i:/[:"\[\]]/,c:[{bK:"extends implements"},e.UTM]},{bK:"new throw return else",r:0},{cN:"function",b:"("+t+"\\s+)+"+e.UIR+"\\s*\\(",rB:!0,e:/[{;=]/,eE:!0,k:r,c:[{b:e.UIR+"\\s*\\(",rB:!0,r:0,c:[e.UTM]},{cN:"params",b:/\(/,e:/\)/,k:r,r:0,c:[e.ASM,e.QSM,e.CNM,e.CBCM]},e.CLCM,e.CBCM]},c,{cN:"meta",b:"@[A-Za-z]+"}]}});
&lt;/script&gt;
&lt;script&gt;hljs.initHighlightingOnLoad();&lt;/script&gt;
&lt;/head&gt;
&lt;body onload="selectjava()"&gt;
&lt;div id="topics"&gt;&lt;/div&gt;
&lt;!-- ####################################################################### --&gt;
&lt;h2&gt;static keyword in Java&lt;/h2&gt;
The static keyword in java is used for memory management mainly. We can apply java static keyword with variables, methods, blocks and nested class. The static keyword belongs to the class than instance of the class.
&lt;h2&gt;static members&lt;/h2&gt;
Instance variables and methods are associated with and accessed through an instance of the class (i.e., through a particular object). In contrast, members that are declared with the static modifier live in the class and are shared by all instances of the class. Variables declared with the static modifier are called &lt;strong&gt;static variables&lt;/strong&gt; or &lt;strong&gt;class variables&lt;/strong&gt;; similarly, these kinds of methods are called &lt;strong&gt;static methods&lt;/strong&gt; or &lt;strong&gt;class methods&lt;/strong&gt;. &lt;br&gt;&lt;br&gt;

The static variable can be used to refer the common property of all objects (that is not unique for each object) e.g. company name of employees,college name of students etc.
The static variable gets memory only once in class area at the time of class loading.static keyword saves memory reasources and make program more efficient.

&lt;h3&gt;Without static variable&lt;/h3&gt;
&lt;pre&gt;
&lt;code class="java"&gt;
class Employee
{  
     int emp_no;  
     String name;  
     String department="IT";  
}  
&lt;/code&gt;  
&lt;/pre&gt;
Suppose there are 1000 employees in my department, now all instance data members will get memory each time when object is created.All employee have its unique emp_no and name so instance data member is good.Here, department refers to the common property of all objects.If we make it static,this field will get memory only once.

&lt;h2&gt;Example of static variable&lt;/h2&gt;
&lt;h3&gt;Program&lt;/h3&gt;
&lt;pre&gt;
&lt;code class="java"&gt;
class Employee
{  
   int emp_no;  
   String name;  
   // department is static variable so it will allocate
   //memory only once at compile time
   static String department ="IT";  
     
   Employee(int e,String n)
   {  
        emp_no = e;  
        name = n;  
   }  
    void display ()
    {
        System.out.println("emp_no " + emp_no + " department = " + department);
    }  
}

public class Main
{
     public static void main(String args[])
     {  
         Employee e1 = new Employee(111,"raj");  
         Employee e2 = new Employee(222,"aditya");  
         e1.display();  
         e2.display();  
     }  
}  
&lt;/code&gt;  
  &lt;a href="https://onlinegdb.com/ryib4IeZG"&gt;&lt;button class="button"&gt;&lt;span&gt;Run &lt;/span&gt;&lt;/button&gt;&lt;/a&gt;
&lt;/pre&gt;

&lt;h3&gt;Output&lt;/h3&gt;
&lt;pre&gt;
&lt;code class="java"&gt;
emp_no = 111 department = IT
emp_no = 222 department = IT
&lt;/code&gt;  
&lt;/pre&gt;

&lt;h3&gt;Explanation&lt;/h3&gt;
Static members can be accessed like instance members. Inside our class, we can refer to it like any other variables.However, since static members exist in the class itself, independent of any instance, we can also access them directly through the class. We don’t need a object to get or set the variable; instead, we can use the class to select the variable.

&lt;h3&gt;Program&lt;/h3&gt;
&lt;pre&gt;
&lt;code class="java"&gt;
public class Main
{
    //initialize counter variable
    static int counter = 0;
    
    Main()
    {
        counter++;
    }
    
    public static void main (String[] args) 
    {
        new Main();
        new Main();
        new Main();
        new Main();
        // accessing static member through classname
        System.out.println(Main.counter);
    }
}
&lt;/code&gt;  
  &lt;a href="https://onlinegdb.com/BJbaUUx-f"&gt;&lt;button class="button"&gt;&lt;span&gt;Run &lt;/span&gt;&lt;/button&gt;&lt;/a&gt;
&lt;/pre&gt;

&lt;h3&gt;Output&lt;/h3&gt;
&lt;pre&gt;
&lt;code class="java"&gt;
4
&lt;/code&gt;  
&lt;/pre&gt;

&lt;h3&gt;Explanation&lt;/h3&gt;
In this example, we have created an instance variable named counter which is incremented in the constructor. Since this is variable so gets the memory at the compile time , each object is sharing the instance variable, if it is incremented, it will reflect to other objects. So each objects will increment the value of shared variable in the counter variable.Static variables are, essentially, global variables.

&lt;div id="imp"&gt;
We can create static variables at class-level only.see below code:
&lt;/div&gt;
&lt;pre&gt;
&lt;code class="java"&gt;
class Main
{
   public static void main(String args[]) 
   { 
        System.out.println(fun());
   }
   static int fun()
   {
       //static variables are allowed at class level only
        static int x= 10;  //Error: Static local variables are not allowed
        return x--;
   }
} 
&lt;/code&gt;  
&lt;/pre&gt;

&lt;h3&gt;Explanation&lt;/h3&gt;
The above code will give the error.

&lt;h2&gt;static block&lt;/h2&gt;
static block and static variables are executed in order they are present in a program.
&lt;h3&gt;Program&lt;/h3&gt;
&lt;pre&gt;
&lt;code class="java"&gt;
// static blocks and variables
class Main
{
    // static variable
    static int a = m1(); // 2
     
    // static block
    static // 5
    {
        System.out.println("We are inside static block"); // 6
    }
     
    // static method
    static int m1() // 3
    {
        System.out.println("We are inside method m1"); .// 4
        return 20; // 7
    }

    // static main method
    public static void main(String[] args)
    {
       System.out.println("Value of a : "+ a); // 1 // 9
       System.out.println("We are inside main method"); // 8
    }
}
&lt;/code&gt;  
  &lt;a href="https://onlinegdb.com/S1WE3IgbG"&gt;&lt;button class="button"&gt;&lt;span&gt;Run &lt;/span&gt;&lt;/button&gt;&lt;/a&gt;
&lt;/pre&gt;

&lt;h3&gt;Output&lt;/h3&gt;
&lt;pre&gt;
&lt;code class="java"&gt;
We are inside method m1
We are inside static block
Value of a : 20
We are inside main method
&lt;/code&gt;  
&lt;/pre&gt;

&lt;h2&gt;static methods&lt;/h2&gt;
When a method is declared with static keyword, it is known as static method. The most common example of a static method is main( ) method.As discussed above, Any static member can be accessed before any objects of its class are created, and without reference to any object.Methods declared as static have several restrictions:
&lt;ol&gt;
 &lt;li&gt;They can only directly call other static methods.&lt;/li&gt;
&lt;li&gt;They can only directly access static data.&lt;/li&gt;
&lt;li&gt;They cannot refer to this or super in any way.&lt;/li&gt;
&lt;/ol&gt;

&lt;h3&gt;Program&lt;/h3&gt;
&lt;pre&gt;
&lt;code class="java"&gt;
class cl
{
    int a = 10;
}

// java program to demonstrate restriction on static methods
class Test extends cl
{
    // static variable
    static int a = 10;
     
    // instance variable
    int b = 20;
     
    // static method
    static void m1()
    {
        //method m1 is static so it can access it and modify it
        a = 20;
        System.out.println("inside m1");
         
         // Cannot make a static reference to the non-static field b
         b = 10; // compilation error
                 
         // Cannot make a static reference to the 
        // non-static method m2() from the type Test
         m2();  // compilation error
          
         //  Cannot use super in a static context
         System.out.println(super.a); // compiler error 
    }
     
    // instance method
    void m2()
    {    
        System.out.println("from m2");
    }

    public static void main(String[] args)
    {
        // main method 
    }
}
&lt;/code&gt;  
  &lt;a href="https://onlinegdb.com/B1MMWve-G"&gt;&lt;button class="button"&gt;&lt;span&gt;Run &lt;/span&gt;&lt;/button&gt;&lt;/a&gt;
&lt;/pre&gt;

&lt;h3&gt;Output&lt;/h3&gt;
&lt;pre&gt;
&lt;code class="java"&gt;
Main.java:23: error: non-static variable b cannot be referenced from a static context
         b = 10; // compilation error
         ^
Main.java:27: error: non-static method m2() cannot be referenced from a static context
         m2();  // compilation error
         ^
Main.java:30: error: non-static variable super cannot be referenced from a static context
         System.out.println(super.a); // compiler error
                            ^
3 errors
&lt;/code&gt;  
&lt;/pre&gt;
extends keyword which is used in above program we will learn about this when we see inheritance.

&lt;h2&gt;static final variable in Java&lt;/h2&gt;
In Java, non-static final variables can be assigned a value either in constructor or with the declaration. But, static final variables cannot be assigned value in constructor; they must be assigned a value with their declaration.Such behavior is obvious as static variables are shared among all the objects of a class; creating a new object would change the same static variable which is not allowed if the static variable is final.

&lt;h3&gt;Program&lt;/h3&gt;
&lt;pre&gt;
&lt;code class="java"&gt;
class Main
{
    //since this variable is not static
    final int a;
    Main()
    {
        //it can be initialize by constructor
        a = 10;
    }

    public static void main(String args[]){}
}
&lt;/code&gt;  
  &lt;a href="https://onlinegdb.com/HJ5S4wgbf"&gt;&lt;button class="button"&gt;&lt;span&gt;Run &lt;/span&gt;&lt;/button&gt;&lt;/a&gt;
&lt;/pre&gt;
&lt;h3&gt;Explanation&lt;/h3&gt;
The above program works fine but if variable is &lt;strong&gt;static final&lt;/strong&gt;
it can not be initialized by constructor.see program below...
&lt;h3&gt;Program&lt;/h3&gt;
&lt;pre&gt;
&lt;code class="java"&gt;
class Main
{
    //since this variable is static
    static final int a;
    Main()
    {
        //it can not be initialize by constructor
        a = 10;
    }

    public static void main(String args[]){}
}
&lt;/code&gt;  
  &lt;a href="https://onlinegdb.com/ryXxrPgbG"&gt;&lt;button class="button"&gt;&lt;span&gt;Run &lt;/span&gt;&lt;/button&gt;&lt;/a&gt;
&lt;/pre&gt;
&lt;h3&gt;Output&lt;/h3&gt;
&lt;pre&gt;
&lt;code class="java"&gt;
Main.java:8: error: cannot assign a value to final variable a
        a = 10;
        ^
1 error
&lt;/code&gt;  
&lt;/pre&gt;

&lt;h2&gt;Why java main method is static ?&lt;/h2&gt;
Main method in Java is entry point for any core Java program. In core Java program, execution starts from main method when you type java main-class-name, JVM search for public static void main(String args[]) method in that class and if it doesn't find that method it throws error &lt;strong&gt;NoSuchMethodError:main&lt;/strong&gt; and terminates.&lt;br&gt;&lt;br&gt;

Now come to the main point "Why the main method is static in Java", there are quite a few reasons around but here are few reasons which make sense to me:&lt;br&gt;&lt;br&gt;

1. Since the main method is static Java virtual Machine can call it without creating any instance of a class which contains the main method.&lt;br&gt;&lt;br&gt;


2. If main method were not declared static than JVM has to create instance of main Class and since constructor can be overloaded and can have arguments there would not be any certain and consistent way for JVM to find main method in Java.&lt;br&gt;&lt;br&gt;

3. Anything which is declared in class in Java comes under reference type and requires object to be created before using them but static method and static data are loaded into separate memory inside JVM called context which is created when a class is loaded. If main method is static than it will be loaded in JVM context and are available to execution.&lt;br&gt;&lt;br&gt;

&lt;h2&gt;difference of static keyword in c++ and Java&lt;/h2&gt;
Static keyword is used for almost same purpose in both C++ and Java. There are some differences though. &lt;br&gt;&lt;br&gt;
1. Unlike C++, Java supports a special block, called static block (also called static clause) which can be used for static initialization of a class. The code inside static block is executed only once. See Static blocks in Java for details.&lt;br&gt;&lt;br&gt;
2. Unlike C++, Java doesn’t support static local variables. &lt;br&gt;&lt;br&gt;

&lt;!-- ####################################################################### --&gt;
&lt;/body&gt;
&lt;/html&gt;&lt;/div&gt;
</description><link>http://tangled-java.blogspot.com/2017/12/static-keyword-in-java.html</link><author>noreply@blogger.com (Anonymous)</author><thr:total>0</thr:total></item><item><guid isPermaLink="false">tag:blogger.com,1999:blog-3082064622906880860.post-8227767549278922363</guid><pubDate>Sat, 02 Dec 2017 15:43:00 +0000</pubDate><atom:updated>2017-12-02T07:43:48.043-08:00</atom:updated><category domain="http://www.blogger.com/atom/ns#">6 usage of this keyword</category><category domain="http://www.blogger.com/atom/ns#">this</category><title>this keyword in Java</title><description>&lt;div dir="ltr" style="text-align: left;" trbidi="on"&gt;
&lt;html&gt;
&lt;head&gt;
 &lt;title&gt;&lt;/title&gt;
&lt;style&gt; strong{ color: white; }&lt;/style&gt;
&lt;script type="text/javascript"&gt;
 /*! highlight.js v9.12.0 | BSD3 License | git.io/hljslicense */
!function(e){var n="object"==typeof window&amp;&amp;window||"object"==typeof self&amp;&amp;self;"undefined"!=typeof exports?e(exports):n&amp;&amp;(n.hljs=e({}),"function"==typeof define&amp;&amp;define.amd&amp;&amp;define([],function(){return n.hljs}))}(function(e){function n(e){return e.replace(/&amp;/g,"&amp;amp;").replace(/&lt;/g,"&amp;lt;").replace(/&gt;/g,"&amp;gt;")}function t(e){return e.nodeName.toLowerCase()}function r(e,n){var t=e&amp;&amp;e.exec(n);return t&amp;&amp;0===t.index}function a(e){return k.test(e)}function i(e){var n,t,r,i,o=e.className+" ";if(o+=e.parentNode?e.parentNode.className:"",t=B.exec(o))return w(t[1])?t[1]:"no-highlight";for(o=o.split(/\s+/),n=0,r=o.length;r&gt;n;n++)if(i=o[n],a(i)||w(i))return i}function o(e){var n,t={},r=Array.prototype.slice.call(arguments,1);for(n in e)t[n]=e[n];return r.forEach(function(e){for(n in e)t[n]=e[n]}),t}function u(e){var n=[];return function r(e,a){for(var i=e.firstChild;i;i=i.nextSibling)3===i.nodeType?a+=i.nodeValue.length:1===i.nodeType&amp;&amp;(n.push({event:"start",offset:a,node:i}),a=r(i,a),t(i).match(/br|hr|img|input/)||n.push({event:"stop",offset:a,node:i}));return a}(e,0),n}function c(e,r,a){function i(){return e.length&amp;&amp;r.length?e[0].offset!==r[0].offset?e[0].offset&lt;r[0].offset?e:r:"start"===r[0].event?e:r:e.length?e:r}function o(e){function r(e){return" "+e.nodeName+'="'+n(e.value).replace('"',"&amp;quot;")+'"'}s+="&lt;"+t(e)+E.map.call(e.attributes,r).join("")+"&gt;"}function u(e){s+="&lt;/"+t(e)+"&gt;"}function c(e){("start"===e.event?o:u)(e.node)}for(var l=0,s="",f=[];e.length||r.length;){var g=i();if(s+=n(a.substring(l,g[0].offset)),l=g[0].offset,g===e){f.reverse().forEach(u);do c(g.splice(0,1)[0]),g=i();while(g===e&amp;&amp;g.length&amp;&amp;g[0].offset===l);f.reverse().forEach(o)}else"start"===g[0].event?f.push(g[0].node):f.pop(),c(g.splice(0,1)[0])}return s+n(a.substr(l))}function l(e){return e.v&amp;&amp;!e.cached_variants&amp;&amp;(e.cached_variants=e.v.map(function(n){return o(e,{v:null},n)})),e.cached_variants||e.eW&amp;&amp;[o(e)]||[e]}function s(e){function n(e){return e&amp;&amp;e.source||e}function t(t,r){return new RegExp(n(t),"m"+(e.cI?"i":"")+(r?"g":""))}function r(a,i){if(!a.compiled){if(a.compiled=!0,a.k=a.k||a.bK,a.k){var o={},u=function(n,t){e.cI&amp;&amp;(t=t.toLowerCase()),t.split(" ").forEach(function(e){var t=e.split("|");o[t[0]]=[n,t[1]?Number(t[1]):1]})};"string"==typeof a.k?u("keyword",a.k):x(a.k).forEach(function(e){u(e,a.k[e])}),a.k=o}a.lR=t(a.l||/\w+/,!0),i&amp;&amp;(a.bK&amp;&amp;(a.b="\\b("+a.bK.split(" ").join("|")+")\\b"),a.b||(a.b=/\B|\b/),a.bR=t(a.b),a.e||a.eW||(a.e=/\B|\b/),a.e&amp;&amp;(a.eR=t(a.e)),a.tE=n(a.e)||"",a.eW&amp;&amp;i.tE&amp;&amp;(a.tE+=(a.e?"|":"")+i.tE)),a.i&amp;&amp;(a.iR=t(a.i)),null==a.r&amp;&amp;(a.r=1),a.c||(a.c=[]),a.c=Array.prototype.concat.apply([],a.c.map(function(e){return l("self"===e?a:e)})),a.c.forEach(function(e){r(e,a)}),a.starts&amp;&amp;r(a.starts,i);var c=a.c.map(function(e){return e.bK?"\\.?("+e.b+")\\.?":e.b}).concat([a.tE,a.i]).map(n).filter(Boolean);a.t=c.length?t(c.join("|"),!0):{exec:function(){return null}}}}r(e)}function f(e,t,a,i){function o(e,n){var t,a;for(t=0,a=n.c.length;a&gt;t;t++)if(r(n.c[t].bR,e))return n.c[t]}function u(e,n){if(r(e.eR,n)){for(;e.endsParent&amp;&amp;e.parent;)e=e.parent;return e}return e.eW?u(e.parent,n):void 0}function c(e,n){return!a&amp;&amp;r(n.iR,e)}function l(e,n){var t=N.cI?n[0].toLowerCase():n[0];return e.k.hasOwnProperty(t)&amp;&amp;e.k[t]}function p(e,n,t,r){var a=r?"":I.classPrefix,i='&lt;span class="'+a,o=t?"":C;return i+=e+'"&gt;',i+n+o}function h(){var e,t,r,a;if(!E.k)return n(k);for(a="",t=0,E.lR.lastIndex=0,r=E.lR.exec(k);r;)a+=n(k.substring(t,r.index)),e=l(E,r),e?(B+=e[1],a+=p(e[0],n(r[0]))):a+=n(r[0]),t=E.lR.lastIndex,r=E.lR.exec(k);return a+n(k.substr(t))}function d(){var e="string"==typeof E.sL;if(e&amp;&amp;!y[E.sL])return n(k);var t=e?f(E.sL,k,!0,x[E.sL]):g(k,E.sL.length?E.sL:void 0);return E.r&gt;0&amp;&amp;(B+=t.r),e&amp;&amp;(x[E.sL]=t.top),p(t.language,t.value,!1,!0)}function b(){L+=null!=E.sL?d():h(),k=""}function v(e){L+=e.cN?p(e.cN,"",!0):"",E=Object.create(e,{parent:{value:E}})}function m(e,n){if(k+=e,null==n)return b(),0;var t=o(n,E);if(t)return t.skip?k+=n:(t.eB&amp;&amp;(k+=n),b(),t.rB||t.eB||(k=n)),v(t,n),t.rB?0:n.length;var r=u(E,n);if(r){var a=E;a.skip?k+=n:(a.rE||a.eE||(k+=n),b(),a.eE&amp;&amp;(k=n));do E.cN&amp;&amp;(L+=C),E.skip||(B+=E.r),E=E.parent;while(E!==r.parent);return r.starts&amp;&amp;v(r.starts,""),a.rE?0:n.length}if(c(n,E))throw new Error('Illegal lexeme "'+n+'" for mode "'+(E.cN||"&lt;unnamed&gt;")+'"');return k+=n,n.length||1}var N=w(e);if(!N)throw new Error('Unknown language: "'+e+'"');s(N);var R,E=i||N,x={},L="";for(R=E;R!==N;R=R.parent)R.cN&amp;&amp;(L=p(R.cN,"",!0)+L);var k="",B=0;try{for(var M,j,O=0;;){if(E.t.lastIndex=O,M=E.t.exec(t),!M)break;j=m(t.substring(O,M.index),M[0]),O=M.index+j}for(m(t.substr(O)),R=E;R.parent;R=R.parent)R.cN&amp;&amp;(L+=C);return{r:B,value:L,language:e,top:E}}catch(T){if(T.message&amp;&amp;-1!==T.message.indexOf("Illegal"))return{r:0,value:n(t)};throw T}}function g(e,t){t=t||I.languages||x(y);var r={r:0,value:n(e)},a=r;return t.filter(w).forEach(function(n){var t=f(n,e,!1);t.language=n,t.r&gt;a.r&amp;&amp;(a=t),t.r&gt;r.r&amp;&amp;(a=r,r=t)}),a.language&amp;&amp;(r.second_best=a),r}function p(e){return I.tabReplace||I.useBR?e.replace(M,function(e,n){return I.useBR&amp;&amp;"\n"===e?"&lt;br&gt;":I.tabReplace?n.replace(/\t/g,I.tabReplace):""}):e}function h(e,n,t){var r=n?L[n]:t,a=[e.trim()];return e.match(/\bhljs\b/)||a.push("hljs"),-1===e.indexOf(r)&amp;&amp;a.push(r),a.join(" ").trim()}function d(e){var n,t,r,o,l,s=i(e);a(s)||(I.useBR?(n=document.createElementNS("http://www.w3.org/1999/xhtml","div"),n.innerHTML=e.innerHTML.replace(/\n/g,"").replace(/&lt;br[ \/]*&gt;/g,"\n")):n=e,l=n.textContent,r=s?f(s,l,!0):g(l),t=u(n),t.length&amp;&amp;(o=document.createElementNS("http://www.w3.org/1999/xhtml","div"),o.innerHTML=r.value,r.value=c(t,u(o),l)),r.value=p(r.value),e.innerHTML=r.value,e.className=h(e.className,s,r.language),e.result={language:r.language,re:r.r},r.second_best&amp;&amp;(e.second_best={language:r.second_best.language,re:r.second_best.r}))}function b(e){I=o(I,e)}function v(){if(!v.called){v.called=!0;var e=document.querySelectorAll("pre code");E.forEach.call(e,d)}}function m(){addEventListener("DOMContentLoaded",v,!1),addEventListener("load",v,!1)}function N(n,t){var r=y[n]=t(e);r.aliases&amp;&amp;r.aliases.forEach(function(e){L[e]=n})}function R(){return x(y)}function w(e){return e=(e||"").toLowerCase(),y[e]||y[L[e]]}var E=[],x=Object.keys,y={},L={},k=/^(no-?highlight|plain|text)$/i,B=/\blang(?:uage)?-([\w-]+)\b/i,M=/((^(&lt;[^&gt;]+&gt;|\t|)+|(?:\n)))/gm,C="&lt;/span&gt;",I={classPrefix:"hljs-",tabReplace:null,useBR:!1,languages:void 0};return e.highlight=f,e.highlightAuto=g,e.fixMarkup=p,e.highlightBlock=d,e.configure=b,e.initHighlighting=v,e.initHighlightingOnLoad=m,e.registerLanguage=N,e.listLanguages=R,e.getLanguage=w,e.inherit=o,e.IR="[a-zA-Z]\\w*",e.UIR="[a-zA-Z_]\\w*",e.NR="\\b\\d+(\\.\\d+)?",e.CNR="(-?)(\\b0[xX][a-fA-F0-9]+|(\\b\\d+(\\.\\d*)?|\\.\\d+)([eE][-+]?\\d+)?)",e.BNR="\\b(0b[01]+)",e.RSR="!|!=|!==|%|%=|&amp;|&amp;&amp;|&amp;=|\\*|\\*=|\\+|\\+=|,|-|-=|/=|/|:|;|&lt;&lt;|&lt;&lt;=|&lt;=|&lt;|===|==|=|&gt;&gt;&gt;=|&gt;&gt;=|&gt;=|&gt;&gt;&gt;|&gt;&gt;|&gt;|\\?|\\[|\\{|\\(|\\^|\\^=|\\||\\|=|\\|\\||~",e.BE={b:"\\\\[\\s\\S]",r:0},e.ASM={cN:"string",b:"'",e:"'",i:"\\n",c:[e.BE]},e.QSM={cN:"string",b:'"',e:'"',i:"\\n",c:[e.BE]},e.PWM={b:/\b(a|an|the|are|I'm|isn't|don't|doesn't|won't|but|just|should|pretty|simply|enough|gonna|going|wtf|so|such|will|you|your|they|like|more)\b/},e.C=function(n,t,r){var a=e.inherit({cN:"comment",b:n,e:t,c:[]},r||{});return a.c.push(e.PWM),a.c.push({cN:"doctag",b:"(?:TODO|FIXME|NOTE|BUG|XXX):",r:0}),a},e.CLCM=e.C("//","$"),e.CBCM=e.C("/\\*","\\*/"),e.HCM=e.C("#","$"),e.NM={cN:"number",b:e.NR,r:0},e.CNM={cN:"number",b:e.CNR,r:0},e.BNM={cN:"number",b:e.BNR,r:0},e.CSSNM={cN:"number",b:e.NR+"(%|em|ex|ch|rem|vw|vh|vmin|vmax|cm|mm|in|pt|pc|px|deg|grad|rad|turn|s|ms|Hz|kHz|dpi|dpcm|dppx)?",r:0},e.RM={cN:"regexp",b:/\//,e:/\/[gimuy]*/,i:/\n/,c:[e.BE,{b:/\[/,e:/\]/,r:0,c:[e.BE]}]},e.TM={cN:"title",b:e.IR,r:0},e.UTM={cN:"title",b:e.UIR,r:0},e.METHOD_GUARD={b:"\\.\\s*"+e.UIR,r:0},e});hljs.registerLanguage("java",function(e){var a="[À-ʸa-zA-Z_$][À-ʸa-zA-Z_$0-9]*",t=a+"(&lt;"+a+"(\\s*,\\s*"+a+")*&gt;)?",r="false synchronized int abstract float private char boolean static null if const for true while long strictfp finally protected import native final void enum else break transient catch instanceof byte super volatile case assert short package default double public try this switch continue throws protected public private module requires exports do",s="\\b(0[bB]([01]+[01_]+[01]+|[01]+)|0[xX]([a-fA-F0-9]+[a-fA-F0-9_]+[a-fA-F0-9]+|[a-fA-F0-9]+)|(([\\d]+[\\d_]+[\\d]+|[\\d]+)(\\.([\\d]+[\\d_]+[\\d]+|[\\d]+))?|\\.([\\d]+[\\d_]+[\\d]+|[\\d]+))([eE][-+]?\\d+)?)[lLfF]?",c={cN:"number",b:s,r:0};return{aliases:["jsp"],k:r,i:/&lt;\/|#/,c:[e.C("/\\*\\*","\\*/",{r:0,c:[{b:/\w+@/,r:0},{cN:"doctag",b:"@[A-Za-z]+"}]}),e.CLCM,e.CBCM,e.ASM,e.QSM,{cN:"class",bK:"class interface",e:/[{;=]/,eE:!0,k:"class interface",i:/[:"\[\]]/,c:[{bK:"extends implements"},e.UTM]},{bK:"new throw return else",r:0},{cN:"function",b:"("+t+"\\s+)+"+e.UIR+"\\s*\\(",rB:!0,e:/[{;=]/,eE:!0,k:r,c:[{b:e.UIR+"\\s*\\(",rB:!0,r:0,c:[e.UTM]},{cN:"params",b:/\(/,e:/\)/,k:r,r:0,c:[e.ASM,e.QSM,e.CNM,e.CBCM]},e.CLCM,e.CBCM]},c,{cN:"meta",b:"@[A-Za-z]+"}]}});
&lt;/script&gt;
&lt;script&gt;hljs.initHighlightingOnLoad();&lt;/script&gt;
&lt;/head&gt;
&lt;body onload="selectjava()"&gt;
&lt;!-- ####################################################################### --&gt;
&lt;div id="topics"&gt;&lt;/div&gt;
In this article we will see &lt;strong&gt;this&lt;/strong&gt; keyword in Java.

&lt;h2&gt;this keyword in Java&lt;/h2&gt;
this keyword in Java is a special keyword which can be used to represent current object or instance of any class in Java. “this” keyword can also call constructor of same class in Java and used to call overloaded constructor. In this article we will see how to use &lt;strong&gt;this&lt;/strong&gt; keyword in Java  and different examples. this sometime also associate with &lt;strong&gt;super&lt;/strong&gt; keyword which is used to denote instance of super class in Java and can be used to call overloaded constructor in Java.

&lt;h2&gt;6 usage of this keyword&lt;/h2&gt;
&lt;h2&gt;1. to refer current class instance variable&lt;/h2&gt;

&lt;h3&gt;Program&lt;/h3&gt;
&lt;pre&gt;
&lt;code class="java"&gt;
//Java code for using 'this' keyword to
//refer current class instance variables
class demo
{
    int a;
    int b;
     
    // parameterized constructor
    demo(int a, int b)
    {
        this.a = a;
        this.b = b;
    }
 
    void display()
    {
        //displays the value of variables a and b
        System.out.println("a = " + a);
        System.out.println("b = " + b);
    }
}

public class Main
    {
        public static void main(String[] args)
        {
            demo object = new demo(10, 20);
            object.display();
        }
}
&lt;/code&gt;  
  &lt;a href="https://onlinegdb.com/SJNOu4xbz"&gt;&lt;button class="button"&gt;&lt;span&gt;Run &lt;/span&gt;&lt;/button&gt;&lt;/a&gt;
&lt;/pre&gt;

&lt;h3&gt;Output&lt;/h3&gt;
&lt;pre&gt;
&lt;code class="java"&gt;
a = 10
b = 20
&lt;/code&gt;  
&lt;/pre&gt;

&lt;h3&gt;Explanation&lt;/h3&gt;
The this keyword can be used to refer current class instance variable. If there is ambiguity between the instance variables and parameters, this keyword resolves the problem of ambiguity.
In the above example, parameters (formal arguments) and instance variables are same. So, we are using this keyword to distinguish local variable and instance variable.If local variables(formal arguments) and instance variables are different, there is no need to use this keyword like in the following program.It is better approach to use meaningful names for variables. So we use same name for instance variables and parameters in real time, and always use this keyword.

&lt;h2&gt;2. to invoke current class method&lt;/h2&gt;
&lt;h3&gt;Program&lt;/h3&gt;
&lt;pre&gt;
&lt;code class="java"&gt;
// this keyword in class method
class demo 
{
    void display() // 3
    {
        // calling fuction show()
        this.show(); // 4
       System.out.println("We are inside display function"); // 7
    }
     
    void show()  // 5
    { 
        System.out.println("We are inside show funcion"); // 6
    }
}

public class Main
{
    public static void main(String args[]) 
    {
        demo t1 = new demo();  // 1
        t1.display(); // 2
    }
}
&lt;/code&gt;  
  &lt;a href="https://onlinegdb.com/HyWM8HxWf"&gt;&lt;button class="button"&gt;&lt;span&gt;Run &lt;/span&gt;&lt;/button&gt;&lt;/a&gt;
&lt;/pre&gt;

&lt;h3&gt;Output&lt;/h3&gt;
&lt;pre&gt;
&lt;code class="java"&gt;
We are inside show funcion
We are inside display function
&lt;/code&gt;  
&lt;/pre&gt;

&lt;h2&gt;3. to invoke current class constructor&lt;/h2&gt;
&lt;h3&gt;Program&lt;/h3&gt;
&lt;pre&gt;
&lt;code class="java"&gt;
class demo
{
    int a;
    int b;
 
    //2. Default constructor
    demo()
    {  
        //3. calling parameterized constructor of this class
        this(10, 20);
        //5. back in default constructor
        System.out.println("We are inside  default constructor \n");
    }
     
    //4. Parameterized constructor
    demo(int a, int b)
    {
        this.a = a;
        this.b = b;
        System.out.println("We are inside parameterized constructor");
    }
}

public class Main
{
    public static void main(String[] args)
    {
        //1. calls default constructor
        demo object = new demo();
    }
}
&lt;/code&gt;  
  &lt;a href="https://onlinegdb.com/Hy3NsVlZG"&gt;&lt;button class="button"&gt;&lt;span&gt;Run &lt;/span&gt;&lt;/button&gt;&lt;/a&gt;
&lt;/pre&gt;

&lt;h3&gt;Output&lt;/h3&gt;
&lt;pre&gt;
&lt;code class="java"&gt;
We are inside parameterized constructor
We are inside  default constructor
&lt;/code&gt;  
&lt;/pre&gt;



&lt;h2&gt;4. as an argument in the method call&lt;/h2&gt;
&lt;h3&gt;Program&lt;/h3&gt;
&lt;pre&gt;
&lt;code class="java"&gt;
// this keyword in method parameter
class demo
{
    int a;
    int b;
     
    // Default constructor
    demo()
    {
        a = 10;
        b = 20;
    }
     
    // Method that receives 'this' keyword as parameter
    void display(demo obj) // 5
    {
        System.out.println("a = " + a + "  b = " + b); // 6
    }
  
    // Method that returns current class instance
    void get() // 3
    {
        display(this); // 4
    }
}

public class Main
{ 
    public static void main(String[] args)
    {
        demo object = new demo(); // 1
        object.get(); // 2
    }
}
&lt;/code&gt;  
  &lt;a href="https://onlinegdb.com/SythQHlbM"&gt;&lt;button class="button"&gt;&lt;span&gt;Run &lt;/span&gt;&lt;/button&gt;&lt;/a&gt;
&lt;/pre&gt;

&lt;h3&gt;Output&lt;/h3&gt;
&lt;pre&gt;
&lt;code class="java"&gt;
a = 10 b = 20
&lt;/code&gt;  
&lt;/pre&gt;

&lt;h2&gt;5. as argument in the constructor call&lt;/h2&gt;
&lt;h3&gt;Program&lt;/h3&gt;
&lt;pre&gt;
&lt;code class="java"&gt;
class A
{
    B obj;
     
    // Parameterized constructor with object of B as a parameter
    A(B obj) // 4
    {
        this.obj = obj; // 5
        
     // calling display method of class B
        obj.display(); // 6
    }
     
}
 
class B
{
    int x = 5;
     
    // Default Contructor that create a object of A  with passing this as an argument in the constructor
    B() // 2
    {
        A obj = new A(this); // 3
    }
     
    // method to show value of x 
    void display()  // 7
    {
        System.out.println("Value of x in Class B is " + x); // 8
    }
     
    public static void main(String[] args) {
        B obj = new B();
    }
}

public class Main
{
    public static void main(String[] args) 
    {
        B obj = new B(); // 1
    }
}
&lt;/code&gt;  
  &lt;a href="https://onlinegdb.com/H1cv_rebM"&gt;&lt;button class="button"&gt;&lt;span&gt;Run &lt;/span&gt;&lt;/button&gt;&lt;/a&gt;
&lt;/pre&gt;

&lt;h3&gt;Output&lt;/h3&gt;
&lt;pre&gt;
&lt;code class="java"&gt;
Value of x in Class B is 5
&lt;/code&gt;  
&lt;/pre&gt;
&lt;h2&gt;6. to return the current class instance from the method&lt;/h2&gt;
&lt;h3&gt;Program&lt;/h3&gt;
&lt;pre&gt;
&lt;code class="java"&gt;
//to return the current class instance
class demo
{
    int a;
    int b;
 
    //Default constructor
    demo()
    {
        a = 10;
        b = 20;
    }
     
    //Method that returns current class instance
    // 3
    demo get()
    {
        // 4. returns the instance of class demo
        return this;
    }
     
    //Displaying value of variables a and b
    void display() // 6
    {
        System.out.println("a = " + a + "  b = " + b);  // 7
    }
}

public class Main
{
    public static void main(String[] args)
    {
        //1. create object of class demo
        demo object = new demo();
        object.get().display(); // 2 // 5
    }
}
&lt;/code&gt;  
  &lt;a href="https://onlinegdb.com/rJg2GSxbz"&gt;&lt;button class="button"&gt;&lt;span&gt;Run &lt;/span&gt;&lt;/button&gt;&lt;/a&gt;
&lt;/pre&gt;

&lt;h3&gt;Output&lt;/h3&gt;
&lt;pre&gt;
&lt;code class="java"&gt;
a = 10 b = 20
&lt;/code&gt;  
&lt;/pre&gt;







&lt;!-- ####################################################################### --&gt;
&lt;/body&gt;
&lt;/html&gt;&lt;/div&gt;
</description><link>http://tangled-java.blogspot.com/2017/12/this-keyword-in-java.html</link><author>noreply@blogger.com (Anonymous)</author><thr:total>0</thr:total></item><item><guid isPermaLink="false">tag:blogger.com,1999:blog-3082064622906880860.post-8734791732405336300</guid><pubDate>Thu, 30 Nov 2017 09:43:00 +0000</pubDate><atom:updated>2017-12-01T23:51:50.549-08:00</atom:updated><category domain="http://www.blogger.com/atom/ns#">difference between local and instance variable</category><category domain="http://www.blogger.com/atom/ns#">local variables</category><category domain="http://www.blogger.com/atom/ns#">method. method overloading</category><title>Method in Java</title><description>&lt;div dir="ltr" style="text-align: left;" trbidi="on"&gt;
&lt;html&gt;
&lt;head&gt;
 &lt;title&gt;&lt;/title&gt;
&lt;style&gt; strong{ color: white; }&lt;/style&gt;
&lt;script type="text/javascript"&gt;
 /*! highlight.js v9.12.0 | BSD3 License | git.io/hljslicense */
!function(e){var n="object"==typeof window&amp;&amp;window||"object"==typeof self&amp;&amp;self;"undefined"!=typeof exports?e(exports):n&amp;&amp;(n.hljs=e({}),"function"==typeof define&amp;&amp;define.amd&amp;&amp;define([],function(){return n.hljs}))}(function(e){function n(e){return e.replace(/&amp;/g,"&amp;amp;").replace(/&lt;/g,"&amp;lt;").replace(/&gt;/g,"&amp;gt;")}function t(e){return e.nodeName.toLowerCase()}function r(e,n){var t=e&amp;&amp;e.exec(n);return t&amp;&amp;0===t.index}function a(e){return k.test(e)}function i(e){var n,t,r,i,o=e.className+" ";if(o+=e.parentNode?e.parentNode.className:"",t=B.exec(o))return w(t[1])?t[1]:"no-highlight";for(o=o.split(/\s+/),n=0,r=o.length;r&gt;n;n++)if(i=o[n],a(i)||w(i))return i}function o(e){var n,t={},r=Array.prototype.slice.call(arguments,1);for(n in e)t[n]=e[n];return r.forEach(function(e){for(n in e)t[n]=e[n]}),t}function u(e){var n=[];return function r(e,a){for(var i=e.firstChild;i;i=i.nextSibling)3===i.nodeType?a+=i.nodeValue.length:1===i.nodeType&amp;&amp;(n.push({event:"start",offset:a,node:i}),a=r(i,a),t(i).match(/br|hr|img|input/)||n.push({event:"stop",offset:a,node:i}));return a}(e,0),n}function c(e,r,a){function i(){return e.length&amp;&amp;r.length?e[0].offset!==r[0].offset?e[0].offset&lt;r[0].offset?e:r:"start"===r[0].event?e:r:e.length?e:r}function o(e){function r(e){return" "+e.nodeName+'="'+n(e.value).replace('"',"&amp;quot;")+'"'}s+="&lt;"+t(e)+E.map.call(e.attributes,r).join("")+"&gt;"}function u(e){s+="&lt;/"+t(e)+"&gt;"}function c(e){("start"===e.event?o:u)(e.node)}for(var l=0,s="",f=[];e.length||r.length;){var g=i();if(s+=n(a.substring(l,g[0].offset)),l=g[0].offset,g===e){f.reverse().forEach(u);do c(g.splice(0,1)[0]),g=i();while(g===e&amp;&amp;g.length&amp;&amp;g[0].offset===l);f.reverse().forEach(o)}else"start"===g[0].event?f.push(g[0].node):f.pop(),c(g.splice(0,1)[0])}return s+n(a.substr(l))}function l(e){return e.v&amp;&amp;!e.cached_variants&amp;&amp;(e.cached_variants=e.v.map(function(n){return o(e,{v:null},n)})),e.cached_variants||e.eW&amp;&amp;[o(e)]||[e]}function s(e){function n(e){return e&amp;&amp;e.source||e}function t(t,r){return new RegExp(n(t),"m"+(e.cI?"i":"")+(r?"g":""))}function r(a,i){if(!a.compiled){if(a.compiled=!0,a.k=a.k||a.bK,a.k){var o={},u=function(n,t){e.cI&amp;&amp;(t=t.toLowerCase()),t.split(" ").forEach(function(e){var t=e.split("|");o[t[0]]=[n,t[1]?Number(t[1]):1]})};"string"==typeof a.k?u("keyword",a.k):x(a.k).forEach(function(e){u(e,a.k[e])}),a.k=o}a.lR=t(a.l||/\w+/,!0),i&amp;&amp;(a.bK&amp;&amp;(a.b="\\b("+a.bK.split(" ").join("|")+")\\b"),a.b||(a.b=/\B|\b/),a.bR=t(a.b),a.e||a.eW||(a.e=/\B|\b/),a.e&amp;&amp;(a.eR=t(a.e)),a.tE=n(a.e)||"",a.eW&amp;&amp;i.tE&amp;&amp;(a.tE+=(a.e?"|":"")+i.tE)),a.i&amp;&amp;(a.iR=t(a.i)),null==a.r&amp;&amp;(a.r=1),a.c||(a.c=[]),a.c=Array.prototype.concat.apply([],a.c.map(function(e){return l("self"===e?a:e)})),a.c.forEach(function(e){r(e,a)}),a.starts&amp;&amp;r(a.starts,i);var c=a.c.map(function(e){return e.bK?"\\.?("+e.b+")\\.?":e.b}).concat([a.tE,a.i]).map(n).filter(Boolean);a.t=c.length?t(c.join("|"),!0):{exec:function(){return null}}}}r(e)}function f(e,t,a,i){function o(e,n){var t,a;for(t=0,a=n.c.length;a&gt;t;t++)if(r(n.c[t].bR,e))return n.c[t]}function u(e,n){if(r(e.eR,n)){for(;e.endsParent&amp;&amp;e.parent;)e=e.parent;return e}return e.eW?u(e.parent,n):void 0}function c(e,n){return!a&amp;&amp;r(n.iR,e)}function l(e,n){var t=N.cI?n[0].toLowerCase():n[0];return e.k.hasOwnProperty(t)&amp;&amp;e.k[t]}function p(e,n,t,r){var a=r?"":I.classPrefix,i='&lt;span class="'+a,o=t?"":C;return i+=e+'"&gt;',i+n+o}function h(){var e,t,r,a;if(!E.k)return n(k);for(a="",t=0,E.lR.lastIndex=0,r=E.lR.exec(k);r;)a+=n(k.substring(t,r.index)),e=l(E,r),e?(B+=e[1],a+=p(e[0],n(r[0]))):a+=n(r[0]),t=E.lR.lastIndex,r=E.lR.exec(k);return a+n(k.substr(t))}function d(){var e="string"==typeof E.sL;if(e&amp;&amp;!y[E.sL])return n(k);var t=e?f(E.sL,k,!0,x[E.sL]):g(k,E.sL.length?E.sL:void 0);return E.r&gt;0&amp;&amp;(B+=t.r),e&amp;&amp;(x[E.sL]=t.top),p(t.language,t.value,!1,!0)}function b(){L+=null!=E.sL?d():h(),k=""}function v(e){L+=e.cN?p(e.cN,"",!0):"",E=Object.create(e,{parent:{value:E}})}function m(e,n){if(k+=e,null==n)return b(),0;var t=o(n,E);if(t)return t.skip?k+=n:(t.eB&amp;&amp;(k+=n),b(),t.rB||t.eB||(k=n)),v(t,n),t.rB?0:n.length;var r=u(E,n);if(r){var a=E;a.skip?k+=n:(a.rE||a.eE||(k+=n),b(),a.eE&amp;&amp;(k=n));do E.cN&amp;&amp;(L+=C),E.skip||(B+=E.r),E=E.parent;while(E!==r.parent);return r.starts&amp;&amp;v(r.starts,""),a.rE?0:n.length}if(c(n,E))throw new Error('Illegal lexeme "'+n+'" for mode "'+(E.cN||"&lt;unnamed&gt;")+'"');return k+=n,n.length||1}var N=w(e);if(!N)throw new Error('Unknown language: "'+e+'"');s(N);var R,E=i||N,x={},L="";for(R=E;R!==N;R=R.parent)R.cN&amp;&amp;(L=p(R.cN,"",!0)+L);var k="",B=0;try{for(var M,j,O=0;;){if(E.t.lastIndex=O,M=E.t.exec(t),!M)break;j=m(t.substring(O,M.index),M[0]),O=M.index+j}for(m(t.substr(O)),R=E;R.parent;R=R.parent)R.cN&amp;&amp;(L+=C);return{r:B,value:L,language:e,top:E}}catch(T){if(T.message&amp;&amp;-1!==T.message.indexOf("Illegal"))return{r:0,value:n(t)};throw T}}function g(e,t){t=t||I.languages||x(y);var r={r:0,value:n(e)},a=r;return t.filter(w).forEach(function(n){var t=f(n,e,!1);t.language=n,t.r&gt;a.r&amp;&amp;(a=t),t.r&gt;r.r&amp;&amp;(a=r,r=t)}),a.language&amp;&amp;(r.second_best=a),r}function p(e){return I.tabReplace||I.useBR?e.replace(M,function(e,n){return I.useBR&amp;&amp;"\n"===e?"&lt;br&gt;":I.tabReplace?n.replace(/\t/g,I.tabReplace):""}):e}function h(e,n,t){var r=n?L[n]:t,a=[e.trim()];return e.match(/\bhljs\b/)||a.push("hljs"),-1===e.indexOf(r)&amp;&amp;a.push(r),a.join(" ").trim()}function d(e){var n,t,r,o,l,s=i(e);a(s)||(I.useBR?(n=document.createElementNS("http://www.w3.org/1999/xhtml","div"),n.innerHTML=e.innerHTML.replace(/\n/g,"").replace(/&lt;br[ \/]*&gt;/g,"\n")):n=e,l=n.textContent,r=s?f(s,l,!0):g(l),t=u(n),t.length&amp;&amp;(o=document.createElementNS("http://www.w3.org/1999/xhtml","div"),o.innerHTML=r.value,r.value=c(t,u(o),l)),r.value=p(r.value),e.innerHTML=r.value,e.className=h(e.className,s,r.language),e.result={language:r.language,re:r.r},r.second_best&amp;&amp;(e.second_best={language:r.second_best.language,re:r.second_best.r}))}function b(e){I=o(I,e)}function v(){if(!v.called){v.called=!0;var e=document.querySelectorAll("pre code");E.forEach.call(e,d)}}function m(){addEventListener("DOMContentLoaded",v,!1),addEventListener("load",v,!1)}function N(n,t){var r=y[n]=t(e);r.aliases&amp;&amp;r.aliases.forEach(function(e){L[e]=n})}function R(){return x(y)}function w(e){return e=(e||"").toLowerCase(),y[e]||y[L[e]]}var E=[],x=Object.keys,y={},L={},k=/^(no-?highlight|plain|text)$/i,B=/\blang(?:uage)?-([\w-]+)\b/i,M=/((^(&lt;[^&gt;]+&gt;|\t|)+|(?:\n)))/gm,C="&lt;/span&gt;",I={classPrefix:"hljs-",tabReplace:null,useBR:!1,languages:void 0};return e.highlight=f,e.highlightAuto=g,e.fixMarkup=p,e.highlightBlock=d,e.configure=b,e.initHighlighting=v,e.initHighlightingOnLoad=m,e.registerLanguage=N,e.listLanguages=R,e.getLanguage=w,e.inherit=o,e.IR="[a-zA-Z]\\w*",e.UIR="[a-zA-Z_]\\w*",e.NR="\\b\\d+(\\.\\d+)?",e.CNR="(-?)(\\b0[xX][a-fA-F0-9]+|(\\b\\d+(\\.\\d*)?|\\.\\d+)([eE][-+]?\\d+)?)",e.BNR="\\b(0b[01]+)",e.RSR="!|!=|!==|%|%=|&amp;|&amp;&amp;|&amp;=|\\*|\\*=|\\+|\\+=|,|-|-=|/=|/|:|;|&lt;&lt;|&lt;&lt;=|&lt;=|&lt;|===|==|=|&gt;&gt;&gt;=|&gt;&gt;=|&gt;=|&gt;&gt;&gt;|&gt;&gt;|&gt;|\\?|\\[|\\{|\\(|\\^|\\^=|\\||\\|=|\\|\\||~",e.BE={b:"\\\\[\\s\\S]",r:0},e.ASM={cN:"string",b:"'",e:"'",i:"\\n",c:[e.BE]},e.QSM={cN:"string",b:'"',e:'"',i:"\\n",c:[e.BE]},e.PWM={b:/\b(a|an|the|are|I'm|isn't|don't|doesn't|won't|but|just|should|pretty|simply|enough|gonna|going|wtf|so|such|will|you|your|they|like|more)\b/},e.C=function(n,t,r){var a=e.inherit({cN:"comment",b:n,e:t,c:[]},r||{});return a.c.push(e.PWM),a.c.push({cN:"doctag",b:"(?:TODO|FIXME|NOTE|BUG|XXX):",r:0}),a},e.CLCM=e.C("//","$"),e.CBCM=e.C("/\\*","\\*/"),e.HCM=e.C("#","$"),e.NM={cN:"number",b:e.NR,r:0},e.CNM={cN:"number",b:e.CNR,r:0},e.BNM={cN:"number",b:e.BNR,r:0},e.CSSNM={cN:"number",b:e.NR+"(%|em|ex|ch|rem|vw|vh|vmin|vmax|cm|mm|in|pt|pc|px|deg|grad|rad|turn|s|ms|Hz|kHz|dpi|dpcm|dppx)?",r:0},e.RM={cN:"regexp",b:/\//,e:/\/[gimuy]*/,i:/\n/,c:[e.BE,{b:/\[/,e:/\]/,r:0,c:[e.BE]}]},e.TM={cN:"title",b:e.IR,r:0},e.UTM={cN:"title",b:e.UIR,r:0},e.METHOD_GUARD={b:"\\.\\s*"+e.UIR,r:0},e});hljs.registerLanguage("java",function(e){var a="[À-ʸa-zA-Z_$][À-ʸa-zA-Z_$0-9]*",t=a+"(&lt;"+a+"(\\s*,\\s*"+a+")*&gt;)?",r="false synchronized int abstract float private char boolean static null if const for true while long strictfp finally protected import native final void enum else break transient catch instanceof byte super volatile case assert short package default double public try this switch continue throws protected public private module requires exports do",s="\\b(0[bB]([01]+[01_]+[01]+|[01]+)|0[xX]([a-fA-F0-9]+[a-fA-F0-9_]+[a-fA-F0-9]+|[a-fA-F0-9]+)|(([\\d]+[\\d_]+[\\d]+|[\\d]+)(\\.([\\d]+[\\d_]+[\\d]+|[\\d]+))?|\\.([\\d]+[\\d_]+[\\d]+|[\\d]+))([eE][-+]?\\d+)?)[lLfF]?",c={cN:"number",b:s,r:0};return{aliases:["jsp"],k:r,i:/&lt;\/|#/,c:[e.C("/\\*\\*","\\*/",{r:0,c:[{b:/\w+@/,r:0},{cN:"doctag",b:"@[A-Za-z]+"}]}),e.CLCM,e.CBCM,e.ASM,e.QSM,{cN:"class",bK:"class interface",e:/[{;=]/,eE:!0,k:"class interface",i:/[:"\[\]]/,c:[{bK:"extends implements"},e.UTM]},{bK:"new throw return else",r:0},{cN:"function",b:"("+t+"\\s+)+"+e.UIR+"\\s*\\(",rB:!0,e:/[{;=]/,eE:!0,k:r,c:[{b:e.UIR+"\\s*\\(",rB:!0,r:0,c:[e.UTM]},{cN:"params",b:/\(/,e:/\)/,k:r,r:0,c:[e.ASM,e.QSM,e.CNM,e.CBCM]},e.CLCM,e.CBCM]},c,{cN:"meta",b:"@[A-Za-z]+"}]}});
&lt;/script&gt;
&lt;script&gt;hljs.initHighlightingOnLoad();&lt;/script&gt;
&lt;/head&gt;
&lt;body onload="selectjava()"&gt;
&lt;!-- ####################################################################### --&gt;
&lt;img src="https://www.shareicon.net/download/2015/09/16/101886_java_512x512.png" style="display: none;"/&gt;
Methods appear inside class bodies. They contain local variable declarations and other Java statements that are executed when the method is invoked. Methods may return a value to the caller. They always specify a return type, which can be a primitive type, a reference type, or the type void , which indicates no returned value. Methods may take arguments, which are values supplied by the caller of the method.

Lets see example:

&lt;h3&gt;Program&lt;/h3&gt;
&lt;pre&gt;
&lt;code class="java"&gt;
class multiply
{
    int num1;
    int num2;
    int mul(int x,int y)
    {
        int result;
        num1 = x;
        num2 = y;
        result = num1*num2;
        return result;
    }
}

public class Main
{
    public static void main (String[] args) 
    {
        multiply m = new multiply();
        System.out.println("multiplication of 3 and 5 is " + m.mul(3,5));
    }
}
&lt;/code&gt;  
  &lt;a href="https://onlinegdb.com/By6pyHalG"&gt;&lt;button class="button"&gt;&lt;span&gt;Run &lt;/span&gt;&lt;/button&gt;&lt;/a&gt;
&lt;/pre&gt;

&lt;h3&gt;Output&lt;/h3&gt;
&lt;pre&gt;
&lt;code class="java"&gt;
multiplication of 3 and 5 is 15
&lt;/code&gt;  
&lt;/pre&gt;

&lt;h3&gt;Explanation&lt;/h3&gt;
In this example, the class &lt;strong&gt;multiply&lt;/strong&gt; defines a method, &lt;strong&gt;mul()&lt;/strong&gt;, that takes as arguments two integers: x and y. It returns a &lt;strong&gt;int&lt;/strong&gt; type value as a result, using the &lt;strong&gt;return&lt;/strong&gt; keyword.

Our method has a fixed number of arguments (two); however, methods can have variable-length argument lists, which allow the method to specify that it can take any number of arguments and sort them itself at runtime. 

&lt;h2&gt;Local variables&lt;/h2&gt;
Our &lt;strong&gt;mul()&lt;/strong&gt; method declares a local variable called &lt;strong&gt;result&lt;/strong&gt;, which it uses to compute the multiplication of two numbers. A local variable is temporary; it exists only within the scope (the block) of its method. Local variables are allocated when a method is invoked; they are normally destroyed when the method returns. They can’t be referenced from outside the method itself. If the method is executing concurrently in different threads, each thread has its own version of the method’s local variables. A method’s arguments also serve as local variables within the scope of the method; the only difference is that they are initialized by being passed in from the caller of the method.&lt;br&gt;&lt;br&gt;

A varibale created within a method and assigned to a local variable may or may not persist after the method has returned. As with all variable in Java, it depends on whether any references to the variable remain. If an variable is created, assigned to a local variable, and never used anywhere else, that variable is no longer referenced when the local variable disappears from scope, so garbage collection removes the variable. If, however, we assign the variable to an instance variable of an object, pass it as an argument to another method, or pass it back as a return value, it may be saved by another variable holding its reference.

&lt;h2&gt;Difference between local variable and instance variable&lt;/h2&gt;
Now let's see the difference between &lt;strong&gt;instance variable&lt;/strong&gt; and &lt;strong&gt;local variable&lt;/strong&gt;. local variables are local in scope and they are not visible or accessible outside there scope which is determined by &lt;strong&gt;{}&lt;/strong&gt; while instance variables are visible on all part of code based on there access modifier &lt;strong&gt;e.g. public , private or protected&lt;/strong&gt;. The only public can be accessed from outside while protected and private can be accessed from subclass and class itself. Access modifier can not be applied to a local variable and you can not even make them static. The only modifier which is applicable to a local variable is final and only final local variables are visible inside the anonymous class. the value of instance variable is limited to an instance, one instance can not access the value of other instance in Java.

&lt;h2&gt;Shadowing of instance variable by local variable&lt;/h2&gt;
If a local variable and an instance variable have the same name, the local variable shadows or hides the name of the instance variable within the scope of the method. In the following example, the local variables num1 and num2 hide the instance variables of the same name:

&lt;h3&gt;Program&lt;/h3&gt;
&lt;pre&gt;
&lt;code class="java"&gt;
class multiply
{
    //instance variable
    int num1;
    int num2;
    int mul(int x,int y)
    {
        //local variable
        int result;
        //assigning x and y to local variable 
        int num1 = x;
        int num2 = y;
        result = num1*num2;
        return result;
    }
}

public class Main
{
    public static void main (String[] args) 
    {
        multiply m = new multiply();
        System.out.println("multiplication of 3 and 5 is " + m.mul(5,3));
        //we have assigned x and y to local variable so we can't access the value of x and y outside method
        System.out.println("num1 = " + m.num1 + " num2 = " + m.num2);
    }
}
&lt;/code&gt;  
  &lt;a href="https://onlinegdb.com/BJZUKS6ez"&gt;&lt;button class="button"&gt;&lt;span&gt;Run &lt;/span&gt;&lt;/button&gt;&lt;/a&gt;
&lt;/pre&gt;

&lt;h3&gt;Output&lt;/h3&gt;
&lt;pre&gt;
&lt;code class="java"&gt;
multiplication of 3 and 5 is 15
num1 = 0 num2 = 0
&lt;/code&gt;  
&lt;/pre&gt;

&lt;h3&gt;Explanation&lt;/h3&gt;
When we set the values of the local variables in &lt;strong&gt;mul()&lt;/strong&gt;, it has no effect on the values of the instance variables.So they are zero.So, this is also example of a varibale created within a method and assigned to a local variable may or may not persist after the method has returned. As with all variable in Java, it depends on whether any references to the variable remain.&lt;br&gt;&lt;br&gt;



Now lets see the example without shadowing.


&lt;h3&gt;Program&lt;/h3&gt;
&lt;pre&gt;
&lt;code class="java"&gt;
class multiply
{
    //instance variable
    int num1;
    int num2;
    int mul(int x,int y)
    {
        //local variable
        int result;
        //assigning x and y to instance variable 
        num1 = x;
        num2 = y;
        result = num1*num2;
        return result;
    }
}

public class Main
{
    public static void main (String[] args) 
    {
        multiply m = new multiply();
        System.out.println("multiplication of 3 and 5 is " + m.mul(5,3));
        //we have assigned x and y to instance variable so we can access the value of x and y outside method
        System.out.println("num1 = " + m.num1 + " num2 = " + m.num2);
    }
}
&lt;/code&gt;  
  &lt;a href="https://onlinegdb.com/rJkCjrpxG"&gt;&lt;button class="button"&gt;&lt;span&gt;Run &lt;/span&gt;&lt;/button&gt;&lt;/a&gt;
&lt;/pre&gt;

&lt;h3&gt;Output&lt;/h3&gt;
&lt;pre&gt;
&lt;code class="java"&gt;
multiplication of 3 and 5 is 15
num1 = 5 num2 = 3
&lt;/code&gt;  
&lt;/pre&gt;

&lt;h3&gt;Explanation&lt;/h3&gt;
Like I said- If, however, we assign the variable to an instance variable of an object, pass it as an argument to another method, or pass it back as a return value, it may be saved by another variable holding its reference.&lt;br&gt;

&lt;h2&gt;Method overloading&lt;/h2&gt;

Method overloading is the ability to define multiple methods with the same name in a class; when the method is invoked, the compiler picks the correct one based on the arguments passed to the method. This implies that overloaded methods must have different numbers or types of arguments. &lt;br&gt;&lt;br&gt;

Method overloading (also called ad-hoc polymorphism ) is a powerful and useful feature. The idea is to create methods that act in the same way on different types of arguments. This creates the illusion that a single method can operate on many types of arguments. The print() method in the standard PrintStream class is a good example of method overloading in action. As you’ve probably deduced by now, you can print a string representation of just about anything using this expression:

&lt;pre&gt;
&lt;code class="java"&gt;
System.out.print( argument );
&lt;/code&gt;  
&lt;/pre&gt;


The variable out is a reference to an object (a PrintStream) that defines nine different, “overloaded” versions of the print() method. The versions take arguments of the following types: &lt;strong&gt;Object, String, char[], char, int, long, float, double, and boolean.&lt;/strong&gt;&lt;br&gt;&lt;br&gt;

You can invoke the print() method with any of these types as an argument, and it’s printed in an appropriate way. In a language without method overloading, this requires something more cumbersome, such as a uniquely named method for printing each type of object. In that case, it’s your responsibility to figure out what method to use for each data type.&lt;br&gt;&lt;br&gt;

What if there’s more than one possible match? For example, we try to print a subclass of String called MyString. (The String class is final so it can’t really be subclassed, but let’s use our imaginations.) MyString is assignable to either String or to Object. Here, the compiler makes a determination as to which match is “better” and selects that method. In this case, it’s the String method.&lt;br&gt;&lt;br&gt;

The intuitive explanation for this is that the String class is "closer" to MyString in the inheritance hierarchy. It is a more specific match. A slightly more rigorous way of specifying it would be to say that a given method is more specific than another method if the argument types of the first method are all assignable to the argument types of the second method. In this case, the String method is more specific to a subclass of String than the Object method because type String is assignable to type Object. The reverse is not true.&lt;br&gt;&lt;br&gt;

&lt;div id="imp"&gt;Method overloading is not something that happens at runtime; this is an important distinction. It means that the selected method is chosen once, when the code is compiled. Once the overloaded method is selected, the choice is fixed until the code is recompiled.&lt;/div&gt;

&lt;h2&gt;Example of method overloading with changing no of arguments&lt;/h2&gt;

&lt;h3&gt;Program&lt;/h3&gt;
&lt;pre&gt;
&lt;code class="java"&gt;
class SUM
{  
    //two arguments
    int add(int a, int b)
    {
        return a+b;
    }  
    //three arguments
    int add(int a,int b,int c)
    {
        return a+b+c;
    }  
}  
class Main{  
    public static void main(String[] args)
    {  
        SUM s = new SUM();
        System.out.println(s.add(11,12));  
        System.out.println(s.add(12,1,15));  
    }
}  
&lt;/code&gt;  
  &lt;a href="https://onlinegdb.com/r1iUWUplz"&gt;&lt;button class="button"&gt;&lt;span&gt;Run &lt;/span&gt;&lt;/button&gt;&lt;/a&gt;
&lt;/pre&gt;

&lt;h3&gt;Output&lt;/h3&gt;
&lt;pre&gt;
&lt;code class="java"&gt;
23
28
&lt;/code&gt;  
&lt;/pre&gt;

&lt;h3&gt;Explanation&lt;/h3&gt;
In this example, we have created two methods, first &lt;strong&gt;add()&lt;/strong&gt; method performs addition of two numbers and second add method performs addition of three numbers.&lt;br&gt;&lt;br&gt;

&lt;h2&gt;Example of method overloading with changing data type of arguments&lt;/h2&gt;

&lt;h3&gt;Program&lt;/h3&gt;
&lt;pre&gt;
&lt;code class="java"&gt;
class SUM
{  
    //int argument
    int add(int a, int b)
    {
        return a+b;
    }  
    //double argument
    double add(double a, double b)
    {
        return a+b;
    }  
}  
class Main{  
    public static void main(String[] args)
    {  
        SUM s = new SUM();
        System.out.println(s.add(11,12));  
        System.out.println(s.add(12.3,1.6));  
    }
}  
&lt;/code&gt;  
  &lt;a href="https://onlinegdb.com/rykKl8plG"&gt;&lt;button class="button"&gt;&lt;span&gt;Run &lt;/span&gt;&lt;/button&gt;&lt;/a&gt;
&lt;/pre&gt;

&lt;h3&gt;Output&lt;/h3&gt;
&lt;pre&gt;
&lt;code class="java"&gt;
23
13.9
&lt;/code&gt;  
&lt;/pre&gt;

&lt;h3&gt;Explanation&lt;/h3&gt;
In this example, we have created two methods that differs in data type. The first add method receives two integer arguments and second add method receives two double arguments.


&lt;!-- ####################################################################### --&gt;
&lt;/body&gt;
&lt;/html&gt;&lt;/div&gt;
</description><link>http://tangled-java.blogspot.com/2017/11/method-in-java.html</link><author>noreply@blogger.com (Anonymous)</author><thr:total>0</thr:total></item><item><guid isPermaLink="false">tag:blogger.com,1999:blog-3082064622906880860.post-4565337113842724642</guid><pubDate>Wed, 29 Nov 2017 18:52:00 +0000</pubDate><atom:updated>2017-12-02T05:33:54.067-08:00</atom:updated><category domain="http://www.blogger.com/atom/ns#">constructor</category><category domain="http://www.blogger.com/atom/ns#">copy constructor</category><title>Constructor in Java</title><description>&lt;div dir="ltr" style="text-align: left;" trbidi="on"&gt;
&lt;html&gt;
&lt;head&gt;
 &lt;title&gt;&lt;/title&gt;
&lt;style&gt;
table {
    border-collapse: collapse;
    border-spacing: 0;
    width: 100%;
    border: 1px solid #ddd;
}

th, td {
    text-align: left;
    padding: 8px;
border: 1px solid #ddd;

}

tr:nth-child(even){background-color: #1e1e1e;}

&lt;/style&gt;
&lt;script type="text/javascript"&gt;
 /*! highlight.js v9.12.0 | BSD3 License | git.io/hljslicense */
!function(e){var n="object"==typeof window&amp;&amp;window||"object"==typeof self&amp;&amp;self;"undefined"!=typeof exports?e(exports):n&amp;&amp;(n.hljs=e({}),"function"==typeof define&amp;&amp;define.amd&amp;&amp;define([],function(){return n.hljs}))}(function(e){function n(e){return e.replace(/&amp;/g,"&amp;amp;").replace(/&lt;/g,"&amp;lt;").replace(/&gt;/g,"&amp;gt;")}function t(e){return e.nodeName.toLowerCase()}function r(e,n){var t=e&amp;&amp;e.exec(n);return t&amp;&amp;0===t.index}function a(e){return k.test(e)}function i(e){var n,t,r,i,o=e.className+" ";if(o+=e.parentNode?e.parentNode.className:"",t=B.exec(o))return w(t[1])?t[1]:"no-highlight";for(o=o.split(/\s+/),n=0,r=o.length;r&gt;n;n++)if(i=o[n],a(i)||w(i))return i}function o(e){var n,t={},r=Array.prototype.slice.call(arguments,1);for(n in e)t[n]=e[n];return r.forEach(function(e){for(n in e)t[n]=e[n]}),t}function u(e){var n=[];return function r(e,a){for(var i=e.firstChild;i;i=i.nextSibling)3===i.nodeType?a+=i.nodeValue.length:1===i.nodeType&amp;&amp;(n.push({event:"start",offset:a,node:i}),a=r(i,a),t(i).match(/br|hr|img|input/)||n.push({event:"stop",offset:a,node:i}));return a}(e,0),n}function c(e,r,a){function i(){return e.length&amp;&amp;r.length?e[0].offset!==r[0].offset?e[0].offset&lt;r[0].offset?e:r:"start"===r[0].event?e:r:e.length?e:r}function o(e){function r(e){return" "+e.nodeName+'="'+n(e.value).replace('"',"&amp;quot;")+'"'}s+="&lt;"+t(e)+E.map.call(e.attributes,r).join("")+"&gt;"}function u(e){s+="&lt;/"+t(e)+"&gt;"}function c(e){("start"===e.event?o:u)(e.node)}for(var l=0,s="",f=[];e.length||r.length;){var g=i();if(s+=n(a.substring(l,g[0].offset)),l=g[0].offset,g===e){f.reverse().forEach(u);do c(g.splice(0,1)[0]),g=i();while(g===e&amp;&amp;g.length&amp;&amp;g[0].offset===l);f.reverse().forEach(o)}else"start"===g[0].event?f.push(g[0].node):f.pop(),c(g.splice(0,1)[0])}return s+n(a.substr(l))}function l(e){return e.v&amp;&amp;!e.cached_variants&amp;&amp;(e.cached_variants=e.v.map(function(n){return o(e,{v:null},n)})),e.cached_variants||e.eW&amp;&amp;[o(e)]||[e]}function s(e){function n(e){return e&amp;&amp;e.source||e}function t(t,r){return new RegExp(n(t),"m"+(e.cI?"i":"")+(r?"g":""))}function r(a,i){if(!a.compiled){if(a.compiled=!0,a.k=a.k||a.bK,a.k){var o={},u=function(n,t){e.cI&amp;&amp;(t=t.toLowerCase()),t.split(" ").forEach(function(e){var t=e.split("|");o[t[0]]=[n,t[1]?Number(t[1]):1]})};"string"==typeof a.k?u("keyword",a.k):x(a.k).forEach(function(e){u(e,a.k[e])}),a.k=o}a.lR=t(a.l||/\w+/,!0),i&amp;&amp;(a.bK&amp;&amp;(a.b="\\b("+a.bK.split(" ").join("|")+")\\b"),a.b||(a.b=/\B|\b/),a.bR=t(a.b),a.e||a.eW||(a.e=/\B|\b/),a.e&amp;&amp;(a.eR=t(a.e)),a.tE=n(a.e)||"",a.eW&amp;&amp;i.tE&amp;&amp;(a.tE+=(a.e?"|":"")+i.tE)),a.i&amp;&amp;(a.iR=t(a.i)),null==a.r&amp;&amp;(a.r=1),a.c||(a.c=[]),a.c=Array.prototype.concat.apply([],a.c.map(function(e){return l("self"===e?a:e)})),a.c.forEach(function(e){r(e,a)}),a.starts&amp;&amp;r(a.starts,i);var c=a.c.map(function(e){return e.bK?"\\.?("+e.b+")\\.?":e.b}).concat([a.tE,a.i]).map(n).filter(Boolean);a.t=c.length?t(c.join("|"),!0):{exec:function(){return null}}}}r(e)}function f(e,t,a,i){function o(e,n){var t,a;for(t=0,a=n.c.length;a&gt;t;t++)if(r(n.c[t].bR,e))return n.c[t]}function u(e,n){if(r(e.eR,n)){for(;e.endsParent&amp;&amp;e.parent;)e=e.parent;return e}return e.eW?u(e.parent,n):void 0}function c(e,n){return!a&amp;&amp;r(n.iR,e)}function l(e,n){var t=N.cI?n[0].toLowerCase():n[0];return e.k.hasOwnProperty(t)&amp;&amp;e.k[t]}function p(e,n,t,r){var a=r?"":I.classPrefix,i='&lt;span class="'+a,o=t?"":C;return i+=e+'"&gt;',i+n+o}function h(){var e,t,r,a;if(!E.k)return n(k);for(a="",t=0,E.lR.lastIndex=0,r=E.lR.exec(k);r;)a+=n(k.substring(t,r.index)),e=l(E,r),e?(B+=e[1],a+=p(e[0],n(r[0]))):a+=n(r[0]),t=E.lR.lastIndex,r=E.lR.exec(k);return a+n(k.substr(t))}function d(){var e="string"==typeof E.sL;if(e&amp;&amp;!y[E.sL])return n(k);var t=e?f(E.sL,k,!0,x[E.sL]):g(k,E.sL.length?E.sL:void 0);return E.r&gt;0&amp;&amp;(B+=t.r),e&amp;&amp;(x[E.sL]=t.top),p(t.language,t.value,!1,!0)}function b(){L+=null!=E.sL?d():h(),k=""}function v(e){L+=e.cN?p(e.cN,"",!0):"",E=Object.create(e,{parent:{value:E}})}function m(e,n){if(k+=e,null==n)return b(),0;var t=o(n,E);if(t)return t.skip?k+=n:(t.eB&amp;&amp;(k+=n),b(),t.rB||t.eB||(k=n)),v(t,n),t.rB?0:n.length;var r=u(E,n);if(r){var a=E;a.skip?k+=n:(a.rE||a.eE||(k+=n),b(),a.eE&amp;&amp;(k=n));do E.cN&amp;&amp;(L+=C),E.skip||(B+=E.r),E=E.parent;while(E!==r.parent);return r.starts&amp;&amp;v(r.starts,""),a.rE?0:n.length}if(c(n,E))throw new Error('Illegal lexeme "'+n+'" for mode "'+(E.cN||"&lt;unnamed&gt;")+'"');return k+=n,n.length||1}var N=w(e);if(!N)throw new Error('Unknown language: "'+e+'"');s(N);var R,E=i||N,x={},L="";for(R=E;R!==N;R=R.parent)R.cN&amp;&amp;(L=p(R.cN,"",!0)+L);var k="",B=0;try{for(var M,j,O=0;;){if(E.t.lastIndex=O,M=E.t.exec(t),!M)break;j=m(t.substring(O,M.index),M[0]),O=M.index+j}for(m(t.substr(O)),R=E;R.parent;R=R.parent)R.cN&amp;&amp;(L+=C);return{r:B,value:L,language:e,top:E}}catch(T){if(T.message&amp;&amp;-1!==T.message.indexOf("Illegal"))return{r:0,value:n(t)};throw T}}function g(e,t){t=t||I.languages||x(y);var r={r:0,value:n(e)},a=r;return t.filter(w).forEach(function(n){var t=f(n,e,!1);t.language=n,t.r&gt;a.r&amp;&amp;(a=t),t.r&gt;r.r&amp;&amp;(a=r,r=t)}),a.language&amp;&amp;(r.second_best=a),r}function p(e){return I.tabReplace||I.useBR?e.replace(M,function(e,n){return I.useBR&amp;&amp;"\n"===e?"&lt;br&gt;":I.tabReplace?n.replace(/\t/g,I.tabReplace):""}):e}function h(e,n,t){var r=n?L[n]:t,a=[e.trim()];return e.match(/\bhljs\b/)||a.push("hljs"),-1===e.indexOf(r)&amp;&amp;a.push(r),a.join(" ").trim()}function d(e){var n,t,r,o,l,s=i(e);a(s)||(I.useBR?(n=document.createElementNS("http://www.w3.org/1999/xhtml","div"),n.innerHTML=e.innerHTML.replace(/\n/g,"").replace(/&lt;br[ \/]*&gt;/g,"\n")):n=e,l=n.textContent,r=s?f(s,l,!0):g(l),t=u(n),t.length&amp;&amp;(o=document.createElementNS("http://www.w3.org/1999/xhtml","div"),o.innerHTML=r.value,r.value=c(t,u(o),l)),r.value=p(r.value),e.innerHTML=r.value,e.className=h(e.className,s,r.language),e.result={language:r.language,re:r.r},r.second_best&amp;&amp;(e.second_best={language:r.second_best.language,re:r.second_best.r}))}function b(e){I=o(I,e)}function v(){if(!v.called){v.called=!0;var e=document.querySelectorAll("pre code");E.forEach.call(e,d)}}function m(){addEventListener("DOMContentLoaded",v,!1),addEventListener("load",v,!1)}function N(n,t){var r=y[n]=t(e);r.aliases&amp;&amp;r.aliases.forEach(function(e){L[e]=n})}function R(){return x(y)}function w(e){return e=(e||"").toLowerCase(),y[e]||y[L[e]]}var E=[],x=Object.keys,y={},L={},k=/^(no-?highlight|plain|text)$/i,B=/\blang(?:uage)?-([\w-]+)\b/i,M=/((^(&lt;[^&gt;]+&gt;|\t|)+|(?:\n)))/gm,C="&lt;/span&gt;",I={classPrefix:"hljs-",tabReplace:null,useBR:!1,languages:void 0};return e.highlight=f,e.highlightAuto=g,e.fixMarkup=p,e.highlightBlock=d,e.configure=b,e.initHighlighting=v,e.initHighlightingOnLoad=m,e.registerLanguage=N,e.listLanguages=R,e.getLanguage=w,e.inherit=o,e.IR="[a-zA-Z]\\w*",e.UIR="[a-zA-Z_]\\w*",e.NR="\\b\\d+(\\.\\d+)?",e.CNR="(-?)(\\b0[xX][a-fA-F0-9]+|(\\b\\d+(\\.\\d*)?|\\.\\d+)([eE][-+]?\\d+)?)",e.BNR="\\b(0b[01]+)",e.RSR="!|!=|!==|%|%=|&amp;|&amp;&amp;|&amp;=|\\*|\\*=|\\+|\\+=|,|-|-=|/=|/|:|;|&lt;&lt;|&lt;&lt;=|&lt;=|&lt;|===|==|=|&gt;&gt;&gt;=|&gt;&gt;=|&gt;=|&gt;&gt;&gt;|&gt;&gt;|&gt;|\\?|\\[|\\{|\\(|\\^|\\^=|\\||\\|=|\\|\\||~",e.BE={b:"\\\\[\\s\\S]",r:0},e.ASM={cN:"string",b:"'",e:"'",i:"\\n",c:[e.BE]},e.QSM={cN:"string",b:'"',e:'"',i:"\\n",c:[e.BE]},e.PWM={b:/\b(a|an|the|are|I'm|isn't|don't|doesn't|won't|but|just|should|pretty|simply|enough|gonna|going|wtf|so|such|will|you|your|they|like|more)\b/},e.C=function(n,t,r){var a=e.inherit({cN:"comment",b:n,e:t,c:[]},r||{});return a.c.push(e.PWM),a.c.push({cN:"doctag",b:"(?:TODO|FIXME|NOTE|BUG|XXX):",r:0}),a},e.CLCM=e.C("//","$"),e.CBCM=e.C("/\\*","\\*/"),e.HCM=e.C("#","$"),e.NM={cN:"number",b:e.NR,r:0},e.CNM={cN:"number",b:e.CNR,r:0},e.BNM={cN:"number",b:e.BNR,r:0},e.CSSNM={cN:"number",b:e.NR+"(%|em|ex|ch|rem|vw|vh|vmin|vmax|cm|mm|in|pt|pc|px|deg|grad|rad|turn|s|ms|Hz|kHz|dpi|dpcm|dppx)?",r:0},e.RM={cN:"regexp",b:/\//,e:/\/[gimuy]*/,i:/\n/,c:[e.BE,{b:/\[/,e:/\]/,r:0,c:[e.BE]}]},e.TM={cN:"title",b:e.IR,r:0},e.UTM={cN:"title",b:e.UIR,r:0},e.METHOD_GUARD={b:"\\.\\s*"+e.UIR,r:0},e});hljs.registerLanguage("java",function(e){var a="[À-ʸa-zA-Z_$][À-ʸa-zA-Z_$0-9]*",t=a+"(&lt;"+a+"(\\s*,\\s*"+a+")*&gt;)?",r="false synchronized int abstract float private char boolean static null if const for true while long strictfp finally protected import native final void enum else break transient catch instanceof byte super volatile case assert short package default double public try this switch continue throws protected public private module requires exports do",s="\\b(0[bB]([01]+[01_]+[01]+|[01]+)|0[xX]([a-fA-F0-9]+[a-fA-F0-9_]+[a-fA-F0-9]+|[a-fA-F0-9]+)|(([\\d]+[\\d_]+[\\d]+|[\\d]+)(\\.([\\d]+[\\d_]+[\\d]+|[\\d]+))?|\\.([\\d]+[\\d_]+[\\d]+|[\\d]+))([eE][-+]?\\d+)?)[lLfF]?",c={cN:"number",b:s,r:0};return{aliases:["jsp"],k:r,i:/&lt;\/|#/,c:[e.C("/\\*\\*","\\*/",{r:0,c:[{b:/\w+@/,r:0},{cN:"doctag",b:"@[A-Za-z]+"}]}),e.CLCM,e.CBCM,e.ASM,e.QSM,{cN:"class",bK:"class interface",e:/[{;=]/,eE:!0,k:"class interface",i:/[:"\[\]]/,c:[{bK:"extends implements"},e.UTM]},{bK:"new throw return else",r:0},{cN:"function",b:"("+t+"\\s+)+"+e.UIR+"\\s*\\(",rB:!0,e:/[{;=]/,eE:!0,k:r,c:[{b:e.UIR+"\\s*\\(",rB:!0,r:0,c:[e.UTM]},{cN:"params",b:/\(/,e:/\)/,k:r,r:0,c:[e.ASM,e.QSM,e.CNM,e.CBCM]},e.CLCM,e.CBCM]},c,{cN:"meta",b:"@[A-Za-z]+"}]}});
&lt;/script&gt;
&lt;script&gt;hljs.initHighlightingOnLoad();&lt;/script&gt;
&lt;/head&gt;
&lt;body onload="selectjava()"&gt;
&lt;!-- ####################################################################### --&gt;
&lt;div id="topics"&gt;
&lt;ul&gt;&lt;/ul&gt;
&lt;/div&gt;

Objects in Java are allocated on a system “heap” memory space. Unlike other languages, however, we needn’t manage that memory ourselves. Java takes care of memory allocation and deallocation for you. Java explicitly allocates storage for an object when you create it with the new operator. More importantly, objects are removed by garbage collection when they’re no longer referenced.&lt;br&gt;&lt;br&gt;

&lt;h2&gt;Constructors&lt;/h2&gt;

Objects are allocated with the new operator using an object constructor. A constructor is a special method with the same name as its class and no return type. It’s called when a new class instance is created, which gives the class an opportunity to set up the object for use. Constructors, like other methods, can accept arguments and can be overloaded. they are not, however, inherited like other methods.&lt;br&gt;&lt;br&gt;

There are two types of constructors:

&lt;h2&gt;1. Default constructor (no-arg constructor)&lt;/h2&gt;
A constructor that has no parameter is known as default constructor. If we don’t define a constructor in a class, then compiler creates default constructor(with no arguments) for the class. And if we write a constructor with arguments or no-argument then compiler does not create default constructor.
Default constructor provides the default values to the object like 0, null etc. depending on the type.

&lt;h3&gt;Syntax&lt;/h3&gt;
&lt;pre&gt;
&lt;code class="java"&gt;
class_name()
{

}
&lt;/code&gt;  
&lt;/pre&gt;
&lt;h3&gt;Program&lt;/h3&gt;
&lt;pre&gt;
&lt;code class="java"&gt;
class Car 
{
    //car constructor
    Car()
    {
        System.out.println("new car is ready.");
    }
}

public class Default_Constructer
{
    public static void main(String args[])
    {
        //object creation
        Car swift = new Car();
    }
}
&lt;/code&gt;  
  &lt;a href="https://onlinegdb.com/SkSFTDheM"&gt;&lt;button class="button"&gt;&lt;span&gt;Run &lt;/span&gt;&lt;/button&gt;&lt;/a&gt;
&lt;/pre&gt;
&lt;h3&gt;Output&lt;/h3&gt;
&lt;pre&gt;
&lt;code class="java"&gt;
new car is ready.
&lt;/code&gt;  
&lt;/pre&gt;
&lt;h3&gt;Explanation&lt;/h3&gt;
In this example, the class &lt;strong&gt;Car&lt;/strong&gt; has one constructors. which takes no arguments; it’s known as the default constructor. Default constructors play a special role: if we don’t define any constructors for a class, an empty default constructor is supplied for us. The default constructor is what gets called whenever you create an object by calling its constructor with no arguments. Here we have implemented the default constructor so that it sets the instance swift. 

&lt;div id="imp"&gt;If there is no constructor in a class, compiler automatically creates a default constructor.Default constructor provides the default values to the object like 0, null etc. depending on the type.&lt;/div&gt;

let see example of default constructor with default value.&lt;br&gt;&lt;br&gt;

&lt;h2&gt;default constructor with default value&lt;/h2&gt;

&lt;h3&gt;Program&lt;/h3&gt;
&lt;pre&gt;
&lt;code class="java"&gt;
class Car 
{
    int speed;
    String model;
    
    void display()
    {
        System.out.println(model + " " + speed);
    }
}

public class default_value
{
    public static void main(String args[])
    {
        //object creation
        Car swift = new Car();
        swift.display();
        
        Car eco = new Car();
        eco.speed = 500;
        //it will display speed but not model
        eco.display();
    }
}
&lt;/code&gt;  
  &lt;a href="https://onlinegdb.com/B1irfd2lG"&gt;&lt;button class="button"&gt;&lt;span&gt;Run &lt;/span&gt;&lt;/button&gt;&lt;/a&gt;
&lt;/pre&gt;

&lt;h3&gt;Output&lt;/h3&gt;
&lt;pre&gt;
&lt;code class="java"&gt;
null 0
null 500
&lt;/code&gt;  
&lt;/pre&gt;

&lt;h3&gt;Explanation&lt;/h3&gt;
In the above class,you are not creating any constructor so compiler provides you a default constructor.Here 0 and null values are provided by default constructor.In second object we have defined speed of that object so, it will display speed but not model.

&lt;h2&gt;2. Parameterized constructor&lt;/h2&gt;
A constructor that has parameters is known as parameterized constructor. If we want to initialize fields of the class with your own values, then use parameterized constructor.

&lt;h3&gt;Syntax&lt;/h3&gt;
&lt;pre&gt;
&lt;code class="java"&gt;
class_name(parameters...)
{

}
&lt;/code&gt;  
&lt;/pre&gt;
&lt;h3&gt;Program&lt;/h3&gt;
&lt;pre&gt;
&lt;code class="java"&gt;
class Car 
{
    int speed;
    String model;
    
    //parametarized constructor
    Car(int s,String m)
    {
        speed = s;
        model = m;
    }
    
    void display()
    {
        System.out.println(model + " " + speed);
    }
}

public class para_constructor
{
    public static void main(String args[])
    {
        //object creation
        Car swift = new Car(500,"swift");
        swift.display();
    }
}
&lt;/code&gt;  
  &lt;a href="https://onlinegdb.com/HJaaV_heG"&gt;&lt;button class="button"&gt;&lt;span&gt;Run &lt;/span&gt;&lt;/button&gt;&lt;/a&gt;
&lt;/pre&gt;
&lt;h3&gt;Output&lt;/h3&gt;
&lt;pre&gt;
&lt;code class="java"&gt;
swift 500
&lt;/code&gt;  
&lt;/pre&gt;

&lt;h2&gt;Example program with default and parametarized constructor&lt;/h2&gt;
&lt;h3&gt;Program&lt;/h3&gt;
&lt;pre&gt;
&lt;code class="java"&gt;
class Car
{
    Car() 
    {
        System.out.println("default constructor");
    }

    Car(int speed) 
    {
        System.out.println("parametarized constructor");
    }
}

public class para_def
{
    public static void main (String[] args) 
    {
        Car def = new Car();
        Car par = new Car(500);
    }
}
&lt;/code&gt;  
  &lt;a href="https://onlinegdb.com/SyC7Ou2gM"&gt;&lt;button class="button"&gt;&lt;span&gt;Run &lt;/span&gt;&lt;/button&gt;&lt;/a&gt;
&lt;/pre&gt;
&lt;h3&gt;Output&lt;/h3&gt;
&lt;pre&gt;
&lt;code class="java"&gt;
default constructor
parametarized constructor
&lt;/code&gt;  
&lt;/pre&gt;
&lt;h3&gt;Explanation&lt;/h3&gt;
In this example, the class &lt;strong&gt;Car&lt;/strong&gt; has two constructors. The first takes no arguments; it’s known as the default constructor. Default constructors play a special role: if we don’t define any constructors for a class, an empty default constructor is supplied for us. The default constructor is what gets called whenever you create an object by calling its constructor with no arguments. The second constructor takes a int argument. Given the constructors in the previous example, we create two &lt;strong&gt;Car&lt;/strong&gt; objects.&lt;br&gt;&lt;br&gt;

In each case, Java chooses the appropriate constructor at compile time based on the rules for overloaded method selection.&lt;br&gt;&lt;br&gt;

&lt;h2&gt;copy constructor in Java&lt;/h2&gt;

There is no copy constructor in java. But, we can copy the values of one object to another like copy constructor in C++.&lt;br&gt;&lt;br&gt;

There are many ways to copy the values of one object into another in java. They are:&lt;br&gt;
&lt;ol&gt;
&lt;li&gt;By constructor&lt;/li&gt;
&lt;li&gt;By assigning the values of one object into another&lt;/li&gt;
&lt;li&gt;By clone() method of Object class&lt;/li&gt;
&lt;/ol&gt;
In this example, we are going to copy the values of one object into another using java constructor.&lt;br&gt;

&lt;h3&gt;Program&lt;/h3&gt;
&lt;pre&gt;
&lt;code class="java"&gt;
class Car
{
    int speed;
    String model;
    
    Car(int s,String m) 
    {
        speed = s;
        model = m;
    }
    
    //copy constructor
    Car(Car c) 
    {
        speed = c.speed;
        model = c.model;
    }
    
    void display()
    {
        System.out.println(speed + " " + model);
    }
}

public class copy_constructor
{
    public static void main (String[] args) 
    {
        Car c1 = new Car(500,"eco");
        //assigning parameter of c1 to c2
        Car c2 = new Car(c1);
        c1.display();
        c2.display();
    }
}
&lt;/code&gt;  
  &lt;a href="https://onlinegdb.com/rk3Lhungf"&gt;&lt;button class="button"&gt;&lt;span&gt;Run &lt;/span&gt;&lt;/button&gt;&lt;/a&gt;
&lt;/pre&gt;

&lt;h3&gt;Output&lt;/h3&gt;
&lt;pre&gt;
&lt;code class="java"&gt;
500 eco
500 eco
&lt;/code&gt;  
&lt;/pre&gt;

&lt;h2&gt;difference between constructor and method&lt;/h2&gt;
&lt;table&gt;
&lt;tbody&gt;&lt;tr&gt;&lt;th&gt;Java Constructor&lt;/th&gt;&lt;th&gt;Java Method&lt;/th&gt;&lt;/tr&gt;
&lt;tr&gt;&lt;td&gt;Constructor is used to initialize the state of an object.&lt;/td&gt;&lt;td&gt;Method is used to expose behaviour of an object.&lt;/td&gt;&lt;/tr&gt;
&lt;tr&gt;&lt;td&gt;Constructor must not have return type.&lt;/td&gt;&lt;td&gt;Method must have return type.&lt;/td&gt;&lt;/tr&gt;
&lt;tr&gt;&lt;td&gt;Constructor is invoked implicitly.&lt;/td&gt;&lt;td&gt;Method is invoked explicitly.&lt;/td&gt;&lt;/tr&gt;
&lt;tr&gt;&lt;td&gt;The java compiler provides a default constructor if you don't have any constructor.&lt;/td&gt;&lt;td&gt;Method is not provided by compiler in any case.&lt;/td&gt;&lt;/tr&gt;
&lt;tr&gt;&lt;td&gt;Constructor name must be same as the class name.&lt;/td&gt;&lt;td&gt; Method name may or may not be same as class name.&lt;/td&gt;&lt;/tr&gt;
&lt;/tbody&gt;&lt;/table&gt;

&lt;!-- ####################################################################### --&gt;
&lt;/body&gt;
&lt;/html&gt;&lt;/div&gt;
</description><link>http://tangled-java.blogspot.com/2017/11/constructor-in-java.html</link><author>noreply@blogger.com (Anonymous)</author><thr:total>0</thr:total></item><item><guid isPermaLink="false">tag:blogger.com,1999:blog-3082064622906880860.post-2406301109781043393</guid><pubDate>Tue, 28 Nov 2017 19:33:00 +0000</pubDate><atom:updated>2017-11-28T11:38:31.734-08:00</atom:updated><category domain="http://www.blogger.com/atom/ns#">class</category><category domain="http://www.blogger.com/atom/ns#">object</category><title>Class and Objects</title><description>&lt;!DOCTYPE html&gt;
&lt;html&gt;
&lt;head&gt;
 &lt;title&gt;&lt;/title&gt;
 &lt;link rel="stylesheet" type="text/css" href="myblog.css"&gt;
&lt;script type="text/javascript"&gt;
 /*! highlight.js v9.12.0 | BSD3 License | git.io/hljslicense */
!function(e){var n="object"==typeof window&amp;&amp;window||"object"==typeof self&amp;&amp;self;"undefined"!=typeof exports?e(exports):n&amp;&amp;(n.hljs=e({}),"function"==typeof define&amp;&amp;define.amd&amp;&amp;define([],function(){return n.hljs}))}(function(e){function n(e){return e.replace(/&amp;/g,"&amp;amp;").replace(/&lt;/g,"&amp;lt;").replace(/&gt;/g,"&amp;gt;")}function t(e){return e.nodeName.toLowerCase()}function r(e,n){var t=e&amp;&amp;e.exec(n);return t&amp;&amp;0===t.index}function a(e){return k.test(e)}function i(e){var n,t,r,i,o=e.className+" ";if(o+=e.parentNode?e.parentNode.className:"",t=B.exec(o))return w(t[1])?t[1]:"no-highlight";for(o=o.split(/\s+/),n=0,r=o.length;r&gt;n;n++)if(i=o[n],a(i)||w(i))return i}function o(e){var n,t={},r=Array.prototype.slice.call(arguments,1);for(n in e)t[n]=e[n];return r.forEach(function(e){for(n in e)t[n]=e[n]}),t}function u(e){var n=[];return function r(e,a){for(var i=e.firstChild;i;i=i.nextSibling)3===i.nodeType?a+=i.nodeValue.length:1===i.nodeType&amp;&amp;(n.push({event:"start",offset:a,node:i}),a=r(i,a),t(i).match(/br|hr|img|input/)||n.push({event:"stop",offset:a,node:i}));return a}(e,0),n}function c(e,r,a){function i(){return e.length&amp;&amp;r.length?e[0].offset!==r[0].offset?e[0].offset&lt;r[0].offset?e:r:"start"===r[0].event?e:r:e.length?e:r}function o(e){function r(e){return" "+e.nodeName+'="'+n(e.value).replace('"',"&amp;quot;")+'"'}s+="&lt;"+t(e)+E.map.call(e.attributes,r).join("")+"&gt;"}function u(e){s+="&lt;/"+t(e)+"&gt;"}function c(e){("start"===e.event?o:u)(e.node)}for(var l=0,s="",f=[];e.length||r.length;){var g=i();if(s+=n(a.substring(l,g[0].offset)),l=g[0].offset,g===e){f.reverse().forEach(u);do c(g.splice(0,1)[0]),g=i();while(g===e&amp;&amp;g.length&amp;&amp;g[0].offset===l);f.reverse().forEach(o)}else"start"===g[0].event?f.push(g[0].node):f.pop(),c(g.splice(0,1)[0])}return s+n(a.substr(l))}function l(e){return e.v&amp;&amp;!e.cached_variants&amp;&amp;(e.cached_variants=e.v.map(function(n){return o(e,{v:null},n)})),e.cached_variants||e.eW&amp;&amp;[o(e)]||[e]}function s(e){function n(e){return e&amp;&amp;e.source||e}function t(t,r){return new RegExp(n(t),"m"+(e.cI?"i":"")+(r?"g":""))}function r(a,i){if(!a.compiled){if(a.compiled=!0,a.k=a.k||a.bK,a.k){var o={},u=function(n,t){e.cI&amp;&amp;(t=t.toLowerCase()),t.split(" ").forEach(function(e){var t=e.split("|");o[t[0]]=[n,t[1]?Number(t[1]):1]})};"string"==typeof a.k?u("keyword",a.k):x(a.k).forEach(function(e){u(e,a.k[e])}),a.k=o}a.lR=t(a.l||/\w+/,!0),i&amp;&amp;(a.bK&amp;&amp;(a.b="\\b("+a.bK.split(" ").join("|")+")\\b"),a.b||(a.b=/\B|\b/),a.bR=t(a.b),a.e||a.eW||(a.e=/\B|\b/),a.e&amp;&amp;(a.eR=t(a.e)),a.tE=n(a.e)||"",a.eW&amp;&amp;i.tE&amp;&amp;(a.tE+=(a.e?"|":"")+i.tE)),a.i&amp;&amp;(a.iR=t(a.i)),null==a.r&amp;&amp;(a.r=1),a.c||(a.c=[]),a.c=Array.prototype.concat.apply([],a.c.map(function(e){return l("self"===e?a:e)})),a.c.forEach(function(e){r(e,a)}),a.starts&amp;&amp;r(a.starts,i);var c=a.c.map(function(e){return e.bK?"\\.?("+e.b+")\\.?":e.b}).concat([a.tE,a.i]).map(n).filter(Boolean);a.t=c.length?t(c.join("|"),!0):{exec:function(){return null}}}}r(e)}function f(e,t,a,i){function o(e,n){var t,a;for(t=0,a=n.c.length;a&gt;t;t++)if(r(n.c[t].bR,e))return n.c[t]}function u(e,n){if(r(e.eR,n)){for(;e.endsParent&amp;&amp;e.parent;)e=e.parent;return e}return e.eW?u(e.parent,n):void 0}function c(e,n){return!a&amp;&amp;r(n.iR,e)}function l(e,n){var t=N.cI?n[0].toLowerCase():n[0];return e.k.hasOwnProperty(t)&amp;&amp;e.k[t]}function p(e,n,t,r){var a=r?"":I.classPrefix,i='&lt;span class="'+a,o=t?"":C;return i+=e+'"&gt;',i+n+o}function h(){var e,t,r,a;if(!E.k)return n(k);for(a="",t=0,E.lR.lastIndex=0,r=E.lR.exec(k);r;)a+=n(k.substring(t,r.index)),e=l(E,r),e?(B+=e[1],a+=p(e[0],n(r[0]))):a+=n(r[0]),t=E.lR.lastIndex,r=E.lR.exec(k);return a+n(k.substr(t))}function d(){var e="string"==typeof E.sL;if(e&amp;&amp;!y[E.sL])return n(k);var t=e?f(E.sL,k,!0,x[E.sL]):g(k,E.sL.length?E.sL:void 0);return E.r&gt;0&amp;&amp;(B+=t.r),e&amp;&amp;(x[E.sL]=t.top),p(t.language,t.value,!1,!0)}function b(){L+=null!=E.sL?d():h(),k=""}function v(e){L+=e.cN?p(e.cN,"",!0):"",E=Object.create(e,{parent:{value:E}})}function m(e,n){if(k+=e,null==n)return b(),0;var t=o(n,E);if(t)return t.skip?k+=n:(t.eB&amp;&amp;(k+=n),b(),t.rB||t.eB||(k=n)),v(t,n),t.rB?0:n.length;var r=u(E,n);if(r){var a=E;a.skip?k+=n:(a.rE||a.eE||(k+=n),b(),a.eE&amp;&amp;(k=n));do E.cN&amp;&amp;(L+=C),E.skip||(B+=E.r),E=E.parent;while(E!==r.parent);return r.starts&amp;&amp;v(r.starts,""),a.rE?0:n.length}if(c(n,E))throw new Error('Illegal lexeme "'+n+'" for mode "'+(E.cN||"&lt;unnamed&gt;")+'"');return k+=n,n.length||1}var N=w(e);if(!N)throw new Error('Unknown language: "'+e+'"');s(N);var R,E=i||N,x={},L="";for(R=E;R!==N;R=R.parent)R.cN&amp;&amp;(L=p(R.cN,"",!0)+L);var k="",B=0;try{for(var M,j,O=0;;){if(E.t.lastIndex=O,M=E.t.exec(t),!M)break;j=m(t.substring(O,M.index),M[0]),O=M.index+j}for(m(t.substr(O)),R=E;R.parent;R=R.parent)R.cN&amp;&amp;(L+=C);return{r:B,value:L,language:e,top:E}}catch(T){if(T.message&amp;&amp;-1!==T.message.indexOf("Illegal"))return{r:0,value:n(t)};throw T}}function g(e,t){t=t||I.languages||x(y);var r={r:0,value:n(e)},a=r;return t.filter(w).forEach(function(n){var t=f(n,e,!1);t.language=n,t.r&gt;a.r&amp;&amp;(a=t),t.r&gt;r.r&amp;&amp;(a=r,r=t)}),a.language&amp;&amp;(r.second_best=a),r}function p(e){return I.tabReplace||I.useBR?e.replace(M,function(e,n){return I.useBR&amp;&amp;"\n"===e?"&lt;br&gt;":I.tabReplace?n.replace(/\t/g,I.tabReplace):""}):e}function h(e,n,t){var r=n?L[n]:t,a=[e.trim()];return e.match(/\bhljs\b/)||a.push("hljs"),-1===e.indexOf(r)&amp;&amp;a.push(r),a.join(" ").trim()}function d(e){var n,t,r,o,l,s=i(e);a(s)||(I.useBR?(n=document.createElementNS("http://www.w3.org/1999/xhtml","div"),n.innerHTML=e.innerHTML.replace(/\n/g,"").replace(/&lt;br[ \/]*&gt;/g,"\n")):n=e,l=n.textContent,r=s?f(s,l,!0):g(l),t=u(n),t.length&amp;&amp;(o=document.createElementNS("http://www.w3.org/1999/xhtml","div"),o.innerHTML=r.value,r.value=c(t,u(o),l)),r.value=p(r.value),e.innerHTML=r.value,e.className=h(e.className,s,r.language),e.result={language:r.language,re:r.r},r.second_best&amp;&amp;(e.second_best={language:r.second_best.language,re:r.second_best.r}))}function b(e){I=o(I,e)}function v(){if(!v.called){v.called=!0;var e=document.querySelectorAll("pre code");E.forEach.call(e,d)}}function m(){addEventListener("DOMContentLoaded",v,!1),addEventListener("load",v,!1)}function N(n,t){var r=y[n]=t(e);r.aliases&amp;&amp;r.aliases.forEach(function(e){L[e]=n})}function R(){return x(y)}function w(e){return e=(e||"").toLowerCase(),y[e]||y[L[e]]}var E=[],x=Object.keys,y={},L={},k=/^(no-?highlight|plain|text)$/i,B=/\blang(?:uage)?-([\w-]+)\b/i,M=/((^(&lt;[^&gt;]+&gt;|\t|)+|(?:\n)))/gm,C="&lt;/span&gt;",I={classPrefix:"hljs-",tabReplace:null,useBR:!1,languages:void 0};return e.highlight=f,e.highlightAuto=g,e.fixMarkup=p,e.highlightBlock=d,e.configure=b,e.initHighlighting=v,e.initHighlightingOnLoad=m,e.registerLanguage=N,e.listLanguages=R,e.getLanguage=w,e.inherit=o,e.IR="[a-zA-Z]\\w*",e.UIR="[a-zA-Z_]\\w*",e.NR="\\b\\d+(\\.\\d+)?",e.CNR="(-?)(\\b0[xX][a-fA-F0-9]+|(\\b\\d+(\\.\\d*)?|\\.\\d+)([eE][-+]?\\d+)?)",e.BNR="\\b(0b[01]+)",e.RSR="!|!=|!==|%|%=|&amp;|&amp;&amp;|&amp;=|\\*|\\*=|\\+|\\+=|,|-|-=|/=|/|:|;|&lt;&lt;|&lt;&lt;=|&lt;=|&lt;|===|==|=|&gt;&gt;&gt;=|&gt;&gt;=|&gt;=|&gt;&gt;&gt;|&gt;&gt;|&gt;|\\?|\\[|\\{|\\(|\\^|\\^=|\\||\\|=|\\|\\||~",e.BE={b:"\\\\[\\s\\S]",r:0},e.ASM={cN:"string",b:"'",e:"'",i:"\\n",c:[e.BE]},e.QSM={cN:"string",b:'"',e:'"',i:"\\n",c:[e.BE]},e.PWM={b:/\b(a|an|the|are|I'm|isn't|don't|doesn't|won't|but|just|should|pretty|simply|enough|gonna|going|wtf|so|such|will|you|your|they|like|more)\b/},e.C=function(n,t,r){var a=e.inherit({cN:"comment",b:n,e:t,c:[]},r||{});return a.c.push(e.PWM),a.c.push({cN:"doctag",b:"(?:TODO|FIXME|NOTE|BUG|XXX):",r:0}),a},e.CLCM=e.C("//","$"),e.CBCM=e.C("/\\*","\\*/"),e.HCM=e.C("#","$"),e.NM={cN:"number",b:e.NR,r:0},e.CNM={cN:"number",b:e.CNR,r:0},e.BNM={cN:"number",b:e.BNR,r:0},e.CSSNM={cN:"number",b:e.NR+"(%|em|ex|ch|rem|vw|vh|vmin|vmax|cm|mm|in|pt|pc|px|deg|grad|rad|turn|s|ms|Hz|kHz|dpi|dpcm|dppx)?",r:0},e.RM={cN:"regexp",b:/\//,e:/\/[gimuy]*/,i:/\n/,c:[e.BE,{b:/\[/,e:/\]/,r:0,c:[e.BE]}]},e.TM={cN:"title",b:e.IR,r:0},e.UTM={cN:"title",b:e.UIR,r:0},e.METHOD_GUARD={b:"\\.\\s*"+e.UIR,r:0},e});hljs.registerLanguage("java",function(e){var a="[À-ʸa-zA-Z_$][À-ʸa-zA-Z_$0-9]*",t=a+"(&lt;"+a+"(\\s*,\\s*"+a+")*&gt;)?",r="false synchronized int abstract float private char boolean static null if const for true while long strictfp finally protected import native final void enum else break transient catch instanceof byte super volatile case assert short package default double public try this switch continue throws protected public private module requires exports do",s="\\b(0[bB]([01]+[01_]+[01]+|[01]+)|0[xX]([a-fA-F0-9]+[a-fA-F0-9_]+[a-fA-F0-9]+|[a-fA-F0-9]+)|(([\\d]+[\\d_]+[\\d]+|[\\d]+)(\\.([\\d]+[\\d_]+[\\d]+|[\\d]+))?|\\.([\\d]+[\\d_]+[\\d]+|[\\d]+))([eE][-+]?\\d+)?)[lLfF]?",c={cN:"number",b:s,r:0};return{aliases:["jsp"],k:r,i:/&lt;\/|#/,c:[e.C("/\\*\\*","\\*/",{r:0,c:[{b:/\w+@/,r:0},{cN:"doctag",b:"@[A-Za-z]+"}]}),e.CLCM,e.CBCM,e.ASM,e.QSM,{cN:"class",bK:"class interface",e:/[{;=]/,eE:!0,k:"class interface",i:/[:"\[\]]/,c:[{bK:"extends implements"},e.UTM]},{bK:"new throw return else",r:0},{cN:"function",b:"("+t+"\\s+)+"+e.UIR+"\\s*\\(",rB:!0,e:/[{;=]/,eE:!0,k:r,c:[{b:e.UIR+"\\s*\\(",rB:!0,r:0,c:[e.UTM]},{cN:"params",b:/\(/,e:/\)/,k:r,r:0,c:[e.ASM,e.QSM,e.CNM,e.CBCM]},e.CLCM,e.CBCM]},c,{cN:"meta",b:"@[A-Za-z]+"}]}});
&lt;/script&gt;
&lt;script&gt;hljs.initHighlightingOnLoad();&lt;/script&gt;
&lt;/head&gt;
&lt;body onload='selectjava()'&gt;
&lt;!-- ####################################################################### --&gt;

From this article we are starting to do object oriented programing in Java.&lt;br&gt;

In object-oriented programming technique, we design a program using objects and classes.Object is the physical as well as logical entity whereas class is the logical entity only.&lt;br&gt;&lt;br&gt;

&lt;h2&gt;Objects in Java&lt;/h2&gt;

An entity that has state and behavior is known as an object e.g. chair, bike, marker, pen, table, car etc. It can be physical or logical.t is a basic unit of Object Oriented Programming and represents the real life entities.A typical Java program creates many objects, which interact by invoking methods. An object consist of : &lt;br&gt;&lt;br&gt;

1. &lt;strong&gt;State&lt;/strong&gt; : It is represented by attributes of an object. It also reflect the properties of an object.&lt;br&gt;&lt;br&gt;
2. &lt;strong&gt;Behavior&lt;/strong&gt; : It is represented by methods of an object. It also reflects the response of an object with other objects.&lt;br&gt;&lt;br&gt;
3. &lt;strong&gt;Identity&lt;/strong&gt; : It gives a unique name to an object and enables one object to interact with other objects.&lt;br&gt;&lt;br&gt;

If you compare the software object with a real-world object, they have very similar characteristics.
Software objects also have a state and a behavior. A software object's state is stored in fields and behavior is shown via methods.So in software development, methods operate on the internal state of an object and the object-to-object communication is done via methods.&lt;br&gt;&lt;br&gt;

For Example: Pen is an object. Its name is Reynolds, color is white etc. known as its state. It is used to write, so writing is its behavior.&lt;br&gt;&lt;br&gt;

&lt;h2&gt;Declaring objects&lt;/h2&gt;

When an object of a class is created, the class is said to be instantiated. All the instances share the attributes and the behavior of the class. But the values of those attributes, i.e. the state are unique for each object. A single class may have any number of instances.Object is an instance of a class. Class is a template or blueprint from which objects are created. So object is the instance(result) of a class.&lt;br&gt;&lt;br&gt;

&lt;h3&gt;Syntax for declaring object&lt;/h3&gt;
&lt;pre&gt;
&lt;code class="java"&gt;
 Person somebody;
&lt;/code&gt;  
&lt;/pre&gt;

As we declare variables like (type name;). This notifies the compiler that we will use name to refer to data whose type is type. With a primitive variable, this declaration also reserves the proper amount of memory for the variable. So for reference variable, type must be strictly a concrete class name. &lt;br&gt;&lt;br&gt;

&lt;h2&gt;Class in Java&lt;/h2&gt;

A class is a user defined blueprint or prototype from which objects are created.  It represents the set of properties or methods that are common to all objects of one type.A class in Java can contain: &lt;br&gt;&lt;br&gt;
&lt;ol&gt;
&lt;li&gt;fields&lt;/li&gt;
&lt;li&gt;methods&lt;/li&gt;
&lt;li&gt;constructors&lt;/li&gt;
&lt;li&gt;blocks&lt;/li&gt;
&lt;li&gt;nested class and interface&lt;/li&gt;
&lt;/ol&gt;

Constructors are used for initializing new objects. Fields are variables that provides the state of the class and its objects, and methods are used to implement the behavior of the class and its objects.There are various types of classes that are used in real time applications such as nested classes, anonymous classes, lambda expressions. &lt;br&gt;

&lt;h3&gt;Syntax for declaring class&lt;/h3&gt;
&lt;pre&gt;
&lt;code class="java"&gt;
class &lt;class_name&gt;{  
    field;  
    method;  
}  
&lt;/code&gt;  
&lt;/pre&gt;

A class can contain any of the following variable types.&lt;br&gt;&lt;br&gt;

&lt;strong&gt;Local variables&lt;/strong&gt; − Variables defined inside methods, constructors or blocks are called local variables. The variable will be declared and initialized within the method and the variable will be destroyed when the method has completed.&lt;br&gt;&lt;br&gt;

&lt;strong&gt;Instance variables&lt;/strong&gt; − Instance variables are variables within a class but outside any method. These variables are initialized when the class is instantiated. Instance variables can be accessed from inside any method, constructor or blocks of that particular class.&lt;br&gt;&lt;br&gt;

&lt;strong&gt;Class variables&lt;/strong&gt; − Class variables are variables declared within a class, outside any method, with the static keyword.&lt;br&gt;&lt;br&gt;

A variable which is created inside the class but outside the method, is known as &lt;strong&gt;instance variable&lt;/strong&gt;. Instance variable doesn't get memory at compile time. It gets memory at run time when object(instance) is created. That is why, it is known as &lt;strong&gt;instance variable&lt;/strong&gt;.&lt;br&gt;

&lt;h2&gt;Creating an object&lt;/h2&gt;

As mentioned previously, a class provides the blueprints for objects. So basically, an object is created from a class. In Java, the new keyword is used to create new objects.There are three steps when creating an object from a class − &lt;br&gt;

&lt;strong&gt;Declaration&lt;/strong&gt; − A variable declaration with a variable name with an object type.As we shown above
&lt;pre&gt;
&lt;code class="java"&gt;
Person somebody;
&lt;/code&gt;  
&lt;/pre&gt;
&lt;strong&gt;Instantiation&lt;/strong&gt; − The 'new' keyword is used to create the object.
&lt;pre&gt;
&lt;code class="java"&gt;
new Person();
&lt;/code&gt;  
&lt;/pre&gt;
&lt;strong&gt;Initialization&lt;/strong&gt; − The 'new' keyword is followed by a call to a constructor. This call initializes the new object.
&lt;pre&gt;
&lt;code class="java"&gt;
Person Hansraj = new Person(); 
&lt;/code&gt;  
&lt;/pre&gt;

&lt;h2&gt;Object and class example&lt;/h2&gt;

&lt;h3&gt;Program&lt;/h3&gt;
&lt;pre&gt;
&lt;code class="java"&gt;
//declaring class
class Employee
{
    int emp_id;
    String name;
}

public class Main
{
    public static void main(String args[])
    {
        //make instance of Employee class through refrence
        Employee e1 = new Employee();
        e1.emp_id = 1234;
        e1.name = "Raj";
        System.out.println(e1.name + " \'s employee id is " +  e1.emp_id);
    }
}
&lt;/code&gt;  
  &lt;a href="https://onlinegdb.com/ry2IIEogM"&gt;&lt;button class="button"&gt;&lt;span&gt;Run &lt;/span&gt;&lt;/button&gt;&lt;/a&gt;
&lt;/pre&gt;

&lt;h3&gt;Output&lt;/h3&gt;
&lt;pre&gt;
&lt;code class="java"&gt;
Raj's employee id is 1234
&lt;/code&gt;  
&lt;/pre&gt;

&lt;h3&gt;Explanation&lt;/h3&gt;
Here, &lt;strong&gt;Employee&lt;/strong&gt; is a class name. It has two properties &lt;strong&gt;emp_id&lt;/strong&gt; and &lt;strong&gt;name&lt;/strong&gt;. &lt;strong&gt;e1&lt;/strong&gt; is a reference for object of class &lt;strong&gt;Employee&lt;/strong&gt;.

&lt;!-- ####################################################################### --&gt;
&lt;/body&gt;
&lt;/html&gt;</description><link>http://tangled-java.blogspot.com/2017/11/class-and-objects.html</link><author>noreply@blogger.com (Anonymous)</author><thr:total>0</thr:total></item><item><guid isPermaLink="false">tag:blogger.com,1999:blog-3082064622906880860.post-8196357278902317091</guid><pubDate>Mon, 27 Nov 2017 09:43:00 +0000</pubDate><atom:updated>2017-11-27T02:34:47.733-08:00</atom:updated><category domain="http://www.blogger.com/atom/ns#">abstraction</category><category domain="http://www.blogger.com/atom/ns#">aggregation</category><category domain="http://www.blogger.com/atom/ns#">association</category><category domain="http://www.blogger.com/atom/ns#">composition</category><category domain="http://www.blogger.com/atom/ns#">encapsulation</category><category domain="http://www.blogger.com/atom/ns#">inheritance</category><category domain="http://www.blogger.com/atom/ns#">oops</category><category domain="http://www.blogger.com/atom/ns#">oops concept</category><category domain="http://www.blogger.com/atom/ns#">polymorphism</category><title>OOPs concepts</title><description>&lt;body onload='selectjava()'&gt;
&lt;div dir="ltr" style="text-align: left;" trbidi="on"&gt;
In this article we will learn about OOP ( Object oriented programing ) concepts. If you want to learn further lessons about objects, classes, inheritance, polymorphism, how objects interact with each other then you must read these lesson carefully.&lt;br /&gt;
&lt;div&gt;
&lt;br /&gt;&lt;/div&gt;
&lt;div&gt;
There are total 7 core OOPs concepts.&lt;/div&gt;
&lt;h2 style="text-align: left;"&gt;
&amp;nbsp;1. Abstraction&amp;nbsp;&lt;/h2&gt;
&lt;div&gt;
&lt;div&gt;
Abstraction is the concept of hiding the internal details and describing things in simple terms. For example, a method that adds two integers. The method internal processing is hidden from outer world. There are many ways to achieve abstraction in object oriented programming, such as encapsulation and inheritance.&lt;/div&gt;
&lt;div&gt;
&lt;br /&gt;&lt;/div&gt;
&lt;div&gt;
A java program is also a great example of abstraction. Here java takes care of converting simple statements to machine language and hides the inner implementation details from outer world.&lt;/div&gt;
&lt;/div&gt;
&lt;h2 style="text-align: left;"&gt;
&amp;nbsp;2. Encapsulation&lt;/h2&gt;
&lt;div&gt;
&lt;div&gt;
Encapsulation is the technique used to implement abstraction in object oriented programming. Encapsulation is used for access restriction to a class members and methods.&lt;/div&gt;
&lt;div&gt;
&lt;br /&gt;&lt;/div&gt;
&lt;div&gt;
Access modifier keywords are used for encapsulation in object oriented programming. For example, encapsulation in java is achieved using&lt;b&gt; private&lt;/b&gt;, &lt;b&gt;protected&lt;/b&gt; and &lt;b&gt;public&lt;/b&gt; keywords.&lt;/div&gt;
&lt;/div&gt;
&lt;h2 style="text-align: left;"&gt;
&amp;nbsp;3.&amp;nbsp; Inheritance&amp;nbsp;&lt;/h2&gt;
&lt;div class="separator" style="clear: both; text-align: center;"&gt;
&lt;a href="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEggp9fby8TQtMGpdzWWZ7JtxSRuzmyE4s8QvF5hjkW6Rd1Up68sDamnZTnvEcrbxQU6t7AKVJFFDTR9TxZHY8GOJU4AD782_9S5C5IVwXDVeXCCb7DfBBUHqGMvPltfGFIVzHSt0u9Lib8/s1600/subclass-superclass.png" imageanchor="1" style="margin-left: 1em; margin-right: 1em;"&gt;&lt;img border="0" data-original-height="223" data-original-width="552" height="161" src="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEggp9fby8TQtMGpdzWWZ7JtxSRuzmyE4s8QvF5hjkW6Rd1Up68sDamnZTnvEcrbxQU6t7AKVJFFDTR9TxZHY8GOJU4AD782_9S5C5IVwXDVeXCCb7DfBBUHqGMvPltfGFIVzHSt0u9Lib8/s400/subclass-superclass.png" width="400" /&gt;&lt;/a&gt;&lt;/div&gt;
&lt;div class="separator" style="clear: both; text-align: center;"&gt;
&lt;/div&gt;
&lt;div class="separator" style="clear: both; text-align: center;"&gt;
&lt;/div&gt;
&lt;div&gt;
&lt;br /&gt;&lt;/div&gt;
&lt;div&gt;
&lt;div&gt;
Inheritance is the object oriented programming concept where an object is based on another object. Inheritance is the mechanism of code reuse. The object that is getting inherited is called superclass and the object that inherits the superclass is called subclass.&lt;/div&gt;
&lt;div&gt;
&lt;br /&gt;&lt;/div&gt;
&lt;div&gt;
We use &lt;b&gt;extends&lt;/b&gt; keyword in java to implement inheritance.&amp;nbsp;&lt;/div&gt;
&lt;/div&gt;
&lt;h2 style="text-align: left;"&gt;
&amp;nbsp;4. Polymorphism&amp;nbsp;&lt;/h2&gt;
&lt;div class="separator" style="clear: both; text-align: center;"&gt;
&lt;a href="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEgVBanAep7zN4OnIllvnGY65cpJnmhjw74c77nEMdLWvQniRRSZyCTbzc4a_zuYUWpNs4Rop7D4k6TSDUXBgWvDqvjnnNyTNJX9AtHr6I7-EKFjWJBiX9KTuFA2zc2V-y-Id0gGL4w873Y/s1600/Polymorphism.png" imageanchor="1" style="margin-left: 1em; margin-right: 1em;"&gt;&lt;img border="0" data-original-height="194" data-original-width="399" height="192" src="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEgVBanAep7zN4OnIllvnGY65cpJnmhjw74c77nEMdLWvQniRRSZyCTbzc4a_zuYUWpNs4Rop7D4k6TSDUXBgWvDqvjnnNyTNJX9AtHr6I7-EKFjWJBiX9KTuFA2zc2V-y-Id0gGL4w873Y/s400/Polymorphism.png" width="400" /&gt;&lt;/a&gt;&lt;/div&gt;
&lt;div&gt;
&lt;br /&gt;&lt;/div&gt;
&lt;div&gt;
&lt;div&gt;
Polymorphism is the concept where an object behaves differently in different situations. There are two types of polymorphism – compile time polymorphism and runtime polymorphism.&lt;/div&gt;
&lt;div&gt;
&lt;br /&gt;&lt;/div&gt;
&lt;div&gt;
Compile time polymorphism is achieved by method overloading.&lt;/div&gt;
&lt;/div&gt;
&lt;div&gt;
&lt;br /&gt;&lt;/div&gt;
&lt;div&gt;
Runtime polymorphism is implemented when we have “IS-A” relationship between objects. This is also called as method overriding because subclass has to override the superclass method for runtime polymorphism. If we are working in terms of superclass, the actual implementation class is decided at runtime. Compiler is not able to decide which class method will be invoked. This decision is done at runtime, hence the name as runtime polymorphism or dynamic method dispatch.&lt;/div&gt;
&lt;h2 style="text-align: left;"&gt;
&amp;nbsp;5. Association&amp;nbsp;&lt;/h2&gt;
&lt;div class="separator" style="clear: both; text-align: center;"&gt;
&lt;a href="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEgvG0JtCgNX0d1_nTpAD5NzffvRgs8eblioPI1q76-aOLavoKihRoosF3Hulkk1IRzlShl9-S1y7VJzxcF50yqXuu-QEMlV3cPSAq23aFKMTzrdCXG-GYAA3wOHscwlXQdynwx46n5lieQ/s1600/Association.png" imageanchor="1" style="margin-left: 1em; margin-right: 1em;"&gt;&lt;img border="0" data-original-height="197" data-original-width="594" height="132" src="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEgvG0JtCgNX0d1_nTpAD5NzffvRgs8eblioPI1q76-aOLavoKihRoosF3Hulkk1IRzlShl9-S1y7VJzxcF50yqXuu-QEMlV3cPSAq23aFKMTzrdCXG-GYAA3wOHscwlXQdynwx46n5lieQ/s400/Association.png" width="400" /&gt;&lt;/a&gt;&lt;/div&gt;
&lt;div&gt;
&lt;br /&gt;&lt;/div&gt;
&lt;div&gt;
Association is the OOPS concept to define the relationship between objects. Association defines the multiplicity between objects. For example Teacher and Student objects. There is one to many relationship between a teacher and students. Similarly a student can have one to many relationship with teacher objects. However both student and teacher objects are independent of each other.&lt;/div&gt;
&lt;h2 style="text-align: left;"&gt;
&amp;nbsp;6. Aggregation&amp;nbsp;&lt;/h2&gt;
&lt;div class="separator" style="clear: both; text-align: center;"&gt;
&lt;a href="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEjVmjkoEYfMJO04Ia-NIfY6QFsQWndmCrpYfkhmbv80_LWuc-6dB9Ks4Ff1LMnzMVB1IDOSQjhyphenhyphenHUBH_R4enMTTadZwmtU3LAX_VrFI2283Mf24T8Ge8ZACL1pYSo9Rr1Gk8F7ys9woT7c/s1600/Aggregation.png" imageanchor="1" style="margin-left: 1em; margin-right: 1em;"&gt;&lt;img border="0" data-original-height="330" data-original-width="603" height="218" src="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEjVmjkoEYfMJO04Ia-NIfY6QFsQWndmCrpYfkhmbv80_LWuc-6dB9Ks4Ff1LMnzMVB1IDOSQjhyphenhyphenHUBH_R4enMTTadZwmtU3LAX_VrFI2283Mf24T8Ge8ZACL1pYSo9Rr1Gk8F7ys9woT7c/s400/Aggregation.png" width="400" /&gt;&lt;/a&gt;&lt;/div&gt;
&lt;div&gt;
&lt;br /&gt;&lt;/div&gt;
&lt;div&gt;
Aggregation is a special type of association. In aggregation, objects have their own life cycle but there is an ownership. Whenever we have “HAS-A” relationship between objects and ownership then it’s a case of aggregation.&lt;/div&gt;
&lt;div&gt;
&lt;br /&gt;&lt;/div&gt;
&lt;div&gt;
For example consider two classes Student class and Address class. Every student has an address so the relationship between student and address is a Has-A relationship. But if you consider its vice versa then it would not make any sense as an Address doesn’t need to have a Student necessarily.&amp;nbsp;&lt;/div&gt;
&lt;h2&gt;
&amp;nbsp;7. Composition&amp;nbsp;&lt;/h2&gt;
&lt;div class="separator" style="clear: both; text-align: center;"&gt;
&lt;a href="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEhCWhA1FEZ14SWAGods6SouM_OyeFiRatQsXMeY3B9tFge3utHh4dPwmzj_Q_QJzSnCP8aRzn1WvGAEN83F2bgujPLB-gFQ6XXGc5n5zmboXzcK6qWPxMHXkk58094esq7NT8YCDHQdQqo/s1600/Composition.png" imageanchor="1" style="margin-left: 1em; margin-right: 1em;"&gt;&lt;img border="0" data-original-height="244" data-original-width="731" height="132" src="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEhCWhA1FEZ14SWAGods6SouM_OyeFiRatQsXMeY3B9tFge3utHh4dPwmzj_Q_QJzSnCP8aRzn1WvGAEN83F2bgujPLB-gFQ6XXGc5n5zmboXzcK6qWPxMHXkk58094esq7NT8YCDHQdQqo/s400/Composition.png" width="400" /&gt;&lt;/a&gt;&lt;/div&gt;
&lt;div&gt;
&lt;br /&gt;&lt;/div&gt;
&lt;div&gt;
Composition is a special case of aggregation. Composition is a more restrictive form of aggregation. When the contained object in “HAS-A” relationship can’t exist on it’s own, then it’s a case of composition. For example, House has-a Room. Here room can’t exist without house.&lt;/div&gt;
&lt;/div&gt;
</description><link>http://tangled-java.blogspot.com/2017/11/oops-concepts.html</link><author>noreply@blogger.com (Anonymous)</author><media:thumbnail xmlns:media="http://search.yahoo.com/mrss/" height="72" url="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEggp9fby8TQtMGpdzWWZ7JtxSRuzmyE4s8QvF5hjkW6Rd1Up68sDamnZTnvEcrbxQU6t7AKVJFFDTR9TxZHY8GOJU4AD782_9S5C5IVwXDVeXCCb7DfBBUHqGMvPltfGFIVzHSt0u9Lib8/s72-c/subclass-superclass.png" width="72"/><thr:total>0</thr:total></item><item><guid isPermaLink="false">tag:blogger.com,1999:blog-3082064622906880860.post-487342324403242040</guid><pubDate>Mon, 27 Nov 2017 08:06:00 +0000</pubDate><atom:updated>2017-11-27T00:06:36.966-08:00</atom:updated><category domain="http://www.blogger.com/atom/ns#">setup java</category><title>Setup JAVA in your PC</title><description>&lt;body onload='selectjava()'&gt;
&lt;div dir="ltr" style="text-align: left;" trbidi="on"&gt;
&lt;br /&gt;
&lt;div class="MsoListParagraphCxSpFirst" style="mso-list: l0 level1 lfo1; text-indent: -18.0pt;"&gt;
&lt;!--[if !supportLists]--&gt;1.&lt;span style="font-size: 7pt; font-stretch: normal; font-variant-numeric: normal; line-height: normal;"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;
&lt;/span&gt;&lt;!--[endif]--&gt;Download JDK from &lt;a href="http://www.oracle.com/technetwork/java/javase/downloads/index.html"&gt;http://www.oracle.com/technetwork/java/javase/downloads/index.html&lt;/a&gt;&lt;br /&gt;
&lt;br /&gt;&lt;/div&gt;
&lt;div class="separator" style="clear: both; text-align: center;"&gt;
&lt;a href="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEh7vjXRvw1YqswggIzF5cXoCW1H55Nf0Wn7X8ozSxW2Jvalm3i6Xn4zLsdiL5Bme-_kWhNmOTiaojVh5FkD02LulmnaurGRCeoCX857wv8ucO_tz2V9euBT8dhEQDMvLXknL-TwcxtVnj0/s1600/Screenshot+%2528261%2529.png" imageanchor="1"&gt;&lt;img border="0" data-original-height="768" data-original-width="1366" height="359" src="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEh7vjXRvw1YqswggIzF5cXoCW1H55Nf0Wn7X8ozSxW2Jvalm3i6Xn4zLsdiL5Bme-_kWhNmOTiaojVh5FkD02LulmnaurGRCeoCX857wv8ucO_tz2V9euBT8dhEQDMvLXknL-TwcxtVnj0/s1600/Screenshot+%2528261%2529.png" width="640" /&gt;&lt;/a&gt;&lt;/div&gt;
&lt;div class="MsoListParagraphCxSpFirst" style="mso-list: l0 level1 lfo1; text-indent: -18.0pt;"&gt;
&lt;br /&gt;&lt;/div&gt;
&lt;div class="separator" style="clear: both; text-align: center;"&gt;
&lt;/div&gt;
&lt;div class="separator" style="clear: both; text-align: center;"&gt;
&lt;/div&gt;
&lt;div class="MsoListParagraphCxSpFirst" style="mso-list: l0 level1 lfo1; text-indent: -18.0pt;"&gt;
&lt;o:p&gt;&lt;/o:p&gt;&lt;!--[if !supportLists]--&gt;2.&lt;span style="font-size: 7pt; font-stretch: normal; font-variant-numeric: normal; line-height: normal;"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;
&lt;/span&gt;&lt;!--[endif]--&gt;Install the JDK.&lt;o:p&gt;&lt;/o:p&gt;&lt;br /&gt;
&lt;br /&gt;&lt;/div&gt;
&lt;div class="MsoListParagraphCxSpMiddle" style="mso-list: l0 level1 lfo1; text-indent: -18.0pt;"&gt;
&lt;!--[if !supportLists]--&gt;3.&lt;span style="font-size: 7pt; font-stretch: normal; font-variant-numeric: normal; line-height: normal;"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;
&lt;/span&gt;&lt;!--[endif]--&gt;Go to path &lt;span style="color: red;"&gt;C:\Program
Files (x86)\Java\jdk1.8.0_131\bin &lt;/span&gt;in your PC and copy it.&lt;o:p&gt;&lt;/o:p&gt;&lt;br /&gt;
&lt;br /&gt;&lt;/div&gt;
&lt;div class="MsoListParagraphCxSpMiddle" style="mso-list: l0 level1 lfo1; text-indent: -18.0pt;"&gt;
&lt;!--[if !supportLists]--&gt;4.&lt;span style="font-size: 7pt; font-stretch: normal; font-variant-numeric: normal; line-height: normal;"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;
&lt;/span&gt;&lt;!--[endif]--&gt;Now go to control panel&lt;br /&gt;
&lt;br /&gt;&lt;/div&gt;
&lt;div class="MsoListParagraphCxSpMiddle" style="mso-list: l0 level1 lfo1; text-indent: -18.0pt;"&gt;
&lt;!--[if !supportLists]--&gt;5.&lt;span style="font-size: 7pt; font-stretch: normal; font-variant-numeric: normal; line-height: normal;"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;
&lt;/span&gt;&lt;!--[endif]--&gt;Click on system&lt;o:p&gt;&lt;/o:p&gt;&lt;br /&gt;
&lt;br /&gt;&lt;/div&gt;
&lt;div class="separator" style="clear: both; text-align: center;"&gt;
&lt;a href="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEgd7Ug8JZTqxPoUTg9UnIAsEfoh5DPD6jdAvnFvGMJ7LhBJ4ADS3_BxnZhDRSPcGJSpLaQ7pB6oYfYq_4DBvW6SYGpdJvT9azkwo0S84CxADm4SXUXSXzKv53F28FVE0wnsSwS-kBdsFF0/s1600/Screenshot+%2528263%2529.png" imageanchor="1"&gt;&lt;img border="0" data-original-height="768" data-original-width="1366" height="358" src="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEgd7Ug8JZTqxPoUTg9UnIAsEfoh5DPD6jdAvnFvGMJ7LhBJ4ADS3_BxnZhDRSPcGJSpLaQ7pB6oYfYq_4DBvW6SYGpdJvT9azkwo0S84CxADm4SXUXSXzKv53F28FVE0wnsSwS-kBdsFF0/s1600/Screenshot+%2528263%2529.png" width="640" /&gt;&lt;/a&gt;&lt;/div&gt;
&lt;div class="MsoListParagraphCxSpMiddle" style="mso-list: l0 level1 lfo1; text-indent: -18.0pt;"&gt;
&lt;br /&gt;&lt;/div&gt;
&lt;div class="MsoListParagraphCxSpMiddle" style="mso-list: l0 level1 lfo1; text-indent: -18.0pt;"&gt;
&lt;!--[if !supportLists]--&gt;6.&lt;span style="font-size: 7pt; font-stretch: normal; font-variant-numeric: normal; line-height: normal;"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;
&lt;/span&gt;&lt;!--[endif]--&gt;Click on advance system settings&lt;o:p&gt;&lt;/o:p&gt;&lt;br /&gt;
&lt;br /&gt;
&lt;div class="separator" style="clear: both; text-align: center;"&gt;
&lt;a href="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEgyLreFfFPV5Z6nO9pFNnIAcbo_pBVx3cqqegUCkvUIslb8F3-pYvezbTJ05IRThOhFQoUETfeP2CFwjWhb2uGvUJELo5Y_4CHB6M9QEbRRpARn7VhuNu8o0ZJ3-qT42oi7GOaPmevZTFw/s1600/Screenshot+%2528264%2529.png" imageanchor="1" style="margin-left: 1em; margin-right: 1em;"&gt;&lt;img border="0" data-original-height="768" data-original-width="1366" height="358" src="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEgyLreFfFPV5Z6nO9pFNnIAcbo_pBVx3cqqegUCkvUIslb8F3-pYvezbTJ05IRThOhFQoUETfeP2CFwjWhb2uGvUJELo5Y_4CHB6M9QEbRRpARn7VhuNu8o0ZJ3-qT42oi7GOaPmevZTFw/s640/Screenshot+%2528264%2529.png" width="640" /&gt;&lt;/a&gt;&lt;/div&gt;
&lt;br /&gt;
&lt;br /&gt;&lt;/div&gt;
&lt;div class="separator" style="clear: both; text-align: center;"&gt;
&lt;/div&gt;
&lt;div class="MsoListParagraphCxSpMiddle" style="mso-list: l0 level1 lfo1; text-indent: -18.0pt;"&gt;
&lt;!--[if !supportLists]--&gt;7.&lt;span style="font-size: 7pt; font-stretch: normal; font-variant-numeric: normal; line-height: normal;"&gt;&amp;nbsp; &amp;nbsp;&amp;nbsp;&lt;/span&gt;&lt;span style="text-indent: -18pt;"&gt;Click on environment variables&lt;/span&gt;&lt;br /&gt;
&lt;span style="text-indent: -18pt;"&gt;&lt;br /&gt;&lt;/span&gt;&lt;/div&gt;
&lt;div class="MsoListParagraphCxSpMiddle" style="mso-list: l0 level1 lfo1; text-indent: -18.0pt;"&gt;
&lt;o:p&gt;&lt;/o:p&gt;&lt;/div&gt;
&lt;div class="separator" style="clear: both; text-align: center;"&gt;
&lt;a href="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEg0qH5tsFFgsEy7TQVShKZllOZsODZnarvM5o091o6Yf00l8hgxQ7_AfL2YPcvkiKwz1L__pLBFcLTRFLSKU0gBO3YMaqykQbFqsBOxI9dCEHIOVNBdsYpQksEysllrUIO9AiXubZgjNyE/s1600/Screenshot+%2528265%2529.png" imageanchor="1" style="margin-left: 1em; margin-right: 1em;"&gt;&lt;img border="0" data-original-height="768" data-original-width="1366" height="358" src="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEg0qH5tsFFgsEy7TQVShKZllOZsODZnarvM5o091o6Yf00l8hgxQ7_AfL2YPcvkiKwz1L__pLBFcLTRFLSKU0gBO3YMaqykQbFqsBOxI9dCEHIOVNBdsYpQksEysllrUIO9AiXubZgjNyE/s640/Screenshot+%2528265%2529.png" width="640" /&gt;&lt;/a&gt;&lt;/div&gt;
&lt;div class="MsoListParagraphCxSpMiddle" style="mso-list: l0 level1 lfo1; text-indent: -18.0pt;"&gt;
&lt;br /&gt;&lt;/div&gt;
&lt;div class="separator" style="clear: both; text-align: center;"&gt;
&lt;/div&gt;
&lt;div class="MsoListParagraphCxSpMiddle" style="mso-list: l0 level1 lfo1; text-indent: -18.0pt;"&gt;
&lt;br /&gt;&lt;/div&gt;
&lt;div class="MsoListParagraphCxSpMiddle" style="mso-list: l0 level1 lfo1; text-indent: -18.0pt;"&gt;
&lt;!--[if !supportLists]--&gt;8.&lt;span style="font-size: 7pt; font-stretch: normal; font-variant-numeric: normal; line-height: normal;"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;
&lt;/span&gt;&lt;!--[endif]--&gt;Click on new and name it as path and copy path
which is in your pc as shown above in red colour&lt;o:p&gt;&lt;/o:p&gt;&lt;br /&gt;
&lt;br /&gt;&lt;/div&gt;
&lt;div class="separator" style="clear: both; text-align: center;"&gt;
&lt;a href="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEjx1Fx_2Kmu5h7GdN1VYKpXL-YVwKIoEWfVy49ldF3D7uWR_rAsPva1rhbV-c6UnGFuaz1q3mI1mUBa6-7Tzv814ARARkuQptIj_LZ9mfOBADl4MXEGMiD5Shpk8l25zN1kp59NXYPI0gw/s1600/Screenshot+%2528266%2529.png" imageanchor="1" style="margin-left: 1em; margin-right: 1em;"&gt;&lt;img border="0" data-original-height="768" data-original-width="1366" height="358" src="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEjx1Fx_2Kmu5h7GdN1VYKpXL-YVwKIoEWfVy49ldF3D7uWR_rAsPva1rhbV-c6UnGFuaz1q3mI1mUBa6-7Tzv814ARARkuQptIj_LZ9mfOBADl4MXEGMiD5Shpk8l25zN1kp59NXYPI0gw/s640/Screenshot+%2528266%2529.png" width="640" /&gt;&lt;/a&gt;&lt;/div&gt;
&lt;div class="MsoListParagraphCxSpMiddle" style="mso-list: l0 level1 lfo1; text-indent: -18.0pt;"&gt;
&lt;br /&gt;&lt;/div&gt;
&lt;div class="separator" style="clear: both; text-align: center;"&gt;
&lt;/div&gt;
&lt;div class="MsoListParagraphCxSpMiddle" style="mso-list: l0 level1 lfo1; text-indent: -18.0pt;"&gt;
&lt;br /&gt;&lt;/div&gt;
&lt;div class="MsoListParagraphCxSpMiddle" style="mso-list: l0 level1 lfo1; text-indent: -18.0pt;"&gt;
&lt;!--[if !supportLists]--&gt;9.&lt;span style="font-size: 7pt; font-stretch: normal; font-variant-numeric: normal; line-height: normal;"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;
&lt;/span&gt;&lt;!--[endif]--&gt;Click on OK&lt;br /&gt;
&lt;br /&gt;&lt;/div&gt;
&lt;div class="separator" style="clear: both; text-align: center;"&gt;
&lt;a href="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEiu-kahJVzRo712b0Ri51kmhhhWW4svtkZh8PkEldBdrl_-uPbOaoTO9FgvP2-CknZ4O1ZoLVGb06QK1tUfatmEWXAvq1xuHWJ-lM9phOO_YDHZoJoquQ2j53I8my50tlsnY5dNRBPfA1A/s1600/Screenshot+%2528267%2529.png" imageanchor="1" style="margin-left: 1em; margin-right: 1em;"&gt;&lt;img border="0" data-original-height="768" data-original-width="1366" height="358" src="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEiu-kahJVzRo712b0Ri51kmhhhWW4svtkZh8PkEldBdrl_-uPbOaoTO9FgvP2-CknZ4O1ZoLVGb06QK1tUfatmEWXAvq1xuHWJ-lM9phOO_YDHZoJoquQ2j53I8my50tlsnY5dNRBPfA1A/s640/Screenshot+%2528267%2529.png" width="640" /&gt;&lt;/a&gt;&lt;/div&gt;
&lt;div class="MsoListParagraphCxSpMiddle" style="mso-list: l0 level1 lfo1; text-indent: -18.0pt;"&gt;
&lt;br /&gt;&lt;/div&gt;
&lt;div class="MsoListParagraphCxSpMiddle" style="mso-list: l0 level1 lfo1; text-indent: -18.0pt;"&gt;
&lt;br /&gt;&lt;/div&gt;
&lt;div class="MsoListParagraphCxSpMiddle" style="mso-list: l0 level1 lfo1; text-indent: -18.0pt;"&gt;
&lt;!--[if !supportLists]--&gt;10.&lt;span style="font-size: 7pt; font-stretch: normal; font-variant-numeric: normal; line-height: normal;"&gt;&amp;nbsp;&amp;nbsp;
&lt;/span&gt;&lt;!--[endif]--&gt;Now open CMD and type &lt;u&gt;javac&lt;/u&gt; and press
enter if it shows messy long list then congratulation java is installed in your
PC.&lt;o:p&gt;&lt;/o:p&gt;&lt;br /&gt;
&lt;br /&gt;&lt;/div&gt;
&lt;div class="MsoListParagraphCxSpLast" style="text-align: left; text-indent: -18pt;"&gt;
&lt;!--[if !supportLists]--&gt;11.&lt;span style="font-size: 7pt; font-stretch: normal; font-variant-numeric: normal; line-height: normal;"&gt;&amp;nbsp;&amp;nbsp;
&lt;/span&gt;&lt;!--[endif]--&gt;Now go to next article for Hello World program.&lt;o:p&gt;&lt;/o:p&gt;&lt;/div&gt;
&lt;/div&gt;
&lt;/body&gt;
</description><link>http://tangled-java.blogspot.com/2017/11/setup-java-in-your-pc.html</link><author>noreply@blogger.com (Anonymous)</author><media:thumbnail xmlns:media="http://search.yahoo.com/mrss/" height="72" url="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEh7vjXRvw1YqswggIzF5cXoCW1H55Nf0Wn7X8ozSxW2Jvalm3i6Xn4zLsdiL5Bme-_kWhNmOTiaojVh5FkD02LulmnaurGRCeoCX857wv8ucO_tz2V9euBT8dhEQDMvLXknL-TwcxtVnj0/s72-c/Screenshot+%2528261%2529.png" width="72"/><thr:total>1</thr:total></item><item><guid isPermaLink="false">tag:blogger.com,1999:blog-3082064622906880860.post-8692773515993913622</guid><pubDate>Mon, 27 Nov 2017 03:50:00 +0000</pubDate><atom:updated>2017-11-29T05:03:54.272-08:00</atom:updated><category domain="http://www.blogger.com/atom/ns#">about java</category><category domain="http://www.blogger.com/atom/ns#">history of java</category><title>About JAVA</title><description>&lt;body onload='selectjava()'&gt;
&lt;div dir="ltr" style="text-align: left;" trbidi="on"&gt;
The greatest challenges and most exciting opportunities for software developers today lie in harnessing the power of networks. Applications created today, whatever their intended scope or audience, will almost certainly run on machines linked by a global network of computing resources. The increasing importance of networks is placing new demands on existing tools and fueling the demand for a rapidly growing list of completely new kinds of applications.&lt;br /&gt;
&lt;br /&gt;
We want software that works—consistently, anywhere, on any platform—and that plays well with other applications. We want dynamic applications that take advantage of a connected world, capable of accessing disparate and distributed information sources. We want truly distributed software that can be extended and upgraded seamlessly. We want intelligent applications that can roam the Net for us, ferreting out information and serving as electronic emissaries. We have known for some time what kind of software we want, but it is really only in the past few years that we have begun to get it.&lt;br /&gt;
&lt;br /&gt;
The problem, historically, has been that the tools for building these applications have fallen short. The requirements of speed and portability have been, for the most part, mutually exclusive, and security has been largely ignored or misunderstood. In the past, truly portable languages were bulky, interpreted, and slow. These languages were popular as much for their high-level functionality as for their portability. Fast languages usually provided speed by binding themselves to particular platforms, so they met the portability issue only halfway. There were even a few safe languages, but they were primarily offshoots of the portable languages and suffered from the same problems. Java is a modern language that addresses all three of these fronts: portability, speed, and security. This is why it has been a dominant language in the world of programming for more than a decade and a half.&lt;br /&gt;
&lt;h2 style="text-align: left;"&gt;
&amp;nbsp;About Java&amp;nbsp;&lt;/h2&gt;
&lt;div class="separator" style="clear: both; text-align: center;"&gt;
&lt;a href="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEjs9I5REpiTcNvdM_7Cz3JeSmWmvZ50528W5mif8chHiPqO0CUiSd8N4wlvXZHs2QNjgQjQQeNlk8PB9jDGGy6761_MovYAM7gQQ5b6u7WC4MWeX4wAa5F435TYPsJ0S6eA_jg2tEfukE4/s1600/java.jpg" imageanchor="1" style="clear: left; float: left; margin-bottom: 1em; margin-right: 1em;"&gt;&lt;img border="0" data-original-height="900" data-original-width="900" height="320" src="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEjs9I5REpiTcNvdM_7Cz3JeSmWmvZ50528W5mif8chHiPqO0CUiSd8N4wlvXZHs2QNjgQjQQeNlk8PB9jDGGy6761_MovYAM7gQQ5b6u7WC4MWeX4wAa5F435TYPsJ0S6eA_jg2tEfukE4/s320/java.jpg" width="320" /&gt;&lt;/a&gt;&lt;/div&gt;
&lt;div&gt;
&lt;div&gt;
The Java programming language, developed at Sun Microsystems under the guidance of Net luminaries James Gosling and Bill Joy, was designed to be a machine-independent programming language that is both safe enough to traverse networks and powerful enough to replace native executable code. Java addresses the issues raised here and played a starring role in the growth of the Internet, leading to where we are today.&lt;/div&gt;
&lt;div&gt;
&lt;br /&gt;&lt;/div&gt;
&lt;div&gt;
Initially, most of the enthusiasm for Java centered on its capabilities for building embedded applications for the Web called applets. But in the early days, applets and other client-side GUI applications written in Java were limited. Today, Java has Swing, one of the most sophisticated toolkits for building graphical user interfaces (GUIs) in any language. This development has allowed Java to become a popular platform for developing traditional client-side application software.&lt;/div&gt;
&lt;div&gt;
&lt;br /&gt;&lt;/div&gt;
&lt;div&gt;
Of even more importance, however, Java has become the premier platform for web-based applications and web services. These applications use technologies including the Java Servlet API, Java web services, and many popular open source and commercial Java application servers and frameworks. Java’s portability and speed make it the platform of choice for modern business applications. Java servers running on open source Linux platforms are at the heart of the business and financial world today.&lt;/div&gt;
&lt;div&gt;
&lt;br /&gt;&lt;/div&gt;
&lt;div&gt;
This book will show you how to use Java to accomplish real-world programming tasks. In the coming chapters we’ll cover everything from text processing to networking, building rich client-side GUI applications with Swing and lightweight web-based applications and services.&lt;/div&gt;
&lt;/div&gt;
&lt;h2 style="text-align: left;"&gt;
&amp;nbsp;History of Java&amp;nbsp;&lt;/h2&gt;
&lt;div class="separator" style="clear: both; text-align: center;"&gt;
&lt;a href="https://media.licdn.com/mpr/mpr/shrinknp_200_200/AAEAAQAAAAAAAAW-AAAAJGQ4MDE0MDU1LWM2ZDMtNGE2Ni1iMGIxLTU3Y2VlODZkZGYyNA.jpg" imageanchor="1" style="clear: right; float: right; margin-bottom: 1em; margin-left: 1em;"&gt;&lt;img border="0" data-original-height="199" data-original-width="199" height="400" src="https://media.licdn.com/mpr/mpr/shrinknp_200_200/AAEAAQAAAAAAAAW-AAAAJGQ4MDE0MDU1LWM2ZDMtNGE2Ni1iMGIxLTU3Y2VlODZkZGYyNA.jpg" width="399" /&gt;&lt;/a&gt;&lt;/div&gt;
&lt;div&gt;
&lt;div&gt;
The seeds of Java were planted in 1990 by Sun Microsystems patriarch and chief researcher Bill Joy. At the time, Sun was competing in a relatively small workstation market while Microsoft was beginning its domination of the more mainstream, Intel-based PC world. When Sun missed the boat on the PC revolution, Joy retreated to Aspen, Colorado, to work on advanced research. He was committed to the idea of accomplishing complex tasks with simple software and founded the aptly named Sun Aspen Smallworks.&lt;/div&gt;
&lt;div&gt;
&lt;br /&gt;&lt;/div&gt;
&lt;div&gt;
Of the original members of the small team of programmers assembled in Aspen, James Gosling will be remembered as the father of Java. Gosling first made a name for himself in the early 80s as the author of Gosling Emacs, the first version of the popular Emacs editor that was written in C and ran under Unix. Gosling Emacs became popular but was soon eclipsed by a free version, GNU Emacs, written by Emacs’s original designer. By that time, Gosling had moved on to design Sun’s NeWS, which briefly contended with the X Window System for control of the Unix GUI desktop in 1987. Although some people would argue that NeWS was superior to X, NeWS lost because Sun kept it proprietary and didn’t publish source code while the primary developers of X formed the X Consortium and took the opposite approach.&lt;/div&gt;
&lt;div&gt;
&lt;br /&gt;&lt;/div&gt;
&lt;div&gt;
Designing NeWS taught Gosling the power of integrating an expressive language with a network-aware windowing GUI. It also taught Sun that the Internet programming community will ultimately refuse to accept proprietary standards, no matter how good they may be. The seeds of Java’s licensing scheme and open (if not quite “open source”) code were sown by NeWS’s failure. Gosling brought what he had learned to Bill Joy’s nascent Aspen project. In 1992, work on the project led to the founding of the Sun subsidiary FirstPerson, Inc. Its mission was to lead Sun into the world of consumer electronics.&lt;/div&gt;
&lt;div&gt;
&lt;br /&gt;&lt;/div&gt;
&lt;div&gt;
The FirstPerson team worked on developing software for information appliances, such as cellular phones and personal digital assistants (PDAs). The goal was to enable the transfer of information and real-time applications over cheap infrared and traditional packet-based networks. Memory and bandwidth limitations dictated small, efficient code. The nature of the applications also demanded they be safe and robust. Gosling and his teammates began programming in C++, but they soon found themselves confounded by a language that was too complex, unwieldy, and insecure for the task. They decided to start from scratch, and Gosling began working on something he dubbed “C++ minus minus.”&lt;/div&gt;
&lt;div&gt;
&lt;br /&gt;&lt;/div&gt;
&lt;div&gt;
With the foundering of the Apple Newton (Apple’s earliest handheld computer), it became apparent that the PDA’s ship had not yet come in, so Sun shifted FirstPerson’s efforts to interactive TV (ITV). The programming language of choice for ITV set-top boxes was to be the near ancestor of Java, a language called Oak. Even with its elegance and ability to provide safe interactivity, Oak could not salvage the lost cause of ITV at that time. Customers didn’t want it, and Sun soon abandoned the concept.&lt;/div&gt;
&lt;div&gt;
&lt;br /&gt;&lt;/div&gt;
&lt;div&gt;
At that time, Joy and Gosling got together to decide on a new strategy for their innovative language. It was 1993, and the explosion of interest in the Web presented a new opportunity. Oak was small, safe, architecture-independent, and object-oriented. As it happens, these are also some of the requirements for a universal, Internet-savvy programming language. Sun quickly changed focus, and, with a little retooling, Oak became Java.&lt;/div&gt;
&lt;/div&gt;
&lt;h2 style="text-align: left;"&gt;
&amp;nbsp;Growing up Java&amp;nbsp;&lt;/h2&gt;
&lt;div&gt;
&lt;div&gt;
It would not be overstating it to say that Java caught on like wildfire. Even before its first official release when Java was still a nonproduct, nearly every major industry player had jumped on the Java bandwagon. Java licensees included Microsoft, Intel, IBM, and virtually all major hardware and software vendors. However, even with all this support Java took a lot of knocks and experienced some growing pains during its first few years.&lt;/div&gt;
&lt;div&gt;
&lt;br /&gt;&lt;/div&gt;
&lt;div&gt;
A series of breach of contract and antitrust lawsuits between Sun and Microsoft over the distribution of Java and its use in Internet Explorer hampered its deployment on the world’s most common desktop operating system—Windows. Microsoft’s involvement with Java also become one focus of a larger federal lawsuit over serious anticompetitive practices at the company, with court testimony revealing concerted efforts by the software giant to undermine Java by introducing incompatibilities in its version of the language. Meanwhile, Microsoft introduced its own Java-derived language called C# (C-sharp) as part of its .NET initiative and dropped Java from inclusion in Windows. C# has gone on to become a very good language in its own right, enjoying more innovation in recent years than has Java.&lt;/div&gt;
&lt;div&gt;
&lt;br /&gt;&lt;/div&gt;
&lt;div&gt;
But Java continues to spread on a wide variety of platforms. As we begin looking at the Java architecture, you’ll see that much of what is exciting about Java comes from the self-contained, virtual machine environment in which Java applications run. Java was carefully designed so that this supporting architecture can be implemented either in software, for existing computer platforms, or in customized hardware. Hardware implementations of Java are used in some smart cards and other embedded systems. You can even buy “wearable” devices, such as rings and dog tags, that have Java interpreters embedded in them. Software implementations of Java are available for all modern computer platforms down to portable computing devices. Today, an offshoot of the Java platform is the basis for Google’s Android operating system that powers billions of phones and other mobile devices.&lt;/div&gt;
&lt;div&gt;
&lt;br /&gt;&lt;/div&gt;
&lt;div&gt;
In 2010, Oracle corporation bought Sun Microsystems and became the steward of the Java language. In a somewhat rocky start to its tenure, Oracle sued Google over its use of the Java language in Android and lost. In July of 2011, Oracle released Java SE 7, a significant Java release.&lt;/div&gt;
&lt;/div&gt;
&lt;div class="separator" style="clear: both; text-align: center;"&gt;
&lt;/div&gt;
&lt;/div&gt;
&lt;/body&gt;</description><link>http://tangled-java.blogspot.com/2017/11/about-java.html</link><author>noreply@blogger.com (Anonymous)</author><media:thumbnail xmlns:media="http://search.yahoo.com/mrss/" height="72" url="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEjs9I5REpiTcNvdM_7Cz3JeSmWmvZ50528W5mif8chHiPqO0CUiSd8N4wlvXZHs2QNjgQjQQeNlk8PB9jDGGy6761_MovYAM7gQQ5b6u7WC4MWeX4wAa5F435TYPsJ0S6eA_jg2tEfukE4/s72-c/java.jpg" width="72"/><thr:total>0</thr:total></item><item><guid isPermaLink="false">tag:blogger.com,1999:blog-3082064622906880860.post-534507241232239287</guid><pubDate>Sat, 18 Nov 2017 14:44:00 +0000</pubDate><atom:updated>2017-11-27T00:14:37.346-08:00</atom:updated><category domain="http://www.blogger.com/atom/ns#">break</category><category domain="http://www.blogger.com/atom/ns#">continue</category><category domain="http://www.blogger.com/atom/ns#">default</category><category domain="http://www.blogger.com/atom/ns#">switch statement</category><title>switch statement</title><description>&lt;!DOCTYPE html&gt;
&lt;html&gt;
&lt;head&gt;
 &lt;title&gt;&lt;/title&gt;
&lt;script type="text/javascript"&gt;
 /*! highlight.js v9.12.0 | BSD3 License | git.io/hljslicense */
!function(e){var n="object"==typeof window&amp;&amp;window||"object"==typeof self&amp;&amp;self;"undefined"!=typeof exports?e(exports):n&amp;&amp;(n.hljs=e({}),"function"==typeof define&amp;&amp;define.amd&amp;&amp;define([],function(){return n.hljs}))}(function(e){function n(e){return e.replace(/&amp;/g,"&amp;amp;").replace(/&lt;/g,"&amp;lt;").replace(/&gt;/g,"&amp;gt;")}function t(e){return e.nodeName.toLowerCase()}function r(e,n){var t=e&amp;&amp;e.exec(n);return t&amp;&amp;0===t.index}function a(e){return k.test(e)}function i(e){var n,t,r,i,o=e.className+" ";if(o+=e.parentNode?e.parentNode.className:"",t=B.exec(o))return w(t[1])?t[1]:"no-highlight";for(o=o.split(/\s+/),n=0,r=o.length;r&gt;n;n++)if(i=o[n],a(i)||w(i))return i}function o(e){var n,t={},r=Array.prototype.slice.call(arguments,1);for(n in e)t[n]=e[n];return r.forEach(function(e){for(n in e)t[n]=e[n]}),t}function u(e){var n=[];return function r(e,a){for(var i=e.firstChild;i;i=i.nextSibling)3===i.nodeType?a+=i.nodeValue.length:1===i.nodeType&amp;&amp;(n.push({event:"start",offset:a,node:i}),a=r(i,a),t(i).match(/br|hr|img|input/)||n.push({event:"stop",offset:a,node:i}));return a}(e,0),n}function c(e,r,a){function i(){return e.length&amp;&amp;r.length?e[0].offset!==r[0].offset?e[0].offset&lt;r[0].offset?e:r:"start"===r[0].event?e:r:e.length?e:r}function o(e){function r(e){return" "+e.nodeName+'="'+n(e.value).replace('"',"&amp;quot;")+'"'}s+="&lt;"+t(e)+E.map.call(e.attributes,r).join("")+"&gt;"}function u(e){s+="&lt;/"+t(e)+"&gt;"}function c(e){("start"===e.event?o:u)(e.node)}for(var l=0,s="",f=[];e.length||r.length;){var g=i();if(s+=n(a.substring(l,g[0].offset)),l=g[0].offset,g===e){f.reverse().forEach(u);do c(g.splice(0,1)[0]),g=i();while(g===e&amp;&amp;g.length&amp;&amp;g[0].offset===l);f.reverse().forEach(o)}else"start"===g[0].event?f.push(g[0].node):f.pop(),c(g.splice(0,1)[0])}return s+n(a.substr(l))}function l(e){return e.v&amp;&amp;!e.cached_variants&amp;&amp;(e.cached_variants=e.v.map(function(n){return o(e,{v:null},n)})),e.cached_variants||e.eW&amp;&amp;[o(e)]||[e]}function s(e){function n(e){return e&amp;&amp;e.source||e}function t(t,r){return new RegExp(n(t),"m"+(e.cI?"i":"")+(r?"g":""))}function r(a,i){if(!a.compiled){if(a.compiled=!0,a.k=a.k||a.bK,a.k){var o={},u=function(n,t){e.cI&amp;&amp;(t=t.toLowerCase()),t.split(" ").forEach(function(e){var t=e.split("|");o[t[0]]=[n,t[1]?Number(t[1]):1]})};"string"==typeof a.k?u("keyword",a.k):x(a.k).forEach(function(e){u(e,a.k[e])}),a.k=o}a.lR=t(a.l||/\w+/,!0),i&amp;&amp;(a.bK&amp;&amp;(a.b="\\b("+a.bK.split(" ").join("|")+")\\b"),a.b||(a.b=/\B|\b/),a.bR=t(a.b),a.e||a.eW||(a.e=/\B|\b/),a.e&amp;&amp;(a.eR=t(a.e)),a.tE=n(a.e)||"",a.eW&amp;&amp;i.tE&amp;&amp;(a.tE+=(a.e?"|":"")+i.tE)),a.i&amp;&amp;(a.iR=t(a.i)),null==a.r&amp;&amp;(a.r=1),a.c||(a.c=[]),a.c=Array.prototype.concat.apply([],a.c.map(function(e){return l("self"===e?a:e)})),a.c.forEach(function(e){r(e,a)}),a.starts&amp;&amp;r(a.starts,i);var c=a.c.map(function(e){return e.bK?"\\.?("+e.b+")\\.?":e.b}).concat([a.tE,a.i]).map(n).filter(Boolean);a.t=c.length?t(c.join("|"),!0):{exec:function(){return null}}}}r(e)}function f(e,t,a,i){function o(e,n){var t,a;for(t=0,a=n.c.length;a&gt;t;t++)if(r(n.c[t].bR,e))return n.c[t]}function u(e,n){if(r(e.eR,n)){for(;e.endsParent&amp;&amp;e.parent;)e=e.parent;return e}return e.eW?u(e.parent,n):void 0}function c(e,n){return!a&amp;&amp;r(n.iR,e)}function l(e,n){var t=N.cI?n[0].toLowerCase():n[0];return e.k.hasOwnProperty(t)&amp;&amp;e.k[t]}function p(e,n,t,r){var a=r?"":I.classPrefix,i='&lt;span class="'+a,o=t?"":C;return i+=e+'"&gt;',i+n+o}function h(){var e,t,r,a;if(!E.k)return n(k);for(a="",t=0,E.lR.lastIndex=0,r=E.lR.exec(k);r;)a+=n(k.substring(t,r.index)),e=l(E,r),e?(B+=e[1],a+=p(e[0],n(r[0]))):a+=n(r[0]),t=E.lR.lastIndex,r=E.lR.exec(k);return a+n(k.substr(t))}function d(){var e="string"==typeof E.sL;if(e&amp;&amp;!y[E.sL])return n(k);var t=e?f(E.sL,k,!0,x[E.sL]):g(k,E.sL.length?E.sL:void 0);return E.r&gt;0&amp;&amp;(B+=t.r),e&amp;&amp;(x[E.sL]=t.top),p(t.language,t.value,!1,!0)}function b(){L+=null!=E.sL?d():h(),k=""}function v(e){L+=e.cN?p(e.cN,"",!0):"",E=Object.create(e,{parent:{value:E}})}function m(e,n){if(k+=e,null==n)return b(),0;var t=o(n,E);if(t)return t.skip?k+=n:(t.eB&amp;&amp;(k+=n),b(),t.rB||t.eB||(k=n)),v(t,n),t.rB?0:n.length;var r=u(E,n);if(r){var a=E;a.skip?k+=n:(a.rE||a.eE||(k+=n),b(),a.eE&amp;&amp;(k=n));do E.cN&amp;&amp;(L+=C),E.skip||(B+=E.r),E=E.parent;while(E!==r.parent);return r.starts&amp;&amp;v(r.starts,""),a.rE?0:n.length}if(c(n,E))throw new Error('Illegal lexeme "'+n+'" for mode "'+(E.cN||"&lt;unnamed&gt;")+'"');return k+=n,n.length||1}var N=w(e);if(!N)throw new Error('Unknown language: "'+e+'"');s(N);var R,E=i||N,x={},L="";for(R=E;R!==N;R=R.parent)R.cN&amp;&amp;(L=p(R.cN,"",!0)+L);var k="",B=0;try{for(var M,j,O=0;;){if(E.t.lastIndex=O,M=E.t.exec(t),!M)break;j=m(t.substring(O,M.index),M[0]),O=M.index+j}for(m(t.substr(O)),R=E;R.parent;R=R.parent)R.cN&amp;&amp;(L+=C);return{r:B,value:L,language:e,top:E}}catch(T){if(T.message&amp;&amp;-1!==T.message.indexOf("Illegal"))return{r:0,value:n(t)};throw T}}function g(e,t){t=t||I.languages||x(y);var r={r:0,value:n(e)},a=r;return t.filter(w).forEach(function(n){var t=f(n,e,!1);t.language=n,t.r&gt;a.r&amp;&amp;(a=t),t.r&gt;r.r&amp;&amp;(a=r,r=t)}),a.language&amp;&amp;(r.second_best=a),r}function p(e){return I.tabReplace||I.useBR?e.replace(M,function(e,n){return I.useBR&amp;&amp;"\n"===e?"&lt;br&gt;":I.tabReplace?n.replace(/\t/g,I.tabReplace):""}):e}function h(e,n,t){var r=n?L[n]:t,a=[e.trim()];return e.match(/\bhljs\b/)||a.push("hljs"),-1===e.indexOf(r)&amp;&amp;a.push(r),a.join(" ").trim()}function d(e){var n,t,r,o,l,s=i(e);a(s)||(I.useBR?(n=document.createElementNS("http://www.w3.org/1999/xhtml","div"),n.innerHTML=e.innerHTML.replace(/\n/g,"").replace(/&lt;br[ \/]*&gt;/g,"\n")):n=e,l=n.textContent,r=s?f(s,l,!0):g(l),t=u(n),t.length&amp;&amp;(o=document.createElementNS("http://www.w3.org/1999/xhtml","div"),o.innerHTML=r.value,r.value=c(t,u(o),l)),r.value=p(r.value),e.innerHTML=r.value,e.className=h(e.className,s,r.language),e.result={language:r.language,re:r.r},r.second_best&amp;&amp;(e.second_best={language:r.second_best.language,re:r.second_best.r}))}function b(e){I=o(I,e)}function v(){if(!v.called){v.called=!0;var e=document.querySelectorAll("pre code");E.forEach.call(e,d)}}function m(){addEventListener("DOMContentLoaded",v,!1),addEventListener("load",v,!1)}function N(n,t){var r=y[n]=t(e);r.aliases&amp;&amp;r.aliases.forEach(function(e){L[e]=n})}function R(){return x(y)}function w(e){return e=(e||"").toLowerCase(),y[e]||y[L[e]]}var E=[],x=Object.keys,y={},L={},k=/^(no-?highlight|plain|text)$/i,B=/\blang(?:uage)?-([\w-]+)\b/i,M=/((^(&lt;[^&gt;]+&gt;|\t|)+|(?:\n)))/gm,C="&lt;/span&gt;",I={classPrefix:"hljs-",tabReplace:null,useBR:!1,languages:void 0};return e.highlight=f,e.highlightAuto=g,e.fixMarkup=p,e.highlightBlock=d,e.configure=b,e.initHighlighting=v,e.initHighlightingOnLoad=m,e.registerLanguage=N,e.listLanguages=R,e.getLanguage=w,e.inherit=o,e.IR="[a-zA-Z]\\w*",e.UIR="[a-zA-Z_]\\w*",e.NR="\\b\\d+(\\.\\d+)?",e.CNR="(-?)(\\b0[xX][a-fA-F0-9]+|(\\b\\d+(\\.\\d*)?|\\.\\d+)([eE][-+]?\\d+)?)",e.BNR="\\b(0b[01]+)",e.RSR="!|!=|!==|%|%=|&amp;|&amp;&amp;|&amp;=|\\*|\\*=|\\+|\\+=|,|-|-=|/=|/|:|;|&lt;&lt;|&lt;&lt;=|&lt;=|&lt;|===|==|=|&gt;&gt;&gt;=|&gt;&gt;=|&gt;=|&gt;&gt;&gt;|&gt;&gt;|&gt;|\\?|\\[|\\{|\\(|\\^|\\^=|\\||\\|=|\\|\\||~",e.BE={b:"\\\\[\\s\\S]",r:0},e.ASM={cN:"string",b:"'",e:"'",i:"\\n",c:[e.BE]},e.QSM={cN:"string",b:'"',e:'"',i:"\\n",c:[e.BE]},e.PWM={b:/\b(a|an|the|are|I'm|isn't|don't|doesn't|won't|but|just|should|pretty|simply|enough|gonna|going|wtf|so|such|will|you|your|they|like|more)\b/},e.C=function(n,t,r){var a=e.inherit({cN:"comment",b:n,e:t,c:[]},r||{});return a.c.push(e.PWM),a.c.push({cN:"doctag",b:"(?:TODO|FIXME|NOTE|BUG|XXX):",r:0}),a},e.CLCM=e.C("//","$"),e.CBCM=e.C("/\\*","\\*/"),e.HCM=e.C("#","$"),e.NM={cN:"number",b:e.NR,r:0},e.CNM={cN:"number",b:e.CNR,r:0},e.BNM={cN:"number",b:e.BNR,r:0},e.CSSNM={cN:"number",b:e.NR+"(%|em|ex|ch|rem|vw|vh|vmin|vmax|cm|mm|in|pt|pc|px|deg|grad|rad|turn|s|ms|Hz|kHz|dpi|dpcm|dppx)?",r:0},e.RM={cN:"regexp",b:/\//,e:/\/[gimuy]*/,i:/\n/,c:[e.BE,{b:/\[/,e:/\]/,r:0,c:[e.BE]}]},e.TM={cN:"title",b:e.IR,r:0},e.UTM={cN:"title",b:e.UIR,r:0},e.METHOD_GUARD={b:"\\.\\s*"+e.UIR,r:0},e});hljs.registerLanguage("java",function(e){var a="[À-ʸa-zA-Z_$][À-ʸa-zA-Z_$0-9]*",t=a+"(&lt;"+a+"(\\s*,\\s*"+a+")*&gt;)?",r="false synchronized int abstract float private char boolean static null if const for true while long strictfp finally protected import native final void enum else break transient catch instanceof byte super volatile case assert short package default double public try this switch continue throws protected public private module requires exports do",s="\\b(0[bB]([01]+[01_]+[01]+|[01]+)|0[xX]([a-fA-F0-9]+[a-fA-F0-9_]+[a-fA-F0-9]+|[a-fA-F0-9]+)|(([\\d]+[\\d_]+[\\d]+|[\\d]+)(\\.([\\d]+[\\d_]+[\\d]+|[\\d]+))?|\\.([\\d]+[\\d_]+[\\d]+|[\\d]+))([eE][-+]?\\d+)?)[lLfF]?",c={cN:"number",b:s,r:0};return{aliases:["jsp"],k:r,i:/&lt;\/|#/,c:[e.C("/\\*\\*","\\*/",{r:0,c:[{b:/\w+@/,r:0},{cN:"doctag",b:"@[A-Za-z]+"}]}),e.CLCM,e.CBCM,e.ASM,e.QSM,{cN:"class",bK:"class interface",e:/[{;=]/,eE:!0,k:"class interface",i:/[:"\[\]]/,c:[{bK:"extends implements"},e.UTM]},{bK:"new throw return else",r:0},{cN:"function",b:"("+t+"\\s+)+"+e.UIR+"\\s*\\(",rB:!0,e:/[{;=]/,eE:!0,k:r,c:[{b:e.UIR+"\\s*\\(",rB:!0,r:0,c:[e.UTM]},{cN:"params",b:/\(/,e:/\)/,k:r,r:0,c:[e.ASM,e.QSM,e.CNM,e.CBCM]},e.CLCM,e.CBCM]},c,{cN:"meta",b:"@[A-Za-z]+"}]}});
&lt;/script&gt;
&lt;script&gt;hljs.initHighlightingOnLoad();&lt;/script&gt;
&lt;/head&gt;
&lt;body onload='selectjava()'&gt;
&lt;!-- #################################################################### --&gt;
The Java switch statement executes one statement from multiple conditions. It is like if-else-if ladder statement.

&lt;h2&gt;switch statement&lt;/h2&gt;

&lt;h3&gt;Syntax&lt;/h3&gt;
&lt;pre&gt;
&lt;code class="java"&gt;
switch(expression){    
case value1:    
 //code to be executed;    
 break;  //optional  
case value2:    
 //code to be executed;    
 break;  //optional  
......    
    
default:     
 code to be executed if all cases are not matched;    
}    
&lt;/code&gt;
&lt;/pre&gt;

&lt;h3&gt;Program&lt;/h3&gt;
&lt;pre&gt;
&lt;code class="java"&gt;
public class switch_example
{
    public static void main(String args[])
    {
        int age = 20;
        switch(age)
        {
            case 10:
                System.out.println("You are child.");
            break;
            case 20:
                System.out.println("You are teenager.");
            break;
            case 30:
                System.out.println("You are matured.");
            break;
            case 40:
                System.out.println("You are old.");
            break;
            default:
                System.out.println("You are ageless.");
        }
    }
}
&lt;/code&gt;  
  &lt;a href="https://onlinegdb.com/HJGsUpakG"&gt;&lt;button class="button"&gt;&lt;span&gt;Run &lt;/span&gt;&lt;/button&gt;&lt;/a&gt;
&lt;/pre&gt;

&lt;h3&gt;Output&lt;/h3&gt;
&lt;pre&gt;
&lt;code class="java"&gt;
You are teenager.
&lt;/code&gt;  
&lt;/pre&gt;

&lt;h3&gt;Explanation&lt;/h3&gt;
&lt;div&gt;
The switch statement is a multi-way branch statement. It provides an easy way to dispatch execution to different parts of code based on the value of the expression. Basically, the expression can be byte, short, char, and int primitive data types. Beginning with JDK7, it also works with enumerated types ( Enums in java), the String class and Wrapper classes.&lt;/div&gt;
&lt;div&gt;
&lt;br /&gt;&lt;/div&gt;
&lt;div&gt;
&lt;div&gt;
Some Important rules for switch statements :&lt;/div&gt;
&lt;div&gt;
&lt;ul style="text-align: left;"&gt;
&lt;li&gt;Duplicate case values are not allowed.&lt;/li&gt;
&lt;li&gt;The value for a case must be the same data type as the variable in the switch.&lt;/li&gt;
&lt;li&gt;The value for a case must be a constant or a literal.Variables are not allowed.&lt;/li&gt;
&lt;li&gt;The break statement is used inside the switch to terminate a statement sequence.&lt;/li&gt;
&lt;li&gt;The break statement is optional. If omitted, execution will continue on into the next case.&lt;/li&gt;
&lt;li&gt;The default statement is optional, and it must appear at the end of the switch.&lt;/li&gt;
&lt;/ul&gt;
&lt;div&gt;
We will see break and continue keyword in other lesson.&lt;/div&gt;
&lt;/div&gt;
&lt;/div&gt;
&lt;/div&gt;
&lt;!-- ####################################################################### --&gt;
&lt;/body&gt;
&lt;/html&gt;</description><link>http://tangled-java.blogspot.com/2017/11/switch-statement.html</link><author>noreply@blogger.com (Anonymous)</author><thr:total>0</thr:total></item><item><guid isPermaLink="false">tag:blogger.com,1999:blog-3082064622906880860.post-1269336716697332270</guid><pubDate>Sat, 18 Nov 2017 14:32:00 +0000</pubDate><atom:updated>2017-11-27T00:11:47.354-08:00</atom:updated><category domain="http://www.blogger.com/atom/ns#">control statement</category><category domain="http://www.blogger.com/atom/ns#">if - else</category><category domain="http://www.blogger.com/atom/ns#">if-else if</category><title>If - Else control statement</title><description>&lt;!DOCTYPE html&gt;
&lt;html&gt;
&lt;head&gt;
 &lt;title&gt;&lt;/title&gt;
&lt;script type="text/javascript"&gt;
 /*! highlight.js v9.12.0 | BSD3 License | git.io/hljslicense */
!function(e){var n="object"==typeof window&amp;&amp;window||"object"==typeof self&amp;&amp;self;"undefined"!=typeof exports?e(exports):n&amp;&amp;(n.hljs=e({}),"function"==typeof define&amp;&amp;define.amd&amp;&amp;define([],function(){return n.hljs}))}(function(e){function n(e){return e.replace(/&amp;/g,"&amp;amp;").replace(/&lt;/g,"&amp;lt;").replace(/&gt;/g,"&amp;gt;")}function t(e){return e.nodeName.toLowerCase()}function r(e,n){var t=e&amp;&amp;e.exec(n);return t&amp;&amp;0===t.index}function a(e){return k.test(e)}function i(e){var n,t,r,i,o=e.className+" ";if(o+=e.parentNode?e.parentNode.className:"",t=B.exec(o))return w(t[1])?t[1]:"no-highlight";for(o=o.split(/\s+/),n=0,r=o.length;r&gt;n;n++)if(i=o[n],a(i)||w(i))return i}function o(e){var n,t={},r=Array.prototype.slice.call(arguments,1);for(n in e)t[n]=e[n];return r.forEach(function(e){for(n in e)t[n]=e[n]}),t}function u(e){var n=[];return function r(e,a){for(var i=e.firstChild;i;i=i.nextSibling)3===i.nodeType?a+=i.nodeValue.length:1===i.nodeType&amp;&amp;(n.push({event:"start",offset:a,node:i}),a=r(i,a),t(i).match(/br|hr|img|input/)||n.push({event:"stop",offset:a,node:i}));return a}(e,0),n}function c(e,r,a){function i(){return e.length&amp;&amp;r.length?e[0].offset!==r[0].offset?e[0].offset&lt;r[0].offset?e:r:"start"===r[0].event?e:r:e.length?e:r}function o(e){function r(e){return" "+e.nodeName+'="'+n(e.value).replace('"',"&amp;quot;")+'"'}s+="&lt;"+t(e)+E.map.call(e.attributes,r).join("")+"&gt;"}function u(e){s+="&lt;/"+t(e)+"&gt;"}function c(e){("start"===e.event?o:u)(e.node)}for(var l=0,s="",f=[];e.length||r.length;){var g=i();if(s+=n(a.substring(l,g[0].offset)),l=g[0].offset,g===e){f.reverse().forEach(u);do c(g.splice(0,1)[0]),g=i();while(g===e&amp;&amp;g.length&amp;&amp;g[0].offset===l);f.reverse().forEach(o)}else"start"===g[0].event?f.push(g[0].node):f.pop(),c(g.splice(0,1)[0])}return s+n(a.substr(l))}function l(e){return e.v&amp;&amp;!e.cached_variants&amp;&amp;(e.cached_variants=e.v.map(function(n){return o(e,{v:null},n)})),e.cached_variants||e.eW&amp;&amp;[o(e)]||[e]}function s(e){function n(e){return e&amp;&amp;e.source||e}function t(t,r){return new RegExp(n(t),"m"+(e.cI?"i":"")+(r?"g":""))}function r(a,i){if(!a.compiled){if(a.compiled=!0,a.k=a.k||a.bK,a.k){var o={},u=function(n,t){e.cI&amp;&amp;(t=t.toLowerCase()),t.split(" ").forEach(function(e){var t=e.split("|");o[t[0]]=[n,t[1]?Number(t[1]):1]})};"string"==typeof a.k?u("keyword",a.k):x(a.k).forEach(function(e){u(e,a.k[e])}),a.k=o}a.lR=t(a.l||/\w+/,!0),i&amp;&amp;(a.bK&amp;&amp;(a.b="\\b("+a.bK.split(" ").join("|")+")\\b"),a.b||(a.b=/\B|\b/),a.bR=t(a.b),a.e||a.eW||(a.e=/\B|\b/),a.e&amp;&amp;(a.eR=t(a.e)),a.tE=n(a.e)||"",a.eW&amp;&amp;i.tE&amp;&amp;(a.tE+=(a.e?"|":"")+i.tE)),a.i&amp;&amp;(a.iR=t(a.i)),null==a.r&amp;&amp;(a.r=1),a.c||(a.c=[]),a.c=Array.prototype.concat.apply([],a.c.map(function(e){return l("self"===e?a:e)})),a.c.forEach(function(e){r(e,a)}),a.starts&amp;&amp;r(a.starts,i);var c=a.c.map(function(e){return e.bK?"\\.?("+e.b+")\\.?":e.b}).concat([a.tE,a.i]).map(n).filter(Boolean);a.t=c.length?t(c.join("|"),!0):{exec:function(){return null}}}}r(e)}function f(e,t,a,i){function o(e,n){var t,a;for(t=0,a=n.c.length;a&gt;t;t++)if(r(n.c[t].bR,e))return n.c[t]}function u(e,n){if(r(e.eR,n)){for(;e.endsParent&amp;&amp;e.parent;)e=e.parent;return e}return e.eW?u(e.parent,n):void 0}function c(e,n){return!a&amp;&amp;r(n.iR,e)}function l(e,n){var t=N.cI?n[0].toLowerCase():n[0];return e.k.hasOwnProperty(t)&amp;&amp;e.k[t]}function p(e,n,t,r){var a=r?"":I.classPrefix,i='&lt;span class="'+a,o=t?"":C;return i+=e+'"&gt;',i+n+o}function h(){var e,t,r,a;if(!E.k)return n(k);for(a="",t=0,E.lR.lastIndex=0,r=E.lR.exec(k);r;)a+=n(k.substring(t,r.index)),e=l(E,r),e?(B+=e[1],a+=p(e[0],n(r[0]))):a+=n(r[0]),t=E.lR.lastIndex,r=E.lR.exec(k);return a+n(k.substr(t))}function d(){var e="string"==typeof E.sL;if(e&amp;&amp;!y[E.sL])return n(k);var t=e?f(E.sL,k,!0,x[E.sL]):g(k,E.sL.length?E.sL:void 0);return E.r&gt;0&amp;&amp;(B+=t.r),e&amp;&amp;(x[E.sL]=t.top),p(t.language,t.value,!1,!0)}function b(){L+=null!=E.sL?d():h(),k=""}function v(e){L+=e.cN?p(e.cN,"",!0):"",E=Object.create(e,{parent:{value:E}})}function m(e,n){if(k+=e,null==n)return b(),0;var t=o(n,E);if(t)return t.skip?k+=n:(t.eB&amp;&amp;(k+=n),b(),t.rB||t.eB||(k=n)),v(t,n),t.rB?0:n.length;var r=u(E,n);if(r){var a=E;a.skip?k+=n:(a.rE||a.eE||(k+=n),b(),a.eE&amp;&amp;(k=n));do E.cN&amp;&amp;(L+=C),E.skip||(B+=E.r),E=E.parent;while(E!==r.parent);return r.starts&amp;&amp;v(r.starts,""),a.rE?0:n.length}if(c(n,E))throw new Error('Illegal lexeme "'+n+'" for mode "'+(E.cN||"&lt;unnamed&gt;")+'"');return k+=n,n.length||1}var N=w(e);if(!N)throw new Error('Unknown language: "'+e+'"');s(N);var R,E=i||N,x={},L="";for(R=E;R!==N;R=R.parent)R.cN&amp;&amp;(L=p(R.cN,"",!0)+L);var k="",B=0;try{for(var M,j,O=0;;){if(E.t.lastIndex=O,M=E.t.exec(t),!M)break;j=m(t.substring(O,M.index),M[0]),O=M.index+j}for(m(t.substr(O)),R=E;R.parent;R=R.parent)R.cN&amp;&amp;(L+=C);return{r:B,value:L,language:e,top:E}}catch(T){if(T.message&amp;&amp;-1!==T.message.indexOf("Illegal"))return{r:0,value:n(t)};throw T}}function g(e,t){t=t||I.languages||x(y);var r={r:0,value:n(e)},a=r;return t.filter(w).forEach(function(n){var t=f(n,e,!1);t.language=n,t.r&gt;a.r&amp;&amp;(a=t),t.r&gt;r.r&amp;&amp;(a=r,r=t)}),a.language&amp;&amp;(r.second_best=a),r}function p(e){return I.tabReplace||I.useBR?e.replace(M,function(e,n){return I.useBR&amp;&amp;"\n"===e?"&lt;br&gt;":I.tabReplace?n.replace(/\t/g,I.tabReplace):""}):e}function h(e,n,t){var r=n?L[n]:t,a=[e.trim()];return e.match(/\bhljs\b/)||a.push("hljs"),-1===e.indexOf(r)&amp;&amp;a.push(r),a.join(" ").trim()}function d(e){var n,t,r,o,l,s=i(e);a(s)||(I.useBR?(n=document.createElementNS("http://www.w3.org/1999/xhtml","div"),n.innerHTML=e.innerHTML.replace(/\n/g,"").replace(/&lt;br[ \/]*&gt;/g,"\n")):n=e,l=n.textContent,r=s?f(s,l,!0):g(l),t=u(n),t.length&amp;&amp;(o=document.createElementNS("http://www.w3.org/1999/xhtml","div"),o.innerHTML=r.value,r.value=c(t,u(o),l)),r.value=p(r.value),e.innerHTML=r.value,e.className=h(e.className,s,r.language),e.result={language:r.language,re:r.r},r.second_best&amp;&amp;(e.second_best={language:r.second_best.language,re:r.second_best.r}))}function b(e){I=o(I,e)}function v(){if(!v.called){v.called=!0;var e=document.querySelectorAll("pre code");E.forEach.call(e,d)}}function m(){addEventListener("DOMContentLoaded",v,!1),addEventListener("load",v,!1)}function N(n,t){var r=y[n]=t(e);r.aliases&amp;&amp;r.aliases.forEach(function(e){L[e]=n})}function R(){return x(y)}function w(e){return e=(e||"").toLowerCase(),y[e]||y[L[e]]}var E=[],x=Object.keys,y={},L={},k=/^(no-?highlight|plain|text)$/i,B=/\blang(?:uage)?-([\w-]+)\b/i,M=/((^(&lt;[^&gt;]+&gt;|\t|)+|(?:\n)))/gm,C="&lt;/span&gt;",I={classPrefix:"hljs-",tabReplace:null,useBR:!1,languages:void 0};return e.highlight=f,e.highlightAuto=g,e.fixMarkup=p,e.highlightBlock=d,e.configure=b,e.initHighlighting=v,e.initHighlightingOnLoad=m,e.registerLanguage=N,e.listLanguages=R,e.getLanguage=w,e.inherit=o,e.IR="[a-zA-Z]\\w*",e.UIR="[a-zA-Z_]\\w*",e.NR="\\b\\d+(\\.\\d+)?",e.CNR="(-?)(\\b0[xX][a-fA-F0-9]+|(\\b\\d+(\\.\\d*)?|\\.\\d+)([eE][-+]?\\d+)?)",e.BNR="\\b(0b[01]+)",e.RSR="!|!=|!==|%|%=|&amp;|&amp;&amp;|&amp;=|\\*|\\*=|\\+|\\+=|,|-|-=|/=|/|:|;|&lt;&lt;|&lt;&lt;=|&lt;=|&lt;|===|==|=|&gt;&gt;&gt;=|&gt;&gt;=|&gt;=|&gt;&gt;&gt;|&gt;&gt;|&gt;|\\?|\\[|\\{|\\(|\\^|\\^=|\\||\\|=|\\|\\||~",e.BE={b:"\\\\[\\s\\S]",r:0},e.ASM={cN:"string",b:"'",e:"'",i:"\\n",c:[e.BE]},e.QSM={cN:"string",b:'"',e:'"',i:"\\n",c:[e.BE]},e.PWM={b:/\b(a|an|the|are|I'm|isn't|don't|doesn't|won't|but|just|should|pretty|simply|enough|gonna|going|wtf|so|such|will|you|your|they|like|more)\b/},e.C=function(n,t,r){var a=e.inherit({cN:"comment",b:n,e:t,c:[]},r||{});return a.c.push(e.PWM),a.c.push({cN:"doctag",b:"(?:TODO|FIXME|NOTE|BUG|XXX):",r:0}),a},e.CLCM=e.C("//","$"),e.CBCM=e.C("/\\*","\\*/"),e.HCM=e.C("#","$"),e.NM={cN:"number",b:e.NR,r:0},e.CNM={cN:"number",b:e.CNR,r:0},e.BNM={cN:"number",b:e.BNR,r:0},e.CSSNM={cN:"number",b:e.NR+"(%|em|ex|ch|rem|vw|vh|vmin|vmax|cm|mm|in|pt|pc|px|deg|grad|rad|turn|s|ms|Hz|kHz|dpi|dpcm|dppx)?",r:0},e.RM={cN:"regexp",b:/\//,e:/\/[gimuy]*/,i:/\n/,c:[e.BE,{b:/\[/,e:/\]/,r:0,c:[e.BE]}]},e.TM={cN:"title",b:e.IR,r:0},e.UTM={cN:"title",b:e.UIR,r:0},e.METHOD_GUARD={b:"\\.\\s*"+e.UIR,r:0},e});hljs.registerLanguage("java",function(e){var a="[À-ʸa-zA-Z_$][À-ʸa-zA-Z_$0-9]*",t=a+"(&lt;"+a+"(\\s*,\\s*"+a+")*&gt;)?",r="false synchronized int abstract float private char boolean static null if const for true while long strictfp finally protected import native final void enum else break transient catch instanceof byte super volatile case assert short package default double public try this switch continue throws protected public private module requires exports do",s="\\b(0[bB]([01]+[01_]+[01]+|[01]+)|0[xX]([a-fA-F0-9]+[a-fA-F0-9_]+[a-fA-F0-9]+|[a-fA-F0-9]+)|(([\\d]+[\\d_]+[\\d]+|[\\d]+)(\\.([\\d]+[\\d_]+[\\d]+|[\\d]+))?|\\.([\\d]+[\\d_]+[\\d]+|[\\d]+))([eE][-+]?\\d+)?)[lLfF]?",c={cN:"number",b:s,r:0};return{aliases:["jsp"],k:r,i:/&lt;\/|#/,c:[e.C("/\\*\\*","\\*/",{r:0,c:[{b:/\w+@/,r:0},{cN:"doctag",b:"@[A-Za-z]+"}]}),e.CLCM,e.CBCM,e.ASM,e.QSM,{cN:"class",bK:"class interface",e:/[{;=]/,eE:!0,k:"class interface",i:/[:"\[\]]/,c:[{bK:"extends implements"},e.UTM]},{bK:"new throw return else",r:0},{cN:"function",b:"("+t+"\\s+)+"+e.UIR+"\\s*\\(",rB:!0,e:/[{;=]/,eE:!0,k:r,c:[{b:e.UIR+"\\s*\\(",rB:!0,r:0,c:[e.UTM]},{cN:"params",b:/\(/,e:/\)/,k:r,r:0,c:[e.ASM,e.QSM,e.CNM,e.CBCM]},e.CLCM,e.CBCM]},c,{cN:"meta",b:"@[A-Za-z]+"}]}});
&lt;/script&gt;
&lt;script&gt;hljs.initHighlightingOnLoad();&lt;/script&gt;
&lt;/head&gt;
&lt;body onload='selectjava()'&gt;
&lt;!-- #################################################################### --&gt;

In this article we will learn about If-else control statement.

There are four types of if-else control statement.

&lt;h2&gt;if statement&lt;/h2&gt;

&lt;h3&gt;Syntax&lt;/h3&gt;
&lt;pre&gt;
&lt;code class="java"&gt;
if(condition)
{  
    //code to be executed  
}  
&lt;/code&gt;
&lt;/pre&gt;

&lt;h3&gt;Program&lt;/h3&gt;
&lt;pre&gt;
&lt;code class="java"&gt;
public class If_Example
{
    public static void main(String args[])
    {
        int age = 20;
        if(age &gt; 18)
        {
            System.out.println("You can give vote.");
        }
    }
}

&lt;/code&gt;
  &lt;a href="https://onlinegdb.com/r12ef6p1f"&gt;&lt;button class="button"&gt;&lt;span&gt;Run &lt;/span&gt;&lt;/button&gt;&lt;/a&gt;
&lt;/pre&gt;


&lt;h3&gt;Output&lt;/h3&gt;
&lt;pre&gt;
&lt;code class="java"&gt;
You can give vote.
&lt;/code&gt;  
&lt;/pre&gt;

&lt;h3&gt;Explanation&lt;/h3&gt;
If statement executes the block if the condition becomes true.




&lt;h2&gt;if-else statement&lt;/h2&gt;

&lt;h3&gt;Syntax&lt;/h3&gt;
&lt;pre&gt;
&lt;code class="java"&gt;
if(condition)
{  
    //code if condition is true  
}
else
{  
    //code if condition is false  
}  
&lt;/code&gt;
&lt;/pre&gt;

&lt;h3&gt;Program&lt;/h3&gt;
&lt;pre&gt;
&lt;code class="java"&gt;
public class IfElse_Example
{
    public static void main(String args[])
    {
        int age = 17;
        if(age &gt; 18)
        {
            System.out.println("You can give vote.");
        }
        else
        {
            System.out.println("You can't give vote.");
        }
    }
}
&lt;/code&gt;  
  &lt;a href="https://onlinegdb.com/ByZ4Qp61M"&gt;&lt;button class="button"&gt;&lt;span&gt;Run &lt;/span&gt;&lt;/button&gt;&lt;/a&gt;
&lt;/pre&gt;

&lt;h3&gt;Output&lt;/h3&gt;
&lt;pre&gt;
&lt;code class="java"&gt;
You can't give vote.
&lt;/code&gt;  
&lt;/pre&gt;

&lt;h3&gt;Explanation&lt;/h3&gt;
If condition becomes true then if block will be executed. otherwise else block will be executed.



&lt;h2&gt;nested if statement&lt;/h2&gt;

&lt;h3&gt;Syntax&lt;/h3&gt;
&lt;pre&gt;
&lt;code class="java"&gt;
if (condition1) 
{
   // Executes when condition1 is true
   if (condition2) 
   {
      // Executes when condition2 is true
   }
   else
   {
       // Executes when condition2 is false
   }
}
&lt;/code&gt;
&lt;/pre&gt;

&lt;h3&gt;Program&lt;/h3&gt;
&lt;pre&gt;
&lt;code class="java"&gt;
public class Nested_If
{
    public static void main(String args[])
    {
        int age = 20;
        if(age &gt; 18)
        {
            System.out.println("You can give vote.");
            if(age % 2 == 0)
            {
                System.out.println("Your age is even.");
            }
            else
            {
                System.out.println("Your age is odd.");
            }
        }
    }
}
&lt;/code&gt;  
  &lt;a href="https://onlinegdb.com/rJp9m6akf"&gt;&lt;button class="button"&gt;&lt;span&gt;Run &lt;/span&gt;&lt;/button&gt;&lt;/a&gt;
&lt;/pre&gt;

&lt;h3&gt;Output&lt;/h3&gt;
&lt;pre&gt;
&lt;code class="java"&gt;
You can give vote.
Your age is even.
&lt;/code&gt;  
&lt;/pre&gt;

&lt;h3&gt;Explanation&lt;/h3&gt;
If condition becomes true it executes statement of if block. if there is another if block exists it checks condition if condition becomes true then if block will be executed otherwise else block will be executed.


&lt;h2&gt;if-else-if ladder&lt;/h2&gt;

&lt;h3&gt;Syntax&lt;/h3&gt;
&lt;pre&gt;
&lt;code class="java"&gt;
if(condition1){  
//code to be executed if condition1 is true  
}else if(condition2){  
//code to be executed if condition2 is true  
}  
else if(condition3){  
//code to be executed if condition3 is true  
}  
...  
else{  
//code to be executed if all the conditions are false  
}  
&lt;/code&gt;
&lt;/pre&gt;

&lt;h3&gt;Program&lt;/h3&gt;
&lt;pre&gt;
&lt;code class="java"&gt;
public class IfElse_leader
{
    public static void main(String args[])
    {
        int age = 22;
        if(age &lt; 12)
        {
            System.out.println("You are child.");
        }
        else if(age &gt; 12 &amp;&amp; age &lt; 20)
        {
            System.out.println("You are teenager.");
        }
        else if(age &gt; 20 &amp;&amp; age &lt; 50)
        {
            System.out.println("You are mature.");
        }
        else
        {
            System.out.println("You are old.");
        }
    }
}
&lt;/code&gt;  
  &lt;a href="https://onlinegdb.com/HyZm46pJf"&gt;&lt;button class="button"&gt;&lt;span&gt;Run &lt;/span&gt;&lt;/button&gt;&lt;/a&gt;
&lt;/pre&gt;

&lt;h3&gt;Output&lt;/h3&gt;
&lt;pre&gt;
&lt;code class="java"&gt;
You are mature.
&lt;/code&gt;  
&lt;/pre&gt;

&lt;h3&gt;Explanation&lt;/h3&gt;
Here, if condition becomes true then it's block will be executed and rest of the condition will be ignored. If all conditions become false then else block will be executed.
&lt;!-- ####################################################################### --&gt;
&lt;/body&gt;
&lt;/html&gt;</description><link>http://tangled-java.blogspot.com/2017/11/if-else-control-statement.html</link><author>noreply@blogger.com (Anonymous)</author><thr:total>0</thr:total></item><item><guid isPermaLink="false">tag:blogger.com,1999:blog-3082064622906880860.post-4275768425126435298</guid><pubDate>Sat, 18 Nov 2017 11:14:00 +0000</pubDate><atom:updated>2017-11-27T00:15:37.362-08:00</atom:updated><title>Comments in Java</title><description>&lt;!DOCTYPE html&gt;
&lt;html&gt;
&lt;head&gt;
 &lt;title&gt;&lt;/title&gt;
 &lt;style type="text/css"&gt;
  pre{ 
   border-left: 5px solid lightgreen;
   padding-left: 5px;
   background: rgba(96,96,96,0.3); 
   color: white;
   line-height: 7px;
   font-size: 16.5px;
  }
  h2{ 
   background-color: lightgrey;
   padding: 3px 5px;
   color: #1e1e1e;
  }
  h3{ 
   color: white; 
  }
  .button {
    border-radius: 4px;
    background-color: #f4511e;
    border: none;
    color: #FFFFFF;
    text-align: center;
    font-size: 28px;
    padding: 10px;
    width: 150px;
    height: 50px;
    transition: all 0.5s;
    cursor: pointer;
    margin: 5px;
    float: right;
    margin-top: -50px;
  }

  .button span {
    cursor: pointer;
    display: inline-block;
    position: relative;
    transition: 0.5s;
  }

  .button span:after {
    content: '\00bb';
    position: absolute;
    opacity: 0;
    top: 0;
    right: -20px;
    transition: 0.5s;
  }

  .button:hover span {
    padding-right: 25px;
  }

  .button:hover span:after {
    opacity: 1;
    right: 0;
  }
 &lt;/style&gt;
&lt;/head&gt;
&lt;body onload='selectjava()'&gt;

The java comments are statements that are not executed by the compiler and interpreter. The comments can be used to provide information or explanation about the variable, method, class or any statement. It can also be used to hide program code for specific time.

&lt;h2&gt;Three types of comment in Java&lt;/h2&gt;
&lt;h2&gt;1. Single line comment&lt;/h2&gt;

&lt;h3&gt;Syntax&lt;/h3&gt;
&lt;pre&gt;
&lt;div&gt;
&lt;span style="color: #608b4e;"&gt;// This is single line comment&lt;/span&gt;&lt;/div&gt;
&lt;div&gt;
&lt;span style="color: #608b4e;"&gt;// This line won't be executed&lt;/span&gt;&lt;/div&gt;
&lt;/pre&gt;

&lt;h3&gt;Program&lt;/h3&gt;
&lt;pre&gt;
 &lt;div&gt;
&lt;span style="color: #569cd6;"&gt;public&lt;/span&gt; &lt;span style="color: #569cd6;"&gt;class&lt;/span&gt; SingleLineComment&lt;/div&gt;
&lt;div&gt;
{&lt;/div&gt;
&lt;div&gt;
    &lt;span style="color: #569cd6;"&gt;public&lt;/span&gt; &lt;span style="color: #569cd6;"&gt;static&lt;/span&gt; &lt;span style="color: #569cd6;"&gt;void&lt;/span&gt; main(&lt;span style="color: #569cd6;"&gt;String&lt;/span&gt; args[])&lt;/div&gt;
&lt;div&gt;
    {&lt;/div&gt;
&lt;div&gt;
        &lt;span style="color: #608b4e;"&gt;// break keyword example&lt;/span&gt;&lt;/div&gt;
&lt;div&gt;
        &lt;span style="color: #569cd6;"&gt;for&lt;/span&gt;(&lt;span style="color: #569cd6;"&gt;int&lt;/span&gt; i=&lt;span style="color: #b5cea8;"&gt;1&lt;/span&gt;; i&amp;lt;=&lt;span style="color: #b5cea8;"&gt;10&lt;/span&gt;; i++)&lt;/div&gt;
&lt;div&gt;
        {&lt;/div&gt;
&lt;div&gt;
            &lt;span style="color: #569cd6;"&gt;if&lt;/span&gt;(i==&lt;span style="color: #b5cea8;"&gt;6&lt;/span&gt;)&lt;/div&gt;
&lt;div&gt;
            {&lt;/div&gt;
&lt;div&gt;
                &lt;span style="color: #569cd6;"&gt;break&lt;/span&gt;;&lt;/div&gt;
&lt;div&gt;
            }&lt;/div&gt;
&lt;div&gt;
            System.out.println(i);&lt;/div&gt;
&lt;div&gt;
        }&lt;/div&gt;
&lt;div&gt;
    }&lt;/div&gt;
&lt;div&gt;
}&lt;/div&gt;
 &lt;a href="https://onlinegdb.com/HkeUr9aJf"&gt;&lt;button class="button"&gt;&lt;span&gt;Run &lt;/span&gt;&lt;/button&gt;&lt;/a&gt;
&lt;/pre&gt;

&lt;h3&gt;Output&lt;/h3&gt;
&lt;pre&gt;
 &lt;div dir="ltr" style="text-align: left;" trbidi="on"&gt;
&lt;div&gt;
&lt;span style="color: #569cd6;"&gt;1&lt;/span&gt;&lt;/div&gt;
&lt;div&gt;
&lt;span style="color: #569cd6;"&gt;2&lt;/span&gt;&lt;/div&gt;
&lt;div&gt;
&lt;span style="color: #569cd6;"&gt;3&lt;/span&gt;&lt;/div&gt;
&lt;div&gt;
&lt;span style="color: #569cd6;"&gt;4&lt;/span&gt;&lt;/div&gt;
&lt;div&gt;
&lt;span style="color: #569cd6;"&gt;5&lt;/span&gt;&lt;/div&gt;
&lt;/div&gt;

&lt;/pre&gt;

&lt;h2&gt;2. Multi line comment&lt;/h2&gt;

&lt;h3&gt;Syntax&lt;/h3&gt;
&lt;pre&gt;
&lt;div&gt;
&lt;span style="color: #608b4e;"&gt;/* This is multi &lt;/span&gt;&lt;/div&gt;
&lt;div&gt;
&lt;span style="color: #608b4e;"&gt;line commment&lt;/span&gt;&lt;/div&gt;
&lt;div&gt;
&lt;span style="color: #608b4e;"&gt; This line won't &lt;/span&gt;&lt;/div&gt;
&lt;div&gt;
&lt;span style="color: #608b4e;"&gt; be executed */&lt;/span&gt;&lt;/div&gt;
&lt;/pre&gt;

&lt;h3&gt;Program&lt;/h3&gt;
&lt;pre&gt;
 &lt;div&gt;
&lt;span style="color: #569cd6;"&gt;public&lt;/span&gt; &lt;span style="color: #569cd6;"&gt;class&lt;/span&gt; MultiLineComment&lt;/div&gt;
&lt;div&gt;
{&lt;/div&gt;
&lt;div&gt;
    &lt;span style="color: #569cd6;"&gt;public&lt;/span&gt; &lt;span style="color: #569cd6;"&gt;static&lt;/span&gt; &lt;span style="color: #569cd6;"&gt;void&lt;/span&gt; main(&lt;span style="color: #569cd6;"&gt;String&lt;/span&gt; args[])&lt;/div&gt;
&lt;div&gt;
    {&lt;/div&gt;
&lt;div&gt;
        &lt;span style="color: #569cd6;"&gt;for&lt;/span&gt;(&lt;span style="color: #569cd6;"&gt;int&lt;/span&gt; i=&lt;span style="color: #b5cea8;"&gt;1&lt;/span&gt;; i&amp;lt;=&lt;span style="color: #b5cea8;"&gt;10&lt;/span&gt;; i++)&lt;/div&gt;
&lt;div&gt;
        {&lt;/div&gt;
&lt;div&gt;
            &lt;span style="color: #608b4e;"&gt;/* Exmple of&lt;/span&gt;&lt;/div&gt;
&lt;div&gt;
&lt;span style="color: #608b4e;"&gt;            break&lt;/span&gt;&lt;/div&gt;
&lt;div&gt;
&lt;span style="color: #608b4e;"&gt;            keyword */&lt;/span&gt;&lt;/div&gt;
&lt;div&gt;
            &lt;span style="color: #569cd6;"&gt;if&lt;/span&gt;(i==&lt;span style="color: #b5cea8;"&gt;6&lt;/span&gt;)&lt;/div&gt;
&lt;div&gt;
            {&lt;/div&gt;
&lt;div&gt;
                &lt;span style="color: #569cd6;"&gt;break&lt;/span&gt;;&lt;/div&gt;
&lt;div&gt;
            }&lt;/div&gt;
&lt;div&gt;
            System.out.println(i);&lt;/div&gt;
&lt;div&gt;
        }&lt;/div&gt;
&lt;div&gt;
    }&lt;/div&gt;
&lt;div&gt;
}&lt;/div&gt;
 &lt;a href="https://onlinegdb.com/SkWYr9TkG"&gt;&lt;button class="button"&gt;&lt;span&gt;Run &lt;/span&gt;&lt;/button&gt;&lt;/a&gt;
&lt;/pre&gt;

&lt;h3&gt;Output&lt;/h3&gt;
&lt;pre&gt;
 &lt;div dir="ltr" style="text-align: left;" trbidi="on"&gt;
&lt;div&gt;
&lt;span style="color: #569cd6;"&gt;1&lt;/span&gt;&lt;/div&gt;
&lt;div&gt;
&lt;span style="color: #569cd6;"&gt;2&lt;/span&gt;&lt;/div&gt;
&lt;div&gt;
&lt;span style="color: #569cd6;"&gt;3&lt;/span&gt;&lt;/div&gt;
&lt;div&gt;
&lt;span style="color: #569cd6;"&gt;4&lt;/span&gt;&lt;/div&gt;
&lt;div&gt;
&lt;span style="color: #569cd6;"&gt;5&lt;/span&gt;&lt;/div&gt;
&lt;/div&gt;

&lt;/pre&gt;

&lt;h2&gt;3. Documentation comment&lt;/h2&gt;

&lt;h3&gt;Syntax&lt;/h3&gt;
&lt;pre&gt;
&lt;div&gt;
&lt;span style="color: #608b4e;"&gt;/** This is &lt;/span&gt;&lt;/div&gt;
&lt;div&gt;
&lt;span style="color: #608b4e;"&gt; documentation&lt;/span&gt;&lt;/div&gt;
&lt;div&gt;
&lt;span style="color: #608b4e;"&gt;  comment */&lt;/span&gt;&lt;/div&gt;
&lt;/pre&gt;

&lt;h3&gt;Program&lt;/h3&gt;
&lt;pre&gt;
 &lt;div&gt;
&lt;span style="color: #569cd6;"&gt;public&lt;/span&gt; &lt;span style="color: #569cd6;"&gt;class&lt;/span&gt; DocComment&lt;/div&gt;
&lt;div&gt;
{&lt;/div&gt;
&lt;div&gt;
    &lt;span style="color: #569cd6;"&gt;public&lt;/span&gt; &lt;span style="color: #569cd6;"&gt;static&lt;/span&gt; &lt;span style="color: #569cd6;"&gt;void&lt;/span&gt; main(&lt;span style="color: #569cd6;"&gt;String&lt;/span&gt; args[])&lt;/div&gt;
&lt;div&gt;
    {&lt;/div&gt;
&lt;div&gt;
        &lt;/div&gt;
&lt;div&gt;
    }&lt;/div&gt;
&lt;div&gt;
&lt;span style="color: #608b4e;"&gt;    /** The add() method returns addition of given numbers.*/&lt;/span&gt;  &lt;/div&gt;
&lt;div&gt;
    &lt;span style="color: #569cd6;"&gt;public&lt;/span&gt; &lt;span style="color: #569cd6;"&gt;static&lt;/span&gt; &lt;span style="color: #569cd6;"&gt;int&lt;/span&gt; add(&lt;span style="color: #569cd6;"&gt;int&lt;/span&gt; a, &lt;span style="color: #569cd6;"&gt;int&lt;/span&gt; b)&lt;/div&gt;
&lt;div&gt;
    {&lt;/div&gt;
&lt;div&gt;
        &lt;span style="color: #569cd6;"&gt;return&lt;/span&gt; a+b;&lt;/div&gt;
&lt;div&gt;
    }  &lt;/div&gt;
&lt;div&gt;
&lt;span style="color: #608b4e;"&gt;    /** The div() method returns divison of given numbers.*/&lt;/span&gt;  &lt;/div&gt;
&lt;div&gt;
    &lt;span style="color: #569cd6;"&gt;public&lt;/span&gt; &lt;span style="color: #569cd6;"&gt;static&lt;/span&gt; &lt;span style="color: #569cd6;"&gt;int&lt;/span&gt; div(&lt;span style="color: #569cd6;"&gt;int&lt;/span&gt; a, &lt;span style="color: #569cd6;"&gt;int&lt;/span&gt; b)&lt;/div&gt;
&lt;div&gt;
    {&lt;/div&gt;
&lt;div&gt;
        &lt;span style="color: #569cd6;"&gt;return&lt;/span&gt; a/b;&lt;/div&gt;
&lt;div&gt;
    }  &lt;/div&gt;
&lt;div&gt;
}&lt;/div&gt;
 &lt;a href="https://onlinegdb.com/HyAnScTkz"&gt;&lt;button class="button"&gt;&lt;span&gt;Run &lt;/span&gt;&lt;/button&gt;&lt;/a&gt;
&lt;/pre&gt;

&lt;h3&gt;Output&lt;/h3&gt;
&lt;pre&gt;

javac DocComment.java

javadoc DocComment.java

&lt;/pre&gt;

&lt;h3&gt;Explanation&lt;/h3&gt;
The documentation comment is used to create documentation API. To create documentation API, you need to use javadoc tool.
Now, there will be HTML files created for your Calculator class in the current directory. Open the HTML files and see the explanation of Calculator class provided through documentation comment.

&lt;/body&gt;
&lt;/html&gt;</description><link>http://tangled-java.blogspot.com/2017/11/comments-in-java.html</link><author>noreply@blogger.com (Anonymous)</author><thr:total>0</thr:total></item><item><guid isPermaLink="false">tag:blogger.com,1999:blog-3082064622906880860.post-2329125354117112850</guid><pubDate>Sat, 18 Nov 2017 07:28:00 +0000</pubDate><atom:updated>2017-11-27T00:11:22.907-08:00</atom:updated><category domain="http://www.blogger.com/atom/ns#">break</category><category domain="http://www.blogger.com/atom/ns#">continue</category><category domain="http://www.blogger.com/atom/ns#">Java</category><title>continue keyword in Java</title><description>&lt;!DOCTYPE html&gt;
&lt;html&gt;
&lt;head&gt;
 &lt;title&gt;&lt;/title&gt;
 &lt;style type="text/css"&gt;
  pre{ 
   border-left: 5px solid lightgreen;
   padding-left: 5px;
   background: rgba(96,96,96,0.3); 
   color: white;
   line-height: 7px;
   font-size: 16.5px;
  }
  h2{ 
   background-color: lightgrey;
   padding: 3px 5px;
   color: #1e1e1e;
  }
  h3{ 
   color: white; 
  }
  .button {
    border-radius: 4px;
    background-color: #f4511e;
    border: none;
    color: #FFFFFF;
    text-align: center;
    font-size: 28px;
    padding: 10px;
    width: 150px;
    height: 50px;
    transition: all 0.5s;
    cursor: pointer;
    margin: 5px;
    float: right;
    margin-top: -50px;
  }

  .button span {
    cursor: pointer;
    display: inline-block;
    position: relative;
    transition: 0.5s;
  }

  .button span:after {
    content: '\00bb';
    position: absolute;
    opacity: 0;
    top: 0;
    right: -20px;
    transition: 0.5s;
  }

  .button:hover span {
    padding-right: 25px;
  }

  .button:hover span:after {
    opacity: 1;
    right: 0;
  }
 &lt;/style&gt;
&lt;/head&gt;
&lt;body onload='selectjava()'&gt;

&lt;h2&gt;continue keyword in Java&lt;/h2&gt;

&lt;h3&gt;Syntax&lt;/h3&gt;
&lt;pre&gt;
&lt;div&gt;
&lt;span style="color: #608b4e;"&gt;// condition  &lt;/span&gt;&lt;/div&gt;
&lt;div&gt;
    &lt;span style="color: #569cd6;"&gt;continue&lt;/span&gt;;  &lt;/div&gt;
&lt;/pre&gt;

&lt;h3&gt;Program&lt;/h3&gt;
&lt;pre&gt;
 &lt;div&gt;
&lt;span style="color: #569cd6;"&gt;public&lt;/span&gt; &lt;span style="color: #569cd6;"&gt;class&lt;/span&gt; continue_demo&lt;/div&gt;
&lt;div&gt;
{&lt;/div&gt;
&lt;div&gt;
    &lt;span style="color: #569cd6;"&gt;public&lt;/span&gt; &lt;span style="color: #569cd6;"&gt;static&lt;/span&gt; &lt;span style="color: #569cd6;"&gt;void&lt;/span&gt; main(&lt;span style="color: #569cd6;"&gt;String&lt;/span&gt; args[])&lt;/div&gt;
&lt;div&gt;
    {&lt;/div&gt;
&lt;div&gt;
        &lt;span style="color: #569cd6;"&gt;for&lt;/span&gt;(&lt;span style="color: #569cd6;"&gt;int&lt;/span&gt; i=&lt;span style="color: #b5cea8;"&gt;1&lt;/span&gt;; i&amp;lt;=&lt;span style="color: #b5cea8;"&gt;10&lt;/span&gt;; i++)&lt;/div&gt;
&lt;div&gt;
        {&lt;/div&gt;
&lt;div&gt;
            &lt;span style="color: #569cd6;"&gt;if&lt;/span&gt;(i==&lt;span style="color: #b5cea8;"&gt;6&lt;/span&gt;)&lt;/div&gt;
&lt;div&gt;
            {&lt;/div&gt;
&lt;div&gt;
                &lt;span style="color: #569cd6;"&gt;continue&lt;/span&gt;;&lt;/div&gt;
&lt;div&gt;
            }&lt;/div&gt;
&lt;div&gt;
            System.out.println(i);&lt;/div&gt;
&lt;div&gt;
        }&lt;/div&gt;
&lt;div&gt;
    }&lt;/div&gt;
&lt;div&gt;
}&lt;/div&gt;
 &lt;a href="https://onlinegdb.com/HJeRigwpkG"&gt;&lt;button class="button"&gt;&lt;span&gt;Run &lt;/span&gt;&lt;/button&gt;&lt;/a&gt;
&lt;/pre&gt;

&lt;h3&gt;Output&lt;/h3&gt;
&lt;pre&gt;
 &lt;div dir="ltr" style="text-align: left;" trbidi="on"&gt;
&lt;div&gt;
&lt;span style="color: #569cd6;"&gt;1&lt;/span&gt;&lt;/div&gt;
&lt;div&gt;
&lt;span style="color: #569cd6;"&gt;2&lt;/span&gt;&lt;/div&gt;
&lt;div&gt;
&lt;span style="color: #569cd6;"&gt;3&lt;/span&gt;&lt;/div&gt;
&lt;div&gt;
&lt;span style="color: #569cd6;"&gt;4&lt;/span&gt;&lt;/div&gt;
&lt;div&gt;
&lt;span style="color: #569cd6;"&gt;5&lt;/span&gt;&lt;/div&gt;
&lt;div&gt;
&lt;span style="color: #569cd6;"&gt;7&lt;/span&gt;&lt;/div&gt;
&lt;div&gt;
&lt;span style="color: #569cd6;"&gt;8&lt;/span&gt;&lt;/div&gt;
&lt;div&gt;
&lt;span style="color: #569cd6;"&gt;9&lt;/span&gt;&lt;/div&gt;
&lt;div&gt;
&lt;span style="color: #569cd6;"&gt;10&lt;/span&gt;&lt;/div&gt;
&lt;/div&gt;

&lt;/pre&gt;

&lt;h3&gt;Explanation&lt;/h3&gt;
The Java continue statement is used to continue loop. It continues the current flow of the program and skips the remaining code at specified condition.

&lt;h2&gt;continue keyword in innerloop&lt;/h2&gt;


&lt;h3&gt;Program&lt;/h3&gt;
&lt;pre&gt;
 &lt;div&gt;
&lt;span style="color: #569cd6;"&gt;public&lt;/span&gt; &lt;span style="color: #569cd6;"&gt;class&lt;/span&gt; continue_inner&lt;/div&gt;
&lt;div&gt;
{&lt;/div&gt;
&lt;div&gt;
    &lt;span style="color: #569cd6;"&gt;public&lt;/span&gt; &lt;span style="color: #569cd6;"&gt;static&lt;/span&gt; &lt;span style="color: #569cd6;"&gt;void&lt;/span&gt; main(&lt;span style="color: #569cd6;"&gt;String&lt;/span&gt; args[])&lt;/div&gt;
&lt;div&gt;
    {&lt;/div&gt;
&lt;div&gt;
        &lt;span style="color: #569cd6;"&gt;for&lt;/span&gt;(&lt;span style="color: #569cd6;"&gt;int&lt;/span&gt; i=&lt;span style="color: #b5cea8;"&gt;1&lt;/span&gt;; i&amp;lt;=&lt;span style="color: #b5cea8;"&gt;5&lt;/span&gt;; i++)&lt;/div&gt;
&lt;div&gt;
        {&lt;/div&gt;
&lt;div&gt;
            &lt;span style="color: #569cd6;"&gt;for&lt;/span&gt;(&lt;span style="color: #569cd6;"&gt;int&lt;/span&gt; j=&lt;span style="color: #b5cea8;"&gt;1&lt;/span&gt;; j&amp;lt;=&lt;span style="color: #b5cea8;"&gt;5&lt;/span&gt;; j++)&lt;/div&gt;
&lt;div&gt;
            {&lt;/div&gt;
&lt;div&gt;
                &lt;span style="color: #569cd6;"&gt;if&lt;/span&gt;(i==&lt;span style="color: #b5cea8;"&gt;3&lt;/span&gt; &amp;amp;&amp;amp; j==&lt;span style="color: #b5cea8;"&gt;3&lt;/span&gt;)&lt;/div&gt;
&lt;div&gt;
                {&lt;/div&gt;
&lt;div&gt;
                    &lt;span style="color: #569cd6;"&gt;continue&lt;/span&gt;;&lt;/div&gt;
&lt;div&gt;
                }&lt;/div&gt;
&lt;div&gt;
                System.out.println(i + &lt;span style="color: #ce9178;"&gt;"-"&lt;/span&gt; + j);&lt;/div&gt;
&lt;div&gt;
            }&lt;/div&gt;
&lt;div&gt;
        }&lt;/div&gt;
&lt;div&gt;
    }&lt;/div&gt;
&lt;div&gt;
}&lt;/div&gt;
 &lt;a href="https://onlinegdb.com/r1XxbDTJM"&gt;&lt;button class="button"&gt;&lt;span&gt;Run &lt;/span&gt;&lt;/button&gt;&lt;/a&gt;
&lt;/pre&gt;

&lt;h3&gt;Output&lt;/h3&gt;
&lt;pre&gt;
 &lt;div dir="ltr" style="text-align: left;" trbidi="on"&gt;
&lt;div&gt;
&lt;span style="color: #569cd6;"&gt;1-1&lt;/span&gt;&lt;/div&gt;
&lt;div&gt;
&lt;span style="color: #569cd6;"&gt;1-2&lt;/span&gt;&lt;/div&gt;
&lt;div&gt;
&lt;span style="color: #569cd6;"&gt;1-3&lt;/span&gt;&lt;/div&gt;
&lt;div&gt;
&lt;span style="color: #569cd6;"&gt;1-4&lt;/span&gt;&lt;/div&gt;
&lt;div&gt;
&lt;span style="color: #569cd6;"&gt;1-5&lt;/span&gt;&lt;/div&gt;
&lt;div&gt;
&lt;span style="color: #569cd6;"&gt;2-1&lt;/span&gt;&lt;/div&gt;
&lt;div&gt;
&lt;span style="color: #569cd6;"&gt;2-2&lt;/span&gt;&lt;/div&gt;
&lt;div&gt;
&lt;span style="color: #569cd6;"&gt;2-3&lt;/span&gt;&lt;/div&gt;
&lt;div&gt;
&lt;span style="color: #569cd6;"&gt;2-4&lt;/span&gt;&lt;/div&gt;
&lt;div&gt;
&lt;span style="color: #569cd6;"&gt;2-5&lt;/span&gt;&lt;/div&gt;
&lt;div&gt;
&lt;span style="color: #569cd6;"&gt;3-1&lt;/span&gt;&lt;/div&gt;
&lt;div&gt;
&lt;span style="color: #569cd6;"&gt;3-2&lt;/span&gt;&lt;/div&gt;
&lt;div&gt;
&lt;span style="color: #569cd6;"&gt;3-4&lt;/span&gt;&lt;/div&gt;
&lt;div&gt;
&lt;span style="color: #569cd6;"&gt;3-5&lt;/span&gt;&lt;/div&gt;
&lt;div&gt;
&lt;span style="color: #569cd6;"&gt;4-1&lt;/span&gt;&lt;/div&gt;
&lt;div&gt;
&lt;span style="color: #569cd6;"&gt;4-2&lt;/span&gt;&lt;/div&gt;
&lt;div&gt;
&lt;span style="color: #569cd6;"&gt;4-3&lt;/span&gt;&lt;/div&gt;
&lt;div&gt;
&lt;span style="color: #569cd6;"&gt;4-4&lt;/span&gt;&lt;/div&gt;
&lt;div&gt;
&lt;span style="color: #569cd6;"&gt;4-5&lt;/span&gt;&lt;/div&gt;
&lt;div&gt;
&lt;span style="color: #569cd6;"&gt;5-1&lt;/span&gt;&lt;/div&gt;
&lt;div&gt;
&lt;span style="color: #569cd6;"&gt;5-2&lt;/span&gt;&lt;/div&gt;
&lt;div&gt;
&lt;span style="color: #569cd6;"&gt;5-3&lt;/span&gt;&lt;/div&gt;
&lt;div&gt;
&lt;span style="color: #569cd6;"&gt;5-4&lt;/span&gt;&lt;/div&gt;
&lt;div&gt;
&lt;span style="color: #569cd6;"&gt;5-5&lt;/span&gt;&lt;/div&gt;
&lt;/div&gt;

&lt;/pre&gt;

&lt;h3&gt;Explanation&lt;/h3&gt;
It continues inner loop only if you use continue statement inside the inner loop.
&lt;/body&gt;
&lt;/html&gt;</description><link>http://tangled-java.blogspot.com/2017/11/continue-keyword-in-java.html</link><author>noreply@blogger.com (Anonymous)</author><thr:total>0</thr:total></item><item><guid isPermaLink="false">tag:blogger.com,1999:blog-3082064622906880860.post-3248622425967384192</guid><pubDate>Sat, 18 Nov 2017 06:29:00 +0000</pubDate><atom:updated>2017-11-27T00:11:03.356-08:00</atom:updated><category domain="http://www.blogger.com/atom/ns#">break</category><category domain="http://www.blogger.com/atom/ns#">continue</category><category domain="http://www.blogger.com/atom/ns#">Java</category><title>break keyword</title><description>&lt;!DOCTYPE html&gt;
&lt;html&gt;
&lt;head&gt;
 &lt;title&gt;&lt;/title&gt;
 &lt;style type="text/css"&gt;
  pre{ 
   border-left: 5px solid lightgreen;
   padding-left: 5px;
   background: rgba(96,96,96,0.3); 
   color: white;
   line-height: 7px;
   font-size: 16.5px;
  }
  h2{ 
   background-color: lightgrey;
   padding: 3px 5px;
   color: #1e1e1e;
  }
  h3{ 
   color: white; 
  }
  .button {
    border-radius: 4px;
    background-color: #f4511e;
    border: none;
    color: #FFFFFF;
    text-align: center;
    font-size: 28px;
    padding: 10px;
    width: 150px;
    height: 50px;
    transition: all 0.5s;
    cursor: pointer;
    margin: 5px;
    float: right;
    margin-top: -50px;
  }

  .button span {
    cursor: pointer;
    display: inline-block;
    position: relative;
    transition: 0.5s;
  }

  .button span:after {
    content: '\00bb';
    position: absolute;
    opacity: 0;
    top: 0;
    right: -20px;
    transition: 0.5s;
  }

  .button:hover span {
    padding-right: 25px;
  }

  .button:hover span:after {
    opacity: 1;
    right: 0;
  }
 &lt;/style&gt;
&lt;/head&gt;
&lt;body onload='selectjava()'&gt;

&lt;h2&gt;break keyword in Java&lt;/h2&gt;

&lt;h3&gt;Syntax&lt;/h3&gt;
&lt;pre&gt;
&lt;div&gt;
&lt;span style="color: #608b4e;"&gt;// condition&lt;/span&gt;&lt;/div&gt;
&lt;div&gt;
    &lt;span style="color: #569cd6;"&gt;break&lt;/span&gt;;&lt;/div&gt;
&lt;/pre&gt;

&lt;h3&gt;Program&lt;/h3&gt;
&lt;pre&gt;
 &lt;div&gt;
&lt;span style="color: #569cd6;"&gt;public&lt;/span&gt; &lt;span style="color: #569cd6;"&gt;class&lt;/span&gt; break_demo&lt;/div&gt;
&lt;div&gt;
{&lt;/div&gt;
&lt;div&gt;
    &lt;span style="color: #569cd6;"&gt;public&lt;/span&gt; &lt;span style="color: #569cd6;"&gt;static&lt;/span&gt; &lt;span style="color: #569cd6;"&gt;void&lt;/span&gt; main(&lt;span style="color: #569cd6;"&gt;String&lt;/span&gt; args[])&lt;/div&gt;
&lt;div&gt;
    {&lt;/div&gt;
&lt;div&gt;
        &lt;span style="color: #569cd6;"&gt;for&lt;/span&gt;(&lt;span style="color: #569cd6;"&gt;int&lt;/span&gt; i=&lt;span style="color: #b5cea8;"&gt;1&lt;/span&gt;; i&amp;lt;=&lt;span style="color: #b5cea8;"&gt;10&lt;/span&gt;; i++)&lt;/div&gt;
&lt;div&gt;
        {&lt;/div&gt;
&lt;div&gt;
            &lt;span style="color: #569cd6;"&gt;if&lt;/span&gt;(i==&lt;span style="color: #b5cea8;"&gt;6&lt;/span&gt;)&lt;/div&gt;
&lt;div&gt;
            {&lt;/div&gt;
&lt;div&gt;
                &lt;span style="color: #569cd6;"&gt;break&lt;/span&gt;;&lt;/div&gt;
&lt;div&gt;
            }&lt;/div&gt;
&lt;div&gt;
            System.out.println(i);&lt;/div&gt;
&lt;div&gt;
        }&lt;/div&gt;
&lt;div&gt;
    }&lt;/div&gt;
&lt;div&gt;
}&lt;/div&gt;
 &lt;a href="https://onlinegdb.com/rJipGUTyz"&gt;&lt;button class="button"&gt;&lt;span&gt;Run &lt;/span&gt;&lt;/button&gt;&lt;/a&gt;
&lt;/pre&gt;

&lt;h3&gt;Output&lt;/h3&gt;
&lt;pre&gt;
 &lt;div dir="ltr" style="text-align: left;" trbidi="on"&gt;
&lt;div&gt;
&lt;span style="color: #569cd6;"&gt;1&lt;/span&gt;&lt;/div&gt;
&lt;div&gt;
&lt;span style="color: #569cd6;"&gt;2&lt;/span&gt;&lt;/div&gt;
&lt;div&gt;
&lt;span style="color: #569cd6;"&gt;3&lt;/span&gt;&lt;/div&gt;
&lt;div&gt;
&lt;span style="color: #569cd6;"&gt;4&lt;/span&gt;&lt;/div&gt;
&lt;div&gt;
&lt;span style="color: #569cd6;"&gt;5&lt;/span&gt;&lt;/div&gt;
&lt;/div&gt;

&lt;/pre&gt;

&lt;h3&gt;Explanation&lt;/h3&gt;
The Java break is used to break loop or switch statement. It breaks the current flow of the program at specified condition.

&lt;h2&gt;break keyword in inner loop&lt;/h2&gt;


&lt;h3&gt;Program&lt;/h3&gt;
&lt;pre&gt;
 &lt;div&gt;
&lt;span style="color: #569cd6;"&gt;public&lt;/span&gt; &lt;span style="color: #569cd6;"&gt;class&lt;/span&gt; break_inner&lt;/div&gt;
&lt;div&gt;
{&lt;/div&gt;
&lt;div&gt;
    &lt;span style="color: #569cd6;"&gt;public&lt;/span&gt; &lt;span style="color: #569cd6;"&gt;static&lt;/span&gt; &lt;span style="color: #569cd6;"&gt;void&lt;/span&gt; main(&lt;span style="color: #569cd6;"&gt;String&lt;/span&gt; args[])&lt;/div&gt;
&lt;div&gt;
    {&lt;/div&gt;
&lt;div&gt;
        &lt;span style="color: #569cd6;"&gt;for&lt;/span&gt;(&lt;span style="color: #569cd6;"&gt;int&lt;/span&gt; i=&lt;span style="color: #b5cea8;"&gt;1&lt;/span&gt;; i&amp;lt;=&lt;span style="color: #b5cea8;"&gt;5&lt;/span&gt;; i++)&lt;/div&gt;
&lt;div&gt;
        {&lt;/div&gt;
&lt;div&gt;
            &lt;span style="color: #569cd6;"&gt;for&lt;/span&gt;(&lt;span style="color: #569cd6;"&gt;int&lt;/span&gt; j=&lt;span style="color: #b5cea8;"&gt;1&lt;/span&gt;; j&amp;lt;=&lt;span style="color: #b5cea8;"&gt;5&lt;/span&gt;; j++)&lt;/div&gt;
&lt;div&gt;
            {&lt;/div&gt;
&lt;div&gt;
                &lt;span style="color: #569cd6;"&gt;if&lt;/span&gt;(i==&lt;span style="color: #b5cea8;"&gt;3&lt;/span&gt; &amp;amp;&amp;amp; j==&lt;span style="color: #b5cea8;"&gt;3&lt;/span&gt;)&lt;/div&gt;
&lt;div&gt;
                {&lt;/div&gt;
&lt;div&gt;
                    &lt;span style="color: #569cd6;"&gt;break&lt;/span&gt;;&lt;/div&gt;
&lt;div&gt;
                }&lt;/div&gt;
&lt;div&gt;
                System.out.println(i + &lt;span style="color: #ce9178;"&gt;"-"&lt;/span&gt; + j);&lt;/div&gt;
&lt;div&gt;
            }&lt;/div&gt;
&lt;div&gt;
        }&lt;/div&gt;
&lt;div&gt;
    }&lt;/div&gt;
&lt;div&gt;
}&lt;/div&gt;
 &lt;a href="https://onlinegdb.com/S1iZQL6JG"&gt;&lt;button class="button"&gt;&lt;span&gt;Run &lt;/span&gt;&lt;/button&gt;&lt;/a&gt;
&lt;/pre&gt;

&lt;h3&gt;Output&lt;/h3&gt;
&lt;pre&gt;
 &lt;div dir="ltr" style="text-align: left;" trbidi="on"&gt;
&lt;div&gt;
1-1&lt;/div&gt;
&lt;div&gt;
1-2&lt;/div&gt;
&lt;div&gt;
1-3&lt;/div&gt;
&lt;div&gt;
1-4&lt;/div&gt;
&lt;div&gt;
1-5&lt;/div&gt;
&lt;div&gt;
2-1&lt;/div&gt;
&lt;div&gt;
2-2&lt;/div&gt;
&lt;div&gt;
2-3&lt;/div&gt;
&lt;div&gt;
2-4&lt;/div&gt;
&lt;div&gt;
2-5&lt;/div&gt;
&lt;div&gt;
3-1&lt;/div&gt;
&lt;div&gt;
3-2&lt;/div&gt;
&lt;div&gt;
4-1&lt;/div&gt;
&lt;div&gt;
4-2&lt;/div&gt;
&lt;div&gt;
4-3&lt;/div&gt;
&lt;div&gt;
4-4&lt;/div&gt;
&lt;div&gt;
4-5&lt;/div&gt;
&lt;div&gt;
5-1&lt;/div&gt;
&lt;div&gt;
5-2&lt;/div&gt;
&lt;div&gt;
5-3&lt;/div&gt;
&lt;div&gt;
5-4&lt;/div&gt;
&lt;div&gt;
5-5&lt;/div&gt;
&lt;/div&gt;

&lt;/pre&gt;

&lt;h3&gt;Explanation&lt;/h3&gt;
It breaks inner loop only if you use break statement inside the inner loop.Outer loop will continue to iterate.
&lt;/body&gt;
&lt;/html&gt;</description><link>http://tangled-java.blogspot.com/2017/11/break-keyword.html</link><author>noreply@blogger.com (Anonymous)</author><thr:total>0</thr:total></item><item><guid isPermaLink="false">tag:blogger.com,1999:blog-3082064622906880860.post-8128927872418462208</guid><pubDate>Fri, 17 Nov 2017 13:28:00 +0000</pubDate><atom:updated>2017-11-27T00:10:30.851-08:00</atom:updated><title>Do-while loop</title><description>&lt;!DOCTYPE html&gt;
&lt;html&gt;
&lt;head&gt;
 &lt;title&gt;&lt;/title&gt;
 &lt;style type="text/css"&gt;
  pre{ 
   border-left: 5px solid lightgreen;
   padding-left: 5px;
   background: rgba(96,96,96,0.3); 
   color: white;
   line-height: 7px;
   font-size: 16.5px;
  }
  h2{ 
   background-color: lightgrey;
   padding: 3px 5px;
   color: #1e1e1e;
  }
  h3{ 
   color: white; 
  }
  .button {
    border-radius: 4px;
    background-color: #f4511e;
    border: none;
    color: #FFFFFF;
    text-align: center;
    font-size: 28px;
    padding: 10px;
    width: 150px;
    height: 50px;
    transition: all 0.5s;
    cursor: pointer;
    margin: 5px;
    float: right;
    margin-top: -50px;
  }

  .button span {
    cursor: pointer;
    display: inline-block;
    position: relative;
    transition: 0.5s;
  }

  .button span:after {
    content: '\00bb';
    position: absolute;
    opacity: 0;
    top: 0;
    right: -20px;
    transition: 0.5s;
  }

  .button:hover span {
    padding-right: 25px;
  }

  .button:hover span:after {
    opacity: 1;
    right: 0;
  }
 &lt;/style&gt;
&lt;/head&gt;
&lt;body onload='selectjava()'&gt;

&lt;h2&gt;Do-while loop in Java&lt;/h2&gt;


&lt;h3&gt;Syntax&lt;/h3&gt;
&lt;pre&gt;
&lt;div&gt;
&lt;span style="color: #569cd6;"&gt;do&lt;/span&gt;{  &lt;/div&gt;
&lt;div&gt;
&lt;span style="color: #608b4e;"&gt;//code to be executed  &lt;/span&gt;&lt;/div&gt;
&lt;div&gt;
}&lt;span style="color: #569cd6;"&gt;while&lt;/span&gt;(condition); &lt;/div&gt;
&lt;/pre&gt;

&lt;h3&gt;Program&lt;/h3&gt;
&lt;pre&gt;
 &lt;div&gt;
&lt;span style="color: #569cd6;"&gt;public&lt;/span&gt; &lt;span style="color: #569cd6;"&gt;class&lt;/span&gt; do_while&lt;/div&gt;
&lt;div&gt;
{&lt;/div&gt;
&lt;div&gt;
    &lt;span style="color: #569cd6;"&gt;public&lt;/span&gt; &lt;span style="color: #569cd6;"&gt;static&lt;/span&gt; &lt;span style="color: #569cd6;"&gt;void&lt;/span&gt; main(&lt;span style="color: #569cd6;"&gt;String&lt;/span&gt; args[])&lt;/div&gt;
&lt;div&gt;
    {&lt;/div&gt;
&lt;div&gt;
        &lt;span style="color: #569cd6;"&gt;int&lt;/span&gt; i = &lt;span style="color: #b5cea8;"&gt;1&lt;/span&gt;;&lt;/div&gt;
&lt;div&gt;
        &lt;span style="color: #569cd6;"&gt;do&lt;/span&gt;&lt;/div&gt;
&lt;div&gt;
        {&lt;/div&gt;
&lt;div&gt;
            System.out.println(i);&lt;/div&gt;
&lt;div&gt;
            i++;&lt;/div&gt;
&lt;div&gt;
        }&lt;span style="color: #569cd6;"&gt;while&lt;/span&gt;(i &amp;lt;= &lt;span style="color: #b5cea8;"&gt;10&lt;/span&gt;);&lt;/div&gt;
&lt;div&gt;
    }&lt;/div&gt;
&lt;div&gt;
}&lt;/div&gt;
 &lt;a href="https://onlinegdb.com/HkJLfvhkz"&gt;&lt;button class="button"&gt;&lt;span&gt;Run &lt;/span&gt;&lt;/button&gt;&lt;/a&gt;
&lt;/pre&gt;

&lt;h3&gt;Output&lt;/h3&gt;
&lt;pre&gt;
 &lt;div dir="ltr" style="text-align: left;" trbidi="on"&gt;
&lt;div&gt;
&lt;span style="color: #569cd6;"&gt;1&lt;/span&gt;&lt;/div&gt;
&lt;div&gt;
&lt;span style="color: #569cd6;"&gt;2&lt;/span&gt;&lt;/div&gt;
&lt;div&gt;
&lt;span style="color: #569cd6;"&gt;3&lt;/span&gt;&lt;/div&gt;
&lt;div&gt;
&lt;span style="color: #569cd6;"&gt;4&lt;/span&gt;&lt;/div&gt;
&lt;div&gt;
&lt;span style="color: #569cd6;"&gt;5&lt;/span&gt;&lt;/div&gt;
&lt;div&gt;
&lt;span style="color: #569cd6;"&gt;6&lt;/span&gt;&lt;/div&gt;
&lt;div&gt;
&lt;span style="color: #569cd6;"&gt;7&lt;/span&gt;&lt;/div&gt;
&lt;div&gt;
&lt;span style="color: #569cd6;"&gt;8&lt;/span&gt;&lt;/div&gt;
&lt;div&gt;
&lt;span style="color: #569cd6;"&gt;9&lt;/span&gt;&lt;/div&gt;
&lt;div&gt;
&lt;span style="color: #569cd6;"&gt;10&lt;/span&gt;&lt;/div&gt;
&lt;/div&gt;

&lt;/pre&gt;

&lt;h3&gt;Explanation&lt;/h3&gt;
&lt;ul&gt;
&lt;li&gt;The Java do-while loop is used to iterate a part of the program several times. If the number of iteration is not fixed and you must have to execute the loop at least once, it is recommended to use do-while loop.&lt;/li&gt;

&lt;li&gt;The Java do-while loop is executed at least once because condition is checked after loop body.&lt;/li&gt;

&lt;li&gt;do while loop starts with the execution of the statement(s). There is no checking of any condition for the first time.&lt;/li&gt;
&lt;li&gt;After the execution of the statements, and update of the variable value, the condition is checked for true or false value. If it is evaluated to true, next iteration of loop starts.&lt;/li&gt;
&lt;li&gt;When the condition becomes false, the loop terminates which marks the end of its life cycle.&lt;/li&gt;
&lt;li&gt;It is important to note that the do-while loop will execute its statements atleast once before any condition is checked, and therefore is an example of exit control loop.&lt;/li&gt;
&lt;/ul&gt;


&lt;h2&gt;Infinite do-while loop&lt;/h2&gt;

&lt;h3&gt;Syntax&lt;/h3&gt;
&lt;pre&gt;
 &lt;div&gt;
&lt;span style="color: #569cd6;"&gt;do&lt;/span&gt;{  &lt;/div&gt;
&lt;div&gt;
&lt;span style="color: #608b4e;"&gt;//code to be executed  &lt;/span&gt;&lt;/div&gt;
&lt;div&gt;
}&lt;span style="color: #569cd6;"&gt;while&lt;/span&gt;(&lt;span style="color: #569cd6;"&gt;true&lt;/span&gt;); &lt;/div&gt;
&lt;/pre&gt;

&lt;h3&gt;Program&lt;/h3&gt;
&lt;pre&gt;
 &lt;div&gt;
&lt;span style="color: #569cd6;"&gt;public&lt;/span&gt; &lt;span style="color: #569cd6;"&gt;class&lt;/span&gt; infinite_dowhile&lt;/div&gt;
&lt;div&gt;
{&lt;/div&gt;
&lt;div&gt;
    &lt;span style="color: #569cd6;"&gt;public&lt;/span&gt; &lt;span style="color: #569cd6;"&gt;static&lt;/span&gt; &lt;span style="color: #569cd6;"&gt;void&lt;/span&gt; main(&lt;span style="color: #569cd6;"&gt;String&lt;/span&gt; args[])&lt;/div&gt;
&lt;div&gt;
    {&lt;/div&gt;
&lt;div&gt;
        &lt;span style="color: #569cd6;"&gt;do&lt;/span&gt;&lt;/div&gt;
&lt;div&gt;
        {&lt;/div&gt;
&lt;div&gt;
            System.out.println(&lt;span style="color: #ce9178;"&gt;"Infinite while loop"&lt;/span&gt;);&lt;/div&gt;
&lt;div&gt;
        }&lt;span style="color: #569cd6;"&gt;while&lt;/span&gt;(&lt;span style="color: #569cd6;"&gt;true&lt;/span&gt;);&lt;/div&gt;
&lt;div&gt;
    }&lt;/div&gt;
&lt;div&gt;
}&lt;/div&gt;
 &lt;a href="https://onlinegdb.com/r1rwQDhJG"&gt;&lt;button class="button"&gt;&lt;span&gt;Run &lt;/span&gt;&lt;/button&gt;&lt;/a&gt;
&lt;/pre&gt;

&lt;h3&gt;Output&lt;/h3&gt;
&lt;pre&gt;
 &lt;div dir="ltr" style="text-align: left;" trbidi="on"&gt;
&lt;div&gt;
&lt;span style="color: #569cd6;"&gt;Infinite while loop&lt;/span&gt;&lt;/div&gt;
&lt;div&gt;
&lt;span style="color: #569cd6;"&gt;Infinite while loop&lt;/span&gt;&lt;/div&gt;
&lt;div&gt;
&lt;span style="color: #569cd6;"&gt;Infinite while loop&lt;/span&gt;&lt;/div&gt;
&lt;div&gt;
&lt;span style="color: #569cd6;"&gt;Infinite while loop&lt;/span&gt;&lt;/div&gt;
&lt;div&gt;
&lt;span style="color: #569cd6;"&gt;Infinite while loop&lt;/span&gt;&lt;/div&gt;
&lt;div&gt;
&lt;span style="color: #569cd6;"&gt;Infinite while loop&lt;/span&gt;&lt;/div&gt;
&lt;/div&gt;

&lt;/pre&gt;

&lt;h3&gt;Explanation&lt;/h3&gt;
&lt;ul&gt;
 &lt;li&gt;If you pass true in the do-while loop, it will be infinitive do-while loop.&lt;/li&gt;
&lt;li&gt;You have to press ctrl+c to stop this program otherwise it will run continuously.&lt;/li&gt;
&lt;/ul&gt;

&lt;/body&gt;
&lt;/html&gt;</description><link>http://tangled-java.blogspot.com/2017/11/do-while-loop.html</link><author>noreply@blogger.com (Anonymous)</author><thr:total>0</thr:total></item><item><guid isPermaLink="false">tag:blogger.com,1999:blog-3082064622906880860.post-1477374032257331804</guid><pubDate>Fri, 17 Nov 2017 07:06:00 +0000</pubDate><atom:updated>2017-11-27T00:10:06.767-08:00</atom:updated><category domain="http://www.blogger.com/atom/ns#">while loop</category><title>While loop</title><description>&lt;body onload='selectjava()'&gt;
&lt;div dir="ltr" style="text-align: left;" trbidi="on"&gt;
&lt;html&gt;
&lt;head&gt;
 &lt;title&gt;&lt;/title&gt;
 &lt;style type="text/css"&gt;
  pre{ 
   border-left: 5px solid lightgreen;
   padding-left: 5px;
   background: rgba(96,96,96,0.3); 
   color: white;
   line-height: 7px;
   font-size: 16.5px;
  }
  h2{ 
   background-color: lightgrey;
   padding: 3px 5px;
   color: #1e1e1e;
  }
  h3{ 
   color: white; 
  }
  .button {
    border-radius: 4px;
    background-color: #f4511e;
    border: none;
    color: #FFFFFF;
    text-align: center;
    font-size: 28px;
    padding: 10px;
    width: 150px;
    height: 50px;
    transition: all 0.5s;
    cursor: pointer;
    margin: 5px;
    float: right;
    margin-top: -50px;
  }

  .button span {
    cursor: pointer;
    display: inline-block;
    position: relative;
    transition: 0.5s;
  }

  .button span:after {
    content: '\00bb';
    position: absolute;
    opacity: 0;
    top: 0;
    right: -20px;
    transition: 0.5s;
  }

  .button:hover span {
    padding-right: 25px;
  }

  .button:hover span:after {
    opacity: 1;
    right: 0;
  }
 &lt;/style&gt;
&lt;/head&gt;
&lt;body&gt;
&lt;h2&gt;
While loop in JAVA&lt;/h2&gt;
&lt;h3&gt;
Syntax&lt;/h3&gt;
&lt;pre&gt;
&lt;div&gt;
&lt;span style="color: #569cd6;"&gt;while&lt;/span&gt;(condition){  &lt;/div&gt;
&lt;div&gt;
&lt;span style="color: #608b4e;"&gt;//code to be executed  &lt;/span&gt;&lt;/div&gt;
&lt;div&gt;
}  &lt;/div&gt;
&lt;/pre&gt;
&lt;h3&gt;
Program&lt;/h3&gt;
&lt;pre&gt;
 &lt;div&gt;
&lt;span style="color: #569cd6;"&gt;public&lt;/span&gt; &lt;span style="color: #569cd6;"&gt;class&lt;/span&gt; while_loop&lt;/div&gt;
&lt;div&gt;
{&lt;/div&gt;
&lt;div&gt;
    &lt;span style="color: #569cd6;"&gt;public&lt;/span&gt; &lt;span style="color: #569cd6;"&gt;static&lt;/span&gt; &lt;span style="color: #569cd6;"&gt;void&lt;/span&gt; main(&lt;span style="color: #569cd6;"&gt;String&lt;/span&gt; args[])&lt;/div&gt;
&lt;div&gt;
    {&lt;/div&gt;
&lt;div&gt;
        &lt;span style="color: #569cd6;"&gt;int&lt;/span&gt; i = &lt;span style="color: #b5cea8;"&gt;1&lt;/span&gt;;&lt;/div&gt;
&lt;div&gt;
        &lt;span style="color: #569cd6;"&gt;while&lt;/span&gt;(i &amp;lt;= &lt;span style="color: #b5cea8;"&gt;10&lt;/span&gt;)&lt;/div&gt;
&lt;div&gt;
        {&lt;/div&gt;
&lt;div&gt;
            System.out.println(i);&lt;/div&gt;
&lt;div&gt;
            i++;&lt;/div&gt;
&lt;div&gt;
        }&lt;/div&gt;
&lt;div&gt;
    }&lt;/div&gt;
&lt;div&gt;
}&lt;/div&gt;
&lt;a href="https://onlinegdb.com/HkpZYZh1G"&gt;&lt;button class="button"&gt;&lt;span&gt;Run &lt;/span&gt;&lt;/button&gt;&lt;/a&gt;
&lt;/pre&gt;
&lt;h3&gt;
Output&lt;/h3&gt;
&lt;pre&gt;
 &lt;div dir="ltr" style="text-align: left;" trbidi="on"&gt;
&lt;div&gt;
&lt;span style="color: #569cd6;"&gt;1&lt;/span&gt;&lt;/div&gt;
&lt;div&gt;
&lt;span style="color: #569cd6;"&gt;2&lt;/span&gt;&lt;/div&gt;
&lt;div&gt;
&lt;span style="color: #569cd6;"&gt;3&lt;/span&gt;&lt;/div&gt;
&lt;div&gt;
&lt;span style="color: #569cd6;"&gt;4&lt;/span&gt;&lt;/div&gt;
&lt;div&gt;
&lt;span style="color: #569cd6;"&gt;5&lt;/span&gt;&lt;/div&gt;
&lt;div&gt;
&lt;span style="color: #569cd6;"&gt;6&lt;/span&gt;&lt;/div&gt;
&lt;div&gt;
&lt;span style="color: #569cd6;"&gt;7&lt;/span&gt;&lt;/div&gt;
&lt;div&gt;
&lt;span style="color: #569cd6;"&gt;8&lt;/span&gt;&lt;/div&gt;
&lt;div&gt;
&lt;span style="color: #569cd6;"&gt;9&lt;/span&gt;&lt;/div&gt;
&lt;div&gt;
&lt;span style="color: #569cd6;"&gt;10&lt;/span&gt;&lt;/div&gt;
&lt;/div&gt;
&lt;/pre&gt;
&lt;h3&gt;
Explanation&lt;/h3&gt;
The Java while loop is used to iterate a part of the program several times. If the number of iteration is not fixed, it is recommended to use while loop.

&lt;ul&gt;
&lt;li&gt;While loop starts with the checking of condition. If it evaluated to true, then the loop body statements are executed otherwise first statement following the loop is executed. For this reason it is also called Entry control loop.&lt;/li&gt;
&lt;li&gt;Once the condition is evaluated to true, the statements in the loop body are executed. Normally the statements contain an update value for the variable being processed for the next iteration.&lt;/li&gt;
&lt;li&gt;When the condition becomes false, the loop terminates which marks the end of its life cycle.&lt;/li&gt;
&lt;/ul&gt;
&lt;h2&gt;
Infinite while loop&lt;/h2&gt;
&lt;h3&gt;
Syntax&lt;/h3&gt;
&lt;pre&gt;
&lt;div&gt;
&lt;span style="color: #569cd6;"&gt;while&lt;/span&gt;(&lt;span style="color: #569cd6;"&gt;true&lt;/span&gt;){  &lt;/div&gt;
&lt;div&gt;
&lt;span style="color: #608b4e;"&gt;//code to be executed  &lt;/span&gt;&lt;/div&gt;
&lt;div&gt;
}  &lt;/div&gt;
&lt;/pre&gt;
&lt;h3&gt;
Program&lt;/h3&gt;
&lt;pre&gt;
 &lt;div&gt;
&lt;span style="color: #569cd6;"&gt;public&lt;/span&gt; &lt;span style="color: #569cd6;"&gt;class&lt;/span&gt; infinite_while&lt;/div&gt;
&lt;div&gt;
{&lt;/div&gt;
&lt;div&gt;
    &lt;span style="color: #569cd6;"&gt;public&lt;/span&gt; &lt;span style="color: #569cd6;"&gt;static&lt;/span&gt; &lt;span style="color: #569cd6;"&gt;void&lt;/span&gt; main(&lt;span style="color: #569cd6;"&gt;String&lt;/span&gt; args[])&lt;/div&gt;
&lt;div&gt;
    {&lt;/div&gt;
&lt;div&gt;
        &lt;span style="color: #569cd6;"&gt;while&lt;/span&gt;(&lt;span style="color: #569cd6;"&gt;true&lt;/span&gt;)&lt;/div&gt;
&lt;div&gt;
        {&lt;/div&gt;
&lt;div&gt;
            System.out.println(&lt;span style="color: #ce9178;"&gt;"Infinite while loop"&lt;/span&gt;);&lt;/div&gt;
&lt;div&gt;
        }&lt;/div&gt;
&lt;div&gt;
    }&lt;/div&gt;
&lt;div&gt;
}&lt;/div&gt;
&lt;a href="https://onlinegdb.com/SyIDK-2yM"&gt;&lt;button class="button"&gt;&lt;span&gt;Run &lt;/span&gt;&lt;/button&gt;&lt;/a&gt;
&lt;/pre&gt;
&lt;h3&gt;
Output&lt;/h3&gt;
&lt;pre&gt;
 &lt;div dir="ltr" style="text-align: left;" trbidi="on"&gt;
&lt;div&gt;
&lt;span style="color: #569cd6;"&gt;Infinite while loop&lt;/span&gt;&lt;/div&gt;
&lt;div&gt;
&lt;span style="color: #569cd6;"&gt;Infinite while loop&lt;/span&gt;&lt;/div&gt;
&lt;div&gt;
&lt;span style="color: #569cd6;"&gt;Infinite while loop&lt;/span&gt;&lt;/div&gt;
&lt;div&gt;
&lt;span style="color: #569cd6;"&gt;Infinite while loop&lt;/span&gt;&lt;/div&gt;
&lt;div&gt;
&lt;span style="color: #569cd6;"&gt;Infinite while loop&lt;/span&gt;&lt;/div&gt;
&lt;div&gt;
&lt;span style="color: #569cd6;"&gt;Infinite while loop&lt;/span&gt;&lt;/div&gt;
&lt;div&gt;
&lt;span style="color: #569cd6;"&gt;Infinite while loop&lt;/span&gt;&lt;/div&gt;
&lt;div&gt;
&lt;span style="color: #569cd6;"&gt;Infinite while loop&lt;/span&gt;&lt;/div&gt;
&lt;/div&gt;
&lt;/pre&gt;
&lt;h3&gt;
Explanation&lt;/h3&gt;
&lt;ul&gt;
&lt;li&gt;If you pass true in the while loop, it will be infinitive while loop.&lt;/li&gt;
&lt;li&gt;Here, condition is always true so program runs continuously. You have to press ctrl+c to stop the program.&lt;/li&gt;
&lt;li&gt;Remember true and false are keywords in Java.&lt;/li&gt;
&lt;/ul&gt;
&lt;/body&gt;
&lt;/html&gt;&lt;/div&gt;
&lt;/body&gt;</description><link>http://tangled-java.blogspot.com/2017/11/while-loop.html</link><author>noreply@blogger.com (Anonymous)</author><thr:total>0</thr:total></item></channel></rss>