<?xml version="1.0" encoding="UTF-8"?>
<?xml-stylesheet type="text/xsl" media="screen" href="/~d/styles/rss2enclosuresfull.xsl"?><?xml-stylesheet type="text/css" media="screen" href="http://feeds.feedburner.com/~d/styles/itemcontent.css"?><rss xmlns:atom="http://www.w3.org/2005/Atom" xmlns:openSearch="http://a9.com/-/spec/opensearch/1.1/" 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" xmlns:media="http://search.yahoo.com/mrss/" xmlns:itunes="http://www.itunes.com/dtds/podcast-1.0.dtd" xmlns:creativeCommons="http://backend.userland.com/creativeCommonsRssModule" xmlns:feedburner="http://rssnamespace.org/feedburner/ext/1.0" version="2.0"><channel><atom:id>tag:blogger.com,1999:blog-2981436578666077634</atom:id><lastBuildDate>Tue, 18 Jun 2013 20:31:25 +0000</lastBuildDate><category>Google App</category><category>Fedora</category><category>ParseInt</category><category>Rational Robot</category><category>Lumia</category><category>Hybrid Framework</category><category>Google Book</category><category>SOAPUI</category><category>jobs in SAP</category><category>Apple</category><category>Live Messanger</category><category>war</category><category>JDeveloper</category><category>SAP</category><category>Modular Framework</category><category>Windows Script Host (WSH)</category><category>Reddit</category><category>Camera</category><category>HAS-A relationship</category><category>QTP Related</category><category>Idea of Framework</category><category>Linked In</category><category>Zen Mobile</category><category>Keyword Driven Framework</category><category>Assertion</category><category>Jobs in Data Engineer</category><category>java</category><category>Ring The bell</category><category>Photography</category><category>MySpace</category><category>Jobs for Freshers</category><category>Reader's Desk</category><category>Assert</category><category>About Ask QTP</category><category>SmartPhone</category><category>Vizio</category><category>jobs in java</category><category>iPhone</category><category>Operators</category><category>Quality Related Concept</category><category>Values from enum</category><category>System Configuration</category><category>local variable</category><category>Intel</category><category>QTP Interview Question</category><category>Datahiding</category><category>Microsoft</category><category>Enumeration</category><category>Google Watch</category><category>Arithmetic Operator</category><category>Enum and Enumeration</category><category>Exam Help on ISTQB-Basic</category><category>Web Testing</category><category>Dual Sim</category><category>Leading conferences</category><category>Great Books to Read</category><category>Oracle</category><category>SOA</category><category>Database Concept</category><category>Phablet</category><category>Constructor</category><category>jobs in other domain</category><category>Wikipedia</category><category>Blackberry</category><category>Software Update</category><category>Difference between enum</category><category>infinity</category><category>G+</category><category>JSON</category><category>Facebook</category><category>Inheritance</category><category>Cloud</category><category>Test Automation Advanced Concept</category><category>Box</category><category>Existing Tools</category><category>QNX</category><category>Certification</category><category>Leading Contests</category><category>System Properties</category><category>enum concept</category><category>Intel Processor</category><category>Inserting Transaction Points</category><category>Type casting</category><category>Zynga</category><category>Live chat Live help</category><category>Testing Related</category><category>Cyclic Inheritance</category><category>Google</category><category>Classpath</category><category>HR Interview</category><category>ADF</category><category>Indiblogger</category><category>eMusic</category><category>Record Playback Framework</category><category>Multiple Inheritance</category><category>This blog is under outage</category><category>Lumapad</category><category>Data Driven Framework</category><category>Linux</category><category>Jobs in Quality</category><category>Samsung</category><category>hot</category><category>VB Scripting</category><category>Zip file</category><category>Encapsulation</category><category>About Me:Animesh Chatterjee</category><category>JSF Tutorials</category><category>path</category><category>OCJP</category><category>JSP</category><category>SmartWatch</category><category>Game</category><category>C</category><category>jobs in dot net</category><category>Quick Mathematics</category><category>Practise Test in Quick Test Professional</category><category>Management Tools</category><category>jar</category><category>Exam Help on QTP</category><category>Your Voice</category><category>Travel</category><category>Be Carefull when you invest money on a training institute</category><category>iWatch</category><category>Jobs In Testing</category><category>servlet</category><category>Happy New Year-2010</category><category>Abstract method</category><category>Jobs in BPO</category><category>HTC</category><category>MySQL</category><category>Switch case</category><category>Management Concept</category><category>Sony</category><category>BPT Framework</category><category>Nokia</category><category>Web Services</category><category>Gmail</category><category>jobs for C Developers</category><category>MariaDB</category><category>ear</category><category>HAS-A</category><category>Settings of Classpath</category><category>TSL</category><category>jobs for C++ Developers</category><category>Persistent Properties</category><category>Google Script</category><category>Lenovo</category><category>Bugzilla</category><category>Oracle Open Script Related(OATS)</category><category>Hacking-Tips And Tricks</category><category>JavaScript</category><category>Interview Preparation</category><category>Contact Details</category><category>Chromebook</category><category>Wireless</category><category>Exam Help on ComTIA</category><category>Twitter</category><category>Friends</category><category>IS-A Relationship</category><category>Precondition checks</category><category>Security</category><category>Ajax</category><category>Instance variable</category><category>WSDL</category><category>SmartTV</category><category>Micromax</category><category>Mozilla</category><category>Cloud App</category><category>Memory Allocation in Java</category><category>LG</category><category>New Tools</category><category>Animation Industry</category><category>Android</category><category>Operating System</category><category>HTML5</category><category>Runtime Exception in java</category><category>Tech News</category><category>Practice of Code</category><category>enum</category><category>General QA Concept</category><category>Internet</category><category>Advanced QA Concept</category><category>Arithmetic exception in java</category><category>jobs in Management</category><category>Music</category><category>Test Automation General Concept</category><category>YouTube</category><category>Quality Tools</category><category>SOAP</category><category>Selenium Tutorial</category><category>Jobs In Informatica</category><category>Java Zip File</category><category>Torrent</category><category>Notebook</category><category>Lifestyle</category><category>Excel Macro</category><category>Shell Scripting</category><category>Quality Center</category><category>Uncategorized</category><category>Tablet</category><category>Testing Glossary</category><title>Ask QTP</title><description>A Techno Managerial Weblog</description><link>http://www.askqtp.com/</link><managingEditor>noreply@blogger.com (Animesh Chatterjee)</managingEditor><generator>Blogger</generator><openSearch:totalResults>1501</openSearch:totalResults><openSearch:startIndex>1</openSearch:startIndex><openSearch:itemsPerPage>25</openSearch:itemsPerPage><atom10:link xmlns:atom10="http://www.w3.org/2005/Atom" rel="self" type="application/rss+xml" href="http://feeds.feedburner.com/blogspot/TerSJ" /><feedburner:info uri="blogspot/tersj" /><atom10:link xmlns:atom10="http://www.w3.org/2005/Atom" rel="hub" href="http://pubsubhubbub.appspot.com/" /><media:copyright>@Animesh-Ask QTP</media:copyright><media:keywords>HP,QTP,Manual,Testing,Automation,Testing,QC</media:keywords><media:category scheme="http://www.itunes.com/dtds/podcast-1.0.dtd">Technology/Gadgets</media:category><itunes:owner><itunes:email>ani01104@gmail.com</itunes:email><itunes:name>Madhumita</itunes:name></itunes:owner><itunes:author>Madhumita</itunes:author><itunes:explicit>no</itunes:explicit><itunes:keywords>HP,QTP,Manual,Testing,Automation,Testing,QC</itunes:keywords><itunes:subtitle>Ask QTP</itunes:subtitle><itunes:summary>Objective of this blog to help in real time test engineers by providing code which i have gathered or prepared.This blog is noway a discussion blog rather i would say this is a global repository</itunes:summary><itunes:category text="Technology"><itunes:category text="Gadgets" /></itunes:category><creativeCommons:license>http://creativecommons.org/licenses/by-sa/2.0/</creativeCommons:license><image><link>http://creativecommons.org/licenses/by-sa/2.0/</link><url>http://creativecommons.org/images/public/somerights20.gif</url><title>Some Rights Reserved</title></image><xhtml:meta xmlns:xhtml="http://www.w3.org/1999/xhtml" name="robots" content="noindex" /><meta xmlns="http://pipes.yahoo.com" name="pipes" content="noprocess" /><feedburner:emailServiceId>blogspot/TerSJ</feedburner:emailServiceId><feedburner:feedburnerHostname>http://feedburner.google.com</feedburner:feedburnerHostname><item><guid isPermaLink="false">tag:blogger.com,1999:blog-2981436578666077634.post-5328664260486560011</guid><pubDate>Sat, 15 Jun 2013 16:29:00 +0000</pubDate><atom:updated>2013-06-15T22:01:28.860+05:30</atom:updated><category domain="http://www.blogger.com/atom/ns#">Constructor</category><category domain="http://www.blogger.com/atom/ns#">java</category><category domain="http://www.blogger.com/atom/ns#">Memory Allocation in Java</category><title>How Memory Allocation Happens in Java?</title><description>&lt;div dir="ltr" style="text-align: left;" trbidi="on"&gt;&lt;div dir="ltr" style="text-align: left;" trbidi="on"&gt;&lt;div class="separator" style="clear: both; text-align: center;"&gt;&lt;a href="http://3.bp.blogspot.com/-DMlF_GUaKWQ/Ubtju8NetxI/AAAAAAAARlQ/N19WLUVqBbw/s1600/java.jpeg" imageanchor="1" style="clear: left; float: left; margin-bottom: 1em; margin-right: 1em;"&gt;&lt;img border="0" src="http://3.bp.blogspot.com/-DMlF_GUaKWQ/Ubtju8NetxI/AAAAAAAARlQ/N19WLUVqBbw/s1600/java.jpeg" /&gt;&lt;/a&gt;&lt;/div&gt;This post is all about a small introduction about how memory is allocated in java.&lt;br /&gt;
When JVM is getting started , Underlaying Operating system allocates a chunk of memory to JVM.&lt;br /&gt;
This chunk size is dependent on the version of OS, Version of java and total memory available to OS.&lt;br /&gt;
&lt;br /&gt;
A quick way to explain java memory allocation is , java mainly keeps it data to heap and stack area. So whenever JVM gets some memory it divides the area to stack and heap area.&lt;br /&gt;
Heap area is to keep the live objects and stack area is to keep all method calls and local variables.&lt;br /&gt;
Mainly the heap area is the garbage collectable area.&lt;br /&gt;
&lt;br /&gt;
The problem arises when we talk about the variables. It is bit complicated to understand where they live.&lt;br /&gt;
Let me explain the variable part to make it easy...&lt;br /&gt;
Variables can be divided into two broad categories..&lt;br /&gt;
&lt;br /&gt;
&lt;ul style="text-align: left;"&gt;&lt;li&gt;Instance variables&lt;/li&gt;
&lt;li&gt;Local variables&lt;/li&gt;
&lt;/ul&gt;&lt;div&gt;Local variables mostly declared in methods, even the method parameters are local to method. As all the methods stay in stack, hence local variables stay in stack in the frame corresponding to the method. That is the reason Local variables are called stack variables.&lt;/div&gt;&lt;div&gt;&lt;br /&gt;
&lt;/div&gt;&lt;div&gt;again for instance variable they are mostly declared inside a class. They become active when the object is created. So instance variable stay in heap area,where the objects are stored.The memory allocation depends on the size of the type. say a int will take 32 bits, a long will take 64 bits. JVM will not consider the value of it, It will allocate 32 / 64 bit memory.&lt;/div&gt;&lt;div&gt;&lt;br /&gt;
&lt;/div&gt;&lt;div&gt;Methods:&lt;/div&gt;&lt;div&gt;For methods as I said earlier, JVM pushes themselves to stack.&lt;/div&gt;&lt;div&gt;So if your program have 3 methods&lt;/div&gt;&lt;div&gt;&lt;pre class="java" name="code"&gt;main()
dosometask1() // having 1 local variable
dosometask2()//having 2 local variables

&lt;/pre&gt;&lt;div&gt;JVM reads it and pushes the methods to the stack one by one.&lt;/div&gt;&lt;div&gt;so the stack will be ..&lt;/div&gt;&lt;div&gt;&lt;ul style="text-align: left;"&gt;&lt;li&gt;dosometask2()&lt;/li&gt;
&lt;li&gt;dosometask1()&lt;/li&gt;
&lt;li&gt;main()&lt;/li&gt;
&lt;/ul&gt;&lt;div&gt;with Local variables.&lt;/div&gt;&lt;/div&gt;&lt;div&gt;One more area we need to think, if the variable holds reference of an object. like..&lt;/div&gt;&lt;pre class="java" name="code"&gt;public int calc()
{
Tree t=new Tree();

}&lt;/pre&gt;&lt;/div&gt;&lt;/div&gt;For this case, the method calc() will go to stack, with the variable  't'. But since we have created a new object here with new keyword, the object will go to heap and the reference will be created with this variable.&lt;br /&gt;
&lt;br /&gt;
So if only give &lt;br /&gt;
&lt;br /&gt;
&lt;pre class="java" name="code"&gt;public int calc()
{
Tree t;

}&lt;/pre&gt;&lt;br /&gt;
so public method calc will be pushed to stack with a reference variable t but no object will be crated in the heap.again when JVM gets a command called new Tree(); only then the object in the heap will be created.&lt;br /&gt;
&lt;br /&gt;
In the first look we might think that object creation is calling a method..Method name is Tree()&lt;br /&gt;
&lt;pre class="java" name="code"&gt;public int calc()
{
Tree t=new Tree();

}&lt;/pre&gt;&lt;br /&gt;
Not exactly, It is calling the Tree constructor.(Constructor is nothing but a set of codes which runs when we instantiate an object)&lt;/div&gt;&lt;img src="http://feeds.feedburner.com/~r/blogspot/TerSJ/~4/1ASUUfPe_dk" height="1" width="1"/&gt;</description><link>http://feedproxy.google.com/~r/blogspot/TerSJ/~3/1ASUUfPe_dk/how-memory-allocation-happens-in-java.html</link><author>ani01104@gmail.com (Madhumita)</author><media:thumbnail url="http://3.bp.blogspot.com/-DMlF_GUaKWQ/Ubtju8NetxI/AAAAAAAARlQ/N19WLUVqBbw/s72-c/java.jpeg" height="72" width="72" /><thr:total>0</thr:total><feedburner:origLink>http://www.askqtp.com/2013/06/how-memory-allocation-happens-in-java.html</feedburner:origLink></item><item><guid isPermaLink="false">tag:blogger.com,1999:blog-2981436578666077634.post-4615213968564113541</guid><pubDate>Sat, 01 Jun 2013 07:23:00 +0000</pubDate><atom:updated>2013-06-01T12:54:05.795+05:30</atom:updated><category domain="http://www.blogger.com/atom/ns#">enum</category><category domain="http://www.blogger.com/atom/ns#">java</category><category domain="http://www.blogger.com/atom/ns#">Enum and Enumeration</category><category domain="http://www.blogger.com/atom/ns#">Difference between enum</category><category domain="http://www.blogger.com/atom/ns#">Enumeration</category><title>What Is The Difference Between enum,Enum and Enumeration in Java?</title><description>&lt;div dir="ltr" style="text-align: left;" trbidi="on"&gt;&lt;div class="separator" style="clear: both; text-align: center;"&gt;&lt;a href="http://2.bp.blogspot.com/-rpWwP_eXdqE/Uamdrc5K2yI/AAAAAAAARi0/cxD3Jtcr9FY/s1600/enum+vs+Enum+vs+Enumeration.jpg" imageanchor="1" style="clear: left; float: left; margin-bottom: 1em; margin-right: 1em;"&gt;&lt;img border="0" height="135" src="http://2.bp.blogspot.com/-rpWwP_eXdqE/Uamdrc5K2yI/AAAAAAAARi0/cxD3Jtcr9FY/s320/enum+vs+Enum+vs+Enumeration.jpg" width="320" /&gt;&lt;/a&gt;&lt;/div&gt;Few days back I got this question from one of my blog follower Anish. Thanks for raising this point Anish. I am going publish a little comparison between them what ever I got with the help of Google.&lt;br /&gt;
&lt;br /&gt;
&lt;div class="CSSTableGenerator"&gt;&lt;table&gt;&lt;tbody&gt;
&lt;tr&gt;                         &lt;td&gt;&lt;br /&gt;
enum&lt;/td&gt;                         &lt;td&gt;&lt;br /&gt;
Enum&lt;/td&gt;                         &lt;td&gt;&lt;br /&gt;
Enumeration&lt;/td&gt;                     &lt;/tr&gt;
&lt;tr&gt;                         &lt;td&gt;&lt;br /&gt;
enum is a keyword which represents a group of named constants&lt;/td&gt;                         &lt;td&gt;&lt;br /&gt;
Enum is present in java.lang package. It is a parent class of enum. So it acts as a base class for every enum&lt;/td&gt;                         &lt;td&gt;&lt;br /&gt;
Enumeration is an interface present in java.util package&lt;/td&gt;                     &lt;/tr&gt;
&lt;tr&gt;                         &lt;td&gt;&lt;br /&gt;
enum can hold constructor(no argumented and argumented) and methods&lt;/td&gt;                         &lt;td&gt;&lt;br /&gt;
Enum can not hold the constructor or methods&lt;/td&gt;                         &lt;td&gt;&lt;br /&gt;
We use this method to get object from collection one by one&lt;/td&gt;                     &lt;/tr&gt;
&lt;tr&gt;                         &lt;td&gt;&lt;br /&gt;
Below 1.4 version it was used as a literal and after 1.4 version it becomes group of constants and it is reserved &lt;/td&gt;                         &lt;td&gt;&lt;br /&gt;
&lt;/td&gt;                         &lt;td&gt;&lt;br /&gt;
&lt;/td&gt;                     &lt;/tr&gt;
&lt;/tbody&gt;&lt;/table&gt;&lt;/div&gt;&lt;br /&gt;
&lt;/div&gt;&lt;img src="http://feeds.feedburner.com/~r/blogspot/TerSJ/~4/aNkkUY6LETY" height="1" width="1"/&gt;</description><link>http://feedproxy.google.com/~r/blogspot/TerSJ/~3/aNkkUY6LETY/what-is-difference-between-enumenum-and.html</link><author>ani01104@gmail.com (Madhumita)</author><media:thumbnail url="http://2.bp.blogspot.com/-rpWwP_eXdqE/Uamdrc5K2yI/AAAAAAAARi0/cxD3Jtcr9FY/s72-c/enum+vs+Enum+vs+Enumeration.jpg" height="72" width="72" /><thr:total>0</thr:total><feedburner:origLink>http://www.askqtp.com/2013/06/what-is-difference-between-enumenum-and.html</feedburner:origLink></item><item><guid isPermaLink="false">tag:blogger.com,1999:blog-2981436578666077634.post-7493797689077510274</guid><pubDate>Thu, 30 May 2013 19:47:00 +0000</pubDate><atom:updated>2013-06-01T00:05:18.570+05:30</atom:updated><category domain="http://www.blogger.com/atom/ns#">enum</category><category domain="http://www.blogger.com/atom/ns#">Constructor</category><category domain="http://www.blogger.com/atom/ns#">java</category><category domain="http://www.blogger.com/atom/ns#">enum concept</category><title>How Constructor Works In Java Enum ?</title><description>&lt;div dir="ltr" style="text-align: left;" trbidi="on"&gt;&lt;div dir="ltr" style="text-align: left;" trbidi="on"&gt;&lt;div class="separator" style="clear: both; text-align: center;"&gt;&lt;a href="http://1.bp.blogspot.com/-jD2ibxMD4xc/UacejyBqQYI/AAAAAAAARik/afFnZ5tJ3k4/s1600/constractor.jpg" imageanchor="1" style="clear: left; float: left; margin-bottom: 1em; margin-right: 1em;"&gt;&lt;img border="0" src="http://1.bp.blogspot.com/-jD2ibxMD4xc/UacejyBqQYI/AAAAAAAARik/afFnZ5tJ3k4/s1600/constractor.jpg" /&gt;&lt;/a&gt;&lt;/div&gt;In my last few posts&lt;br /&gt;
&lt;br /&gt;
&lt;ul style="text-align: left;"&gt;&lt;li&gt;&lt;a href="http://www.askqtp.com/2013/05/enum-concept-simplified-in-java.html"&gt;http://www.askqtp.com/2013/05/enum-concept-simplified-in-java.html&lt;/a&gt;&lt;/li&gt;
&lt;li&gt;&lt;a href="http://www.askqtp.com/2013/05/how-to-get-values-from-enum-in-java.html"&gt;http://www.askqtp.com/2013/05/how-to-get-values-from-enum-in-java.html&lt;/a&gt;&lt;/li&gt;
&lt;li&gt;&lt;a href="http://www.askqtp.com/2013/05/how-to-work-with-java-enum-in-switch.html"&gt;http://www.askqtp.com/2013/05/how-to-work-with-java-enum-in-switch.html&lt;/a&gt;&lt;/li&gt;
&lt;li&gt;&lt;a href="http://www.askqtp.com/2013/05/how-inheritance-concept-works-for-java.html"&gt;http://www.askqtp.com/2013/05/how-inheritance-concept-works-for-java.html&lt;/a&gt;&lt;/li&gt;
&lt;/ul&gt;I have discussed concepts on Enum. In this post I would like to show the constructor concept in java enum.Constructor!!! that too in enum???&lt;br /&gt;
Yes!!! java has come up with this beautiful concept.&lt;br /&gt;
enum can contain constructors. This constructors will be executed at the time of enum class loading automatically for every enum constant.&lt;br /&gt;
&lt;br /&gt;
&lt;pre class="java" name="code"&gt;enum Month    
{    
JAN,FEB,MAR;    
//note semicolon(;) is optional here    
Month()
{
System.out.println("enum constructor");
}
} 
class Testenumcons{
public static void main(String... Args)
{
Month mon=Month.JAN;
System.out.println("Main method");
}
}
&lt;/pre&gt;output:&lt;br /&gt;
enum constructor&lt;br /&gt;
enum constructor&lt;br /&gt;
enum constructor&lt;br /&gt;
Main method&lt;br /&gt;
Now we can also conclude-&lt;br /&gt;
we can not create enum object explicitly if we do so we will get compile time error.&lt;br /&gt;
&lt;br /&gt;
&lt;pre class="java" name="code"&gt;enum Month    
{    
JAN,FEB,MAR;    
//note semicolon(;) is optional here    
Month()
{
System.out.println("enum constructor");
}
} 
class Testenumcons{
public static void main(String... Args)
{
Month mon=new Month();
//illegal statement.
Month mon=Month.JAN;
System.out.println("Main method");
}
}
&lt;/pre&gt;E:\myProgram\Testenumcons.java:13: error: enum types may not be instantiated&lt;br /&gt;
Month mon=new Month();&lt;br /&gt;
^&lt;br /&gt;
E:\myProgram\Testenumcons.java:14: error: variable mon is already defined in met&lt;br /&gt;
hod main(String...)&lt;br /&gt;
Month mon=Month.JAN;&lt;br /&gt;
^&lt;br /&gt;
2 errors&lt;br /&gt;
So we can not invoke enum constructor directly.&lt;br /&gt;
Till now in the above example we have seen no argument constructor.But we can also have argumented constructor.&lt;br /&gt;
&lt;pre class="java" name="code"&gt;enum Month    
{    
JAN(31),FEB(28),MAR(31),APR;   
int days ;
//note semicolon(;) is optional here  
//argumented constructor  
Month(int days)
{
System.out.println("enum argumented constructor ");
this.days=days;
}
// no argumented constructor
Month()
{
System.out.println("enum no argument constructor");
this.days=31;
}
public int getDays()
{
return days;
}
} 
class Testenumcons{
public static void main(String... Args)
{

Month[] mon=Month.values();
for (Month m:mon)
{
System.out.println(m+"--&amp;gt;"+m.getDays());
}
}
}

&lt;/pre&gt;output:&lt;br /&gt;
enum argumented constructor&lt;br /&gt;
enum argumented constructor&lt;br /&gt;
enum argumented constructor&lt;br /&gt;
enum no argument constructor&lt;br /&gt;
JAN--&amp;gt;31&lt;br /&gt;
FEB--&amp;gt;28&lt;br /&gt;
MAR--&amp;gt;31&lt;br /&gt;
APR--&amp;gt;31&lt;br /&gt;
&lt;div class="Note"&gt;in general if you do not define any no argument constructor, Compiler will automatically put a no argument constructor inside enum when it transfer enum to class. but that will have no statement inside it. But there are two cases to check out..&lt;br /&gt;
Case 1. if the enum constants have mix with argumented and non argumented then it is compulsory to define both argumented and non argumented constructor. Otherwise compiler will throw compile time error.&lt;br /&gt;
Case-2 Compiler will automatically add no argumented constructor if no argumented constructor is defined.&lt;/div&gt;&lt;pre class="java" name="code"&gt;enum Month    
{    
JAN(31),FEB(28),MAR(31),APR;   
int days ;
//note semicolon(;) is optional here  
//argumented constructor  
Month(int days)
{
System.out.println("enum argumented constructor ");
this.days=days;
}
// no argumented constructor

public int getDays()
{
return days;
}
} 
class Testenumcons{
public static void main(String... Args)
{

Month[] mon=Month.values();
for (Month m:mon)
{
System.out.println(m+"--&amp;gt;"+m.getDays());
}
}
}

