<?xml version='1.0' encoding='UTF-8'?><?xml-stylesheet href="http://www.blogger.com/styles/atom.css" type="text/css"?><feed xmlns='http://www.w3.org/2005/Atom' xmlns:openSearch='http://a9.com/-/spec/opensearchrss/1.0/' xmlns:blogger='http://schemas.google.com/blogger/2008' xmlns:georss='http://www.georss.org/georss' xmlns:gd="http://schemas.google.com/g/2005" xmlns:thr='http://purl.org/syndication/thread/1.0'><id>tag:blogger.com,1999:blog-3771177150982125782</id><updated>2024-10-06T20:17:46.470-07:00</updated><category term="java introduction"/><category term="OOPS Concepts"/><category term="interview-questions"/><category term="Datatypes and Literals"/><title type='text'>java</title><subtitle type='html'></subtitle><link rel='http://schemas.google.com/g/2005#feed' type='application/atom+xml' href='http://java-intellectual.blogspot.com/feeds/posts/default'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/3771177150982125782/posts/default'/><link rel='alternate' type='text/html' href='http://java-intellectual.blogspot.com/'/><link rel='hub' href='http://pubsubhubbub.appspot.com/'/><link rel='next' type='application/atom+xml' href='http://www.blogger.com/feeds/3771177150982125782/posts/default?start-index=26&amp;max-results=25'/><author><name>siva</name><uri>http://www.blogger.com/profile/01922721189098931789</uri><email>noreply@blogger.com</email><gd:image rel='http://schemas.google.com/g/2005#thumbnail' width='16' height='16' src='https://img1.blogblog.com/img/b16-rounded.gif'/></author><generator version='7.00' uri='http://www.blogger.com'>Blogger</generator><openSearch:totalResults>46</openSearch:totalResults><openSearch:startIndex>1</openSearch:startIndex><openSearch:itemsPerPage>25</openSearch:itemsPerPage><entry><id>tag:blogger.com,1999:blog-3771177150982125782.post-3227824538493546007</id><published>2011-12-16T02:30:00.000-08:00</published><updated>2011-12-16T06:35:44.717-08:00</updated><category scheme="http://www.blogger.com/atom/ns#" term="OOPS Concepts"/><title type='text'>Need of method overriding in java ?</title><content type='html'>&lt;div dir=&quot;ltr&quot; style=&quot;text-align: left;&quot; trbidi=&quot;on&quot;&gt;&lt;div dir=&quot;ltr&quot; style=&quot;text-align: left;&quot; trbidi=&quot;on&quot;&gt;&lt;div style=&quot;text-align: justify;&quot;&gt;&lt;span class=&quot;Apple-style-span&quot; style=&quot;font-family: &#39;Lucida Sans Unicode&#39;, &#39;Lucida Grande&#39;, &#39;Lucida Sans&#39;, Lucida, sans-serif; font-size: 15px;&quot;&gt;If a super class method logic is not fulfilling sub class business requirements, sub class should override that method with required business logic. Usually in super class, methods are defined with generic logic which is common for all sub classes.&lt;/span&gt;&lt;/div&gt;&lt;div style=&quot;text-align: justify;&quot;&gt;&lt;span class=&quot;Apple-style-span&quot; style=&quot;font-family: &#39;Lucida Sans Unicode&#39;, &#39;Lucida Grande&#39;, &#39;Lucida Sans&#39;, Lucida, sans-serif; font-size: 15px;&quot;&gt;For instance if we take Shape type of classes all Shape classes like Rectangle,Square,Circle etc...should have methods area() and perimeter(). Usually these methods are defined in super class Shape with generic logic but in sub classes Rectangle,Square,Circle etc...these methods must have logic based on their specific logic. Hence in Shape sub classes, these two methods must be overridden with sub class specific logic.&lt;/span&gt;&lt;a name=&#39;more&#39;&gt;&lt;/a&gt;&lt;br /&gt;
&lt;div style=&quot;text-align: justify;&quot;&gt;&lt;span class=&quot;Apple-style-span&quot; style=&quot;font-family: &#39;Lucida Sans Unicode&#39;, &#39;Lucida Grande&#39;, &#39;Lucida Sans&#39;, Lucida, sans-serif; font-size: 15px;&quot;&gt;We can also override the predefined methods like toString(),equals(),Hashcode() methods of object class, so that we can use it in different functionality. Let us take an example program.&lt;/span&gt;&lt;/div&gt;&lt;/div&gt;&lt;div style=&quot;text-align: justify;&quot;&gt;&lt;br /&gt;
&lt;/div&gt;&lt;/div&gt;&lt;span class=&quot;Apple-style-span&quot; style=&quot;font-family: &#39;Lucida Sans Unicode&#39;, &#39;Lucida Grande&#39;, &#39;Lucida Sans&#39;, Lucida, sans-serif; font-size: 15px;&quot;&gt;&lt;pre class=&quot;brush:java;&quot;&gt;class Example 
{
   void m1()
   {
      System.out.println(&quot;Example m1&quot;);
   }
   void m2()
   {
      System.out.println(&quot;Example m2&quot;);
      m1();
   }
}
&lt;/pre&gt;&lt;/span&gt;&lt;br /&gt;
&lt;span class=&quot;Apple-style-span&quot; style=&quot;font-family: &#39;Lucida Sans Unicode&#39;, &#39;Lucida Grande&#39;, &#39;Lucida Sans&#39;, Lucida, sans-serif; font-size: 15px;&quot;&gt;&lt;pre class=&quot;brush:java;&quot;&gt;class Sample extends Example
{
   void m1()
   {
      System.out.println(&quot;Sample m1&quot;);
   }
   public static void main(String[] args) 
   {
      Sample s = new Sample();
      s.m1();
      s.m2();
   }
}
&lt;/pre&gt;&lt;/span&gt;&lt;br /&gt;
&lt;span class=&quot;Apple-style-span&quot; style=&quot;font-family: &#39;Lucida Sans Unicode&#39;, &#39;Lucida Grande&#39;, &#39;Lucida Sans&#39;, Lucida, sans-serif; font-size: 15px;&quot;&gt;&lt;b&gt;Output:&lt;/b&gt;&lt;/span&gt;&lt;br /&gt;
&lt;span class=&quot;Apple-style-span&quot; style=&quot;font-family: &#39;Lucida Sans Unicode&#39;, &#39;Lucida Grande&#39;, &#39;Lucida Sans&#39;, Lucida, sans-serif; font-size: 15px;&quot;&gt;   Sample m1&lt;/span&gt;&lt;br /&gt;
&lt;span class=&quot;Apple-style-span&quot; style=&quot;font-family: &#39;Lucida Sans Unicode&#39;, &#39;Lucida Grande&#39;, &#39;Lucida Sans&#39;, Lucida, sans-serif; font-size: 15px;&quot;&gt;   Example m2&lt;/span&gt;&lt;br /&gt;
&lt;span class=&quot;Apple-style-span&quot; style=&quot;font-family: &#39;Lucida Sans Unicode&#39;, &#39;Lucida Grande&#39;, &#39;Lucida Sans&#39;, Lucida, sans-serif; font-size: 15px;&quot;&gt;   Sample m1&lt;/span&gt;&lt;br /&gt;
&lt;br /&gt;
&lt;div style=&quot;text-align: justify;&quot;&gt;&lt;span class=&quot;Apple-style-span&quot; style=&quot;font-family: &#39;Lucida Sans Unicode&#39;, &#39;Lucida Grande&#39;, &#39;Lucida Sans&#39;, Lucida, sans-serif; font-size: 15px;&quot;&gt;In the above program m1() method is overridden in sub class i.e Sample class. Whenever m2() method is called through sample class object first JVM checks m2() method in Sample class it is not available so JVM goes to super class i.e Example class m2() method, the method is there in that class so JVM executes m2() method in Example class, In that method whenever the control comes to m1() method JVM executes m1() method in Sample class because compiler replaces m1() by this.m1() after compilation. In &#39;this&#39; variable current object reference is stored which is nothing but the Sample class object is stored in &#39;this&#39; variable so Sample class m1() method is executed.&lt;/span&gt;&lt;span class=&quot;Apple-style-span&quot; style=&quot;font-family: &#39;Lucida Sans Unicode&#39;, &#39;Lucida Grande&#39;, &#39;Lucida Sans&#39;, Lucida, sans-serif;&quot;&gt;&lt;span class=&quot;Apple-style-span&quot; style=&quot;font-size: 15px;&quot;&gt;One thing&lt;/span&gt;&lt;/span&gt;&lt;span class=&quot;Apple-style-span&quot; style=&quot;font-family: &#39;Lucida Sans Unicode&#39;, &#39;Lucida Grande&#39;, &#39;Lucida Sans&#39;, Lucida, sans-serif; font-size: 15px;&quot;&gt; we have to keep in mind that &lt;b&gt;Compiler will check only type of the variable but JVM checks object stored in the reference variable&lt;/b&gt;&lt;/span&gt;&lt;br /&gt;
&lt;/div&gt;&lt;/div&gt;</content><link rel='replies' type='application/atom+xml' href='http://java-intellectual.blogspot.com/feeds/3227824538493546007/comments/default' title='Post Comments'/><link rel='replies' type='text/html' href='http://java-intellectual.blogspot.com/2011/12/need-of-method-overriding-in-java.html#comment-form' title='0 Comments'/><link rel='edit' type='application/atom+xml' href='http://www.blogger.com/feeds/3771177150982125782/posts/default/3227824538493546007'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/3771177150982125782/posts/default/3227824538493546007'/><link rel='alternate' type='text/html' href='http://java-intellectual.blogspot.com/2011/12/need-of-method-overriding-in-java.html' title='Need of method overriding in java ?'/><author><name>siva</name><uri>http://www.blogger.com/profile/01922721189098931789</uri><email>noreply@blogger.com</email><gd:image rel='http://schemas.google.com/g/2005#thumbnail' width='16' height='16' src='https://img1.blogblog.com/img/b16-rounded.gif'/></author><thr:total>0</thr:total></entry><entry><id>tag:blogger.com,1999:blog-3771177150982125782.post-1211731363590411723</id><published>2011-12-14T03:07:00.000-08:00</published><updated>2011-12-15T22:20:08.446-08:00</updated><category scheme="http://www.blogger.com/atom/ns#" term="OOPS Concepts"/><title type='text'>Java method overriding rules?</title><content type='html'>&lt;div dir=&quot;ltr&quot; style=&quot;text-align: left;&quot; trbidi=&quot;on&quot;&gt;&lt;span class=&quot;Apple-style-span&quot; style=&quot;font-family: &#39;Lucida Sans Unicode&#39;, &#39;Lucida Grande&#39;, &#39;Lucida Sans&#39;, Lucida, sans-serif; font-size: 15px;&quot;&gt;A method is said to be overriding method if it satisfies the below rules.&lt;/span&gt;&lt;br /&gt;
&lt;br /&gt;
&lt;span class=&quot;Apple-style-span&quot; style=&quot;font-family: &#39;Lucida Sans Unicode&#39;, &#39;Lucida Grande&#39;, &#39;Lucida Sans&#39;, Lucida, sans-serif; font-size: 15px;&quot;&gt;1.return type should be same as super class method.&lt;/span&gt;&lt;br /&gt;
&lt;br /&gt;
&lt;div style=&quot;text-align: justify;&quot;&gt;&lt;span class=&quot;Apple-style-span&quot; style=&quot;font-family: &#39;Lucida Sans Unicode&#39;,&#39;Lucida Grande&#39;,&#39;Lucida Sans&#39;,Lucida,sans-serif; font-size: 15px;&quot;&gt;In the below program we should not place return type as int we will get a compile time error, in order to override that method we should place the below method return type as void.&lt;/span&gt;&lt;/div&gt;&lt;a name=&#39;more&#39;&gt;&lt;/a&gt;&lt;br /&gt;
&lt;span class=&quot;Apple-style-span&quot; style=&quot;font-family: &#39;Lucida Sans Unicode&#39;, &#39;Lucida Grande&#39;, &#39;Lucida Sans&#39;, Lucida, sans-serif; font-size: 15px;&quot;&gt;&lt;pre class=&quot;brush:java;&quot;&gt;class Example{
   void m1(){ }
}
&lt;/pre&gt;&lt;/span&gt;&lt;br /&gt;
&lt;span class=&quot;Apple-style-span&quot; style=&quot;font-family: &#39;Lucida Sans Unicode&#39;, &#39;Lucida Grande&#39;, &#39;Lucida Sans&#39;, Lucida, sans-serif; font-size: 15px;&quot;&gt;&lt;pre class=&quot;brush:java;&quot;&gt;class Sample extends Example{
   void m1(){ }
}
&lt;/pre&gt;&lt;/span&gt;&lt;br /&gt;
&lt;span class=&quot;Apple-style-span&quot; style=&quot;font-family: &#39;Lucida Sans Unicode&#39;, &#39;Lucida Grande&#39;, &#39;Lucida Sans&#39;, Lucida, sans-serif; font-size: 15px;&quot;&gt;&lt;pre class=&quot;brush:java;&quot;&gt;class Sample extends Example{
   int m1(){ return 10;}
}
&lt;/pre&gt;&lt;/span&gt;&lt;br /&gt;
&lt;span class=&quot;Apple-style-span&quot; style=&quot;font-family: &#39;Lucida Sans Unicode&#39;, &#39;Lucida Grande&#39;, &#39;Lucida Sans&#39;, Lucida, sans-serif; font-size: 15px;&quot;&gt;2.static modifier should not be removed or added.&lt;/span&gt;&lt;br /&gt;
&lt;span class=&quot;Apple-style-span&quot; style=&quot;font-family: &#39;Lucida Sans Unicode&#39;, &#39;Lucida Grande&#39;, &#39;Lucida Sans&#39;, Lucida, sans-serif; font-size: 15px;&quot;&gt;&lt;pre class=&quot;brush:java;&quot;&gt;class Example{
   void m1(){ }
}
&lt;/pre&gt;&lt;/span&gt;&lt;br /&gt;
&lt;span class=&quot;Apple-style-span&quot; style=&quot;font-family: &#39;Lucida Sans Unicode&#39;, &#39;Lucida Grande&#39;, &#39;Lucida Sans&#39;, Lucida, sans-serif; font-size: 15px;&quot;&gt;&lt;pre class=&quot;brush:java;&quot;&gt;class Sample extends Example{
   static void m1(){}
}
&lt;/pre&gt;&lt;/span&gt;&lt;br /&gt;
&lt;div style=&quot;text-align: justify;&quot;&gt;&lt;span class=&quot;Apple-style-span&quot; style=&quot;font-family: &#39;Lucida Sans Unicode&#39;,&#39;Lucida Grande&#39;,&#39;Lucida Sans&#39;,Lucida,sans-serif; font-size: 15px;&quot;&gt;If we place modifier as static in sub class it leads to compile time error in the above program.&lt;/span&gt;&lt;/div&gt;&lt;span class=&quot;Apple-style-span&quot; style=&quot;font-family: &#39;Lucida Sans Unicode&#39;, &#39;Lucida Grande&#39;, &#39;Lucida Sans&#39;, Lucida, sans-serif; font-size: 15px;&quot;&gt;&lt;pre class=&quot;brush:java;&quot;&gt;class Example{
   static void m1(){ }
}
&lt;/pre&gt;&lt;/span&gt;&lt;br /&gt;
&lt;span class=&quot;Apple-style-span&quot; style=&quot;font-family: &#39;Lucida Sans Unicode&#39;, &#39;Lucida Grande&#39;, &#39;Lucida Sans&#39;, Lucida, sans-serif; font-size: 15px;&quot;&gt;&lt;pre class=&quot;brush:java;&quot;&gt;class Sample extends Example{
   void m1(){}
}
&lt;/pre&gt;&lt;/span&gt;&lt;br /&gt;
&lt;div style=&quot;text-align: justify;&quot;&gt;&lt;span class=&quot;Apple-style-span&quot; style=&quot;font-family: &#39;Lucida Sans Unicode&#39;,&#39;Lucida Grande&#39;,&#39;Lucida Sans&#39;,Lucida,sans-serif; font-size: 15px;&quot;&gt;If we should not place modifier as static in sub class it leads to compile time error in the above program.&lt;/span&gt;&lt;/div&gt;&lt;br /&gt;
&lt;span class=&quot;Apple-style-span&quot; style=&quot;font-family: &#39;Lucida Sans Unicode&#39;, &#39;Lucida Grande&#39;, &#39;Lucida Sans&#39;, Lucida, sans-serif; font-size: 15px;&quot;&gt;3.access specifier should be same as super class method or it can be increased,but should not be decreased. The below table shows the allowed access specifiers for the sub class method based on super class method access specifier.&lt;/span&gt;&lt;br /&gt;
&lt;br /&gt;
&lt;table border=&#39;1&#39;&gt;&lt;tbody&gt;
&lt;tr&gt;&lt;td&gt;&lt;span class=&quot;Apple-style-span&quot; style=&quot;font-family: &#39;Lucida Sans Unicode&#39;,&#39;Lucida Grande&#39;,&#39;Lucida Sans&#39;,Lucida,sans-serif; font-size: 15px;&quot;&gt;&lt;b&gt;Super class method&lt;/b&gt;&lt;/span&gt;&lt;/td&gt;&lt;td&gt;&lt;span class=&quot;Apple-style-span&quot; style=&quot;font-family: &#39;Lucida Sans Unicode&#39;,&#39;Lucida Grande&#39;,&#39;Lucida Sans&#39;,Lucida,sans-serif; font-size: 15px;&quot;&gt;&lt;b&gt;Sub class method&lt;/b&gt;&lt;/span&gt;&lt;/td&gt;&lt;/tr&gt;
&lt;tr&gt;&lt;td&gt;&lt;span class=&quot;Apple-style-span&quot; style=&quot;font-family: &#39;Lucida Sans Unicode&#39;,&#39;Lucida Grande&#39;,&#39;Lucida Sans&#39;,Lucida,sans-serif; font-size: 15px;&quot;&gt;Private&lt;/span&gt;&lt;/td&gt;&lt;td&gt;&lt;span class=&quot;Apple-style-span&quot; style=&quot;font-family: &#39;Lucida Sans Unicode&#39;,&#39;Lucida Grande&#39;,&#39;Lucida Sans&#39;,Lucida,sans-serif; font-size: 15px;&quot;&gt;private,default,protected,public(method is not considered as overridden method because it is not inherited)&lt;/span&gt;&lt;/td&gt;&lt;/tr&gt;
&lt;tr&gt;&lt;td&gt;&lt;span class=&quot;Apple-style-span&quot; style=&quot;font-family: &#39;Lucida Sans Unicode&#39;,&#39;Lucida Grande&#39;,&#39;Lucida Sans&#39;,Lucida,sans-serif; font-size: 15px;&quot;&gt;Package&lt;/span&gt;&lt;/td&gt;&lt;td&gt;&lt;span class=&quot;Apple-style-span&quot; style=&quot;font-family: &#39;Lucida Sans Unicode&#39;,&#39;Lucida Grande&#39;,&#39;Lucida Sans&#39;,Lucida,sans-serif; font-size: 15px;&quot;&gt;package,protected,public&lt;/span&gt;&lt;/td&gt;&lt;/tr&gt;
&lt;tr&gt;&lt;td&gt;&lt;span class=&quot;Apple-style-span&quot; style=&quot;font-family: &#39;Lucida Sans Unicode&#39;,&#39;Lucida Grande&#39;,&#39;Lucida Sans&#39;,Lucida,sans-serif; font-size: 15px;&quot;&gt;Protected&lt;/span&gt;&lt;/td&gt;&lt;td&gt;&lt;span class=&quot;Apple-style-span&quot; style=&quot;font-family: &#39;Lucida Sans Unicode&#39;,&#39;Lucida Grande&#39;,&#39;Lucida Sans&#39;,Lucida,sans-serif; font-size: 15px;&quot;&gt;protected,public&lt;/span&gt;&lt;/td&gt;&lt;/tr&gt;
&lt;tr&gt;&lt;td&gt;&lt;span class=&quot;Apple-style-span&quot; style=&quot;font-family: &#39;Lucida Sans Unicode&#39;,&#39;Lucida Grande&#39;,&#39;Lucida Sans&#39;,Lucida,sans-serif; font-size: 15px;&quot;&gt;Public&lt;/span&gt;&lt;/td&gt;&lt;td&gt;&lt;span class=&quot;Apple-style-span&quot; style=&quot;font-family: &#39;Lucida Sans Unicode&#39;,&#39;Lucida Grande&#39;,&#39;Lucida Sans&#39;,Lucida,sans-serif; font-size: 15px;&quot;&gt;public&lt;/span&gt;&lt;/td&gt;&lt;/tr&gt;
&lt;/tbody&gt;&lt;/table&gt;&lt;br /&gt;
&lt;div style=&quot;text-align: justify;&quot;&gt;&lt;span class=&quot;Apple-style-span&quot; style=&quot;font-family: &#39;Lucida Sans Unicode&#39;,&#39;Lucida Grande&#39;,&#39;Lucida Sans&#39;,Lucida,sans-serif; font-size: 15px;&quot;&gt;If the super class method is private and if we define the same method in sub class with or without private then the sub class method is not called as overriding method means they are not inherited, only super class&#39;s non private members are inherited . We have to keep in mind that constructor,blocks,private members are not inherited. If we are able to call super class members with &#39;super.&#39; or by using sub class object then we can say they are inherited.&lt;/span&gt;&lt;/div&gt;&lt;br /&gt;
&lt;div style=&quot;text-align: justify;&quot;&gt;&lt;span class=&quot;Apple-style-span&quot; style=&quot;font-family: &#39;Lucida Sans Unicode&#39;,&#39;Lucida Grande&#39;,&#39;Lucida Sans&#39;,Lucida,sans-serif; font-size: 15px;&quot;&gt;4. throws clause should not be added if super class method does not contain it. If super class method contain throws clause then in sub class, overriding method should contain throws clause with same exception class.&lt;/span&gt;&lt;/div&gt;&lt;/div&gt;</content><link rel='replies' type='application/atom+xml' href='http://java-intellectual.blogspot.com/feeds/1211731363590411723/comments/default' title='Post Comments'/><link rel='replies' type='text/html' href='http://java-intellectual.blogspot.com/2011/12/java-method-overriding-rules.html#comment-form' title='0 Comments'/><link rel='edit' type='application/atom+xml' href='http://www.blogger.com/feeds/3771177150982125782/posts/default/1211731363590411723'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/3771177150982125782/posts/default/1211731363590411723'/><link rel='alternate' type='text/html' href='http://java-intellectual.blogspot.com/2011/12/java-method-overriding-rules.html' title='Java method overriding rules?'/><author><name>siva</name><uri>http://www.blogger.com/profile/01922721189098931789</uri><email>noreply@blogger.com</email><gd:image rel='http://schemas.google.com/g/2005#thumbnail' width='16' height='16' src='https://img1.blogblog.com/img/b16-rounded.gif'/></author><thr:total>0</thr:total></entry><entry><id>tag:blogger.com,1999:blog-3771177150982125782.post-3854333823509709594</id><published>2011-12-11T22:47:00.000-08:00</published><updated>2011-12-12T01:14:51.228-08:00</updated><category scheme="http://www.blogger.com/atom/ns#" term="OOPS Concepts"/><title type='text'>What is method overriding in java ?</title><content type='html'>&lt;div dir=&quot;ltr&quot; style=&quot;text-align: left;&quot; trbidi=&quot;on&quot;&gt;&lt;div style=&quot;text-align: justify;&quot;&gt;&lt;span class=&quot;Apple-style-span&quot; style=&quot;font-family: &#39;Lucida Sans Unicode&#39;, &#39;Lucida Grande&#39;, &#39;Lucida Sans&#39;, Lucida, sans-serif; font-size: 15px;&quot;&gt;Redefining super class method in sub class is called method overriding. Method overriding, in object oriented programming, is a language feature that allows a sub class to provide a specific implementation of a method that is already provided by one of its super classes. The implementation in the sub class overrides (replaces) the implementation in the super class. If a method in sub class contains signature same as super class non private method, sub class method is treated as overriding method and super class method is treated as overridden method.&lt;/span&gt;&lt;br /&gt;
&lt;span class=&quot;Apple-style-span&quot; style=&quot;font-family: &#39;Lucida Sans Unicode&#39;, &#39;Lucida Grande&#39;, &#39;Lucida Sans&#39;, Lucida, sans-serif; font-size: 15px;&quot;&gt;&lt;/span&gt;&lt;br /&gt;
&lt;a name=&#39;more&#39;&gt;&lt;/a&gt;&lt;/div&gt;&lt;div style=&quot;text-align: justify;&quot;&gt;&lt;span class=&quot;Apple-style-span&quot; style=&quot;font-family: &#39;Lucida Sans Unicode&#39;, &#39;Lucida Grande&#39;, &#39;Lucida Sans&#39;, Lucida, sans-serif; font-size: 15px;&quot;&gt;&lt;b&gt;//Example.java&lt;/b&gt;&lt;/span&gt;&lt;/div&gt;&lt;span class=&quot;Apple-style-span&quot; style=&quot;font-family: &#39;Lucida Sans Unicode&#39;, &#39;Lucida Grande&#39;, &#39;Lucida Sans&#39;, Lucida, sans-serif; font-size: 15px;&quot;&gt;&lt;pre class=&quot;brush:java;&quot;&gt;class Example  
{  
   void add(int a,int b){
      System.out.println(&quot;Example add:&quot;+(a+b));
   }
   void sub(int a,int b){
      System.out.println(&quot;Example sub:&quot;+(a-b));
   }
}   
&lt;/pre&gt;&lt;/span&gt;&lt;br /&gt;
&lt;div style=&quot;text-align: justify;&quot;&gt;&lt;span class=&quot;Apple-style-span&quot; style=&quot;font-family: &#39;Lucida Sans Unicode&#39;, &#39;Lucida Grande&#39;, &#39;Lucida Sans&#39;, Lucida, sans-serif; font-size: 15px;&quot;&gt;&lt;b&gt;//Sample.java&lt;/b&gt;&lt;/span&gt;&lt;/div&gt;&lt;span class=&quot;Apple-style-span&quot; style=&quot;font-family: &#39;Lucida Sans Unicode&#39;, &#39;Lucida Grande&#39;, &#39;Lucida Sans&#39;, Lucida, sans-serif; font-size: 15px;&quot;&gt;&lt;pre class=&quot;brush:java;&quot;&gt;class Sample extends Example  
{       
   void add(int a,int b){
      System.out.println(&quot;Sample add:&quot;+(a+b));
   }
   public static void main(String[] args)  
   {  
      Sample s = new Sample();
   s.add(10,20);
   s.sub(10,20);
   }  
}  
&lt;/pre&gt;&lt;/span&gt;&lt;br /&gt;
&lt;div style=&quot;text-align: justify;&quot;&gt;&lt;span class=&quot;Apple-style-span&quot; style=&quot;font-family: &#39;Lucida Sans Unicode&#39;, &#39;Lucida Grande&#39;, &#39;Lucida Sans&#39;, Lucida, sans-serif; font-size: 15px;&quot;&gt;In the above program, add(int,int) method in Sample overrides add(int, int) in Example,because both methods have same signature and it is not private in Example class. Then Example class add() method is called overridden method, Sample class add() method is called overriding method. Here Sample class add() method is executed because add method is called from Sample class main method so first preference is given to Sample class add() method and it is executed. Here signature means add(int,int). &lt;/span&gt;&lt;/div&gt;&lt;/div&gt;</content><link rel='replies' type='application/atom+xml' href='http://java-intellectual.blogspot.com/feeds/3854333823509709594/comments/default' title='Post Comments'/><link rel='replies' type='text/html' href='http://java-intellectual.blogspot.com/2011/12/what-is-method-overloading-in-java.html#comment-form' title='0 Comments'/><link rel='edit' type='application/atom+xml' href='http://www.blogger.com/feeds/3771177150982125782/posts/default/3854333823509709594'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/3771177150982125782/posts/default/3854333823509709594'/><link rel='alternate' type='text/html' href='http://java-intellectual.blogspot.com/2011/12/what-is-method-overloading-in-java.html' title='What is method overriding in java ?'/><author><name>siva</name><uri>http://www.blogger.com/profile/01922721189098931789</uri><email>noreply@blogger.com</email><gd:image rel='http://schemas.google.com/g/2005#thumbnail' width='16' height='16' src='https://img1.blogblog.com/img/b16-rounded.gif'/></author><thr:total>0</thr:total></entry><entry><id>tag:blogger.com,1999:blog-3771177150982125782.post-7428470392915638705</id><published>2011-12-11T21:29:00.000-08:00</published><updated>2011-12-11T21:34:01.679-08:00</updated><category scheme="http://www.blogger.com/atom/ns#" term="OOPS Concepts"/><title type='text'>Can main method is executed from super classes ?</title><content type='html'>&lt;div dir=&quot;ltr&quot; style=&quot;text-align: left;&quot; trbidi=&quot;on&quot;&gt;&lt;div style=&quot;text-align: justify;&quot;&gt;&lt;span class=&quot;Apple-style-span&quot; style=&quot;font-family: &#39;Lucida Sans Unicode&#39;, &#39;Lucida Grande&#39;, &#39;Lucida Sans&#39;, Lucida, sans-serif; font-size: 15px;&quot;&gt;Yes,if subclass doesn&#39;t have main method JVM will not through exception directly instead  it search in super class complete hierarchy till object class. If main method is found in any of the super class it stops searching and executes main method from that class. Otherwise it throws an exception.Check below program.&lt;/span&gt;&lt;/div&gt;&lt;div style=&quot;text-align: justify;&quot;&gt;&lt;span class=&quot;Apple-style-span&quot; style=&quot;font-family: &#39;Lucida Sans Unicode&#39;, &#39;Lucida Grande&#39;, &#39;Lucida Sans&#39;, Lucida, sans-serif; font-size: 15px;&quot;&gt;&lt;/span&gt;&lt;br /&gt;
&lt;a name=&#39;more&#39;&gt;&lt;/a&gt;&lt;/div&gt;&lt;div style=&quot;text-align: justify;&quot;&gt;&lt;span class=&quot;Apple-style-span&quot; style=&quot;font-family: &#39;Lucida Sans Unicode&#39;, &#39;Lucida Grande&#39;, &#39;Lucida Sans&#39;, Lucida, sans-serif; font-size: 15px;&quot;&gt;&lt;b&gt;//Example.java&lt;/b&gt;&lt;/span&gt;&lt;/div&gt;&lt;span class=&quot;Apple-style-span&quot; style=&quot;font-family: &#39;Lucida Sans Unicode&#39;, &#39;Lucida Grande&#39;, &#39;Lucida Sans&#39;, Lucida, sans-serif; font-size: 15px;&quot;&gt;&lt;/span&gt;&lt;br /&gt;
&lt;span class=&quot;Apple-style-span&quot; style=&quot;font-family: &#39;Lucida Sans Unicode&#39;, &#39;Lucida Grande&#39;, &#39;Lucida Sans&#39;, Lucida, sans-serif; font-size: 15px;&quot;&gt;&lt;pre class=&quot;brush:java;&quot;&gt;class Example  
{  
   public static void main(String[] args)  
   {  
      System.out.println(&quot;Example main&quot;);
   }  
}  
&lt;/pre&gt;&lt;/span&gt;&lt;br /&gt;
&lt;div style=&quot;text-align: justify;&quot;&gt;&lt;span class=&quot;Apple-style-span&quot; style=&quot;font-family: &#39;Lucida Sans Unicode&#39;, &#39;Lucida Grande&#39;, &#39;Lucida Sans&#39;, Lucida, sans-serif; font-size: 15px;&quot;&gt;&lt;/span&gt;&lt;/div&gt;&lt;div style=&quot;text-align: justify;&quot;&gt;&lt;span class=&quot;Apple-style-span&quot; style=&quot;font-family: &#39;Lucida Sans Unicode&#39;, &#39;Lucida Grande&#39;, &#39;Lucida Sans&#39;, Lucida, sans-serif; font-size: 15px;&quot;&gt;&lt;b&gt;//Sample.java&lt;/b&gt;&lt;/span&gt;&lt;/div&gt;&lt;span class=&quot;Apple-style-span&quot; style=&quot;font-family: &#39;Lucida Sans Unicode&#39;, &#39;Lucida Grande&#39;, &#39;Lucida Sans&#39;, Lucida, sans-serif; font-size: 15px;&quot;&gt;&lt;/span&gt;&lt;br /&gt;
&lt;span class=&quot;Apple-style-span&quot; style=&quot;font-family: &#39;Lucida Sans Unicode&#39;, &#39;Lucida Grande&#39;, &#39;Lucida Sans&#39;, Lucida, sans-serif; font-size: 15px;&quot;&gt;&lt;pre class=&quot;brush:java;&quot;&gt;class Sample extends Example  
{         
}  
&lt;/pre&gt;&lt;/span&gt;&lt;br /&gt;
&lt;div style=&quot;text-align: justify;&quot;&gt;&lt;span class=&quot;Apple-style-span&quot; style=&quot;font-family: &#39;Lucida Sans Unicode&#39;, &#39;Lucida Grande&#39;, &#39;Lucida Sans&#39;, Lucida, sans-serif; font-size: 15px;&quot;&gt;&lt;br /&gt;
&lt;/span&gt;&lt;/div&gt;&lt;div style=&quot;text-align: justify;&quot;&gt;&lt;span class=&quot;Apple-style-span&quot; style=&quot;font-family: &#39;Lucida Sans Unicode&#39;, &#39;Lucida Grande&#39;, &#39;Lucida Sans&#39;, Lucida, sans-serif; font-size: 15px;&quot;&gt;Then two .class files are created Example.class and Sample.class.&lt;/span&gt;&lt;/div&gt;&lt;/div&gt;</content><link rel='replies' type='application/atom+xml' href='http://java-intellectual.blogspot.com/feeds/7428470392915638705/comments/default' title='Post Comments'/><link rel='replies' type='text/html' href='http://java-intellectual.blogspot.com/2011/12/can-main-method-is-executed-from-super.html#comment-form' title='0 Comments'/><link rel='edit' type='application/atom+xml' href='http://www.blogger.com/feeds/3771177150982125782/posts/default/7428470392915638705'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/3771177150982125782/posts/default/7428470392915638705'/><link rel='alternate' type='text/html' href='http://java-intellectual.blogspot.com/2011/12/can-main-method-is-executed-from-super.html' title='Can main method is executed from super classes ?'/><author><name>siva</name><uri>http://www.blogger.com/profile/01922721189098931789</uri><email>noreply@blogger.com</email><gd:image rel='http://schemas.google.com/g/2005#thumbnail' width='16' height='16' src='https://img1.blogblog.com/img/b16-rounded.gif'/></author><thr:total>0</thr:total></entry><entry><id>tag:blogger.com,1999:blog-3771177150982125782.post-8148986517217913928</id><published>2011-12-11T18:18:00.000-08:00</published><updated>2011-12-11T21:00:05.117-08:00</updated><category scheme="http://www.blogger.com/atom/ns#" term="OOPS Concepts"/><title type='text'>Differences between this and super keyword in java</title><content type='html'>&lt;div dir=&quot;ltr&quot; style=&quot;text-align: left;&quot; trbidi=&quot;on&quot;&gt;&lt;div style=&quot;text-align: justify;&quot;&gt;&lt;span class=&quot;Apple-style-span&quot; style=&quot;font-family: &#39;Lucida Sans Unicode&#39;,&#39;Lucida Grande&#39;,&#39;Lucida Sans&#39;,Lucida,sans-serif; font-size: 15px;&quot;&gt;The following are the similarities and differences between this and super keyword. One thing keep in mind that we cannot print &#39;super&#39; like &#39;this&#39; why because super class non-static members memory doesn&#39;t have hashcode. And also keep in mind that super method is different from super keyword. super method is used to call super class constructor where as super keyword is used to access super class members.&lt;/span&gt;&lt;/div&gt;&lt;div style=&quot;text-align: justify;&quot;&gt;&lt;span class=&quot;Apple-style-span&quot; style=&quot;font-family: &#39;Lucida Sans Unicode&#39;,&#39;Lucida Grande&#39;,&#39;Lucida Sans&#39;,Lucida,sans-serif; font-size: 15px;&quot;&gt;&lt;/span&gt;&lt;/div&gt;&lt;a name=&#39;more&#39;&gt;&lt;/a&gt;&lt;span class=&quot;Apple-style-span&quot; style=&quot;font-family: &#39;Lucida Sans Unicode&#39;,&#39;Lucida Grande&#39;,&#39;Lucida Sans&#39;,Lucida,sans-serif; font-size: 15px;&quot;&gt;&lt;br /&gt;
&lt;/span&gt;&lt;br /&gt;
&lt;table border=&quot;1&quot;&gt;&lt;tbody&gt;
&lt;tr&gt; &lt;td&gt;&lt;b&gt;&lt;span class=&quot;Apple-style-span&quot; style=&quot;font-family: &#39;Lucida Sans Unicode&#39;,&#39;Lucida Grande&#39;,&#39;Lucida Sans&#39;,Lucida,sans-serif; font-size: 15px;&quot;&gt;this(current class)&lt;/span&gt;&lt;/b&gt;&lt;/td&gt;&lt;td&gt;&lt;b&gt;&lt;span class=&quot;Apple-style-span&quot; style=&quot;font-family: &#39;Lucida Sans Unicode&#39;,&#39;Lucida Grande&#39;,&#39;Lucida Sans&#39;,Lucida,sans-serif; font-size: 15px;&quot;&gt;super(super class)&lt;/span&gt;&lt;/b&gt;&lt;/td&gt;&lt;/tr&gt;
&lt;tr&gt; &lt;td&gt;&lt;span class=&quot;Apple-style-span&quot; style=&quot;font-family: &#39;Lucida Sans Unicode&#39;,&#39;Lucida Grande&#39;,&#39;Lucida Sans&#39;,Lucida,sans-serif; font-size: 15px;&quot;&gt;1.It is a keyword used to store current object reference.&lt;/span&gt;&lt;/td&gt;&lt;td&gt;&lt;span class=&quot;Apple-style-span&quot; style=&quot;font-family: &#39;Lucida Sans Unicode&#39;,&#39;Lucida Grande&#39;,&#39;Lucida Sans&#39;,Lucida,sans-serif; font-size: 15px;&quot;&gt;1.It is a keyword used to store super class object in sub class.&lt;/span&gt;&lt;/td&gt;&lt;/tr&gt;
&lt;tr&gt; &lt;td&gt;&lt;span class=&quot;Apple-style-span&quot; style=&quot;font-family: &#39;Lucida Sans Unicode&#39;,&#39;Lucida Grande&#39;,&#39;Lucida Sans&#39;,Lucida,sans-serif; font-size: 15px;&quot;&gt;2.Pre define instance variable used to hold current object reference.&lt;/span&gt;&lt;/td&gt;&lt;td&gt;&lt;span class=&quot;Apple-style-span&quot; style=&quot;font-family: &#39;Lucida Sans Unicode&#39;,&#39;Lucida Grande&#39;,&#39;Lucida Sans&#39;,Lucida,sans-serif; font-size: 15px;&quot;&gt;2.Pre define instance variable used to hold super class object reference through sub class object.&lt;/span&gt;&lt;/td&gt;&lt;/tr&gt;
&lt;tr&gt;&lt;td&gt;&lt;span class=&quot;Apple-style-span&quot; style=&quot;font-family: &#39;Lucida Sans Unicode&#39;,&#39;Lucida Grande&#39;,&#39;Lucida Sans&#39;,Lucida,sans-serif; font-size: 15px;&quot;&gt;3.Used to&amp;nbsp;separate&amp;nbsp;state of multiple objects of same class and also used to&amp;nbsp;separate&amp;nbsp;local variables and class level variables in a non-static method if both have same name.&lt;/span&gt;&lt;/td&gt;&lt;td&gt;&lt;span class=&quot;Apple-style-span&quot; style=&quot;font-family: &#39;Lucida Sans Unicode&#39;,&#39;Lucida Grande&#39;,&#39;Lucida Sans&#39;,Lucida,sans-serif; font-size: 15px;&quot;&gt;3.Used to seperate super class and subclass members if both have same name.&lt;/span&gt;&lt;/td&gt;&lt;/tr&gt;
&lt;tr&gt;&lt;td&gt;&lt;span class=&quot;Apple-style-span&quot; style=&quot;font-family: &#39;Lucida Sans Unicode&#39;,&#39;Lucida Grande&#39;,&#39;Lucida Sans&#39;,Lucida,sans-serif; font-size: 15px;&quot;&gt;4.It must be used explicitly if non-static variables and local variables or parameter name is same.&lt;/span&gt;&lt;/td&gt;&lt;td&gt;&lt;span class=&quot;Apple-style-span&quot; style=&quot;font-family: &#39;Lucida Sans Unicode&#39;,&#39;Lucida Grande&#39;,&#39;Lucida Sans&#39;,Lucida,sans-serif; font-size: 15px;&quot;&gt;4.It must be used explicitly if super class and sub class members have same names.&lt;/span&gt;&lt;/td&gt;&lt;/tr&gt;
&lt;tr&gt;&lt;td&gt;&lt;span class=&quot;Apple-style-span&quot; style=&quot;font-family: &#39;Lucida Sans Unicode&#39;,&#39;Lucida Grande&#39;,&#39;Lucida Sans&#39;,Lucida,sans-serif; font-size: 15px;&quot;&gt;5.Can&#39;t be referred from static context. It can be printed, means can be called from System.out.println. For example System.out.println(this.x);&lt;/span&gt;&lt;/td&gt;&lt;td&gt;&lt;span class=&quot;Apple-style-span&quot; style=&quot;font-family: &#39;Lucida Sans Unicode&#39;,&#39;Lucida Grande&#39;,&#39;Lucida Sans&#39;,Lucida,sans-serif; font-size: 15px;&quot;&gt;5.Can&#39;t be referred from static context.It can&#39;t be printed, means cannot be called from System.out.println. For example System.out.println(super.x); it leads to compile time error.&lt;/span&gt;&lt;/td&gt;&lt;/tr&gt;
&lt;/tbody&gt;&lt;/table&gt;&lt;/div&gt;</content><link rel='replies' type='application/atom+xml' href='http://java-intellectual.blogspot.com/feeds/8148986517217913928/comments/default' title='Post Comments'/><link rel='replies' type='text/html' href='http://java-intellectual.blogspot.com/2011/12/differences-between-this-and-super.html#comment-form' title='0 Comments'/><link rel='edit' type='application/atom+xml' href='http://www.blogger.com/feeds/3771177150982125782/posts/default/8148986517217913928'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/3771177150982125782/posts/default/8148986517217913928'/><link rel='alternate' type='text/html' href='http://java-intellectual.blogspot.com/2011/12/differences-between-this-and-super.html' title='Differences between this and super keyword in java'/><author><name>siva</name><uri>http://www.blogger.com/profile/01922721189098931789</uri><email>noreply@blogger.com</email><gd:image rel='http://schemas.google.com/g/2005#thumbnail' width='16' height='16' src='https://img1.blogblog.com/img/b16-rounded.gif'/></author><thr:total>0</thr:total></entry><entry><id>tag:blogger.com,1999:blog-3771177150982125782.post-6026216720873616444</id><published>2011-12-10T09:09:00.000-08:00</published><updated>2011-12-10T10:25:22.600-08:00</updated><category scheme="http://www.blogger.com/atom/ns#" term="OOPS Concepts"/><title type='text'>Use of super keyword  in java ?</title><content type='html'>&lt;div dir=&quot;ltr&quot; style=&quot;text-align: left;&quot; trbidi=&quot;on&quot;&gt;&lt;div dir=&quot;ltr&quot; style=&quot;text-align: left;&quot; trbidi=&quot;on&quot;&gt;&lt;div style=&quot;text-align: justify;&quot;&gt;&lt;span class=&quot;Apple-style-span&quot; style=&quot;font-family: &#39;Lucida Sans Unicode&#39;, &#39;Lucida Grande&#39;, &#39;Lucida Sans&#39;, Lucida, sans-serif;&quot;&gt;&lt;span class=&quot;Apple-style-span&quot; style=&quot;font-size: 15px;&quot;&gt;The super is a java keyword,used to access the members of the&amp;nbsp;super class.Use of keyword super is to access the hidden data variables of the&amp;nbsp;super class&amp;nbsp;hidden by subclass.&lt;/span&gt;&lt;/span&gt;&lt;/div&gt;&lt;div style=&quot;text-align: justify;&quot;&gt;&lt;span class=&quot;Apple-style-span&quot; style=&quot;font-family: &#39;Lucida Sans Unicode&#39;, &#39;Lucida Grande&#39;, &#39;Lucida Sans&#39;, Lucida, sans-serif; font-size: 15px;&quot;&gt;Ex:Suppose Example&amp;nbsp;class&amp;nbsp;is the super class in the below program that has two instance variables as int x and int y. Sample&amp;nbsp;class&amp;nbsp;is the subclass that also contains its own data members named x and y,then we can access the super class (Example class) variables x and y inside the subclass (Sample class) just by calling the following command.&lt;/span&gt;&lt;/div&gt;&lt;div style=&quot;text-align: justify;&quot;&gt;&lt;span class=&quot;Apple-style-span&quot; style=&quot;font-family: &#39;Lucida Sans Unicode&#39;, &#39;Lucida Grande&#39;, &#39;Lucida Sans&#39;, Lucida, sans-serif; font-size: 15px;&quot;&gt;super.member;&lt;/span&gt;&lt;/div&gt;&lt;div style=&quot;text-align: justify;&quot;&gt;&lt;span class=&quot;Apple-style-span&quot; style=&quot;font-family: &#39;Lucida Sans Unicode&#39;, &#39;Lucida Grande&#39;, &#39;Lucida Sans&#39;, Lucida, sans-serif; font-size: 15px;&quot;&gt;Here member can either be an instance variable or a method. super keyword most useful to handle situations where the local members of the subclass hide the members of the super class having the same name.&lt;/span&gt;&lt;/div&gt;&lt;div style=&quot;text-align: justify;&quot;&gt;&lt;span class=&quot;Apple-style-span&quot; style=&quot;font-family: &#39;Lucida Sans Unicode&#39;, &#39;Lucida Grande&#39;, &#39;Lucida Sans&#39;, Lucida, sans-serif; font-size: 15px;&quot;&gt;&lt;/span&gt;&lt;br /&gt;
&lt;a name=&#39;more&#39;&gt;&lt;/a&gt;&lt;/div&gt;&lt;div style=&quot;text-align: justify;&quot;&gt;&lt;span class=&quot;Apple-style-span&quot; style=&quot;font-family: &#39;Lucida Sans Unicode&#39;, &#39;Lucida Grande&#39;, &#39;Lucida Sans&#39;, Lucida, sans-serif; font-size: 15px;&quot;&gt;Hence super keyword can be defined as &quot;&lt;b&gt;it&#39;s a non static variable used to store super class non-static memory reference through current sub class object.&lt;/b&gt;&quot;&lt;/span&gt;&lt;br /&gt;
&lt;span class=&quot;Apple-style-span&quot; style=&quot;font-family: &#39;Lucida Sans Unicode&#39;, &#39;Lucida Grande&#39;, &#39;Lucida Sans&#39;, Lucida, sans-serif; font-size: 15px;&quot;&gt;&lt;/span&gt;&lt;br /&gt;
&lt;span class=&quot;Apple-style-span&quot; style=&quot;font-family: &#39;Lucida Sans Unicode&#39;, &#39;Lucida Grande&#39;, &#39;Lucida Sans&#39;, Lucida, sans-serif; font-size: 15px;&quot;&gt;&lt;b&gt;//Example.java&lt;/b&gt;&lt;/span&gt;&lt;/div&gt;&lt;span class=&quot;Apple-style-span&quot; style=&quot;font-family: &#39;Lucida Sans Unicode&#39;, &#39;Lucida Grande&#39;, &#39;Lucida Sans&#39;, Lucida, sans-serif; font-size: 15px;&quot;&gt;&lt;pre class=&quot;brush:java;&quot;&gt;class Example
{
   int x=10;
   int y=20;
   void m1(){
      System.out.println(&quot;Example m1&quot;);
   }
}&lt;/pre&gt;&lt;/span&gt;&lt;br /&gt;
&lt;b&gt;&lt;span class=&quot;Apple-style-span&quot; style=&quot;font-family: &#39;Lucida Sans Unicode&#39;, &#39;Lucida Grande&#39;, &#39;Lucida Sans&#39;, Lucida, sans-serif;&quot;&gt;&lt;span class=&quot;Apple-style-span&quot; style=&quot;font-size: 15px;&quot;&gt;//Sample.java&lt;/span&gt;&lt;span class=&quot;Apple-style-span&quot; style=&quot;font-size: 15px;&quot;&gt;&lt;/span&gt;&lt;/span&gt;&lt;/b&gt;&lt;br /&gt;
&lt;span class=&quot;Apple-style-span&quot; style=&quot;font-family: &#39;Lucida Sans Unicode&#39;, &#39;Lucida Grande&#39;, &#39;Lucida Sans&#39;, Lucida, sans-serif; font-size: 15px;&quot;&gt;&lt;pre class=&quot;brush:java;&quot;&gt;class Sample extends Example
{
   void m2(){
      System.out.println(&quot;x: &quot;+x);
      System.out.println(&quot;y: &quot;+y);
   }
   public static void main(String[] args)
   {
      Sample s = new Sample();
      s.m2();
   }
}
&lt;/pre&gt;&lt;/span&gt;&lt;br /&gt;
&lt;span class=&quot;Apple-style-span&quot; style=&quot;font-family: &#39;Lucida Sans Unicode&#39;,&#39;Lucida Grande&#39;,&#39;Lucida Sans&#39;,Lucida,sans-serif; font-size: 15px;&quot;&gt;&lt;b&gt;Output:&lt;/b&gt;&lt;/span&gt;&lt;br /&gt;
&lt;br /&gt;
&lt;div&gt;&lt;span class=&quot;Apple-style-span&quot;&gt;&lt;div&gt;&lt;span class=&quot;Apple-style-span&quot; style=&quot;font-family: &#39;Lucida Sans Unicode&#39;,&#39;Lucida Grande&#39;,&#39;Lucida Sans&#39;,Lucida,sans-serif; font-size: 15px;&quot;&gt;&amp;nbsp;&amp;nbsp;x: 10&lt;/span&gt;&lt;/div&gt;&lt;div&gt;&lt;span class=&quot;Apple-style-span&quot; style=&quot;font-family: &#39;Lucida Sans Unicode&#39;,&#39;Lucida Grande&#39;,&#39;Lucida Sans&#39;,Lucida,sans-serif; font-size: 15px;&quot;&gt;&amp;nbsp;&amp;nbsp;y: 20&lt;/span&gt;&lt;/div&gt;&lt;/span&gt;&lt;/div&gt;&lt;br /&gt;
&lt;div style=&quot;text-align: justify;&quot;&gt;&lt;span class=&quot;Apple-style-span&quot; style=&quot;font-family: &#39;Lucida Sans Unicode&#39;, &#39;Lucida Grande&#39;, &#39;Lucida Sans&#39;, Lucida, sans-serif;&quot;&gt;&lt;span class=&quot;Apple-style-span&quot; style=&quot;font-size: 15px;&quot;&gt;In the above program compiler first checks if the variables are available in that method or not which is nothing but &lt;/span&gt;&lt;b style=&quot;font-size: 15px;&quot;&gt;local preference&lt;/b&gt;&lt;span class=&quot;Apple-style-span&quot; style=&quot;font-size: 15px;&quot;&gt; if they are available then they are accessed from that method itself if they are not available then compiler replaces x and y variables by this.x and this.y to check variables are present at sub class level, if the&amp;nbsp;variables&amp;nbsp;are not available in sub class they are replaced by super.x and super.y to access those variables if they are present in super class. This is the internal mechanism done by compiler. &quot;this&quot; and &quot;super&quot; keyword is placed implicitly. But if you want to place those keywords explicitly then check below program.&lt;/span&gt;&lt;/span&gt;&lt;br /&gt;
&lt;span class=&quot;Apple-style-span&quot; style=&quot;font-family: &#39;Lucida Sans Unicode&#39;, &#39;Lucida Grande&#39;, &#39;Lucida Sans&#39;, Lucida, sans-serif; font-size: 15px;&quot;&gt;&lt;/span&gt;&lt;br /&gt;
&lt;span class=&quot;Apple-style-span&quot; style=&quot;font-family: &#39;Lucida Sans Unicode&#39;, &#39;Lucida Grande&#39;, &#39;Lucida Sans&#39;, Lucida, sans-serif; font-size: 15px;&quot;&gt;&lt;b&gt;//Example.java&lt;/b&gt;&lt;/span&gt;&lt;/div&gt;&lt;/div&gt;&lt;span class=&quot;Apple-style-span&quot; style=&quot;font-family: &#39;Lucida Sans Unicode&#39;, &#39;Lucida Grande&#39;, &#39;Lucida Sans&#39;, Lucida, sans-serif; font-size: 15px;&quot;&gt;&lt;pre class=&quot;brush:java;&quot;&gt;class Example
{
   int x=50;
   int y=60;
   void m1(){
      System.out.println(&quot;Example m1&quot;);
   }
}&lt;/pre&gt;&lt;/span&gt;&lt;br /&gt;
&lt;span class=&quot;Apple-style-span&quot; style=&quot;font-family: &#39;Lucida Sans Unicode&#39;, &#39;Lucida Grande&#39;, &#39;Lucida Sans&#39;, Lucida, sans-serif; font-size: 15px;&quot;&gt;&lt;b&gt;//Sample.java&lt;/b&gt;&lt;/span&gt;&lt;br /&gt;
&lt;span class=&quot;Apple-style-span&quot; style=&quot;font-family: &#39;Lucida Sans Unicode&#39;, &#39;Lucida Grande&#39;, &#39;Lucida Sans&#39;, Lucida, sans-serif; font-size: 15px;&quot;&gt;&lt;pre class=&quot;brush:java;&quot;&gt;class Sample extends Example
{
   int x=30;//class level variables
   int y=40;

   void m2(){
      int x=10;//loacal preference 
      int y=20;

      System.out.println(&quot;x: &quot;+x);
      System.out.println(&quot;y: &quot;+y);
      System.out.println();
      System.out.println(&quot;x: &quot;+this.x);
      System.out.println(&quot;y: &quot;+this.y);
      System.out.println();
      System.out.println(&quot;x: &quot;+super.x);
      System.out.println(&quot;y: &quot;+super.y);
    }

   public static void main(String[] args){
      Sample s = new Sample();
      s.m2();
   }
}&lt;/pre&gt;&lt;/span&gt;&lt;br /&gt;
&lt;span class=&quot;Apple-style-span&quot; style=&quot;font-family: &#39;Lucida Sans Unicode&#39;,&#39;Lucida Grande&#39;,&#39;Lucida Sans&#39;,Lucida,sans-serif; font-size: 15px;&quot;&gt;&lt;b&gt;Output:&lt;/b&gt;&lt;/span&gt;&lt;br /&gt;
&lt;br /&gt;
&lt;span class=&quot;Apple-style-span&quot; style=&quot;font-family: &#39;Lucida Sans Unicode&#39;,&#39;Lucida Grande&#39;,&#39;Lucida Sans&#39;,Lucida,sans-serif; font-size: 15px;&quot;&gt;&amp;nbsp;&amp;nbsp;x: 10&lt;/span&gt;&lt;br /&gt;
&lt;span class=&quot;Apple-style-span&quot; style=&quot;font-family: &#39;Lucida Sans Unicode&#39;,&#39;Lucida Grande&#39;,&#39;Lucida Sans&#39;,Lucida,sans-serif; font-size: 15px;&quot;&gt;&amp;nbsp;&amp;nbsp;y: 20&lt;/span&gt;&lt;br /&gt;
&lt;br /&gt;
&lt;span class=&quot;Apple-style-span&quot; style=&quot;font-family: &#39;Lucida Sans Unicode&#39;,&#39;Lucida Grande&#39;,&#39;Lucida Sans&#39;,Lucida,sans-serif; font-size: 15px;&quot;&gt;&amp;nbsp;&amp;nbsp;x: 30&lt;/span&gt;&lt;br /&gt;
&lt;span class=&quot;Apple-style-span&quot; style=&quot;font-family: &#39;Lucida Sans Unicode&#39;,&#39;Lucida Grande&#39;,&#39;Lucida Sans&#39;,Lucida,sans-serif; font-size: 15px;&quot;&gt;&amp;nbsp;&amp;nbsp;y: 40&lt;/span&gt;&lt;br /&gt;
&lt;br /&gt;
&lt;span class=&quot;Apple-style-span&quot; style=&quot;font-family: &#39;Lucida Sans Unicode&#39;,&#39;Lucida Grande&#39;,&#39;Lucida Sans&#39;,Lucida,sans-serif; font-size: 15px;&quot;&gt;&amp;nbsp;&amp;nbsp;x: 50&lt;/span&gt;&lt;br /&gt;
&lt;span class=&quot;Apple-style-span&quot; style=&quot;font-family: &#39;Lucida Sans Unicode&#39;,&#39;Lucida Grande&#39;,&#39;Lucida Sans&#39;,Lucida,sans-serif; font-size: 15px;&quot;&gt;&amp;nbsp;&amp;nbsp;y: 60&lt;/span&gt;&lt;br /&gt;
&lt;/div&gt;</content><link rel='replies' type='application/atom+xml' href='http://java-intellectual.blogspot.com/feeds/6026216720873616444/comments/default' title='Post Comments'/><link rel='replies' type='text/html' href='http://java-intellectual.blogspot.com/2011/12/use-of-super-keyword-in-java.html#comment-form' title='0 Comments'/><link rel='edit' type='application/atom+xml' href='http://www.blogger.com/feeds/3771177150982125782/posts/default/6026216720873616444'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/3771177150982125782/posts/default/6026216720873616444'/><link rel='alternate' type='text/html' href='http://java-intellectual.blogspot.com/2011/12/use-of-super-keyword-in-java.html' title='Use of super keyword  in java ?'/><author><name>siva</name><uri>http://www.blogger.com/profile/01922721189098931789</uri><email>noreply@blogger.com</email><gd:image rel='http://schemas.google.com/g/2005#thumbnail' width='16' height='16' src='https://img1.blogblog.com/img/b16-rounded.gif'/></author><thr:total>0</thr:total></entry><entry><id>tag:blogger.com,1999:blog-3771177150982125782.post-621140852572882150</id><published>2011-12-08T20:26:00.000-08:00</published><updated>2011-12-08T21:05:26.697-08:00</updated><category scheme="http://www.blogger.com/atom/ns#" term="OOPS Concepts"/><title type='text'>What is super method in java ?</title><content type='html'>&lt;div dir=&quot;ltr&quot; style=&quot;text-align: left;&quot; trbidi=&quot;on&quot;&gt;&lt;div dir=&quot;ltr&quot; style=&quot;text-align: left;&quot; trbidi=&quot;on&quot;&gt;&lt;div style=&quot;text-align: justify;&quot;&gt;&lt;span class=&quot;Apple-style-span&quot; style=&quot;font-family: &#39;Lucida Sans Unicode&#39;, &#39;Lucida Grande&#39;, &#39;Lucida Sans&#39;, Lucida, sans-serif; font-size: 15px;&quot;&gt;super() method is used to call super class constructor from subclass constructor to create super class object .You might get a doubt that who does place this super() method in all constructors. Compiler only places the super method call in all constructors at the time of compilation.Even though we&amp;nbsp;don&#39;t&amp;nbsp;place super() method in constructor compiler places the super() method call in all constructors explicitly.&lt;/span&gt;&lt;br /&gt;
&lt;span class=&quot;Apple-style-span&quot; style=&quot;font-family: &#39;Lucida Sans Unicode&#39;, &#39;Lucida Grande&#39;, &#39;Lucida Sans&#39;, Lucida, sans-serif; font-size: 15px;&quot;&gt;&lt;/span&gt;&lt;br /&gt;
&lt;a name=&#39;more&#39;&gt;&lt;/a&gt;&lt;br /&gt;
&lt;span class=&quot;Apple-style-span&quot; style=&quot;font-family: &#39;Lucida Sans Unicode&#39;, &#39;Lucida Grande&#39;, &#39;Lucida Sans&#39;, Lucida, sans-serif; font-size: 15px;&quot;&gt;&lt;b&gt;//Example.java&lt;/b&gt;&lt;/span&gt;&lt;/div&gt;&lt;span class=&quot;Apple-style-span&quot; style=&quot;font-size: 15px;&quot;&gt;&lt;pre class=&quot;brush:java;&quot;&gt;class Example extends Object
{
   Example(){
      //super();This method is placed by constructor implicitly to call object class constructor
      System.out.println(&quot;Example No-arg constructor&quot;);
   }
}
&lt;/pre&gt;&lt;/span&gt;&lt;br /&gt;
&lt;span class=&quot;Apple-style-span&quot; style=&quot;font-family: &#39;Lucida Sans Unicode&#39;, &#39;Lucida Grande&#39;, &#39;Lucida Sans&#39;, Lucida, sans-serif; font-size: 15px;&quot;&gt;&lt;b&gt;//Sample.java&lt;/b&gt;&lt;/span&gt;&lt;br /&gt;
&lt;span class=&quot;Apple-style-span&quot; style=&quot;font-size: 15px;&quot;&gt;&lt;pre class=&quot;brush:java;&quot;&gt;class Sample extends Example
{
   Sample(){
      //super(); This method is placed by constructor implicitly
      System.out.println(&quot;Sample No-arg constructor&quot;);
   }
   public static void main(String[] args){
      Sample s = new Sample();
   }
}
&lt;/pre&gt;&lt;/span&gt;&lt;br /&gt;
&lt;div style=&quot;text-align: justify;&quot;&gt;&lt;span class=&quot;Apple-style-span&quot; style=&quot;font-family: &#39;Lucida Sans Unicode&#39;, &#39;Lucida Grande&#39;, &#39;Lucida Sans&#39;, Lucida, sans-serif; font-size: 15px;&quot;&gt;Object class is nothing but the superclass of all classes it contains 11 methods. In the above program compiler automatically extends the object class in Example program even if you&amp;nbsp;&lt;/span&gt;&lt;span class=&quot;Apple-style-span&quot; style=&quot;font-family: &#39;Lucida Sans Unicode&#39;, &#39;Lucida Grande&#39;, &#39;Lucida Sans&#39;, Lucida, sans-serif; font-size: 15px;&quot;&gt;don&#39;t&lt;/span&gt;&lt;span class=&quot;Apple-style-span&quot; style=&quot;font-family: &#39;Lucida Sans Unicode&#39;, &#39;Lucida Grande&#39;, &#39;Lucida Sans&#39;, Lucida, sans-serif; font-size: 15px;&quot;&gt;&amp;nbsp;extend the object class&lt;/span&gt;&lt;/div&gt;&lt;div style=&quot;text-align: justify;&quot;&gt;&lt;span class=&quot;Apple-style-span&quot; style=&quot;font-family: &#39;Lucida Sans Unicode&#39;, &#39;Lucida Grande&#39;, &#39;Lucida Sans&#39;, Lucida, sans-serif; font-size: 15px;&quot;&gt;When super() method should be placed by developer ?&lt;/span&gt;&lt;/div&gt;&lt;div style=&quot;text-align: justify;&quot;&gt;&lt;span class=&quot;Apple-style-span&quot; style=&quot;font-family: &#39;Lucida Sans Unicode&#39;, &#39;Lucida Grande&#39;, &#39;Lucida Sans&#39;, Lucida, sans-serif; font-size: 15px;&quot;&gt;Developer should place super() method call in below two cases&lt;/span&gt;&lt;/div&gt;&lt;div style=&quot;text-align: justify;&quot;&gt;&lt;span class=&quot;Apple-style-span&quot; style=&quot;font-family: &#39;Lucida Sans Unicode&#39;, &#39;Lucida Grande&#39;, &#39;Lucida Sans&#39;, Lucida, sans-serif; font-size: 15px;&quot;&gt;1. If super class does not contain no-arg constructor that is if it contains parameterized constructor. &amp;nbsp;&lt;/span&gt;&lt;/div&gt;&lt;div style=&quot;text-align: justify;&quot;&gt;&lt;span class=&quot;Apple-style-span&quot; style=&quot;font-family: &#39;Lucida Sans Unicode&#39;, &#39;Lucida Grande&#39;, &#39;Lucida Sans&#39;, Lucida, sans-serif; font-size: 15px;&quot;&gt;2. If developer wants to create super class object with parameterized constructor&lt;/span&gt;&lt;/div&gt;&lt;div style=&quot;text-align: justify;&quot;&gt;&lt;span class=&quot;Apple-style-span&quot; style=&quot;font-family: &#39;Lucida Sans Unicode&#39;, &#39;Lucida Grande&#39;, &#39;Lucida Sans&#39;, Lucida, sans-serif; font-size: 15px;&quot;&gt;&lt;br /&gt;
&lt;/span&gt;&lt;/div&gt;&lt;div style=&quot;text-align: justify;&quot;&gt;&lt;span class=&quot;Apple-style-span&quot; style=&quot;font-family: &#39;Lucida Sans Unicode&#39;, &#39;Lucida Grande&#39;, &#39;Lucida Sans&#39;, Lucida, sans-serif; font-size: 15px;&quot;&gt;In the above two cases developer should define constructor in sub class with explicit super() method call by passing argument of type same as super class constructor type.Check the below program.&lt;/span&gt;&lt;br /&gt;
&lt;span class=&quot;Apple-style-span&quot; style=&quot;font-family: &#39;Lucida Sans Unicode&#39;, &#39;Lucida Grande&#39;, &#39;Lucida Sans&#39;, Lucida, sans-serif; font-size: 15px;&quot;&gt;&lt;br /&gt;
&lt;/span&gt;&lt;br /&gt;
&lt;span class=&quot;Apple-style-span&quot; style=&quot;font-family: &#39;Lucida Sans Unicode&#39;, &#39;Lucida Grande&#39;, &#39;Lucida Sans&#39;, Lucida, sans-serif; font-size: 15px;&quot;&gt;&lt;b&gt;//Example.java&lt;/b&gt;&lt;/span&gt;&lt;/div&gt;&lt;/div&gt;&lt;span class=&quot;Apple-style-span&quot; style=&quot;font-size: 15px;&quot;&gt;&lt;/span&gt;&lt;br /&gt;
&lt;span class=&quot;Apple-style-span&quot; style=&quot;font-size: 15px;&quot;&gt;&lt;pre class=&quot;brush:java;&quot;&gt;class Example
{
   Example(){
      //super(); Compiler placed super method call
      System.out.println(&quot;Example no-arg constructor&quot;);
   }
   Example(int a){
      //super(); Compiler placed super method call
      System.out.println(&quot;Example int arg constructor&quot;);
   }
}&lt;/pre&gt;&lt;/span&gt;&lt;br /&gt;
&lt;span class=&quot;Apple-style-span&quot; style=&quot;font-family: &#39;Lucida Sans Unicode&#39;, &#39;Lucida Grande&#39;, &#39;Lucida Sans&#39;, Lucida, sans-serif; font-size: 15px;&quot;&gt;&lt;b&gt;//Sample.java&lt;/b&gt;&lt;br /&gt;
&lt;/span&gt;&lt;span class=&quot;Apple-style-span&quot; style=&quot;font-size: 15px;&quot;&gt;&lt;/span&gt;&lt;br /&gt;
&lt;span class=&quot;Apple-style-span&quot; style=&quot;font-size: 15px;&quot;&gt;&lt;pre class=&quot;brush:java;&quot;&gt;class Sample extends Example
{
   Sample(){
      //super(); Compiler placed super method call
      System.out.println(&quot;Sample no-arg constructor&quot;);
   }
   Sample(int a){
      //super(); Compiler placed super method call
      System.out.println(&quot;Sample int-arg constructor&quot;);
   }
   public static void main(String[] args)
   {
      Sample s1 = new Sample();
      Sample s2 = new Sample(10);
   }
}   
&lt;/pre&gt;&lt;/span&gt;&lt;br /&gt;
&lt;span class=&quot;Apple-style-span&quot; style=&quot;font-family: &#39;Lucida Sans Unicode&#39;, &#39;Lucida Grande&#39;, &#39;Lucida Sans&#39;, Lucida, sans-serif; font-size: 15px;&quot;&gt;&lt;b&gt;Output:&lt;/b&gt;&lt;br /&gt;
&lt;/span&gt;&lt;br /&gt;
&lt;span class=&quot;Apple-style-span&quot; style=&quot;font-family: &#39;Lucida Sans Unicode&#39;, &#39;Lucida Grande&#39;, &#39;Lucida Sans&#39;, Lucida, sans-serif; font-size: 15px;&quot;&gt;Example no-arg constructor&lt;br /&gt;
Sample no-arg constructor&lt;br /&gt;
Example no-arg constructor&lt;br /&gt;
Sample int-arg constructor&lt;/span&gt;&lt;br /&gt;
&lt;div style=&quot;text-align: justify;&quot;&gt;&lt;span class=&quot;Apple-style-span&quot; style=&quot;font-size: 15px;&quot;&gt;&lt;br /&gt;
&lt;span class=&quot;Apple-style-span&quot; style=&quot;font-family: &#39;Lucida Sans Unicode&#39;, &#39;Lucida Grande&#39;, &#39;Lucida Sans&#39;, Lucida, sans-serif; font-size: 15px;&quot;&gt;If we do not place super method call by passing a value in parameterized constructor,compiler places default super() method call ,then Example no-arg constructor is called shown in the above program. So if we want to call super class parameterized constructor developer need to place super method call explicitly with some value in subclass parameterized constructor by creating subclass object by passing some value. The below program shows the importance of super method call that should be placed explicitly.&lt;/span&gt;&lt;/span&gt;&lt;/div&gt;&lt;span class=&quot;Apple-style-span&quot; style=&quot;font-size: 15px;&quot;&gt;&lt;span class=&quot;Apple-style-span&quot; style=&quot;font-family: &#39;Lucida Sans Unicode&#39;, &#39;Lucida Grande&#39;, &#39;Lucida Sans&#39;, Lucida, sans-serif; font-size: 15px;&quot;&gt;&lt;br /&gt;
&lt;/span&gt;&lt;/span&gt;&lt;br /&gt;
&lt;span class=&quot;Apple-style-span&quot;&gt;&lt;span class=&quot;Apple-style-span&quot; style=&quot;font-family: &#39;Lucida Sans Unicode&#39;, &#39;Lucida Grande&#39;, &#39;Lucida Sans&#39;, Lucida, sans-serif; font-size: 15px;&quot;&gt;&lt;b&gt;//Example.java&lt;/b&gt;&lt;br /&gt;
&lt;/span&gt;&lt;span class=&quot;Apple-style-span&quot;&gt;&lt;span class=&quot;Apple-style-span&quot; style=&quot;font-size: 16px;&quot;&gt;&lt;pre class=&quot;brush:java;&quot;&gt;class Example
{
   Example(){
      //super(); Compiler placed super method call
      System.out.println(&quot;Example no-arg constructor&quot;);
   }
   Example(int a){
      //super(); Compiler placed super method call
      System.out.println(&quot;Example int arg constructor&quot;);
   }
}
&lt;/pre&gt;&lt;/span&gt;&lt;br /&gt;
&lt;/span&gt;&lt;span class=&quot;Apple-style-span&quot; style=&quot;font-size: medium;&quot;&gt;&lt;br /&gt;
&lt;/span&gt;&lt;/span&gt;&lt;span class=&quot;Apple-style-span&quot; style=&quot;font-family: &#39;Lucida Sans Unicode&#39;, &#39;Lucida Grande&#39;, &#39;Lucida Sans&#39;, Lucida, sans-serif; font-size: 15px;&quot;&gt;&lt;b&gt;//Sample.java&lt;/b&gt;&lt;/span&gt;&lt;span class=&quot;Apple-style-span&quot; style=&quot;font-size: 15px;&quot;&gt;&lt;span class=&quot;Apple-style-span&quot; style=&quot;font-family: &#39;Lucida Sans Unicode&#39;, &#39;Lucida Grande&#39;, &#39;Lucida Sans&#39;, Lucida, sans-serif;&quot;&gt;&lt;br /&gt;
&lt;/span&gt;&lt;span class=&quot;Apple-style-span&quot; style=&quot;font-size: 15px;&quot;&gt;&lt;span class=&quot;Apple-style-span&quot; style=&quot;font-size: 16px;&quot;&gt;&lt;pre class=&quot;brush:java;&quot;&gt;class Sample extends Example
{
   Sample(){
      //super(); Compiler placed super method call
      System.out.println(&quot;Sample no-arg constructor&quot;);
   }
   Sample(int a){
      super(10);
      System.out.println(&quot;Sample int-arg constructor&quot;);
   }
   public static void main(String[] args)
   {
      Sample s1 = new Sample();
      Sample s2 = new Sample(10);
   }
}   

&lt;/pre&gt;&lt;/span&gt;&lt;br /&gt;
&lt;span class=&quot;Apple-style-span&quot; style=&quot;font-family: &#39;Lucida Sans Unicode&#39;, &#39;Lucida Grande&#39;, &#39;Lucida Sans&#39;, Lucida, sans-serif; font-size: 15px;&quot;&gt;&lt;b&gt;Output:&lt;/b&gt;&lt;/span&gt;&lt;/span&gt;&lt;/span&gt;&lt;br /&gt;
&lt;span class=&quot;Apple-style-span&quot; style=&quot;font-size: 15px;&quot;&gt;&lt;span class=&quot;Apple-style-span&quot; style=&quot;font-size: 15px;&quot;&gt;&lt;br /&gt;
&lt;span class=&quot;Apple-style-span&quot; style=&quot;font-family: &#39;Lucida Sans Unicode&#39;, &#39;Lucida Grande&#39;, &#39;Lucida Sans&#39;, Lucida, sans-serif; font-size: 15px;&quot;&gt;Example no-arg constructor&lt;br /&gt;
Sample no-arg constructor&lt;br /&gt;
Example int arg constructor&lt;br /&gt;
Sample int-arg constructor&lt;/span&gt;&lt;br /&gt;
&lt;/span&gt;&lt;/span&gt;&lt;br /&gt;
&lt;/div&gt;</content><link rel='replies' type='application/atom+xml' href='http://java-intellectual.blogspot.com/feeds/621140852572882150/comments/default' title='Post Comments'/><link rel='replies' type='text/html' href='http://java-intellectual.blogspot.com/2011/12/super-method-in-java.html#comment-form' title='0 Comments'/><link rel='edit' type='application/atom+xml' href='http://www.blogger.com/feeds/3771177150982125782/posts/default/621140852572882150'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/3771177150982125782/posts/default/621140852572882150'/><link rel='alternate' type='text/html' href='http://java-intellectual.blogspot.com/2011/12/super-method-in-java.html' title='What is super method in java ?'/><author><name>siva</name><uri>http://www.blogger.com/profile/01922721189098931789</uri><email>noreply@blogger.com</email><gd:image rel='http://schemas.google.com/g/2005#thumbnail' width='16' height='16' src='https://img1.blogblog.com/img/b16-rounded.gif'/></author><thr:total>0</thr:total></entry><entry><id>tag:blogger.com,1999:blog-3771177150982125782.post-4580314851714367213</id><published>2011-12-06T06:46:00.000-08:00</published><updated>2011-12-08T03:20:18.532-08:00</updated><category scheme="http://www.blogger.com/atom/ns#" term="OOPS Concepts"/><title type='text'>Compiler and JVM activities of a java program with inheritance</title><content type='html'>&lt;div dir=&quot;ltr&quot; style=&quot;text-align: left;&quot; trbidi=&quot;on&quot;&gt;&lt;div style=&quot;text-align: justify;&quot;&gt;&lt;span class=&quot;Apple-style-span&quot; style=&quot;font-family: &#39;Lucida Sans Unicode&#39;, &#39;Lucida Grande&#39;, &#39;Lucida Sans&#39;, Lucida, sans-serif; font-size: 15px;&quot;&gt;&lt;b&gt;Compiler Activities:&lt;/b&gt;&lt;/span&gt;&lt;/div&gt;&lt;div style=&quot;text-align: justify;&quot;&gt;&lt;span class=&quot;Apple-style-span&quot; style=&quot;font-family: &#39;Lucida Sans Unicode&#39;, &#39;Lucida Grande&#39;, &#39;Lucida Sans&#39;, Lucida, sans-serif; font-size: 15px;&quot;&gt;&lt;br /&gt;
&lt;/span&gt;&lt;/div&gt;&lt;div style=&quot;text-align: justify;&quot;&gt;&lt;span class=&quot;Apple-style-span&quot; style=&quot;font-family: &#39;Lucida Sans Unicode&#39;, &#39;Lucida Grande&#39;, &#39;Lucida Sans&#39;, Lucida, sans-serif; font-size: 15px;&quot;&gt;While compiling a class with inheritance relationship, compiler first compiles the super class and then it compiles the sub class&lt;/span&gt;&lt;/div&gt;&lt;div style=&quot;text-align: justify;&quot;&gt;&lt;span class=&quot;Apple-style-span&quot; style=&quot;font-family: &#39;Lucida Sans Unicode&#39;, &#39;Lucida Grande&#39;, &#39;Lucida Sans&#39;, Lucida, sans-serif; font-size: 15px;&quot;&gt;In finding method or&amp;nbsp;variables&amp;nbsp;definitions, compiler always first search in sub class. If it is not available in sub class, it searches in immediate super class. If there also it is not available compiler throws &lt;span class=&quot;Apple-style-span&quot; style=&quot;color: #990000;&quot;&gt;CE: &quot;cannot find symbol&quot;&lt;/span&gt;&lt;/span&gt;&lt;/div&gt;&lt;div style=&quot;text-align: justify;&quot;&gt;&lt;span class=&quot;Apple-style-span&quot; style=&quot;font-family: &#39;Lucida Sans Unicode&#39;, &#39;Lucida Grande&#39;, &#39;Lucida Sans&#39;, Lucida, sans-serif; font-size: 15px;&quot;&gt;This phenomenon is called local preference.&lt;/span&gt;&lt;/div&gt;&lt;div style=&quot;text-align: justify;&quot;&gt;&lt;span class=&quot;Apple-style-span&quot; style=&quot;font-family: &#39;Lucida Sans Unicode&#39;, &#39;Lucida Grande&#39;, &#39;Lucida Sans&#39;, Lucida, sans-serif; font-size: 15px;&quot;&gt;&lt;br /&gt;
&lt;/span&gt;&lt;/div&gt;&lt;div style=&quot;text-align: justify;&quot;&gt;&lt;span class=&quot;Apple-style-span&quot; style=&quot;font-family: &#39;Lucida Sans Unicode&#39;, &#39;Lucida Grande&#39;, &#39;Lucida Sans&#39;, Lucida, sans-serif; font-size: 15px;&quot;&gt;&lt;b&gt;JVM Activities:&lt;/b&gt;&lt;/span&gt;&lt;/div&gt;&lt;div style=&quot;text-align: justify;&quot;&gt;&lt;span class=&quot;Apple-style-span&quot; style=&quot;font-family: &#39;Lucida Sans Unicode&#39;, &#39;Lucida Grande&#39;, &#39;Lucida Sans&#39;, Lucida, sans-serif; font-size: 15px;&quot;&gt;&lt;br /&gt;
&lt;/span&gt;&lt;/div&gt;&lt;div style=&quot;text-align: justify;&quot;&gt;&lt;span class=&quot;Apple-style-span&quot; style=&quot;font-family: &#39;Lucida Sans Unicode&#39;, &#39;Lucida Grande&#39;, &#39;Lucida Sans&#39;, Lucida, sans-serif; font-size: 15px;&quot;&gt;JVM also executes the invoked members from sub class, if that member definition is not available in sub class,JVM executes it from super class&lt;/span&gt;&lt;/div&gt;&lt;div style=&quot;text-align: justify;&quot;&gt;&lt;span class=&quot;Apple-style-span&quot; style=&quot;font-family: &#39;Lucida Sans Unicode&#39;, &#39;Lucida Grande&#39;, &#39;Lucida Sans&#39;, Lucida, sans-serif; font-size: 15px;&quot;&gt;Execution control flow in inheritance:&lt;/span&gt;&lt;/div&gt;&lt;div style=&quot;text-align: justify;&quot;&gt;&lt;span class=&quot;Apple-style-span&quot; style=&quot;font-family: &#39;Lucida Sans Unicode&#39;, &#39;Lucida Grande&#39;, &#39;Lucida Sans&#39;, Lucida, sans-serif; font-size: 15px;&quot;&gt;when sub class is loaded its entire super classes are loaded, and also when sub class object is created all its super class memory is created.&lt;/span&gt;&lt;/div&gt;&lt;div style=&quot;text-align: justify;&quot;&gt;&lt;span class=&quot;Apple-style-span&quot; style=&quot;font-family: &#39;Lucida Sans Unicode&#39;, &#39;Lucida Grande&#39;, &#39;Lucida Sans&#39;, Lucida, sans-serif; font-size: 15px;&quot;&gt;What is the order of execution of class members when we invoke them using sub class object ?&lt;/span&gt;&lt;br /&gt;
&lt;span class=&quot;Apple-style-span&quot; style=&quot;font-family: &#39;Lucida Sans Unicode&#39;, &#39;Lucida Grande&#39;, &#39;Lucida Sans&#39;, Lucida, sans-serif; font-size: 15px;&quot;&gt;&lt;/span&gt;&lt;br /&gt;
&lt;a name=&#39;more&#39;&gt;&lt;/a&gt;&lt;/div&gt;&lt;div style=&quot;text-align: justify;&quot;&gt;&lt;span class=&quot;Apple-style-span&quot; style=&quot;font-family: &#39;Lucida Sans Unicode&#39;, &#39;Lucida Grande&#39;, &#39;Lucida Sans&#39;, Lucida, sans-serif; font-size: 15px;&quot;&gt;1. Class loading order is from super class to sub class.&amp;nbsp;Static variables and static blocks execution is from super class to sub class&lt;/span&gt;&lt;/div&gt;&lt;div style=&quot;text-align: justify;&quot;&gt;&lt;span class=&quot;Apple-style-span&quot; style=&quot;font-family: &#39;Lucida Sans Unicode&#39;, &#39;Lucida Grande&#39;, &#39;Lucida Sans&#39;, Lucida, sans-serif; font-size: 15px;&quot;&gt;If you want to know that then type&lt;/span&gt;&lt;/div&gt;&lt;div style=&quot;text-align: justify;&quot;&gt;&lt;span class=&quot;Apple-style-span&quot; style=&quot;font-family: &#39;Lucida Sans Unicode&#39;, &#39;Lucida Grande&#39;, &#39;Lucida Sans&#39;, Lucida, sans-serif; font-size: 15px;&quot;&gt;java -verbose:class&amp;nbsp;subclass-name&amp;nbsp;in command prompt&lt;/span&gt;&lt;/div&gt;&lt;div style=&quot;text-align: justify;&quot;&gt;&lt;span class=&quot;Apple-style-span&quot; style=&quot;font-family: &#39;Lucida Sans Unicode&#39;, &#39;Lucida Grande&#39;, &#39;Lucida Sans&#39;, Lucida, sans-serif; font-size: 15px;&quot;&gt;and see the loading order of classes first super class is loaded into JVM and then subclass is loaded. Super class is loaded into JVM using extends keyword.&lt;/span&gt;&lt;/div&gt;&lt;div style=&quot;text-align: justify;&quot;&gt;&lt;span class=&quot;Apple-style-span&quot; style=&quot;font-family: &#39;Lucida Sans Unicode&#39;, &#39;Lucida Grande&#39;, &#39;Lucida Sans&#39;, Lucida, sans-serif; font-size: 15px;&quot;&gt;2. Object creation is from super class to sub class&lt;/span&gt;&lt;/div&gt;&lt;div style=&quot;text-align: justify;&quot;&gt;&lt;span class=&quot;Apple-style-span&quot; style=&quot;font-family: &#39;Lucida Sans Unicode&#39;, &#39;Lucida Grande&#39;, &#39;Lucida Sans&#39;, Lucida, sans-serif; font-size: 15px;&quot;&gt;Non static&amp;nbsp;variables and non static blocks and constructor execution is from super class to sub class. Super class object is created by calling super class constructor from sub class constructor using super() keyword. Actually speaking object is not created for super class only memory is created.&lt;/span&gt;&lt;/div&gt;&lt;div style=&quot;text-align: justify;&quot;&gt;&lt;span class=&quot;Apple-style-span&quot; style=&quot;font-family: &#39;Lucida Sans Unicode&#39;, &#39;Lucida Grande&#39;, &#39;Lucida Sans&#39;, Lucida, sans-serif; font-size: 15px;&quot;&gt;3. Execution starts from sub class to super class&lt;/span&gt;&lt;/div&gt;&lt;div style=&quot;text-align: justify;&quot;&gt;&lt;span class=&quot;Apple-style-span&quot; style=&quot;font-family: &#39;Lucida Sans Unicode&#39;, &#39;Lucida Grande&#39;, &#39;Lucida Sans&#39;, Lucida, sans-serif; font-size: 15px;&quot;&gt;Invoked method is executed from sub class . If it is not defined in sub class, it is executed from super class&lt;/span&gt;&lt;br /&gt;
&lt;span class=&quot;Apple-style-span&quot; style=&quot;font-family: &#39;Lucida Sans Unicode&#39;, &#39;Lucida Grande&#39;, &#39;Lucida Sans&#39;, Lucida, sans-serif; font-size: 15px;&quot;&gt;&lt;br /&gt;
&lt;/span&gt;&lt;/div&gt;&lt;div style=&quot;text-align: justify;&quot;&gt;&lt;span class=&quot;Apple-style-span&quot; style=&quot;font-family: &#39;Lucida Sans Unicode&#39;, &#39;Lucida Grande&#39;, &#39;Lucida Sans&#39;, Lucida, sans-serif; font-size: 15px;&quot;&gt;//Below program explains above points&lt;/span&gt;&lt;br /&gt;
&lt;span class=&quot;Apple-style-span&quot; style=&quot;font-family: &#39;Lucida Sans Unicode&#39;, &#39;Lucida Grande&#39;, &#39;Lucida Sans&#39;, Lucida, sans-serif; font-size: 15px;&quot;&gt;&lt;br /&gt;
&lt;/span&gt;&lt;/div&gt;&lt;div style=&quot;text-align: justify;&quot;&gt;&lt;span class=&quot;Apple-style-span&quot; style=&quot;font-family: &#39;Lucida Sans Unicode&#39;, &#39;Lucida Grande&#39;, &#39;Lucida Sans&#39;, Lucida, sans-serif; font-size: 15px;&quot;&gt;&lt;b&gt;//Example.java&lt;/b&gt;&lt;/span&gt;&lt;/div&gt;&lt;span class=&quot;Apple-style-span&quot; style=&quot;font-size: 16px;&quot;&gt;&lt;pre class=&quot;brush:java;&quot;&gt;class Example 
{
   static int a = m1();

   //static block starts
   static
   {
      System.out.println(&quot;Example SB - Example is loaded&quot;);
   }
   //static block ends

   int x = m2();

   //non-static block starts
   {
      System.out.println(&quot;Example-NSB&quot;);
   }
   //non-static block ends

   Example(){
      System.out.println(&quot;Example class constructor-object is created&quot;);
   }
   static int m1(){
      System.out.println(&quot;Example static variable is created&quot;);
      return 10;
   }
   int m2(){
      System.out.println(&quot;Example non-static varible is executed&quot;);
      return 20;
   }
   void abc(){
      System.out.println(&quot;Example abc&quot;);
   }
   void bbc(){
      System.out.println(&quot;Example bbc&quot;);
   }
}
&lt;/pre&gt;&lt;/span&gt;&lt;br /&gt;
&lt;div style=&quot;text-align: justify;&quot;&gt;&lt;span class=&quot;Apple-style-span&quot; style=&quot;font-family: &#39;Lucida Sans Unicode&#39;, &#39;Lucida Grande&#39;, &#39;Lucida Sans&#39;, Lucida, sans-serif; font-size: 15px;&quot;&gt;&lt;b&gt;//Sample.java&lt;/b&gt;&lt;/span&gt;&lt;/div&gt;&lt;span class=&quot;Apple-style-span&quot; style=&quot;font-size: 16px;&quot;&gt;&lt;pre class=&quot;brush:java;&quot;&gt;class Sample extends Example 
{
   static int b = m3();

   //static block starts
   static
   {
      System.out.println(&quot;Sample SB - Sample is loaded&quot;);
   }
   //static block ends

   int x = m4();

   //non-static block starts
   {
      System.out.println(&quot;Sample-NSB&quot;);
   }
   //non-static block ends

   Sample(){
      System.out.println(&quot;Sample class constructor-object is created&quot;);
   }
   static int m3(){
      System.out.println(&quot;Sample static variable is created&quot;);
      return 30;
   }
   int m4(){
      System.out.println(&quot;Sample non-static varible is executed&quot;);
      return 40;
   }
   void abc(){
      System.out.println(&quot;Sample abc&quot;);
   }

   public static void main(String[] args) 
   {
      System.out.println(&quot;main method&quot;);
      Sample s = new Sample();
      s.abc();
      s.bbc();
   }
}
&lt;/pre&gt;&lt;/span&gt;&lt;br /&gt;
&lt;div style=&quot;text-align: justify; white-space: normal;&quot;&gt;&lt;span class=&quot;Apple-style-span&quot; style=&quot;font-family: &#39;Lucida Sans Unicode&#39;, &#39;Lucida Grande&#39;, &#39;Lucida Sans&#39;, Lucida, sans-serif; font-size: 15px;&quot;&gt;In the above program first static variables and static blocks of super class (Example) &amp;nbsp;are executed and then the static variables and static blocks of sub class (Sample) are executed. If all the static variables and blocks execution is completed then the main method is executed which is present in Sample class. After that object creation statement is executed control passes to Sample constructor and then passes to Example constructor due to the super() keyword that is placed by the compiler during compilation time.The super class of all classes is Object class so Object class statements are executed then Example class object is created means non-static variables and non-static blocks of Example class are executed then Example constructor statements are executed. So object creation of Example class is completed. Then&amp;nbsp;non-static variables and non-static blocks of Sample class are executed&amp;nbsp; and then Sample constructor statements are executed. Object creation of Sample class is completed. Finally invoked methods from sub class to super class are executed. This is the control flow of inheritance program.&lt;/span&gt;&lt;/div&gt;&lt;div&gt;&lt;br /&gt;
&lt;/div&gt;&lt;span class=&quot;Apple-style-span&quot; style=&quot;font-family: &#39;Lucida Sans Unicode&#39;, &#39;Lucida Grande&#39;, &#39;Lucida Sans&#39;, Lucida, sans-serif; font-size: 15px;&quot;&gt;The output for the above program is:&lt;/span&gt;&lt;br /&gt;
&lt;br /&gt;
&lt;span class=&quot;Apple-style-span&quot; style=&quot;font-family: &#39;Lucida Sans Unicode&#39;, &#39;Lucida Grande&#39;, &#39;Lucida Sans&#39;, Lucida, sans-serif; font-size: 15px;&quot;&gt;Example static variable is created&lt;/span&gt;&lt;br /&gt;
&lt;span class=&quot;Apple-style-span&quot; style=&quot;font-family: &#39;Lucida Sans Unicode&#39;, &#39;Lucida Grande&#39;, &#39;Lucida Sans&#39;, Lucida, sans-serif; font-size: 15px;&quot;&gt; Example SB - Example is loaded&lt;br /&gt;
Sample static variable is created&lt;br /&gt;
Sample SB - Sample is loaded&lt;br /&gt;
main method&lt;br /&gt;
Example non-static varible is executed&lt;br /&gt;
Example-NSB&lt;br /&gt;
Example class constructor-object is created&lt;br /&gt;
Sample non-static varible is executed&lt;br /&gt;
Sample-NSB&lt;br /&gt;
Sample class constructor-object is created&lt;br /&gt;
Sample abc&lt;br /&gt;
Example bbc&lt;/span&gt;&lt;/div&gt;</content><link rel='replies' type='application/atom+xml' href='http://java-intellectual.blogspot.com/feeds/4580314851714367213/comments/default' title='Post Comments'/><link rel='replies' type='text/html' href='http://java-intellectual.blogspot.com/2011/12/compiler-and-jvm-activities-of-java.html#comment-form' title='0 Comments'/><link rel='edit' type='application/atom+xml' href='http://www.blogger.com/feeds/3771177150982125782/posts/default/4580314851714367213'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/3771177150982125782/posts/default/4580314851714367213'/><link rel='alternate' type='text/html' href='http://java-intellectual.blogspot.com/2011/12/compiler-and-jvm-activities-of-java.html' title='Compiler and JVM activities of a java program with inheritance'/><author><name>siva</name><uri>http://www.blogger.com/profile/01922721189098931789</uri><email>noreply@blogger.com</email><gd:image rel='http://schemas.google.com/g/2005#thumbnail' width='16' height='16' src='https://img1.blogblog.com/img/b16-rounded.gif'/></author><thr:total>0</thr:total></entry><entry><id>tag:blogger.com,1999:blog-3771177150982125782.post-6995694853952984361</id><published>2011-12-06T01:54:00.000-08:00</published><updated>2011-12-08T03:23:39.155-08:00</updated><category scheme="http://www.blogger.com/atom/ns#" term="OOPS Concepts"/><title type='text'>How inheritance is implemented in java technically ?</title><content type='html'>&lt;div dir=&quot;ltr&quot; style=&quot;text-align: left;&quot; trbidi=&quot;on&quot;&gt;&lt;div style=&quot;text-align: justify;&quot;&gt;&lt;span class=&quot;Apple-style-span&quot; style=&quot;font-family: &#39;Lucida Sans Unicode&#39;, &#39;Lucida Grande&#39;, &#39;Lucida Sans&#39;, Lucida, sans-serif; font-size: 15px;&quot;&gt;As the name suggests inheritance means to take something that is already made.It is one of the most important features of Object Oriented Programming. It is the concept that is used for&amp;nbsp;reusability&amp;nbsp;purpose. Inheritance is the mechanism through which we can derive classes from another classes.&lt;/span&gt;&lt;/div&gt;&lt;div style=&quot;text-align: justify;&quot;&gt;&lt;span class=&quot;Apple-style-span&quot; style=&quot;font-family: &#39;Lucida Sans Unicode&#39;, &#39;Lucida Grande&#39;, &#39;Lucida Sans&#39;, Lucida, sans-serif; font-size: 15px;&quot;&gt;Inheritance is the process of reusing class members from another class as if they were defined int that class. Through inheritance we can obtain one object property to another object.&lt;/span&gt;&lt;/div&gt;&lt;div style=&quot;text-align: justify;&quot;&gt;&lt;span class=&quot;Apple-style-span&quot; style=&quot;font-family: &#39;Lucida Sans Unicode&#39;, &#39;Lucida Grande&#39;, &#39;Lucida Sans&#39;, Lucida, sans-serif; font-size: 15px;&quot;&gt;Basically by implementing inheritance we are&amp;nbsp;establishing a relation between two classes and then extending one class scope to another class.So that other class members can be accessed directly from this class by their names as if they were developed in this class.&lt;/span&gt;&lt;/div&gt;&lt;div style=&quot;text-align: justify;&quot;&gt;&lt;span class=&quot;Apple-style-span&quot; style=&quot;font-family: &#39;Lucida Sans Unicode&#39;, &#39;Lucida Grande&#39;, &#39;Lucida Sans&#39;, Lucida, sans-serif; font-size: 15px;&quot;&gt;&lt;/span&gt;&lt;br /&gt;
&lt;a name=&#39;more&#39;&gt;&lt;/a&gt;&lt;/div&gt;&lt;div style=&quot;text-align: justify;&quot;&gt;&lt;span class=&quot;Apple-style-span&quot; style=&quot;font-family: &#39;Lucida Sans Unicode&#39;, &#39;Lucida Grande&#39;, &#39;Lucida Sans&#39;, Lucida, sans-serif; font-size: 15px;&quot;&gt;Inheritance can be implemented in java using below two keywords:&lt;/span&gt;&lt;/div&gt;&lt;div style=&quot;text-align: justify;&quot;&gt;&lt;span class=&quot;Apple-style-span&quot; style=&quot;font-family: &#39;Lucida Sans Unicode&#39;, &#39;Lucida Grande&#39;, &#39;Lucida Sans&#39;, Lucida, sans-serif; font-size: 15px;&quot;&gt;1.extends&lt;/span&gt;&lt;/div&gt;&lt;div style=&quot;text-align: justify;&quot;&gt;&lt;span class=&quot;Apple-style-span&quot; style=&quot;font-family: &#39;Lucida Sans Unicode&#39;, &#39;Lucida Grande&#39;, &#39;Lucida Sans&#39;, Lucida, sans-serif; font-size: 15px;&quot;&gt;2.implements&lt;/span&gt;&lt;/div&gt;&lt;div style=&quot;text-align: justify;&quot;&gt;&lt;span class=&quot;Apple-style-span&quot; style=&quot;font-family: &#39;Lucida Sans Unicode&#39;, &#39;Lucida Grande&#39;, &#39;Lucida Sans&#39;, Lucida, sans-serif; font-size: 15px;&quot;&gt;&lt;br /&gt;
&lt;/span&gt;&lt;/div&gt;&lt;div style=&quot;text-align: justify;&quot;&gt;&lt;span class=&quot;Apple-style-span&quot; style=&quot;font-family: &#39;Lucida Sans Unicode&#39;, &#39;Lucida Grande&#39;, &#39;Lucida Sans&#39;, Lucida, sans-serif; font-size: 15px;&quot;&gt;Differences between extends and implements keywords&lt;/span&gt;&lt;/div&gt;&lt;div style=&quot;text-align: justify;&quot;&gt;&lt;span class=&quot;Apple-style-span&quot; style=&quot;font-family: &#39;Lucida Sans Unicode&#39;, &#39;Lucida Grande&#39;, &#39;Lucida Sans&#39;, Lucida, sans-serif; font-size: 15px;&quot;&gt;&lt;br /&gt;
&lt;/span&gt;&lt;/div&gt;&lt;div style=&quot;text-align: justify;&quot;&gt;&lt;span class=&quot;Apple-style-span&quot; style=&quot;font-family: &#39;Lucida Sans Unicode&#39;, &#39;Lucida Grande&#39;, &#39;Lucida Sans&#39;, Lucida, sans-serif; font-size: 15px;&quot;&gt;Although, Implements and Extends are two keywords that provide a mechanism to inherit attributes and behavior to a class in Java programming language, they are used for two different purposes. Implements keyword is used for a class to implement a certain interface, while Extends keyword is used for a subclass to extend from a super class. When a class implements an interface, that class needs to implement all the methods defined in the interface, but when a subclass extends a super class, it may or may not override the methods included in the parent class. Finally, another key difference between Implements and Extends is that, a class can implement multiple interfaces but it can only extend from one super class in Java. In general, usage of Implements (interfaces) is considered more favorable compared to the usage of Extends (inheritance), for several reasons like higher flexibility and the ability to minimize coupling. Therefore in practice, programming to an interface is preferred over extending from base classes.&lt;/span&gt;&lt;br /&gt;
&lt;span class=&quot;Apple-style-span&quot; style=&quot;font-family: &#39;Lucida Sans Unicode&#39;, &#39;Lucida Grande&#39;, &#39;Lucida Sans&#39;, Lucida, sans-serif; font-size: 15px;&quot;&gt;&lt;br /&gt;
&lt;/span&gt;&lt;/div&gt;&lt;div style=&quot;text-align: justify;&quot;&gt;&lt;span class=&quot;Apple-style-span&quot; style=&quot;font-family: &#39;Lucida Sans Unicode&#39;, &#39;Lucida Grande&#39;, &#39;Lucida Sans&#39;, Lucida, sans-serif; font-size: 15px;&quot;&gt;&lt;b&gt;Syntax:&lt;/b&gt;&lt;/span&gt;&lt;br /&gt;
&lt;span class=&quot;Apple-style-span&quot; style=&quot;font-family: &#39;Lucida Sans Unicode&#39;, &#39;Lucida Grande&#39;, &#39;Lucida Sans&#39;, Lucida, sans-serif; font-size: 15px;&quot;&gt;&lt;br /&gt;
&lt;/span&gt;&lt;/div&gt;&lt;div style=&quot;text-align: justify;&quot;&gt;&lt;span class=&quot;Apple-style-span&quot; style=&quot;font-family: &#39;Lucida Sans Unicode&#39;, &#39;Lucida Grande&#39;, &#39;Lucida Sans&#39;, Lucida, sans-serif; font-size: 15px;&quot;&gt;class Example { }&lt;/span&gt;&lt;/div&gt;&lt;div style=&quot;text-align: justify;&quot;&gt;&lt;span class=&quot;Apple-style-span&quot; style=&quot;font-family: &#39;Lucida Sans Unicode&#39;, &#39;Lucida Grande&#39;, &#39;Lucida Sans&#39;, Lucida, sans-serif; font-size: 15px;&quot;&gt;class Sample extends Example { }&lt;/span&gt;&lt;br /&gt;
&lt;span class=&quot;Apple-style-span&quot; style=&quot;font-family: &#39;Lucida Sans Unicode&#39;, &#39;Lucida Grande&#39;, &#39;Lucida Sans&#39;, Lucida, sans-serif; font-size: 15px;&quot;&gt;&lt;br /&gt;
&lt;/span&gt;&lt;/div&gt;&lt;div style=&quot;text-align: justify;&quot;&gt;&lt;span class=&quot;Apple-style-span&quot; style=&quot;font-family: &#39;Lucida Sans Unicode&#39;, &#39;Lucida Grande&#39;, &#39;Lucida Sans&#39;, Lucida, sans-serif; font-size: 15px;&quot;&gt;The class followed by extends keyword is called super class, here Example is super class, and the class that follows extends keyword is called subclass, here Sample is sub class.&lt;/span&gt;&lt;/div&gt;&lt;div style=&quot;text-align: justify;&quot;&gt;&lt;span class=&quot;Apple-style-span&quot; style=&quot;font-family: &#39;Lucida Sans Unicode&#39;, &#39;Lucida Grande&#39;, &#39;Lucida Sans&#39;, Lucida, sans-serif; font-size: 15px;&quot;&gt;Super class is also called as Parent / Base class&lt;/span&gt;&lt;/div&gt;&lt;div style=&quot;text-align: justify;&quot;&gt;&lt;span class=&quot;Apple-style-span&quot; style=&quot;font-family: &#39;Lucida Sans Unicode&#39;, &#39;Lucida Grande&#39;, &#39;Lucida Sans&#39;, Lucida, sans-serif; font-size: 15px;&quot;&gt;Sub class is also called as Child / Derived class&lt;/span&gt;&lt;br /&gt;
&lt;span class=&quot;Apple-style-span&quot; style=&quot;font-family: &#39;Lucida Sans Unicode&#39;, &#39;Lucida Grande&#39;, &#39;Lucida Sans&#39;, Lucida, sans-serif; font-size: 15px;&quot;&gt;&lt;br /&gt;
&lt;/span&gt;&lt;/div&gt;&lt;div style=&quot;text-align: justify;&quot;&gt;&lt;span class=&quot;Apple-style-span&quot; style=&quot;font-family: &#39;Lucida Sans Unicode&#39;, &#39;Lucida Grande&#39;, &#39;Lucida Sans&#39;, Lucida, sans-serif; font-size: 15px;&quot;&gt;//The below program explains implementing inheritance&lt;/span&gt;&lt;br /&gt;
&lt;span class=&quot;Apple-style-span&quot; style=&quot;font-family: &#39;Lucida Sans Unicode&#39;, &#39;Lucida Grande&#39;, &#39;Lucida Sans&#39;, Lucida, sans-serif; font-size: 15px;&quot;&gt;&lt;br /&gt;
&lt;/span&gt;&lt;/div&gt;&lt;div style=&quot;text-align: justify;&quot;&gt;&lt;span class=&quot;Apple-style-span&quot; style=&quot;font-family: &#39;Lucida Sans Unicode&#39;, &#39;Lucida Grande&#39;, &#39;Lucida Sans&#39;, Lucida, sans-serif; font-size: 15px;&quot;&gt;&lt;b&gt;//Example.java&lt;/b&gt;&lt;/span&gt;&lt;/div&gt;&lt;span class=&quot;Apple-style-span&quot; style=&quot;font-size: 16px;&quot;&gt;&lt;pre class=&quot;brush:java;&quot;&gt;class Example 
{
   static int a=10;
   int x=20;
   static void m1()
   {
      System.out.println(&quot;Example m1&quot;);
   }
   void m2()
   {
      System.out.println(&quot;Example m2&quot;);
   }
}
&lt;/pre&gt;&lt;/span&gt;&lt;br /&gt;
&lt;div style=&quot;text-align: justify;&quot;&gt;&lt;span class=&quot;Apple-style-span&quot; style=&quot;font-family: &#39;Lucida Sans Unicode&#39;, &#39;Lucida Grande&#39;, &#39;Lucida Sans&#39;, Lucida, sans-serif; font-size: 15px;&quot;&gt;&lt;b&gt;//Sample.java&lt;/b&gt;&lt;/span&gt;&lt;/div&gt;&lt;span class=&quot;Apple-style-span&quot; style=&quot;font-size: 16px;&quot;&gt;&lt;pre class=&quot;brush:java;&quot;&gt;class Sample extends Example
{
   public static void main(String[] args) 
   {
      System.out.println(a);
      m1();
      Sample s = new Sample();
      System.out.println(s.x);
      s.m2();
   }
}
&lt;/pre&gt;&lt;/span&gt;&lt;br /&gt;
&lt;div style=&quot;text-align: justify;&quot;&gt;&lt;span class=&quot;Apple-style-span&quot; style=&quot;font-family: &#39;Lucida Sans Unicode&#39;, &#39;Lucida Grande&#39;, &#39;Lucida Sans&#39;, Lucida, sans-serif; font-size: 15px;&quot;&gt;In the above program we accessed super class static members variable &#39;a&#39; and m1() directly by their names and&amp;nbsp;without creating super class object&amp;nbsp;we also accessed&amp;nbsp;non-static members variable &#39;x&#39; and method m2() with sub class object.&lt;/span&gt;&lt;/div&gt;&lt;/div&gt;</content><link rel='replies' type='application/atom+xml' href='http://java-intellectual.blogspot.com/feeds/6995694853952984361/comments/default' title='Post Comments'/><link rel='replies' type='text/html' href='http://java-intellectual.blogspot.com/2011/12/how-inheritance-is-implemented-in-java.html#comment-form' title='0 Comments'/><link rel='edit' type='application/atom+xml' href='http://www.blogger.com/feeds/3771177150982125782/posts/default/6995694853952984361'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/3771177150982125782/posts/default/6995694853952984361'/><link rel='alternate' type='text/html' href='http://java-intellectual.blogspot.com/2011/12/how-inheritance-is-implemented-in-java.html' title='How inheritance is implemented in java technically ?'/><author><name>siva</name><uri>http://www.blogger.com/profile/01922721189098931789</uri><email>noreply@blogger.com</email><gd:image rel='http://schemas.google.com/g/2005#thumbnail' width='16' height='16' src='https://img1.blogblog.com/img/b16-rounded.gif'/></author><thr:total>0</thr:total></entry><entry><id>tag:blogger.com,1999:blog-3771177150982125782.post-912637300102742649</id><published>2011-12-05T23:09:00.000-08:00</published><updated>2011-12-08T03:55:13.878-08:00</updated><category scheme="http://www.blogger.com/atom/ns#" term="OOPS Concepts"/><title type='text'>What will be the problem if we do not follow encapsulation in designing a class ?</title><content type='html'>&lt;div dir=&quot;ltr&quot; style=&quot;text-align: left;&quot; trbidi=&quot;on&quot;&gt;&lt;div style=&quot;text-align: justify;&quot;&gt;&lt;span class=&quot;Apple-style-span&quot; style=&quot;font-family: &#39;Lucida Sans Unicode&#39;, &#39;Lucida Grande&#39;, &#39;Lucida Sans&#39;, Lucida, sans-serif; font-size: 15px;&quot;&gt;If we do not follow encapsulation in designing a class, future changes will affect user programs. User programs must recompile and retest them completely.&lt;/span&gt;&lt;/div&gt;&lt;div style=&quot;text-align: justify;&quot;&gt;&lt;span class=&quot;Apple-style-span&quot; style=&quot;font-family: &#39;Lucida Sans Unicode&#39;, &#39;Lucida Grande&#39;, &#39;Lucida Sans&#39;, Lucida, sans-serif; font-size: 15px;&quot;&gt;&lt;br /&gt;
&lt;/span&gt;&lt;/div&gt;&lt;div style=&quot;text-align: justify;&quot;&gt;&lt;span class=&quot;Apple-style-span&quot; style=&quot;font-family: &#39;Lucida Sans Unicode&#39;, &#39;Lucida Grande&#39;, &#39;Lucida Sans&#39;, Lucida, sans-serif; font-size: 15px;&quot;&gt;Consider an example &quot;In class we have variable that should be filled with a value by that class user&quot; as shown in the below program.&lt;/span&gt;&lt;/div&gt;&lt;div&gt;&lt;div style=&quot;text-align: justify;&quot;&gt;&lt;span class=&quot;Apple-style-span&quot; style=&quot;font-family: &#39;Lucida Sans Unicode&#39;, &#39;Lucida Grande&#39;, &#39;Lucida Sans&#39;, Lucida, sans-serif; font-size: 15px;&quot;&gt;&lt;/span&gt;&lt;br /&gt;
&lt;a name=&#39;more&#39;&gt;&lt;/a&gt;&lt;/div&gt;&lt;div style=&quot;text-align: justify;&quot;&gt;&lt;span class=&quot;Apple-style-span&quot; style=&quot;font-family: &#39;Lucida Sans Unicode&#39;, &#39;Lucida Grande&#39;, &#39;Lucida Sans&#39;, Lucida, sans-serif; font-size: 15px;&quot;&gt;&lt;b&gt;//Example.java&lt;/b&gt;&lt;/span&gt;&lt;/div&gt;&lt;span class=&quot;Apple-style-span&quot; style=&quot;font-size: 16px;&quot;&gt;&lt;/span&gt;&lt;br /&gt;
&lt;span class=&quot;Apple-style-span&quot; style=&quot;font-size: 16px;&quot;&gt;&lt;pre class=&quot;brush:java;&quot;&gt;class Example
{
   int x;
}
&lt;/pre&gt;&lt;/span&gt;&lt;br /&gt;
&lt;div style=&quot;text-align: justify;&quot;&gt;&lt;span class=&quot;Apple-style-span&quot; style=&quot;font-family: &#39;Lucida Sans Unicode&#39;, &#39;Lucida Grande&#39;, &#39;Lucida Sans&#39;, Lucida, sans-serif; font-size: 15px;&quot;&gt;&lt;b&gt;//Sample.java&lt;/b&gt;&lt;/span&gt;&lt;/div&gt;&lt;span class=&quot;Apple-style-span&quot; style=&quot;font-size: 16px;&quot;&gt;&lt;/span&gt;&lt;br /&gt;
&lt;span class=&quot;Apple-style-span&quot; style=&quot;font-size: 16px;&quot;&gt;&lt;pre class=&quot;brush:java;&quot;&gt;class Sample
{
   public static void main(String[] args)
   {
      Example e = new Example();
      e.x=50;
      System.out.println(e.x);
      e.x=-10;
      System.out.println(e.x);
   }
}
&lt;/pre&gt;&lt;/span&gt;&lt;br /&gt;
&lt;span class=&quot;Apple-style-span&quot; style=&quot;font-size: 15px;&quot;&gt;&lt;br /&gt;
&lt;/span&gt;&lt;br /&gt;
&lt;div style=&quot;text-align: justify;&quot;&gt;&lt;span class=&quot;Apple-style-span&quot; style=&quot;font-family: &#39;Lucida Sans Unicode&#39;, &#39;Lucida Grande&#39;, &#39;Lucida Sans&#39;, Lucida, sans-serif; font-size: 15px;&quot;&gt;Assume in initial project requirement document customer did not mention that the application should not allow negative numbers to store.So we gave direct access to the variable and user can store any value as shown above.&lt;/span&gt;&lt;/div&gt;&lt;/div&gt;&lt;div&gt;&lt;div style=&quot;text-align: justify;&quot;&gt;&lt;span class=&quot;Apple-style-span&quot; style=&quot;font-family: &#39;Lucida Sans Unicode&#39;, &#39;Lucida Grande&#39;, &#39;Lucida Sans&#39;, Lucida, sans-serif; font-size: 15px;&quot;&gt;Assume in future,customer wants application not allows negative numbers.Then we should validate user given value before storing it in the variable.Hence application architecture should as like below.&lt;/span&gt;&lt;/div&gt;&lt;/div&gt;&lt;div&gt;&lt;div style=&quot;text-align: justify;&quot;&gt;&lt;span class=&quot;Apple-style-span&quot; style=&quot;font-family: &#39;Lucida Sans Unicode&#39;, &#39;Lucida Grande&#39;, &#39;Lucida Sans&#39;, Lucida, sans-serif; font-size: 15px;&quot;&gt;Declare variable as private, to stop direct access, and define setter method to take value from user. Then user invokes this method to initialize variable.In this method we can validate the passed value before storing it in the variable.If it is &amp;lt;0 we can terminate assignment and informs the same to user, else we will store that data in variable.&lt;/span&gt;&lt;/div&gt;&lt;/div&gt;&lt;div&gt;&lt;div style=&quot;text-align: justify;&quot;&gt;&lt;span class=&quot;Apple-style-span&quot; style=&quot;font-family: &#39;Lucida Sans Unicode&#39;, &#39;Lucida Grande&#39;, &#39;Lucida Sans&#39;, Lucida, sans-serif; font-size: 15px;&quot;&gt;Below program shows correct implementation of class by following encapsulation principle with required above validation logic.&lt;/span&gt;&lt;/div&gt;&lt;/div&gt;&lt;div&gt;&lt;div style=&quot;text-align: justify;&quot;&gt;&lt;span class=&quot;Apple-style-span&quot; style=&quot;font-family: &#39;Lucida Sans Unicode&#39;, &#39;Lucida Grande&#39;, &#39;Lucida Sans&#39;, Lucida, sans-serif; font-size: 15px;&quot;&gt;&lt;br /&gt;
&lt;/span&gt;&lt;/div&gt;&lt;div style=&quot;text-align: justify;&quot;&gt;&lt;span class=&quot;Apple-style-span&quot; style=&quot;font-family: &#39;Lucida Sans Unicode&#39;, &#39;Lucida Grande&#39;, &#39;Lucida Sans&#39;, Lucida, sans-serif; font-size: 15px;&quot;&gt;&lt;br /&gt;
&lt;/span&gt;&lt;/div&gt;&lt;div style=&quot;text-align: justify;&quot;&gt;&lt;span class=&quot;Apple-style-span&quot; style=&quot;font-family: &#39;Lucida Sans Unicode&#39;, &#39;Lucida Grande&#39;, &#39;Lucida Sans&#39;, Lucida, sans-serif; font-size: 15px;&quot;&gt;&lt;b&gt;//Example.java&lt;/b&gt;&lt;/span&gt;&lt;/div&gt;&lt;span class=&quot;Apple-style-span&quot; style=&quot;font-size: 16px;&quot;&gt;&lt;/span&gt;&lt;br /&gt;
&lt;span class=&quot;Apple-style-span&quot; style=&quot;font-size: 16px;&quot;&gt;&lt;pre class=&quot;brush:java;&quot;&gt;class Example 
{
   private int x;
   public void setA(int x)
   {
      if(x&amp;gt;0)
      {
         this.x=x;
      }
      else
      {
         System.out.println(&quot;do no pass negative number&quot;);
      }
   }
   public  int getA()
   {
      return x;
   }
}
&lt;/pre&gt;&lt;/span&gt;&lt;br /&gt;
&lt;span class=&quot;Apple-style-span&quot; style=&quot;font-family: &#39;Lucida Sans Unicode&#39;, &#39;Lucida Grande&#39;, &#39;Lucida Sans&#39;, Lucida, sans-serif; font-size: 15px;&quot;&gt;&lt;b&gt;//Sample.java&lt;/b&gt;&lt;/span&gt;&lt;br /&gt;
&lt;span class=&quot;Apple-style-span&quot; style=&quot;font-size: 16px;&quot;&gt;&lt;/span&gt;&lt;br /&gt;
&lt;span class=&quot;Apple-style-span&quot; style=&quot;font-size: 16px;&quot;&gt;&lt;pre class=&quot;brush:java;&quot;&gt;class Sample 
{
   public static void main(String[] args) 
   {
      Example e = new Example();
      //e.x=50; CE:x has private access in Example
      //System.out.println(e.x); CE:x has private access in Example
      e.setA(50);
      System.out.println(e.getA());
      e.setA(-6);
      System.out.println(e.getA());
   }
}
&lt;/pre&gt;&lt;/span&gt;&lt;br /&gt;
&lt;div&gt;&lt;div style=&quot;text-align: justify;&quot;&gt;&lt;span class=&quot;Apple-style-span&quot; style=&quot;font-family: &#39;Lucida Sans Unicode&#39;, &#39;Lucida Grande&#39;, &#39;Lucida Sans&#39;, Lucida, sans-serif; font-size: 15px;&quot;&gt;Since we have changed the code after application is used by several programmers, every one now should rebuild their application to access variable through setter and getter methods. Otherwise their previous .class file code execution is failed with exception &lt;span class=&quot;Apple-style-span&quot; style=&quot;color: #cc0000;&quot;&gt;java.lang.IllegalAccessError&lt;/span&gt;&lt;span class=&quot;Apple-style-span&quot; style=&quot;color: #0c343d;&quot;&gt;.&lt;/span&gt;&lt;/span&gt;&lt;/div&gt;&lt;/div&gt;&lt;div&gt;&lt;div style=&quot;text-align: justify;&quot;&gt;&lt;span class=&quot;Apple-style-span&quot; style=&quot;font-family: &#39;Lucida Sans Unicode&#39;, &#39;Lucida Grande&#39;, &#39;Lucida Sans&#39;, Lucida, sans-serif; font-size: 15px;&quot;&gt;It means since we are not followed encapsulation in developing class it leads lot of&amp;nbsp;maintenance&amp;nbsp;cost.Hence to avoid all these future problems we should always develop classes by following encapsulation principle, even though we do not have any validations before setting and getting variable, it is all required for future sake.&lt;/span&gt;&lt;/div&gt;&lt;/div&gt;&lt;div&gt;&lt;div style=&quot;text-align: justify;&quot;&gt;&lt;span class=&quot;Apple-style-span&quot; style=&quot;font-family: &#39;Lucida Sans Unicode&#39;, &#39;Lucida Grande&#39;, &#39;Lucida Sans&#39;, Lucida, sans-serif; font-size: 15px;&quot;&gt;In the above program the variable x we cannot access from Sample class because it is declared as private.&lt;/span&gt;&lt;/div&gt;&lt;/div&gt;&lt;div&gt;&lt;div style=&quot;text-align: justify;&quot;&gt;&lt;span class=&quot;Apple-style-span&quot; style=&quot;font-family: &#39;Lucida Sans Unicode&#39;, &#39;Lucida Grande&#39;, &#39;Lucida Sans&#39;, Lucida, sans-serif; font-size: 15px;&quot;&gt;The advantage in designing classes by following encapsulation principle is in future user programs are no need to be recompiled due to code change in setter and getter methods. Ultimately through encapsulation we are hiding implementation details from user.&lt;/span&gt;&lt;/div&gt;&lt;/div&gt;&lt;div&gt;&lt;div style=&quot;text-align: justify;&quot;&gt;&lt;span class=&quot;Apple-style-span&quot; style=&quot;font-family: &#39;Lucida Sans Unicode&#39;, &#39;Lucida Grande&#39;, &#39;Lucida Sans&#39;, Lucida, sans-serif; font-size: 15px;&quot;&gt;Consider another example to understand need of encapsulation better, for example bike has 5 gears a method to change gears could reject any value that is less than 1 or greater than 5. If we provide direct access to variable we cannot reject storing a value &amp;lt;1 or &amp;gt;5&lt;/span&gt;&lt;/div&gt;&lt;/div&gt;&lt;/div&gt;&lt;/div&gt;</content><link rel='replies' type='application/atom+xml' href='http://java-intellectual.blogspot.com/feeds/912637300102742649/comments/default' title='Post Comments'/><link rel='replies' type='text/html' href='http://java-intellectual.blogspot.com/2011/12/what-will-be-problem-if-we-do-not.html#comment-form' title='0 Comments'/><link rel='edit' type='application/atom+xml' href='http://www.blogger.com/feeds/3771177150982125782/posts/default/912637300102742649'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/3771177150982125782/posts/default/912637300102742649'/><link rel='alternate' type='text/html' href='http://java-intellectual.blogspot.com/2011/12/what-will-be-problem-if-we-do-not.html' title='What will be the problem if we do not follow encapsulation in designing a class ?'/><author><name>siva</name><uri>http://www.blogger.com/profile/01922721189098931789</uri><email>noreply@blogger.com</email><gd:image rel='http://schemas.google.com/g/2005#thumbnail' width='16' height='16' src='https://img1.blogblog.com/img/b16-rounded.gif'/></author><thr:total>0</thr:total></entry><entry><id>tag:blogger.com,1999:blog-3771177150982125782.post-1666371761424593388</id><published>2011-11-27T02:58:00.000-08:00</published><updated>2011-12-09T01:16:53.979-08:00</updated><category scheme="http://www.blogger.com/atom/ns#" term="OOPS Concepts"/><title type='text'>How can we develop Encapsulation technically in Java ?</title><content type='html'>&lt;div dir=&quot;ltr&quot; style=&quot;text-align: left;&quot; trbidi=&quot;on&quot;&gt;&lt;div style=&quot;text-align: justify;&quot;&gt;&lt;span class=&quot;Apple-style-span&quot; style=&quot;font-family: &#39;Lucida Sans Unicode&#39;, &#39;Lucida Grande&#39;, &#39;Lucida Sans&#39;, Lucida, sans-serif; font-size: 15px;&quot;&gt;Ok, first review encapsulation definition again &quot; Hiding class data from the outside world and accessing it only through publicly exposed methods&quot;.&lt;/span&gt;&lt;/div&gt;&lt;div style=&quot;text-align: justify;&quot;&gt;&lt;span class=&quot;Apple-style-span&quot; style=&quot;font-family: &#39;Lucida Sans Unicode&#39;, &#39;Lucida Grande&#39;, &#39;Lucida Sans&#39;, Lucida, sans-serif; font-size: 15px;&quot;&gt;It means restricting direct access of class variables to outside class members and providing accessibility to those variables through public methods is called encapsulation.&lt;/span&gt;&lt;/div&gt;&lt;div style=&quot;text-align: justify;&quot;&gt;&lt;span class=&quot;Apple-style-span&quot; style=&quot;font-family: &#39;Lucida Sans Unicode&#39;, &#39;Lucida Grande&#39;, &#39;Lucida Sans&#39;, Lucida, sans-serif; font-size: 15px;&quot;&gt;In Java encapsulation can be implemented&lt;/span&gt;&lt;br /&gt;
&lt;span class=&quot;Apple-style-span&quot; style=&quot;font-family: &#39;Lucida Sans Unicode&#39;, &#39;Lucida Grande&#39;, &#39;Lucida Sans&#39;, Lucida, sans-serif; font-size: 15px;&quot;&gt;&lt;br /&gt;
&lt;/span&gt;&lt;/div&gt;&lt;div style=&quot;text-align: justify;&quot;&gt;&lt;span class=&quot;Apple-style-span&quot; style=&quot;font-family: &#39;Lucida Sans Unicode&#39;, &#39;Lucida Grande&#39;, &#39;Lucida Sans&#39;, Lucida, sans-serif; font-size: 15px;&quot;&gt;By declaring variables as private, to restrict direct access and&lt;/span&gt;&lt;/div&gt;&lt;div style=&quot;text-align: justify;&quot;&gt;&lt;span class=&quot;Apple-style-span&quot; style=&quot;font-family: &#39;Lucida Sans Unicode&#39;, &#39;Lucida Grande&#39;, &#39;Lucida Sans&#39;, Lucida, sans-serif; font-size: 15px;&quot;&gt;By defining one pair of public setter and getter methods to give access to private variables&lt;/span&gt;&lt;br /&gt;
&lt;span class=&quot;Apple-style-span&quot; style=&quot;font-family: &#39;Lucida Sans Unicode&#39;, &#39;Lucida Grande&#39;, &#39;Lucida Sans&#39;, Lucida, sans-serif; font-size: 15px;&quot;&gt;&lt;br /&gt;
&lt;/span&gt;&lt;/div&gt;&lt;div style=&quot;text-align: justify;&quot;&gt;&lt;span class=&quot;Apple-style-span&quot; style=&quot;font-family: &#39;Lucida Sans Unicode&#39;, &#39;Lucida Grande&#39;, &#39;Lucida Sans&#39;, Lucida, sans-serif; font-size: 15px;&quot;&gt;The &lt;b style=&quot;font-style: italic;&quot;&gt;Rule &lt;/b&gt;on private access specifier members (variables and methods) is, they cannot be accessed from outside world of this class directly. Voilation leads to compile time error.&lt;/span&gt;&lt;/div&gt;&lt;div style=&quot;text-align: justify;&quot;&gt;&lt;span class=&quot;Apple-style-span&quot; style=&quot;font-family: &#39;Lucida Sans Unicode&#39;, &#39;Lucida Grande&#39;, &#39;Lucida Sans&#39;, Lucida, sans-serif; font-size: 15px;&quot;&gt;&lt;/span&gt;&lt;br /&gt;
&lt;a name=&#39;more&#39;&gt;&lt;/a&gt;&lt;/div&gt;&lt;div style=&quot;text-align: justify;&quot;&gt;&lt;span class=&quot;Apple-style-span&quot; style=&quot;font-family: &#39;Lucida Sans Unicode&#39;, &#39;Lucida Grande&#39;, &#39;Lucida Sans&#39;, Lucida, sans-serif; font-size: 15px;&quot;&gt;The below program explains developing a class by following encapsulation principle&lt;/span&gt;&lt;/div&gt;&lt;div style=&quot;text-align: justify;&quot;&gt;&lt;span class=&quot;Apple-style-span&quot; style=&quot;font-family: &#39;Lucida Sans Unicode&#39;, &#39;Lucida Grande&#39;, &#39;Lucida Sans&#39;, Lucida, sans-serif; font-size: 15px;&quot;&gt;&lt;br /&gt;
&lt;/span&gt;&lt;/div&gt;&lt;div style=&quot;text-align: justify;&quot;&gt;&lt;span class=&quot;Apple-style-span&quot; style=&quot;font-family: &#39;Lucida Sans Unicode&#39;, &#39;Lucida Grande&#39;, &#39;Lucida Sans&#39;, Lucida, sans-serif; font-size: 15px;&quot;&gt;&lt;b&gt;// Bank.java&lt;/b&gt;&lt;/span&gt;&lt;/div&gt;&lt;span class=&quot;Apple-style-span&quot; style=&quot;font-size: 16px;&quot;&gt;&lt;pre class=&quot;brush:java;&quot;&gt;public class Bank
{
 //hiding class data
 private static final double MIN_BALANCE=5000;

 private long accno;
 private String username;
 private String password;
 private double balance;
 
 public Bank(long accno,String username,String password,double balance)
 {
  this.accno = accno;
  this.username = username;
  this.password = password;
  this.balance = balance;
 }
 //giving access to outside of the class members

 public void setAccno(long accno)
 {
  this.accno = accno;
 }
  
 public long getAccno()
 {
  return accno;
 }
 
 public void setUsername(String username)
 {
  this.username = username; 
 }

 public String getUsername()
 {
  return username;
 }
 
 public void setPassword(String password)
 {
  this.password = password;
 }
 
 public String getPassword()
 { 
  return password;
 }
 
 public void setBalance(double balance)
 {
  this.balance = this.balance + balance;
 }

 public double getBalance()
 {
  //add validation logic,if needed
  return balance;
 }
}&lt;/span&gt;&lt;/pre&gt;&lt;div style=&quot;text-align: justify;&quot;&gt;&lt;span class=&quot;Apple-style-span&quot; style=&quot;font-family: &#39;Lucida Sans Unicode&#39;, &#39;Lucida Grande&#39;, &#39;Lucida Sans&#39;, Lucida, sans-serif; font-size: 15px;&quot;&gt;&lt;b&gt;//Encapsulation.java&lt;/b&gt;&lt;/span&gt;&lt;/div&gt;&lt;span class=&quot;Apple-style-span&quot; style=&quot;font-size: 16px;&quot;&gt;&lt;pre class=&quot;brush:java;&quot;&gt;class Encapsulation
{
 public static void main(String[] args)
 {
  Bank iciciBank = new Bank(1,&quot;siva&quot;,&quot;chaitanya&quot;,999999999);

  //accessing private variables directly from this class is not possible it leads to CE
  //System.out.println(iciciBank.balance);
  //System.out.println(iciciBank.username);
  //System.out.println(iciciBank.password);
  

  //access them through getXxx() methods 
  System.out.println(iciciBank.getUsername());
  System.out.println(iciciBank.getPassword());
  System.out.println(iciciBank.getBalance());

  //setting the variables with different values using setXxx() method
  iciciBank.setBalance(1000);
  
  iciciBank.setUsername(&quot;Pond James Pond&quot;);
  iciciBank.setPassword(&quot;siva chaitanya&quot;);
  
  System.out.println(iciciBank.getUsername());
  System.out.println(iciciBank.getPassword());
  System.out.println(iciciBank.getBalance());
 }
}&lt;/span&gt;
&lt;/pre&gt;&lt;div style=&quot;text-align: justify;&quot;&gt;&lt;span class=&quot;Apple-tab-span&quot; style=&quot;font-family: &#39;Lucida Sans Unicode&#39;, &#39;Lucida Grande&#39;, &#39;Lucida Sans&#39;, Lucida, sans-serif; font-size: 15px; white-space: pre;&quot;&gt; &lt;/span&gt;&lt;/div&gt;&lt;div style=&quot;text-align: justify;&quot;&gt;&lt;span class=&quot;Apple-style-span&quot; style=&quot;font-family: &#39;Lucida Sans Unicode&#39;, &#39;Lucida Grande&#39;, &#39;Lucida Sans&#39;, Lucida, sans-serif; font-size: 15px;&quot;&gt;The advantage in providing variable access via setter and getter methods is we can authenticate user with proper authentication logic before setting or returning variable value. In the above program before giving balance details, in getBalance() method we can authenticate user. It is not possible if we provide direct access to balance variable.Here in the above example we have to execute Encapsulation program because it contains main method.&lt;/span&gt;&lt;/div&gt;&lt;/div&gt;</content><link rel='replies' type='application/atom+xml' href='http://java-intellectual.blogspot.com/feeds/1666371761424593388/comments/default' title='Post Comments'/><link rel='replies' type='text/html' href='http://java-intellectual.blogspot.com/2011/11/how-we-can-develop-encapsulation-in.html#comment-form' title='0 Comments'/><link rel='edit' type='application/atom+xml' href='http://www.blogger.com/feeds/3771177150982125782/posts/default/1666371761424593388'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/3771177150982125782/posts/default/1666371761424593388'/><link rel='alternate' type='text/html' href='http://java-intellectual.blogspot.com/2011/11/how-we-can-develop-encapsulation-in.html' title='How can we develop Encapsulation technically in Java ?'/><author><name>siva</name><uri>http://www.blogger.com/profile/01922721189098931789</uri><email>noreply@blogger.com</email><gd:image rel='http://schemas.google.com/g/2005#thumbnail' width='16' height='16' src='https://img1.blogblog.com/img/b16-rounded.gif'/></author><thr:total>0</thr:total></entry><entry><id>tag:blogger.com,1999:blog-3771177150982125782.post-7867776738502247611</id><published>2011-11-25T03:47:00.000-08:00</published><updated>2011-12-09T01:12:44.809-08:00</updated><category scheme="http://www.blogger.com/atom/ns#" term="OOPS Concepts"/><title type='text'>What are OOPS Principles ?</title><content type='html'>&lt;div dir=&quot;ltr&quot; style=&quot;text-align: left;&quot; trbidi=&quot;on&quot;&gt;&lt;div style=&quot;text-align: justify;&quot;&gt;&lt;span class=&quot;Apple-style-span&quot; style=&quot;font-family: &#39;Lucida Sans Unicode&#39;, &#39;Lucida Grande&#39;, &#39;Lucida Sans&#39;, Lucida, sans-serif; font-size: 15px;&quot;&gt;OOPS principles are design patters those suggest how we should develop program to organize and reuse effectively with high scalability.The programming language that supports below principles is called as object oriented programming language.&lt;/span&gt;&lt;/div&gt;&lt;div style=&quot;text-align: justify;&quot;&gt;&lt;span class=&quot;Apple-style-span&quot; style=&quot;font-family: &#39;Lucida Sans Unicode&#39;, &#39;Lucida Grande&#39;, &#39;Lucida Sans&#39;, Lucida, sans-serif; font-size: 15px;&quot;&gt;&lt;br /&gt;
&lt;/span&gt;&lt;/div&gt;&lt;div style=&quot;text-align: justify;&quot;&gt;&lt;span class=&quot;Apple-style-span&quot; style=&quot;font-family: &#39;Lucida Sans Unicode&#39;, &#39;Lucida Grande&#39;, &#39;Lucida Sans&#39;, Lucida, sans-serif; font-size: 15px;&quot;&gt;1) Encapsulation&lt;/span&gt;&lt;/div&gt;&lt;div style=&quot;text-align: justify;&quot;&gt;&lt;span class=&quot;Apple-style-span&quot; style=&quot;font-family: &#39;Lucida Sans Unicode&#39;, &#39;Lucida Grande&#39;, &#39;Lucida Sans&#39;, Lucida, sans-serif; font-size: 15px;&quot;&gt;2) Inheritance&lt;/span&gt;&lt;/div&gt;&lt;div style=&quot;text-align: justify;&quot;&gt;&lt;span class=&quot;Apple-style-span&quot; style=&quot;font-family: &#39;Lucida Sans Unicode&#39;, &#39;Lucida Grande&#39;, &#39;Lucida Sans&#39;, Lucida, sans-serif; font-size: 15px;&quot;&gt;3) Polymorphism&lt;/span&gt;&lt;/div&gt;&lt;div style=&quot;text-align: justify;&quot;&gt;&lt;span class=&quot;Apple-style-span&quot; style=&quot;font-family: &#39;Lucida Sans Unicode&#39;, &#39;Lucida Grande&#39;, &#39;Lucida Sans&#39;, Lucida, sans-serif; font-size: 15px;&quot;&gt;&lt;br /&gt;
&lt;/span&gt;&lt;/div&gt;&lt;div style=&quot;text-align: justify;&quot;&gt;&lt;span class=&quot;Apple-style-span&quot; style=&quot;font-family: &#39;Lucida Sans Unicode&#39;, &#39;Lucida Grande&#39;, &#39;Lucida Sans&#39;, Lucida, sans-serif; font-size: 15px;&quot;&gt;Java supports &lt;u&gt;Abstraction &lt;/u&gt;which is the backbone of all the above three oops principles. It is the supporting principle of OOPS that ensures all three principles working together to give final shape of the project.&lt;/span&gt;&lt;/div&gt;&lt;div style=&quot;text-align: justify;&quot;&gt;&lt;span class=&quot;Apple-style-span&quot; style=&quot;font-family: &#39;Lucida Sans Unicode&#39;, &#39;Lucida Grande&#39;, &#39;Lucida Sans&#39;, Lucida, sans-serif; font-size: 15px;&quot;&gt;&lt;/span&gt;&lt;br /&gt;
&lt;a name=&#39;more&#39;&gt;&lt;/a&gt;&lt;/div&gt;&lt;div style=&quot;text-align: justify;&quot;&gt;&lt;b&gt;&lt;span class=&quot;Apple-style-span&quot; style=&quot;font-family: &#39;Lucida Sans Unicode&#39;, &#39;Lucida Grande&#39;, &#39;Lucida Sans&#39;, Lucida, sans-serif; font-size: 15px;&quot;&gt;Encapsulation:&lt;/span&gt;&lt;/b&gt;&lt;/div&gt;&lt;div style=&quot;text-align: justify;&quot;&gt;&lt;b&gt;&lt;span class=&quot;Apple-style-span&quot; style=&quot;font-family: &#39;Lucida Sans Unicode&#39;, &#39;Lucida Grande&#39;, &#39;Lucida Sans&#39;, Lucida, sans-serif; font-size: 15px;&quot;&gt;&lt;br /&gt;
&lt;/span&gt;&lt;/b&gt;&lt;/div&gt;&lt;div style=&quot;text-align: justify;&quot;&gt;&lt;span class=&quot;Apple-style-span&quot; style=&quot;font-family: &#39;Lucida Sans Unicode&#39;, &#39;Lucida Grande&#39;, &#39;Lucida Sans&#39;, Lucida, sans-serif; font-size: 15px;&quot;&gt;The process of hiding internal data from the outside world and accessing it only through publicly exposed methods is known as data encapsulation.Let us take an example&lt;/span&gt;&lt;/div&gt;&lt;div class=&quot;separator&quot; style=&quot;clear: both; text-align: center;&quot;&gt;&lt;a href=&quot;https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEiSj5ZiftHWs01IuifcTcyrgmjqel3Fj236uQDTSaaNMcqxPzKjy18Z4pJTDLtOTffwv70bffA-5uT88-cnZDks3-kXkyWUgXC0gD4qgtcHIkR8nj7nBWk0pQWy9GewgH532m-cURSPIrQ/s1600/Untitled.jpg&quot; imageanchor=&quot;1&quot; style=&quot;margin-left: 1em; margin-right: 1em;&quot;&gt;&lt;span class=&quot;Apple-style-span&quot; style=&quot;font-family: Georgia, &#39;Times New Roman&#39;, serif; font-size: 15px;&quot;&gt;&lt;img border=&quot;0&quot; height=&quot;640&quot; src=&quot;https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEiSj5ZiftHWs01IuifcTcyrgmjqel3Fj236uQDTSaaNMcqxPzKjy18Z4pJTDLtOTffwv70bffA-5uT88-cnZDks3-kXkyWUgXC0gD4qgtcHIkR8nj7nBWk0pQWy9GewgH532m-cURSPIrQ/s640/Untitled.jpg&quot; width=&quot;393&quot; /&gt;&lt;/span&gt;&lt;/a&gt;&lt;/div&gt;&lt;div class=&quot;separator&quot; style=&quot;clear: both; text-align: justify;&quot;&gt;&lt;span class=&quot;Apple-style-span&quot; style=&quot;font-family: &#39;Lucida Sans Unicode&#39;, &#39;Lucida Grande&#39;, &#39;Lucida Sans&#39;, Lucida, sans-serif; font-size: 15px;&quot;&gt;&lt;br /&gt;
&lt;/span&gt;&lt;/div&gt;&lt;div style=&quot;text-align: justify;&quot;&gt;&lt;span class=&quot;Apple-style-span&quot; style=&quot;font-family: &#39;Lucida Sans Unicode&#39;, &#39;Lucida Grande&#39;, &#39;Lucida Sans&#39;, Lucida, sans-serif; font-size: 15px;&quot;&gt;In the above diagram father earns 1 crore per annum&amp;nbsp;and deposited that money in bank in mothers account to protect it and withdrawing it later with proper authentication.This is called encapsulation.&lt;/span&gt;&lt;/div&gt;&lt;div style=&quot;text-align: justify;&quot;&gt;&lt;span class=&quot;Apple-style-span&quot; style=&quot;font-family: &#39;Lucida Sans Unicode&#39;, &#39;Lucida Grande&#39;, &#39;Lucida Sans&#39;, Lucida, sans-serif; font-size: 15px;&quot;&gt;&lt;br /&gt;
&lt;/span&gt;&lt;/div&gt;&lt;div style=&quot;text-align: justify;&quot;&gt;&lt;b&gt;&lt;span class=&quot;Apple-style-span&quot; style=&quot;font-family: &#39;Lucida Sans Unicode&#39;, &#39;Lucida Grande&#39;, &#39;Lucida Sans&#39;, Lucida, sans-serif; font-size: 15px;&quot;&gt;Inheritance:&lt;/span&gt;&lt;/b&gt;&lt;/div&gt;&lt;div style=&quot;text-align: justify;&quot;&gt;&lt;b&gt;&lt;span class=&quot;Apple-style-span&quot; style=&quot;font-family: &#39;Lucida Sans Unicode&#39;, &#39;Lucida Grande&#39;, &#39;Lucida Sans&#39;, Lucida, sans-serif; font-size: 15px;&quot;&gt;&lt;br /&gt;
&lt;/span&gt;&lt;/b&gt;&lt;/div&gt;&lt;div style=&quot;text-align: justify;&quot;&gt;&lt;span class=&quot;Apple-style-span&quot; style=&quot;font-family: &#39;Lucida Sans Unicode&#39;, &#39;Lucida Grande&#39;, &#39;Lucida Sans&#39;, Lucida, sans-serif; font-size: 15px;&quot;&gt;The process of reusing class members from another class as if it were defined in that class is called inheritance. It can also be defined as it is a process of obtaining one object property to other object is called inheritance&lt;/span&gt;&lt;/div&gt;&lt;div class=&quot;separator&quot; style=&quot;clear: both; text-align: center;&quot;&gt;&lt;a href=&quot;https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEi3q1JfmcQ_BsFm5JkE7w0Uz20lSyBJuRFDolbukVVZdlZoOX3JI9svXGtHvqHeiRMuAsZAow61VNyIYdbjUM8k2J0Lukpr4y43-sO64IekFlaA9QPfH1RIXXWhq2_Igv5uYd5_ecqkdwk/s1600/Untitled.jpg&quot; imageanchor=&quot;1&quot; style=&quot;margin-left: 1em; margin-right: 1em;&quot;&gt;&lt;span class=&quot;Apple-style-span&quot; style=&quot;font-family: Georgia, &#39;Times New Roman&#39;, serif; font-size: 15px;&quot;&gt;&lt;img border=&quot;0&quot; height=&quot;640&quot; src=&quot;https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEi3q1JfmcQ_BsFm5JkE7w0Uz20lSyBJuRFDolbukVVZdlZoOX3JI9svXGtHvqHeiRMuAsZAow61VNyIYdbjUM8k2J0Lukpr4y43-sO64IekFlaA9QPfH1RIXXWhq2_Igv5uYd5_ecqkdwk/s640/Untitled.jpg&quot; width=&quot;502&quot; /&gt;&lt;/span&gt;&lt;/a&gt;&lt;/div&gt;&lt;div style=&quot;text-align: justify;&quot;&gt;&lt;span class=&quot;Apple-style-span&quot; style=&quot;font-family: &#39;Lucida Sans Unicode&#39;, &#39;Lucida Grande&#39;, &#39;Lucida Sans&#39;, Lucida, sans-serif; font-size: 15px;&quot;&gt;In the above diagram father is earning 1 crore per annum and one of the child reusing father&#39;s money in his/her own business to get more money or just spending it for enjoyment just like child 2 in the above diagram.This is called inheritance.&lt;/span&gt;&lt;/div&gt;&lt;div style=&quot;text-align: justify;&quot;&gt;&lt;span class=&quot;Apple-style-span&quot; style=&quot;font-family: &#39;Lucida Sans Unicode&#39;, &#39;Lucida Grande&#39;, &#39;Lucida Sans&#39;, Lucida, sans-serif; font-size: 15px;&quot;&gt;&lt;br /&gt;
&lt;/span&gt;&lt;/div&gt;&lt;div style=&quot;text-align: justify;&quot;&gt;&lt;b&gt;&lt;span class=&quot;Apple-style-span&quot; style=&quot;font-family: &#39;Lucida Sans Unicode&#39;, &#39;Lucida Grande&#39;, &#39;Lucida Sans&#39;, Lucida, sans-serif; font-size: 15px;&quot;&gt;Polymorphism:&lt;/span&gt;&lt;/b&gt;&lt;/div&gt;&lt;div style=&quot;text-align: justify;&quot;&gt;&lt;b&gt;&lt;span class=&quot;Apple-style-span&quot; style=&quot;font-family: &#39;Lucida Sans Unicode&#39;, &#39;Lucida Grande&#39;, &#39;Lucida Sans&#39;, Lucida, sans-serif; font-size: 15px;&quot;&gt;&lt;br /&gt;
&lt;/span&gt;&lt;/b&gt;&lt;/div&gt;&lt;div style=&quot;text-align: justify;&quot;&gt;&lt;span class=&quot;Apple-style-span&quot; style=&quot;font-family: &#39;Lucida Sans Unicode&#39;, &#39;Lucida Grande&#39;, &#39;Lucida Sans&#39;, Lucida, sans-serif; font-size: 15px;&quot;&gt;Having multiple forms of a method with same name is called polymorphism.&lt;/span&gt;&lt;/div&gt;&lt;div class=&quot;separator&quot; style=&quot;clear: both; text-align: justify;&quot;&gt;&lt;span class=&quot;Apple-style-span&quot; style=&quot;font-family: &#39;Lucida Sans Unicode&#39;, &#39;Lucida Grande&#39;, &#39;Lucida Sans&#39;, Lucida, sans-serif; font-size: 15px;&quot;&gt;&lt;br /&gt;
&lt;/span&gt;&lt;/div&gt;&lt;div class=&quot;separator&quot; style=&quot;clear: both; text-align: center;&quot;&gt;&lt;a href=&quot;https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEgSftaWvPUH5fxIwgEFrky-jFmp8OpZpx7s3V9oW4sHrH5u2TVNDg-s2g7OjG3ma1Ngnz7sufsHHOjmXUfmpXiG4N5Pg_UHuIdwL6ozfb41kxs4BbcqrnZmd8GmlCxxu1GJGaem6KCtELc/s1600/Untitled.png&quot; imageanchor=&quot;1&quot; style=&quot;margin-left: 1em; margin-right: 1em;&quot;&gt;&lt;span class=&quot;Apple-style-span&quot; style=&quot;font-family: &#39;Lucida Sans Unicode&#39;, &#39;Lucida Grande&#39;, &#39;Lucida Sans&#39;, Lucida, sans-serif; font-size: 15px;&quot;&gt;&lt;img border=&quot;0&quot; height=&quot;160&quot; src=&quot;https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEgSftaWvPUH5fxIwgEFrky-jFmp8OpZpx7s3V9oW4sHrH5u2TVNDg-s2g7OjG3ma1Ngnz7sufsHHOjmXUfmpXiG4N5Pg_UHuIdwL6ozfb41kxs4BbcqrnZmd8GmlCxxu1GJGaem6KCtELc/s200/Untitled.png&quot; width=&quot;200&quot; /&gt;&lt;/span&gt;&lt;/a&gt;&lt;/div&gt;&lt;div style=&quot;text-align: justify;&quot;&gt;&lt;span class=&quot;Apple-style-span&quot; style=&quot;font-family: &#39;Lucida Sans Unicode&#39;, &#39;Lucida Grande&#39;, &#39;Lucida Sans&#39;, Lucida, sans-serif; font-size: 15px;&quot;&gt;In the world so many persons&amp;nbsp;will have&amp;nbsp;the same name &#39;arnold&#39; .This is called polymorphism.&lt;/span&gt;&lt;br /&gt;
&lt;span class=&quot;Apple-style-span&quot; style=&quot;font-family: &#39;Lucida Sans Unicode&#39;, &#39;Lucida Grande&#39;, &#39;Lucida Sans&#39;, Lucida, sans-serif; font-size: 15px;&quot;&gt;&lt;br /&gt;
&lt;/span&gt;&lt;/div&gt;&lt;div style=&quot;text-align: justify;&quot;&gt;&lt;b&gt;&lt;span class=&quot;Apple-style-span&quot; style=&quot;font-family: &#39;Lucida Sans Unicode&#39;, &#39;Lucida Grande&#39;, &#39;Lucida Sans&#39;, Lucida, sans-serif; font-size: 15px;&quot;&gt;Abstraction:&lt;/span&gt;&lt;/b&gt;&lt;/div&gt;&lt;div style=&quot;text-align: justify;&quot;&gt;&lt;b&gt;&lt;span class=&quot;Apple-style-span&quot; style=&quot;font-family: &#39;Lucida Sans Unicode&#39;, &#39;Lucida Grande&#39;, &#39;Lucida Sans&#39;, Lucida, sans-serif; font-size: 15px;&quot;&gt;&lt;br /&gt;
&lt;/span&gt;&lt;/b&gt;&lt;/div&gt;&lt;div style=&quot;text-align: justify;&quot;&gt;&lt;span class=&quot;Apple-style-span&quot; style=&quot;font-family: &#39;Lucida Sans Unicode&#39;, &#39;Lucida Grande&#39;, &#39;Lucida Sans&#39;, Lucida, sans-serif; font-size: 15px;&quot;&gt;The process of removing or hiding unnecessary information is called abstraction.The process of providing necessary method prototype by removing/hiding unnecessary method logic is called as abstraction. Let us take an example&lt;/span&gt;&lt;/div&gt;&lt;div class=&quot;separator&quot; style=&quot;clear: both; text-align: center;&quot;&gt;&lt;a href=&quot;https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEhtQq1bRLzIPW12GNBLRHgG_wDQTk4WPyUiF-TkTDYmD-jwRin_NoFxQnUolocAfPTBETPcc673SbBmRKqOqF23b3HfI-r-Z03KzhGcXv5Dqx8NfGNtjehpM64DWnoujEsBo5odH6TuK9U/s1600/Untitled.png&quot; imageanchor=&quot;1&quot; style=&quot;margin-left: 1em; margin-right: 1em;&quot;&gt;&lt;span class=&quot;Apple-style-span&quot; style=&quot;font-family: &#39;Lucida Sans Unicode&#39;, &#39;Lucida Grande&#39;, &#39;Lucida Sans&#39;, Lucida, sans-serif; font-size: 15px;&quot;&gt;&lt;img border=&quot;0&quot; height=&quot;640&quot; src=&quot;https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEhtQq1bRLzIPW12GNBLRHgG_wDQTk4WPyUiF-TkTDYmD-jwRin_NoFxQnUolocAfPTBETPcc673SbBmRKqOqF23b3HfI-r-Z03KzhGcXv5Dqx8NfGNtjehpM64DWnoujEsBo5odH6TuK9U/s640/Untitled.png&quot; width=&quot;544&quot; /&gt;&lt;/span&gt;&lt;/a&gt;&lt;/div&gt;&lt;div style=&quot;text-align: justify;&quot;&gt;&lt;span class=&quot;Apple-style-span&quot; style=&quot;font-family: &#39;Lucida Sans Unicode&#39;, &#39;Lucida Grande&#39;, &#39;Lucida Sans&#39;, Lucida, sans-serif; font-size: 15px;&quot;&gt;In the above diagram if we enter into books stall and if we ask shopkeeper for java books then he shows only &amp;nbsp; &amp;nbsp; java books hiding the unnecessary information and from that 100 books if we select 50 books that we like then another unnecessary 50 books he hides.Finally we select one book and remaining 49 books he hides.This is called abstraction&lt;/span&gt;&lt;br /&gt;
&lt;span class=&quot;Apple-style-span&quot; style=&quot;font-family: &#39;Lucida Sans Unicode&#39;, &#39;Lucida Grande&#39;, &#39;Lucida Sans&#39;, Lucida, sans-serif; font-size: 15px;&quot;&gt;&lt;br /&gt;
&lt;/span&gt;&lt;br /&gt;
&lt;span class=&quot;Apple-style-span&quot; style=&quot;font-family: &#39;Lucida Sans Unicode&#39;, &#39;Lucida Grande&#39;, &#39;Lucida Sans&#39;, Lucida, sans-serif; font-size: 15px;&quot;&gt;Comment for any doubts.......&lt;/span&gt;&lt;br /&gt;
&lt;span class=&quot;Apple-style-span&quot; style=&quot;font-family: &#39;Lucida Sans Unicode&#39;, &#39;Lucida Grande&#39;, &#39;Lucida Sans&#39;, Lucida, sans-serif; font-size: 15px;&quot;&gt;&lt;br /&gt;
&lt;/span&gt;&lt;/div&gt;&lt;/div&gt;</content><link rel='replies' type='application/atom+xml' href='http://java-intellectual.blogspot.com/feeds/7867776738502247611/comments/default' title='Post Comments'/><link rel='replies' type='text/html' href='http://java-intellectual.blogspot.com/2011/11/what-are-oops-principles.html#comment-form' title='0 Comments'/><link rel='edit' type='application/atom+xml' href='http://www.blogger.com/feeds/3771177150982125782/posts/default/7867776738502247611'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/3771177150982125782/posts/default/7867776738502247611'/><link rel='alternate' type='text/html' href='http://java-intellectual.blogspot.com/2011/11/what-are-oops-principles.html' title='What are OOPS Principles ?'/><author><name>siva</name><uri>http://www.blogger.com/profile/01922721189098931789</uri><email>noreply@blogger.com</email><gd:image rel='http://schemas.google.com/g/2005#thumbnail' width='16' height='16' src='https://img1.blogblog.com/img/b16-rounded.gif'/></author><media:thumbnail xmlns:media="http://search.yahoo.com/mrss/" url="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEiSj5ZiftHWs01IuifcTcyrgmjqel3Fj236uQDTSaaNMcqxPzKjy18Z4pJTDLtOTffwv70bffA-5uT88-cnZDks3-kXkyWUgXC0gD4qgtcHIkR8nj7nBWk0pQWy9GewgH532m-cURSPIrQ/s72-c/Untitled.jpg" height="72" width="72"/><thr:total>0</thr:total></entry><entry><id>tag:blogger.com,1999:blog-3771177150982125782.post-9158440385659598842</id><published>2011-11-24T01:04:00.000-08:00</published><updated>2011-12-09T01:21:52.356-08:00</updated><category scheme="http://www.blogger.com/atom/ns#" term="OOPS Concepts"/><title type='text'>Designing a class to create real world objects of type Person</title><content type='html'>&lt;div dir=&quot;ltr&quot; style=&quot;text-align: left;&quot; trbidi=&quot;on&quot;&gt;&lt;div style=&quot;text-align: justify;&quot;&gt;&lt;span class=&quot;Apple-style-span&quot; style=&quot;font-family: &#39;Lucida Sans Unicode&#39;, &#39;Lucida Grande&#39;, &#39;Lucida Sans&#39;, Lucida, sans-serif; font-size: 15px;&quot;&gt;Identity is the hashcode of an object,it is a 32 bit integer number created randomly and assigned to an object by default by JVM.&amp;nbsp;&lt;/span&gt;&lt;span class=&quot;Apple-style-span&quot; style=&quot;font-family: &#39;Lucida Sans Unicode&#39;, &#39;Lucida Grande&#39;, &#39;Lucida Sans&#39;, Lucida, sans-serif; font-size: 15px;&quot;&gt;Each object will have a unique identity.&lt;/span&gt;&lt;/div&gt;&lt;div style=&quot;text-align: justify;&quot;&gt;&lt;span class=&quot;Apple-style-span&quot; style=&quot;font-family: &#39;Lucida Sans Unicode&#39;, &#39;Lucida Grande&#39;, &#39;Lucida Sans&#39;, Lucida, sans-serif; font-size: 15px;&quot;&gt;Developer can also generate hashcode of an object based on state of that object by overriding hashcode() method pf java.lang.objectclass. Then if state is changed automatically hashcode will be changed.&lt;/span&gt;&lt;/div&gt;&lt;div style=&quot;text-align: justify;&quot;&gt;&lt;span class=&quot;Apple-style-span&quot; style=&quot;font-family: &#39;Lucida Sans Unicode&#39;, &#39;Lucida Grande&#39;, &#39;Lucida Sans&#39;, Lucida, sans-serif; font-size: 15px;&quot;&gt;JVM generated hashcode will not be changed if object state is changed because it is not generated based on object state.Hashcode is used when object is stored in hashtable.Hashcode is used when object is stored in hashtable&lt;/span&gt;&lt;/div&gt;&lt;div style=&quot;text-align: justify;&quot;&gt;&lt;span class=&quot;Apple-style-span&quot; style=&quot;font-family: &#39;Lucida Sans Unicode&#39;, &#39;Lucida Grande&#39;, &#39;Lucida Sans&#39;, Lucida, sans-serif; font-size: 15px;&quot;&gt;To understand all above points, consider real world object person as an example.&lt;/span&gt;&lt;br /&gt;
&lt;span class=&quot;Apple-style-span&quot; style=&quot;font-family: &#39;Lucida Sans Unicode&#39;, &#39;Lucida Grande&#39;, &#39;Lucida Sans&#39;, Lucida, sans-serif; font-size: 15px;&quot;&gt;&lt;/span&gt;&lt;br /&gt;
&lt;a name=&#39;more&#39;&gt;&lt;/a&gt;&lt;/div&gt;&lt;div style=&quot;text-align: justify;&quot;&gt;&lt;span class=&quot;Apple-style-span&quot; style=&quot;font-family: &#39;Lucida Sans Unicode&#39;, &#39;Lucida Grande&#39;, &#39;Lucida Sans&#39;, Lucida, sans-serif; font-size: 15px;&quot;&gt;Every person will have&amp;nbsp;&lt;/span&gt;&lt;br /&gt;
&lt;span class=&quot;Apple-style-span&quot; style=&quot;font-family: &#39;Lucida Sans Unicode&#39;, &#39;Lucida Grande&#39;, &#39;Lucida Sans&#39;, Lucida, sans-serif; font-size: 15px;&quot;&gt;state - eyes, ears, hands, legs, name, height, weight, foodhabits&lt;/span&gt;&lt;/div&gt;&lt;div style=&quot;text-align: justify;&quot;&gt;&lt;span class=&quot;Apple-style-span&quot; style=&quot;font-family: &#39;Lucida Sans Unicode&#39;, &#39;Lucida Grande&#39;, &#39;Lucida Sans&#39;, Lucida, sans-serif; font-size: 15px;&quot;&gt;Behavior - getName(), setName(), sleep(), eat().&lt;/span&gt;&lt;/div&gt;&lt;div style=&quot;text-align: justify;&quot;&gt;&lt;span class=&quot;Apple-style-span&quot; style=&quot;font-family: &#39;Lucida Sans Unicode&#39;, &#39;Lucida Grande&#39;, &#39;Lucida Sans&#39;, Lucida, sans-serif; font-size: 15px;&quot;&gt;&lt;br /&gt;
&lt;/span&gt;&lt;/div&gt;&lt;div style=&quot;text-align: justify;&quot;&gt;&lt;span class=&quot;Apple-style-span&quot; style=&quot;font-family: &#39;Lucida Sans Unicode&#39;, &#39;Lucida Grande&#39;, &#39;Lucida Sans&#39;, Lucida, sans-serif; font-size: 15px;&quot;&gt;we should consider below things to design a class(blueprint) to create objects of type person&lt;/span&gt;&lt;/div&gt;&lt;div style=&quot;text-align: justify;&quot;&gt;&lt;span class=&quot;Apple-style-span&quot; style=&quot;font-family: &#39;Lucida Sans Unicode&#39;, &#39;Lucida Grande&#39;, &#39;Lucida Sans&#39;, Lucida, sans-serif; font-size: 15px;&quot;&gt;What are the common attributes and individual attributes ?&lt;/span&gt;&lt;/div&gt;&lt;div style=&quot;text-align: justify;&quot;&gt;&lt;span class=&quot;Apple-style-span&quot; style=&quot;font-family: &#39;Lucida Sans Unicode&#39;, &#39;Lucida Grande&#39;, &#39;Lucida Sans&#39;, Lucida, sans-serif; font-size: 15px;&quot;&gt;What are the common behaviors, and individual behaviors ?&lt;/span&gt;&lt;/div&gt;&lt;div style=&quot;text-align: justify;&quot;&gt;&lt;span class=&quot;Apple-style-span&quot; style=&quot;font-family: &#39;Lucida Sans Unicode&#39;, &#39;Lucida Grande&#39;, &#39;Lucida Sans&#39;, Lucida, sans-serif; font-size: 15px;&quot;&gt;&lt;br /&gt;
&lt;/span&gt;&lt;/div&gt;&lt;div style=&quot;text-align: justify;&quot;&gt;&lt;span class=&quot;Apple-style-span&quot; style=&quot;font-family: &#39;Lucida Sans Unicode&#39;, &#39;Lucida Grande&#39;, &#39;Lucida Sans&#39;, Lucida, sans-serif; font-size: 15px;&quot;&gt;Every person has 2 eyes, 2 ears, 2 legs, 2 hands, so create these variables as&lt;u&gt; static final variables&lt;/u&gt; to store values common for all person objects,it will save memory. Every person has his/her own name, height, weight, foodHabits so create these variables as &lt;u&gt;non-static variables&lt;/u&gt; to store value individual to every object.&lt;/span&gt;&lt;/div&gt;&lt;div style=&quot;text-align: justify;&quot;&gt;&lt;span class=&quot;Apple-style-span&quot; style=&quot;font-family: &#39;Lucida Sans Unicode&#39;, &#39;Lucida Grande&#39;, &#39;Lucida Sans&#39;, Lucida, sans-serif; font-size: 15px;&quot;&gt;Create behaviors getName(), setName() methods as non-static methods to change name specific to Person object. Also eat() method should be a non-static method as it uses object data,non-static variable foodHabits. Create sleep() method as static method to execute logic common for all objects.&lt;/span&gt;&lt;br /&gt;
&lt;span class=&quot;Apple-style-span&quot; style=&quot;font-family: &#39;Lucida Sans Unicode&#39;, &#39;Lucida Grande&#39;, &#39;Lucida Sans&#39;, Lucida, sans-serif; font-size: 15px;&quot;&gt;&lt;br /&gt;
&lt;/span&gt;&lt;/div&gt;&lt;div style=&quot;text-align: justify;&quot;&gt;&lt;span class=&quot;Apple-style-span&quot; style=&quot;font-family: &#39;Lucida Sans Unicode&#39;, &#39;Lucida Grande&#39;, &#39;Lucida Sans&#39;, Lucida, sans-serif; font-size: 15px;&quot;&gt;Check below program&lt;/span&gt;&lt;br /&gt;
&lt;span class=&quot;Apple-style-span&quot; style=&quot;font-family: &#39;Lucida Sans Unicode&#39;, &#39;Lucida Grande&#39;, &#39;Lucida Sans&#39;, Lucida, sans-serif; font-size: 15px;&quot;&gt;&lt;br /&gt;
&lt;/span&gt;&lt;/div&gt;&lt;div style=&quot;text-align: justify;&quot;&gt;&lt;b&gt;&lt;span class=&quot;Apple-style-span&quot; style=&quot;font-family: &#39;Lucida Sans Unicode&#39;, &#39;Lucida Grande&#39;, &#39;Lucida Sans&#39;, Lucida, sans-serif; font-size: 15px;&quot;&gt;//Person.java&lt;/span&gt;&lt;/b&gt;&lt;br /&gt;
&lt;b&gt;&lt;span class=&quot;Apple-style-span&quot; style=&quot;font-family: &#39;Lucida Sans Unicode&#39;, &#39;Lucida Grande&#39;, &#39;Lucida Sans&#39;, Lucida, sans-serif; font-size: 15px;&quot;&gt;&lt;br /&gt;
&lt;/span&gt;&lt;/b&gt;&lt;/div&gt;&lt;div style=&quot;text-align: justify;&quot;&gt;&lt;/div&gt;&lt;span class=&quot;Apple-style-span&quot; style=&quot;font-size: 16px;&quot;&gt;&lt;pre class=&quot;brush:java;&quot;&gt;class Person
{
//static variables having values common for all&amp;nbsp;objects
static final int eyes=2;

static final int ears=2;

static final int hands=2;

static final int legs=2;

//non-static variable having values individual to&amp;nbsp;every object

String name;

double height;

double weight;

String foodHabits;

//parameterized constructor to initialize object state&amp;nbsp;with&amp;nbsp;user given values

Person(String name,double height,double weight,String&amp;nbsp;foodHabits)
{
     this.name &amp;nbsp; &amp;nbsp; &amp;nbsp; = name;

     this.height &amp;nbsp; &amp;nbsp; = height;

     this.weight &amp;nbsp; &amp;nbsp; = weight;

     this.foodHabits = foodHabits;
}

//parameterized non-static methods to change object&amp;nbsp;state&amp;nbsp;with user given values

void setName(String name)
{
     this.name = name;
}

void setheight(double height)
{
     this.height = height;
}

void setWeight(double weight)
{
     this.weight = weight;
}

void setfoodhabits(String foodHabits)
{
     this.foodHabits = foodHabits;
}

void printNHW()
{
     System.out.println(&quot;name: &quot;+name);

     System.out.println(&quot;height: &quot;+height);

     System.out.println(&quot;weight: &quot;+weight);

     System.out.println(&quot;foodHabits: &quot;+foodHabits);

}

}&lt;/span&gt;
&lt;/pre&gt;&lt;div&gt;&lt;b&gt;&lt;span class=&quot;Apple-style-span&quot; style=&quot;font-family: &#39;Lucida Sans Unicode&#39;, &#39;Lucida Grande&#39;, &#39;Lucida Sans&#39;, Lucida, sans-serif; font-size: 15px;&quot;&gt;//PersonUser.java&lt;/span&gt;&lt;/b&gt;&lt;/div&gt;&lt;span class=&quot;Apple-style-span&quot; style=&quot;font-size: 16px;&quot;&gt;&lt;pre class=&quot;brush:java;&quot;&gt;class PersonUser