&lt;/pre&gt;E:\myProgram\Testenumcons.java:3: error: constructor Month in enum Month cannot&lt;br /&gt;
be applied to given types;&lt;br /&gt;
JAN(31),FEB(28),MAR(31),APR;&lt;br /&gt;
^&lt;br /&gt;
required: int&lt;br /&gt;
found: no arguments&lt;br /&gt;
reason: actual and formal argument lists differ in length&lt;br /&gt;
1 error&lt;br /&gt;
&lt;div class="Blue_hearder"&gt;Also inside enum we can add methods. But the methods should be concrete,not abstract.&lt;br /&gt;
Every enum constant represents an object of the type enum so the calling of the methods are same as the way we call normal methods  &lt;br /&gt;
Possible operators we can use are--&lt;/div&gt;&lt;ul style="text-align: left;"&gt;&lt;li&gt;enum.constantname.equals(enum.constantname)&lt;/li&gt;
&lt;li&gt;enum.constantname==enum.constantname&lt;/li&gt;
&lt;li&gt;enum.constantname.ordinal&amp;gt;enum.constantname.ordinal&lt;/li&gt;
&lt;/ul&gt;&lt;/div&gt;&lt;table bgcolor="#e4eded" border="0" bordercolor="#000000" style="width: 100%;"&gt;&lt;tbody&gt;
&lt;tr&gt; &lt;td&gt;&lt;b&gt;&lt;span style="color: #004080;"&gt;Normal methods in enum&lt;/span&gt;&lt;/b&gt;&lt;/td&gt;&lt;/tr&gt;
&lt;/tbody&gt;&lt;/table&gt;&lt;br /&gt;
&lt;pre class="java" name="code"&gt;enum testenum21
{
JAN,FEB,MAR;
public void info()
{
System.out.println("enum info method called");
}
}

class getvalues{
public static void main(String... Args)
{
testenum21[] mon=testenum21.values();
for(testenum21 m: mon)
{
System.out.print(m.ordinal()+ " ");
m.info();

}
}
}
&lt;/pre&gt;output:&lt;br /&gt;
0 enum info method called&lt;br /&gt;
1 enum info method called&lt;br /&gt;
2 enum info method called&lt;br /&gt;
&lt;br /&gt;
&lt;table bgcolor="#e4eded" border="0" bordercolor="#000000" style="width: 100%;"&gt;&lt;tbody&gt;
&lt;tr&gt; &lt;td&gt;&lt;b&gt;&lt;span style="color: #004080;"&gt;Specific methods in enum&lt;/span&gt;&lt;/b&gt;&lt;/td&gt;&lt;/tr&gt;
&lt;/tbody&gt;&lt;/table&gt;Let us see some specific method attached to enum.&lt;br /&gt;
&lt;pre class="java" name="code"&gt;enum testenum21
{
JAN,FEB{
public void info()
{
System.out.println("Festival of love");
}
},MAR;
public void info()
{
System.out.println("enum info method called");
}
}

class getvalues{
public static void main(String... Args)
{
testenum21[] mon=testenum21.values();
for(testenum21 m: mon)
{
System.out.print(m.ordinal()+" ");
m.info();

}
}
}
&lt;/pre&gt;output:&lt;br /&gt;
0 enum info method called&lt;br /&gt;
1 Festival of love&lt;br /&gt;
2 enum info method called&lt;br /&gt;
&lt;/div&gt;&lt;img src="http://feeds.feedburner.com/~r/blogspot/TerSJ/~4/7xUX-Hrrq0I" height="1" width="1"/&gt;</description><link>http://feedproxy.google.com/~r/blogspot/TerSJ/~3/7xUX-Hrrq0I/how-constructor-works-in-java-enum.html</link><author>ani01104@gmail.com (Madhumita)</author><media:thumbnail url="http://1.bp.blogspot.com/-jD2ibxMD4xc/UacejyBqQYI/AAAAAAAARik/afFnZ5tJ3k4/s72-c/constractor.jpg" height="72" width="72" /><thr:total>0</thr:total><feedburner:origLink>http://www.askqtp.com/2013/05/how-constructor-works-in-java-enum.html</feedburner:origLink></item><item><guid isPermaLink="false">tag:blogger.com,1999:blog-2981436578666077634.post-1554204328899487771</guid><pubDate>Wed, 29 May 2013 21:21:00 +0000</pubDate><atom:updated>2013-05-30T02:51:49.466+05:30</atom:updated><category domain="http://www.blogger.com/atom/ns#">enum</category><category domain="http://www.blogger.com/atom/ns#">java</category><category domain="http://www.blogger.com/atom/ns#">Inheritance</category><category domain="http://www.blogger.com/atom/ns#">enum concept</category><title>How Inheritance Concept Works For Java Enum??</title><description>&lt;div dir="ltr" style="text-align: left;" trbidi="on"&gt;&lt;div class="separator" style="clear: both; text-align: center;"&gt;&lt;a href="http://2.bp.blogspot.com/-6kSIArohEM4/UaZehOitTJI/AAAAAAAARiU/ytOrH2ZZ5iM/s1600/inheritance.jpg" imageanchor="1" style="clear: left; float: left; margin-bottom: 1em; margin-right: 1em;"&gt;&lt;img border="0" src="http://2.bp.blogspot.com/-6kSIArohEM4/UaZehOitTJI/AAAAAAAARiU/ytOrH2ZZ5iM/s1600/inheritance.jpg" /&gt;&lt;/a&gt;&lt;/div&gt;In my previous post (http://www.askqtp.com/2013/05/enum-concept-simplified-in-java.html) I have told how compiler will treat enum.&lt;br /&gt;
It will treat enum as a class.&lt;br /&gt;
&lt;pre class="java" name="code"&gt;enum Month  
{  
JAN,FEB,MAR;  
//note semicolon(;) is optional here  
}  
&lt;/pre&gt;will be transferred by the compiler as..&lt;br /&gt;
&lt;pre class="java" name="code"&gt;Class Month  
{  
//for JAN  
public static final Month JAN=new Month();  
//similarly for FEB and MAR  
public static final Month FEB=new Month();  
public static final Month MAR=new Month();  
}  

&lt;/pre&gt;Since the underlying concept is class, the very next question arises as can Inheritance concept works for enum? Let us see few concepts..&lt;br /&gt;
&lt;div class="Blue_hearder"&gt;&lt;br /&gt;
&lt;ul style="text-align: left;"&gt;&lt;li&gt;Every enum is direct child of java.lang.Enum class in java, So enum can't extend any other enum&lt;/li&gt;
&lt;li&gt;Every enum is always final implicitly hence we can't create child enum&lt;/li&gt;
&lt;/ul&gt;&lt;/div&gt;With the above statements we can conclude that inheritance concept is not applicable for explicitly.Hence we can't use extends keyword for enums.&lt;br /&gt;
&lt;pre name="code" class="java"&gt;enum x
{}
enum y extends x{}
&lt;/pre&gt;output: Compile time error&lt;br /&gt;
&lt;pre name="code" class="java"&gt;enum x extends java.lan.Enum
{}
&lt;/pre&gt;output: Compile time error&lt;br /&gt;
&lt;pre name="code" class="java"&gt;Class x
{}
enum y extends x{}
&lt;/pre&gt;output: Compile time error&lt;br /&gt;
&lt;pre name="code" class="java"&gt;enum x
{}
Class y extends x{}
&lt;/pre&gt;output: Compile time error&lt;br /&gt;
&lt;div class="Note"&gt;  Can not inherit from final (enum) or enum types are not extensible&lt;br /&gt;
&lt;br /&gt;
&lt;/div&gt;However an enum can implement any no of interfaces simultaneously.&lt;br /&gt;
&lt;pre name="code" class="java"&gt;interface x
{}
enum y implements x{}
&lt;/pre&gt;Valid deceleration.&lt;br /&gt;
&lt;/div&gt;&lt;img src="http://feeds.feedburner.com/~r/blogspot/TerSJ/~4/k6PawIc0oTU" height="1" width="1"/&gt;</description><link>http://feedproxy.google.com/~r/blogspot/TerSJ/~3/k6PawIc0oTU/how-inheritance-concept-works-for-java.html</link><author>ani01104@gmail.com (Madhumita)</author><media:thumbnail url="http://2.bp.blogspot.com/-6kSIArohEM4/UaZehOitTJI/AAAAAAAARiU/ytOrH2ZZ5iM/s72-c/inheritance.jpg" height="72" width="72" /><thr:total>0</thr:total><feedburner:origLink>http://www.askqtp.com/2013/05/how-inheritance-concept-works-for-java.html</feedburner:origLink></item><item><guid isPermaLink="false">tag:blogger.com,1999:blog-2981436578666077634.post-3017074403462039956</guid><pubDate>Wed, 29 May 2013 19:52:00 +0000</pubDate><atom:updated>2013-05-30T01:26:02.873+05:30</atom:updated><category domain="http://www.blogger.com/atom/ns#">enum</category><category domain="http://www.blogger.com/atom/ns#">java</category><category domain="http://www.blogger.com/atom/ns#">Switch case</category><category domain="http://www.blogger.com/atom/ns#">enum concept</category><title>How To Work With Java Enum In Switch Argument?? </title><description>&lt;div dir="ltr" style="text-align: left;" trbidi="on"&gt;&lt;div class="separator" style="clear: both; text-align: center;"&gt;&lt;a href="http://3.bp.blogspot.com/-TjtiYYT4t44/UaZYMqVMSTI/AAAAAAAARiI/CBrEhpaFiy8/s1600/switch.jpg" imageanchor="1" style="clear: left; float: left; margin-bottom: 1em; margin-right: 1em;"&gt;&lt;img border="0" src="http://3.bp.blogspot.com/-TjtiYYT4t44/UaZYMqVMSTI/AAAAAAAARiI/CBrEhpaFiy8/s1600/switch.jpg" /&gt;&lt;/a&gt;&lt;/div&gt;In my last post (&lt;a href="http://www.askqtp.com/2013/05/how-to-get-values-from-enum-in-java.html"&gt;http://www.askqtp.com/2013/05/how-to-get-values-from-enum-in-java.html&lt;/a&gt;) I have said how to get values from enum. This post talks about how to work with enum inside switch statement.&lt;br /&gt;
&lt;br /&gt;
Generally we use if when we need to compare small number of (say 2-3) variables,but for big number of condition check it is always better to go for switch statement.&lt;br /&gt;
Until java 1.4 version(java4) switch statement used to take byte,short,char and int as argument.&lt;br /&gt;
From java1.5(java 5 or tiger) edition switch supports corresponding wrapper classes and enum types.&lt;br /&gt;
&lt;div class="CSSTableGenerator"&gt;&lt;table&gt;&lt;tbody&gt;
&lt;tr&gt;                         &lt;td&gt;&lt;br /&gt;
Java 1.4&lt;/td&gt;                         &lt;td&gt;&lt;br /&gt;
java 1.5&lt;/td&gt;                         &lt;td&gt;&lt;br /&gt;
java 1.7&lt;/td&gt;                     &lt;/tr&gt;
&lt;tr&gt;                         &lt;td&gt;&lt;br /&gt;
byte&lt;/td&gt;                         &lt;td&gt;&lt;br /&gt;
Byte&lt;/td&gt;                         &lt;td&gt;&lt;br /&gt;
String&lt;/td&gt;                     &lt;/tr&gt;
&lt;tr&gt;                         &lt;td&gt;&lt;br /&gt;
short&lt;/td&gt;                         &lt;td&gt;&lt;br /&gt;
Short&lt;/td&gt;                         &lt;td&gt;&lt;br /&gt;
&lt;br /&gt;
&lt;/td&gt;                     &lt;/tr&gt;
&lt;tr&gt;                         &lt;td&gt;&lt;br /&gt;
char&lt;/td&gt;                         &lt;td&gt;&lt;br /&gt;
Character&lt;/td&gt;                         &lt;td&gt;&lt;br /&gt;
&lt;br /&gt;
&lt;/td&gt;                     &lt;/tr&gt;
&lt;tr&gt;                         &lt;td&gt;&lt;br /&gt;
int&lt;/td&gt;                         &lt;td&gt;&lt;br /&gt;
Interger&lt;/td&gt;                         &lt;td&gt;&lt;br /&gt;
&lt;br /&gt;
&lt;/td&gt;                     &lt;/tr&gt;
&lt;tr&gt;                         &lt;td&gt;&lt;br /&gt;
&lt;br /&gt;
&lt;/td&gt;                         &lt;td&gt;&lt;br /&gt;
enum&lt;/td&gt;                         &lt;td&gt;&lt;br /&gt;
&lt;/td&gt;                     &lt;/tr&gt;
&lt;/tbody&gt;&lt;/table&gt;&lt;/div&gt;&lt;/div&gt;&lt;div class="Note"&gt;So after java 1.5 onwards,enum can be passed as a type as an argument to switch statement&lt;br /&gt;
&lt;/div&gt;lets check out one example:&lt;br /&gt;
&lt;pre name="code" class="java"&gt;enum Month
{
 JAN,FEB,MAR;
//declare enum
}
public class enumTest {

 /**
  * @param args
  */
 public static void main(String[] args) {
  // TODO Auto-generated method stub
  Month mon=Month.MAR;
//create switch statement
  switch(mon)
  {
  case JAN : System.out.println("1st Month");break;
  case FEB : System.out.println("2nd Month");break;
  case MAR : System.out.println("3rd Month");break;
  
  }

 }

}

&lt;/pre&gt;output:&lt;br /&gt;
3rd Month&lt;br /&gt;
&lt;div class="Blue_hearder"&gt;we can pass enum type as argument to switch statement, but every case label should be Valid enum contant. Otherwise we will get compile time error.&lt;br /&gt;
&lt;/div&gt;&lt;pre name="code" class="java"&gt;enum Month
{
 JAN,FEB,MAR;
//declare enum
}
public class enumTest {

 /**
  * @param args
  */
 public static void main(String[] args) {
  // TODO Auto-generated method stub
  Month mon=Month.MAR;
//create switch statement
  switch(mon)
  {
  case JAN : System.out.println("1st Month");break;
  case FEB : System.out.println("2nd Month");break;
  case MAR : System.out.println("3rd Month");break;
  case APR : System.out.println("4th Month");break;
  }

 }

}

&lt;/pre&gt;Output:&lt;br /&gt;
Compilation error:&lt;br /&gt;
Exception in thread "main" java.lang.Error: Unresolved compilation problem: &lt;br /&gt;
APR cannot be resolved or is not a field&lt;br /&gt;
^&lt;br /&gt;
at enumTest.main(enumTest.java:20)&lt;img src="http://feeds.feedburner.com/~r/blogspot/TerSJ/~4/euNqDf7bBbk" height="1" width="1"/&gt;</description><link>http://feedproxy.google.com/~r/blogspot/TerSJ/~3/euNqDf7bBbk/how-to-work-with-java-enum-in-switch.html</link><author>ani01104@gmail.com (Madhumita)</author><media:thumbnail url="http://3.bp.blogspot.com/-TjtiYYT4t44/UaZYMqVMSTI/AAAAAAAARiI/CBrEhpaFiy8/s72-c/switch.jpg" height="72" width="72" /><thr:total>0</thr:total><feedburner:origLink>http://www.askqtp.com/2013/05/how-to-work-with-java-enum-in-switch.html</feedburner:origLink></item><item><guid isPermaLink="false">tag:blogger.com,1999:blog-2981436578666077634.post-7095045597935673295</guid><pubDate>Wed, 29 May 2013 03:14:00 +0000</pubDate><atom:updated>2013-05-29T08:45:14.714+05:30</atom:updated><category domain="http://www.blogger.com/atom/ns#">enum</category><category domain="http://www.blogger.com/atom/ns#">Values from enum</category><category domain="http://www.blogger.com/atom/ns#">java</category><category domain="http://www.blogger.com/atom/ns#">enum concept</category><title>How To Get Values from Enum In Java</title><description>&lt;div dir="ltr" style="text-align: left;" trbidi="on"&gt;
&lt;div class="separator" style="clear: both; text-align: center;"&gt;
&lt;a href="http://4.bp.blogspot.com/-g-v8JZ61TiY/UaVreYUWo7I/AAAAAAAARh4/9j7-ZsoOZzE/s1600/Article-Java-Enums.png" imageanchor="1" style="clear: left; float: left; margin-bottom: 1em; margin-right: 1em;"&gt;&lt;img border="0" height="200" src="http://4.bp.blogspot.com/-g-v8JZ61TiY/UaVreYUWo7I/AAAAAAAARh4/9j7-ZsoOZzE/s320/Article-Java-Enums.png" width="220" /&gt;&lt;/a&gt;&lt;/div&gt;
In my last post (&lt;a href="http://www.askqtp.com/2013/05/enum-concept-simplified-in-java.html"&gt;http://www.askqtp.com/2013/05/enum-concept-simplified-in-java.html&lt;/a&gt;) I have shown how to declare enum in java. In this post we would see how to get values from enum rather how to get values from enum in a systematic approach.&lt;br /&gt;
&lt;br /&gt;
There are three ways we can get values from enum..&lt;br /&gt;
&lt;ul style="text-align: left;"&gt;
&lt;li&gt;direct way&lt;/li&gt;
&lt;li&gt;by using values() method&lt;/li&gt;
&lt;li&gt;by using ordinal() method&lt;/li&gt;
&lt;/ul&gt;
&lt;div&gt;
&lt;br /&gt;&lt;/div&gt;
&lt;table bgcolor="#e4eded" border="0" bordercolor="#000000" style="width: 100%;"&gt;&lt;tbody&gt;
&lt;tr&gt; &lt;td&gt;&lt;b&gt;&lt;span style="color: #004080;"&gt;Direct Method&lt;/span&gt;&lt;/b&gt;&lt;/td&gt;&lt;/tr&gt;
&lt;/tbody&gt;&lt;/table&gt;
&lt;pre class="java" name="code"&gt;enum testenum21
{
JAN,FEB,MAR;
}
class getvalues{
public static void main(String... Args)
{
testenum21 mon=testenum21.JAN;
System.out.println(mon);
}
}

&lt;/pre&gt;
output: JAN&lt;br /&gt;
&lt;table bgcolor="#e4eded" border="0" bordercolor="#000000" style="width: 100%;"&gt;&lt;tbody&gt;
&lt;tr&gt; &lt;td&gt;&lt;b&gt;&lt;span style="color: #004080;"&gt;values() Method&lt;/span&gt;&lt;/b&gt;&lt;/td&gt;&lt;/tr&gt;
&lt;/tbody&gt;&lt;/table&gt;
We can use values method to get each element from enum.&lt;br /&gt;
The syntax is&lt;span style="background-color: #eeeeee;"&gt; [[enumname]][] variable=[[enumname]].values();&lt;/span&gt;&lt;br /&gt;
&lt;pre class="java" name="code"&gt;enum testenum21
{
JAN,FEB,MAR;
}
class getvalues{
public static void main(String... Args)
{
testenum21[] mon=testenum21.values();
for(testenum21 m: mon)
{
System.out.println(m);
}
}
}

&lt;/pre&gt;
output:&lt;br /&gt;
JAN&lt;br /&gt;
FEB&lt;br /&gt;
MAR&lt;br /&gt;
&lt;table bgcolor="#e4eded" border="0" bordercolor="#000000" style="width: 100%;"&gt;&lt;tbody&gt;
&lt;tr&gt; &lt;td&gt;&lt;b&gt;&lt;span style="color: #004080;"&gt;ordinal() Method&lt;/span&gt;&lt;/b&gt;&lt;/td&gt;&lt;/tr&gt;
&lt;/tbody&gt;&lt;/table&gt;
If in our programming order of the enum constant becomes important,we can use ordinal method to get the order of the element.&lt;br /&gt;
The syntax is &lt;br /&gt;
&lt;span style="background-color: #eeeeee;"&gt;public final int ordinal();&lt;/span&gt;&lt;br /&gt;
&lt;pre class="java" name="code"&gt;enum testenum21
{
JAN,FEB,MAR;
}
class getvalues{
public static void main(String... Args)
{
testenum21[] mon=testenum21.values();
for(testenum21 m: mon)
{
System.out.println(m+"..."+m.ordinal());
}
}
}
&lt;/pre&gt;
The output is &lt;br /&gt;
JAN...0&lt;br /&gt;
FEB...1&lt;br /&gt;
MAR...2&lt;br /&gt;
&lt;div class="Note"&gt;
The ordinal method is more powerful and starts with zero. It is zero based.&lt;/div&gt;
&lt;/div&gt;&lt;img src="http://feeds.feedburner.com/~r/blogspot/TerSJ/~4/BvQ6GwrpFzo" height="1" width="1"/&gt;</description><link>http://feedproxy.google.com/~r/blogspot/TerSJ/~3/BvQ6GwrpFzo/how-to-get-values-from-enum-in-java.html</link><author>ani01104@gmail.com (Madhumita)</author><media:thumbnail url="http://4.bp.blogspot.com/-g-v8JZ61TiY/UaVreYUWo7I/AAAAAAAARh4/9j7-ZsoOZzE/s72-c/Article-Java-Enums.png" height="72" width="72" /><thr:total>0</thr:total><feedburner:origLink>http://www.askqtp.com/2013/05/how-to-get-values-from-enum-in-java.html</feedburner:origLink></item><item><guid isPermaLink="false">tag:blogger.com,1999:blog-2981436578666077634.post-3390649938880414450</guid><pubDate>Tue, 28 May 2013 17:40:00 +0000</pubDate><atom:updated>2013-05-29T00:59:11.071+05:30</atom:updated><category domain="http://www.blogger.com/atom/ns#">enum</category><category domain="http://www.blogger.com/atom/ns#">java</category><category domain="http://www.blogger.com/atom/ns#">enum concept</category><title>ENUM Concept Simplified In Java</title><description>&lt;div dir="ltr" style="text-align: left;" trbidi="on"&gt;
&lt;div class="separator" style="clear: both; text-align: center;"&gt;
&lt;a href="http://4.bp.blogspot.com/-1RwrG6AJN90/UaTjm0T0LrI/AAAAAAAARgo/a4BlzLDqf1w/s1600/enum.jpg" imageanchor="1" style="clear: left; float: left; margin-bottom: 1em; margin-right: 1em;"&gt;&lt;img border="0" src="http://4.bp.blogspot.com/-1RwrG6AJN90/UaTjm0T0LrI/AAAAAAAARgo/a4BlzLDqf1w/s1600/enum.jpg" /&gt;&lt;/a&gt;&lt;/div&gt;
If the programmer wants to represent a group of constants across programming, then they can implement &lt;b&gt;&lt;u&gt;enum.&lt;/u&gt;&lt;/b&gt;&lt;br /&gt;
Enumeration. It has been introduced in Java 1.5 (or java 5 or Tiger release)&lt;br /&gt;
&lt;br /&gt;
The main objective of enum is to define our own datatypes like enumerated data types. This is more powerful concept than older java constant.&lt;br /&gt;
&lt;br /&gt;
&lt;pre class="java" name="code"&gt;enum Month
{
JAN,FEB,MAR;
//note semicolon(;) is optional here
}


&lt;/pre&gt;
or let us check a new example&lt;br /&gt;
&lt;pre class="java" name="code"&gt;enum Laptop_company
{
Lenevo,DELL,HP;
//note semicolon(;) is optional here
}


&lt;/pre&gt;
&lt;table bgcolor="#e4eded" border="0" bordercolor="#000000" style="width: 100%;"&gt;&lt;tbody&gt;
&lt;tr&gt; &lt;td&gt;&lt;b&gt;&lt;span style="color: #004080;"&gt;Internal Implementation of enum:&lt;/span&gt;&lt;/b&gt;&lt;/td&gt;&lt;/tr&gt;
&lt;/tbody&gt;&lt;/table&gt;
&lt;br /&gt;
&lt;ul style="text-align: left;"&gt;
&lt;li&gt;If we declare a enum in java compiler is going to transform that to a class concept so in the .class file that enum is structured as class. you can see a &amp;lt;&amp;lt;enum name.class&amp;gt;&amp;gt; file where you have stored your .class file.&lt;/li&gt;
&lt;li&gt;If we declare element inside enum that is constant. So they are public static and final.&lt;/li&gt;
&lt;li&gt;Every enum constant is an object of the type enum&lt;/li&gt;
&lt;/ul&gt;
&lt;div&gt;
Now let us see in practical how it works. Lets us take the first example..&lt;br /&gt;
&lt;br /&gt;
&lt;pre class="java" name="code"&gt;enum Month
{
JAN,FEB,MAR;
//note semicolon(;) is optional here
}


&lt;/pre&gt;
Compiler will transform that in to the class file as..&lt;br /&gt;
&lt;pre class="java" name="code"&gt;Class Month
{
//for JAN
public static final Month JAN=new Month();
//similarly for FEB and MAR
public static final Month FEB=new Month();
public static final Month MAR=new Month();
}
&lt;/pre&gt;
Based on the discussion we can say ..&lt;br /&gt;
&lt;div class="Blue_hearder"&gt;
Every enum constant is always static hence we can always access them using enum name &lt;/div&gt;
&lt;br /&gt;
&lt;pre class="java" name="code"&gt;enum Month{
JAN,FEB,MAR;
}
class testenum2
{
public static void main(String... Args)
{
Month m=Month.JAN;
System.out.println(m);
}

}

&lt;/pre&gt;
output: JAN&lt;br /&gt;
&lt;div class="Blue_hearder"&gt;
&lt;br /&gt;
&lt;ul style="text-align: left;"&gt;
&lt;li&gt;Inside every enum toString() method is internally implemented to return the name of the constant.&lt;/li&gt;
&lt;li&gt;We can declare enum inside of a class and outside of a class.If we declare inside of a class compiler will treat that as inner class.&lt;br /&gt;
The applicable modifiers are 1. public 2. &amp;lt;default&amp;gt; 3. strictfp 4.private 5. protected 6.static&amp;nbsp;&lt;/li&gt;
&lt;li&gt;if we put enum outside of the class then compiler will treat it as different class. Hence the modifier would be public,&amp;lt;default&amp;gt;,strictfp&amp;nbsp;&lt;/li&gt;
&lt;/ul&gt;
&lt;/div&gt;
so &lt;br /&gt;
&lt;pre class="java" name="code"&gt;enum Month{
JAN,FEB,MAR;
}
class testenum2
{
public static void main(String... Args)
{
Month m=Month.JAN;
System.out.println(m);
}

}

&lt;/pre&gt;
This is a valid deceleration&lt;br /&gt;
&lt;pre class="java" name="code"&gt;class testenum2
{
enum Month{
JAN,FEB,MAR;
}
public static void main(String... Args)
{
Month m=Month.JAN;
System.out.println(m);
}

}

&lt;/pre&gt;
This is also a valid deceleration.&lt;br /&gt;
&lt;div class="Note"&gt;
We can not declare an enum inside of a method. If so, Compiler will throw Compile time exception. &lt;br /&gt;
&lt;br /&gt;&lt;/div&gt;
let us check out that example..&lt;br /&gt;
&lt;pre class="java" name="code"&gt;class testenum2
{
public static void main(String... Args)
{
Month m=Month.JAN;
System.out.println(m);
}
public static void somemethod();
{
enum Month{
JAN,FEB,MAR;
}
}
}
&lt;/pre&gt;
here well get the compiler error as..&lt;br /&gt;
E:\myProgram\testenum2.java:11: error: enum types must not be local&lt;br /&gt;
enum Month{&lt;br /&gt;
^&lt;br /&gt;
1 error&lt;br /&gt;
&lt;a href="http://2.bp.blogspot.com/-MPy9iiUBUVI/UaTufC2xloI/AAAAAAAARg4/1AShyMgBHDU/s1600/enum+error.PNG" imageanchor="1"&gt;&lt;img border="0" height="130" src="http://2.bp.blogspot.com/-MPy9iiUBUVI/UaTufC2xloI/AAAAAAAARg4/1AShyMgBHDU/s640/enum+error.PNG" width="640" /&gt;&lt;/a&gt;&lt;br /&gt;
&lt;br /&gt;
When I said new enum is more powerful after 1.5 version of java.In new enum, we can add constant, method, constructor, normal variables.&lt;br /&gt;
Even enum can contain main method. We can also invoke enum class directly from command prompt.&lt;br /&gt;
&lt;pre class="java" name="code"&gt;enum testenum21
{
JAN,FEB,MAR;
public static void main(String... Args)
{
System.out.println("Runing enum main method");
}
}

&lt;/pre&gt;
output:&lt;br /&gt;
C:\Documents and Settings\anichatt.APPLICATIONS&amp;gt;javac E:\myProgram\testenum21.java&lt;br /&gt;
C:\Documents and Settings\anichatt.APPLICATIONS&amp;gt;java testenum21&lt;br /&gt;
Runing enum main method&lt;br /&gt;
&lt;div class="separator" style="clear: both; text-align: center;"&gt;
&lt;a href="http://1.bp.blogspot.com/-rQ5609RwgG4/UaT8YlT94kI/AAAAAAAARhI/C5dC0Vp7o9k/s1600/mainmethodenum.PNG" imageanchor="1" style="margin-left: 1em; margin-right: 1em;"&gt;&lt;img border="0" height="74" src="http://1.bp.blogspot.com/-rQ5609RwgG4/UaT8YlT94kI/AAAAAAAARhI/C5dC0Vp7o9k/s640/mainmethodenum.PNG" width="640" /&gt;&lt;/a&gt;&lt;/div&gt;
&lt;div class="Note"&gt;
&lt;br /&gt;
&lt;ul style="text-align: left;"&gt;
&lt;li&gt;In addition to constant if other members(methods) other than constant are taken, list of constant should be in the written in the first line.&lt;/li&gt;
&lt;li&gt;The constants must end with semicolon.&lt;/li&gt;
&lt;li&gt;No constants are allowed to write after method name.&lt;/li&gt;
&lt;li&gt;If the enum is having only method inside in, then the firstline should be empty statement(i.e only semi colon)&amp;nbsp;&lt;/li&gt;
&lt;li&gt;empty enum is valid in java.&lt;/li&gt;
&lt;/ul&gt;
&lt;/div&gt;
let us check the standards one by one..&lt;br /&gt;
The first line should be constant deceleration and it must end with semicolon &lt;br /&gt;
&lt;pre class="java" name="code"&gt;enum testenum21
{
JAN,FEB,MAR;

public static void somemethod()
{
System.out.println("do something");
}
}
&lt;/pre&gt;
This syntax is valid and semicolon is mandate&lt;br /&gt;
&lt;br /&gt;
Let us check out if we don't give semicolon what will happen&lt;br /&gt;
&lt;br /&gt;
&lt;pre class="java" name="code"&gt;enum testenum21
{
JAN,FEB,MAR

public static void somemethod()
{
System.out.println("do something");
}
}
&lt;/pre&gt;
The output is :&lt;br /&gt;
E:\myProgram\testenum21.java:4: error: ',', '}', or ';' expected&lt;br /&gt;
public static void somemethod()&lt;br /&gt;
^&lt;br /&gt;
E:\myProgram\testenum21.java:4: error: '}' expected&lt;br /&gt;
public static void somemethod()&lt;br /&gt;
^&lt;br /&gt;
E:\myProgram\testenum21.java:7: error: class, interface, or enum expected&lt;br /&gt;
}&lt;br /&gt;
^&lt;br /&gt;
3 errors&lt;br /&gt;
&lt;a href="http://2.bp.blogspot.com/-Vu_AFd-sw4U/UaUChVuB5gI/AAAAAAAARhY/62kQkESRndE/s1600/semicolon+error.PNG" imageanchor="1"&gt;&lt;img border="0" height="140" src="http://2.bp.blogspot.com/-Vu_AFd-sw4U/UaUChVuB5gI/AAAAAAAARhY/62kQkESRndE/s640/semicolon+error.PNG" width="640" /&gt;&lt;/a&gt;&lt;/div&gt;
Let us see how it behaves with constants to declared after method:&lt;br /&gt;
&lt;pre class="java" name="code"&gt;enum testenum21
{
public static void somemethod()
{
System.out.println("do something");
}
JAN,FEB,MAR;
}
&lt;/pre&gt;
The output: Compilation error:&lt;br /&gt;
E:\myProgram\testenum21.java:2: error: &lt;identifier&gt; expected&lt;br /&gt;
{&lt;br /&gt;
^&lt;br /&gt;
E:\myProgram\testenum21.java:4: error: ',', '}', or ';' expected&lt;br /&gt;
public static void somemethod()&lt;br /&gt;
^&lt;br /&gt;
E:\myProgram\testenum21.java:4: error: '}' expected&lt;br /&gt;
public static void somemethod()&lt;br /&gt;
^&lt;br /&gt;
E:\myProgram\testenum21.java:7: error: class, interface, or enum expected&lt;br /&gt;
}&lt;br /&gt;
^&lt;br /&gt;
E:\myProgram\testenum21.java:9: error: class, interface, or enum expected&lt;br /&gt;
}&lt;br /&gt;
^&lt;br /&gt;
5 errors&lt;br /&gt;
&lt;br /&gt;
&lt;a href="http://4.bp.blogspot.com/-dTEVPR4AAQE/UaUDq7KIo_I/AAAAAAAARho/B4IaTVE81s4/s1600/semicolon+error.PNG" imageanchor="1"&gt;&lt;img border="0" height="212" src="http://4.bp.blogspot.com/-dTEVPR4AAQE/UaUDq7KIo_I/AAAAAAAARho/B4IaTVE81s4/s640/semicolon+error.PNG" width="640" /&gt;&lt;/a&gt;&lt;br /&gt;
&lt;/identifier&gt;&lt;br /&gt;
&lt;br /&gt;
Similar compilation error will happen if and only if methods are declared inside enum without blank statement:&lt;br /&gt;
&lt;pre class="java" name="code"&gt;enum testenum21
{
public static void somemethod()
{
System.out.println("do something");
}

}
&lt;/pre&gt;
This syntax is also invalid.&lt;br /&gt;
The modified version will be something like written below with an empty statement.&lt;br /&gt;
&lt;pre class="java" name="code"&gt;enum testenum21
{
;
//this semicolon means an empty statement.
public static void somemethod()
{
System.out.println("do something");
}

}
&lt;/pre&gt;
Also empty enum is valid...&lt;br /&gt;
&lt;br /&gt;
&lt;pre class="java" name="code"&gt;enum testenum21
{

}
&lt;/pre&gt;
&lt;div class="Blue_hearder"&gt;
Final points to remember:&lt;br /&gt;
&lt;br /&gt;
&lt;ul style="text-align: left;"&gt;
&lt;li&gt;Every enum is direct child of java.lang.Enum class.&lt;/li&gt;
&lt;li&gt;It is an abstract class&lt;/li&gt;
&lt;li&gt;Hence it becomes a base class for java enum&lt;/li&gt;
&lt;li&gt;This is also a direct child of Object&lt;/li&gt;
&lt;li&gt;enum implements comparable and serializable interface&lt;/li&gt;
&lt;/ul&gt;
&lt;br /&gt;
&lt;br /&gt;&lt;/div&gt;
&lt;/div&gt;&lt;img src="http://feeds.feedburner.com/~r/blogspot/TerSJ/~4/NJJkgxYmcr4" height="1" width="1"/&gt;</description><link>http://feedproxy.google.com/~r/blogspot/TerSJ/~3/NJJkgxYmcr4/enum-concept-simplified-in-java.html</link><author>ani01104@gmail.com (Madhumita)</author><media:thumbnail url="http://4.bp.blogspot.com/-1RwrG6AJN90/UaTjm0T0LrI/AAAAAAAARgo/a4BlzLDqf1w/s72-c/enum.jpg" height="72" width="72" /><thr:total>0</thr:total><feedburner:origLink>http://www.askqtp.com/2013/05/enum-concept-simplified-in-java.html</feedburner:origLink></item><item><guid isPermaLink="false">tag:blogger.com,1999:blog-2981436578666077634.post-5448431476216804953</guid><pubDate>Sun, 19 May 2013 19:06:00 +0000</pubDate><atom:updated>2013-05-27T11:16:41.773+05:30</atom:updated><category domain="http://www.blogger.com/atom/ns#">java</category><category domain="http://www.blogger.com/atom/ns#">ParseInt</category><title>How Integer.ParseInt Method Works In Java</title><description>&lt;div dir="ltr" style="text-align: left;" trbidi="on"&gt;
&lt;div class="separator" style="clear: both; text-align: center;"&gt;
&lt;a href="http://4.bp.blogspot.com/-5szaafVbA_o/UZUjpLXvbqI/AAAAAAAARfM/mJxvAYh7L2o/s1600/parseint.jpg" imageanchor="1" style="clear: left; float: left; margin-bottom: 1em; margin-right: 1em;"&gt;&lt;img border="0" height="128" src="http://4.bp.blogspot.com/-5szaafVbA_o/UZUjpLXvbqI/AAAAAAAARfM/mJxvAYh7L2o/s320/parseint.jpg" width="320" /&gt;&lt;/a&gt;&lt;/div&gt;
&lt;span style="background-color: #f3f3f3;"&gt;Integer.ParseInt&lt;/span&gt;&amp;nbsp;is very commonly used method in java.The parameter to this method will be String. So It works on String only.But what kind of String??&lt;br /&gt;
Those which can represent ASCII values for digit(0-...9). Remember&amp;nbsp;&lt;span style="background-color: #f3f3f3;"&gt;Integer.ParseInt only works on string representation of numeric value but not something like "five".&lt;/span&gt;&lt;br /&gt;
&lt;br /&gt;
&lt;pre class="java" name="code"&gt;int x=Integer.parseInt("9");
//valid
int y=Integer.parseInt("nine");
//invalid compilation error