{

public static void main(String[] args)

{

Person p1=new Person(&quot;venkatesh&quot;,6.0,80,&quot;veg&quot;);

Person p2=new Person(&quot;balakrishna&quot;,5.9,180,&quot;non-veg&quot;);

System.out.println(&quot;objects default state&quot;);

p1.printNHW();

p2.printNHW();

System.out.println(p1);

System.out.println(p2);

System.out.println(&quot;==================================&quot;);

p2.setName(&quot;balayya&quot;);

p2.setWeight(120);

System.out.println(p1);

System.out.println(p2);

System.out.println(&quot;objects changed state&quot;); 

p1.printNHW();

p2.printNHW();

}

}
&lt;/span&gt;&lt;/pre&gt;&lt;span class=&quot;Apple-style-span&quot; style=&quot;font-family: &#39;Lucida Sans Unicode&#39;, &#39;Lucida Grande&#39;, &#39;Lucida Sans&#39;, Lucida, sans-serif;&quot;&gt;&lt;span class=&quot;Apple-style-span&quot; style=&quot;font-size: 16px;&quot;&gt;&lt;b&gt;&lt;br /&gt;
&lt;/b&gt;&lt;/span&gt;&lt;/span&gt;&lt;br /&gt;
&lt;div class=&quot;separator&quot; style=&quot;clear: both; text-align: center;&quot;&gt;&lt;/div&gt;&lt;div class=&quot;separator&quot; style=&quot;clear: both; text-align: left;&quot;&gt;&lt;br /&gt;
&lt;/div&gt;&lt;/div&gt;</content><link rel='replies' type='application/atom+xml' href='http://java-intellectual.blogspot.com/feeds/9158440385659598842/comments/default' title='Post Comments'/><link rel='replies' type='text/html' href='http://java-intellectual.blogspot.com/2011/11/designing-class-to-create-real-world.html#comment-form' title='0 Comments'/><link rel='edit' type='application/atom+xml' href='http://www.blogger.com/feeds/3771177150982125782/posts/default/9158440385659598842'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/3771177150982125782/posts/default/9158440385659598842'/><link rel='alternate' type='text/html' href='http://java-intellectual.blogspot.com/2011/11/designing-class-to-create-real-world.html' title='Designing a class to create real world objects of type Person'/><author><name>siva</name><uri>http://www.blogger.com/profile/01922721189098931789</uri><email>noreply@blogger.com</email><gd:image rel='http://schemas.google.com/g/2005#thumbnail' width='16' height='16' src='https://img1.blogblog.com/img/b16-rounded.gif'/></author><thr:total>0</thr:total></entry><entry><id>tag:blogger.com,1999:blog-3771177150982125782.post-1128193748057917127</id><published>2011-11-23T19:42:00.000-08:00</published><updated>2011-12-09T01:23:34.744-08:00</updated><category scheme="http://www.blogger.com/atom/ns#" term="OOPS Concepts"/><title type='text'>What is a class and object in java ?</title><content type='html'>&lt;div dir=&quot;ltr&quot; style=&quot;text-align: left;&quot; trbidi=&quot;on&quot;&gt;&lt;div style=&quot;text-align: justify;&quot;&gt;&lt;span class=&quot;Apple-style-span&quot; style=&quot;font-family: &#39;Lucida Sans Unicode&#39;, &#39;Lucida Grande&#39;, &#39;Lucida Sans&#39;, Lucida, sans-serif; font-size: 15px;&quot;&gt;Java is an object oriented programming language. This means Java programs use objects and classes.So what is an object? An object is anything that really exists in the real world and can be distinguished from others. Every thing that we see physically will come into this definition , for&amp;nbsp;example&amp;nbsp;every human being, a book, a tree, and so on.&lt;/span&gt;&lt;/div&gt;&lt;div style=&quot;text-align: justify;&quot;&gt;&lt;span class=&quot;Apple-style-span&quot; style=&quot;font-family: &#39;Lucida Sans Unicode&#39;, &#39;Lucida Grande&#39;, &#39;Lucida Sans&#39;, Lucida, sans-serif; font-size: 15px;&quot;&gt;Now every object has properties and exhibits certain behaviour. Let us try to illustrate this point by taking an example of dog. It got properties like name,height,color,age etc. These properties are represented by variables. Now the object dog will have some actions like running,barking,eating etc. These actions are represented by various methods (functions) in our programming. In programming various tasks are done by methods only. So we can console that objects contain variables and methods.&lt;/span&gt;&lt;/div&gt;&lt;div class=&quot;separator&quot; style=&quot;clear: both; text-align: justify;&quot;&gt;&lt;span class=&quot;Apple-style-span&quot; style=&quot;font-family: &#39;Lucida Sans Unicode&#39;, &#39;Lucida Grande&#39;, &#39;Lucida Sans&#39;, Lucida, sans-serif; font-size: 15px;&quot;&gt;&lt;/span&gt;&lt;/div&gt;&lt;a name=&#39;more&#39;&gt;&lt;/a&gt;&lt;br /&gt;
&lt;div style=&quot;text-align: justify;&quot;&gt;&lt;span class=&quot;Apple-style-span&quot; style=&quot;font-family: &#39;Lucida Sans Unicode&#39;, &#39;Lucida Grande&#39;, &#39;Lucida Sans&#39;, Lucida, sans-serif; font-size: 15px;&quot;&gt;A group of objects exhibiting same behaviour (properties and actions) will come under&amp;nbsp;same group&amp;nbsp;called class. A class represents a group name given to several objects. For example take the dogs: Tom,Jimmy,Pinky,Subbu&amp;nbsp;etc . All these four exhibit same behaviour and hence belongs to the same group, called dog. So dog is a&amp;nbsp;class name&amp;nbsp;which contains four objects. In other words we can define a class as a specification or &lt;b&gt;blueprint &lt;/b&gt;or template of an object that defines what goes to make up a particular sort of object. A class can be used as a model for creation of objects.&lt;/span&gt;&lt;/div&gt;&lt;div style=&quot;text-align: left;&quot;&gt;&lt;a href=&quot;https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEiNbfCHAmfdFQ0Duqp3chUPEvSwO0p7e4QfTJTOo9XqNwTZ0tdkhOwjuwvabTD1RjnJouWEe4Cafo8EbAVrUpsnezkjEuuVQoNfZ4d6ij-5MTtFFxv5O5qKwDgOJZWDaQQL_OtTT0uZiVc/s1600/Untitled.png&quot; imageanchor=&quot;1&quot; style=&quot;margin-left: 1em; margin-right: 1em; text-align: center;&quot;&gt;&lt;span class=&quot;Apple-style-span&quot; style=&quot;font-family: &#39;Lucida Sans Unicode&#39;, &#39;Lucida Grande&#39;, &#39;Lucida Sans&#39;, Lucida, sans-serif; font-size: 15px;&quot;&gt;&lt;img border=&quot;0&quot; height=&quot;392&quot; src=&quot;https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEiNbfCHAmfdFQ0Duqp3chUPEvSwO0p7e4QfTJTOo9XqNwTZ0tdkhOwjuwvabTD1RjnJouWEe4Cafo8EbAVrUpsnezkjEuuVQoNfZ4d6ij-5MTtFFxv5O5qKwDgOJZWDaQQL_OtTT0uZiVc/s640/Untitled.png&quot; width=&quot;640&quot; /&gt;&lt;/span&gt;&lt;/a&gt;&lt;/div&gt;&lt;div style=&quot;text-align: justify;&quot;&gt;&lt;span class=&quot;Apple-style-span&quot; style=&quot;font-family: &#39;Lucida Sans Unicode&#39;, &#39;Lucida Grande&#39;, &#39;Lucida Sans&#39;, Lucida, sans-serif; font-size: 15px;&quot;&gt;A class and object are almost the same with the difference that a class does not exist physically, while the object does. For example if we say dog; it forms a picture into our mind with 4 legs, 2 ears some length and height. This picture in our mind is class. If we tally that picture with the physical things around us, we can find Tom living in our house is satisfying these qualities. So tom physically exists is an object and not a class. In technical terms we say object as &quot;&lt;b&gt;It is an encapsulated form of all non static variables and non static methods of a particular class&lt;/b&gt;.&quot;The process of creating objects of a class is called &lt;b&gt;instantiation&lt;/b&gt;.&lt;/span&gt;&lt;/div&gt;&lt;div style=&quot;text-align: justify;&quot;&gt;&lt;span class=&quot;Apple-style-span&quot; style=&quot;font-family: &#39;Lucida Sans Unicode&#39;, &#39;Lucida Grande&#39;, &#39;Lucida Sans&#39;, Lucida, sans-serif; font-size: 15px;&quot;&gt;&lt;br /&gt;
&lt;/span&gt;&lt;/div&gt;&lt;div style=&quot;text-align: justify;&quot;&gt;&lt;span class=&quot;Apple-style-span&quot; style=&quot;font-family: &#39;Lucida Sans Unicode&#39;, &#39;Lucida Grande&#39;, &#39;Lucida Sans&#39;, Lucida, sans-serif; font-size: 15px;&quot;&gt;Comment for any doubts.......&lt;/span&gt;&lt;/div&gt;&lt;/div&gt;</content><link rel='replies' type='application/atom+xml' href='http://java-intellectual.blogspot.com/feeds/1128193748057917127/comments/default' title='Post Comments'/><link rel='replies' type='text/html' href='http://java-intellectual.blogspot.com/2011/11/what-is-class-and-object-in-java.html#comment-form' title='0 Comments'/><link rel='edit' type='application/atom+xml' href='http://www.blogger.com/feeds/3771177150982125782/posts/default/1128193748057917127'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/3771177150982125782/posts/default/1128193748057917127'/><link rel='alternate' type='text/html' href='http://java-intellectual.blogspot.com/2011/11/what-is-class-and-object-in-java.html' title='What is a class and object in java ?'/><author><name>siva</name><uri>http://www.blogger.com/profile/01922721189098931789</uri><email>noreply@blogger.com</email><gd:image rel='http://schemas.google.com/g/2005#thumbnail' width='16' height='16' src='https://img1.blogblog.com/img/b16-rounded.gif'/></author><media:thumbnail xmlns:media="http://search.yahoo.com/mrss/" url="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEiNbfCHAmfdFQ0Duqp3chUPEvSwO0p7e4QfTJTOo9XqNwTZ0tdkhOwjuwvabTD1RjnJouWEe4Cafo8EbAVrUpsnezkjEuuVQoNfZ4d6ij-5MTtFFxv5O5qKwDgOJZWDaQQL_OtTT0uZiVc/s72-c/Untitled.png" height="72" width="72"/><thr:total>0</thr:total></entry><entry><id>tag:blogger.com,1999:blog-3771177150982125782.post-5781128184931786924</id><published>2011-11-23T18:27:00.000-08:00</published><updated>2011-12-09T01:24:47.092-08:00</updated><category scheme="http://www.blogger.com/atom/ns#" term="OOPS Concepts"/><title type='text'>What is Object Oriented  Programming Language ?</title><content type='html'>&lt;div dir=&quot;ltr&quot; style=&quot;text-align: left;&quot; trbidi=&quot;on&quot;&gt;&lt;div style=&quot;text-align: justify;&quot;&gt;&lt;span class=&quot;Apple-style-span&quot; style=&quot;font-family: &#39;Lucida Sans Unicode&#39;, &#39;Lucida Grande&#39;, &#39;Lucida Sans&#39;, Lucida, sans-serif; font-size: 15px;&quot;&gt;OOP is an approach that provides a way of modularizing a program by creating&amp;nbsp;partitioned&amp;nbsp;memory area for both data and methods that can be used as template for creating copies of such modules(objects) on demand.&lt;/span&gt;&lt;/div&gt;&lt;div style=&quot;text-align: justify;&quot;&gt;&lt;span class=&quot;Apple-style-span&quot; style=&quot;font-family: &#39;Lucida Sans Unicode&#39;, &#39;Lucida Grande&#39;, &#39;Lucida Sans&#39;, Lucida, sans-serif; font-size: 15px;&quot;&gt;So Object Oriented Programming or OOP is a technique to create programs based on the real world object. Unlike procedural programming, here in the OOP programming model, programs are organized around objects and data rather than actions and logic.&lt;/span&gt;&lt;/div&gt;&lt;br /&gt;
&lt;a name=&#39;more&#39;&gt;&lt;/a&gt;&lt;br /&gt;
&lt;div style=&quot;background-color: white; line-height: 19px; margin-bottom: 20px; text-align: justify;&quot;&gt;&lt;span class=&quot;Apple-style-span&quot; style=&quot;font-family: &#39;Lucida Sans Unicode&#39;, &#39;Lucida Grande&#39;, &#39;Lucida Sans&#39;, Lucida, sans-serif; font-size: 15px;&quot;&gt;The concepts and rules used in object-oriented programming provide these important benefits:&lt;/span&gt;&lt;/div&gt;&lt;div style=&quot;background-color: white; line-height: 19px; margin-bottom: 20px; text-align: justify;&quot;&gt;&lt;span class=&quot;Apple-style-span&quot; style=&quot;line-height: 24px;&quot;&gt;&lt;span class=&quot;Apple-style-span&quot; style=&quot;font-family: &#39;Lucida Sans Unicode&#39;, &#39;Lucida Grande&#39;, &#39;Lucida Sans&#39;, Lucida, sans-serif; font-size: 15px;&quot;&gt;1) The concept of a data class makes it possible to define subclasses of data objects that share some or all of the main class characteristics. Called inheritance, this property of OOP forces a more thorough data analysis, reduces development time, and ensures more accurate coding.&lt;/span&gt;&lt;/span&gt;&lt;/div&gt;&lt;div style=&quot;background-color: white; line-height: 19px; margin-bottom: 20px; text-align: justify;&quot;&gt;&lt;span class=&quot;Apple-style-span&quot; style=&quot;line-height: 24px;&quot;&gt;&lt;span class=&quot;Apple-style-span&quot; style=&quot;font-family: &#39;Lucida Sans Unicode&#39;, &#39;Lucida Grande&#39;, &#39;Lucida Sans&#39;, Lucida, sans-serif; font-size: 15px;&quot;&gt;2) Since a class defines only the data it needs to be concerned with, when an instance of that class (an object) is run, the code will not be able to accidentally access other program data. This characteristic of data hiding provides greater system security and avoids unintended data corruption.&lt;/span&gt;&lt;/span&gt;&lt;/div&gt;&lt;div style=&quot;background-color: white; margin-bottom: 20px; text-align: justify;&quot;&gt;&lt;span class=&quot;Apple-style-span&quot; style=&quot;line-height: 24px;&quot;&gt;&lt;span class=&quot;Apple-style-span&quot; style=&quot;font-family: &#39;Lucida Sans Unicode&#39;, &#39;Lucida Grande&#39;, &#39;Lucida Sans&#39;, Lucida, sans-serif; font-size: 15px;&quot;&gt;3) The definition of a class is&amp;nbsp;reusable&amp;nbsp;not only by the program for which it is initially created but also by other object-oriented programs (and, for this reason, can be more easily distributed for use in networks).&lt;/span&gt;&lt;/span&gt;&lt;/div&gt;&lt;div style=&quot;background-color: white; line-height: 19px; margin-bottom: 20px; text-align: justify;&quot;&gt;&lt;span class=&quot;Apple-style-span&quot; style=&quot;line-height: 24px;&quot;&gt;&lt;span class=&quot;Apple-style-span&quot; style=&quot;font-family: &#39;Lucida Sans Unicode&#39;, &#39;Lucida Grande&#39;, &#39;Lucida Sans&#39;, Lucida, sans-serif; font-size: 15px;&quot;&gt;4) The concept of data classes allows a programmer to create any new data type that is not already defined in the language itself.&lt;/span&gt;&lt;/span&gt;&lt;br /&gt;
&lt;span class=&quot;Apple-style-span&quot; style=&quot;line-height: 24px;&quot;&gt;&lt;span class=&quot;Apple-style-span&quot; style=&quot;font-family: &#39;Lucida Sans Unicode&#39;, &#39;Lucida Grande&#39;, &#39;Lucida Sans&#39;, Lucida, sans-serif; font-size: 15px;&quot;&gt;&lt;br /&gt;
&lt;/span&gt;&lt;/span&gt;&lt;br /&gt;
&lt;span class=&quot;Apple-style-span&quot; style=&quot;line-height: 24px;&quot;&gt;&lt;span class=&quot;Apple-style-span&quot; style=&quot;font-family: &#39;Lucida Sans Unicode&#39;, &#39;Lucida Grande&#39;, &#39;Lucida Sans&#39;, Lucida, sans-serif; font-size: 15px;&quot;&gt;Comment for any doubts.......&lt;/span&gt;&lt;/span&gt;&lt;br /&gt;
&lt;span class=&quot;Apple-style-span&quot; style=&quot;line-height: 24px;&quot;&gt;&lt;span class=&quot;Apple-style-span&quot; style=&quot;font-family: &#39;Lucida Sans Unicode&#39;, &#39;Lucida Grande&#39;, &#39;Lucida Sans&#39;, Lucida, sans-serif; font-size: 15px;&quot;&gt;&lt;br /&gt;
&lt;/span&gt;&lt;/span&gt;&lt;/div&gt;&lt;/div&gt;</content><link rel='replies' type='application/atom+xml' href='http://java-intellectual.blogspot.com/feeds/5781128184931786924/comments/default' title='Post Comments'/><link rel='replies' type='text/html' href='http://java-intellectual.blogspot.com/2011/11/what-is-object-oriented-programming.html#comment-form' title='0 Comments'/><link rel='edit' type='application/atom+xml' href='http://www.blogger.com/feeds/3771177150982125782/posts/default/5781128184931786924'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/3771177150982125782/posts/default/5781128184931786924'/><link rel='alternate' type='text/html' href='http://java-intellectual.blogspot.com/2011/11/what-is-object-oriented-programming.html' title='What is Object Oriented  Programming Language ?'/><author><name>siva</name><uri>http://www.blogger.com/profile/01922721189098931789</uri><email>noreply@blogger.com</email><gd:image rel='http://schemas.google.com/g/2005#thumbnail' width='16' height='16' src='https://img1.blogblog.com/img/b16-rounded.gif'/></author><thr:total>0</thr:total></entry><entry><id>tag:blogger.com,1999:blog-3771177150982125782.post-3772723420390164022</id><published>2011-11-23T17:34:00.000-08:00</published><updated>2011-12-09T01:25:39.299-08:00</updated><category scheme="http://www.blogger.com/atom/ns#" term="OOPS Concepts"/><title type='text'>Why OOPS ?</title><content type='html'>&lt;div dir=&quot;ltr&quot; style=&quot;text-align: left;&quot; trbidi=&quot;on&quot;&gt;&lt;div style=&quot;text-align: justify;&quot;&gt;&lt;span class=&quot;Apple-style-span&quot; style=&quot;font-family: &#39;Lucida Sans Unicode&#39;, &#39;Lucida Grande&#39;, &#39;Lucida Sans&#39;, Lucida, sans-serif; font-size: 15px;&quot;&gt;It is introduced to represent objects in programming languages and further to achieve security and to communicate with other programming languages, such as C, C++, .NET,PHP, HTML, JAVA etc.&amp;nbsp;Object oriented programming enables programmers define not only the data, but also&amp;nbsp;its associated&amp;nbsp;behaviors/functions that can be applied to the data. It also enables programmers to create relationships between one object and another. For example, objects can&amp;nbsp;inherit characteristics&amp;nbsp;from other objects.To understand the importance of OOP we need to first understand the problem&amp;nbsp;with procedural/structural programming practices.&amp;nbsp;&lt;/span&gt;&lt;br /&gt;
&lt;span class=&quot;Apple-style-span&quot; style=&quot;font-family: &#39;Lucida Sans Unicode&#39;, &#39;Lucida Grande&#39;, &#39;Lucida Sans&#39;, Lucida, sans-serif; font-size: 15px;&quot;&gt;&lt;/span&gt;&lt;br /&gt;
&lt;a name=&#39;more&#39;&gt;&lt;/a&gt;&lt;span class=&quot;Apple-style-span&quot; style=&quot;font-family: &#39;Lucida Sans Unicode&#39;, &#39;Lucida Grande&#39;, &#39;Lucida Sans&#39;, Lucida, sans-serif; font-size: 15px;&quot;&gt;Procedural programming was suitable&amp;nbsp;for small&amp;nbsp;projects. But as the program grew in size, along with it grew the&amp;nbsp;maintenance nightmare. Also, since the modules were tightly integrated changes in one part of&amp;nbsp;the module&amp;nbsp;inadvertently breaks the other part. Team development was not truly achievable.The next big problem with procedural programming was with respect to&amp;nbsp;re-usability. It&amp;nbsp;was very&amp;nbsp;difficult to write truly reusable code, with minimum maintenance.So why OOP? OOPs facilitates code reuse, team-development, eliminate redundant code,easy management of software complexity etc.&amp;nbsp;&lt;/span&gt;&lt;br /&gt;
&lt;span class=&quot;Apple-style-span&quot; style=&quot;font-family: &#39;Lucida Sans Unicode&#39;, &#39;Lucida Grande&#39;, &#39;Lucida Sans&#39;, Lucida, sans-serif; font-size: 15px;&quot;&gt;&lt;br /&gt;
&lt;/span&gt;&lt;br /&gt;
&lt;span class=&quot;Apple-style-span&quot; style=&quot;font-family: &#39;Lucida Sans Unicode&#39;, &#39;Lucida Grande&#39;, &#39;Lucida Sans&#39;, Lucida, sans-serif; font-size: 15px;&quot;&gt;Comment for any doubts.......&lt;/span&gt;&lt;br /&gt;
&lt;span class=&quot;Apple-style-span&quot; style=&quot;font-family: &#39;Lucida Sans Unicode&#39;, &#39;Lucida Grande&#39;, &#39;Lucida Sans&#39;, Lucida, sans-serif; font-size: 15px;&quot;&gt;&lt;br /&gt;
&lt;/span&gt;&lt;/div&gt;&lt;/div&gt;</content><link rel='replies' type='application/atom+xml' href='http://java-intellectual.blogspot.com/feeds/3772723420390164022/comments/default' title='Post Comments'/><link rel='replies' type='text/html' href='http://java-intellectual.blogspot.com/2011/11/why-oops.html#comment-form' title='0 Comments'/><link rel='edit' type='application/atom+xml' href='http://www.blogger.com/feeds/3771177150982125782/posts/default/3772723420390164022'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/3771177150982125782/posts/default/3772723420390164022'/><link rel='alternate' type='text/html' href='http://java-intellectual.blogspot.com/2011/11/why-oops.html' title='Why OOPS ?'/><author><name>siva</name><uri>http://www.blogger.com/profile/01922721189098931789</uri><email>noreply@blogger.com</email><gd:image rel='http://schemas.google.com/g/2005#thumbnail' width='16' height='16' src='https://img1.blogblog.com/img/b16-rounded.gif'/></author><thr:total>0</thr:total></entry><entry><id>tag:blogger.com,1999:blog-3771177150982125782.post-9192255457239180602</id><published>2011-11-02T22:59:00.000-07:00</published><updated>2011-12-15T05:33:54.958-08:00</updated><category scheme="http://www.blogger.com/atom/ns#" term="OOPS Concepts"/><title type='text'>What is a constructor and rules in defining constructor ?</title><content type='html'>&lt;div dir=&quot;ltr&quot; style=&quot;text-align: left;&quot; trbidi=&quot;on&quot;&gt;&lt;div dir=&quot;ltr&quot; style=&quot;text-align: left;&quot; trbidi=&quot;on&quot;&gt;&lt;div style=&quot;text-align: justify;&quot;&gt;&lt;span class=&quot;Apple-style-span&quot; style=&quot;font-family: &#39;Lucida Sans Unicode&#39;, &#39;Lucida Grande&#39;, &#39;Lucida Sans&#39;, Lucida, sans-serif; font-size: 15px;&quot;&gt;Constructor is a special method given in OOP language for creating and initializing object. In java, constructor role is only initializing object and new keyword role is creating object. In C++, constructor alone creates and initializes object.&lt;/span&gt;&lt;/div&gt;&lt;br /&gt;
&lt;div style=&quot;text-align: justify;&quot;&gt;&lt;span class=&quot;Apple-style-span&quot; style=&quot;font-family: &#39;Lucida Sans Unicode&#39;, &#39;Lucida Grande&#39;, &#39;Lucida Sans&#39;, Lucida, sans-serif; font-size: 15px;&quot;&gt;&lt;b&gt;Rules in defining constructor:&lt;/b&gt;&lt;/span&gt;&lt;/div&gt;&lt;br /&gt;
&lt;div style=&quot;text-align: justify;&quot;&gt;&lt;span class=&quot;Apple-style-span&quot; style=&quot;font-family: &#39;Lucida Sans Unicode&#39;, &#39;Lucida Grande&#39;, &#39;Lucida Sans&#39;, Lucida, sans-serif; font-size: 15px;&quot;&gt;1) Constructor name should be same as class name.&lt;/span&gt;&lt;/div&gt;&lt;div style=&quot;text-align: justify;&quot;&gt;&lt;span class=&quot;Apple-style-span&quot; style=&quot;font-family: &#39;Lucida Sans Unicode&#39;, &#39;Lucida Grande&#39;, &#39;Lucida Sans&#39;, Lucida, sans-serif; font-size: 15px;&quot;&gt;2) It should not contain return type.&lt;/span&gt;&lt;/div&gt;&lt;div style=&quot;text-align: justify;&quot;&gt;&lt;span class=&quot;Apple-style-span&quot; style=&quot;font-family: &#39;Lucida Sans Unicode&#39;, &#39;Lucida Grande&#39;, &#39;Lucida Sans&#39;, Lucida, sans-serif; font-size: 15px;&quot;&gt;3) It should not contain modifiers.&lt;/span&gt;&lt;/div&gt;&lt;div style=&quot;text-align: justify;&quot;&gt;&lt;span class=&quot;Apple-style-span&quot; style=&quot;font-family: &#39;Lucida Sans Unicode&#39;, &#39;Lucida Grande&#39;, &#39;Lucida Sans&#39;, Lucida, sans-serif; font-size: 15px;&quot;&gt;4) In its logic, return statement with value is not allowed.&lt;/span&gt;&lt;/div&gt;&lt;a name=&#39;more&#39;&gt;&lt;/a&gt;&lt;br /&gt;
&lt;b style=&quot;font-family: &#39;Lucida Sans Unicode&#39;, &#39;Lucida Grande&#39;, &#39;Lucida Sans&#39;, Lucida, sans-serif; font-size: 15px; text-align: justify;&quot;&gt;Note:&lt;/b&gt;&lt;br /&gt;
&lt;br /&gt;
&lt;div style=&quot;text-align: justify;&quot;&gt;&lt;span class=&quot;Apple-style-span&quot; style=&quot;font-family: &#39;Lucida Sans Unicode&#39;, &#39;Lucida Grande&#39;, &#39;Lucida Sans&#39;, Lucida, sans-serif; font-size: 15px;&quot;&gt;5) It can have all four accessibility modifiers(private,protected,default,public).&lt;/span&gt;&lt;/div&gt;&lt;div style=&quot;text-align: justify;&quot;&gt;&lt;span class=&quot;Apple-style-span&quot; style=&quot;font-family: &#39;Lucida Sans Unicode&#39;, &#39;Lucida Grande&#39;, &#39;Lucida Sans&#39;, Lucida, sans-serif; font-size: 15px;&quot;&gt;6) It can have parameters.&lt;/span&gt;&lt;/div&gt;&lt;div style=&quot;text-align: justify;&quot;&gt;&lt;span class=&quot;Apple-style-span&quot; style=&quot;font-family: &#39;Lucida Sans Unicode&#39;, &#39;Lucida Grande&#39;, &#39;Lucida Sans&#39;, Lucida, sans-serif; font-size: 15px;&quot;&gt;7) It can have throws clause-it means we can throw exception from constructor.&lt;/span&gt;&lt;/div&gt;&lt;div style=&quot;text-align: justify;&quot;&gt;&lt;span class=&quot;Apple-style-span&quot; style=&quot;font-family: &#39;Lucida Sans Unicode&#39;, &#39;Lucida Grande&#39;, &#39;Lucida Sans&#39;, Lucida, sans-serif; font-size: 15px;&quot;&gt;8) It can have logic, as part of logic it can have all legal statement except return statement with value.&lt;/span&gt;&lt;/div&gt;&lt;div style=&quot;text-align: justify;&quot;&gt;&lt;span class=&quot;Apple-style-span&quot; style=&quot;font-family: &#39;Lucida Sans Unicode&#39;, &#39;Lucida Grande&#39;, &#39;Lucida Sans&#39;, Lucida, sans-serif; font-size: 15px;&quot;&gt;9) We can place return; in constructor.&lt;/span&gt;&lt;/div&gt;&lt;br /&gt;
&lt;div style=&quot;text-align: justify;&quot;&gt;&lt;span class=&quot;Apple-style-span&quot; style=&quot;font-family: &#39;Lucida Sans Unicode&#39;, &#39;Lucida Grande&#39;, &#39;Lucida Sans&#39;, Lucida, sans-serif; font-size: 15px;&quot;&gt;Constructor creation &lt;b&gt;syntax&lt;/b&gt; is as follows&lt;/span&gt;&lt;/div&gt;&lt;span class=&quot;Apple-style-span&quot; style=&quot;font-family: &#39;Lucida Sans Unicode&#39;, &#39;Lucida Grande&#39;, &#39;Lucida Sans&#39;, Lucida, sans-serif; font-size: 15px;&quot;&gt;&lt;/span&gt;&lt;br /&gt;
&lt;span class=&quot;Apple-style-span&quot; style=&quot;font-family: &#39;Lucida Sans Unicode&#39;, &#39;Lucida Grande&#39;, &#39;Lucida Sans&#39;, Lucida, sans-serif; font-size: 15px;&quot;&gt;&lt;pre class=&quot;brush:java;&quot;&gt;class Example 
{ 
   Example()
   {
      //All java legal statements are allowed except return statement
      ------;
      ------; 
      ------;
   }
}
&lt;/pre&gt;&lt;/span&gt;&lt;br /&gt;
&lt;span class=&quot;Apple-style-span&quot; style=&quot;font-family: &#39;Lucida Sans Unicode&#39;, &#39;Lucida Grande&#39;, &#39;Lucida Sans&#39;, Lucida, sans-serif; font-size: 15px;&quot;&gt;Below application shows defining a class with constructor and its execution&lt;/span&gt;&lt;br /&gt;
&lt;span class=&quot;Apple-style-span&quot; style=&quot;font-family: &#39;Lucida Sans Unicode&#39;, &#39;Lucida Grande&#39;, &#39;Lucida Sans&#39;, Lucida, sans-serif; font-size: 15px;&quot;&gt;&lt;/span&gt;&lt;br /&gt;
&lt;span class=&quot;Apple-style-span&quot; style=&quot;font-family: &#39;Lucida Sans Unicode&#39;, &#39;Lucida Grande&#39;, &#39;Lucida Sans&#39;, Lucida, sans-serif; font-size: 15px;&quot;&gt;&lt;pre class=&quot;brush:java;&quot;&gt;class Example {
   Example()
   {
      System.out.println(&quot;constructor&quot;);
   }
   public static void main(String[] args)
   {
      System.out.println(&quot;main&quot;);     
      Example e = new Example();
   }
}
&lt;/pre&gt;&lt;/span&gt;&lt;br /&gt;
&lt;/div&gt;&lt;div style=&quot;text-align: justify;&quot;&gt;&lt;span class=&quot;Apple-style-span&quot; style=&quot;font-family: &#39;Lucida Sans Unicode&#39;, &#39;Lucida Grande&#39;, &#39;Lucida Sans&#39;, Lucida, sans-serif; font-size: 15px;&quot;&gt;Whenever we compile the java file by using &lt;b&gt;javac Example.java&lt;/b&gt; &#39;.class&#39; file is generated and when we execute the &#39;.class&#39; file by using &lt;b&gt;java Example&lt;/b&gt; &#39;.class&#39; file is loaded into JVM, then the first statement that is executed by JVM is the main method and later main is printed by using &lt;b&gt;System.out.println&lt;/b&gt; statement. After that object creation statement is executed. In that statement whenever the control comes to new Example(), &amp;nbsp;then object is created and constructor is initialized. One thing we should keep in mind that object is created first and then the constructor is initialized. Whenever the execution comes to new Example(), if you carefully observe in that statement Example() is a method. So thats why constructor is called and it is executed.So we can say that constructor is also a method but it has a different functionality like initializing object.&amp;nbsp;&lt;/span&gt;&lt;br /&gt;
&lt;span class=&quot;Apple-style-span&quot; style=&quot;font-family: &#39;Lucida Sans Unicode&#39;, &#39;Lucida Grande&#39;, &#39;Lucida Sans&#39;, Lucida, sans-serif; font-size: 15px;&quot;&gt;&lt;br /&gt;
&lt;/span&gt;&lt;/div&gt;&lt;div class=&quot;separator&quot; style=&quot;clear: both; text-align: center;&quot;&gt;&lt;/div&gt;&lt;div class=&quot;separator&quot; style=&quot;clear: both; text-align: center;&quot;&gt;&lt;/div&gt;&lt;div class=&quot;separator&quot; style=&quot;clear: both; text-align: center;&quot;&gt;&lt;/div&gt;&lt;div class=&quot;separator&quot; style=&quot;clear: both; text-align: center;&quot;&gt;&lt;/div&gt;&lt;div class=&quot;separator&quot; style=&quot;clear: both; text-align: center;&quot;&gt;&lt;/div&gt;&lt;div class=&quot;separator&quot; style=&quot;clear: both; text-align: center;&quot;&gt;&lt;/div&gt;&lt;div class=&quot;separator&quot; style=&quot;clear: both; text-align: center;&quot;&gt;&lt;/div&gt;&lt;div class=&quot;separator&quot; style=&quot;clear: both; text-align: center;&quot;&gt;&lt;br /&gt;
&lt;/div&gt;&lt;br /&gt;
&lt;/div&gt;</content><link rel='replies' type='application/atom+xml' href='http://java-intellectual.blogspot.com/feeds/9192255457239180602/comments/default' title='Post Comments'/><link rel='replies' type='text/html' href='http://java-intellectual.blogspot.com/2011/12/what-is-constructor-and-rules-in.html#comment-form' title='0 Comments'/><link rel='edit' type='application/atom+xml' href='http://www.blogger.com/feeds/3771177150982125782/posts/default/9192255457239180602'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/3771177150982125782/posts/default/9192255457239180602'/><link rel='alternate' type='text/html' href='http://java-intellectual.blogspot.com/2011/12/what-is-constructor-and-rules-in.html' title='What is a constructor and rules in defining constructor ?'/><author><name>siva</name><uri>http://www.blogger.com/profile/01922721189098931789</uri><email>noreply@blogger.com</email><gd:image rel='http://schemas.google.com/g/2005#thumbnail' width='16' height='16' src='https://img1.blogblog.com/img/b16-rounded.gif'/></author><thr:total>0</thr:total></entry><entry><id>tag:blogger.com,1999:blog-3771177150982125782.post-3713378897816573346</id><published>2011-11-01T08:11:00.000-07:00</published><updated>2011-12-09T01:26:34.515-08:00</updated><category scheme="http://www.blogger.com/atom/ns#" term="Datatypes and Literals"/><title type='text'>Types of Literals and their default datatypes</title><content type='html'>&lt;div dir=&quot;ltr&quot; style=&quot;text-align: left;&quot; trbidi=&quot;on&quot;&gt;&lt;div style=&quot;font-family: &#39;Lucida Sans Unicode&#39;,&#39;Lucida Grande&#39;,&#39;Lucida Sans&#39;,Lucida,sans-serif; text-align: justify;&quot;&gt;&lt;span class=&quot;Apple-style-span&quot; style=&quot;font-size: 15px;&quot;&gt;&lt;span class=&quot;Apple-style-span&quot;&gt;All &lt;/span&gt;&lt;u style=&quot;text-align: left;&quot;&gt;Integer type Literals&lt;/u&gt;&lt;span class=&quot;Apple-style-span&quot; style=&quot;text-align: left;&quot;&gt; are by default of type &lt;/span&gt;&lt;u style=&quot;text-align: left;&quot;&gt;int&lt;/u&gt;&lt;span class=&quot;Apple-style-span&quot; style=&quot;text-align: left;&quot;&gt;. If we want to represent them as &lt;/span&gt;&lt;u style=&quot;text-align: left;&quot;&gt;long &lt;/u&gt;&lt;span class=&quot;Apple-style-span&quot; style=&quot;text-align: left;&quot;&gt;we must &lt;/span&gt;&lt;u style=&quot;text-align: left;&quot;&gt;suffix &#39;l&#39; or &#39;L&#39;&lt;/u&gt;&lt;span class=&quot;Apple-style-span&quot; style=&quot;text-align: left;&quot;&gt; to the Literal. we do not have byte or short type Literals.&lt;/span&gt;&lt;/span&gt;&lt;/div&gt;&lt;div style=&quot;font-family: &#39;Lucida Sans Unicode&#39;,&#39;Lucida Grande&#39;,&#39;Lucida Sans&#39;,Lucida,sans-serif; text-align: justify;&quot;&gt;&lt;span style=&quot;font-size: 15px;&quot;&gt;&lt;br /&gt;
&lt;/span&gt;&lt;/div&gt;&lt;div style=&quot;font-family: &#39;Lucida Sans Unicode&#39;,&#39;Lucida Grande&#39;,&#39;Lucida Sans&#39;,Lucida,sans-serif; text-align: justify;&quot;&gt;&lt;span style=&quot;font-size: 15px;&quot;&gt;All &lt;u&gt;floating type Literals&lt;/u&gt; are of type &lt;u&gt;double&lt;/u&gt; by default. If we want to represent them as &lt;u&gt;float &lt;/u&gt;we must suffix &#39;f&#39; or &#39;F&#39; to the Literals.&lt;/span&gt;&lt;/div&gt;&lt;div style=&quot;font-family: &#39;Lucida Sans Unicode&#39;,&#39;Lucida Grande&#39;,&#39;Lucida Sans&#39;,Lucida,sans-serif; text-align: justify;&quot;&gt;&lt;span style=&quot;font-size: 15px;&quot;&gt;&lt;br /&gt;
&lt;/span&gt;&lt;/div&gt;&lt;div style=&quot;font-family: &#39;Lucida Sans Unicode&#39;,&#39;Lucida Grande&#39;,&#39;Lucida Sans&#39;,Lucida,sans-serif; text-align: justify;&quot;&gt;&lt;span style=&quot;font-size: 15px;&quot;&gt;The data placed inside single quote is considered as &lt;u&gt;char&lt;/u&gt; Literal&lt;/span&gt;&lt;/div&gt;&lt;div style=&quot;font-family: &#39;Lucida Sans Unicode&#39;,&#39;Lucida Grande&#39;,&#39;Lucida Sans&#39;,Lucida,sans-serif; text-align: justify;&quot;&gt;&lt;span style=&quot;font-size: 15px;&quot;&gt;&lt;br /&gt;
&lt;/span&gt;&lt;/div&gt;&lt;div style=&quot;font-family: &#39;Lucida Sans Unicode&#39;,&#39;Lucida Grande&#39;,&#39;Lucida Sans&#39;,Lucida,sans-serif; text-align: justify;&quot;&gt;&lt;span style=&quot;font-size: 15px;&quot;&gt;Rule: In single quote we are not allowed to place more than one character. We can place either &#39;0&#39; or &#39;1&#39; characters.&lt;/span&gt;&lt;/div&gt;&lt;div style=&quot;font-family: &#39;Lucida Sans Unicode&#39;,&#39;Lucida Grande&#39;,&#39;Lucida Sans&#39;,Lucida,sans-serif; text-align: justify;&quot;&gt;&lt;span style=&quot;font-size: 15px;&quot;&gt;&lt;/span&gt;&lt;br /&gt;
&lt;a name=&#39;more&#39;&gt;&lt;/a&gt;&lt;/div&gt;&lt;div style=&quot;font-family: &#39;Lucida Sans Unicode&#39;,&#39;Lucida Grande&#39;,&#39;Lucida Sans&#39;,Lucida,sans-serif; text-align: justify;&quot;&gt;&lt;span style=&quot;font-size: 15px;&quot;&gt;The data placed inside double quotes is considered as &lt;u&gt;String&lt;/u&gt; Literal&lt;/span&gt;&lt;/div&gt;&lt;div style=&quot;font-family: &#39;Lucida Sans Unicode&#39;,&#39;Lucida Grande&#39;,&#39;Lucida Sans&#39;,Lucida,sans-serif; text-align: justify;&quot;&gt;&lt;span style=&quot;font-size: 15px;&quot;&gt;&lt;br /&gt;
&lt;/span&gt;&lt;/div&gt;&lt;div style=&quot;font-family: &#39;Lucida Sans Unicode&#39;,&#39;Lucida Grande&#39;,&#39;Lucida Sans&#39;,Lucida,sans-serif; text-align: justify;&quot;&gt;&lt;span style=&quot;font-size: 15px;&quot;&gt;Note: In double quotes we can place &#39;0&#39; or &#39;n&#39; number of characters.&lt;/span&gt;&lt;br /&gt;
&lt;span style=&quot;font-size: 15px;&quot;&gt;&lt;br /&gt;
&lt;/span&gt;&lt;br /&gt;
&lt;span style=&quot;font-size: 15px;&quot;&gt;Below are the following Literals in Java&lt;/span&gt;&lt;br /&gt;
&lt;span style=&quot;font-size: 15px;&quot;&gt;&lt;br /&gt;
&lt;/span&gt;&lt;br /&gt;
&lt;span style=&quot;font-size: 15px;&quot;&gt;&lt;a href=&quot;https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEioyjL3kKmrXI3wY7gEzcrgwKAPgCHN4ZbixSW-yeJFOyY-9KbKelLmsSJT81Ruk0BOQzoa13NNESQaf3o5ysCrSsHW3h_-gzW1mlfn-jqkpQjA4WNaIY6hIigTebROchEymFChrVIirA0/s1600/chaitu.bmp&quot; imageanchor=&quot;1&quot; style=&quot;margin-left: 1em; margin-right: 1em;&quot;&gt;&lt;img border=&quot;0&quot; height=&quot;452&quot; src=&quot;https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEioyjL3kKmrXI3wY7gEzcrgwKAPgCHN4ZbixSW-yeJFOyY-9KbKelLmsSJT81Ruk0BOQzoa13NNESQaf3o5ysCrSsHW3h_-gzW1mlfn-jqkpQjA4WNaIY6hIigTebROchEymFChrVIirA0/s640/chaitu.bmp&quot; width=&quot;640&quot; /&gt;&lt;/a&gt;&lt;/span&gt;&lt;br /&gt;
&lt;span class=&quot;Apple-style-span&quot; style=&quot;font-size: 15px;&quot;&gt;&lt;br /&gt;
&lt;/span&gt;&lt;br /&gt;
&lt;span style=&quot;font-size: 15px;&quot;&gt;Comment for any doubts.....&lt;/span&gt;&lt;/div&gt;&lt;div style=&quot;font-family: &#39;Salsa&#39;,&amp;quot;Times New Roman&amp;quot;,serif; text-align: justify;&quot;&gt;&lt;span style=&quot;font-size: 15px;&quot;&gt;&lt;br /&gt;
&lt;/span&gt;&lt;/div&gt;&lt;/div&gt;</content><link rel='replies' type='application/atom+xml' href='http://java-intellectual.blogspot.com/feeds/3713378897816573346/comments/default' title='Post Comments'/><link rel='replies' type='text/html' href='http://java-intellectual.blogspot.com/2011/11/types-of-literals-and-their-default.html#comment-form' title='0 Comments'/><link rel='edit' type='application/atom+xml' href='http://www.blogger.com/feeds/3771177150982125782/posts/default/3713378897816573346'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/3771177150982125782/posts/default/3713378897816573346'/><link rel='alternate' type='text/html' href='http://java-intellectual.blogspot.com/2011/11/types-of-literals-and-their-default.html' title='Types of Literals and their default datatypes'/><author><name>siva</name><uri>http://www.blogger.com/profile/01922721189098931789</uri><email>noreply@blogger.com</email><gd:image rel='http://schemas.google.com/g/2005#thumbnail' width='16' height='16' src='https://img1.blogblog.com/img/b16-rounded.gif'/></author><media:thumbnail xmlns:media="http://search.yahoo.com/mrss/" url="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEioyjL3kKmrXI3wY7gEzcrgwKAPgCHN4ZbixSW-yeJFOyY-9KbKelLmsSJT81Ruk0BOQzoa13NNESQaf3o5ysCrSsHW3h_-gzW1mlfn-jqkpQjA4WNaIY6hIigTebROchEymFChrVIirA0/s72-c/chaitu.bmp" height="72" width="72"/><thr:total>0</thr:total></entry><entry><id>tag:blogger.com,1999:blog-3771177150982125782.post-8721219644117567246</id><published>2011-11-01T07:49:00.000-07:00</published><updated>2011-12-09T01:29:00.227-08:00</updated><category scheme="http://www.blogger.com/atom/ns#" term="Datatypes and Literals"/><title type='text'>What is a Literal ?</title><content type='html'>&lt;div dir=&quot;ltr&quot; style=&quot;text-align: left;&quot; trbidi=&quot;on&quot;&gt;&lt;div style=&quot;font-family: &#39;Lucida Sans Unicode&#39;,&#39;Lucida Grande&#39;,&#39;Lucida Sans&#39;,Lucida,sans-serif; text-align: justify;&quot;&gt;&lt;span style=&quot;font-size: 15px;&quot;&gt;Literal is a nothing but a constant. Literals represent numerical (integer or floating-point or double), character, boolean or string values. For example &lt;span style=&quot;font-family: Arial, Helvetica, sans-serif;&quot;&gt;10, 20.4, &#39;a&#39;, &quot;a&quot;, &quot;ab&quot;, true, false&lt;/span&gt;. Let us take a statement&lt;/span&gt;&lt;br /&gt;
&lt;span style=&quot;font-size: 15px;&quot;&gt;&lt;/span&gt;&lt;br /&gt;
&lt;a name=&#39;more&#39;&gt;&lt;/a&gt;&lt;/div&gt;&lt;pre class=&quot;brush:java;&quot;&gt;int month=10;
&lt;/pre&gt;&lt;div style=&quot;text-align: justify;&quot;&gt;&lt;div style=&quot;font-family: &#39;Lucida Sans Unicode&#39;, &#39;Lucida Grande&#39;, &#39;Lucida Sans&#39;, Lucida, sans-serif;&quot;&gt;&lt;span class=&quot;Apple-style-span&quot; style=&quot;font-size: 15px;&quot;&gt;&lt;span class=&quot;Apple-style-span&quot; style=&quot;font-family: &#39;Lucida Sans Unicode&#39;, &#39;Lucida Grande&#39;, &#39;Lucida Sans&#39;, Lucida, sans-serif;&quot;&gt;&lt;span class=&quot;Apple-style-span&quot;&gt;In the above statement the literal is an integer value i.e &lt;/span&gt;&lt;/span&gt;&lt;span style=&quot;font-family: Arial, Helvetica, sans-serif;&quot;&gt;10&lt;/span&gt;&lt;span class=&quot;Apple-style-span&quot; style=&quot;font-family: &#39;Lucida Sans Unicode&#39;, &#39;Lucida Grande&#39;, &#39;Lucida Sans&#39;, Lucida, sans-serif;&quot;&gt;&lt;span class=&quot;Apple-style-span&quot;&gt;. The literal is &lt;/span&gt;&lt;/span&gt;&lt;span style=&quot;font-family: Arial, Helvetica, sans-serif;&quot;&gt;10&lt;/span&gt;&lt;span class=&quot;Apple-style-span&quot; style=&quot;font-family: &#39;Lucida Sans Unicode&#39;, &#39;Lucida Grande&#39;, &#39;Lucida Sans&#39;, Lucida, sans-serif;&quot;&gt;&lt;span class=&quot;Apple-style-span&quot;&gt; because it directly represents the integer value.&lt;/span&gt;&lt;/span&gt;&lt;/span&gt;&lt;/div&gt;&lt;/div&gt;&lt;div style=&quot;font-family: &#39;Lucida Sans Unicode&#39;,&#39;Lucida Grande&#39;,&#39;Lucida Sans&#39;,Lucida,sans-serif; text-align: justify;&quot;&gt;&lt;span style=&quot;font-size: 15px;&quot;&gt;&lt;/span&gt;&lt;/div&gt;&lt;span style=&quot;font-family: &#39;Lucida Sans Unicode&#39;, &#39;Lucida Grande&#39;, &#39;Lucida Sans&#39;, Lucida, sans-serif; font-size: 15px;&quot;&gt;&lt;br /&gt;
&lt;/span&gt;&lt;br /&gt;
&lt;span style=&quot;font-family: &#39;Lucida Sans Unicode&#39;, &#39;Lucida Grande&#39;, &#39;Lucida Sans&#39;, Lucida, sans-serif; font-size: 15px;&quot;&gt;Comment for any doubts.......&lt;/span&gt;&lt;br /&gt;
&lt;span style=&quot;font-family: &#39;Lucida Sans Unicode&#39;, &#39;Lucida Grande&#39;, &#39;Lucida Sans&#39;, Lucida, sans-serif; font-size: 15px;&quot;&gt;&lt;br /&gt;
&lt;/span&gt;&lt;/div&gt;</content><link rel='replies' type='application/atom+xml' href='http://java-intellectual.blogspot.com/feeds/8721219644117567246/comments/default' title='Post Comments'/><link rel='replies' type='text/html' href='http://java-intellectual.blogspot.com/2011/11/what-is-literal.html#comment-form' title='0 Comments'/><link rel='edit' type='application/atom+xml' href='http://www.blogger.com/feeds/3771177150982125782/posts/default/8721219644117567246'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/3771177150982125782/posts/default/8721219644117567246'/><link rel='alternate' type='text/html' href='http://java-intellectual.blogspot.com/2011/11/what-is-literal.html' title='What is a Literal ?'/><author><name>siva</name><uri>http://www.blogger.com/profile/01922721189098931789</uri><email>noreply@blogger.com</email><gd:image rel='http://schemas.google.com/g/2005#thumbnail' width='16' height='16' src='https://img1.blogblog.com/img/b16-rounded.gif'/></author><thr:total>0</thr:total></entry><entry><id>tag:blogger.com,1999:blog-3771177150982125782.post-4827220853845095259</id><published>2011-10-28T07:32:00.000-07:00</published><updated>2011-12-09T01:29:50.875-08:00</updated><category scheme="http://www.blogger.com/atom/ns#" term="java introduction"/><title type='text'>Why have Naming Conventions ?</title><content type='html'>&lt;div dir=&quot;ltr&quot; style=&quot;text-align: left;&quot; trbidi=&quot;on&quot;&gt;&lt;div style=&quot;text-align: justify;&quot;&gt;&lt;span class=&quot;Apple-style-span&quot; style=&quot;font-size: 15px;&quot;&gt;&lt;span class=&quot;Apple-style-span&quot; style=&quot;font-family: &#39;Lucida Sans Unicode&#39;, &#39;Lucida Grande&#39;, &#39;Lucida Sans&#39;, Lucida, sans-serif;&quot;&gt;A naming convention is a rule to follow as you decide what to name your identifiers (e.g. class, package, variable, method, etc).&lt;/span&gt;&lt;span class=&quot;Apple-style-span&quot; style=&quot;font-family: &#39;Lucida Sans Unicode&#39;, &#39;Lucida Grande&#39;, &#39;Lucida Sans&#39;, Lucida, sans-serif;&quot;&gt;Different Java programmers can have different styles and approaches to the way they program. By using standard Java naming conventions they make their code easier to read for themselves and for other programmers. Readability of Java code is important because it means less time is spent trying to figure out what the code does, leaving more time to fix or modify it.&lt;/span&gt;&lt;/span&gt;&lt;/div&gt;&lt;div&gt;&lt;div style=&quot;text-align: justify;&quot;&gt;&lt;span class=&quot;Apple-style-span&quot; style=&quot;font-family: &#39;Lucida Sans Unicode&#39;, &#39;Lucida Grande&#39;, &#39;Lucida Sans&#39;, Lucida, sans-serif; font-size: 15px;&quot;&gt;&lt;/span&gt;&lt;br /&gt;
&lt;a name=&#39;more&#39;&gt;&lt;/a&gt;&lt;/div&gt;&lt;div style=&quot;text-align: justify;&quot;&gt;&lt;span class=&quot;Apple-style-span&quot; style=&quot;font-family: &#39;Lucida Sans Unicode&#39;, &#39;Lucida Grande&#39;, &#39;Lucida Sans&#39;, Lucida, sans-serif; font-size: 15px;&quot;&gt;We Should follow naming conventions because of the following reasons.&lt;/span&gt;&lt;/div&gt;&lt;div style=&quot;text-align: justify;&quot;&gt;&lt;span class=&quot;Apple-style-span&quot; style=&quot;font-family: &#39;Lucida Sans Unicode&#39;, &#39;Lucida Grande&#39;, &#39;Lucida Sans&#39;, Lucida, sans-serif; font-size: 15px;&quot;&gt;&lt;br /&gt;
&lt;/span&gt;&lt;/div&gt;&lt;div style=&quot;text-align: justify;&quot;&gt;&lt;span class=&quot;Apple-style-span&quot; style=&quot;font-family: &#39;Lucida Sans Unicode&#39;, &#39;Lucida Grande&#39;, &#39;Lucida Sans&#39;, Lucida, sans-serif; font-size: 15px;&quot;&gt;+ A program is written once and read many times.&lt;/span&gt;&lt;/div&gt;&lt;div style=&quot;text-align: justify;&quot;&gt;&lt;span class=&quot;Apple-style-span&quot; style=&quot;font-family: &#39;Lucida Sans Unicode&#39;, &#39;Lucida Grande&#39;, &#39;Lucida Sans&#39;, Lucida, sans-serif; font-size: 15px;&quot;&gt;+ During debugging&lt;/span&gt;&lt;/div&gt;&lt;div style=&quot;text-align: justify;&quot;&gt;&lt;span class=&quot;Apple-style-span&quot; style=&quot;font-family: &#39;Lucida Sans Unicode&#39;, &#39;Lucida Grande&#39;, &#39;Lucida Sans&#39;, Lucida, sans-serif; font-size: 15px;&quot;&gt;+ When adding to a program&lt;/span&gt;&lt;/div&gt;&lt;div style=&quot;text-align: justify;&quot;&gt;&lt;span class=&quot;Apple-style-span&quot; style=&quot;font-family: &#39;Lucida Sans Unicode&#39;, &#39;Lucida Grande&#39;, &#39;Lucida Sans&#39;, Lucida, sans-serif; font-size: 15px;&quot;&gt;+ When updating the program&lt;/span&gt;&lt;/div&gt;&lt;div style=&quot;text-align: justify;&quot;&gt;&lt;span class=&quot;Apple-style-span&quot; style=&quot;font-family: &#39;Lucida Sans Unicode&#39;, &#39;Lucida Grande&#39;, &#39;Lucida Sans&#39;, Lucida, sans-serif; font-size: 15px;&quot;&gt;+ When trying to understand the program&lt;/span&gt;&lt;/div&gt;&lt;div style=&quot;text-align: justify;&quot;&gt;&lt;span class=&quot;Apple-style-span&quot; style=&quot;font-family: &#39;Lucida Sans Unicode&#39;, &#39;Lucida Grande&#39;, &#39;Lucida Sans&#39;, Lucida, sans-serif; font-size: 15px;&quot;&gt;&lt;/span&gt;&lt;/div&gt;&lt;div style=&quot;text-align: justify;&quot;&gt;&lt;span class=&quot;Apple-style-span&quot; style=&quot;font-family: &#39;Lucida Sans Unicode&#39;, &#39;Lucida Grande&#39;, &#39;Lucida Sans&#39;, Lucida, sans-serif; font-size: 15px;&quot;&gt;&lt;br /&gt;
&lt;/span&gt;&lt;br /&gt;
&lt;span class=&quot;Apple-style-span&quot; style=&quot;font-family: &#39;Lucida Sans Unicode&#39;, &#39;Lucida Grande&#39;, &#39;Lucida Sans&#39;, Lucida, sans-serif; font-size: 15px;&quot;&gt;To illustrate the above points it&#39;s worth mentioning that most software companies will have a document that outlines the naming conventions they want their programmers to follow. A new programmer who becomes familiar with those rules will be able to understand code written by a programmer who might have left the company many years before hand.So anything that makes a program more readable and understandable saves lot of time even in short run.&lt;/span&gt;&lt;/div&gt;&lt;/div&gt;&lt;/div&gt;</content><link rel='replies' type='application/atom+xml' href='http://java-intellectual.blogspot.com/feeds/4827220853845095259/comments/default' title='Post Comments'/><link rel='replies' type='text/html' href='http://java-intellectual.blogspot.com/2011/10/why-have-naming-conventions.html#comment-form' title='1 Comments'/><link rel='edit' type='application/atom+xml' href='http://www.blogger.com/feeds/3771177150982125782/posts/default/4827220853845095259'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/3771177150982125782/posts/default/4827220853845095259'/><link rel='alternate' type='text/html' href='http://java-intellectual.blogspot.com/2011/10/why-have-naming-conventions.html' title='Why have Naming Conventions ?'/><author><name>siva</name><uri>http://www.blogger.com/profile/01922721189098931789</uri><email>noreply@blogger.com</email><gd:image rel='http://schemas.google.com/g/2005#thumbnail' width='16' height='16' src='https://img1.blogblog.com/img/b16-rounded.gif'/></author><thr:total>1</thr:total></entry><entry><id>tag:blogger.com,1999:blog-3771177150982125782.post-3799995213775979290</id><published>2011-10-28T05:19:00.000-07:00</published><updated>2011-12-09T01:31:19.703-08:00</updated><category scheme="http://www.blogger.com/atom/ns#" term="java introduction"/><title type='text'>Coding Standards and Naming Conventions in Java</title><content type='html'>&lt;div dir=&quot;ltr&quot; style=&quot;text-align: left;&quot; trbidi=&quot;on&quot;&gt;&lt;div style=&quot;text-align: justify;&quot;&gt;&lt;span class=&quot;Apple-style-span&quot; style=&quot;font-family: &#39;Lucida Sans Unicode&#39;,&#39;Lucida Grande&#39;,&#39;Lucida Sans&#39;,Lucida,sans-serif; font-size: 15px;&quot;&gt;These Coding Standards and Naming Conventions are nothing but&amp;nbsp;suggestions. If we follow these two while developing Java applications, then it is more readable and understandable. Sun define several coding standards, some of the important ones are&lt;/span&gt;&lt;/div&gt;&lt;div style=&quot;text-align: justify;&quot;&gt;&lt;span class=&quot;Apple-style-span&quot; style=&quot;font-family: &#39;Lucida Sans Unicode&#39;,&#39;Lucida Grande&#39;,&#39;Lucida Sans&#39;,Lucida,sans-serif; font-size: 15px;&quot;&gt;&lt;/span&gt;&lt;/div&gt;&lt;a name=&#39;more&#39;&gt;&lt;/a&gt;&lt;br /&gt;
&lt;div style=&quot;text-align: justify;&quot;&gt;&lt;span class=&quot;Apple-style-span&quot; style=&quot;font-family: &#39;Lucida Sans Unicode&#39;,&#39;Lucida Grande&#39;,&#39;Lucida Sans&#39;,Lucida,sans-serif; font-size: 15px;&quot;&gt;+ Every basic programming language element must have&amp;nbsp;&lt;/span&gt;&lt;span class=&quot;Apple-style-span&quot; style=&quot;font-family: &#39;Lucida Sans Unicode&#39;,&#39;Lucida Grande&#39;,&#39;Lucida Sans&#39;,Lucida,sans-serif; font-size: 15px;&quot;&gt;&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp;&amp;nbsp;&lt;/span&gt;&lt;/div&gt;&lt;div style=&quot;text-align: justify;&quot;&gt;&lt;span class=&quot;Apple-style-span&quot; style=&quot;font-family: &#39;Lucida Sans Unicode&#39;,&#39;Lucida Grande&#39;,&#39;Lucida Sans&#39;,Lucida,sans-serif; font-size: 15px;&quot;&gt;&amp;nbsp; &amp;nbsp;&amp;nbsp;&lt;/span&gt;&lt;span class=&quot;Apple-style-span&quot; style=&quot;font-family: &#39;Lucida Sans Unicode&#39;,&#39;Lucida Grande&#39;,&#39;Lucida Sans&#39;,Lucida,sans-serif; font-size: 15px;&quot;&gt;comment.&lt;/span&gt;&lt;/div&gt;&lt;div style=&quot;text-align: justify;&quot;&gt;&lt;span class=&quot;Apple-style-span&quot; style=&quot;font-family: &#39;Lucida Sans Unicode&#39;,&#39;Lucida Grande&#39;,&#39;Lucida Sans&#39;,Lucida,sans-serif; font-size: 15px;&quot;&gt;&lt;br /&gt;
&lt;/span&gt;&lt;/div&gt;&lt;div style=&quot;text-align: justify;&quot;&gt;&lt;span class=&quot;Apple-style-span&quot; style=&quot;font-family: &#39;Lucida Sans Unicode&#39;,&#39;Lucida Grande&#39;,&#39;Lucida Sans&#39;,Lucida,sans-serif; font-size: 15px;&quot;&gt;+ Every operator must has preceding and trailing space.&amp;nbsp;&lt;/span&gt;&lt;/div&gt;&lt;div style=&quot;text-align: justify;&quot;&gt;&lt;span class=&quot;Apple-style-span&quot; style=&quot;font-family: &#39;Lucida Sans Unicode&#39;,&#39;Lucida Grande&#39;,&#39;Lucida Sans&#39;,Lucida,sans-serif; font-size: 15px;&quot;&gt;&lt;br /&gt;
&lt;/span&gt;&lt;/div&gt;&lt;div style=&quot;text-align: justify;&quot;&gt;&lt;span class=&quot;Apple-style-span&quot; style=&quot;font-family: &#39;Lucida Sans Unicode&#39;,&#39;Lucida Grande&#39;,&#39;Lucida Sans&#39;,Lucida,sans-serif; font-size: 15px;&quot;&gt;+ Variable should not be created inside loops.&lt;/span&gt;&lt;/div&gt;&lt;div style=&quot;text-align: justify;&quot;&gt;&lt;span class=&quot;Apple-style-span&quot; style=&quot;font-family: &#39;Lucida Sans Unicode&#39;,&#39;Lucida Grande&#39;,&#39;Lucida Sans&#39;,Lucida,sans-serif; font-size: 15px;&quot;&gt;&lt;br /&gt;
&lt;/span&gt;&lt;/div&gt;&lt;div style=&quot;text-align: justify;&quot;&gt;&lt;span class=&quot;Apple-style-span&quot; style=&quot;font-family: &#39;Lucida Sans Unicode&#39;,&#39;Lucida Grande&#39;,&#39;Lucida Sans&#39;,Lucida,sans-serif; font-size: 15px;&quot;&gt;+ All &quot;=&quot; operator must be placed in same vertical line.&lt;/span&gt;&lt;/div&gt;&lt;div style=&quot;text-align: justify;&quot;&gt;&lt;span class=&quot;Apple-style-span&quot; style=&quot;font-family: &#39;Lucida Sans Unicode&#39;,&#39;Lucida Grande&#39;,&#39;Lucida Sans&#39;,Lucida,sans-serif; font-size: 15px;&quot;&gt;&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp;&lt;/span&gt;&lt;/div&gt;&lt;/div&gt;</content><link rel='replies' type='application/atom+xml' href='http://java-intellectual.blogspot.com/feeds/3799995213775979290/comments/default' title='Post Comments'/><link rel='replies' type='text/html' href='http://java-intellectual.blogspot.com/2011/10/coding-standards-and-naming-conventions.html#comment-form' title='0 Comments'/><link rel='edit' type='application/atom+xml' href='http://www.blogger.com/feeds/3771177150982125782/posts/default/3799995213775979290'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/3771177150982125782/posts/default/3799995213775979290'/><link rel='alternate' type='text/html' href='http://java-intellectual.blogspot.com/2011/10/coding-standards-and-naming-conventions.html' title='Coding Standards and Naming Conventions in Java'/><author><name>siva</name><uri>http://www.blogger.com/profile/01922721189098931789</uri><email>noreply@blogger.com</email><gd:image rel='http://schemas.google.com/g/2005#thumbnail' width='16' height='16' src='https://img1.blogblog.com/img/b16-rounded.gif'/></author><thr:total>0</thr:total></entry><entry><id>tag:blogger.com,1999:blog-3771177150982125782.post-5189375054076656491</id><published>2011-10-12T08:50:00.000-07:00</published><updated>2011-12-09T02:00:14.340-08:00</updated><category scheme="http://www.blogger.com/atom/ns#" term="java introduction"/><title type='text'>What are Java versions ?</title><content type='html'>&lt;div dir=&quot;ltr&quot; style=&quot;text-align: left;&quot; trbidi=&quot;on&quot;&gt;&lt;div style=&quot;text-align: justify;&quot;&gt;&lt;span class=&quot;Apple-style-span&quot; style=&quot;font-family: &#39;Lucida Sans Unicode&#39;, &#39;Lucida Grande&#39;, &#39;Lucida Sans&#39;, Lucida, sans-serif; font-size: 15px;&quot;&gt;A version is a number used to identify the current features and enhancements developed in that software. Every software is developed with versions. In software all projects and products are developed with versions. In most of the cases the version number starts with &#39;1.0&#39;.&lt;/span&gt;&lt;/div&gt;&lt;div style=&quot;text-align: justify;&quot;&gt;&lt;span class=&quot;Apple-style-span&quot; style=&quot;font-family: &#39;Lucida Sans Unicode&#39;, &#39;Lucida Grande&#39;, &#39;Lucida Sans&#39;, Lucida, sans-serif; font-size: 15px;&quot;&gt;Project is a software that is developed specific to one customer.Product is also a software that is developed common for all companies.The only difference we come across during the project testing and product testing is :&lt;/span&gt;&lt;/div&gt;&lt;div style=&quot;text-align: justify;&quot;&gt;&lt;span class=&quot;Apple-style-span&quot; style=&quot;font-family: &#39;Lucida Sans Unicode&#39;, &#39;Lucida Grande&#39;, &#39;Lucida Sans&#39;, Lucida, sans-serif; font-size: 15px;&quot;&gt;&lt;/span&gt;&lt;/div&gt;&lt;a name=&#39;more&#39;&gt;&lt;/a&gt;&lt;br /&gt;
&lt;div style=&quot;text-align: justify;&quot;&gt;&lt;span class=&quot;Apple-style-span&quot; style=&quot;font-family: &#39;Lucida Sans Unicode&#39;, &#39;Lucida Grande&#39;, &#39;Lucida Sans&#39;, Lucida, sans-serif; font-size: 15px;&quot;&gt;In project testing we go through the Alpha Testing, Beta Testing, User Acceptance testing whereas in product testing we&amp;nbsp;don&#39;t&amp;nbsp;have this.In Both Project and Product testing we have to perform the below test to make sure that application is properly developed WRT&amp;nbsp;&amp;nbsp;requirements&amp;nbsp;and meets the client expectation.&lt;/span&gt;&lt;/div&gt;&lt;div style=&quot;text-align: justify;&quot;&gt;&lt;span class=&quot;Apple-style-span&quot; style=&quot;font-family: &#39;Lucida Sans Unicode&#39;, &#39;Lucida Grande&#39;, &#39;Lucida Sans&#39;, Lucida, sans-serif; font-size: 15px;&quot;&gt;The test that are performed are&lt;/span&gt;&lt;/div&gt;&lt;div style=&quot;text-align: justify;&quot;&gt;&lt;span class=&quot;Apple-style-span&quot; style=&quot;font-family: &#39;Lucida Sans Unicode&#39;, &#39;Lucida Grande&#39;, &#39;Lucida Sans&#39;, Lucida, sans-serif; font-size: 15px;&quot;&gt;Unit test&lt;/span&gt;&lt;/div&gt;&lt;div style=&quot;text-align: justify;&quot;&gt;&lt;span class=&quot;Apple-style-span&quot; style=&quot;font-family: &#39;Lucida Sans Unicode&#39;, &#39;Lucida Grande&#39;, &#39;Lucida Sans&#39;, Lucida, sans-serif; font-size: 15px;&quot;&gt;Integration testing&lt;/span&gt;&lt;/div&gt;&lt;div style=&quot;text-align: justify;&quot;&gt;&lt;span class=&quot;Apple-style-span&quot; style=&quot;font-family: &#39;Lucida Sans Unicode&#39;, &#39;Lucida Grande&#39;, &#39;Lucida Sans&#39;, Lucida, sans-serif; font-size: 15px;&quot;&gt;System testing&lt;/span&gt;&lt;/div&gt;&lt;div style=&quot;text-align: justify;&quot;&gt;&lt;span class=&quot;Apple-style-span&quot; style=&quot;font-family: &#39;Lucida Sans Unicode&#39;, &#39;Lucida Grande&#39;, &#39;Lucida Sans&#39;, Lucida, sans-serif; font-size: 15px;&quot;&gt;Regression test&lt;/span&gt;&lt;/div&gt;&lt;div style=&quot;text-align: justify;&quot;&gt;&lt;span class=&quot;Apple-style-span&quot; style=&quot;font-family: &#39;Lucida Sans Unicode&#39;, &#39;Lucida Grande&#39;, &#39;Lucida Sans&#39;, Lucida, sans-serif; font-size: 15px;&quot;&gt;Retest&amp;nbsp;&lt;/span&gt;&lt;/div&gt;&lt;div style=&quot;text-align: justify;&quot;&gt;&lt;span class=&quot;Apple-style-span&quot; style=&quot;font-family: &#39;Lucida Sans Unicode&#39;, &#39;Lucida Grande&#39;, &#39;Lucida Sans&#39;, Lucida, sans-serif; font-size: 15px;&quot;&gt;&lt;br /&gt;
&lt;/span&gt;&lt;/div&gt;&lt;div style=&quot;text-align: justify;&quot;&gt;&lt;span class=&quot;Apple-style-span&quot; style=&quot;font-family: &#39;Lucida Sans Unicode&#39;, &#39;Lucida Grande&#39;, &#39;Lucida Sans&#39;, Lucida, sans-serif; font-size: 15px;&quot;&gt;Below are sample products with&amp;nbsp;their&amp;nbsp;version numbers.&lt;/span&gt;&lt;/div&gt;&lt;div class=&quot;separator&quot; style=&quot;clear: both; text-align: center;&quot;&gt;&lt;a href=&quot;https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEhM2DA8i0iogv0YqWgoHzqdpz28cRa2ErkIX2yJnEJcXd_ablhScKFawNjAVMoLYoiVWNGKBAVRdzzn7YljcFLhp-Z0LzhFDJwLHFvL77coKeFgZ2cicd1S422kOhtEC1CqPL5qjl6vEuE/s1600/Untitled.png&quot; imageanchor=&quot;1&quot; style=&quot;clear: left; float: left; margin-bottom: 1em; margin-right: 1em;&quot;&gt;&lt;img border=&quot;0&quot; height=&quot;320&quot; src=&quot;https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEhM2DA8i0iogv0YqWgoHzqdpz28cRa2ErkIX2yJnEJcXd_ablhScKFawNjAVMoLYoiVWNGKBAVRdzzn7YljcFLhp-Z0LzhFDJwLHFvL77coKeFgZ2cicd1S422kOhtEC1CqPL5qjl6vEuE/s640/Untitled.png&quot; width=&quot;640&quot; /&gt;&lt;/a&gt;&lt;a href=&quot;https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEhM2DA8i0iogv0YqWgoHzqdpz28cRa2ErkIX2yJnEJcXd_ablhScKFawNjAVMoLYoiVWNGKBAVRdzzn7YljcFLhp-Z0LzhFDJwLHFvL77coKeFgZ2cicd1S422kOhtEC1CqPL5qjl6vEuE/s1600/Untitled.png&quot; imageanchor=&quot;1&quot; style=&quot;clear: left; float: left; margin-bottom: 1em; margin-right: 1em;&quot;&gt;&lt;span class=&quot;Apple-style-span&quot; style=&quot;color: black;&quot;&gt;&lt;br /&gt;
&lt;/span&gt;&lt;/a&gt;&lt;a href=&quot;https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEhM2DA8i0iogv0YqWgoHzqdpz28cRa2ErkIX2yJnEJcXd_ablhScKFawNjAVMoLYoiVWNGKBAVRdzzn7YljcFLhp-Z0LzhFDJwLHFvL77coKeFgZ2cicd1S422kOhtEC1CqPL5qjl6vEuE/s1600/Untitled.png&quot; imageanchor=&quot;1&quot; style=&quot;clear: left; float: left; margin-bottom: 1em; margin-right: 1em;&quot;&gt;&lt;span class=&quot;Apple-style-span&quot; style=&quot;color: black;&quot;&gt;&lt;br /&gt;
&lt;/span&gt;&lt;/a&gt;&lt;/div&gt;&lt;div style=&quot;text-align: justify;&quot;&gt;&lt;span class=&quot;Apple-style-span&quot; style=&quot;font-family: &#39;Lucida Sans Unicode&#39;, &#39;Lucida Grande&#39;, &#39;Lucida Sans&#39;, Lucida, sans-serif; font-size: 15px;&quot;&gt;Comment for any doubts....... &lt;/span&gt;&lt;/div&gt;&lt;/div&gt;</content><link rel='replies' type='application/atom+xml' href='http://java-intellectual.blogspot.com/feeds/5189375054076656491/comments/default' title='Post Comments'/><link rel='replies' type='text/html' href='http://java-intellectual.blogspot.com/2011/10/what-are-java-versions.html#comment-form' title='0 Comments'/><link rel='edit' type='application/atom+xml' href='http://www.blogger.com/feeds/3771177150982125782/posts/default/5189375054076656491'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/3771177150982125782/posts/default/5189375054076656491'/><link rel='alternate' type='text/html' href='http://java-intellectual.blogspot.com/2011/10/what-are-java-versions.html' title='What are Java versions ?'/><author><name>siva</name><uri>http://www.blogger.com/profile/01922721189098931789</uri><email>noreply@blogger.com</email><gd:image rel='http://schemas.google.com/g/2005#thumbnail' width='16' height='16' src='https://img1.blogblog.com/img/b16-rounded.gif'/></author><media:thumbnail xmlns:media="http://search.yahoo.com/mrss/" url="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEhM2DA8i0iogv0YqWgoHzqdpz28cRa2ErkIX2yJnEJcXd_ablhScKFawNjAVMoLYoiVWNGKBAVRdzzn7YljcFLhp-Z0LzhFDJwLHFvL77coKeFgZ2cicd1S422kOhtEC1CqPL5qjl6vEuE/s72-c/Untitled.png" height="72" width="72"/><thr:total>0</thr:total></entry><entry><id>tag:blogger.com,1999:blog-3771177150982125782.post-7990184517203082201</id><published>2011-10-12T04:06:00.000-07:00</published><updated>2011-12-09T02:01:06.201-08:00</updated><category scheme="http://www.blogger.com/atom/ns#" term="java introduction"/><title type='text'>Types of Java Software</title><content type='html'>&lt;div dir=&quot;ltr&quot; style=&quot;text-align: left;&quot; trbidi=&quot;on&quot;&gt;&lt;div style=&quot;text-align: justify;&quot;&gt;&lt;span class=&quot;Apple-style-span&quot; style=&quot;font-family: &#39;Lucida Sans Unicode&#39;,&#39;Lucida Grande&#39;,&#39;Lucida Sans&#39;,Lucida,sans-serif; font-size: 15px;&quot;&gt;Java software is divided into two sub products&lt;/span&gt;&lt;/div&gt;&lt;div style=&quot;text-align: justify;&quot;&gt;&lt;span class=&quot;Apple-style-span&quot; style=&quot;font-family: &#39;Lucida Sans Unicode&#39;,&#39;Lucida Grande&#39;,&#39;Lucida Sans&#39;,Lucida,sans-serif; font-size: 15px;&quot;&gt;&lt;br /&gt;
&lt;/span&gt;&lt;/div&gt;&lt;div style=&quot;text-align: justify;&quot;&gt;&lt;span class=&quot;Apple-style-span&quot; style=&quot;font-family: &#39;Lucida Sans Unicode&#39;,&#39;Lucida Grande&#39;,&#39;Lucida Sans&#39;,Lucida,sans-serif; font-size: 15px;&quot;&gt;1) jdk (Java Development Kit)&lt;/span&gt;&lt;/div&gt;&lt;div style=&quot;text-align: justify;&quot;&gt;&lt;span class=&quot;Apple-style-span&quot; style=&quot;font-family: &#39;Lucida Sans Unicode&#39;,&#39;Lucida Grande&#39;,&#39;Lucida Sans&#39;,Lucida,sans-serif; font-size: 15px;&quot;&gt;2) jre (Java&amp;nbsp;Run time&amp;nbsp;Environment)&lt;/span&gt;&lt;/div&gt;&lt;div style=&quot;text-align: justify;&quot;&gt;&lt;span class=&quot;Apple-style-span&quot; style=&quot;font-family: &#39;Lucida Sans Unicode&#39;,&#39;Lucida Grande&#39;,&#39;Lucida Sans&#39;,Lucida,sans-serif; font-size: 15px;&quot;&gt;&lt;br /&gt;
&lt;/span&gt;&lt;/div&gt;&lt;div style=&quot;text-align: justify;&quot;&gt;&lt;span class=&quot;Apple-style-span&quot; style=&quot;font-family: &#39;Lucida Sans Unicode&#39;,&#39;Lucida Grande&#39;,&#39;Lucida Sans&#39;,Lucida,sans-serif; font-size: 15px;&quot;&gt;jdk has both &quot;Compiler + JVM&quot;&lt;/span&gt;&lt;/div&gt;&lt;div style=&quot;text-align: justify;&quot;&gt;&lt;span class=&quot;Apple-style-span&quot; style=&quot;font-family: &#39;Lucida Sans Unicode&#39;,&#39;Lucida Grande&#39;,&#39;Lucida Sans&#39;,Lucida,sans-serif; font-size: 15px;&quot;&gt;jre has only &quot;JVM&quot;&amp;nbsp;&lt;/span&gt;&lt;/div&gt;&lt;div style=&quot;text-align: justify;&quot;&gt;&lt;span class=&quot;Apple-style-span&quot; style=&quot;font-family: &#39;Lucida Sans Unicode&#39;,&#39;Lucida Grande&#39;,&#39;Lucida Sans&#39;,Lucida,sans-serif; font-size: 15px;&quot;&gt;JVM is a&amp;nbsp;sub-part&amp;nbsp;of jre and jre is a&amp;nbsp;sub-part of jdk. So in order to run any java application jre software is sufficient but if we need to compile and execute the java program we have to install jdk software.Below diagram shows the difference between jdk,jre and JVM.&lt;/span&gt;&lt;/div&gt;&lt;div style=&quot;text-align: justify;&quot;&gt;&lt;span class=&quot;Apple-style-span&quot; style=&quot;font-family: &#39;Lucida Sans Unicode&#39;,&#39;Lucida Grande&#39;,&#39;Lucida Sans&#39;,Lucida,sans-serif; font-size: 15px;&quot;&gt;&lt;/span&gt;&lt;/div&gt;&lt;a name=&#39;more&#39;&gt;&lt;/a&gt;&lt;br /&gt;
&lt;div class=&quot;separator&quot; style=&quot;clear: both; text-align: center;&quot;&gt;&lt;a href=&quot;https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEgBREAG07OnqvubAhONTR0FUi0t548cNJXkukgrEKPGSxLFyIeKs6uynYWmFmblyOIBRyqv_zOVgos204_iUIbyQ4PLfQmIDUX-logibZGp7ZcMlTY-Ia51EXa13chyphenhyphenhyphenhyphen0vuetTtq5PbHg/s1600/Untitled.png&quot; imageanchor=&quot;1&quot; style=&quot;margin-left: 1em; margin-right: 1em;&quot;&gt;&lt;img border=&quot;0&quot; height=&quot;248&quot; src=&quot;https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEgBREAG07OnqvubAhONTR0FUi0t548cNJXkukgrEKPGSxLFyIeKs6uynYWmFmblyOIBRyqv_zOVgos204_iUIbyQ4PLfQmIDUX-logibZGp7ZcMlTY-Ia51EXa13chyphenhyphenhyphenhyphen0vuetTtq5PbHg/s400/Untitled.png&quot; width=&quot;400&quot; /&gt;&lt;/a&gt;&lt;/div&gt;&lt;div style=&quot;text-align: justify;&quot;&gt;&lt;span class=&quot;Apple-style-span&quot; style=&quot;font-family: &#39;Lucida Sans Unicode&#39;,&#39;Lucida Grande&#39;,&#39;Lucida Sans&#39;,Lucida,sans-serif; font-size: 15px;&quot;&gt;&lt;br /&gt;
&lt;/span&gt;&lt;/div&gt;&lt;div style=&quot;text-align: justify;&quot;&gt;&lt;br /&gt;
&lt;/div&gt;&lt;/div&gt;</content><link rel='replies' type='application/atom+xml' href='http://java-intellectual.blogspot.com/feeds/7990184517203082201/comments/default' title='Post Comments'/><link rel='replies' type='text/html' href='http://java-intellectual.blogspot.com/2011/10/types-of-java-software.html#comment-form' title='0 Comments'/><link rel='edit' type='application/atom+xml' href='http://www.blogger.com/feeds/3771177150982125782/posts/default/7990184517203082201'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/3771177150982125782/posts/default/7990184517203082201'/><link rel='alternate' type='text/html' href='http://java-intellectual.blogspot.com/2011/10/types-of-java-software.html' title='Types of Java Software'/><author><name>siva</name><uri>http://www.blogger.com/profile/01922721189098931789</uri><email>noreply@blogger.com</email><gd:image rel='http://schemas.google.com/g/2005#thumbnail' width='16' height='16' src='https://img1.blogblog.com/img/b16-rounded.gif'/></author><media:thumbnail xmlns:media="http://search.yahoo.com/mrss/" url="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEgBREAG07OnqvubAhONTR0FUi0t548cNJXkukgrEKPGSxLFyIeKs6uynYWmFmblyOIBRyqv_zOVgos204_iUIbyQ4PLfQmIDUX-logibZGp7ZcMlTY-Ia51EXa13chyphenhyphenhyphenhyphen0vuetTtq5PbHg/s72-c/Untitled.png" height="72" width="72"/><thr:total>0</thr:total></entry><entry><id>tag:blogger.com,1999:blog-3771177150982125782.post-7961841133446435687</id><published>2011-10-11T09:47:00.000-07:00</published><updated>2011-12-09T02:02:17.732-08:00</updated><category scheme="http://www.blogger.com/atom/ns#" term="java introduction"/><title type='text'>How Java achieved Platform Independency ?</title><content type='html'>&lt;div dir=&quot;ltr&quot; style=&quot;text-align: left;&quot; trbidi=&quot;on&quot;&gt;&lt;div style=&quot;text-align: justify;&quot;&gt;&lt;span class=&quot;Apple-style-span&quot; style=&quot;font-family: &#39;Lucida Sans Unicode&#39;, &#39;Lucida Grande&#39;, &#39;Lucida Sans&#39;, Lucida, sans-serif; font-size: 15px;&quot;&gt;Java achieved platform&amp;nbsp;independency&amp;nbsp;by moving machine language generation from compilation phase to execution phase by introducing&amp;nbsp;byte codes&amp;nbsp;and JVM. To support platform&amp;nbsp;independency&amp;nbsp;the program must execute in another operating system means that program must has machine language specific to the client computer OS. The client computer OS is only come to know only when program is downloaded and is being executed. So SUN moved machine language generation to execution phase.Below diagram shows Java&#39;s platform independency&amp;nbsp;diagram.&lt;/span&gt;&lt;/div&gt;&lt;div style=&quot;text-align: justify;&quot;&gt;&lt;span class=&quot;Apple-style-span&quot; style=&quot;font-family: &#39;Lucida Sans Unicode&#39;, &#39;Lucida Grande&#39;, &#39;Lucida Sans&#39;, Lucida, sans-serif; font-size: 15px;&quot;&gt;&lt;br /&gt;
&lt;/span&gt;&lt;/div&gt;&lt;a name=&#39;more&#39;&gt;&lt;/a&gt;&lt;div style=&quot;text-align: justify;&quot;&gt;&lt;span class=&quot;Apple-style-span&quot; style=&quot;font-family: &#39;Lucida Sans Unicode&#39;, &#39;Lucida Grande&#39;, &#39;Lucida Sans&#39;, Lucida, sans-serif; font-size: 15px;&quot;&gt;&lt;br /&gt;
&lt;/span&gt;&lt;/div&gt;&lt;div class=&quot;separator&quot; style=&quot;clear: both; text-align: center;&quot;&gt;&lt;a href=&quot;https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEi81qDzv8SMXtwIB3dQiONsR9K9BETdJsC_xTfM4E73B4fmGDQo1U47HsXmPVbalyAYCxCjqaVEEp9WtvoIlNWU8AlZJXcxbb0YgyGTPfV5kLEtUt23S9ikDFQZWKaY_ljeLm9f0o1sDgk/s1600/Untitled+%25281%2529.png&quot; imageanchor=&quot;1&quot; style=&quot;margin-left: 1em; margin-right: 1em;&quot;&gt;&lt;img border=&quot;0&quot; height=&quot;324&quot; src=&quot;https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEi81qDzv8SMXtwIB3dQiONsR9K9BETdJsC_xTfM4E73B4fmGDQo1U47HsXmPVbalyAYCxCjqaVEEp9WtvoIlNWU8AlZJXcxbb0YgyGTPfV5kLEtUt23S9ikDFQZWKaY_ljeLm9f0o1sDgk/s640/Untitled+%25281%2529.png&quot; width=&quot;640&quot; /&gt;&lt;/a&gt;&lt;/div&gt;&lt;div class=&quot;separator&quot; style=&quot;clear: both; text-align: center;&quot;&gt;&lt;span class=&quot;Apple-style-span&quot; style=&quot;font-family: &#39;Lucida Sans Unicode&#39;, &#39;Lucida Grande&#39;, &#39;Lucida Sans&#39;, Lucida, sans-serif; font-size: 15px;&quot;&gt;&lt;br /&gt;
&lt;/span&gt;&lt;/div&gt;&lt;div style=&quot;text-align: justify;&quot;&gt;&lt;span class=&quot;Apple-style-span&quot; style=&quot;font-family: &#39;Lucida Sans Unicode&#39;, &#39;Lucida Grande&#39;, &#39;Lucida Sans&#39;, Lucida, sans-serif; font-size: 15px;&quot;&gt;Below is the another&amp;nbsp;block&amp;nbsp;diagram shows Java&#39;s platform independency.&lt;/span&gt;&lt;/div&gt;&lt;div style=&quot;text-align: justify;&quot;&gt;&lt;span class=&quot;Apple-style-span&quot; style=&quot;font-family: &#39;Lucida Sans Unicode&#39;, &#39;Lucida Grande&#39;, &#39;Lucida Sans&#39;, Lucida, sans-serif; font-size: 15px;&quot;&gt;&lt;br /&gt;
&lt;/span&gt;&lt;/div&gt;&lt;div class=&quot;separator&quot; style=&quot;clear: both; text-align: center;&quot;&gt;&lt;span class=&quot;Apple-style-span&quot; style=&quot;font-family: &#39;Lucida Sans Unicode&#39;, &#39;Lucida Grande&#39;, &#39;Lucida Sans&#39;, Lucida, sans-serif; font-size: 15px;&quot;&gt;&lt;br /&gt;
&lt;/span&gt;&lt;/div&gt;&lt;div style=&quot;text-align: justify;&quot;&gt;&lt;div class=&quot;separator&quot; style=&quot;clear: both; text-align: left;&quot;&gt;&lt;a href=&quot;https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEg6qWWjJgyWRyV_Zzjhz1KfPHofhg9X4rpeCb7IM3bo61J6OD7vPAzCAesE-gHo4jv12owAGa6As9muxpN9SOuB-Vq5mkqT6en6J7V8ZfQT4KVzP2rVY5pfPP5RmiyF2oIHWuWiyyQjloU/s1600/Untitled.png&quot; imageanchor=&quot;1&quot; style=&quot;margin-left: 1em; margin-right: 1em;&quot;&gt;&lt;img border=&quot;0&quot; height=&quot;420&quot; src=&quot;https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEg6qWWjJgyWRyV_Zzjhz1KfPHofhg9X4rpeCb7IM3bo61J6OD7vPAzCAesE-gHo4jv12owAGa6As9muxpN9SOuB-Vq5mkqT6en6J7V8ZfQT4KVzP2rVY5pfPP5RmiyF2oIHWuWiyyQjloU/s640/Untitled.png&quot; width=&quot;750&quot; /&gt;&lt;/a&gt;&lt;/div&gt;&lt;span class=&quot;Apple-style-span&quot; style=&quot;font-family: &#39;Lucida Sans Unicode&#39;, &#39;Lucida Grande&#39;, &#39;Lucida Sans&#39;, Lucida, sans-serif; font-size: 15px;&quot;&gt;&lt;br /&gt;
&lt;/span&gt;&lt;/div&gt;&lt;div style=&quot;text-align: justify;&quot;&gt;&lt;span class=&quot;Apple-style-span&quot; style=&quot;font-family: &#39;Lucida Sans Unicode&#39;, &#39;Lucida Grande&#39;, &#39;Lucida Sans&#39;, Lucida, sans-serif; font-size: 15px;&quot;&gt;From the above diagram we can conclude below points&lt;/span&gt;&lt;/div&gt;&lt;div style=&quot;text-align: justify;&quot;&gt;&lt;span class=&quot;Apple-style-span&quot; style=&quot;font-family: &#39;Lucida Sans Unicode&#39;, &#39;Lucida Grande&#39;, &#39;Lucida Sans&#39;, Lucida, sans-serif; font-size: 15px;&quot;&gt;1) In Java, compiler is Java specific not OS specific as it takes Java source code as input and generates Java&amp;nbsp;byte codes&amp;nbsp;as output.&lt;/span&gt;&lt;/div&gt;&lt;div style=&quot;text-align: justify;&quot;&gt;&lt;span class=&quot;Apple-style-span&quot; style=&quot;font-family: &#39;Lucida Sans Unicode&#39;, &#39;Lucida Grande&#39;, &#39;Lucida Sans&#39;, Lucida, sans-serif; font-size: 15px;&quot;&gt;2) But JVM is OS specific because it takes Java bytecodes and generates OS dependent Machine language.&lt;/span&gt;&lt;/div&gt;&lt;div style=&quot;text-align: justify;&quot;&gt;&lt;span class=&quot;Apple-style-span&quot; style=&quot;font-family: &#39;Lucida Sans Unicode&#39;, &#39;Lucida Grande&#39;, &#39;Lucida Sans&#39;, Lucida, sans-serif; font-size: 15px;&quot;&gt;3) Since JVM is OS dependent,Java software is also OS dependent because Java software means compiler + JVM.&lt;/span&gt;&lt;/div&gt;&lt;div style=&quot;text-align: justify;&quot;&gt;&lt;span class=&quot;Apple-style-span&quot; style=&quot;font-family: &#39;Lucida Sans Unicode&#39;, &#39;Lucida Grande&#39;, &#39;Lucida Sans&#39;, Lucida, sans-serif; font-size: 15px;&quot;&gt;4) But Java program is platform independent. Both because of JVM implementation&lt;/span&gt;&lt;br /&gt;
&lt;span class=&quot;Apple-style-span&quot; style=&quot;background-color: white; font-family: &#39;Lucida Sans Unicode&#39;, &#39;Lucida Grande&#39;, &#39;Lucida Sans&#39;, Lucida, sans-serif; font-size: 15px;&quot;&gt;&lt;br /&gt;
&lt;/span&gt;&lt;br /&gt;
&lt;span class=&quot;Apple-style-span&quot; style=&quot;background-color: white; font-family: &#39;Lucida Sans Unicode&#39;, &#39;Lucida Grande&#39;, &#39;Lucida Sans&#39;, Lucida, sans-serif; font-size: 15px;&quot;&gt;C&lt;/span&gt;&lt;span class=&quot;Apple-style-span&quot; style=&quot;background-color: white; font-family: &#39;Lucida Sans Unicode&#39;, &#39;Lucida Grande&#39;, &#39;Lucida Sans&#39;, Lucida, sans-serif; font-size: 15px;&quot;&gt;omment for any doubts.....&lt;/span&gt;&lt;br /&gt;
&lt;span class=&quot;Apple-style-span&quot; style=&quot;background-color: white; font-family: &#39;Lucida Sans Unicode&#39;, &#39;Lucida Grande&#39;, &#39;Lucida Sans&#39;, Lucida, sans-serif; font-size: 15px;&quot;&gt;&lt;br /&gt;
&lt;/span&gt;&lt;/div&gt;&lt;/div&gt;</content><link rel='replies' type='application/atom+xml' href='http://java-intellectual.blogspot.com/feeds/7961841133446435687/comments/default' title='Post Comments'/><link rel='replies' type='text/html' href='http://java-intellectual.blogspot.com/2011/10/how-java-achieved-platform-independency.html#comment-form' title='0 Comments'/><link rel='edit' type='application/atom+xml' href='http://www.blogger.com/feeds/3771177150982125782/posts/default/7961841133446435687'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/3771177150982125782/posts/default/7961841133446435687'/><link rel='alternate' type='text/html' href='http://java-intellectual.blogspot.com/2011/10/how-java-achieved-platform-independency.html' title='How Java achieved Platform Independency ?'/><author><name>siva</name><uri>http://www.blogger.com/profile/01922721189098931789</uri><email>noreply@blogger.com</email><gd:image rel='http://schemas.google.com/g/2005#thumbnail' width='16' height='16' src='https://img1.blogblog.com/img/b16-rounded.gif'/></author><media:thumbnail xmlns:media="http://search.yahoo.com/mrss/" url="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEi81qDzv8SMXtwIB3dQiONsR9K9BETdJsC_xTfM4E73B4fmGDQo1U47HsXmPVbalyAYCxCjqaVEEp9WtvoIlNWU8AlZJXcxbb0YgyGTPfV5kLEtUt23S9ikDFQZWKaY_ljeLm9f0o1sDgk/s72-c/Untitled+%25281%2529.png" height="72" width="72"/><thr:total>0</thr:total></entry><entry><id>tag:blogger.com,1999:blog-3771177150982125782.post-3119877977269725608</id><published>2011-10-11T07:56:00.001-07:00</published><updated>2011-12-09T02:02:49.527-08:00</updated><category scheme="http://www.blogger.com/atom/ns#" term="interview-questions"/><title type='text'>What is Java Slogan ?</title><content type='html'>&lt;div dir=&quot;ltr&quot; style=&quot;text-align: left;&quot; trbidi=&quot;on&quot;&gt;&lt;div style=&quot;text-align: justify;&quot;&gt;&lt;span class=&quot;Apple-style-span&quot; style=&quot;font-family: &#39;Lucida Sans Unicode&#39;, &#39;Lucida Grande&#39;, &#39;Lucida Sans&#39;, Lucida, sans-serif; font-size: 15px;&quot;&gt;&quot;Write once Run anywhere&quot;&lt;/span&gt;&lt;/div&gt;&lt;div style=&quot;text-align: justify;&quot;&gt;&lt;span class=&quot;Apple-style-span&quot; style=&quot;font-family: &#39;Lucida Sans Unicode&#39;, &#39;Lucida Grande&#39;, &#39;Lucida Sans&#39;, Lucida, sans-serif; font-size: 15px;&quot;&gt;&lt;br /&gt;
&lt;/span&gt;&lt;/div&gt;&lt;div style=&quot;text-align: justify;&quot;&gt;&lt;span class=&quot;Apple-style-span&quot; style=&quot;font-family: &#39;Lucida Sans Unicode&#39;, &#39;Lucida Grande&#39;, &#39;Lucida Sans&#39;, Lucida, sans-serif; font-size: 15px;&quot;&gt;Java is a platform independent programming language.&lt;/span&gt;&lt;span class=&quot;Apple-style-span&quot; style=&quot;font-family: &#39;Lucida Sans Unicode&#39;, &#39;Lucida Grande&#39;, &#39;Lucida Sans&#39;, Lucida, sans-serif; font-size: 15px;&quot;&gt;It means that program is written once and the program is executed irrespective of the operating system.&lt;/span&gt;&lt;/div&gt;&lt;div style=&quot;text-align: justify;&quot;&gt;&lt;span class=&quot;Apple-style-span&quot; style=&quot;font-family: &#39;Lucida Sans Unicode&#39;, &#39;Lucida Grande&#39;, &#39;Lucida Sans&#39;, Lucida, sans-serif; font-size: 15px;&quot;&gt;&lt;/span&gt;&lt;/div&gt;&lt;a name=&#39;more&#39;&gt;&lt;/a&gt;&lt;br /&gt;
&lt;div style=&quot;text-align: justify;&quot;&gt;&lt;span class=&quot;Apple-style-span&quot; style=&quot;font-family: &#39;Lucida Sans Unicode&#39;, &#39;Lucida Grande&#39;, &#39;Lucida Sans&#39;, Lucida, sans-serif; font-size: 15px;&quot;&gt;&lt;span class=&quot;Apple-style-span&quot; style=&quot;background-color: white;&quot;&gt;Comment for any doubts.....&lt;/span&gt;&lt;/span&gt;&lt;br /&gt;
&lt;span class=&quot;Apple-style-span&quot; style=&quot;font-family: &#39;Lucida Sans Unicode&#39;, &#39;Lucida Grande&#39;, &#39;Lucida Sans&#39;, Lucida, sans-serif;&quot;&gt;&lt;span class=&quot;Apple-style-span&quot; style=&quot;font-size: 15px;&quot;&gt;&lt;br /&gt;
&lt;/span&gt;&lt;/span&gt;&lt;/div&gt;&lt;/div&gt;</content><link rel='replies' type='application/atom+xml' href='http://java-intellectual.blogspot.com/feeds/3119877977269725608/comments/default' title='Post Comments'/><link rel='replies' type='text/html' href='http://java-intellectual.blogspot.com/2011/10/what-is-java-slogan.html#comment-form' title='0 Comments'/><link rel='edit' type='application/atom+xml' href='http://www.blogger.com/feeds/3771177150982125782/posts/default/3119877977269725608'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/3771177150982125782/posts/default/3119877977269725608'/><link rel='alternate' type='text/html' href='http://java-intellectual.blogspot.com/2011/10/what-is-java-slogan.html' title='What is Java Slogan ?'/><author><name>siva</name><uri>http://www.blogger.com/profile/01922721189098931789</uri><email>noreply@blogger.com</email><gd:image rel='http://schemas.google.com/g/2005#thumbnail' width='16' height='16' src='https://img1.blogblog.com/img/b16-rounded.gif'/></author><thr:total>0</thr:total></entry></feed>