&lt;/pre&gt;
Let us check the syntax:&lt;br /&gt;
&lt;div class="Blue_hearder"&gt;
&lt;br /&gt;
&lt;ul style="text-align: left;"&gt;
&lt;li&gt;static int parseInt(String s) // here s is the string representation of Numeric value&lt;/li&gt;
&lt;li&gt;static int parseInt(String s, int radix) //This returns an integer, given a string representation of decimal, binary, octal, or hexadecimal (radix equals 10, 2, 8, or 16 respectively) numbers as input.&lt;/li&gt;
&lt;/ul&gt;
&lt;/div&gt;
Let us check out one example:&lt;br /&gt;
&lt;br /&gt;
&lt;pre class="java" name="code"&gt;public class parseTest{ 

   public static void main(String args[]){
      int x =Integer.parseInt("5");
      double c = Double.parseDouble("8");
      int b = Integer.parseInt("444",16);

      System.out.println(x);
      System.out.println(c);
      System.out.println(b);
   }


&lt;/pre&gt;
Output&lt;br /&gt;
5&lt;br /&gt;
8.00&lt;br /&gt;
1092&lt;/div&gt;&lt;img src="http://feeds.feedburner.com/~r/blogspot/TerSJ/~4/CLlo0ljKFA8" height="1" width="1"/&gt;</description><link>http://feedproxy.google.com/~r/blogspot/TerSJ/~3/CLlo0ljKFA8/how-integerparseint-method-works-in-java.html</link><author>ani01104@gmail.com (Madhumita)</author><media:thumbnail url="http://4.bp.blogspot.com/-5szaafVbA_o/UZUjpLXvbqI/AAAAAAAARfM/mJxvAYh7L2o/s72-c/parseint.jpg" height="72" width="72" /><thr:total>0</thr:total><feedburner:origLink>http://www.askqtp.com/2013/05/how-integerparseint-method-works-in-java.html</feedburner:origLink></item><item><guid isPermaLink="false">tag:blogger.com,1999:blog-2981436578666077634.post-6949469469708735607</guid><pubDate>Sun, 19 May 2013 16:39:00 +0000</pubDate><atom:updated>2013-05-19T22:54:56.259+05:30</atom:updated><category domain="http://www.blogger.com/atom/ns#">Assertion</category><category domain="http://www.blogger.com/atom/ns#">java</category><category domain="http://www.blogger.com/atom/ns#">Assert</category><title>Do's and Don'ts While Working With Assertions In Java</title><description>&lt;div dir="ltr" style="text-align: left;" trbidi="on"&gt;&lt;div class="separator" style="clear: both; text-align: center;"&gt;&lt;a href="http://2.bp.blogspot.com/-1lV1zLcWHTY/UZj88ybkhnI/AAAAAAAARgI/ZDPMlm819ZY/s1600/when+to+use.jpg" imageanchor="1" style="clear: left; float: left; margin-bottom: 1em; margin-right: 1em;"&gt;&lt;img border="0" src="http://2.bp.blogspot.com/-1lV1zLcWHTY/UZj88ybkhnI/AAAAAAAARgI/ZDPMlm819ZY/s1600/when+to+use.jpg" /&gt;&lt;/a&gt;&lt;/div&gt;In my last post (&lt;a href="http://www.askqtp.com/2013/05/assertion-concept-simplified-in-java.html"&gt;http://www.askqtp.com/2013/05/assertion-concept-simplified-in-java.html&lt;/a&gt;). I have briefed how to work with assertion. Now in this post let us check out few rules and best&amp;nbsp;practices to work with assertion.&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
Let us follow few common rules:&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;div class="Note"&gt;Do not mix business logic/programming logic with Assertion. As assertion will not run always until assertion is enabled.(Please refer &lt;a href="http://www.askqtp.com/2013/05/assertion-concept-simplified-in-java.html"&gt;here &lt;/a&gt;for more) &lt;/div&gt;&lt;br /&gt;
Good coding practice:&lt;br /&gt;
&lt;pre class="java" name="code"&gt;amount_withdraw(int amount)
{
//some validation
if((amount&amp;lt;100 || amount&amp;gt;=5000))
System.out.print("This amount can not be deducted");
else
//let user deduct the amount
}
&lt;/pre&gt;Bad coding practice:&lt;br /&gt;
&lt;pre class="java" name="code"&gt;amount_withdraw(int amount)
{
//some validation
assert(amount&amp;gt;=100)||assert(amount&amp;lt;5000)
//let the user allow to get data
}&lt;/pre&gt;&lt;br /&gt;
&lt;div class="Note"&gt;During debugging,in our program, the best place to put assertion where control does not reach or not allowed to reach.(Please refer &lt;a href="http://www.askqtp.com/2013/05/assertion-concept-simplified-in-java.html"&gt;here &lt;/a&gt;for more) &lt;/div&gt;Good coding practice:&lt;br /&gt;
&lt;pre class="java" name="code"&gt;switch(month_val)
{
case 1: System.out.println("Jan");break;
case 2: System.out.println("Feb");break;
case 3: System.out.println("Mar");break;
......
......
case 12: System.out.println("Dec");break;
default: assert(false);
}
&lt;/pre&gt;This is not violating 1st rule ..if the month value is anything other than 1 to 12.We need to check. Hence it is valid.&lt;br /&gt;
&lt;div class="Note"&gt;&lt;br /&gt;
&lt;ul style="text-align: left;"&gt;&lt;li&gt;It is a bad practice to use assertion inside public method.As the public methods will be accessed by outside coders and method consumers, they will not be knowing whether to enable or disable assertion.&lt;/li&gt;
&lt;li&gt;Secondly it is always good to have assert for private method as the method designer is local and can check the assertion&lt;/li&gt;
&lt;li&gt;Thirdly, this not good to put assert while validating command line argument. This can be argument of public main method.(Please refer &lt;a href="http://www.askqtp.com/2013/05/assertion-concept-simplified-in-java.html"&gt;here &lt;/a&gt;for more)&lt;/li&gt;
&lt;/ul&gt;&lt;/div&gt;Let us check with some example.&lt;br /&gt;
&lt;pre class="java" name="code"&gt;class assertTest{
public static void main(String... args)
{
asset(args.length&amp;lt;5):"Need more inputs";

}
}&lt;/pre&gt;&lt;br /&gt;
&lt;div class="Note"&gt;&lt;br /&gt;
&lt;ul style="text-align: left;"&gt;&lt;li&gt;All the assertion errors are child class of Error. Super class Error is unchecked during compile time hence assertion error will be unchecked.&lt;/li&gt;
&lt;li&gt;All the assertion errors will be raised when the assertion will fail during run time&lt;/li&gt;
&lt;li&gt;&amp;nbsp;It is legal to catch assertion error but the objective of assertion is to fail if something is not as per programmer's expectation.So it is not&amp;nbsp;recommended to use.(Please refer &lt;a href="http://www.askqtp.com/2013/05/assertion-concept-simplified-in-java.html"&gt;here &lt;/a&gt;for more)&lt;/li&gt;
&lt;/ul&gt;&lt;/div&gt;&lt;pre class="java" name="code"&gt;class assertTest{
public static void main(string... args)
{

int a=12;
-----
-----
-----
try
{
assert(a&gt;12);
}
catch(AssertionError e)
{
//some code
}
}
}

&lt;/pre&gt;&lt;/div&gt;&lt;img src="http://feeds.feedburner.com/~r/blogspot/TerSJ/~4/0hIrC9lPE7c" height="1" width="1"/&gt;</description><link>http://feedproxy.google.com/~r/blogspot/TerSJ/~3/0hIrC9lPE7c/dos-and-donts-while-working-with.html</link><author>ani01104@gmail.com (Madhumita)</author><media:thumbnail url="http://2.bp.blogspot.com/-1lV1zLcWHTY/UZj88ybkhnI/AAAAAAAARgI/ZDPMlm819ZY/s72-c/when+to+use.jpg" height="72" width="72" /><thr:total>0</thr:total><feedburner:origLink>http://www.askqtp.com/2013/05/dos-and-donts-while-working-with.html</feedburner:origLink></item><item><guid isPermaLink="false">tag:blogger.com,1999:blog-2981436578666077634.post-6408945714437310237</guid><pubDate>Fri, 17 May 2013 20:22:00 +0000</pubDate><atom:updated>2013-05-19T21:52:09.673+05:30</atom:updated><category domain="http://www.blogger.com/atom/ns#">Assertion</category><category domain="http://www.blogger.com/atom/ns#">java</category><category domain="http://www.blogger.com/atom/ns#">Assert</category><title>Assertion Concept Simplified In Java</title><description>&lt;div dir="ltr" style="text-align: left;" trbidi="on"&gt;&lt;div dir="ltr" style="text-align: left;" trbidi="on"&gt;&lt;div class="separator" style="clear: both; text-align: center;"&gt;&lt;a href="http://4.bp.blogspot.com/-QDZ798GAT4I/UZZ5RaD2wAI/AAAAAAAARfg/IsZpoyadN5E/s1600/using+assertion+in+java.jpg" imageanchor="1" style="clear: left; float: left; margin-bottom: 1em; margin-right: 1em;"&gt;&lt;img border="0" src="http://4.bp.blogspot.com/-QDZ798GAT4I/UZZ5RaD2wAI/AAAAAAAARfg/IsZpoyadN5E/s1600/using+assertion+in+java.jpg" /&gt;&lt;/a&gt;&lt;/div&gt;In our day to day coding we frequently use &lt;span style="background-color: #eeeeee;"&gt;S&lt;/span&gt;&lt;span style="background-color: #f3f3f3;"&gt;ystem.out.println()&lt;/span&gt; statement to debug our code. This is very popular and simple way to debug our development code or test code.One problem of this approach, we can not keep these&amp;nbsp;&lt;span style="background-color: #f3f3f3;"&gt;System.out.println()&lt;/span&gt; statement as it is. we need to remove this statement before releasing this code. It is basically overhead for any coder. To overcome this problem Java has come up with a concept called Assertion in java 1.4. prior to java 1.4, in Java 1.3 version it was&amp;nbsp;declared&amp;nbsp;as Indentifier.&lt;br /&gt;
The concepts are as follows..&lt;br /&gt;
&lt;br /&gt;
&lt;ul style="text-align: left;"&gt;&lt;li&gt;The main advantage of assertion is like &lt;span style="background-color: #f3f3f3;"&gt;System.out.println&lt;/span&gt; statement, we don't need to delete these statements &amp;nbsp;as they do not get executed by default.&lt;/li&gt;
&lt;li&gt;Secondly after release if any bug has come to that particular module we need to fix that. Post bug fix or during debugging again we don't need to enter &lt;span style="background-color: #eeeeee;"&gt;System.out.println&lt;/span&gt;&amp;nbsp; &amp;nbsp;or Assert statement. It is already available inside the code hence only enabling that will reduce our work.&lt;/li&gt;
&lt;li&gt;So it exists in development and test instance but not in production environment&lt;/li&gt;
&lt;li&gt;It is a better alternative for &lt;span style="background-color: #f3f3f3;"&gt;System.out.println&lt;/span&gt; statement.&lt;/li&gt;
&lt;/ul&gt;&lt;div&gt;Let us see more details:&lt;/div&gt;&lt;div&gt;&lt;pre class="java" name="code"&gt;class assertTest
{
public static void main(String[] args)
{
int assert=13;
System.out.println(assert);

}
}

&lt;/pre&gt;Compiler will throw errors saying:&lt;br /&gt;
&lt;br /&gt;
javac E:\myProgram\assertTest.java&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
E:\myProgram\assertTest.java:5: error: as of release 1.4, 'assert' is a keyword,and may not be used as an identifier&lt;br /&gt;
int assert=13;&lt;br /&gt;
&amp;nbsp; &amp;nbsp; &amp;nbsp;^&lt;br /&gt;
(use -source 1.3 or lower to use 'assert' as an identifier)&lt;br /&gt;
E:\myProgram\assertTest.java:6: error: as of release 1.4, 'assert' is a keyword,and may not be used as an identifier&lt;br /&gt;
System.out.println(assert);&lt;br /&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; &amp;nbsp; &amp;nbsp; ^&lt;br /&gt;
(use -source 1.3 or lower to use 'assert' as an identifier)&lt;br /&gt;
2 errors&lt;/div&gt;But if we compile against java 1.3, it will compile fine but with warning.&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
javac -source 1.3 E:\myProgram\assertTest.java&lt;br /&gt;
warning: [options] bootstrap class path not set in conjunction with -source 1.3&lt;br /&gt;
E:\myProgram\assertTest.java:5: warning: as of release 1.4, 'assert' is a keywor&lt;br /&gt;
d, and may not be used as an identifier&lt;br /&gt;
int assert=13;&lt;br /&gt;
^&lt;br /&gt;
(use -source 1.4 or higher to use 'assert' as a keyword)&lt;br /&gt;
E:\myProgram\assertTest.java:6: warning: as of release 1.4, 'assert' is a keywor&lt;br /&gt;
d, and may not be used as an identifier&lt;br /&gt;
System.out.println(assert);&lt;br /&gt;
^&lt;br /&gt;
(use -source 1.4 or higher to use 'assert' as a keyword)&lt;br /&gt;
3 warnings&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
let us see one more example..&lt;br /&gt;
&lt;pre class="java" name="code"&gt;class assertTest
{
public static void main(String[] args)
{
assert(false);
System.out.println(assert);

}
}

&lt;/pre&gt;&lt;br /&gt;
For this case if we compile with source -1.3, we will get compiler error. but similarly if we compile against 1.4 or upgraded version of java. We will not get the compilation error.&lt;br /&gt;
&lt;div class="Note"&gt;&lt;b&gt;Conclusion:&lt;/b&gt; assert could have been used as an identifier in java 1.2 or java 1.3 and in java 1.4 it was promoted as a keyword.So, now ,java 1.4&amp;nbsp;onward assert can not be used as an identifier.&amp;nbsp;&lt;/div&gt;&lt;b&gt;Types of Assert:&lt;/b&gt;&lt;br /&gt;
&lt;br /&gt;
&lt;ul style="text-align: left;"&gt;&lt;li&gt;Simple&lt;/li&gt;
&lt;li&gt;Augmented&lt;/li&gt;
&lt;/ul&gt;&lt;table bgcolor="#e4eded" border="0" bordercolor="#000000" style="width: 100%;"&gt;&lt;tbody&gt;
&lt;tr&gt; &lt;td&gt;&lt;b&gt;&lt;span style="color: #004080;"&gt;Simple Assertion:&lt;/span&gt;&lt;/b&gt;&lt;/td&gt;&lt;/tr&gt;
&lt;/tbody&gt;&lt;/table&gt;The syntax for simple assertion is&lt;br /&gt;
assert(b)&lt;br /&gt;
Where b should be&amp;nbsp;Boolean.&lt;br /&gt;
It signifies that up to assert statement if b value calculated as true then rest of the statements (below assert statements will be executed). If the assert value calculated as false then it will throw an assertion error and terminate the program.&lt;br /&gt;
let us check out one sample program&lt;br /&gt;
&lt;pre class="java" name="code"&gt;class assertTest{
public static void main(String... args)
{
int a=12;
//do some calculation
//do some calculation
//do some calculation
//do some calculation
//do some calculation
//do some calculation
//do some calculation
//do some calculation
assert(a&amp;gt;12);
//do some calculation
//do some calculation
//do some calculation
//do some calculation
//do some calculation
System.out.println(a); 
}
}
&lt;/pre&gt;The output for this program will be:&lt;br /&gt;
&lt;br /&gt;
javac assertTest.java&lt;br /&gt;
java assertTest&lt;br /&gt;
output:12&lt;br /&gt;
now ..&lt;br /&gt;
java -ea assertTest&lt;br /&gt;
output:Assertion Error&lt;br /&gt;
Exception in thread "main" java.lang.AssertionError&lt;br /&gt;
at assertTest.main(assertTest.java:6)&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;div class="Note"&gt;&lt;b&gt;Why?&lt;/b&gt;&lt;br /&gt;
By default the assertions are disabled , but by using "-ea" we are enabling the assertion.&lt;/div&gt;&lt;/div&gt;Now if you see the output of the previous program, by seeing the console it is very tough to understand what went wrong.If it is small program then it is ok.We can identify the problem.But think about a scenario where thousands of lines are getting executed.&lt;br /&gt;
To get more clarity to the program java has come up with upgrade version of assertion called Augmented version assertion&lt;br /&gt;
&lt;br /&gt;
&lt;table bgcolor="#e4eded" border="0" bordercolor="#000000" style="width: 100%;"&gt;&lt;tbody&gt;
&lt;tr&gt; &lt;td&gt;&lt;b&gt;&lt;span style="color: #004080;"&gt;Augmented Assertion:&lt;/span&gt;&lt;/b&gt;&lt;/td&gt;&lt;/tr&gt;
&lt;/tbody&gt;&lt;/table&gt;So the main advantage of augmented version is that in the console we can append some description with assertion error.&lt;br /&gt;
The syntax for the augmented assertion is assert(b):c;&lt;br /&gt;
where b is boolean and c can be any data type&lt;br /&gt;
Now let us modify our previous program little bit:&lt;br /&gt;
&lt;pre class="java" name="code"&gt;class assertTest{
public static void main(String... args)
{
int a=12;
//do some calculation
//do some calculation
//do some calculation
//do some calculation
//do some calculation
//do some calculation
//do some calculation
//do some calculation
assert(a&amp;gt;12):"The value of a should be greater than 12";
//do some calculation
//do some calculation
//do some calculation
//do some calculation
//do some calculation
System.out.println(a); 
}
}
&lt;/pre&gt;javac assertTest.java&lt;br /&gt;
java assertTest&lt;br /&gt;
output:12&lt;br /&gt;
now ..&lt;br /&gt;
java -ea assertTest&lt;br /&gt;
The output:&lt;br /&gt;
Exception in thread "main" java.lang.AssertionError: &lt;span style="background-color: #eeeeee;"&gt;The value of a should be greater than 12&lt;/span&gt;&lt;br /&gt;
at assertTest.main(assertTest.java:6)&lt;br /&gt;
So we are getting bit more clarity from the code.&lt;br /&gt;
&lt;div class="Blue_hearder"&gt;&lt;b&gt;Augment Assertion Rule-1&lt;/b&gt;&lt;br /&gt;
For this augmented assertion if the first argument is true(value of b)then the second argument c(some string output for this case) will not be evaluated.&lt;/div&gt;lets see that:&lt;br /&gt;
&lt;pre class="java" name="code"&gt;class assertTest{
public static void main(String... args)
{
int a=12;
//do some calculation
//do some calculation
//do some calculation
//do some calculation
//do some calculation
//do some calculation
//do some calculation
//do some calculation
assert(a==12):++a;
//do some calculation
//do some calculation
//do some calculation
//do some calculation
//do some calculation
System.out.println(a); 
}
}
&lt;/pre&gt;javac assertTest.java&lt;br /&gt;
java assertTest&lt;br /&gt;
output:12&lt;br /&gt;
now ..&lt;br /&gt;
java -ea assertTest&lt;br /&gt;
output:12&lt;br /&gt;
This time the assertion passed hence ++a was not executed .&lt;br /&gt;
&lt;br /&gt;
Now let us see the same example by failing the assertion condition ...this time b fails so c should get executed&lt;br /&gt;
&lt;pre class="java" name="code"&gt;class assertTest{
public static void main(String... args)
{
int a=12;
//do some calculation
//do some calculation
//do some calculation
//do some calculation
//do some calculation
//do some calculation
//do some calculation
//do some calculation
assert(a&amp;gt;12):++a;
//do some calculation
//do some calculation
//do some calculation
//do some calculation
//do some calculation
System.out.println(a);
}
} 
&lt;/pre&gt;javac assertTest.java&lt;br /&gt;
java assertTest&lt;br /&gt;
output:12&lt;br /&gt;
now ..&lt;br /&gt;
java -ea assertTest&lt;br /&gt;
output:Exception in thread "main" java.lang.AssertionError: 13&lt;br /&gt;
at assertTest.main(assertTest.java:6)&lt;br /&gt;
&lt;br /&gt;
So a value is now incremented by one and got printed.&lt;br /&gt;
&lt;div class="Blue_hearder"&gt;&lt;b&gt;Augment Assertion Rule-2&lt;/b&gt;&lt;br /&gt;
The second argument c can be a method call,and very logically that method should not be a void type.&lt;br /&gt;
&lt;br /&gt;
&lt;/div&gt;So the syntax should be assert(b):method_name();&lt;br /&gt;
let us check out via code:&lt;br /&gt;
&lt;pre class="java" name="code"&gt;class assertTest{
public static void main(String... args)
{
int a=12;
//do some calculation
//do some calculation
//do some calculation
//do some calculation
//do some calculation
//do some calculation
//do some calculation
//do some calculation
assert(a&amp;gt;12):methodxyz();
//do some calculation
//do some calculation
//do some calculation
//do some calculation
//do some calculation
System.out.println(a);
}
public static int methodxyz()
{
return 65;
}
} 
&lt;/pre&gt;&lt;br /&gt;
javac assertTest.java&lt;br /&gt;
java assertTest&lt;br /&gt;
output:12&lt;br /&gt;
now ..&lt;br /&gt;
java -ea assertTest&lt;br /&gt;
output:Exception in thread "main" java.lang.AssertionError: 65&lt;br /&gt;
at assertTest.main(assertTest.java:6)&lt;br /&gt;
&lt;br /&gt;
Now if we change the return type of that function as void , we are going to get compile time error.&lt;br /&gt;
The error details:&lt;br /&gt;
E:\myProgram\assertTest.java:6: error: 'void' type not allowed here&lt;br /&gt;
assert(a&amp;gt;12):methodxyz();&lt;br /&gt;
^&lt;br /&gt;
1 error&lt;br /&gt;
&lt;br /&gt;
&lt;table bgcolor="#e4eded" border="0" bordercolor="#000000" style="width: 100%;"&gt;&lt;tbody&gt;
&lt;tr&gt; &lt;td&gt;&lt;b&gt;&lt;span style="color: #004080;"&gt;Various Possible Runtime Flags &lt;/span&gt;&lt;/b&gt;&lt;/td&gt;&lt;/tr&gt;
&lt;/tbody&gt;&lt;/table&gt;Let us check what are the flags available--&lt;br /&gt;
&lt;div class="CSSTableGenerator"&gt;&lt;table&gt;&lt;tbody&gt;
&lt;tr&gt;                         &lt;td&gt;&lt;br /&gt;
Flags&lt;/td&gt;                         &lt;td&gt;&lt;br /&gt;
Description&lt;/td&gt;                         &lt;/tr&gt;
&lt;tr&gt;                         &lt;td&gt;-ea/-enableassertions&lt;/td&gt;                         &lt;td&gt;To enable assertion in every non-system classes&lt;/td&gt;                         &lt;/tr&gt;
&lt;tr&gt;                         &lt;td&gt;-da/-diaableassrtions&lt;/td&gt;                         &lt;td&gt;To disable assertion in every non-system classes&lt;/td&gt;                         &lt;/tr&gt;
&lt;tr&gt;                         &lt;td&gt;-esa/-enablesystemassertions&lt;/td&gt;                         &lt;td&gt;To enable assertion in every system classes&lt;/td&gt;                   &lt;/tr&gt;
&lt;tr&gt;                         &lt;td&gt;-dsa/-deletesystemassertions&lt;/td&gt;                         &lt;td&gt;To disble assertion in every non-system classes&lt;/td&gt;                         &lt;/tr&gt;
&lt;/tbody&gt;&lt;/table&gt;&lt;/div&gt;&lt;br /&gt;
&lt;br /&gt;
&lt;div class="Note"&gt;In general normal java developers use assertion for non-system classes and java-API developers use assertion for system classes.&lt;br /&gt;
we can use the above flags simultaneously then JVM will consider these flags from left to right.&lt;br /&gt;
java -ea -esa -da -ea-esa-da -dsa -ea testAssert&lt;br /&gt;
the above written syntax is valid.&lt;/div&gt;Let us check out few more examples:&lt;br /&gt;
&lt;a href="http://3.bp.blogspot.com/-i4BTZEM1lk0/UZj2LOEFI5I/AAAAAAAARf4/MjoG2bv0FCk/s1600/packagestructure2.JPG" imageanchor="1"&gt;&lt;img border="0" height="412" src="http://3.bp.blogspot.com/-i4BTZEM1lk0/UZj2LOEFI5I/AAAAAAAARf4/MjoG2bv0FCk/s640/packagestructure2.JPG" width="640" /&gt;&lt;/a&gt;&lt;br /&gt;
In our real time coding we might require to enable assertion against customized classes .&lt;br /&gt;
if our package structure is the picture above then..&lt;br /&gt;
&lt;div class="CSSTableGenerator"&gt;&lt;table&gt;&lt;tbody&gt;
&lt;tr&gt;                         &lt;td&gt;&lt;br /&gt;
Objective&lt;/td&gt;                         &lt;td&gt;&lt;br /&gt;
Required Code&lt;/td&gt;                                              &lt;/tr&gt;
&lt;tr&gt;                         &lt;td&gt;&lt;br /&gt;
To enable assertions only for B class&lt;/td&gt;                         &lt;td&gt;&lt;br /&gt;
java -ea:package1:B&lt;/td&gt;                                              &lt;/tr&gt;
&lt;tr&gt;                         &lt;td&gt;&lt;br /&gt;
To enable assertions only in B and D classes&lt;/td&gt;                         &lt;td&gt;&lt;br /&gt;
java -ea:package1:B -ea:package1.package2.D&lt;/td&gt;                                            &lt;/tr&gt;
&lt;tr&gt;                         &lt;td&gt;&lt;br /&gt;
To enable assertion everywhere inside package1 except B class&lt;/td&gt;                         &lt;td&gt;&lt;br /&gt;
java -ea:package1... -da:package1.B&lt;/td&gt;                                              &lt;/tr&gt;
&lt;tr&gt;                         &lt;td&gt;&lt;br /&gt;
To enable assertion everywhere inside package1 except package2 classes&lt;/td&gt;                         &lt;td&gt;&lt;br /&gt;
java -ea:package1... -da:package1.package2...&lt;/td&gt;                                             &lt;/tr&gt;
&lt;tr&gt;                         &lt;td&gt;&lt;br /&gt;
To enable assertions everywhere inside package1&lt;/td&gt;                         &lt;td&gt;&lt;br /&gt;
java -ea:package1...&lt;/td&gt;                                             &lt;/tr&gt;
&lt;/tbody&gt;&lt;/table&gt;&lt;/div&gt;&lt;br /&gt;
&lt;div class="Note"&gt;&lt;b&gt; Conclusion:&lt;/b&gt;&lt;br /&gt;
So we can enable or disable assertions classwise or package wise.&lt;br /&gt;
&lt;/div&gt;&lt;br /&gt;
&lt;/div&gt;&lt;img src="http://feeds.feedburner.com/~r/blogspot/TerSJ/~4/KMnz2nOQGdw" height="1" width="1"/&gt;</description><link>http://feedproxy.google.com/~r/blogspot/TerSJ/~3/KMnz2nOQGdw/assertion-concept-simplified-in-java.html</link><author>ani01104@gmail.com (Madhumita)</author><media:thumbnail url="http://4.bp.blogspot.com/-QDZ798GAT4I/UZZ5RaD2wAI/AAAAAAAARfg/IsZpoyadN5E/s72-c/using+assertion+in+java.jpg" height="72" width="72" /><thr:total>0</thr:total><feedburner:origLink>http://www.askqtp.com/2013/05/assertion-concept-simplified-in-java.html</feedburner:origLink></item><item><guid isPermaLink="false">tag:blogger.com,1999:blog-2981436578666077634.post-8989257325207509640</guid><pubDate>Wed, 15 May 2013 19:26:00 +0000</pubDate><atom:updated>2013-05-16T11:50:32.351+05:30</atom:updated><category domain="http://www.blogger.com/atom/ns#">java</category><category domain="http://www.blogger.com/atom/ns#">HAS-A</category><category domain="http://www.blogger.com/atom/ns#">HAS-A relationship</category><title>What Is HAS-A Relationship In Java??</title><description>&lt;br /&gt;
&lt;div class="separator" style="clear: both; text-align: center;"&gt;&lt;a href="http://1.bp.blogspot.com/-S85gOJiR0NQ/UZOniySisaI/AAAAAAAARe8/30XEJa-sat4/s1600/Has-A.jpg" imageanchor="1" style="clear: left; float: left; margin-bottom: 1em; margin-right: 1em;"&gt;&lt;img border="0" src="http://1.bp.blogspot.com/-S85gOJiR0NQ/UZOniySisaI/AAAAAAAARe8/30XEJa-sat4/s1600/Has-A.jpg" /&gt;&lt;/a&gt;&lt;/div&gt;When designing our classes , our basic tendency is to design classes maximum code re usability.&amp;nbsp; Reusable code means less work and maximum output. in this post(&lt;a href="http://www.askqtp.com/2013/05/what-is-is-relationship-and-what-are.html"&gt;http://www.askqtp.com/2013/05/what-is-is-relationship-and-what-are.html&lt;/a&gt;) we have seen how to make code reusable by using extension.&lt;br /&gt;
We divide our classes into child and parent and then try to put check a IS-A relationship test.&lt;br /&gt;
&lt;a href="http://www.askqtp.com/2013/05/cyclic-inheritance-prohibited.html"&gt;http://www.askqtp.com/2013/05/cyclic-inheritance-prohibited.html&lt;/a&gt;&amp;nbsp; in this post I have shown what are the prohibited concept of java in terms of extension.&lt;br /&gt;
Now think about a scenario, I have a Tree class, I have Leave class and I have Root class as well.&lt;br /&gt;
Now Tree class has a methods like-&lt;br /&gt;
&lt;ul style="text-align: left;"&gt;&lt;li&gt;Consume_water();&lt;/li&gt;
&lt;li&gt;Takes_CO2()&lt;/li&gt;
&lt;li&gt;Release_O2()&lt;/li&gt;
&lt;li&gt;Provide_shelter()&lt;/li&gt;
&lt;/ul&gt;Again for Leaves class we can have the methods&lt;br /&gt;
&lt;ul&gt;&lt;li&gt;Consume_water();&lt;/li&gt;
&lt;li&gt;Takes_CO2()&lt;/li&gt;
&lt;li&gt;Release_O2()&lt;/li&gt;
&lt;/ul&gt;for Root class we can have&amp;nbsp; the methods..&lt;br /&gt;
&lt;ul&gt;&lt;li&gt;Consume_water();&lt;/li&gt;
&lt;li&gt;Provide_strength() &lt;/li&gt;
&lt;/ul&gt;Now if you observe the methods of the classes(Tree,Leaves and Root) we can clearly say that Tree can be super class and Leave and Root can be subclass. By this approach we can get more reusable code.&lt;br /&gt;
so the structure could be for Tree class&lt;br /&gt;
&lt;pre class="java" name="code"&gt;class Tree{
public void Consume_water()
{
//consumes some water
}
Public void Takes_CO2()
{
//takes x amount of CO2
}
public int Release_O2()
{
//return some o2
}
}
&lt;/pre&gt;For Leave class&lt;br /&gt;
&lt;pre class="java" name="code"&gt;class Leave extends Tree
{
//no methods are required as all will come from Tree
}

&lt;/pre&gt;Similarly for Root class&lt;br /&gt;
&lt;pre class="java" name="code"&gt;class Root extends Tree
{
//no methods are required as all will come from Tree
public void Provide_Strength()
{
//provide some strength to tree
}
}

&lt;/pre&gt;Looks like we are good to go!!!&lt;br /&gt;
&lt;br /&gt;
But is it ok?? Surely no. The purpose of Tree is different from Leaves so as the corresponding methods. And to make a parent child relationship the child has to follow IS-A relationship.&lt;br /&gt;
&lt;br /&gt;
Leaves IS(ARE)-A Tree? &lt;br /&gt;
or &lt;br /&gt;
Root IS-A Tree?&lt;br /&gt;
&lt;br /&gt;
Both the answers are false. So this is not a valid parent child relationship. Now the next question is "if we can not extend Root or leaves to Tree , then how to reuse those codes?? if not possible the code redundancy will be higher . Isn't it?&lt;br /&gt;
&lt;br /&gt;
To resolve such problem Java has come up with a concept called &lt;b&gt;HAS-A&lt;/b&gt; Relationship. &lt;br /&gt;
Let us check the feature of HAS-A relationship&lt;br /&gt;
&lt;br /&gt;
&lt;div class="Blue_hearder"&gt;&lt;ul style="text-align: left;"&gt;&lt;li&gt;HAS-A relationship is also known as Composition or Aggregation&amp;nbsp;&lt;/li&gt;
&lt;li&gt;For IS-A relationship there is a keyword available called "extends" but for HAS-A relationship there is no such keyword available,Mostly we use &lt;b&gt;new&lt;/b&gt;.&lt;/li&gt;
&lt;li&gt;Code re usability is the core concept for HAS-A relationship &lt;/li&gt;
&lt;/ul&gt;&lt;/div&gt;&lt;pre class="java" name="code"&gt;Class Tree{
Leaves lvs=new Leaves();
//It means Tree has leaves reference
Root rt=new Root();
//It means Tree has Roots reference

&lt;/pre&gt;&lt;div class="Note"&gt;Even though HAS-A relationship resolves problems of extension.At the same time it increases dependency between the underlying components.&lt;br /&gt;
It creates problem in maintenance of the code. &lt;/div&gt;&lt;br /&gt;
&lt;br /&gt;&lt;img src="http://feeds.feedburner.com/~r/blogspot/TerSJ/~4/QaA03z6xg9s" height="1" width="1"/&gt;</description><link>http://feedproxy.google.com/~r/blogspot/TerSJ/~3/QaA03z6xg9s/what-is-has-relationship-in-java.html</link><author>ani01104@gmail.com (Madhumita)</author><media:thumbnail url="http://1.bp.blogspot.com/-S85gOJiR0NQ/UZOniySisaI/AAAAAAAARe8/30XEJa-sat4/s72-c/Has-A.jpg" height="72" width="72" /><thr:total>0</thr:total><feedburner:origLink>http://www.askqtp.com/2013/05/what-is-has-relationship-in-java.html</feedburner:origLink></item><item><guid isPermaLink="false">tag:blogger.com,1999:blog-2981436578666077634.post-3363598612867060588</guid><pubDate>Wed, 15 May 2013 05:27:00 +0000</pubDate><atom:updated>2013-05-16T11:49:55.475+05:30</atom:updated><category domain="http://www.blogger.com/atom/ns#">Indiblogger</category><category domain="http://www.blogger.com/atom/ns#">Ring The bell</category><category domain="http://www.blogger.com/atom/ns#">Leading Contests</category><title>Indiblogger Organizes Ring The Bell Contest </title><description>&lt;div dir="ltr" style="text-align: left;" trbidi="on"&gt;
&lt;div class="separator" style="clear: both; text-align: center;"&gt;
&lt;a href="http://1.bp.blogspot.com/-PRRskcRAhzc/UZMbInXrtjI/AAAAAAAAReg/wfJiVOgRFms/s1600/ring+the+bail.jpg" imageanchor="1" style="clear: left; float: left; margin-bottom: 1em; margin-right: 1em;"&gt;&lt;img border="0" height="179" src="http://1.bp.blogspot.com/-PRRskcRAhzc/UZMbInXrtjI/AAAAAAAAReg/wfJiVOgRFms/s640/ring+the+bail.jpg" width="640" /&gt;&lt;/a&gt;&lt;/div&gt;
&lt;span class="Apple-style-span" style="color: #111111; font-family: 'Lucida Sans Unicode', Verdana, Arial, sans-serif; font-size: 13px;"&gt;&lt;/span&gt;&lt;br /&gt;
&lt;blockquote&gt;
Laws alone are not enough. Ring The Bell believes in the power of individual and collective action to challenge the habits, norms, and cultures that perpetuate violence. One person adds up to one million; one million acts add up to change.&lt;br /&gt;
You can be a part of the change by telling us how YOU will Ring The Bell, and inspiring your readers to do the same. What action will you take to bring violence against women to a halt? Blog about your experiences, your intentions, and make a promise!--as per indiblogger&lt;/blockquote&gt;
&lt;br /&gt;
&lt;ul style="text-align: left;"&gt;
&lt;li&gt;There is no winner and no looser&lt;/li&gt;
&lt;li&gt;Entries will be displayed on 10/6/2013&lt;/li&gt;
&lt;li&gt;Campaign closes at 11:59 PM on 10/6/2013&lt;/li&gt;
&lt;/ul&gt;
&lt;div&gt;
Every participants with valid entry will get #RingTheBell mug&lt;/div&gt;
&lt;div class="separator" style="clear: both; text-align: center;"&gt;
&lt;a href="http://4.bp.blogspot.com/-d61aXWtmeUY/UZMcG6CMR4I/AAAAAAAARes/NRvBq_irvU4/s1600/prizes_mug.jpg" imageanchor="1" style="margin-left: 1em; margin-right: 1em;"&gt;&lt;img border="0" src="http://4.bp.blogspot.com/-d61aXWtmeUY/UZMcG6CMR4I/AAAAAAAARes/NRvBq_irvU4/s1600/prizes_mug.jpg" /&gt;&lt;/a&gt;&lt;/div&gt;
&lt;div&gt;
&lt;br /&gt;&lt;/div&gt;
&lt;div&gt;
Original publisher of the content is indiblogger. Please go the below written link to provide your valid entry or more information about this contest.&lt;/div&gt;
&lt;div&gt;
link-&lt;a href="http://www.indiblogger.in/topic.php?topic=80"&gt;http://www.indiblogger.in/topic.php?topic=80&lt;/a&gt;&lt;/div&gt;
&lt;div&gt;
&lt;br /&gt;&lt;/div&gt;
&lt;/div&gt;&lt;img src="http://feeds.feedburner.com/~r/blogspot/TerSJ/~4/aGym6ejsw2c" height="1" width="1"/&gt;</description><link>http://feedproxy.google.com/~r/blogspot/TerSJ/~3/aGym6ejsw2c/indiblogger-organizes-ring-bell-contest.html</link><author>ani01104@gmail.com (Madhumita)</author><media:thumbnail url="http://1.bp.blogspot.com/-PRRskcRAhzc/UZMbInXrtjI/AAAAAAAAReg/wfJiVOgRFms/s72-c/ring+the+bail.jpg" height="72" width="72" /><thr:total>0</thr:total><feedburner:origLink>http://www.askqtp.com/2013/05/indiblogger-organizes-ring-bell-contest.html</feedburner:origLink></item><item><guid isPermaLink="false">tag:blogger.com,1999:blog-2981436578666077634.post-7241138605722750677</guid><pubDate>Tue, 14 May 2013 18:31:00 +0000</pubDate><atom:updated>2013-05-26T00:43:25.344+05:30</atom:updated><category domain="http://www.blogger.com/atom/ns#">Multiple Inheritance</category><category domain="http://www.blogger.com/atom/ns#">java</category><category domain="http://www.blogger.com/atom/ns#">Cyclic Inheritance</category><title>Cyclic Inheritance: A Prohibited Approach While Designing Inheritance In Java</title><description>&lt;div dir="ltr" style="text-align: left;" trbidi="on"&gt;&lt;div dir="ltr" style="text-align: left;" trbidi="on"&gt;&lt;div dir="ltr" style="text-align: left;" trbidi="on"&gt;&lt;div class="separator" style="clear: both; text-align: center;"&gt;&lt;a href="http://3.bp.blogspot.com/-seczMPwEzPM/UZE4RtjFCGI/AAAAAAAAReA/_-pgtScGDS8/s1600/Circular_Reference.svg.png" imageanchor="1" style="clear: left; float: left; margin-bottom: 1em; margin-right: 1em;"&gt;&lt;img border="0" height="166" src="http://3.bp.blogspot.com/-seczMPwEzPM/UZE4RtjFCGI/AAAAAAAAReA/_-pgtScGDS8/s200/Circular_Reference.svg.png" width="200" /&gt;&lt;/a&gt;&lt;/div&gt;&lt;div class="boxed"&gt;3 Prohibited Approaches While Designing Inheritance In Java&lt;/div&gt;&lt;/div&gt;In my last post I have written about Inheritance and IS-A relationship &lt;a href="http://www.askqtp.com/2013/05/what-is-is-relationship-and-what-are.html"&gt;here&lt;/a&gt;. That post will talk about what is an inheritance and how to implement that. Objective of this post is little different. This post talks about what we can not do with respect to inheritance.&lt;br /&gt;
&lt;br /&gt;
&lt;div class="Blue_hearder"&gt;Cyclic Inheritance is prohibited in java&lt;/div&gt;&lt;br /&gt;
&lt;/div&gt;&lt;br /&gt;
&lt;pre class="java" name="code"&gt;class A extends B
{
//do some code
}
class B extends A
{
//do some code
}


&lt;/pre&gt;&lt;br /&gt;
let me show one more example&lt;br /&gt;
&lt;pre class="java" name="code"&gt;class A extends A{
//do some code
}
&lt;/pre&gt;&lt;br /&gt;
&lt;div class="Note"&gt;For such cases we are going to get compilation error during compilation but we need to take care while designing this class. It is said the first example of cyclic reference is generally occurred while design real time complex java project.&lt;br /&gt;
&lt;br /&gt;
&lt;/div&gt;&lt;br /&gt;
&lt;div class="Blue_hearder"&gt;Second important aspect of java class design , multiple inheritance. This is not supported in java.&lt;/div&gt;&lt;pre class="java" name="code"&gt;class A
{
//some code
}
class B
{
//some code
}
class c extends A,B
{
//some code
}
&lt;/pre&gt;&lt;br /&gt;
This is also one kind of Cyclic reference.&lt;br /&gt;
&lt;a href="http://3.bp.blogspot.com/--7a7S7kttns/UZKAPinhiEI/AAAAAAAAReQ/e2TmD7cJ_38/s1600/Diamond-Problem-of-Multiple-Inheritance.png" imageanchor="1"&gt;&lt;img border="0" src="http://3.bp.blogspot.com/--7a7S7kttns/UZKAPinhiEI/AAAAAAAAReQ/e2TmD7cJ_38/s320/Diamond-Problem-of-Multiple-Inheritance.png" /&gt;&lt;/a&gt;&lt;br /&gt;
Say for this example Class B and Class C is derived from Class A and A is having a method which is overridden &amp;nbsp;in Class B and Class C. Now if a fourth class D trying to extend both the class,by the principal of inheritance both the modified method will come to D. this creates a ambiguity for compiler which one to take.&lt;br /&gt;
&lt;br /&gt;
Secondly by theory, even if D is trying to override all the conflicting methods, then it has to reinvent the wheel. Code redundancy will increase. It will surely destroy the main idea behind inheritance i.e-code reusability.&lt;br /&gt;
&lt;br /&gt;
This diagram is popularly known as diamond diagram for Multiple inheritance.&lt;br /&gt;
&lt;br /&gt;
&lt;div class="Note"&gt;Multiple inheritance is not directly supported by java. But by using interface we can implement the same. A class can not extend more than one class at a time but for interface there is no such limitation.&lt;br /&gt;
&lt;/div&gt;Now wait for one more concept. Every class in java extends class Object. Class Object is the superclass for all class we create in java.It is the job for compiler to check and update the .class file accordingly.&lt;br /&gt;
Like if you write a class like below:&lt;br /&gt;
&lt;pre class="java" name="code"&gt;class A{
//do some activity
}
&lt;/pre&gt;&lt;br /&gt;
The java compiler will transform the same into a .class file as..&lt;br /&gt;
&lt;pre class="java" name="code"&gt;class A extends Object{
//do some activity
 }
&lt;/pre&gt;&lt;/div&gt;&lt;div class="Note"&gt;Any class that does not explicitly extend another class, implicitly extends object.&lt;br /&gt;
&lt;/div&gt;This is how, java has removed diamond problem.&lt;img src="http://feeds.feedburner.com/~r/blogspot/TerSJ/~4/Okdj40RW8XI" height="1" width="1"/&gt;</description><link>http://feedproxy.google.com/~r/blogspot/TerSJ/~3/Okdj40RW8XI/cyclic-inheritance-prohibited.html</link><author>ani01104@gmail.com (Madhumita)</author><media:thumbnail url="http://3.bp.blogspot.com/-seczMPwEzPM/UZE4RtjFCGI/AAAAAAAAReA/_-pgtScGDS8/s72-c/Circular_Reference.svg.png" height="72" width="72" /><thr:total>0</thr:total><feedburner:origLink>http://www.askqtp.com/2013/05/cyclic-inheritance-prohibited.html</feedburner:origLink></item><item><guid isPermaLink="false">tag:blogger.com,1999:blog-2981436578666077634.post-3141746811782144130</guid><pubDate>Sun, 12 May 2013 19:22:00 +0000</pubDate><atom:updated>2013-05-16T23:35:21.082+05:30</atom:updated><category domain="http://www.blogger.com/atom/ns#">java</category><category domain="http://www.blogger.com/atom/ns#">Inheritance</category><category domain="http://www.blogger.com/atom/ns#">IS-A Relationship</category><title>What Is IS-A Relationship And What Are The Rules Of IS-A Relationship In Java</title><description>&lt;div dir="ltr" style="text-align: left;" trbidi="on"&gt;&lt;div dir="ltr" style="text-align: left;" trbidi="on"&gt;&lt;div class="separator" style="clear: both; text-align: center;"&gt;&lt;a href="http://4.bp.blogspot.com/-pghNwoooKTM/UY_dTqaJ_yI/AAAAAAAARdk/txUxZ9wDcpI/s1600/java.jpg" style="clear: left; float: left; margin-bottom: 1em; margin-right: 1em;"&gt;&lt;img border="0" height="117" src="http://4.bp.blogspot.com/-pghNwoooKTM/UY_dTqaJ_yI/AAAAAAAARdk/txUxZ9wDcpI/s320/java.jpg" width="320" /&gt;&lt;/a&gt;&lt;/div&gt;In java Inheritance concept came to reduce the number of code line i.e code redundancy.&lt;br /&gt;
&lt;br /&gt;
Say in an college we have some student,lecturer,principal.&lt;br /&gt;
&lt;br /&gt;
Now for student we can have n column, so the corresponding class design will be..&lt;br /&gt;
&lt;pre class="java" name="code"&gt;class student{
int id
String name;
int age;
int No_of_Subject;
----
----
student(int id,string name,int age,......)
{
//constructor to initialize the value
this.id=id;
this.name=name;
this.age=age;
----
----

}
}
&lt;/pre&gt;Similarly for lecturer class we will have...&lt;br /&gt;
&lt;pre class="java" name="code"&gt;class lecturer{
int id
String name;
int age;

----
----
lecturer(int id,string name,int age,......)
{
//constructor to initialize the value
this.id=id;
this.name=name;
this.age=age;
----
----

}
}
&lt;/pre&gt;for principal we will have--&lt;br /&gt;
&lt;pre class="java" name="code"&gt;class principal{
int id
String name;
int age;

----
----
principal(int id,string name,int age,......)
{
//constructor to initialize the value
this.id=id;
this.name=name;
this.age=age;
----
----

}

}
&lt;/pre&gt;&lt;br /&gt;
now if you observe closely most of the code is  redundant in nature. To get reduce redundancy we can create a common  class and can derive more special classes from it.&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;div class="boxed"&gt;&lt;b&gt;How to design the common class?&lt;/b&gt;&lt;/div&gt;It is interesting..we can create a parent class with all the common attribute..the common class is more&amp;nbsp;abstract in nature.And the child classes are more specific class.Child classes can override the methods it got from parent class. It can also add more instance variable and child specific method.&amp;nbsp;Instance variables are not overridden because they do not define behavior.So a sub class can give an inherited instance variable any value&lt;br /&gt;
like-&lt;br /&gt;
&lt;pre class="java" name="code"&gt;class College_person{
int id
String name;
int age;

----
----
College_person(int id,string name,int age,......)
{
//constructor to initialize the value
this.id=id;
this.name=name;
this.age=age;
----
----

}

}
&lt;/pre&gt;&lt;br /&gt;
Now the corresponding classes will become:&lt;br /&gt;
Student:&lt;br /&gt;
&lt;pre class="java" name="code"&gt;class student extends College_person {
int id
String name;
int age;

----
----
student(int id,string name,int age,......)
{
//constructor to initialize the value
super(id,name,age,......)
this.xyx=xyz;
----
----

}

}
&lt;/pre&gt;Similarly for lecturer class we will have...&lt;br /&gt;
&lt;pre class="java" name="code"&gt;class lecturer extends College_person{
int id
String name;
int age;

----
----
lecturer(int id,string name,int age,......)
{
//constructor to initialize the value
super(id,name,age,......)
this.abc=abc;
----
----

}
}
&lt;/pre&gt;for principal we will have--&lt;br /&gt;
&lt;pre class="java" name="code"&gt;class principal extends College_person{
int id
String name;
int age;

----
----
principal(int id,string name,int age,......)
{
//constructor to initialize the value
super(id,name,age,......)
this.tgb=tgb;

----
----

}

}
&lt;/pre&gt;If you observe closely the super method is taking care of  default value's initialization and specific values specific to the class  are mentioned in the corresponding class.This is inheritance in nature.&lt;br /&gt;
the College_person becomes parent for all class student,lecturer and principal.&lt;br /&gt;
&lt;br /&gt;
Cool isn't it???&lt;br /&gt;
But  to perform a valid parent child relationship , the relationship has to  go through a IS-A test. If it passes then only we can confirm the  relationship is perfect.&lt;br /&gt;
&lt;br /&gt;
&lt;div class="boxed"&gt;here  is student IS-A College_person? the answer is yes...hence  College_person and student are in valid parent child  relationship.Similarly it is yes for lecturer and principal&lt;/div&gt;&lt;/div&gt;&lt;br /&gt;
So the conclusions are--&lt;br /&gt;
&lt;ul style="text-align: left;"&gt;&lt;li&gt;IS-A relationship is valid inheritance&lt;/li&gt;
&lt;li&gt;By using extends keyword we can implement IS-A relationship&lt;/li&gt;
&lt;li&gt;It reduces the code redundancy but increases code re usability. &lt;/li&gt;
&lt;/ul&gt;Let us see some one more example with respect to inheritance:&lt;br /&gt;
Class Parent:&lt;br /&gt;
&lt;pre class="java" name="code"&gt;Class Parent{
metho1()
{
}
}
&lt;/pre&gt;&lt;br /&gt;
Class Child:&lt;br /&gt;
&lt;br /&gt;
&lt;pre class="java" name="code"&gt;Class Child extends Parent{
method2()
{
}
&lt;/pre&gt;&lt;br /&gt;
Class test:&lt;br /&gt;
&lt;br /&gt;
&lt;pre class="java" name="code"&gt;Class test{
public static void main(String... Args)
{
//case-1
Parent p=new Parent();
p.method1();
p.method2();

//case-2
Child c=new Child();
c.method1();
c.method2();

//case-3
Parent p=new Child()
p.method1();
p.method2();

//case-4
Child c=new Parent();
c.method1();
c.method2();
}
&lt;/pre&gt;Let us discuss case by case..&lt;br /&gt;
&lt;div class="boxed"&gt;Case-1&lt;/div&gt;Parent p=new Parent();&lt;br /&gt;
p.method1();&lt;br /&gt;
p.method2();&lt;br /&gt;
&lt;br /&gt;
here Parent class is a independent class hence &lt;br /&gt;
p.method1() is a valid method call&lt;br /&gt;
but&lt;br /&gt;
p.method2() is invalid as in Parent class, method2 is unavailable&lt;br /&gt;
so we will get a Compilation error&lt;br /&gt;
&lt;b&gt;Error Details:&lt;/b&gt;&lt;br /&gt;
Can not find symbol&lt;br /&gt;
symbol:method method2()&lt;br /&gt;
location:Class Parent&lt;br /&gt;
&lt;div class="Note"&gt;&lt;b&gt;Conclusion:&lt;/b&gt;&lt;br /&gt;
The  methods very specific to child is not available to Parent .So all child  specific methods can not be called with parent reference.&lt;/div&gt;&lt;br /&gt;
&lt;div class="boxed"&gt;Case-2&lt;/div&gt;Child c=new Child();&lt;br /&gt;
c.method1();&lt;br /&gt;
c.method2();&lt;br /&gt;
&lt;br /&gt;
As Child class is extending to Parent class hence by default method1 is available to Child class.&lt;br /&gt;
hence both the method calls are valid&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;div class="Note"&gt;&lt;b&gt;Conclusion:&lt;/b&gt;&lt;br /&gt;
For the valid parent child relationship, whatever the parent is having by default will be available to child&lt;/div&gt;&lt;br /&gt;
&lt;br /&gt;
&lt;div class="boxed"&gt;Case-3&lt;/div&gt;Parent p=new Child()&lt;br /&gt;
p.method1();&lt;br /&gt;
p.method2();&lt;br /&gt;
&lt;br /&gt;
This is really interesting..We are creating object of Child of type Parent.&lt;br /&gt;
so p.method1() call is perfectly valid &lt;br /&gt;
but&lt;br /&gt;
p.method2() we will get compilation error&lt;br /&gt;
&lt;b&gt;Error Details:&lt;/b&gt;&lt;br /&gt;
can not find symbol&lt;br /&gt;
symbol:method method2()&lt;br /&gt;
location:Class Parent&lt;br /&gt;
&lt;br /&gt;
&lt;div class="Note"&gt;&lt;b&gt;Conclusion:&lt;/b&gt;&lt;br /&gt;
Parent  reference can hold child class object but using that variable (reference) we can not call child specific methods. We can only call  parent's methods&lt;/div&gt;&lt;br /&gt;
&lt;br /&gt;
&lt;div class="boxed"&gt;Case-4&lt;/div&gt;We will get compilation error&lt;br /&gt;
&lt;b&gt;Error Details:&lt;/b&gt;&lt;br /&gt;
incompatible types &lt;br /&gt;
found Parent&lt;br /&gt;
Required Child&lt;br /&gt;
&lt;b&gt;&lt;br /&gt;
&lt;/b&gt; &lt;br /&gt;
&lt;br /&gt;
&lt;div class="Note"&gt;&lt;b&gt;Conclusion:&lt;/b&gt;&lt;br /&gt;
Child reference can not be used to hold parent class object.&lt;/div&gt;&lt;div class="Blue_hearder"&gt;  The last point is keep the IS-A direction one way, Child to parent. Java supports Child to parent direction. Not the other way round.&lt;br /&gt;
Square IS-A shape,but not necessarily Shape IS-A Square. &lt;br /&gt;
&lt;/div&gt;That's it for today!!.&lt;/div&gt;&lt;img src="http://feeds.feedburner.com/~r/blogspot/TerSJ/~4/L_ajDD-nuzo" height="1" width="1"/&gt;</description><link>http://feedproxy.google.com/~r/blogspot/TerSJ/~3/L_ajDD-nuzo/what-is-is-relationship-and-what-are.html</link><author>ani01104@gmail.com (Madhumita)</author><media:thumbnail url="http://4.bp.blogspot.com/-pghNwoooKTM/UY_dTqaJ_yI/AAAAAAAARdk/txUxZ9wDcpI/s72-c/java.jpg" height="72" width="72" /><thr:total>0</thr:total><feedburner:origLink>http://www.askqtp.com/2013/05/what-is-is-relationship-and-what-are.html</feedburner:origLink></item><item><guid isPermaLink="false">tag:blogger.com,1999:blog-2981436578666077634.post-745830375129072084</guid><pubDate>Sat, 11 May 2013 20:24:00 +0000</pubDate><atom:updated>2013-05-14T18:03:15.152+05:30</atom:updated><category domain="http://www.blogger.com/atom/ns#">java</category><category domain="http://www.blogger.com/atom/ns#">Encapsulation</category><title>Types Of Encapsulation In Java</title><description>&lt;div dir="ltr" style="text-align: left;" trbidi="on"&gt;&lt;div dir="ltr" style="text-align: left;" trbidi="on"&gt;&lt;div dir="ltr" style="text-align: left;" trbidi="on"&gt;&lt;div dir="ltr" style="text-align: left;" trbidi="on"&gt;&lt;div class="separator" style="clear: both; text-align: center;"&gt;&lt;a href="http://1.bp.blogspot.com/-jyS-HkBuTkA/UY6ND3BSCII/AAAAAAAARZM/W2sBxwGi3gY/s1600/encapsulation.jpg" imageanchor="1" style="clear: left; float: left; margin-bottom: 1em; margin-right: 1em;"&gt;&lt;img border="0" src="http://1.bp.blogspot.com/-jyS-HkBuTkA/UY6ND3BSCII/AAAAAAAARZM/W2sBxwGi3gY/s1600/encapsulation.jpg" /&gt;&lt;/a&gt;&lt;/div&gt;&lt;div class="Blue_hearder"&gt;  Types of Encapsulation&lt;br /&gt;
&lt;/div&gt;&lt;br /&gt;
&lt;br /&gt;
In my last post &lt;a href="http://www.askqtp.com/2013/03/the-golden-rules-of-encapsulation.html" target="_blank"&gt;here &lt;/a&gt;I have provided the concept of Encapsulation. In this post I will describe the different types of Encapsulation.&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
There are two types of Encapsulation present in java..&lt;br /&gt;
&lt;ul style="text-align: left;"&gt;&lt;li&gt;Tightly Encapsulated Class&lt;/li&gt;
&lt;li&gt;Loosely encapsulated class(Normal class)&lt;/li&gt;
&lt;/ul&gt;&lt;br /&gt;
&lt;div class="boxed"&gt;&lt;b&gt; Tightly Encapsulated Class &lt;/b&gt;&lt;br /&gt;
If a class is having every variable declared as private then it is called tightly encapsulated class.&lt;/div&gt;&lt;br /&gt;
&lt;br /&gt;
&lt;pre class="java" name="code"&gt;class test
{

private int age;
private double salary;
private int phoneNumber;

}
&lt;/pre&gt;&lt;div class="boxed"&gt;&lt;b&gt;Loosely Encapsulated Class &lt;/b&gt;&lt;br /&gt;
if a class is having atleast one normal variable or any variable other than private,then it is called Loosely Encapsulated Class.&lt;/div&gt;&lt;br /&gt;
&lt;/div&gt;&lt;br /&gt;
&lt;pre class="java" name="code"&gt;class test
{

int age;
private double salary;
private int phoneNumber;

}
&lt;/pre&gt;&lt;/div&gt;&lt;div class="boxed"&gt;lets see how it works in parent child relationship:&lt;/div&gt;&lt;/div&gt;&lt;table border="1" bordercolor="#000000" cellpadding="3" cellspacing="3" style="background-color: #f8f8f8; height: 306px; width: 627px;"&gt;&lt;tbody&gt;
&lt;tr&gt;   &lt;td&gt;&lt;u&gt;&lt;b&gt;Encapsulation mode&lt;/b&gt;&lt;/u&gt;&lt;/td&gt;   &lt;td&gt;&lt;u&gt;&lt;b&gt;Code&lt;/b&gt;&lt;/u&gt;&lt;/td&gt;  &lt;/tr&gt;
&lt;tr&gt;   &lt;td&gt;Tightly Encapsulated&lt;/td&gt;   &lt;td&gt;&lt;pre class="java" name="code"&gt;class test
{
Private int age;
private double salary;
private int phoneNumber;
}
&lt;/pre&gt;&lt;/td&gt;  &lt;/tr&gt;
&lt;tr&gt;   &lt;td&gt;Loosely Encapsulated&lt;/td&gt;   &lt;td&gt;&lt;pre class="java" name="code"&gt;class abc extends test
{
String Address;
}
&lt;/pre&gt;&lt;/td&gt;  &lt;/tr&gt;
&lt;tr&gt;   &lt;td&gt;Tightly Encapsulated &lt;/td&gt;   &lt;td&gt;&lt;pre class="java" name="code"&gt;class xyz extends test
{
private String Name;
}
&lt;/pre&gt;&lt;/td&gt;  &lt;/tr&gt;
&lt;/tbody&gt;&lt;/table&gt;&lt;br /&gt;
In this above example the parent class &lt;u&gt;&lt;b&gt;test&lt;/b&gt;&lt;/u&gt; is having 3 private variable, hence the parent class is tightly Encapsulated class.&lt;br /&gt;
The class &lt;u&gt;&lt;b&gt;abc&lt;/b&gt;&lt;/u&gt; is extending &lt;u&gt;&lt;b&gt;test&lt;/b&gt;&lt;/u&gt; class hence it is having total 4 variables available with it in which one is normal variable(other than private)&lt;br /&gt;
&lt;pre class="java" name="code"&gt;Private int age;
private double salary;
private int phoneNumber;
String Address;
&lt;/pre&gt;As the string is normal variable so it does not pass the condition to be Tightly Encapsulation rule&amp;nbsp; &lt;br /&gt;
With the same logic the &lt;u&gt;&lt;b&gt;xyz &lt;/b&gt;&lt;/u&gt;class when extending to &lt;u&gt;&lt;b&gt;test&lt;/b&gt;&lt;/u&gt;&amp;nbsp; is a tightly Encapsulated class.&lt;br /&gt;
&lt;br /&gt;
&lt;table border="1" bordercolor="#000000" cellpadding="3" cellspacing="3" style="background-color: #f8f8f8; height: 129px; width: 608px;"&gt;&lt;tbody&gt;
&lt;tr&gt;   &lt;td&gt;&lt;u&gt;&lt;b&gt;Encapsulation mode&lt;/b&gt;&lt;/u&gt;&lt;/td&gt;   &lt;td&gt;&lt;u&gt;&lt;b&gt;Code&lt;/b&gt;&lt;/u&gt;&lt;/td&gt;  &lt;/tr&gt;
&lt;tr&gt;   &lt;td&gt;Loosely Encapsulated&lt;/td&gt;   &lt;td&gt;&lt;pre class="java" name="code"&gt;class test
{
String Name;
}
&lt;/pre&gt;&lt;/td&gt;  &lt;/tr&gt;
&lt;tr&gt;   &lt;td&gt;&lt;br /&gt;
Loosely Encapsulated&lt;/td&gt;   &lt;td&gt;&lt;pre class="java" name="code"&gt;class xyz extends test
{
private String Name;
}
&lt;/pre&gt;&lt;/td&gt;  &lt;/tr&gt;
&lt;tr&gt;   &lt;td&gt;Loosely Encapsulated &lt;/td&gt;   &lt;td&gt;&lt;pre class="java" name="code"&gt;class abc extends xyz
{
private String Name;
}
&lt;/pre&gt;&lt;/td&gt;  &lt;/tr&gt;
&lt;/tbody&gt;&lt;/table&gt;&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;div class="Note"&gt;In the above example &lt;u&gt;&lt;b&gt;test&lt;/b&gt;&lt;/u&gt; is the parent class which is loosely encapsulated as Name variable is not declared&amp;nbsp; as private. so class &lt;u&gt;&lt;b&gt;xyz &lt;/b&gt;&lt;/u&gt;when extends to test , automatically becomes loosely Encapsulated class even though it is having one private variable. Now when &lt;u&gt;&lt;b&gt;abc &lt;/b&gt;&lt;/u&gt;extends to &lt;u&gt;&lt;b&gt;xyz &lt;/b&gt;&lt;/u&gt;which is already a loosely Encapsulated hence it becomes loosely encapsulated.&lt;br /&gt;
&lt;br /&gt;
So the rule is if the parent is not tightly coupled, there is no child class exists who is tightly coupled.&lt;/div&gt;&lt;br /&gt;
&lt;/div&gt;&lt;img src="http://feeds.feedburner.com/~r/blogspot/TerSJ/~4/3Lwcg6ZJppU" height="1" width="1"/&gt;</description><link>http://feedproxy.google.com/~r/blogspot/TerSJ/~3/3Lwcg6ZJppU/types-of-encapsulation-in-java.html</link><author>ani01104@gmail.com (Madhumita)</author><media:thumbnail url="http://1.bp.blogspot.com/-jyS-HkBuTkA/UY6ND3BSCII/AAAAAAAARZM/W2sBxwGi3gY/s72-c/encapsulation.jpg" height="72" width="72" /><thr:total>0</thr:total><feedburner:origLink>http://www.askqtp.com/2013/05/types-of-encapsulation-in-java.html</feedburner:origLink></item><item><guid isPermaLink="false">tag:blogger.com,1999:blog-2981436578666077634.post-2732143015303270356</guid><pubDate>Fri, 10 May 2013 19:02:00 +0000</pubDate><atom:updated>2013-05-11T01:01:07.991+05:30</atom:updated><category domain="http://www.blogger.com/atom/ns#">java</category><category domain="http://www.blogger.com/atom/ns#">jar</category><category domain="http://www.blogger.com/atom/ns#">Zip file</category><category domain="http://www.blogger.com/atom/ns#">war</category><category domain="http://www.blogger.com/atom/ns#">Java Zip File</category><category domain="http://www.blogger.com/atom/ns#">ear</category><title>Difference Between JAR,WAR and EAR</title><description>&lt;div dir="ltr" style="text-align: left;" trbidi="on"&gt;
&lt;a href="http://2.bp.blogspot.com/-UURP1WitnFk/UY04XRwTCFI/AAAAAAAARYQ/0ACs84PRErE/s1600/archive.jpg" imageanchor="1" style="clear: left; float: left; margin-bottom: 1em; margin-right: 1em;"&gt;&lt;img border="0" src="http://2.bp.blogspot.com/-UURP1WitnFk/UY04XRwTCFI/AAAAAAAARYQ/0ACs84PRErE/s320/archive.jpg" /&gt;&lt;/a&gt;&lt;br /&gt;
if there are many files and they are dependent in nature for your program. It is very tough to put them in classpath to access them run time.For solving this problem java has come up with archiving concept. It's concept is simple. put all the classes in a zip file and make that available in classpath while running the java code.&lt;br /&gt;
&lt;br /&gt;
Again consider one more example, if our program contains of many HTML files,images files etc. so to download one single file, it is required to download all the components of the file. And for that we require so many HTTP connections to get all those. It will take more time and patience. so zip file is a nice concept .&lt;br /&gt;
&lt;br /&gt;
Mainly we have 3 types of zip file in java..&lt;br /&gt;
&lt;ol style="text-align: left;"&gt;
&lt;li&gt;jar (java archive file)&lt;/li&gt;
&lt;li&gt;war (web archive file)&lt;/li&gt;
&lt;li&gt;ear (enterprise archive file)&lt;/li&gt;
&lt;/ol&gt;
&lt;br /&gt;
Let's check out the difference between them: &lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;table border="1" style="height: 48px; width: 649px;"&gt;&lt;tbody&gt;
&lt;tr&gt; &lt;td style="text-align: center;"&gt;&lt;b&gt;Jar&lt;/b&gt;&lt;/td&gt; &lt;td style="text-align: center;"&gt;&lt;b&gt;War&lt;/b&gt;&lt;/td&gt;&lt;td style="text-align: center;"&gt;&lt;b&gt;Ear&lt;/b&gt;&lt;/td&gt; &lt;/tr&gt;
&lt;tr&gt; &lt;td&gt;&lt;ol&gt;
&lt;li&gt; contains .class files&lt;/li&gt;
&lt;li&gt;&amp;nbsp;A JAR file encapsulates one or more Java classes, a manifest, and a descriptor. &lt;/li&gt;
&lt;li&gt;&lt;span class="postbody"&gt;JAR files are the lowest level of archive&lt;/span&gt;&lt;/li&gt;
&lt;li&gt;&lt;span class="postbody"&gt;It is having MANIFEST.MF in META-INF folder&lt;/span&gt;&lt;/li&gt;
&lt;li&gt;&lt;span class="postbody"&gt;extension .jar&lt;/span&gt;&lt;/li&gt;
&lt;/ol&gt;
&lt;/td&gt; &lt;td&gt;&lt;ol&gt;
&lt;li&gt;it contains mostly web application resources like HTMl,CSS,JSP,Servlets,images,beans etc&lt;/li&gt;
&lt;li&gt;It is having web.xml to configure&lt;/li&gt;
&lt;li&gt;It helps to maintain,deployment and shipping very easy for web application&lt;/li&gt;
&lt;li&gt;extension .war&lt;/li&gt;
&lt;/ol&gt;
&lt;/td&gt;&lt;td&gt;&lt;ol&gt;
&lt;li&gt;We use it on enterprise application. mainly combination of wars and jars&lt;/li&gt;
&lt;li&gt;It is having xml based deployment descriptor to configure all&lt;/li&gt;
&lt;li&gt;It helps to maintain,deployment and shipping very easy for enterprise&amp;nbsp; application&lt;/li&gt;
&lt;li&gt;extension .ear &lt;/li&gt;
&lt;/ol&gt;
&lt;/td&gt; &lt;/tr&gt;
&lt;/tbody&gt;&lt;/table&gt;
&lt;/div&gt;&lt;img src="http://feeds.feedburner.com/~r/blogspot/TerSJ/~4/hQ7pyw6TRxc" height="1" width="1"/&gt;</description><link>http://feedproxy.google.com/~r/blogspot/TerSJ/~3/hQ7pyw6TRxc/difference-between-jarwar-and-ear.html</link><author>ani01104@gmail.com (Madhumita)</author><media:thumbnail url="http://2.bp.blogspot.com/-UURP1WitnFk/UY04XRwTCFI/AAAAAAAARYQ/0ACs84PRErE/s72-c/archive.jpg" height="72" width="72" /><thr:total>0</thr:total><feedburner:origLink>http://www.askqtp.com/2013/05/difference-between-jarwar-and-ear.html</feedburner:origLink></item><item><guid isPermaLink="false">tag:blogger.com,1999:blog-2981436578666077634.post-4725009714589754307</guid><pubDate>Fri, 10 May 2013 17:58:00 +0000</pubDate><atom:updated>2013-05-10T23:28:38.127+05:30</atom:updated><category domain="http://www.blogger.com/atom/ns#">java</category><category domain="http://www.blogger.com/atom/ns#">Classpath</category><category domain="http://www.blogger.com/atom/ns#">path</category><title>Difference Between Path And Classpath In Java</title><description>&lt;div dir="ltr" style="text-align: left;" trbidi="on"&gt;
&lt;div class="separator" style="clear: both; text-align: center;"&gt;
&lt;a href="http://2.bp.blogspot.com/-MivO_Y-d1Io/UY0xDN56SHI/AAAAAAAARXg/kyLOzydirQI/s1600/java.jpg" imageanchor="1" style="clear: left; float: left; margin-bottom: 1em; margin-right: 1em;"&gt;&lt;img border="0" src="http://2.bp.blogspot.com/-MivO_Y-d1Io/UY0xDN56SHI/AAAAAAAARXg/kyLOzydirQI/s1600/java.jpg" /&gt;&lt;/a&gt;&lt;/div&gt;
Let us understand what is path in java..&lt;br /&gt;
In java path is the variable which holds the specific location of the binary executable files of java like- java/javac etc&lt;br /&gt;
&lt;br /&gt;
How to set path--&lt;br /&gt;
Well there are two ways by which we can set path&lt;br /&gt;
&lt;ul style="text-align: left;"&gt;
&lt;li&gt;Permanently set path via environment variable-(click &lt;a href="http://blog.recurtrix.com/2012/07/java-detailed-installation-instructions.html" target="_blank"&gt;here &lt;/a&gt;for more)&lt;/li&gt;
&lt;li&gt;Temporary for a session.&lt;/li&gt;
&lt;/ul&gt;
we will check out how to set path temporarily ..&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
Temporary settings:&lt;br /&gt;
1. Go to start--&amp;gt;run --&amp;gt;type cmd&lt;br /&gt;
&lt;div class="separator" style="clear: both; text-align: center;"&gt;
&lt;a href="http://3.bp.blogspot.com/-ei-jietsFYQ/UY0x_XaMbYI/AAAAAAAARXo/bF3d8_T-6B0/s1600/run.JPG" imageanchor="1" style="margin-left: 1em; margin-right: 1em;"&gt;&lt;img border="0" height="326" src="http://3.bp.blogspot.com/-ei-jietsFYQ/UY0x_XaMbYI/AAAAAAAARXo/bF3d8_T-6B0/s640/run.JPG" width="640" /&gt;&lt;/a&gt;&lt;/div&gt;
2. click on ok. It will open command prompt for windows&lt;br /&gt;
&lt;div class="separator" style="clear: both; text-align: center;"&gt;
&lt;a href="http://1.bp.blogspot.com/-a1ARnPPs660/UY0yeFKCZXI/AAAAAAAARXw/bfxP0PfulS0/s1600/command.JPG" imageanchor="1" style="margin-left: 1em; margin-right: 1em;"&gt;&lt;img border="0" height="318" src="http://1.bp.blogspot.com/-a1ARnPPs660/UY0yeFKCZXI/AAAAAAAARXw/bfxP0PfulS0/s640/command.JPG" width="640" /&gt;&lt;/a&gt;&lt;/div&gt;
&lt;br /&gt;
3. Now navigate to the path where you have installed your java(JDK installation folder)&lt;br /&gt;
it might be C:\Program Files\java\jdk&amp;lt;&amp;lt;version&amp;gt;&amp;gt;\ &lt;br /&gt;
&lt;div class="separator" style="clear: both; text-align: center;"&gt;
&lt;a href="http://1.bp.blogspot.com/-O7O1xxyEFBQ/UY0zBV6rieI/AAAAAAAARX4/9byQdn5kTP0/s1600/installed+path.JPG" imageanchor="1" style="margin-left: 1em; margin-right: 1em;"&gt;&lt;img border="0" src="http://1.bp.blogspot.com/-O7O1xxyEFBQ/UY0zBV6rieI/AAAAAAAARX4/9byQdn5kTP0/s1600/installed+path.JPG" /&gt;&lt;/a&gt;&lt;/div&gt;
4. Copy the path and come back to command prompt.&lt;br /&gt;
5. Type the below written command:&lt;br /&gt;
&lt;br /&gt;
&lt;pre class="java" name="code"&gt;set path=C:\Program Files\Java\jdk1.7.0_21\bin\

&lt;/pre&gt;
&lt;a href="http://1.bp.blogspot.com/-BdTf5zqZJRI/UY00EKn4-OI/AAAAAAAARYA/ZagpZTvsWoQ/s1600/path.JPG" imageanchor="1"&gt;&lt;img border="0" height="324" src="http://1.bp.blogspot.com/-BdTf5zqZJRI/UY00EKn4-OI/AAAAAAAARYA/ZagpZTvsWoQ/s640/path.JPG" width="640" /&gt;&amp;nbsp;&lt;/a&gt;&lt;br /&gt;
&lt;br /&gt;
you are done!! Now you can write any java program and compile the same.&lt;br /&gt;
&lt;br /&gt;
&lt;u&gt;&lt;b&gt;Classpath:&lt;/b&gt;&lt;/u&gt;&lt;br /&gt;
&lt;br /&gt;
Classpath is the variable which is used to tell JVM from where all my classes are residing. and from which location it has to pick the required .class files.&lt;br /&gt;
How to set classpath:&lt;br /&gt;
Please go through ..&lt;br /&gt;
1. &lt;a href="http://www.askqtp.com/2012/01/setting-class-path-in-java-in-windows.html"&gt;http://www.askqtp.com/2012/01/setting-class-path-in-java-in-windows.html&lt;/a&gt;&lt;br /&gt;
&amp;nbsp;&amp;nbsp; for permanent settings&lt;br /&gt;
2. &lt;a href="http://www.askqtp.com/2013/05/what-is-classpath-and-how-to-set-that.html"&gt;http://www.askqtp.com/2013/05/what-is-classpath-and-how-to-set-that.html&lt;/a&gt;&lt;br /&gt;
&amp;nbsp;&amp;nbsp; for temporary settings&lt;br /&gt;
&lt;br /&gt;&lt;/div&gt;&lt;img src="http://feeds.feedburner.com/~r/blogspot/TerSJ/~4/AFCJupfOsro" height="1" width="1"/&gt;</description><link>http://feedproxy.google.com/~r/blogspot/TerSJ/~3/AFCJupfOsro/difference-between-path-and-classpath.html</link><author>ani01104@gmail.com (Madhumita)</author><media:thumbnail url="http://2.bp.blogspot.com/-MivO_Y-d1Io/UY0xDN56SHI/AAAAAAAARXg/kyLOzydirQI/s72-c/java.jpg" height="72" width="72" /><thr:total>0</thr:total><feedburner:origLink>http://www.askqtp.com/2013/05/difference-between-path-and-classpath.html</feedburner:origLink></item><item><guid isPermaLink="false">tag:blogger.com,1999:blog-2981436578666077634.post-2511127395991648458</guid><pubDate>Thu, 09 May 2013 19:46:00 +0000</pubDate><atom:updated>2013-05-10T01:16:45.860+05:30</atom:updated><category domain="http://www.blogger.com/atom/ns#">java</category><category domain="http://www.blogger.com/atom/ns#">Precondition checks</category><category domain="http://www.blogger.com/atom/ns#">System Configuration</category><title>How To Check System Configuration Before Proceeding With Our Code In Java</title><description>&lt;div dir="ltr" style="text-align: left;" trbidi="on"&gt;&lt;div class="separator" style="clear: both; text-align: center;"&gt;&lt;a href="http://2.bp.blogspot.com/-llkzOZDAyzk/UYv11V5YWoI/AAAAAAAARWU/aGxxwLcppS8/s1600/java.jpg" imageanchor="1" style="clear: left; float: left; margin-bottom: 1em; margin-right: 1em;"&gt;&lt;img border="0" src="http://2.bp.blogspot.com/-llkzOZDAyzk/UYv11V5YWoI/AAAAAAAARWU/aGxxwLcppS8/s1600/java.jpg" /&gt;&lt;/a&gt;&lt;/div&gt;The objective of this post is to check system configuration for running java codes. when it is exactly required??&lt;br /&gt;
Well lets say I have developed a program in Java-1.6, and used some code which got enhanced in that particular version.&lt;br /&gt;
like-&lt;br /&gt;
&lt;ul style="text-align: left;"&gt;&lt;li&gt;Native platform Security (GSS/Kerberos) integration.&lt;/li&gt;
&lt;li&gt;Java Authentication and Authorization Service (JAAS) login&amp;nbsp;&lt;/li&gt;
&lt;li&gt;module that employs LDAP authentication&lt;/li&gt;
&lt;li&gt;New Smart Card I/O API&lt;/li&gt;
&lt;li&gt;Native security services technical article &lt;/li&gt;
&lt;/ul&gt;Lets assume that this program will run on java -1.5 . Definitely the compatibility will not be there.&lt;br /&gt;
&lt;br /&gt;
As per &lt;a href="http://stackoverflow.com/questions/4692626/is-jdk-upward-or-backward-compatible" target="_blank"&gt;stack over flow&lt;/a&gt;...&lt;br /&gt;
&lt;blockquote class="tr_bq"&gt;The compiler is not backwards compatible because bytecode generated with Java6 JDK won't run in Java 1.5 jvm (unless compiled with the -target 1.5 flag). But the JVM is backwards compatible, as it can run older bytecodes.&lt;br /&gt;
&lt;br /&gt;
So I guess they chose to consider the compatibility from the point of view of javac (as it is the part specific to the JDK), meaning that the bytecode generated can be run in future releases of the jvm (that is more related to the JRE, but also bundled in the JDK).&lt;br /&gt;
&lt;br /&gt;
In brief, we can say:&lt;br /&gt;
&lt;br /&gt;
&amp;nbsp;&amp;nbsp;&amp;nbsp; JDK's are (usually) forward compatible.&lt;br /&gt;
&amp;nbsp;&amp;nbsp;&amp;nbsp; JRE's are (usually) backward compatible.&lt;/blockquote&gt;Let us also assume , my program needs the below written...&lt;br /&gt;
&lt;ul style="text-align: left;"&gt;&lt;li&gt;Java version-java 1.7&lt;/li&gt;
&lt;li&gt;OS-Windows XP&lt;/li&gt;
&lt;li&gt;&amp;nbsp;and I have some requirement where the .class file should be in C drive.&lt;/li&gt;
&lt;/ul&gt;if all of the above are matching then our program is good to go else we will simply say with the&amp;nbsp; configuration, this program will not run...&lt;br /&gt;
&lt;br /&gt;
Lets see how:&lt;br /&gt;
In my previous post &lt;a href="http://www.askqtp.com/2013/05/how-to-get-system-properties-in-java.html" target="_blank"&gt;here&lt;/a&gt;..&lt;a href="http://www.askqtp.com/2013/05/how-to-get-system-properties-in-java.html"&gt;http://www.askqtp.com/2013/05/how-to-get-system-properties-in-java.html&lt;/a&gt;&lt;br /&gt;
I have shown how to get system properties.&lt;br /&gt;
From the list of properties we are only going to choose&lt;br /&gt;
&lt;ul style="text-align: left;"&gt;&lt;li&gt;java version&lt;/li&gt;
&lt;li&gt;OS&amp;nbsp;&lt;/li&gt;
&lt;li&gt;class. path&lt;/li&gt;
&lt;/ul&gt;&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;pre class="java" name="code"&gt;import java.util.Properties;


public class systemTest {

 /**
  * @param args
  */
 public static void main(String[] args) {
  // TODO Auto-generated method stub
  boolean b=false;
  Properties p=System.getProperties();
  p.list(System.out);
//get all the list of properties.
                String path=p.getProperty("java.class.path");
  String os=p.getProperty("os.name");
  String javaVersion=p.getProperty("java.specification.version");
  System.out.println(path);
  System.out.println(os);
  System.out.println(javaVersion);
  if((path.indexOf("C:\\")&amp;gt;=0||path.equals(".")) &amp;amp;&amp;amp; os.equals("Windows XP") &amp;amp;&amp;amp; javaVersion.equals("1.7"))
    b=true;
//checks the path contains C drive,also checks for OS or java version
                  if(b)
    System.out.print("We can proceed");
    else
    System.out.print("We can not proceed");
      }
       
}

&lt;/pre&gt;&lt;/div&gt;output:&lt;br /&gt;
. (dot means present working directory.)&lt;br /&gt;
Windows XP&lt;br /&gt;
1.7&lt;br /&gt;
We can proceed&lt;br /&gt;
&lt;br /&gt;
Now if the java version is 1.4 (running)in the client machine. It should say "We can not proceed"&lt;br /&gt;
&lt;br /&gt;
By this way we can achieve the precondition cases for running our tests.&lt;br /&gt;
&lt;br /&gt;&lt;img src="http://feeds.feedburner.com/~r/blogspot/TerSJ/~4/M3sQJT4MOGk" height="1" width="1"/&gt;</description><link>http://feedproxy.google.com/~r/blogspot/TerSJ/~3/M3sQJT4MOGk/how-to-check-system-configuration.html</link><author>ani01104@gmail.com (Madhumita)</author><media:thumbnail url="http://2.bp.blogspot.com/-llkzOZDAyzk/UYv11V5YWoI/AAAAAAAARWU/aGxxwLcppS8/s72-c/java.jpg" height="72" width="72" /><thr:total>0</thr:total><feedburner:origLink>http://www.askqtp.com/2013/05/how-to-check-system-configuration.html</feedburner:origLink></item><item><guid isPermaLink="false">tag:blogger.com,1999:blog-2981436578666077634.post-4617370262733927957</guid><pubDate>Thu, 09 May 2013 17:30:00 +0000</pubDate><atom:updated>2013-05-09T23:17:23.486+05:30</atom:updated><category domain="http://www.blogger.com/atom/ns#">java</category><category domain="http://www.blogger.com/atom/ns#">Persistent Properties</category><category domain="http://www.blogger.com/atom/ns#">System Properties</category><title>How To Get System Properties In Java</title><description>&lt;div dir="ltr" style="text-align: left;" trbidi="on"&gt;
&lt;div dir="ltr" style="text-align: left;" trbidi="on"&gt;
&lt;div class="separator" style="clear: both; text-align: center;"&gt;
&lt;a href="http://2.bp.blogspot.com/-U6QGBp6V_Yw/UYvR9EqPprI/AAAAAAAARV0/Ce2iqNjfEP4/s1600/java.jpg" imageanchor="1" style="clear: left; float: left; margin-bottom: 1em; margin-right: 1em;"&gt;&lt;img border="0" src="http://2.bp.blogspot.com/-U6QGBp6V_Yw/UYvR9EqPprI/AAAAAAAARV0/Ce2iqNjfEP4/s1600/java.jpg" /&gt;&lt;/a&gt;&lt;/div&gt;
For each system , system properties information (persistent ) will be maintained in the form of system properties. Mainly we use properties to maintain system configuration.The system class will maintain a Properties object to get all the details.&lt;br /&gt;
&lt;br /&gt;
In short it is nothing but a key value pair in the form of string.&lt;br /&gt;
The important aspect of System property is "to access any value from it , it requires current security manager's approval"&lt;br /&gt;
&lt;br /&gt;
More details can be found here:&lt;br /&gt;
&lt;ul style="text-align: left;"&gt;
&lt;li&gt;&lt;a href="http://docs.oracle.com/javase/tutorial/essential/environment/properties.html" target="_blank"&gt;Prperties &lt;/a&gt;&lt;/li&gt;
&lt;li&gt;&lt;a href="http://docs.oracle.com/javase/tutorial/essential/environment/sysprop.html" target="_blank"&gt;System Properties&lt;/a&gt;&lt;/li&gt;
&lt;/ul&gt;
&lt;br /&gt;
Lets see an example:&lt;br /&gt;
&lt;pre class="java" name="code"&gt;import java.util.Properties;
public class systemTest {

 /**
  * @param args
  */
 public static void main(String[] args) {
  // TODO Auto-generated method stub
  Properties p=System.getProperties();
  p.list(System.out);
  
 }
}

&lt;/pre&gt;
output:&lt;br /&gt;
java.vm.specification.vendor=XYZ Corporation&lt;br /&gt;
user.variant=&lt;br /&gt;
os.name=Windows XP&lt;br /&gt;
sun.jnu.encoding=Cp1252&lt;br /&gt;
java.library.path=C:\Program Files\Java\jdk1.7.0_21\bin...&lt;br /&gt;
java.specification.name=Java Platform API Specification&lt;br /&gt;
java.class.version=51.0&lt;br /&gt;
sun.management.compiler=HotSpot Client Compiler&lt;br /&gt;
os.version=5.1&lt;br /&gt;
user.home=C:\Documents and Settings\anichatt.AP...&lt;br /&gt;
user.timezone=&lt;br /&gt;
java.awt.printerjob=sun.awt.windows.WPrinterJob&lt;br /&gt;
file.encoding=Cp1252&lt;br /&gt;
java.specification.version=1.7&lt;br /&gt;
user.name=anichatt&lt;br /&gt;
java.class.path=E:\myProgram\&lt;br /&gt;
java.vm.specification.version=1.7&lt;br /&gt;
sun.arch.data.model=32&lt;br /&gt;
java.home=C:\Program Files\Java\jdk1.7.0_21\jre&lt;br /&gt;
sun.java.command=systemTest&lt;br /&gt;
java.specification.vendor=xyz Corporation&lt;br /&gt;
user.language=en&lt;br /&gt;
awt.toolkit=sun.awt.windows.WToolkit&lt;br /&gt;
java.vm.info=mixed mode, sharing&lt;br /&gt;
java.version=1.7.0_21&lt;br /&gt;
java.ext.dirs=C:\Program Files\Java\jdk1.7.0_21\jre...&lt;br /&gt;
sun.boot.class.path=C:\Program Files\Java\jdk1.7.0_21\jre...&lt;br /&gt;
java.vendor=xyz Corporation&lt;br /&gt;
file.separator=\&lt;br /&gt;
java.vendor.url.bug=http://bugreport.sun.com/bugreport/&lt;br /&gt;
sun.cpu.endian=little&lt;br /&gt;
sun.io.unicode.encoding=UnicodeLittle&lt;br /&gt;
sun.desktop=windows&lt;br /&gt;
sun.cpu.isalist=pentium_pro+mmx pentium_pro pentium+m...&lt;br /&gt;
&lt;br /&gt;
&amp;nbsp;Below are the system properties that can be tracked using system class's Property Object. &lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;table align="center" border="1" cellpadding="2" style="height: 447px; width: 543px;" summary="Important system properties"&gt;&lt;tbody&gt;
&lt;tr&gt;&lt;th id="h1"&gt;Key&lt;/th&gt; &lt;th id="h2"&gt;Meaning&lt;/th&gt; &lt;/tr&gt;
&lt;tr&gt; &lt;td headers="h1"&gt;&lt;code&gt;"file.separator"&lt;/code&gt;&lt;/td&gt; &lt;td headers="h2"&gt;Character that separates components of a file path. This is "&lt;code&gt;/&lt;/code&gt;" on UNIX and "&lt;code&gt;\&lt;/code&gt;" on Windows.&lt;/td&gt; &lt;/tr&gt;
&lt;tr&gt; &lt;td headers="h1"&gt;&lt;code&gt;"java.class.path"&lt;/code&gt;&lt;/td&gt; &lt;td headers="h2"&gt;Path used to find directories and JAR archives  containing class files. Elements of the class path are separated by a  platform-specific character specified in the &lt;code&gt;path.separator&lt;/code&gt; property.&lt;/td&gt; &lt;/tr&gt;
&lt;tr&gt; &lt;td headers="h1"&gt;&lt;code&gt;"java.home"&lt;/code&gt;&lt;/td&gt; &lt;td headers="h2"&gt;Installation directory for Java Runtime Environment (JRE)&lt;/td&gt; &lt;/tr&gt;
&lt;tr&gt; &lt;td headers="h1"&gt;&lt;code&gt;"java.vendor"&lt;/code&gt;&lt;/td&gt; &lt;td headers="h2"&gt;JRE vendor name&lt;/td&gt; &lt;/tr&gt;
&lt;tr&gt; &lt;td headers="h1"&gt;&lt;code&gt;"java.vendor.url"&lt;/code&gt;&lt;/td&gt; &lt;td headers="h2"&gt;JRE vendor URL&lt;/td&gt; &lt;/tr&gt;
&lt;tr&gt; &lt;td headers="h1"&gt;&lt;code&gt;"java.version"&lt;/code&gt;&lt;/td&gt; &lt;td headers="h2"&gt;JRE version number&lt;/td&gt; &lt;/tr&gt;
&lt;tr&gt; &lt;td headers="h1"&gt;&lt;code&gt;"line.separator"&lt;/code&gt;&lt;/td&gt; &lt;td headers="h2"&gt;Sequence used by operating system to separate lines in text files&lt;/td&gt; &lt;/tr&gt;
&lt;tr&gt; &lt;td headers="h1"&gt;&lt;code&gt;"os.arch"&lt;/code&gt;&lt;/td&gt; &lt;td headers="h2"&gt;Operating system architecture&lt;/td&gt; &lt;/tr&gt;
&lt;tr&gt; &lt;td headers="h1"&gt;&lt;code&gt;"os.name"&lt;/code&gt;&lt;/td&gt; &lt;td headers="h2"&gt;Operating system name&lt;/td&gt; &lt;/tr&gt;
&lt;tr&gt; &lt;td headers="h1"&gt;&lt;code&gt;"os.version"&lt;/code&gt;&lt;/td&gt; &lt;td headers="h2"&gt;Operating system version&lt;/td&gt; &lt;/tr&gt;
&lt;tr&gt; &lt;td headers="h1"&gt;&lt;code&gt;"path.separator"&lt;/code&gt;&lt;/td&gt; &lt;td headers="h2"&gt;Path separator character used in &lt;code&gt;java.class.path&lt;/code&gt;&lt;/td&gt; &lt;/tr&gt;
&lt;tr&gt; &lt;td headers="h1"&gt;&lt;code&gt;"user.dir"&lt;/code&gt;&lt;/td&gt; &lt;td headers="h2"&gt;User working directory&lt;/td&gt; &lt;/tr&gt;
&lt;tr&gt; &lt;td headers="h1"&gt;&lt;code&gt;"user.home"&lt;/code&gt;&lt;/td&gt; &lt;td headers="h2"&gt;User home directory&lt;/td&gt; &lt;/tr&gt;
&lt;tr&gt; &lt;td headers="h1"&gt;&lt;code&gt;"user.name"&lt;/code&gt;&lt;/td&gt; &lt;td headers="h2"&gt;User account name&lt;/td&gt;&lt;/tr&gt;
&lt;/tbody&gt;&lt;/table&gt;
taken from &lt;a href="http://docs.oracle.com/javase/tutorial/essential/environment/sysprop.html"&gt;docs.oracle.com&lt;/a&gt;&lt;br /&gt;
How to get single property from the list??&lt;br /&gt;
say i want to retrieve OS name and current location of the class file.&lt;br /&gt;
so the corresponding code:&lt;br /&gt;
&lt;pre class="java" name="code"&gt;import java.util.Properties;
public class systemTest {
 /**
  * @param args
  */
 public static void main(String[] args) {
  // TODO Auto-generated method stub
  Properties p=System.getProperties();
  //p.list(System.out);
  System.out.println(p.getProperty("java.class.path"));
  System.out.println(p.getProperty("os.name"));
  }

}

&lt;/pre&gt;
&lt;/div&gt;
output:&lt;br /&gt;
. (dot -it means current working directory)&lt;br /&gt;
Windows XP&lt;br /&gt;
&lt;div class="separator" style="clear: both; text-align: center;"&gt;
&lt;a href="http://2.bp.blogspot.com/-rEjg2EvFQko/UYvfxKCpu-I/AAAAAAAARWE/HyaGDxwGXDI/s1600/system.properties.JPG" imageanchor="1" style="margin-left: 1em; margin-right: 1em;"&gt;&lt;img border="0" height="265" src="http://2.bp.blogspot.com/-rEjg2EvFQko/UYvfxKCpu-I/AAAAAAAARWE/HyaGDxwGXDI/s640/system.properties.JPG" width="640" /&gt;&lt;/a&gt;&lt;/div&gt;
&lt;br /&gt;&lt;/div&gt;&lt;img src="http://feeds.feedburner.com/~r/blogspot/TerSJ/~4/isJbKuKM81k" height="1" width="1"/&gt;</description><link>http://feedproxy.google.com/~r/blogspot/TerSJ/~3/isJbKuKM81k/how-to-get-system-properties-in-java.html</link><author>ani01104@gmail.com (Madhumita)</author><media:thumbnail url="http://2.bp.blogspot.com/-U6QGBp6V_Yw/UYvR9EqPprI/AAAAAAAARV0/Ce2iqNjfEP4/s72-c/java.jpg" height="72" width="72" /><thr:total>0</thr:total><feedburner:origLink>http://www.askqtp.com/2013/05/how-to-get-system-properties-in-java.html</feedburner:origLink></item><item><guid isPermaLink="false">tag:blogger.com,1999:blog-2981436578666077634.post-3490015398514207918</guid><pubDate>Tue, 07 May 2013 19:03:00 +0000</pubDate><atom:updated>2013-05-08T00:54:48.705+05:30</atom:updated><category domain="http://www.blogger.com/atom/ns#">java</category><category domain="http://www.blogger.com/atom/ns#">Classpath</category><category domain="http://www.blogger.com/atom/ns#">Settings of Classpath</category><title>What Is Classpath And How To Set That In Java</title><description>&lt;div dir="ltr" style="text-align: left;" trbidi="on"&gt;
&lt;div dir="ltr" style="text-align: left;" trbidi="on"&gt;
&lt;div dir="ltr" style="text-align: left;" trbidi="on"&gt;
&lt;div class="separator" style="clear: both; text-align: center;"&gt;
&lt;a href="http://2.bp.blogspot.com/-2SSwvXJjn9k/UQv-5zuVTdI/AAAAAAAAQaM/hKNtf1SnBrw/s1600/class.jpg" imageanchor="1" style="clear: left; float: left; margin-bottom: 1em; margin-right: 1em;"&gt;&lt;img border="0" src="http://2.bp.blogspot.com/-2SSwvXJjn9k/UQv-5zuVTdI/AAAAAAAAQaM/hKNtf1SnBrw/s1600/class.jpg" /&gt;&lt;/a&gt;&lt;/div&gt;
&lt;span style="font-family: Arial,Helvetica,sans-serif;"&gt;&lt;span style="font-size: small;"&gt;In java, the source file is written in normal text and saved with &lt;u&gt;&lt;b&gt;.java&amp;nbsp; &lt;/b&gt;&lt;/u&gt;extension.&lt;/span&gt;&lt;/span&gt;&lt;br /&gt;
&lt;span style="font-family: Arial,Helvetica,sans-serif;"&gt;&lt;span style="font-size: small;"&gt;The compiler upon invoked by the command javac creates a .class file for the corresponding .java file.&lt;/span&gt;&lt;/span&gt;&lt;br /&gt;
&lt;span style="font-family: Arial,Helvetica,sans-serif;"&gt;&lt;span style="font-size: small;"&gt;&lt;br /&gt;
&lt;/span&gt;&lt;/span&gt; &lt;span style="font-family: Arial,Helvetica,sans-serif;"&gt;&lt;span style="font-size: small;"&gt;The JVM during run time reads the .class file ,performs certain checks and execute the same.&lt;/span&gt;&lt;/span&gt;&lt;br /&gt;
&lt;span style="font-family: Arial,Helvetica,sans-serif;"&gt;&lt;span style="font-size: small;"&gt;&lt;br /&gt;
&lt;/span&gt;&lt;/span&gt; &lt;span style="font-family: Arial,Helvetica,sans-serif;"&gt;&lt;span style="font-size: small;"&gt;if the .class file is placed under ...../java/bin/ folder . It is not required to mention classpath. But when our project becomes larger, it is required to create some folder structure and place all the necessary .class file at one place,it is extremely required for JVM to know where the .class files resides.&lt;/span&gt;&lt;/span&gt;&lt;br /&gt;
&lt;span style="font-family: Arial,Helvetica,sans-serif;"&gt;&lt;span style="font-size: small;"&gt;&lt;br /&gt;
&lt;/span&gt;&lt;/span&gt; &lt;span style="font-family: Arial,Helvetica,sans-serif;"&gt;&lt;span style="font-size: small;"&gt;This post will talk about the different settings how to set classpath in different way.&lt;/span&gt;&lt;/span&gt;&lt;br /&gt;
&lt;br /&gt;
&lt;u&gt;&lt;b&gt; &lt;/b&gt;&lt;/u&gt;&lt;u&gt;&lt;b&gt; &lt;/b&gt;&lt;/u&gt;&lt;br /&gt;
&lt;table bgcolor="#e4eded" border="0" bordercolor="#000000" style="height: 22px; width: 649px;"&gt;&lt;tbody&gt;
&lt;tr&gt;&lt;td&gt;&lt;b&gt;&lt;span style="color: #004080;"&gt;Classpath settings&lt;/span&gt;&lt;/b&gt;&lt;/td&gt;&lt;/tr&gt;
&lt;/tbody&gt;&lt;/table&gt;
How to set classpath for java...&lt;br /&gt;
&lt;ul style="text-align: left;"&gt;
&lt;li&gt;In my previous post &lt;a href="http://www.askqtp.com/2012/01/setting-class-path-in-java-in-windows.html" target="_blank"&gt;here,&lt;/a&gt; I have shown how to set classpath permanently from environment variable&lt;/li&gt;
&lt;li&gt;Temporary for a command session&lt;br /&gt;
&lt;pre class="java" name="code"&gt;set classpath=%classpath%;E:\myPrograms\
//%classpath% is to keep what ever is already present in the classpath;Now provide the required classpath followed by a semi colon(;)
&lt;/pre&gt;
This command is valid for the command prompt it has been set. If you open another command prompt the java command will not work.&lt;br /&gt;
&lt;br /&gt;
&lt;/li&gt;
&lt;li&gt;One more option is also available for setting classpath, valid for a single command.&lt;br /&gt;
&lt;pre class="java" name="code"&gt;java -cp &amp;lt;&amp;lt;full classpath&amp;gt;&amp;gt; &amp;lt;&amp;lt;name of the class&amp;gt;&amp;gt;
like-java -cp E:\myProgram Test123
&lt;/pre&gt;
&lt;/li&gt;
&lt;/ul&gt;
&lt;/div&gt;
&lt;/div&gt;
The scope of the process:&lt;br /&gt;
&lt;ul style="text-align: left;"&gt;
&lt;li&gt;Set globally--across the command prompts&lt;/li&gt;
&lt;li&gt;Set classpath at command prompt--only for that command prompt session&lt;/li&gt;
&lt;li&gt;Set classpath on command level-only for that command&lt;/li&gt;
&lt;/ul&gt;
While going for the 3rd option there are things to remember:&lt;br /&gt;
&lt;ul style="text-align: left;"&gt;
&lt;li&gt;-cp will not consider present working directory by default. We need to include dot(.) to get present working directory into classpath&lt;/li&gt;
&lt;li&gt;Always use full path while working with -cp&lt;/li&gt;
&lt;li&gt;if the same class file available in different directories then JVM will read from left to write for the -cp command and whenever the first occurrence of the class is available JVM will pick that and execute. But the next sequence will not be picked again. &lt;/li&gt;
&lt;/ul&gt;
&lt;div class="separator" style="clear: both; text-align: center;"&gt;
&lt;a href="http://1.bp.blogspot.com/-WA4Ha_-FE20/UYlNt1s3hQI/AAAAAAAARVk/Uv8CFWK6NPo/s1600/C-D-E.JPG" imageanchor="1" style="margin-left: 1em; margin-right: 1em;"&gt;&lt;img border="0" height="296" src="http://1.bp.blogspot.com/-WA4Ha_-FE20/UYlNt1s3hQI/AAAAAAAARVk/Uv8CFWK6NPo/s640/C-D-E.JPG" width="640" /&gt;&lt;/a&gt;&lt;/div&gt;
&amp;nbsp;so in drive C,D,E three test class is available.&lt;br /&gt;
Now if we provide&lt;br /&gt;
&lt;pre class="java" name="code"&gt;java -cp C:;D:;E: test &lt;/pre&gt;
only C: drives test will be executed,D and E will be ignored.&lt;br /&gt;
similarly if we provide&lt;br /&gt;
&lt;pre class="java" name="code"&gt;java -cp D:;C:;E: test &lt;/pre&gt;
only D: drives test will be executed,C and E will be ignored.&lt;/div&gt;&lt;img src="http://feeds.feedburner.com/~r/blogspot/TerSJ/~4/eAsj81vt098" height="1" width="1"/&gt;</description><link>http://feedproxy.google.com/~r/blogspot/TerSJ/~3/eAsj81vt098/what-is-classpath-and-how-to-set-that.html</link><author>ani01104@gmail.com (Madhumita)</author><media:thumbnail url="http://2.bp.blogspot.com/-2SSwvXJjn9k/UQv-5zuVTdI/AAAAAAAAQaM/hKNtf1SnBrw/s72-c/class.jpg" height="72" width="72" /><thr:total>0</thr:total><feedburner:origLink>http://www.askqtp.com/2013/05/what-is-classpath-and-how-to-set-that.html</feedburner:origLink></item><item><guid isPermaLink="false">tag:blogger.com,1999:blog-2981436578666077634.post-7012349878820347573</guid><pubDate>Mon, 06 May 2013 19:48:00 +0000</pubDate><atom:updated>2013-05-07T01:18:21.499+05:30</atom:updated><category domain="http://www.blogger.com/atom/ns#">java</category><category domain="http://www.blogger.com/atom/ns#">OCJP</category><category domain="http://www.blogger.com/atom/ns#">Certification</category><title>OCJP Cerification Sample Question Set-1</title><description>&lt;div dir="ltr" style="text-align: left;" trbidi="on"&gt;
&lt;div class="separator" style="clear: both; text-align: center;"&gt;
&lt;a href="http://1.bp.blogspot.com/-cYkbTANzpDs/UYgGkOh5ZpI/AAAAAAAARVU/a-A66V-j6RU/s1600/ocjp.jpg" imageanchor="1" style="clear: left; float: left; margin-bottom: 1em; margin-right: 1em;"&gt;&lt;img border="0" src="http://1.bp.blogspot.com/-cYkbTANzpDs/UYgGkOh5ZpI/AAAAAAAARVU/a-A66V-j6RU/s1600/ocjp.jpg" /&gt;&lt;/a&gt;&lt;/div&gt;
In this post I am going to provide the sample question set for preparing OCJP Examination.&lt;br /&gt;
&lt;br /&gt;
&lt;ol style="text-align: left;"&gt;
&lt;li&gt;&lt;u&gt;&lt;b&gt;Question-1&lt;/b&gt;&lt;/u&gt;&lt;/li&gt;
&lt;pre class="java" name="code"&gt;public class operatortest {
static public void main(String[] Args)
{
int i ,j;
for(i=0;i&amp;lt;3;i  )
 {
 for(j=1;j&amp;lt;4;j  )
 {
 i%=j;
 System.out.print(j);
    }
 }
}
}

&lt;/pre&gt;
&lt;/ol&gt;
&lt;u&gt;&lt;b&gt;Options:&lt;/b&gt;&lt;/u&gt;&lt;br /&gt;
&lt;ol style="text-align: left;"&gt;
&lt;li&gt;1 2 3 1&lt;/li&gt;
&lt;li&gt;1 2 3 2&lt;/li&gt;
&lt;li&gt;Continue print 1 2 3 1 2 3&amp;nbsp; and create a infinite loop&lt;/li&gt;
&lt;li&gt;Program compile fails at line -2&lt;/li&gt;
&lt;/ol&gt;
&lt;br /&gt;
&lt;br /&gt;
&amp;nbsp;To be continued...&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;u&gt;&lt;b&gt;Solutions&lt;/b&gt;&lt;/u&gt; &lt;br /&gt;
&lt;ol style="text-align: left;"&gt;
&lt;li&gt;3&lt;/li&gt;
&lt;/ol&gt;
&lt;br /&gt;&lt;/div&gt;&lt;img src="http://feeds.feedburner.com/~r/blogspot/TerSJ/~4/a1bUckcPUIk" height="1" width="1"/&gt;</description><link>http://feedproxy.google.com/~r/blogspot/TerSJ/~3/a1bUckcPUIk/ocjp-cerification-sample-question-set-1.html</link><author>ani01104@gmail.com (Madhumita)</author><media:thumbnail url="http://1.bp.blogspot.com/-cYkbTANzpDs/UYgGkOh5ZpI/AAAAAAAARVU/a-A66V-j6RU/s72-c/ocjp.jpg" height="72" width="72" /><thr:total>0</thr:total><feedburner:origLink>http://www.askqtp.com/2013/05/ocjp-cerification-sample-question-set-1.html</feedburner:origLink></item><item><guid isPermaLink="false">tag:blogger.com,1999:blog-2981436578666077634.post-7354265771007386771</guid><pubDate>Sat, 04 May 2013 18:25:00 +0000</pubDate><atom:updated>2013-05-14T18:05:45.356+05:30</atom:updated><category domain="http://www.blogger.com/atom/ns#">java</category><category domain="http://www.blogger.com/atom/ns#">Runtime Exception in java</category><category domain="http://www.blogger.com/atom/ns#">infinity</category><category domain="http://www.blogger.com/atom/ns#">Arithmetic exception in java</category><title>Concept Of Infinity in Java Arithmetic Exception vs Display of Infinity</title><description>&lt;div dir="ltr" style="text-align: left;" trbidi="on"&gt;&lt;div dir="ltr" style="text-align: left;" trbidi="on"&gt;&lt;div class="separator" style="clear: both; text-align: center;"&gt;&lt;a href="http://1.bp.blogspot.com/-mDWCBqsYy9g/UYU1f5_5JbI/AAAAAAAARU8/ehLf4V4NyiU/s1600/image.jpg" imageanchor="1" style="clear: left; float: left; margin-bottom: 1em; margin-right: 1em;"&gt;&lt;img border="0" src="http://1.bp.blogspot.com/-mDWCBqsYy9g/UYU1f5_5JbI/AAAAAAAARU8/ehLf4V4NyiU/s1600/image.jpg" /&gt;&lt;/a&gt;&lt;/div&gt;Have you ever heard of infinity concept in java? if no, this post is for you.&lt;br /&gt;
In mathematics x/y =infinity when y=0&lt;br /&gt;
in our normal computation there is no way to show infinity. Normal computation means when we use integral arithmetic(data type-int,short,char,byte,long)&lt;br /&gt;
&lt;br /&gt;
So any of these datatype's variable divided by zero , we are going to get &lt;b&gt;Arithmetic exception ::divided by zero error&lt;/b&gt;.&lt;br /&gt;
Mostly&amp;nbsp; &lt;br /&gt;
&lt;br /&gt;
Let's see how..&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;pre class="java" name="code"&gt;public class operatortest {
 public static void main(String[] Args)
 {
 int x=10;
 System.out.print(x/0);
 }
 }

&lt;/pre&gt;&lt;br /&gt;
&lt;br /&gt;
&lt;div class="Blue_hearder"&gt;&lt;b&gt;  Exact Error code:&lt;/b&gt;&lt;br /&gt;
Exception in thread "main" java.lang.ArithmeticException: / by zero at operatortest.main(operatortest.java:6)&lt;br /&gt;
&lt;br /&gt;
&lt;/div&gt;&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
But when we will use double and float point arithmetic computation, we have a way to represent infinity. &lt;br /&gt;
&lt;br /&gt;
&lt;pre class="java" name="code"&gt;public class operatortest {
 public static void main(String[] Args)
 {
 double x=10.00;
 System.out.print(x/0);
 }
 }

&lt;/pre&gt;output: Infinity&lt;br /&gt;
&lt;br /&gt;
In mathematics we can have positive infinity and negative infinity. Similarly in java computation we can have positive infinity and negative infinity.&lt;br /&gt;
The above written code produces positive infinity.&lt;br /&gt;
&lt;br /&gt;
&lt;pre class="java" name="code"&gt;public class operatortest {
 public static void main(String[] Args)
 {
 double x=-10.00;
 System.out.print(x/0);
 }
 }

&lt;/pre&gt;output: - Infinity&lt;br /&gt;
&lt;br /&gt;
&lt;/div&gt;So please remember any number divided by zero does not necessarily give arithmetic exception. There can be infinity too.&lt;br /&gt;
The corresponding definition can be found &lt;a href="http://www.geom.uiuc.edu/~daeron/docs/apidocs/java.lang.Double.html"&gt;here&lt;/a&gt;&lt;br /&gt;
&lt;br /&gt;
&lt;div class="Note"&gt;&lt;b&gt;o POSITIVE_INFINITY&lt;/b&gt;&lt;br /&gt;
public final static double POSITIVE_INFINITY&lt;br /&gt;
Positive infinity. &lt;br /&gt;
&lt;b&gt;o NEGATIVE_INFINITY&lt;/b&gt;&lt;br /&gt;
public final static double NEGATIVE_INFINITY&lt;br /&gt;
Negative infinity.&lt;br /&gt;
So for integral arithmetic we will get Run time Error of Divide by Zero but for floating point arithmetic we will get positive or negative infinity rather than getting Run time error.&lt;/div&gt;&lt;/div&gt;&lt;img src="http://feeds.feedburner.com/~r/blogspot/TerSJ/~4/DMQN0TsTdEA" height="1" width="1"/&gt;</description><link>http://feedproxy.google.com/~r/blogspot/TerSJ/~3/DMQN0TsTdEA/concept-of-infinity-in-java-arithmetic.html</link><author>ani01104@gmail.com (Madhumita)</author><media:thumbnail url="http://1.bp.blogspot.com/-mDWCBqsYy9g/UYU1f5_5JbI/AAAAAAAARU8/ehLf4V4NyiU/s72-c/image.jpg" height="72" width="72" /><thr:total>0</thr:total><feedburner:origLink>http://www.askqtp.com/2013/05/concept-of-infinity-in-java-arithmetic.html</feedburner:origLink></item><item><guid isPermaLink="false">tag:blogger.com,1999:blog-2981436578666077634.post-5836598796377601576</guid><pubDate>Sat, 04 May 2013 13:55:00 +0000</pubDate><atom:updated>2013-05-04T20:10:42.119+05:30</atom:updated><category domain="http://www.blogger.com/atom/ns#">Operators</category><category domain="http://www.blogger.com/atom/ns#">java</category><title>What Is The Difference Between ++x And x=x+1 or --x And x=x-1?</title><description>&lt;div dir="ltr" style="text-align: left;" trbidi="on"&gt;
&lt;div dir="ltr" style="text-align: left;" trbidi="on"&gt;
&lt;div dir="ltr" style="text-align: left;" trbidi="on"&gt;
&lt;div dir="ltr" style="text-align: left;" trbidi="on"&gt;
&lt;div dir="ltr" style="text-align: left;" trbidi="on"&gt;
&lt;div class="separator" style="clear: both; text-align: center;"&gt;
&lt;a href="http://4.bp.blogspot.com/-qBb3PCEJ_Tg/UYTVpxJknNI/AAAAAAAARUE/fsyTlKl8n4g/s1600/java.jpg" imageanchor="1" style="clear: left; float: left; margin-bottom: 1em; margin-right: 1em;"&gt;&lt;img border="0" src="http://4.bp.blogspot.com/-qBb3PCEJ_Tg/UYTVpxJknNI/AAAAAAAARUE/fsyTlKl8n4g/s1600/java.jpg" /&gt;&lt;/a&gt;&lt;/div&gt;
This is most interesting question is What Is the difference between ++x and x=x+1 while working with java.&lt;br /&gt;
&lt;br /&gt;
both the statement does the same thing--increment the value of x by 1.&lt;br /&gt;
Then the doubts come&lt;br /&gt;
&lt;ul style="text-align: left;"&gt;
&lt;li&gt;If both they do same thing why we will have two statements?&lt;/li&gt;
&lt;li&gt;If they are different then how?&lt;/li&gt;
&lt;li&gt;Which one is more efficient?&lt;/li&gt;
&lt;/ul&gt;
&amp;nbsp;Let us discuss the concept with some example..&lt;br /&gt;
&lt;pre class="java" name="code"&gt;public class operatortest {
 public static void main(String[] Args)
 {
 int x=4;
 ++x;
     System.out.println(x);
 }
 }

&lt;/pre&gt;
output-&amp;gt;5&lt;/div&gt;
now if we change the statement like--&lt;br /&gt;
&lt;pre class="java" name="code"&gt;public class operatortest {
 public static void main(String[] Args)
 {
 int x=4;
 x=x=1;
     System.out.println(x);
 }
 }

&lt;/pre&gt;
output-&amp;gt;5 only&lt;br /&gt;
Till now no problem if the datatypes are int/long/double&lt;br /&gt;
but say the  datatype changes now..&lt;br /&gt;
&lt;a href="http://www.blogger.com/blogger.g?blogID=2981436578666077634" imageanchor="1" style="clear: left; float: left; margin-bottom: 1em; margin-right: 1em;"&gt;&lt;/a&gt;instead of int if we use char/byte/short??&lt;br /&gt;
lets see...&lt;br /&gt;
&lt;pre class="java" name="code"&gt;public class operatortest {
 public static void main(String[] Args)
 {
 byte x=4;
 x=x=1;
     System.out.println(x);
 }
 }

&lt;/pre&gt;
&lt;a href="http://www.blogger.com/blogger.g?blogID=2981436578666077634" imageanchor="1" style="clear: left; float: left; margin-bottom: 1em; margin-right: 1em;"&gt;&lt;/a&gt;very quickly we will get a compile time error..&lt;br /&gt;
&lt;div class="separator" style="clear: both; text-align: center;"&gt;
&lt;a href="http://www.blogger.com/blogger.g?blogID=2981436578666077634" imageanchor="1" style="margin-left: 1em; margin-right: 1em;"&gt;&lt;/a&gt;&lt;/div&gt;
&lt;a href="http://www.blogger.com/blogger.g?blogID=2981436578666077634" imageanchor="1" style="clear: left; float: left; margin-bottom: 1em; margin-right: 1em;"&gt;&lt;/a&gt;&lt;a href="http://www.blogger.com/blogger.g?blogID=2981436578666077634" imageanchor="1" style="clear: left; float: left; margin-bottom: 1em; margin-right: 1em;"&gt;&lt;/a&gt;&lt;a href="http://www.blogger.com/blogger.g?blogID=2981436578666077634" imageanchor="1" style="clear: left; float: left; margin-bottom: 1em; margin-right: 1em;"&gt;&lt;/a&gt;&lt;a href="http://4.bp.blogspot.com/-171DyFp47XM/UYUF5oqUEzI/AAAAAAAARUc/wDrOIeFh0uw/s1600/compileerror.JPG" imageanchor="1"&gt;&lt;img border="0" height="232" src="http://4.bp.blogspot.com/-171DyFp47XM/UYUF5oqUEzI/AAAAAAAARUc/wDrOIeFh0uw/s640/compileerror.JPG" width="640" /&gt;&lt;/a&gt;&lt;/div&gt;
if you are running through DOS prompt..&lt;br /&gt;
&lt;a href="http://www.blogger.com/blogger.g?blogID=2981436578666077634" imageanchor="1" style="clear: left; float: left; margin-bottom: 1em; margin-right: 1em;"&gt;&lt;/a&gt;you can see compile error---possible loss of precision&lt;br /&gt;
&lt;a href="http://www.blogger.com/blogger.g?blogID=2981436578666077634" imageanchor="1" style="clear: right; float: right; margin-bottom: 1em; margin-left: 1em;"&gt;&lt;/a&gt;&lt;a href="http://1.bp.blogspot.com/-WQnHYe_2XMA/UYUHNwLF82I/AAAAAAAARUo/LYydYYXonMc/s1600/compileerror1.JPG" imageanchor="1"&gt;&lt;img border="0" height="78" src="http://1.bp.blogspot.com/-WQnHYe_2XMA/UYUHNwLF82I/AAAAAAAARUo/LYydYYXonMc/s640/compileerror1.JPG" width="640" /&gt;&lt;/a&gt;&lt;/div&gt;
&lt;pre class="java" name="code"&gt;public class operatortest {
 public static void main(String[] Args)
 {
        byte x=4;
 ++x;
     System.out.println(x);
 }
 }

&lt;/pre&gt;
output--5&lt;br /&gt;
So no problem with&amp;nbsp;++ operator.&lt;/div&gt;
&lt;br /&gt;
&lt;table bgcolor="#e4eded" border="0" bordercolor="#000000" style="width: 650px;"&gt;&lt;tbody&gt;
&lt;tr&gt; &lt;td&gt;&lt;b&gt;&lt;span style="color: #004080;"&gt;So the answer of questions are even though we have&amp;nbsp;x++ and x=x+1 statement, they have same pourpose. But in case of ++ or -- operator internal type casting is performed by the compiler,but in case of the normal operators developer need to do type casting explicitly. hence ++,-- operators are most efficient.&lt;/span&gt;&lt;/b&gt;&lt;/td&gt;&lt;/tr&gt;
&lt;/tbody&gt;&lt;/table&gt;
&lt;/div&gt;&lt;img src="http://feeds.feedburner.com/~r/blogspot/TerSJ/~4/IT03OJZNQaw" height="1" width="1"/&gt;</description><link>http://feedproxy.google.com/~r/blogspot/TerSJ/~3/IT03OJZNQaw/what-is-difference-between-x-and-xx1-or.html</link><author>ani01104@gmail.com (Madhumita)</author><media:thumbnail url="http://4.bp.blogspot.com/-qBb3PCEJ_Tg/UYTVpxJknNI/AAAAAAAARUE/fsyTlKl8n4g/s72-c/java.jpg" height="72" width="72" /><thr:total>0</thr:total><feedburner:origLink>http://www.askqtp.com/2013/05/what-is-difference-between-x-and-xx1-or.html</feedburner:origLink></item><item><guid isPermaLink="false">tag:blogger.com,1999:blog-2981436578666077634.post-7519010363388408521</guid><pubDate>Wed, 01 May 2013 19:37:00 +0000</pubDate><atom:updated>2013-05-02T01:08:39.325+05:30</atom:updated><category domain="http://www.blogger.com/atom/ns#">java</category><category domain="http://www.blogger.com/atom/ns#">Arithmetic Operator</category><category domain="http://www.blogger.com/atom/ns#">Type casting</category><title>Golden Rules for Type Casting While Working With Arithmetic Operator</title><description>&lt;div dir="ltr" style="text-align: left;" trbidi="on"&gt;
&lt;table cellpadding="0" cellspacing="0" class="tr-caption-container" style="float: left; margin-right: 1em; text-align: left;"&gt;&lt;tbody&gt;
&lt;tr&gt;&lt;td style="text-align: center;"&gt;&lt;a href="http://4.bp.blogspot.com/-81CnHYwNR2U/UYFF03X3yPI/AAAAAAAARTk/pmElKd57yUY/s1600/operator.jpg" imageanchor="1" style="clear: left; margin-bottom: 1em; margin-left: auto; margin-right: auto;"&gt;&lt;img border="0" src="http://4.bp.blogspot.com/-81CnHYwNR2U/UYFF03X3yPI/AAAAAAAARTk/pmElKd57yUY/s1600/operator.jpg" /&gt;&lt;/a&gt;&lt;/td&gt;&lt;/tr&gt;
&lt;tr&gt;&lt;td class="tr-caption" style="text-align: center;"&gt;image credit:devcentral.f5.com&lt;/td&gt;&lt;/tr&gt;
&lt;/tbody&gt;&lt;/table&gt;
&lt;table bgcolor="#e4eded" border="0" bordercolor="#000000" style="width: 650px;"&gt;&lt;tbody&gt;
&lt;tr&gt; &lt;td&gt;&lt;b&gt;&lt;span style="color: #004080;"&gt;Arithmetic Operators:&lt;/span&gt;&lt;/b&gt;&lt;/td&gt;&lt;/tr&gt;
&lt;/tbody&gt;&lt;/table&gt;
In java +,-,*,/,% are called arithmetic operators.Arithmetic operator is used on two operand of same type or different&amp;nbsp; types(applicable)&lt;br /&gt;
&lt;br /&gt;
Like-&lt;br /&gt;
&lt;pre class="java" name="code"&gt;int a=10;
int b=10;
int c=a+b;
System.out.print(c);

&lt;/pre&gt;
output-20&lt;br /&gt;
But if we take some different example like--&lt;br /&gt;
&lt;pre class="java" name="code"&gt;int a=10;
double b=10.00;
int c=a+b;
System.out.print(c);

&lt;/pre&gt;
&lt;br /&gt;
output:&lt;br /&gt;
possible loss of precision&lt;br /&gt;
found   : double&lt;br /&gt;
required: int&lt;br /&gt;
int c=a+b;&lt;br /&gt;
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; ^&lt;br /&gt;
Now this looks very confusing. Is n't? in variable b we are only assigning value 10, which can be considered&amp;nbsp; as valid int. still compiler is not approving the arithmetic operations.&lt;br /&gt;
&lt;br /&gt;
if you are thinking that the second case failed as the operand types are different and first case passed as two operands were of same type, please check out the below code&lt;br /&gt;
&lt;br /&gt;
&lt;pre class="java" name="code"&gt;byte a=10;
byte b=20;
byte c=a+b;
System.out.print(c);

&lt;/pre&gt;
output:&lt;br /&gt;
possible loss of precision&lt;br /&gt;
&lt;u&gt;&lt;b&gt;found   : int&lt;/b&gt;&lt;/u&gt;&lt;br /&gt;
required: byte&lt;br /&gt;
byte c=a+b;&lt;br /&gt;
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; ^&lt;br /&gt;
The most confusing part is the two operand are of type(byte) but still compiler found &lt;b&gt;&lt;u&gt;int type&lt;/u&gt;&lt;/b&gt;.&lt;br /&gt;
Java compiler is too complicated??? &lt;br /&gt;
&lt;br /&gt;
&lt;table bgcolor="#e4eded" border="0" bordercolor="#000000" style="width: 650px;"&gt;&lt;tbody&gt;
&lt;tr&gt; &lt;td&gt;&lt;b&gt;&lt;span style="color: #004080;"&gt;Arithmetic Operators Rule:&lt;/span&gt;&lt;/b&gt;&lt;/td&gt;&lt;/tr&gt;
&lt;/tbody&gt;&lt;/table&gt;
Let us see the data types (primitive ) in java..&lt;br /&gt;
&lt;br /&gt;
&lt;table cellpadding="0" cellspacing="0" class="tr-caption-container" style="margin-left: auto; margin-right: auto; text-align: center;"&gt;&lt;tbody&gt;
&lt;tr&gt;&lt;td style="text-align: center;"&gt;&lt;a href="http://3.bp.blogspot.com/-_Lh40dBWIYo/UYFqkScmRlI/AAAAAAAART0/1sU2xrl687w/s1600/types+in+java.JPG" imageanchor="1" style="clear: left; margin-bottom: 1em; margin-left: auto; margin-right: auto;"&gt;&lt;img border="0" height="507" src="http://3.bp.blogspot.com/-_Lh40dBWIYo/UYFqkScmRlI/AAAAAAAART0/1sU2xrl687w/s640/types+in+java.JPG" width="640" /&gt;&lt;/a&gt;&lt;/td&gt;&lt;/tr&gt;
&lt;tr&gt;&lt;td class="tr-caption" style="text-align: center;"&gt;datatypes as per capacity byte being smallest and double being the highest &lt;/td&gt;&lt;/tr&gt;
&lt;/tbody&gt;&lt;/table&gt;
&lt;br /&gt;
&lt;br /&gt;
If we apply any arithmetic operator between two operands say x,y then the result type should follow the below written rule&lt;br /&gt;
&lt;br /&gt;
&lt;u&gt;&lt;b&gt;MAX(int,datatype of first operand,datatype of second operand)&lt;/b&gt;&lt;/u&gt; &lt;br /&gt;
&lt;br /&gt;
so for all arithmetic operation the above rule will be applicable..&lt;br /&gt;
lets take the third example...&lt;br /&gt;
&lt;pre class="java" name="code"&gt;byte a=10;
byte b=20;
byte c=a+b;
System.out.print(c);

&lt;/pre&gt;
so for this case--the right side datatype evaluation will be..&lt;br /&gt;
as per rule-&lt;br /&gt;
Max(int,byte,byte)&lt;br /&gt;
Now as per the diagram among int,byte and byte the max is int, hence the right hand side datatype evaluation will be int.&lt;br /&gt;
please check the compiler error message--found int.&lt;br /&gt;
the second point is here the int is being assigned to byte whose capacity is&amp;nbsp; lower than int. So compiler is rightly pointing out--"possible loss of precision"&lt;br /&gt;
&lt;br /&gt;
For a quick reference let us see the output datatype for few mixed case..&lt;br /&gt;
&lt;table border="1" bordercolor="FFCC00" cellpadding="3" cellspacing="3" style="background-color: #ffffcc; height: 75px; width: 547px;"&gt; &lt;tbody&gt;
&lt;tr&gt;   &lt;td&gt;Datatypes of first operand and second operand&lt;/td&gt;   &lt;td&gt;output datatype&lt;/td&gt;  &lt;/tr&gt;
&lt;tr&gt;   &lt;td&gt;&lt;b&gt;byte+byte&lt;/b&gt;&lt;/td&gt;   &lt;td&gt;&lt;b&gt;int &lt;/b&gt;&lt;/td&gt;  &lt;/tr&gt;
&lt;tr&gt;   &lt;td&gt;&lt;b&gt;byte+short&lt;/b&gt;&lt;/td&gt;   &lt;td&gt;&lt;b&gt;int &lt;/b&gt;&lt;/td&gt;  &lt;/tr&gt;
&lt;tr&gt;   &lt;td&gt;&lt;b&gt;char+char&lt;/b&gt;&lt;/td&gt;   &lt;td&gt;&lt;b&gt;int &lt;/b&gt;&lt;/td&gt;  &lt;/tr&gt;
&lt;tr&gt;   &lt;td&gt;long+int&lt;/td&gt;   &lt;td&gt;long&lt;/td&gt;  &lt;/tr&gt;
&lt;tr&gt;   &lt;td&gt;float+long &lt;/td&gt;&lt;td&gt;float&lt;/td&gt;  &lt;/tr&gt;
&lt;tr&gt;   &lt;td&gt;double+int &lt;/td&gt;&lt;td&gt;double&lt;/td&gt;  &lt;/tr&gt;
&lt;tr&gt;   &lt;td&gt;double+any&lt;/td&gt;   &lt;td&gt;double &lt;/td&gt;  &lt;/tr&gt;
&lt;/tbody&gt;&lt;/table&gt;
&lt;br /&gt;
The only thing if one of the data type is string then these rules will not be applicable.&lt;br /&gt;
Thats it!!! &lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;&lt;/div&gt;&lt;img src="http://feeds.feedburner.com/~r/blogspot/TerSJ/~4/ao0QxHoIlsk" height="1" width="1"/&gt;</description><link>http://feedproxy.google.com/~r/blogspot/TerSJ/~3/ao0QxHoIlsk/golden-rules-for-type-casting-while.html</link><author>ani01104@gmail.com (Madhumita)</author><media:thumbnail url="http://4.bp.blogspot.com/-81CnHYwNR2U/UYFF03X3yPI/AAAAAAAARTk/pmElKd57yUY/s72-c/operator.jpg" height="72" width="72" /><thr:total>0</thr:total><feedburner:origLink>http://www.askqtp.com/2013/05/golden-rules-for-type-casting-while.html</feedburner:origLink></item><item><guid isPermaLink="false">tag:blogger.com,1999:blog-2981436578666077634.post-2680795331279063398</guid><pubDate>Tue, 30 Apr 2013 17:59:00 +0000</pubDate><atom:updated>2013-04-30T23:29:59.117+05:30</atom:updated><category domain="http://www.blogger.com/atom/ns#">java</category><title>4 Rules to Remember While Working With Incremental And Decremental Operator in Java</title><description>&lt;div dir="ltr" style="text-align: left;" trbidi="on"&gt;
&lt;div dir="ltr" style="text-align: left;" trbidi="on"&gt;
&lt;div dir="ltr" style="text-align: left;" trbidi="on"&gt;
&lt;div dir="ltr" style="text-align: left;" trbidi="on"&gt;
&lt;div dir="ltr" style="text-align: left;" trbidi="on"&gt;
&lt;div dir="ltr" style="text-align: left;" trbidi="on"&gt;
&lt;div dir="ltr" style="text-align: left;" trbidi="on"&gt;
&lt;div dir="ltr" style="text-align: left;" trbidi="on"&gt;
&lt;div dir="ltr" style="text-align: left;" trbidi="on"&gt;
&lt;div class="separator" style="clear: both; text-align: center;"&gt;
&lt;a href="http://3.bp.blogspot.com/-uW3RfTCBTT0/UX7Nbdw96EI/AAAAAAAARSA/F8_IqjxAerI/s1600/java.jpg" imageanchor="1" style="clear: left; float: left; margin-bottom: 1em; margin-right: 1em;"&gt;&lt;img border="0" src="http://3.bp.blogspot.com/-uW3RfTCBTT0/UX7Nbdw96EI/AAAAAAAARSA/F8_IqjxAerI/s1600/java.jpg" /&gt;&lt;/a&gt;&lt;/div&gt;
In java the '++' operator is called incremental and '--' operator is called decremental operator. Again Incremental can be divided&lt;br /&gt;
&lt;ul style="text-align: left;"&gt;
&lt;li&gt;pre increment (y=++x) &lt;/li&gt;
&lt;li&gt;Post increment (y=x++)&lt;/li&gt;
&lt;/ul&gt;
in pre increment the value of the variable is incremented first and then assign to y.&lt;br /&gt;
&lt;br /&gt;
in post increment the value is assigned first then its value is incremented.&lt;br /&gt;
Similarly for decrement we have&lt;br /&gt;
&lt;ul style="text-align: left;"&gt;
&lt;li&gt;pre decrement (y=--x) &lt;/li&gt;
&lt;li&gt;post decrement (y=x--)&lt;/li&gt;
&lt;/ul&gt;
Now most importantly the rules are..&lt;br /&gt;
&lt;table bgcolor="#e4eded" border="0" bordercolor="#000000" style="width: 650px;"&gt;&lt;tbody&gt;
&lt;tr&gt; &lt;td&gt;&lt;b&gt;&lt;span style="color: #004080;"&gt;Increment and decrement operator can only be applied to&lt;b&gt; variable but not for any constant values..&lt;/b&gt;&lt;/span&gt;&lt;/b&gt;&lt;/td&gt;&lt;/tr&gt;
&lt;/tbody&gt;&lt;/table&gt;
&lt;br /&gt;&lt;/div&gt;
&lt;pre class="java" name="code"&gt;int x=10;
int y=++x;
System.out.println(y)

&lt;/pre&gt;
This code works fine but...&lt;br /&gt;
&lt;pre class="java" name="code"&gt;int x=10;
int y=++10;
System.out.println(y)

&lt;/pre&gt;
this code will throw an compile time error.&lt;/div&gt;
Error: Unexpected type &lt;br /&gt;
found: value&lt;br /&gt;
required:variable&lt;br /&gt;
&lt;a href="http://4.bp.blogspot.com/-ZB2zgOj5pDU/UX7R3znV_ZI/AAAAAAAARSQ/qtDoKCXbdg4/s1600/Askqtp+constant-1.JPG" imageanchor="1"&gt;&lt;img border="0" height="140" src="http://4.bp.blogspot.com/-ZB2zgOj5pDU/UX7R3znV_ZI/AAAAAAAARSQ/qtDoKCXbdg4/s640/Askqtp+constant-1.JPG" width="640" /&gt;&lt;/a&gt;&lt;/div&gt;
&lt;br /&gt;&lt;/div&gt;
&lt;table bgcolor="#e4eded" border="0" bordercolor="#000000" style="width: 650px;"&gt;&lt;tbody&gt;
&lt;tr&gt; &lt;td&gt;&lt;b&gt;&lt;span style="color: #004080;"&gt;Nesting of increment and decrement operator is not allowed in java&lt;/span&gt;&lt;/b&gt;&lt;/td&gt;&lt;/tr&gt;
&lt;/tbody&gt;&lt;/table&gt;
&lt;/div&gt;
Let me give some piece of code..&lt;br /&gt;
&lt;br /&gt;
&lt;pre class="java" name="code"&gt;int x=10;
int y=++(++x);
System.out.println(y);
&lt;/pre&gt;
This is also not accepted why?&lt;br /&gt;
&lt;br /&gt;
well (++x)will execute perfectly and after that the equation becomes..&lt;br /&gt;
y=++11&lt;br /&gt;
violating the first rule...hence it will throw the same error.&lt;br /&gt;
&lt;a href="http://2.bp.blogspot.com/-51AF7ikx8ag/UX7UQtwT6VI/AAAAAAAARSo/R5Ha2fLkRrM/s1600/Askqtp+constant-2.JPG" imageanchor="1"&gt;&lt;img border="0" height="132" src="http://2.bp.blogspot.com/-51AF7ikx8ag/UX7UQtwT6VI/AAAAAAAARSo/R5Ha2fLkRrM/s640/Askqtp+constant-2.JPG" width="640" /&gt;&lt;/a&gt; &lt;/div&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;table bgcolor="#e4eded" border="0" bordercolor="#000000" style="width: 650px;"&gt;&lt;tbody&gt;
&lt;tr&gt; &lt;td&gt;&lt;b&gt;&lt;span style="color: #004080;"&gt;Increment and decrement operator is not allowed for final variable in java&lt;/span&gt;&lt;/b&gt;&lt;/td&gt;&lt;/tr&gt;
&lt;/tbody&gt;&lt;/table&gt;
Check out &lt;a href="http://www.askqtp.com/2012/06/final-modifier-in-java.html"&gt;here &lt;/a&gt;for importance of final variable .&lt;br /&gt;
for normal variable- this is valid&lt;br /&gt;
&lt;pre class="java" name="code"&gt;int x=6;
x++;
++x;
&lt;/pre&gt;
but if that is final variable...these expressions are invalid.&lt;br /&gt;
&lt;pre class="java" name="code"&gt;final int x=6;
x++;
++x;
&lt;/pre&gt;
It will throw an compile time error..&lt;br /&gt;
&lt;a href="http://2.bp.blogspot.com/-1AAw5QmtyCI/UYABgf3mo1I/AAAAAAAARS4/Vg3qAxL_xuA/s1600/Askqtp-error.JPG" imageanchor="1"&gt;&lt;img border="0" height="88" src="http://2.bp.blogspot.com/-1AAw5QmtyCI/UYABgf3mo1I/AAAAAAAARS4/Vg3qAxL_xuA/s640/Askqtp-error.JPG" width="640" /&gt;&lt;/a&gt;&lt;/div&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;table bgcolor="#e4eded" border="0" bordercolor="#000000" style="width: 650px;"&gt;&lt;tbody&gt;
&lt;tr&gt; &lt;td&gt;&lt;b&gt;&lt;span style="color: #004080;"&gt;Increment and decrement operator can be applied to all primitive data types except Boolean in java&lt;/span&gt;&lt;/b&gt;&lt;/td&gt;&lt;/tr&gt;
&lt;/tbody&gt;&lt;/table&gt;
&lt;/div&gt;
&lt;b&gt;&lt;i&gt;for int::&lt;/i&gt;&lt;/b&gt;&lt;br /&gt;
&lt;pre class="java" name="code"&gt;int x=6;
++x;
System.out.println(x);
&lt;/pre&gt;
output is 7&lt;br /&gt;
&lt;br /&gt;
&lt;b&gt;&lt;i&gt;for char::&lt;/i&gt;&lt;/b&gt;&lt;br /&gt;
&lt;pre class="java" name="code"&gt;char ch ='c';
ch++;
System.out.println(ch);
&lt;/pre&gt;
output is 'd'&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;b&gt;&lt;i&gt;for double::&lt;/i&gt;&lt;/b&gt;&lt;br /&gt;
&lt;pre class="java" name="code"&gt;double d=12.5;
d++;
System.out.println(d);
&lt;/pre&gt;
output is 13.5&lt;br /&gt;
&lt;br /&gt;
&lt;b&gt;&lt;i&gt;for Boolean::&lt;/i&gt;&lt;/b&gt;&lt;br /&gt;
&lt;pre class="java" name="code"&gt;Boolean b=true;
b++;
System.out.println(b);
&lt;/pre&gt;
output: &lt;br /&gt;
Compile time error&lt;br /&gt;
byteTest.java:6: incompatible types&lt;br /&gt;
found   : boolean&lt;br /&gt;
required: java.lang.Boolean&lt;br /&gt;
&lt;br /&gt;
operator ++ cannot be applied to java.lang.Boolean&lt;br /&gt;
&lt;br /&gt;
&lt;a href="http://1.bp.blogspot.com/-OPAqJlbe0JA/UYAFpzp1NYI/AAAAAAAARTI/0cylkUPrVxM/s1600/Askqtp-error2.JPG" imageanchor="1"&gt;&lt;img border="0" height="140" src="http://1.bp.blogspot.com/-OPAqJlbe0JA/UYAFpzp1NYI/AAAAAAAARTI/0cylkUPrVxM/s640/Askqtp-error2.JPG" width="640" /&gt;&lt;/a&gt;&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
That's all for today!!&lt;/div&gt;&lt;img src="http://feeds.feedburner.com/~r/blogspot/TerSJ/~4/tqe1Fu-0cbg" height="1" width="1"/&gt;</description><link>http://feedproxy.google.com/~r/blogspot/TerSJ/~3/tqe1Fu-0cbg/4-rules-to-remember-while-working-with.html</link><author>ani01104@gmail.com (Madhumita)</author><media:thumbnail url="http://3.bp.blogspot.com/-uW3RfTCBTT0/UX7Nbdw96EI/AAAAAAAARSA/F8_IqjxAerI/s72-c/java.jpg" height="72" width="72" /><thr:total>0</thr:total><feedburner:origLink>http://www.askqtp.com/2013/04/4-rules-to-remember-while-working-with.html</feedburner:origLink></item><language>en-us</language><copyright>@Animesh-Ask QTP</copyright><media:credit role="author">Madhumita</media:credit><media:rating>nonadult</media:rating><media:description type="plain">Ask QTP</media:description></channel></rss>
