<?xml version='1.0' encoding='UTF-8'?><?xml-stylesheet href="http://www.blogger.com/styles/atom.css" type="text/css"?><feed xmlns='http://www.w3.org/2005/Atom' xmlns:openSearch='http://a9.com/-/spec/opensearchrss/1.0/' xmlns:blogger='http://schemas.google.com/blogger/2008' xmlns:georss='http://www.georss.org/georss' xmlns:gd="http://schemas.google.com/g/2005" xmlns:thr='http://purl.org/syndication/thread/1.0'><id>tag:blogger.com,1999:blog-3886129644493468120</id><updated>2024-11-08T21:07:14.503+05:30</updated><category term="java"/><category term="Basics"/><category term="Linux"/><category term="Groovy"/><category term="Installation"/><category term="Python Basics"/><category term="Weblogic Server"/><category term="composition"/><category term="Arithmetic"/><category term="CLASSPATH"/><category term="Code"/><category term="Comparable"/><category term="Comparator"/><category term="Complex Numbers"/><category term="Constant Design Pattern"/><category term="Custom Class"/><category term="Custom Sorting"/><category term="Enum"/><category term="Enum Types"/><category term="Enumerated Types"/><category term="Example"/><category term="External Sorting"/><category term="Functional Programming"/><category term="GROOVY_HOME"/><category term="Hello Python"/><category term="Howto"/><category term="Inheritance"/><category term="Internal Sorting"/><category term="JAVA_HOME"/><category term="JDK 1.5"/><category term="JSF2.0"/><category term="Java 5.0"/><category term="Java 8"/><category term="Lambda Expressions"/><category term="Lambdas"/><category term="New Features"/><category term="PATH"/><category term="Python"/><category term="Python IDE"/><category term="Python3.2"/><category term="Servlet"/><category term="Settings"/><category term="Setup"/><category term="Sorting"/><category term="Tiger Release"/><category term="Ubuntu"/><category term="WIndows"/><category term="WLS"/><category term="abs(x)"/><category term="aggregation"/><category term="application"/><category term="classpath issues"/><category term="design patterns"/><category term="feature"/><category term="fix"/><category term="getRealPath"/><category term="groovyConsole"/><category term="groovysh"/><category term="oops"/><category term="usage"/><title type='text'>Pythonic Way</title><subtitle type='html'>Python is a interpreted, high-level language that allows us to write code, i.e, short, precise and understandable.</subtitle><link rel='http://schemas.google.com/g/2005#feed' type='application/atom+xml' href='http://pythonicway.blogspot.com/feeds/posts/default'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/3886129644493468120/posts/default?redirect=false'/><link rel='alternate' type='text/html' href='http://pythonicway.blogspot.com/'/><link rel='hub' href='http://pubsubhubbub.appspot.com/'/><author><name>Karan Khosla</name><uri>http://www.blogger.com/profile/08752215164714997663</uri><email>noreply@blogger.com</email><gd:image rel='http://schemas.google.com/g/2005#thumbnail' width='33' height='26' src='//blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEjB5sW_u-jFmxQj-6JQ9tkvt8SJpiQkpXqCQf85d9_52l9YbST-SqdpOUMabQDbJ3He2fGAqiERLmX3Xt8kkzKgFdAN4NxTe3LDDIGdvjn07Va2mj5we4kgsSkfEO_JhQ/s220/optimus-prime.jpg'/></author><generator version='7.00' uri='http://www.blogger.com'>Blogger</generator><openSearch:totalResults>14</openSearch:totalResults><openSearch:startIndex>1</openSearch:startIndex><openSearch:itemsPerPage>25</openSearch:itemsPerPage><entry><id>tag:blogger.com,1999:blog-3886129644493468120.post-1004362753271667636</id><published>2014-05-02T12:53:00.000+05:30</published><updated>2014-05-02T12:54:44.594+05:30</updated><category scheme="http://www.blogger.com/atom/ns#" term="Functional Programming"/><category scheme="http://www.blogger.com/atom/ns#" term="java"/><category scheme="http://www.blogger.com/atom/ns#" term="Java 8"/><category scheme="http://www.blogger.com/atom/ns#" term="Lambda Expressions"/><category scheme="http://www.blogger.com/atom/ns#" term="Lambdas"/><category scheme="http://www.blogger.com/atom/ns#" term="New Features"/><title type='text'>Java 8 New Features: Lambda Expressions Part 1</title><content type='html'>&lt;div dir=&quot;ltr&quot; style=&quot;text-align: left;&quot; trbidi=&quot;on&quot;&gt;
&lt;div dir=&quot;ltr&quot; style=&quot;text-align: left;&quot; trbidi=&quot;on&quot;&gt;
&lt;div style=&quot;text-align: left;&quot;&gt;
&lt;span style=&quot;font-family: inherit; font-size: large;&quot;&gt;Java is an object-oriented programming language which we all know very well but with Java 8 (released on 18th March, 2014) it goes functional. What does that means? Functional Programming was there way before Java came out but still Java adopted the object-oriented paradigm. Why? Well one simple answer to this is, its popular back then, Why Java wants to adopt Functional Programming now? Well again, simple answer to this question is Modern Hardware now runs more than one CPU Core and as a Programmer we should put them to good use rather then using a single core. Concurrent Programming provides us coarse-grained parallelization that helps Programmers to write code that can put all Cores to good use.&lt;/span&gt;&lt;/div&gt;
&lt;div style=&quot;text-align: left;&quot;&gt;
&lt;span style=&quot;font-family: inherit; font-size: large;&quot;&gt;&lt;br /&gt;Still accessing a large collection of data is a sequential process well we can make parallel using concurrent programming but thats not an easy task to do at all and even we can&#39;t&amp;nbsp;guarantee&amp;nbsp;the performance gains, if any or our data is not in a&amp;nbsp;fragile state or how to design such things that we can reuse it in other projects as well.&lt;/span&gt;&lt;/div&gt;
&lt;div style=&quot;text-align: left;&quot;&gt;
&lt;span style=&quot;font-family: inherit; font-size: large;&quot;&gt;&lt;br /&gt;If every major Java release since Java 5 adds something to the Java&amp;nbsp;Concurrency&amp;nbsp;API, same&amp;nbsp;way after Java 5, Collections API now makes it easy for accessing the collection of data either sequential or parallel.&lt;/span&gt;&lt;/div&gt;
&lt;div style=&quot;text-align: left;&quot;&gt;
&lt;span style=&quot;font-family: inherit; font-size: large;&quot;&gt;&lt;br /&gt;Secondly, While doing Event-Driven Programming many of our object&amp;nbsp;instantiation&amp;nbsp;are done&amp;nbsp;via ad-hoc&amp;nbsp;Anonymous&amp;nbsp;Inner Classes and if the code is big the&amp;nbsp;amount of class files it generates with &#39;$&#39; sign is quite a mess. In case, a project deadline is near and there is still a lot of code to write, many developer(s) self question including me &quot;Why the hell we have to write so much boilerplate code and we still achieve very less as compared to other programming languages which runs on the Java Virtual Machine (JVM) like Scala, Groovy etc.. and other which don&#39;t run on the JVM but still very less boilerplate code like Python etc..&quot;&lt;/span&gt;&lt;/div&gt;
&lt;div style=&quot;text-align: left;&quot;&gt;
&lt;span style=&quot;font-family: inherit; font-size: large;&quot;&gt;&lt;br /&gt;As discussed, Java is an object-oriented programming language with exception to having primitives at language level we can either pass an Abstract Data Type (ADT) or Primitives as parameters.&lt;br /&gt;Lets start with a question that we should ask&amp;nbsp;our self&amp;nbsp;before we know whats really&amp;nbsp;changed in Java 8.&lt;/span&gt;&lt;/div&gt;
&lt;div style=&quot;text-align: left;&quot;&gt;
&lt;span style=&quot;font-family: inherit; font-size: large;&quot;&gt;&lt;br /&gt;&lt;b&gt;Q&lt;/b&gt; What are interfaces in Java?&lt;/span&gt;&lt;/div&gt;
&lt;div style=&quot;text-align: left;&quot;&gt;
&lt;span style=&quot;font-family: inherit; font-size: large;&quot;&gt;&lt;br /&gt;&lt;b&gt;A&lt;/b&gt; Very simple answer to this basic question can be &amp;nbsp;&quot;An interface is 100% Abstract Classes that can only declare abstract methods or may have constant(s).&quot;&lt;/span&gt;&lt;/div&gt;
&lt;div style=&quot;text-align: left;&quot;&gt;
&lt;span style=&quot;font-family: inherit; font-size: large;&quot;&gt;&lt;br /&gt;If you have plans to move to Java 8 or preparing for an interview etc.., then think once Again?&lt;/span&gt;&lt;/div&gt;
&lt;div style=&quot;text-align: left;&quot;&gt;
&lt;span style=&quot;font-family: inherit; font-size: large;&quot;&gt;&lt;br /&gt;Interfaces are there since the beginning and even a person who is introduced to Java Programming&amp;nbsp;Language&amp;nbsp;was told the same thing. With Java 8, which is the biggest&amp;nbsp;release after Java 5 has changed things (I won&#39;t say a little, you will see it in a bit) so its better to be aware of, what interface were before Java 8 and what they have become Java 8&amp;nbsp;onward.&lt;/span&gt;&lt;/div&gt;
&lt;div style=&quot;text-align: left;&quot;&gt;
&lt;span style=&quot;font-family: inherit; font-size: large;&quot;&gt;&lt;br /&gt;So whats really changed in Java 8 with respect to interface?&lt;/span&gt;&lt;/div&gt;
&lt;div style=&quot;text-align: left;&quot;&gt;
&lt;span style=&quot;font-family: inherit; font-size: large;&quot;&gt;&lt;br /&gt;A new keyword added to the language &#39;default&#39;,&lt;br /&gt;Interface can have default, static and abstract methods,&lt;br /&gt;abstract methods cannot have body but default, static methods have body,&lt;br /&gt;If an interface contains only one abstract method, other than overriding method(s) of Object class as abstract are considered functional interface,&lt;br /&gt;There is a new annotation added in the language, @FunctionalInterface, it&#39;s optional, i.e., you can either mark an interface with this annotation or you can leave it, as far as it comply to the definition of @FunctionalInterface, Java treats it as functional interface, whereas, if you mark an interface with the annotation and later on add another abstract method, you will get compilation error.&lt;/span&gt;&lt;/div&gt;
&lt;div style=&quot;text-align: left;&quot;&gt;
&lt;span style=&quot;font-family: inherit; font-size: large;&quot;&gt;&lt;br /&gt;&lt;/span&gt;&lt;/div&gt;
&lt;div style=&quot;text-align: left;&quot;&gt;
&lt;span style=&quot;font-family: inherit; font-size: large;&quot;&gt;Things covered so far...&lt;/span&gt;&lt;/div&gt;
&lt;div style=&quot;text-align: left;&quot;&gt;
&lt;span style=&quot;font-family: inherit; font-size: large;&quot;&gt;&lt;br /&gt;&lt;u&gt;&lt;b&gt;Till Java 7,&lt;/b&gt;&lt;/u&gt;&lt;/span&gt;&lt;/div&gt;
&lt;div style=&quot;text-align: left;&quot;&gt;
&lt;span style=&quot;font-family: inherit; font-size: large;&quot;&gt;&lt;br /&gt;lots of&amp;nbsp;boilerplate&amp;nbsp;code,&lt;br /&gt;sequential access to data inside a collection,&lt;br /&gt;Not much of parallel computing (except&amp;nbsp;concurrency&amp;nbsp;API, provides coarse-grained&amp;nbsp;parallelization),&lt;br /&gt;Event-driven Programming is a mess,&lt;br /&gt;Strong typing,&lt;br /&gt;Either we can pass a primitive or ADT as a parameter&lt;/span&gt;&lt;/div&gt;
&lt;div style=&quot;text-align: left;&quot;&gt;
&lt;span style=&quot;font-family: inherit; font-size: large;&quot;&gt;&lt;br /&gt;&lt;b&gt;&lt;u&gt;Java 8&amp;nbsp;onward,&lt;/u&gt;&lt;/b&gt;&lt;/span&gt;&lt;/div&gt;
&lt;div style=&quot;text-align: left;&quot;&gt;
&lt;span style=&quot;font-family: inherit; font-size: large;&quot;&gt;&lt;br /&gt;concise syntax,&lt;br /&gt;sequential/parallel access to data inside a collection - out-of-the-box,&lt;br /&gt;fine-grained&amp;nbsp;parallelization,&lt;br /&gt;No more&amp;nbsp;Anonymous&amp;nbsp;classes while doing Event-driven programming&lt;br /&gt;type inference,&lt;br /&gt;Now apart from passing primitives or ADT as a parameter, we can do pass lambdas or &quot;code-as-data&quot; as parameters.&lt;/span&gt;&lt;/div&gt;
&lt;div style=&quot;text-align: left;&quot;&gt;
&lt;span style=&quot;font-family: inherit; font-size: large;&quot;&gt;&lt;br /&gt;&lt;b&gt;&lt;u&gt;Lambda Expressions&lt;/u&gt;&lt;/b&gt;&lt;/span&gt;&lt;/div&gt;
&lt;div style=&quot;text-align: left;&quot;&gt;
&lt;span style=&quot;font-family: inherit; font-size: large;&quot;&gt;&lt;br /&gt;&lt;/span&gt;&lt;/div&gt;
&lt;div style=&quot;text-align: left;&quot;&gt;
&lt;span style=&quot;font-family: inherit; font-size: large;&quot;&gt;Lets now start with an exercise where we can see how things are done till Java 7 and how its improved in terms of syntax, performance etc..&lt;/span&gt;&lt;span style=&quot;font-family: Verdana, sans-serif;&quot;&gt;&lt;br /&gt;&lt;/span&gt;&lt;/div&gt;
&lt;/div&gt;
&lt;br /&gt;
&lt;script src=&quot;https://gist.github.com/karankhosla/cda3398b962f1809f3d0.js&quot;&gt;&lt;/script&gt;
&lt;/div&gt;
&lt;div class=&quot;blogger-post-footer&quot;&gt;PythonicWay&lt;/div&gt;</content><link rel='replies' type='application/atom+xml' href='http://pythonicway.blogspot.com/feeds/1004362753271667636/comments/default' title='Post Comments'/><link rel='replies' type='text/html' href='http://pythonicway.blogspot.com/2014/05/java-8-new-features-lambda-expressions.html#comment-form' title='0 Comments'/><link rel='edit' type='application/atom+xml' href='http://www.blogger.com/feeds/3886129644493468120/posts/default/1004362753271667636'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/3886129644493468120/posts/default/1004362753271667636'/><link rel='alternate' type='text/html' href='http://pythonicway.blogspot.com/2014/05/java-8-new-features-lambda-expressions.html' title='Java 8 New Features: Lambda Expressions Part 1'/><author><name>Karan Khosla</name><uri>http://www.blogger.com/profile/08752215164714997663</uri><email>noreply@blogger.com</email><gd:image rel='http://schemas.google.com/g/2005#thumbnail' width='33' height='26' src='//blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEjB5sW_u-jFmxQj-6JQ9tkvt8SJpiQkpXqCQf85d9_52l9YbST-SqdpOUMabQDbJ3He2fGAqiERLmX3Xt8kkzKgFdAN4NxTe3LDDIGdvjn07Va2mj5we4kgsSkfEO_JhQ/s220/optimus-prime.jpg'/></author><thr:total>0</thr:total><georss:featurename>India</georss:featurename><georss:point>28.627925287618567 77.442626953125</georss:point><georss:box>28.182002787618565 76.797179953125 29.073847787618568 78.088073953125</georss:box></entry><entry><id>tag:blogger.com,1999:blog-3886129644493468120.post-8292826017476013237</id><published>2013-06-02T11:08:00.001+05:30</published><updated>2013-06-02T11:08:22.024+05:30</updated><category scheme="http://www.blogger.com/atom/ns#" term="Constant Design Pattern"/><category scheme="http://www.blogger.com/atom/ns#" term="Enum"/><category scheme="http://www.blogger.com/atom/ns#" term="Enum Types"/><category scheme="http://www.blogger.com/atom/ns#" term="Enumerated Types"/><category scheme="http://www.blogger.com/atom/ns#" term="feature"/><category scheme="http://www.blogger.com/atom/ns#" term="Java 5.0"/><category scheme="http://www.blogger.com/atom/ns#" term="JDK 1.5"/><category scheme="http://www.blogger.com/atom/ns#" term="Tiger Release"/><title type='text'>Java Basics: Enum Types</title><content type='html'>&lt;div dir=&quot;ltr&quot; style=&quot;text-align: left;&quot; trbidi=&quot;on&quot;&gt;
&lt;div class=&quot;MsoNormal&quot;&gt;
JDK 1.5 a.k.a Tiger release marked
the addition of two new reference types into the language. A special Kind Class
called Enum Types and a new kind of interface called an annotation Types.&lt;/div&gt;
&lt;div class=&quot;MsoNormal&quot;&gt;
In this blog post we will discuss about
the Enum Types and how it is better than the existing approach int and String Enum
pattern that many of us used or may still be using in (pity on programmers as
they are missing out better approach to handle things and making the project
fragile in long run) there projects.&lt;/div&gt;
&lt;div class=&quot;MsoNormal&quot;&gt;
&lt;br /&gt;&lt;/div&gt;
&lt;div class=&quot;MsoNormal&quot;&gt;
Note: Enum has been made a
reserved keyword in 1.5 migrating your existing project on JDK 1.5 might break
your existing code if anywhere you have used enum as a variable name.&lt;/div&gt;
&lt;div class=&quot;MsoNormal&quot;&gt;
&lt;br /&gt;&lt;/div&gt;
&lt;div class=&quot;MsoNormal&quot;&gt;
An Enum allows a programmer to define
fixed set of named constants such as the planets in the Solar System, Suits in
the deck of playing cards or Days in a Week. &lt;/div&gt;
&lt;div class=&quot;MsoNormal&quot;&gt;
&lt;br /&gt;&lt;/div&gt;
&lt;div class=&quot;MsoNormal&quot;&gt;
Points to Remember:&lt;/div&gt;
&lt;div class=&quot;MsoNormal&quot;&gt;
&lt;br /&gt;&lt;/div&gt;
&lt;div class=&quot;MsoNormal&quot;&gt;
1. Enum Types over a period of time
can evolve into a full-fledged abstraction.&lt;/div&gt;
&lt;div class=&quot;MsoNormal&quot;&gt;
2. Enum Types are by nature
immutable, so all fields should be marked final they can be public but it’s
better to make them private and provide them public accessors.&amp;nbsp; &lt;/div&gt;
&lt;div class=&quot;MsoNormal&quot;&gt;
3. Before Enum Types a common int and
String Enum pattern was used by the programmer which has many shortcomings. &lt;/div&gt;
&lt;div class=&quot;MsoNormal&quot;&gt;
&lt;br /&gt;&lt;/div&gt;
&lt;div class=&quot;MsoNormal&quot;&gt;
Before JDK 1.5 – Existing int Enum
Pattern&lt;/div&gt;
&lt;div class=&quot;MsoNormal&quot;&gt;
&lt;br /&gt;&lt;/div&gt;
&lt;div class=&quot;MsoNormal&quot; style=&quot;margin-bottom: .0001pt; margin-bottom: 0in; tab-stops: 358.0pt;&quot;&gt;
public static final int Day_SUNDAY &amp;nbsp;= 0;&lt;/div&gt;
&lt;div class=&quot;MsoNormal&quot; style=&quot;margin-bottom: .0001pt; margin-bottom: 0in; tab-stops: 358.0pt;&quot;&gt;
public static final int Day_MONDAY = 1;&lt;/div&gt;
&lt;div class=&quot;MsoNormal&quot; style=&quot;margin-bottom: .0001pt; margin-bottom: 0in; tab-stops: 358.0pt;&quot;&gt;
public static final int Day_TUESDAY = 2;&lt;/div&gt;
&lt;div class=&quot;MsoNormal&quot; style=&quot;margin-bottom: .0001pt; margin-bottom: 0in; tab-stops: 358.0pt;&quot;&gt;
…..&lt;/div&gt;
&lt;div class=&quot;MsoNormal&quot; style=&quot;margin-bottom: .0001pt; margin-bottom: 0in; tab-stops: 358.0pt;&quot;&gt;
&lt;br /&gt;&lt;/div&gt;
&lt;div class=&quot;MsoNormal&quot;&gt;
&amp;nbsp;Shortcomings in above approach:&lt;/div&gt;
&lt;div class=&quot;MsoNormal&quot;&gt;
&lt;br /&gt;&lt;/div&gt;
&lt;div class=&quot;MsoListParagraphCxSpFirst&quot; style=&quot;mso-list: l0 level1 lfo1; tab-stops: 358.0pt; text-indent: -.25in;&quot;&gt;
&lt;span style=&quot;text-indent: -0.25in;&quot;&gt;&amp;nbsp; &amp;nbsp; &amp;nbsp;No
Type Safety: Your compiler without warning you will compile even if you pass
any int value instead of the predefined set of values.&lt;/span&gt;&lt;/div&gt;
&lt;div class=&quot;MsoListParagraphCxSpFirst&quot; style=&quot;mso-list: l0 level1 lfo1; tab-stops: 358.0pt; text-indent: -.25in;&quot;&gt;
&lt;span style=&quot;text-indent: -0.25in;&quot;&gt;&lt;br /&gt;&lt;/span&gt;&lt;/div&gt;
&lt;div class=&quot;MsoListParagraphCxSpMiddle&quot; style=&quot;mso-list: l0 level1 lfo1; tab-stops: 358.0pt; text-indent: -.25in;&quot;&gt;
&amp;nbsp; &amp;nbsp; &lt;span style=&quot;font-size: 7pt;&quot;&gt;&amp;nbsp; &amp;nbsp;&lt;/span&gt;No
Namespace: You must prefix constants (in this case Day_) to avoid any
confusion/collisions in case you introduce a new pattern in your project in
future.&lt;/div&gt;
&lt;div class=&quot;MsoListParagraphCxSpMiddle&quot; style=&quot;mso-list: l0 level1 lfo1; tab-stops: 358.0pt; text-indent: -.25in;&quot;&gt;
&lt;br /&gt;&lt;/div&gt;
&lt;div class=&quot;MsoListParagraphCxSpMiddle&quot; style=&quot;mso-list: l0 level1 lfo1; tab-stops: 358.0pt; text-indent: -.25in;&quot;&gt;
&amp;nbsp; &amp;nbsp; &amp;nbsp;&lt;span style=&quot;font-size: 7pt;&quot;&gt;&amp;nbsp;&lt;/span&gt;&lt;!--[endif]--&gt;Fragile:
As int Enum pattern are compile-time constants, they are compiled in the files
those uses them. It requires recompilation of all those files that uses them if
any changes made to them else it will result in unexpected behavior.&lt;/div&gt;
&lt;div class=&quot;MsoListParagraphCxSpMiddle&quot; style=&quot;mso-list: l0 level1 lfo1; tab-stops: 358.0pt; text-indent: -.25in;&quot;&gt;
&lt;br /&gt;&lt;/div&gt;
&lt;div class=&quot;MsoListParagraphCxSpLast&quot; style=&quot;mso-list: l0 level1 lfo1; tab-stops: 358.0pt; text-indent: -.25in;&quot;&gt;
&amp;nbsp; &amp;nbsp; &amp;nbsp; Uninformative:
These patterns won’t allow you to carry any addition details printing them will
not tell you more than what value each of them are assigned even the type is
not known whether it’s a int or a String. Even the iteration over all the
declared values is not possible and there is no way to find out the exact no.
of declared constants.&lt;/div&gt;
&lt;div class=&quot;MsoListParagraphCxSpLast&quot; style=&quot;mso-list: l0 level1 lfo1; tab-stops: 358.0pt; text-indent: -.25in;&quot;&gt;
&lt;br /&gt;&lt;/div&gt;
&lt;div class=&quot;MsoNormal&quot;&gt;
Enum Types not only overcomes the
above mentioned shortcomings in the existing approach but adds much more
functionality that one can expect from it. Many programmers are aware of Enum
Types even before they were introduced in JDK 1.5 due to its presence in
languages like C/C++. They look similar to their counterparts in other
languages (i.e., in C/C++ or C#) where they are just fancy int values whereas Java
Enum Types are Real Java Classes and are much more powerful thanks to the
Compiler which makes it possible under the hoods with no burden on programmers.&lt;/div&gt;
&lt;div class=&quot;MsoNormal&quot;&gt;
&lt;br /&gt;&lt;/div&gt;
&lt;div class=&quot;MsoNormal&quot;&gt;
Enum in its Simplest Form:&lt;/div&gt;
&lt;div class=&quot;MsoNormal&quot;&gt;
&lt;br /&gt;&lt;/div&gt;
&lt;div class=&quot;MsoNormal&quot;&gt;
enum Day {SUNDAY, MONDAY, TUESDAY,
WEDNESDAY, THURSDAY, FRIDAY, SATURDAY}&lt;/div&gt;
&lt;div class=&quot;MsoNormal&quot;&gt;
&lt;br /&gt;&lt;/div&gt;
&lt;div class=&quot;MsoNormal&quot;&gt;
Enum Types are final by virtue,
having no accessible Constructor and hence are purely instance-controlled. Enum
Types cannot be extended, and an Enum Type cannot extend other class or enum as
all Enum Types are subclasses of java.lang.Enum maintaining the single level
inheritance but all Enum Types can implement interfaces.&lt;/div&gt;
&lt;div class=&quot;MsoNormal&quot;&gt;
&lt;br /&gt;&lt;/div&gt;
&lt;div class=&quot;MsoNormal&quot;&gt;
Enum Types can either defined as
Top-Level full-fledged class or it can be nested static member in another
reference types.&lt;/div&gt;
&lt;div class=&quot;MsoNormal&quot;&gt;
&lt;br /&gt;&lt;/div&gt;
&lt;div class=&quot;MsoNormal&quot;&gt;
Enum Provides Type Safety: You can
assign an Enum one of the defined constant otherwise Complier Error is thrown.&lt;/div&gt;
&lt;div class=&quot;MsoNormal&quot;&gt;
&lt;br /&gt;&lt;/div&gt;
&lt;div class=&quot;MsoNormal&quot;&gt;
Comparison: Comparing Enum Types
using == or equals() will be same.&lt;/div&gt;
&lt;div class=&quot;MsoNormal&quot;&gt;
&lt;br /&gt;&lt;/div&gt;
&lt;div class=&quot;MsoNormal&quot;&gt;
Informative: Each Enum Constant
can override if required the toString() to provide any information they want.&lt;/div&gt;
&lt;div class=&quot;MsoNormal&quot;&gt;
&lt;br /&gt;&lt;/div&gt;
&lt;div class=&quot;MsoNormal&quot;&gt;
Namespaces: Constants with same
name can exist as all constants can be accessed using the Enum name which
cannot be same.&lt;/div&gt;
&lt;div class=&quot;MsoNormal&quot;&gt;
&lt;br /&gt;&lt;/div&gt;
&lt;div class=&quot;MsoNormal&quot;&gt;
No Need to Recompile: As Enum
Types are not compiled into the classes which use them, so we can add/remove or
reorder any enum constant without compiling all the files that uses it.&lt;/div&gt;
&lt;div class=&quot;MsoNormal&quot;&gt;
&lt;br /&gt;&lt;/div&gt;
&lt;div class=&quot;MsoNormal&quot;&gt;
You can define fields or methods
in an Enum Types as you do in a Regular Java Class.&lt;/div&gt;
&lt;div class=&quot;MsoNormal&quot;&gt;
With Enum Types the order in which
you define the fixed set of named constants matter a lot.&lt;/div&gt;
&lt;div class=&quot;MsoNormal&quot;&gt;
Java.lang.Enum overrides methods
from Object class and made a few of them final and it also implements
interfaces like Comparable and Serializable that handles Comparison and
Serialization for you automatically.&lt;/div&gt;
&lt;div class=&quot;MsoNormal&quot;&gt;
&lt;br /&gt;&lt;/div&gt;
&lt;div class=&quot;MsoNormal&quot;&gt;
Enum can be a Top-Level Class or if
it’s defined inside a Top-Level Class then it acts as a static member class of
that Top-Level Class.&lt;/div&gt;
&lt;div class=&quot;MsoNormal&quot;&gt;
&lt;br /&gt;&lt;/div&gt;
&lt;div class=&quot;MsoNormal&quot;&gt;
Inside an Enum Type you can
declare an abstract method in that case we have to @Override the abstract
method with a concrete one for each named constant using Constant-Specific
Class Body. Such methods are known as Constant-Specific Method Implementations.
&lt;/div&gt;
&lt;div class=&quot;MsoNormal&quot;&gt;
&lt;br /&gt;&lt;/div&gt;
&lt;div class=&quot;MsoNormal&quot;&gt;
The toString() method in its
default form will return the Constant Name which is same as calling the name()
method but as toString() method is not final it can be Overridden either for
whole Enum in which case every Constant will share the same value or it can be
Overridden for a few if not all as well that way an Enum Types achieves
Polymorphism like any Regular Java Class.&lt;/div&gt;
&lt;div class=&quot;MsoNormal&quot;&gt;
&lt;br /&gt;&lt;/div&gt;
&lt;div class=&quot;MsoNormal&quot;&gt;
Iteration and Size of Enum can be
known using the values() method. The values() method return an Array which you
can use to iterate and using the length variable its size can be easily known.&lt;/div&gt;
&lt;div class=&quot;MsoNormal&quot;&gt;
&lt;br /&gt;&lt;/div&gt;
&lt;div class=&quot;MsoNormal&quot;&gt;
As mentioned before Order in which the
Constants are defined is very important as whenever the constants are iterated
it can be iterated in the order it’s defined in the Enum.&lt;/div&gt;
&lt;div class=&quot;MsoNormal&quot;&gt;
ordinal() method returns an
integer indicating the index at which the constant is placed.&lt;/div&gt;
&lt;div class=&quot;MsoNormal&quot;&gt;
&lt;br /&gt;&lt;/div&gt;
&lt;div class=&quot;MsoNormal&quot;&gt;
&lt;br /&gt;&lt;/div&gt;
&lt;br /&gt;
&lt;div class=&quot;MsoNormal&quot;&gt;
&lt;o:p&gt;I will update this post with more information and examples. EnumSet and EnumMap later.&amp;nbsp;&lt;/o:p&gt;&lt;/div&gt;
&lt;div class=&quot;MsoNormal&quot;&gt;
&lt;o:p&gt;&lt;br /&gt;&lt;/o:p&gt;&lt;/div&gt;
&lt;div class=&quot;MsoNormal&quot;&gt;
&lt;o:p&gt;Hope this Helps!&lt;/o:p&gt;&lt;/div&gt;
&lt;div class=&quot;MsoNormal&quot;&gt;
&lt;o:p&gt;Please leave your comments.&lt;/o:p&gt;&lt;/div&gt;
&lt;/div&gt;
&lt;div class=&quot;blogger-post-footer&quot;&gt;PythonicWay&lt;/div&gt;</content><link rel='replies' type='application/atom+xml' href='http://pythonicway.blogspot.com/feeds/8292826017476013237/comments/default' title='Post Comments'/><link rel='replies' type='text/html' href='http://pythonicway.blogspot.com/2013/06/java-basics-enum-types.html#comment-form' title='0 Comments'/><link rel='edit' type='application/atom+xml' href='http://www.blogger.com/feeds/3886129644493468120/posts/default/8292826017476013237'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/3886129644493468120/posts/default/8292826017476013237'/><link rel='alternate' type='text/html' href='http://pythonicway.blogspot.com/2013/06/java-basics-enum-types.html' title='Java Basics: Enum Types'/><author><name>Karan Khosla</name><uri>http://www.blogger.com/profile/08752215164714997663</uri><email>noreply@blogger.com</email><gd:image rel='http://schemas.google.com/g/2005#thumbnail' width='33' height='26' src='//blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEjB5sW_u-jFmxQj-6JQ9tkvt8SJpiQkpXqCQf85d9_52l9YbST-SqdpOUMabQDbJ3He2fGAqiERLmX3Xt8kkzKgFdAN4NxTe3LDDIGdvjn07Va2mj5we4kgsSkfEO_JhQ/s220/optimus-prime.jpg'/></author><thr:total>0</thr:total><georss:featurename>United States</georss:featurename><georss:point>37.09024 -95.712891000000013</georss:point><georss:box>-36.612596 98.349608999999987 90 70.224608999999987</georss:box></entry><entry><id>tag:blogger.com,1999:blog-3886129644493468120.post-1031174474923266118</id><published>2013-06-01T22:09:00.000+05:30</published><updated>2013-06-02T10:51:06.198+05:30</updated><category scheme="http://www.blogger.com/atom/ns#" term="Basics"/><category scheme="http://www.blogger.com/atom/ns#" term="Groovy"/><category scheme="http://www.blogger.com/atom/ns#" term="groovyConsole"/><category scheme="http://www.blogger.com/atom/ns#" term="groovysh"/><category scheme="http://www.blogger.com/atom/ns#" term="java"/><title type='text'>Groovy Basics: Hello World Example</title><content type='html'>&lt;div dir=&quot;ltr&quot; style=&quot;text-align: left;&quot; trbidi=&quot;on&quot;&gt;
In Dynamic Language, always remember one Rule of Thumb.&lt;br /&gt;
&lt;br /&gt;
* When you&#39;re unsure what type you want your Object, always use the &#39;dynamically typed&#39; keyword.&lt;br /&gt;
&lt;br /&gt;
In Groovy, def simply means &#39;dynamically typed&#39;.&lt;br /&gt;
&lt;br /&gt;
As the Groovy Site says a dynamic language for the VM you must always remember Groovy Syntax feels Dynamic whereas once it&#39;s compiled it&#39;s the same Class File that Java Compiler (javac) Generates as Groovy runs on the VM and VM doesn&#39;t have a support for dynamic language. You will find Groovy Syntax Much Clear and More Readable as you write less code.&lt;br /&gt;
&lt;br /&gt;
A Groovy File can either Contain Scripts, Class Definition or both. I usually don&#39;t prefer mixing Scripts and Class Definitions in a same file. I will come to this later.&lt;br /&gt;
&lt;br /&gt;
You can check one-liner on the Groovy Shell instead of writing a Script file.&lt;br /&gt;
&lt;br /&gt;
On Console/Prompt Type:&lt;br /&gt;
&lt;br /&gt;
groovysh // It will open a Groovy Shell.&lt;br /&gt;
&lt;br /&gt;
groovy:000&amp;gt; println &quot;Hello, World.&quot;&lt;br /&gt;
Hello, World.&lt;br /&gt;
===&amp;gt; null&lt;br /&gt;
groovy:000&amp;gt;&lt;br /&gt;
&lt;br /&gt;
OR Simply,&lt;br /&gt;
&lt;br /&gt;
groovy:000&amp;gt; &quot;Hello, World.&quot;&lt;br /&gt;
===&amp;gt; Hello, World.&lt;br /&gt;
groovy:000&amp;gt;&lt;br /&gt;
&lt;br /&gt;
You will see the shell doesn&#39;t exit after the execution instead it&#39;s asking for your input again. This is called REPL - Read Evaluate Print Loop. You can type exit, quit, \q or \x to exit the shell.&lt;br /&gt;
&lt;br /&gt;
You can also use the groovy command instead of going into the shell.&lt;br /&gt;
&lt;br /&gt;
groovy -e &quot;println &#39;Hello, World.&#39;&quot;&lt;br /&gt;
&lt;br /&gt;
Here, -e &amp;lt;script&amp;gt; specify a command line script.&lt;br /&gt;
&lt;br /&gt;
You can write that line in a new file and save it as HelloWorldScript.groovy try to run it,&lt;br /&gt;
&lt;br /&gt;
groovy HelloWorldScript.groovy&lt;br /&gt;
&lt;br /&gt;
OR&lt;br /&gt;
&lt;br /&gt;
groovy HelloWorldScript&lt;br /&gt;
&lt;br /&gt;
A Groovy File can have any of the below mentioned extension. You can run the groovy command without extension in which case groovy will look for all the files in your CLASSPATH with one of the below mentioned extention and .class extention as well once it&#39;s found, it will execute that or will throw an error in case file with the same name doesn&#39;t exist in the CLASSPATH.&lt;br /&gt;
&lt;br /&gt;
.groovy&lt;br /&gt;
.gvy&lt;br /&gt;
.gy&lt;br /&gt;
.gsh&lt;br /&gt;
&lt;br /&gt;
The groovy command runs your code without generating .class files. If you use groovyc compiler to explicitly compile your files first and then run them using the groovy command. You can do it. What if you made changes to your groovy source file and forgot to compile them? What will happen? No Worries! The groovy command is smart enough to load and run the right files for you that means suppose you make any changes to your source file but forgot to generate the .class file using the groovyc command (groovyc). the groovy command will ignore the .class file present in the path and will run the source file instead.&lt;br /&gt;
&lt;br /&gt;
Now, Lets write a first HelloWorld.groovy program using the class definition,&lt;br /&gt;
&lt;br /&gt;
You might notice that there are no import statements, parentheses, package prefix or a semi-colon.&lt;br /&gt;
Point to Remember: Like Java imports java.lang.* package by default Groovy imports the following packages by default. groovy.lang.*, groovy.util.*, java.lang.*, java.util.*, java.net.*, java.io.* and classes java.math.BigInteger and java.math.BigDecimal.&lt;br /&gt;
&lt;br /&gt;
Another Point to remember here that Script files don&#39;t have a main method but they are still executed, As Each Script file turned into a Java class with the same name as filename that extends the groovy.lang.Script which contains the main method so the runtime can execute it.&lt;br /&gt;
&lt;br /&gt;
&lt;script src=&quot;https://gist.github.com/karankhosla/10ec55be92d7e5d451d5.js&quot;&gt;&lt;/script&gt;

As, I discussed earlier not to mix Scripts and Class Definitions in a Single file. Here is why,&lt;br /&gt;
&lt;br /&gt;
&lt;script src=&quot;https://gist.github.com/karankhosla/76b6c5e0df265687faf6.js&quot;&gt;&lt;/script&gt;

Let me explain if the above error is still not clear. What Groovy does here is when it sees a Script inside a source file, it tries to create a class with the same name as source filename which in this case is HelloWorld. Their is a class definition inside the source file which has a same name i.e., HelloWorld for which a class will be created but when it comes to the Script it will fail to create as the class HelloWorld already exist.&lt;br /&gt;
&lt;br /&gt;
How to fix?&lt;br /&gt;
&lt;br /&gt;
You can fix this either by changing the Source Filename or Change the Class Name to make it run. Always try not to mix the Class Definition and Script in a same file.&lt;br /&gt;
&lt;br /&gt;
As, I mentioned above that you need a Java VM to run the Groovy code you can run them directly using the Java Command. All you require is a single Groovy Jar in your classpath.&lt;br /&gt;
&lt;br /&gt;
Compile and Run&lt;br /&gt;
&lt;br /&gt;
First you have to generate a .class file using the Groovy Compiler.&lt;br /&gt;
&lt;br /&gt;
Window Users:&lt;br /&gt;
&lt;br /&gt;
C:\GROOVY-DEMOS&amp;gt;groovyc HelloWorld.groovy&lt;br /&gt;
&lt;br /&gt;
Linux Users:&lt;br /&gt;
&lt;br /&gt;
$ groovyc HelloWorld.groovy&lt;br /&gt;
&lt;br /&gt;
To Run,&lt;br /&gt;
&lt;br /&gt;
Window Users:&lt;br /&gt;
&lt;br /&gt;
C:\GROOVY-DEMOS&amp;gt;java -classpath %CLASSPATH%;%GROOVY_HOME%\embeddable\groovy-all-2.1.3.jar HelloWorld&lt;br /&gt;
&lt;br /&gt;
Linux Users:&lt;br /&gt;
&lt;br /&gt;
$ java -classpath %CLASSPATH%:%GROOVY_HOME%/embeddable/groovy-all-2.1.3.jar HelloWorld&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
Note: Never put the groovy-all-&amp;lt;VERSION&amp;gt;.jar in your classpath, it will effect the groovysh command. If you get an error while running the groovysh command make sure you don&#39;t have groovy-all-&amp;lt;VERSION&amp;gt;.jar in your classpath.&lt;br /&gt;
&lt;br /&gt;
If you are looking for editors/IDE with Groovy Support try Sublime Text 2 or IntelliJ Idea.&lt;br /&gt;
&lt;br /&gt;
Hope this Helps!&lt;br /&gt;
Please leave your comments&lt;/div&gt;
&lt;div class=&quot;blogger-post-footer&quot;&gt;PythonicWay&lt;/div&gt;</content><link rel='replies' type='application/atom+xml' href='http://pythonicway.blogspot.com/feeds/1031174474923266118/comments/default' title='Post Comments'/><link rel='replies' type='text/html' href='http://pythonicway.blogspot.com/2013/06/groovy-basics-hello-world-example.html#comment-form' title='0 Comments'/><link rel='edit' type='application/atom+xml' href='http://www.blogger.com/feeds/3886129644493468120/posts/default/1031174474923266118'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/3886129644493468120/posts/default/1031174474923266118'/><link rel='alternate' type='text/html' href='http://pythonicway.blogspot.com/2013/06/groovy-basics-hello-world-example.html' title='Groovy Basics: Hello World Example'/><author><name>Karan Khosla</name><uri>http://www.blogger.com/profile/08752215164714997663</uri><email>noreply@blogger.com</email><gd:image rel='http://schemas.google.com/g/2005#thumbnail' width='33' height='26' src='//blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEjB5sW_u-jFmxQj-6JQ9tkvt8SJpiQkpXqCQf85d9_52l9YbST-SqdpOUMabQDbJ3He2fGAqiERLmX3Xt8kkzKgFdAN4NxTe3LDDIGdvjn07Va2mj5we4kgsSkfEO_JhQ/s220/optimus-prime.jpg'/></author><thr:total>0</thr:total></entry><entry><id>tag:blogger.com,1999:blog-3886129644493468120.post-471078501157944658</id><published>2013-06-01T20:08:00.000+05:30</published><updated>2013-06-01T22:11:42.604+05:30</updated><category scheme="http://www.blogger.com/atom/ns#" term="CLASSPATH"/><category scheme="http://www.blogger.com/atom/ns#" term="Groovy"/><category scheme="http://www.blogger.com/atom/ns#" term="GROOVY_HOME"/><category scheme="http://www.blogger.com/atom/ns#" term="Installation"/><category scheme="http://www.blogger.com/atom/ns#" term="java"/><category scheme="http://www.blogger.com/atom/ns#" term="JAVA_HOME"/><category scheme="http://www.blogger.com/atom/ns#" term="Linux"/><category scheme="http://www.blogger.com/atom/ns#" term="PATH"/><category scheme="http://www.blogger.com/atom/ns#" term="Settings"/><category scheme="http://www.blogger.com/atom/ns#" term="Setup"/><category scheme="http://www.blogger.com/atom/ns#" term="WIndows"/><title type='text'>Running Java And Groovy on Windows And Linux</title><content type='html'>&lt;div dir=&quot;ltr&quot; style=&quot;text-align: left;&quot; trbidi=&quot;on&quot;&gt;
&lt;span style=&quot;font-size: large;&quot;&gt;G&lt;/span&gt;roovy, Another Language that runs on Java Virtual Machine. It supports both Static and Dynamic Typing. If you haven&#39;t heard about this language till now. No Problems!&lt;br /&gt;
&lt;br /&gt;
As, Groovy runs on VM so you must install Java first. Groovy doesn&#39;t require you to be a Java Programmer but some hands-on will help you learn it fast. Those who already have installed Java must set the JAVA_HOME Environment Variable. Here is how you do.&lt;br /&gt;
&lt;br /&gt;
On Windows Machine:&lt;br /&gt;
&lt;br /&gt;
Right-Click My Computer -&amp;gt; Properties -&amp;gt; In Windows XP (Advanced) | In Windows 7 (Advanced System Settings) -&amp;gt; &amp;nbsp;Environment Variable -&amp;gt; New&lt;br /&gt;
&lt;br /&gt;
Here You will see Two Panes. If you select the New on the First One it will set User-Specific Setting i.e., Only the Currently Logged In User can use Java and Groovy.&lt;br /&gt;
&lt;br /&gt;
If you Choose the New from the System Variables, It will be available to all the existing users as well all users that you create later. Choose what you prefer.&lt;br /&gt;
&lt;br /&gt;
Note: System Variables already Contains PATH Key/value pair. Never remove the existing value instead append to it or you end you with an unstable machine. If you are unsure always create the NEW PATH Key/value in the First Pane that way you are sure that your System Settings remains untouched.&lt;br /&gt;
&lt;br /&gt;
Create a New Variable anywhere you prefer.&lt;br /&gt;
&lt;br /&gt;
Variable Name: &amp;nbsp;JAVA_HOME&lt;br /&gt;
Variable Value: &amp;nbsp;PATH\TO\JAVA\FOLDER\WITHOUT\SEMI-COLON\AT\THE\END&lt;br /&gt;
&lt;br /&gt;
For Example: I have installed Java in C:\jdk1.6&lt;br /&gt;
&lt;br /&gt;
Variable Name: &amp;nbsp;JAVA_HOME&lt;br /&gt;
Variable Value: &amp;nbsp;c:\jdk1.6&lt;span class=&quot;Apple-tab-span&quot; style=&quot;white-space: pre;&quot;&gt; &lt;/span&gt;\\ Never put a Semi-Colon at the end.&lt;br /&gt;
&lt;br /&gt;
Once Done Press OK.&lt;br /&gt;
&lt;br /&gt;
Now Create one more Environment Variable. Again by Clicking New any place you prefer:&lt;br /&gt;
&lt;br /&gt;
Variable Name: &amp;nbsp;CLASSPATH&lt;br /&gt;
Variable Value: &amp;nbsp;.;%JAVA_HOME%\lib;&lt;br /&gt;
&lt;br /&gt;
Note: You must put a Semi-Colon at the End. Press OK. The Reason to put a Semi-Colon here is a good practice as you might in near future append a new library to your CLASSPATH just to&amp;nbsp;separate&amp;nbsp;one from another you put a Windows PATH&amp;nbsp;Separator.&lt;br /&gt;
&lt;br /&gt;
Again, If you are unsure which pane to choose for this one always prefer the first one and add the below Key instead of updating your existing System Variable PATH key in global/system settings that way it will remain untouched.&lt;br /&gt;
&lt;br /&gt;
Variable Name: &amp;nbsp;PATH&lt;br /&gt;
Variable Value: &amp;nbsp;%JAVA_HOME%\bin;&lt;br /&gt;
&lt;br /&gt;
Note: Never Override a Key&#39;s Value always append to it.&lt;br /&gt;
&lt;br /&gt;
On Linux Machine:&lt;br /&gt;
&lt;br /&gt;
There is a ~/.bash_profile that is a&amp;nbsp;start-up&amp;nbsp;script which generally runs once. People find it common place to add environment variables such as PATH, JAVA_HOME, create aliases, etc.&lt;br /&gt;
&lt;br /&gt;
Please remember the file ~/.bashrc is similar but ~/.bash_profile runs for Bash Shell whereas, ~/.bashrc runs for every Bash Shell.&lt;br /&gt;
&lt;br /&gt;
Similarly, You can setup for all users i.e., Global Settings to do so you need to add the following&amp;nbsp;entries&amp;nbsp;mentioned below in /etc/profile.&lt;br /&gt;
&lt;br /&gt;
Fire your Terminal or Console: I&#39;m using ~/.bash_profile you can choose what you prefer.&lt;br /&gt;
&lt;br /&gt;
Type: $ vi ~/.bash_profile&lt;br /&gt;
&lt;br /&gt;
export JAVA_HOME=/PATH//TO/JAVA/FOLDER/WITHOUT/COLON/AT/THE/END&lt;br /&gt;
export PATH=$PATH:$JAVA_HOME/bin&lt;br /&gt;
export CLASSPATH=.:$JAVA_HOME/lib&lt;br /&gt;
&lt;br /&gt;
You have to logout and login back to see the new changes in effect. Alternatively you can type the below command to see the changes immediately.&lt;br /&gt;
&lt;br /&gt;
$ source ~/.bash_profile&lt;br /&gt;
&lt;br /&gt;
OR&lt;br /&gt;
&lt;br /&gt;
$ . ~/.bash_profile&lt;br /&gt;
&lt;br /&gt;
Always Remember always place Binary files i.e., files that are executable in the PATH variable irrespective you are working on Windows or Linux OS. CLASSPATH is for libraries.&lt;br /&gt;
&lt;br /&gt;
Now it&#39;s time to download Groovy. Please head over to their Site to download it and all we need is to extract it and add/update some Environment Variables. The same way we did for Java.&lt;br /&gt;
&lt;br /&gt;
Groovy Site: http://groovy.codehaus.org/&lt;br /&gt;
&lt;br /&gt;
You need to Add a New Environment Variable.&lt;br /&gt;
&lt;br /&gt;
Variable Name: &amp;nbsp;GROOVY_HOME&lt;br /&gt;
Variable Value: &amp;nbsp;PATH//TO/GROOVY/FOLDER/(IN WINDOWS WITHOUT SEMI-COLON OR IN LINUX WITHOUT COLON)/AT/THE/END&lt;br /&gt;
&lt;br /&gt;
Append to PATH Variable,&lt;br /&gt;
&lt;br /&gt;
Windows Users: %GROOVY_HOME%\bin;&lt;br /&gt;
Linux Users: $GROOVY_HOME/bin&lt;br /&gt;
&lt;br /&gt;
Make sure that there is a Semi-Colon (Windows), Colon (Linux Users) at the end before you append these values to it. You can confirm this using the echo command which works on both windows and Linux.&lt;br /&gt;
&lt;br /&gt;
Windows Users: echo %PATH%&lt;br /&gt;
Linux Users: echo $PATH&lt;br /&gt;
&lt;br /&gt;
If it&#39;s not present you must provide it otherwise it will not work. For Example: Instead of doing $GROOVY_HOME/bin&lt;br /&gt;
you do :$GROOVY_HOME/bin.&lt;br /&gt;
&lt;br /&gt;
Remember Colon is a Linux Path Separator whereas, Semi-Colon is Windows.&lt;br /&gt;
&lt;br /&gt;
Now As all the installations are done now we head over to test if everything is working fine or not.&lt;br /&gt;
&lt;br /&gt;
Windows Users, Please open Command Prompt close any if already Opened. Linux Users either use the source command to make the settings available to existing Console or login again.&lt;br /&gt;
&lt;br /&gt;
Now, Before we proceed any further we must check our installation.&lt;br /&gt;
&lt;br /&gt;
At prompt or Terminal or Console,&lt;br /&gt;
&lt;br /&gt;
Type:&lt;br /&gt;
&lt;br /&gt;
javac -version // To See if the Java Compiler is Working or not.&lt;br /&gt;
java -version // To See if the java execution environment is ready to run anything you throw at it.&lt;br /&gt;
&lt;br /&gt;
groovyc -version // To See if the Groovy Compiler is Working or not.&lt;br /&gt;
groovy -version // To See if the Groovy execution environment is ready to run anything you throw at it.&lt;br /&gt;
&lt;br /&gt;
groovysh -version // It&#39;s something that only Groovy had not Java. It can execute commands you throw at it. It&#39;s a REPL - Read Evaluate Print Loop.&lt;br /&gt;
&lt;br /&gt;
groovyConsole // It&#39;s a GUI Version.&lt;br /&gt;
&lt;br /&gt;
I hope you don&#39;t ran into any problem. Next Article is coming up on Groovy.&lt;br /&gt;
&lt;br /&gt;
Hope this Helps!&lt;br /&gt;
Please leave your comments.&lt;/div&gt;
&lt;div class=&quot;blogger-post-footer&quot;&gt;PythonicWay&lt;/div&gt;</content><link rel='replies' type='application/atom+xml' href='http://pythonicway.blogspot.com/feeds/471078501157944658/comments/default' title='Post Comments'/><link rel='replies' type='text/html' href='http://pythonicway.blogspot.com/2013/06/running-java-and-groovy-on-windows-and.html#comment-form' title='1 Comments'/><link rel='edit' type='application/atom+xml' href='http://www.blogger.com/feeds/3886129644493468120/posts/default/471078501157944658'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/3886129644493468120/posts/default/471078501157944658'/><link rel='alternate' type='text/html' href='http://pythonicway.blogspot.com/2013/06/running-java-and-groovy-on-windows-and.html' title='Running Java And Groovy on Windows And Linux'/><author><name>Karan Khosla</name><uri>http://www.blogger.com/profile/08752215164714997663</uri><email>noreply@blogger.com</email><gd:image rel='http://schemas.google.com/g/2005#thumbnail' width='33' height='26' src='//blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEjB5sW_u-jFmxQj-6JQ9tkvt8SJpiQkpXqCQf85d9_52l9YbST-SqdpOUMabQDbJ3He2fGAqiERLmX3Xt8kkzKgFdAN4NxTe3LDDIGdvjn07Va2mj5we4kgsSkfEO_JhQ/s220/optimus-prime.jpg'/></author><thr:total>1</thr:total></entry><entry><id>tag:blogger.com,1999:blog-3886129644493468120.post-3833422152580751567</id><published>2013-04-18T19:25:00.000+05:30</published><updated>2013-06-02T15:53:14.468+05:30</updated><category scheme="http://www.blogger.com/atom/ns#" term="Code"/><category scheme="http://www.blogger.com/atom/ns#" term="Comparable"/><category scheme="http://www.blogger.com/atom/ns#" term="Comparator"/><category scheme="http://www.blogger.com/atom/ns#" term="Custom Class"/><category scheme="http://www.blogger.com/atom/ns#" term="Custom Sorting"/><category scheme="http://www.blogger.com/atom/ns#" term="Example"/><category scheme="http://www.blogger.com/atom/ns#" term="External Sorting"/><category scheme="http://www.blogger.com/atom/ns#" term="Howto"/><category scheme="http://www.blogger.com/atom/ns#" term="Internal Sorting"/><category scheme="http://www.blogger.com/atom/ns#" term="java"/><category scheme="http://www.blogger.com/atom/ns#" term="Sorting"/><title type='text'>Howto Use Java Comparator and Comparable by Example</title><content type='html'>&lt;div dir=&quot;ltr&quot; style=&quot;text-align: left;&quot; trbidi=&quot;on&quot;&gt;
In Java, there are some built-in methods that provides basic sorting of Primitive types array or Wrapper classes but what If we wanted to sort a custom class that we have written for use in one of our Projects? Well the answer is to write a sorting algorithm of our own and use it wherever it&#39;s required.&lt;br /&gt;
&lt;br /&gt;
In Java, there are two interfaces that can help us achieve our goal. The reason the language provides two interfaces instead of one giving code developers enough flexibility to choose the one that they find suitable to their requirement.&lt;br /&gt;
&lt;br /&gt;
The first Interface which I prefer to call is the &lt;b&gt;&lt;u&gt;Simple Handy&amp;nbsp;Internal Sorter&lt;/u&gt;&lt;/b&gt; is available in&amp;nbsp;&lt;b&gt;java.lang.Comparable&lt;/b&gt;&amp;nbsp; . The Second Interface which I prefer to call is the &lt;b&gt;&lt;u&gt;Highly&amp;nbsp;&lt;/u&gt;&lt;/b&gt;&lt;u&gt;&lt;b&gt;Flexible External Sorter&lt;/b&gt;&lt;/u&gt;&amp;nbsp;is available in &lt;b&gt;java.util.Comparator.&lt;/b&gt;&lt;br /&gt;
&lt;br /&gt;
The former one is Simple and Internal as it needs to be implemented on the class itself and it&#39;s simple as it allows the code developers to write only single sorting implementation. The latter one is Highly Flexible and External that means it allows the code developer the flexibility to write as many as required sorting implementation for their custom class as it&#39;s declaration and implementation is in a&amp;nbsp;separate&amp;nbsp;class.&lt;br /&gt;
&lt;br /&gt;
Let&#39;s start with the Below Example where Custom Class CarMake have both Simple Handy Internal Sorter and Highly Flexible External Sorter.&lt;br /&gt;
&lt;br /&gt;
&lt;b&gt;&lt;u&gt;CarMake.java&lt;/u&gt;&lt;/b&gt;&lt;br /&gt;
&lt;br /&gt;
As you can see below the Simple Handy Internal Sorter is already implemented on the Custom Class.&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;script src=&quot;https://gist.github.com/karankhosla/e7964c4a137c95bfba55.js&quot;&gt;&lt;/script&gt;

&lt;div&gt;
&lt;b&gt;&lt;u&gt;CarMakeComparatorAsc.java&lt;/u&gt;&lt;/b&gt;&lt;/div&gt;
&lt;div&gt;
&lt;br /&gt;&lt;/div&gt;
&lt;div&gt;
Custom Class CarMake&#39;s Highly Flexible External Sorter Implementation.&lt;/div&gt;
&lt;div&gt;
&lt;br /&gt;&lt;/div&gt;
&lt;div&gt;
&lt;script src=&quot;https://gist.github.com/karankhosla/38301cdec9200169421f.js&quot;&gt;&lt;/script&gt;

&lt;br /&gt;
&lt;div&gt;
&lt;div&gt;
&lt;br /&gt;&lt;/div&gt;
&lt;div&gt;
&lt;br /&gt;&lt;/div&gt;
&lt;div&gt;
&lt;b&gt;&lt;u&gt;CarMakeComparatorDesc.java&lt;/u&gt;&lt;/b&gt;&lt;/div&gt;
&lt;div&gt;
&lt;br /&gt;&lt;/div&gt;
&lt;div&gt;
Custom Class CarMake&#39;s Highly Flexible External Sorter Implementation.&lt;/div&gt;
&lt;div&gt;
&lt;br /&gt;&lt;/div&gt;
&lt;div&gt;
&lt;script src=&quot;https://gist.github.com/karankhosla/3a3b0a37d43774ca93d6.js&quot;&gt;&lt;/script&gt;
&lt;/div&gt;
&lt;div&gt;
&lt;br /&gt;&lt;/div&gt;
&lt;div&gt;
And, Finally the only thing required is to test both the implementation using a CarMakeSortTest.java.&lt;/div&gt;
&lt;div&gt;
&lt;br /&gt;&lt;/div&gt;
&lt;div&gt;
&lt;b&gt;&lt;u&gt;CarMakeSortTest.java&lt;/u&gt;&lt;/b&gt;&lt;/div&gt;
&lt;div&gt;
&lt;br /&gt;&lt;/div&gt;
&lt;div&gt;
&lt;div&gt;
&lt;script src=&quot;https://gist.github.com/karankhosla/1cf17a1b6caeea711af0.js&quot;&gt;&lt;/script&gt;
&lt;/div&gt;
&lt;div&gt;
&lt;br /&gt;&lt;/div&gt;
&lt;div&gt;
I Hope this post helps you learn basics of Custom Class Sorting. Please do write your feedback...&lt;br /&gt;
&lt;br /&gt;
You can download the complete code from &lt;a href=&quot;https://github.com/karankhosla&quot;&gt;Github&lt;/a&gt;&lt;br /&gt;
&lt;br /&gt;&lt;/div&gt;
&lt;/div&gt;
&lt;/div&gt;
&lt;/div&gt;
&lt;/div&gt;
&lt;div class=&quot;blogger-post-footer&quot;&gt;PythonicWay&lt;/div&gt;</content><link rel='replies' type='application/atom+xml' href='http://pythonicway.blogspot.com/feeds/3833422152580751567/comments/default' title='Post Comments'/><link rel='replies' type='text/html' href='http://pythonicway.blogspot.com/2013/04/howto-use-java-comparator-and.html#comment-form' title='0 Comments'/><link rel='edit' type='application/atom+xml' href='http://www.blogger.com/feeds/3886129644493468120/posts/default/3833422152580751567'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/3886129644493468120/posts/default/3833422152580751567'/><link rel='alternate' type='text/html' href='http://pythonicway.blogspot.com/2013/04/howto-use-java-comparator-and.html' title='Howto Use Java Comparator and Comparable by Example'/><author><name>Karan Khosla</name><uri>http://www.blogger.com/profile/08752215164714997663</uri><email>noreply@blogger.com</email><gd:image rel='http://schemas.google.com/g/2005#thumbnail' width='33' height='26' src='//blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEjB5sW_u-jFmxQj-6JQ9tkvt8SJpiQkpXqCQf85d9_52l9YbST-SqdpOUMabQDbJ3He2fGAqiERLmX3Xt8kkzKgFdAN4NxTe3LDDIGdvjn07Va2mj5we4kgsSkfEO_JhQ/s220/optimus-prime.jpg'/></author><thr:total>0</thr:total></entry><entry><id>tag:blogger.com,1999:blog-3886129644493468120.post-3882430025878826761</id><published>2012-04-03T11:43:00.001+05:30</published><updated>2012-04-08T15:22:27.504+05:30</updated><category scheme="http://www.blogger.com/atom/ns#" term="Basics"/><category scheme="http://www.blogger.com/atom/ns#" term="composition"/><category scheme="http://www.blogger.com/atom/ns#" term="design patterns"/><category scheme="http://www.blogger.com/atom/ns#" term="Inheritance"/><category scheme="http://www.blogger.com/atom/ns#" term="java"/><title type='text'>Favor Composition to Inheritance</title><content type='html'>&lt;div dir=&quot;ltr&quot; style=&quot;text-align: left;&quot; trbidi=&quot;on&quot;&gt;
&lt;b&gt;A&lt;/b&gt;s we all know&lt;b&gt; J&lt;/b&gt;ava is an &lt;b&gt;O&lt;/b&gt;bject-&lt;b&gt;O&lt;/b&gt;riented &lt;b&gt;P&lt;/b&gt;rogramming Language. OOP was developed in first place to increase code&amp;nbsp;reuse&amp;nbsp;and&amp;nbsp;maintainability.&lt;br /&gt;
&lt;br /&gt;
&lt;b&gt;&lt;u&gt;The Myth&lt;/u&gt;&lt;/b&gt;&lt;br /&gt;
&lt;br /&gt;
&lt;b&gt;P&lt;/b&gt;rogrammers introduced to OOP Language(s) have a mindset that code reuse can be achieved only by Inheritance (extends) in Java. But are not aware of the alternatives even if they came across them.&lt;br /&gt;
&lt;br /&gt;
For Example:&lt;br /&gt;
&lt;br /&gt;
&lt;div style=&quot;text-align: center;&quot;&gt;
&lt;b&gt;List&amp;lt;Car&amp;gt; carRef = new ArrayList&amp;lt;Car&amp;gt;(); &amp;nbsp;//Generic List of Car References&lt;/b&gt;&lt;/div&gt;
&lt;br /&gt;
&lt;b&gt;Q.&lt;/b&gt;&amp;nbsp; Why Inheritance is considered bad?&lt;br /&gt;
&lt;br /&gt;
&lt;b&gt;A.&lt;/b&gt;&amp;nbsp; Experienced Programmers&amp;nbsp;are aware of the fact and even the Design Patterns states the same &lt;b&gt;using Inheritance across&amp;nbsp;boundaries&amp;nbsp;are&amp;nbsp;considered&amp;nbsp;bad as author of that library may change the internal implementation details which might break our abstraction that depends on it blowing up the whole stack.&lt;/b&gt;&lt;br /&gt;
&lt;b&gt;&lt;br /&gt;&lt;/b&gt;&lt;br /&gt;
&lt;b&gt;Better Alternative - Prefer Composition to Inheritance&lt;/b&gt;&lt;br /&gt;
&lt;b&gt;&lt;br /&gt;&lt;/b&gt;&lt;br /&gt;
&lt;b&gt;&lt;br /&gt;&lt;/b&gt;&lt;br /&gt;
&lt;b&gt;-------------------------&lt;/b&gt;&lt;br /&gt;
&lt;b&gt;I will soon add more on this. Please do post your comments if your thinking differs from me. I will try to incorporate you questions/suggestion here so everyone has a better idea on this concept.&lt;/b&gt;&lt;br /&gt;
&lt;b&gt;&lt;br /&gt;&lt;/b&gt;&lt;br /&gt;
&lt;span style=&quot;background-color: white; font-family: Arial, Tahoma, Helvetica, FreeSans, sans-serif; font-size: 15px; line-height: 20px;&quot;&gt;&lt;b&gt;Hope this Helps! Please write your comments it will help me improve.&lt;/b&gt;&lt;/span&gt;
&lt;br /&gt;
&lt;b&gt;&lt;br /&gt;&lt;/b&gt;&lt;br /&gt;
&lt;b&gt;&lt;br /&gt;&lt;/b&gt;&lt;/div&gt;&lt;div class=&quot;blogger-post-footer&quot;&gt;PythonicWay&lt;/div&gt;</content><link rel='replies' type='application/atom+xml' href='http://pythonicway.blogspot.com/feeds/3882430025878826761/comments/default' title='Post Comments'/><link rel='replies' type='text/html' href='http://pythonicway.blogspot.com/2012/04/in-practice-prefer-compostion-over.html#comment-form' title='4 Comments'/><link rel='edit' type='application/atom+xml' href='http://www.blogger.com/feeds/3886129644493468120/posts/default/3882430025878826761'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/3886129644493468120/posts/default/3882430025878826761'/><link rel='alternate' type='text/html' href='http://pythonicway.blogspot.com/2012/04/in-practice-prefer-compostion-over.html' title='Favor Composition to Inheritance'/><author><name>Karan Khosla</name><uri>http://www.blogger.com/profile/08752215164714997663</uri><email>noreply@blogger.com</email><gd:image rel='http://schemas.google.com/g/2005#thumbnail' width='33' height='26' src='//blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEjB5sW_u-jFmxQj-6JQ9tkvt8SJpiQkpXqCQf85d9_52l9YbST-SqdpOUMabQDbJ3He2fGAqiERLmX3Xt8kkzKgFdAN4NxTe3LDDIGdvjn07Va2mj5we4kgsSkfEO_JhQ/s220/optimus-prime.jpg'/></author><thr:total>4</thr:total></entry><entry><id>tag:blogger.com,1999:blog-3886129644493468120.post-7579555177467270470</id><published>2011-05-22T22:58:00.000+05:30</published><updated>2011-05-22T22:58:36.343+05:30</updated><category scheme="http://www.blogger.com/atom/ns#" term="Basics"/><category scheme="http://www.blogger.com/atom/ns#" term="Linux"/><title type='text'>Linux Basics Walkthrough Part 1</title><content type='html'>&lt;div dir=&quot;ltr&quot; style=&quot;text-align: left;&quot; trbidi=&quot;on&quot;&gt;&lt;span style=&quot;font-size: large;&quot;&gt;&lt;b&gt;N&lt;/b&gt;&lt;/span&gt;owadays, Linux comes with pretty simple to use GUI. Professionals still prefers CLI to perform there tasks as they know the mantra GUI is simple but CLI is powerful. Let&#39;s dig into the basis.&lt;br /&gt;
&lt;br /&gt;
&lt;b&gt;1. Navigation&lt;/b&gt;&lt;br /&gt;
&lt;br /&gt;
cd - Change Directory. For Example: cd /home/karan&lt;br /&gt;
&lt;br /&gt;
&lt;b&gt;2. Where I&#39;m&lt;/b&gt;&lt;br /&gt;
&lt;b&gt;&amp;nbsp;&lt;/b&gt;&lt;br /&gt;
pwd - prints the current working directory.&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;b&gt;3. Who I&#39;m&lt;/b&gt;&lt;br /&gt;
&lt;br /&gt;
whoami - Shows user who is currently issuing command.&lt;br /&gt;
&lt;br /&gt;
&lt;b&gt;4. Feel Secure&lt;/b&gt;&lt;br /&gt;
&lt;br /&gt;
passwd - Allows you to change the password for the user who is issuing the command.&lt;br /&gt;
&lt;br /&gt;
&lt;b style=&quot;color: red;&quot;&gt;Note:&lt;/b&gt; passwd &amp;lt;username&amp;gt; Allows Super Users/Admins to change the password of other users.&lt;br /&gt;
&lt;br /&gt;
&lt;b&gt;5. Reading files&lt;/b&gt;&lt;br /&gt;
&lt;br /&gt;
cat - Allows user to view content of a file.&lt;br /&gt;
&lt;br /&gt;
P.S. I&#39;ll be updating this post soon with lot more commands.&lt;br /&gt;
&lt;br /&gt;
&lt;b&gt;Hope this Helps! Please write your comments it will help me improve.&lt;/b&gt;&lt;/div&gt;&lt;div class=&quot;blogger-post-footer&quot;&gt;PythonicWay&lt;/div&gt;</content><link rel='replies' type='application/atom+xml' href='http://pythonicway.blogspot.com/feeds/7579555177467270470/comments/default' title='Post Comments'/><link rel='replies' type='text/html' href='http://pythonicway.blogspot.com/2011/05/linux-basics-walkthrough-part-1.html#comment-form' title='0 Comments'/><link rel='edit' type='application/atom+xml' href='http://www.blogger.com/feeds/3886129644493468120/posts/default/7579555177467270470'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/3886129644493468120/posts/default/7579555177467270470'/><link rel='alternate' type='text/html' href='http://pythonicway.blogspot.com/2011/05/linux-basics-walkthrough-part-1.html' title='Linux Basics Walkthrough Part 1'/><author><name>Unknown</name><email>noreply@blogger.com</email><gd:image rel='http://schemas.google.com/g/2005#thumbnail' width='16' height='16' src='https://img1.blogblog.com/img/b16-rounded.gif'/></author><thr:total>0</thr:total></entry><entry><id>tag:blogger.com,1999:blog-3886129644493468120.post-6961804121482179406</id><published>2011-03-01T19:44:00.000+05:30</published><updated>2011-03-01T19:44:05.559+05:30</updated><category scheme="http://www.blogger.com/atom/ns#" term="Arithmetic"/><category scheme="http://www.blogger.com/atom/ns#" term="Complex Numbers"/><category scheme="http://www.blogger.com/atom/ns#" term="Python Basics"/><title type='text'>Python Basics: Python Complex Numbers</title><content type='html'>&lt;div dir=&quot;ltr&quot; style=&quot;text-align: left;&quot; trbidi=&quot;on&quot;&gt;Python supports Complex Numbers and are built-in to the language. You can create complex numbers either by specifying the number in (real + imagJ) form or using a built-in method complex(a, b).&lt;br /&gt;
&lt;br /&gt;
&lt;u&gt;&lt;b&gt;Complex Numbers: &lt;/b&gt;&lt;/u&gt;&lt;br /&gt;
&lt;ol style=&quot;text-align: left;&quot;&gt;&lt;li&gt;For Electronic Engineers python uses j or J instead of an i for imaginary numbers.&lt;/li&gt;
&lt;li&gt;j or J means square root of -1.&lt;/li&gt;
&lt;li&gt;You can perform arithmetic operations on Complex Numbers. &lt;/li&gt;
&lt;li&gt;Both real and imagJ part are floating-point numbers.&lt;/li&gt;
&lt;li&gt;Complex Number has a nonzero real part. &lt;/li&gt;
&lt;li&gt;cmath library. (for your reference.)&lt;/li&gt;
&lt;/ol&gt;&lt;b&gt;(Post in your comments if i left out something important so i can add in here.) &lt;/b&gt;&lt;br /&gt;
&lt;br /&gt;
&lt;u&gt;&lt;b&gt;How Complex Numbers Works.&lt;/b&gt;&lt;/u&gt;&lt;br /&gt;
&lt;br /&gt;
&amp;nbsp; 1 #!/usr/local/bin/python3.2&lt;br /&gt;
&amp;nbsp; 2 # Filename: ComplexNum.py&lt;br /&gt;
&amp;nbsp; 3 &lt;br /&gt;
&amp;nbsp; 4 # How Imaginary Number Arithmetic Works.&lt;br /&gt;
&amp;nbsp; 5 print(&#39;1j + 1j :&#39;, 1j + 1j)&lt;br /&gt;
&amp;nbsp; 6 print(&#39;3j - 1j :&#39;, 3j - 1j)&lt;br /&gt;
&amp;nbsp; 7 print(&#39;2j * 1j :&#39;, 2j * 1j)&lt;br /&gt;
&amp;nbsp; 8 print(&#39;2j / 1j :&#39;, 2j / 1j)&lt;br /&gt;
&amp;nbsp; 9 &lt;br /&gt;
&amp;nbsp;10 # complex(real, imagJ)&lt;br /&gt;
&amp;nbsp;11 print(&#39;complex(1, 1) :&#39;, complex(1, 1))&lt;br /&gt;
&amp;nbsp;12 &lt;br /&gt;
&amp;nbsp;13 # Make Complex Numbers bit More Complex. Arithmetic on real and imagJ parts. :)&lt;br /&gt;
&amp;nbsp;14 print(&#39;3 * complex(2, 3) :&#39;, 3 * complex(2, 3))&lt;br /&gt;
&amp;nbsp;15 print(&#39;2j * complex(4, 6) :&#39;, 2j * complex(4, 6))&lt;br /&gt;
&amp;nbsp;16 print(&#39;(2 + 4j) * complex(4, 2) :&#39;, (2 + 4j) * complex(4, 2))&lt;br /&gt;
&amp;nbsp;17 print(&#39;(2 + 4j) * (4 + 2j) :&#39;, (2 + 4j) * (4 + 2j))&lt;br /&gt;
&amp;nbsp;18 print(&#39;complex(2, 4) * complex(4, 2) :&#39;, complex(2, 4) * complex(4, 2))&lt;br /&gt;
&lt;br /&gt;
You can download the file here: &lt;a href=&quot;http://dl.dropbox.com/u/19925378/Python_Work/ComplexNum.py&quot;&gt;ComplexNum.py&lt;/a&gt;&lt;br /&gt;
&lt;br /&gt;
&lt;u&gt;&lt;b&gt;Output:&lt;/b&gt;&lt;/u&gt;&lt;br /&gt;
&lt;br /&gt;
1j + 1j : 2j&lt;br /&gt;
3j - 1j : 2j&lt;br /&gt;
2j * 1j : (-2+0j)&lt;br /&gt;
2j / 1j : (2+0j)&lt;br /&gt;
complex(1, 1) : (1+1j)&lt;br /&gt;
3 * complex(2, 3) : (6+9j)&lt;br /&gt;
2j * complex(4, 6) : (-12+8j)&lt;br /&gt;
(2 + 4j) * complex(4, 2) : 20j&lt;br /&gt;
(2 + 4j) * (4 + 2j) : 20j&lt;br /&gt;
complex(2, 4) * complex(4, 2) : 20j&lt;br /&gt;
&lt;br /&gt;
&lt;u&gt;&lt;b&gt;Explanation:&lt;/b&gt;&lt;/u&gt;&lt;br /&gt;
&lt;ol style=&quot;text-align: left;&quot;&gt;&lt;li&gt;Line #5 &amp;amp; #6 are pretty much self-explained.&lt;/li&gt;
&lt;li&gt;Line #7 2j * 1j = 2j^2. As we know that j here means square root of -1. Now j^2 equals -1. leads to the output of (-2 + 0j). As we know that a complex number has a nonzero real part.&lt;/li&gt;
&lt;li&gt;Line #8 2j / 1j = (2+0j). Complex Part division is a bit harder maybe or not. Because we need to multiply but top and bottom by what we call &lt;b&gt;complex conjugate&lt;/b&gt;. This is what you get when you change the sign of the imaginary part but not the real part. 2j/1j * -1j/-1j, i.e, -2j^2/-1j^2. Minus signs cancels out we are left with (2 + 0j).&lt;/li&gt;
&lt;li&gt;Line #11 uses python interpreter built-in function complex(a, b). But the output has nothing much that i can explain.&lt;/li&gt;
&lt;/ol&gt;I believe rest of it is more or less self -explainable. But if you think they need explanation post in your comments. :) &lt;br /&gt;
&lt;br /&gt;
&lt;b&gt;Hope this Helps! Please write your comments it will help me improve.&lt;/b&gt;&lt;/div&gt;&lt;div class=&quot;blogger-post-footer&quot;&gt;PythonicWay&lt;/div&gt;</content><link rel='replies' type='application/atom+xml' href='http://pythonicway.blogspot.com/feeds/6961804121482179406/comments/default' title='Post Comments'/><link rel='replies' type='text/html' href='http://pythonicway.blogspot.com/2011/03/python-basics-python-complex-numbers.html#comment-form' title='0 Comments'/><link rel='edit' type='application/atom+xml' href='http://www.blogger.com/feeds/3886129644493468120/posts/default/6961804121482179406'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/3886129644493468120/posts/default/6961804121482179406'/><link rel='alternate' type='text/html' href='http://pythonicway.blogspot.com/2011/03/python-basics-python-complex-numbers.html' title='Python Basics: Python Complex Numbers'/><author><name>Unknown</name><email>noreply@blogger.com</email><gd:image rel='http://schemas.google.com/g/2005#thumbnail' width='16' height='16' src='https://img1.blogblog.com/img/b16-rounded.gif'/></author><thr:total>0</thr:total></entry><entry><id>tag:blogger.com,1999:blog-3886129644493468120.post-5265742621169944913</id><published>2011-02-14T14:54:00.000+05:30</published><updated>2011-02-14T14:54:28.940+05:30</updated><category scheme="http://www.blogger.com/atom/ns#" term="aggregation"/><category scheme="http://www.blogger.com/atom/ns#" term="composition"/><category scheme="http://www.blogger.com/atom/ns#" term="java"/><category scheme="http://www.blogger.com/atom/ns#" term="oops"/><title type='text'>Java in Practice: Coding and UML Aggregation v/s Composition</title><content type='html'>&lt;div dir=&quot;ltr&quot; style=&quot;text-align: left;&quot; trbidi=&quot;on&quot;&gt;&lt;br /&gt;
&lt;span class=&quot;postbody&quot;&gt;&lt;span style=&quot;font-size: 18px; line-height: normal;&quot;&gt;&lt;span style=&quot;color: darkblue;&quot;&gt;&lt;b&gt;&lt;/b&gt;&lt;/span&gt;&lt;/span&gt;&lt;/span&gt;&lt;br /&gt;
&lt;span class=&quot;postbody&quot;&gt;&lt;span style=&quot;font-size: 18px; line-height: normal;&quot;&gt;&lt;span style=&quot;color: darkblue;&quot;&gt;&lt;b&gt;Aggregation [ &#39;HAS-A&#39; Relationship ]&lt;/b&gt;&lt;/span&gt;&lt;/span&gt;&lt;/span&gt;&lt;br /&gt;
&lt;br /&gt;
class StereoSystem {&lt;br /&gt;
&amp;nbsp;&amp;nbsp;&amp;nbsp; private boolean state ;&lt;br /&gt;
&amp;nbsp;&amp;nbsp;&amp;nbsp; StereoSystem() {}&lt;br /&gt;
&amp;nbsp;&amp;nbsp;&amp;nbsp; StereoSystem(boolean state) {&lt;br /&gt;
&amp;nbsp;&amp;nbsp;&amp;nbsp; &amp;nbsp;&amp;nbsp;&amp;nbsp; this.state = state ;&lt;br /&gt;
&amp;nbsp;&amp;nbsp;&amp;nbsp; &amp;nbsp;&amp;nbsp;&amp;nbsp; System.out.println(&quot;Stereo System State: &quot; + (state == true ? &quot;On!&quot; : &quot;Off!&quot;)) ;&lt;br /&gt;
&amp;nbsp;&amp;nbsp;&amp;nbsp; }&lt;br /&gt;
}&lt;br /&gt;
&lt;br /&gt;
class Car {&lt;br /&gt;
&amp;nbsp;&amp;nbsp;&amp;nbsp; private StereoSystem s ;&lt;br /&gt;
&amp;nbsp;&amp;nbsp;&amp;nbsp; Car() {}&lt;br /&gt;
&amp;nbsp;&amp;nbsp;&amp;nbsp; Car(String name, StereoSystem s) {&lt;br /&gt;
&amp;nbsp;&amp;nbsp;&amp;nbsp; &amp;nbsp;&amp;nbsp;&amp;nbsp; this.s = s ;&lt;br /&gt;
&amp;nbsp;&amp;nbsp;&amp;nbsp; }&lt;br /&gt;
&amp;nbsp;&amp;nbsp;&amp;nbsp; public static void main(String[] args) {&lt;br /&gt;
&amp;nbsp;&amp;nbsp;&amp;nbsp; &amp;nbsp;&amp;nbsp;&amp;nbsp; StereoSystem ss = new StereoSystem(true) ;&amp;nbsp; // true(System is ON.) or false (System is OFF)&lt;br /&gt;
&amp;nbsp;&amp;nbsp;&amp;nbsp; &amp;nbsp;&amp;nbsp;&amp;nbsp; Car c = new Car(&quot;BMW&quot;, ss) ;&lt;br /&gt;
&amp;nbsp;&amp;nbsp;&amp;nbsp; }&lt;br /&gt;
}&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;span class=&quot;postbody&quot;&gt;&lt;b&gt;&lt;span style=&quot;color: darkblue;&quot;&gt;&lt;span style=&quot;font-size: 14px; line-height: normal;&quot;&gt;In UML Aggregation is Expressed as&lt;/span&gt;&lt;/span&gt;&lt;/b&gt;&lt;/span&gt; &lt;br /&gt;
&lt;br /&gt;
&lt;div class=&quot;separator&quot; style=&quot;clear: both; text-align: center;&quot;&gt;&lt;a href=&quot;http://i41.tinypic.com/aadimf.jpg&quot; imageanchor=&quot;1&quot; style=&quot;margin-left: 1em; margin-right: 1em;&quot;&gt;&lt;img border=&quot;0&quot; height=&quot;86&quot; src=&quot;http://i41.tinypic.com/aadimf.jpg&quot; width=&quot;320&quot; /&gt;&lt;/a&gt;&lt;/div&gt;&lt;br /&gt;
&lt;span style=&quot;font-size: 18px; line-height: normal;&quot;&gt;&lt;span style=&quot;color: darkblue;&quot;&gt;&lt;b&gt;Composition [ &#39;Contains&#39; Relationship ]&lt;/b&gt;&lt;/span&gt;&lt;/span&gt; &lt;br /&gt;
&lt;br /&gt;
import java.util.Date ;&lt;br /&gt;
&lt;br /&gt;
class Piston {&lt;br /&gt;
&amp;nbsp;&amp;nbsp;&amp;nbsp; private Date pistonDate ;&lt;br /&gt;
&amp;nbsp;&amp;nbsp;&amp;nbsp; Piston() {&lt;br /&gt;
&amp;nbsp;&amp;nbsp;&amp;nbsp; &amp;nbsp;&amp;nbsp;&amp;nbsp; pistonDate = new Date() ;&lt;br /&gt;
&amp;nbsp;&amp;nbsp;&amp;nbsp; &amp;nbsp;&amp;nbsp;&amp;nbsp; System.out.println(&quot;Manufactured Date :: &quot; + pistonDate) ;&lt;br /&gt;
&amp;nbsp;&amp;nbsp;&amp;nbsp; }&lt;br /&gt;
}&lt;br /&gt;
&lt;br /&gt;
class Engine {&lt;br /&gt;
&amp;nbsp;&amp;nbsp;&amp;nbsp; private Piston piston ;&lt;br /&gt;
&amp;nbsp;&amp;nbsp;&amp;nbsp; Engine() {&lt;br /&gt;
&amp;nbsp;&amp;nbsp;&amp;nbsp; &amp;nbsp;&amp;nbsp;&amp;nbsp; piston = new Piston() ;&lt;br /&gt;
&amp;nbsp;&amp;nbsp;&amp;nbsp; }&lt;br /&gt;
&amp;nbsp;&amp;nbsp;&amp;nbsp; public static void main(String[] args) {&lt;br /&gt;
&amp;nbsp;&amp;nbsp;&amp;nbsp; &amp;nbsp;&amp;nbsp;&amp;nbsp; Engine engine = new Engine() ;&lt;br /&gt;
&amp;nbsp;&amp;nbsp;&amp;nbsp; }&lt;br /&gt;
}&lt;br /&gt;
&lt;br /&gt;
&lt;b&gt;&lt;span style=&quot;color: darkblue;&quot;&gt;&lt;span style=&quot;font-size: 14px; line-height: normal;&quot;&gt;In UML Composition is Expressed as&lt;/span&gt;&lt;/span&gt;&lt;/b&gt;&amp;nbsp;&lt;br /&gt;
&lt;br /&gt;
&lt;div class=&quot;separator&quot; style=&quot;clear: both; text-align: center;&quot;&gt;&lt;a href=&quot;http://i44.tinypic.com/2agrtdu.jpg&quot; imageanchor=&quot;1&quot; style=&quot;margin-left: 1em; margin-right: 1em;&quot;&gt;&lt;img border=&quot;0&quot; height=&quot;86&quot; src=&quot;http://i44.tinypic.com/2agrtdu.jpg&quot; width=&quot;320&quot; /&gt;&lt;/a&gt;&lt;/div&gt;&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
I originally posted this here: &lt;a href=&quot;http://www.coderanch.com/t/443002/java/java/Java-Coding-UML-Aggregation-Composition&quot;&gt;http://www.coderanch.com/t/443002/java/java/Java-Coding-UML-Aggregation-Composition&lt;/a&gt;&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;b&gt;Hope this Helps! Please write your comments it will help me improve.&lt;/b&gt;&lt;/div&gt;&lt;div class=&quot;blogger-post-footer&quot;&gt;PythonicWay&lt;/div&gt;</content><link rel='replies' type='application/atom+xml' href='http://pythonicway.blogspot.com/feeds/5265742621169944913/comments/default' title='Post Comments'/><link rel='replies' type='text/html' href='http://pythonicway.blogspot.com/2011/02/java-in-practice-coding-and-uml.html#comment-form' title='1 Comments'/><link rel='edit' type='application/atom+xml' href='http://www.blogger.com/feeds/3886129644493468120/posts/default/5265742621169944913'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/3886129644493468120/posts/default/5265742621169944913'/><link rel='alternate' type='text/html' href='http://pythonicway.blogspot.com/2011/02/java-in-practice-coding-and-uml.html' title='Java in Practice: Coding and UML Aggregation v/s Composition'/><author><name>Unknown</name><email>noreply@blogger.com</email><gd:image rel='http://schemas.google.com/g/2005#thumbnail' width='16' height='16' src='https://img1.blogblog.com/img/b16-rounded.gif'/></author><media:thumbnail xmlns:media="http://search.yahoo.com/mrss/" url="http://i41.tinypic.com/aadimf_th.jpg" height="72" width="72"/><thr:total>1</thr:total></entry><entry><id>tag:blogger.com,1999:blog-3886129644493468120.post-5536926512639753933</id><published>2011-02-14T11:21:00.000+05:30</published><updated>2011-02-14T11:21:24.310+05:30</updated><category scheme="http://www.blogger.com/atom/ns#" term="abs(x)"/><category scheme="http://www.blogger.com/atom/ns#" term="Python Basics"/><category scheme="http://www.blogger.com/atom/ns#" term="usage"/><title type='text'>Python Basics: Built-in function abs usage</title><content type='html'>&lt;div dir=&quot;ltr&quot; style=&quot;text-align: left;&quot; trbidi=&quot;on&quot;&gt;First of all Built-in functions are those functions that are available to us all the time without importing any python modules. Today we&#39;ll see how to use abs(x) function.&lt;br /&gt;
&lt;blockquote&gt;So, Let&#39;s get Started:&lt;br /&gt;
&lt;blockquote&gt;abs(x) function takes an argument that can be a integer or a floating point number. It returns you the absolute value of a given number. A argument can be complex number, in that case the magnitude is returned.&lt;/blockquote&gt;&lt;/blockquote&gt;&lt;u&gt;&lt;b&gt;Simple Case:&lt;/b&gt;&lt;/u&gt;&lt;br /&gt;
&lt;br /&gt;
Let, say if x is less than zero, i.e, x &amp;lt; 0, than -x is returned. Otherwise, if x is greater than or equal to zero, i.e, x &amp;gt;= 0, than x is returned.&lt;br /&gt;
&lt;br /&gt;
&lt;u&gt;&lt;b&gt;Complex Case:&lt;/b&gt;&lt;/u&gt;&lt;br /&gt;
&lt;br /&gt;
Let, say if x is complex, than in that case abs returns a square root of&amp;nbsp; x.imag**2 + x.real**2 (a.k.a magnitude) of a number.&lt;br /&gt;
&lt;br /&gt;
We&#39;ll be discussing complex numbers in another post. But in any case the formula to compute them remains same.&lt;br /&gt;
&lt;br /&gt;
&lt;b&gt;Hope this Helps! Please write your comments it will help me improve.&lt;/b&gt;&lt;/div&gt;&lt;div class=&quot;blogger-post-footer&quot;&gt;PythonicWay&lt;/div&gt;</content><link rel='replies' type='application/atom+xml' href='http://pythonicway.blogspot.com/feeds/5536926512639753933/comments/default' title='Post Comments'/><link rel='replies' type='text/html' href='http://pythonicway.blogspot.com/2011/02/python-basics-built-in-function-abs.html#comment-form' title='0 Comments'/><link rel='edit' type='application/atom+xml' href='http://www.blogger.com/feeds/3886129644493468120/posts/default/5536926512639753933'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/3886129644493468120/posts/default/5536926512639753933'/><link rel='alternate' type='text/html' href='http://pythonicway.blogspot.com/2011/02/python-basics-built-in-function-abs.html' title='Python Basics: Built-in function abs usage'/><author><name>Unknown</name><email>noreply@blogger.com</email><gd:image rel='http://schemas.google.com/g/2005#thumbnail' width='16' height='16' src='https://img1.blogblog.com/img/b16-rounded.gif'/></author><thr:total>0</thr:total></entry><entry><id>tag:blogger.com,1999:blog-3886129644493468120.post-629434458414138027</id><published>2011-02-12T21:00:00.000+05:30</published><updated>2011-02-12T21:00:37.906+05:30</updated><category scheme="http://www.blogger.com/atom/ns#" term="fix"/><category scheme="http://www.blogger.com/atom/ns#" term="getRealPath"/><category scheme="http://www.blogger.com/atom/ns#" term="Servlet"/><category scheme="http://www.blogger.com/atom/ns#" term="Weblogic Server"/><category scheme="http://www.blogger.com/atom/ns#" term="WLS"/><title type='text'>Fix: Weblogic ServletContext.getRealPath() returns null</title><content type='html'>&lt;div dir=&quot;ltr&quot; style=&quot;text-align: left;&quot; trbidi=&quot;on&quot;&gt;Weblogic Server[WLS] returns null if your code is using Servlet.getRealPath() many of you expect that it&#39;s another weblogic server bug but it&#39;s not. An application can be deployed in two ways either exploded or archive. If you are deploying an application as exploded which is a folder containing your application you won&#39;t see such an error. But, if you deploy it as an archive which is like zipping the folder having extentions like war, ear etc.&amp;nbsp; you will see this error, and mostly we prefer to deploy our applications as archive rather than exploded. So, how to fix such an error.&lt;br /&gt;
&lt;blockquote&gt;So, Let&#39;s get started&lt;/blockquote&gt;&lt;blockquote&gt;&lt;blockquote&gt;&lt;b&gt;&lt;span style=&quot;color: red;&quot;&gt;Note:&lt;/span&gt;&lt;/b&gt;&amp;nbsp; The advantage of deploying an application as exploded over archive is the access to the application content is much faster.&lt;/blockquote&gt;&lt;/blockquote&gt;It&#39;s a simple fix. You can fix this problem by approaching it in two ways one is application server level. The other is application level.&lt;br /&gt;
&lt;br /&gt;
&lt;u&gt;&lt;b&gt;Application Server Level&lt;/b&gt;&lt;/u&gt;&lt;br /&gt;
&lt;br /&gt;
Goto Server Admin Console &amp;gt; Domain &amp;gt; Web Application &amp;gt; Archived Real Path Enabled. Enable this option restart the server and Bingo.!!!&lt;br /&gt;
&lt;br /&gt;
It makes an entry into domain config.xml file something like this,&lt;br /&gt;
&lt;br /&gt;
&amp;lt;web-app-container&amp;gt;&lt;br /&gt;
&amp;nbsp;&amp;nbsp;&amp;nbsp; &amp;lt;show-archived-real-path-enabled&amp;gt;true&amp;lt;/show-archived-real-path-enabled&amp;gt;&lt;br /&gt;
&amp;lt;/web-app-container&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&lt;u&gt;&lt;b&gt;Application Level&lt;/b&gt;&lt;/u&gt;&lt;br /&gt;
&lt;br /&gt;
Create a xml file in WEB-INF folder name it weblogic.xml if it&#39;s not there by default. Add the following entry.&lt;br /&gt;
&lt;br /&gt;
&amp;lt;container-descriptor&amp;gt;&lt;br /&gt;
&amp;nbsp;&amp;nbsp;&amp;nbsp; &amp;lt;show-archived-real-path-enabled&amp;gt;true&amp;lt;/show-archived-real-path-enabled&amp;gt;&lt;br /&gt;
&amp;lt;/container-descriptor&amp;gt;&lt;br /&gt;
&lt;br /&gt;
Redeploy your application done.&lt;br /&gt;
&lt;br /&gt;
&lt;b&gt;Hope this Helps! Please write your comments it will help me improve.&lt;/b&gt;&lt;/div&gt;&lt;div class=&quot;blogger-post-footer&quot;&gt;PythonicWay&lt;/div&gt;</content><link rel='replies' type='application/atom+xml' href='http://pythonicway.blogspot.com/feeds/629434458414138027/comments/default' title='Post Comments'/><link rel='replies' type='text/html' href='http://pythonicway.blogspot.com/2011/02/fix-weblogic-servletcontextgetrealpath.html#comment-form' title='0 Comments'/><link rel='edit' type='application/atom+xml' href='http://www.blogger.com/feeds/3886129644493468120/posts/default/629434458414138027'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/3886129644493468120/posts/default/629434458414138027'/><link rel='alternate' type='text/html' href='http://pythonicway.blogspot.com/2011/02/fix-weblogic-servletcontextgetrealpath.html' title='Fix: Weblogic ServletContext.getRealPath() returns null'/><author><name>Unknown</name><email>noreply@blogger.com</email><gd:image rel='http://schemas.google.com/g/2005#thumbnail' width='16' height='16' src='https://img1.blogblog.com/img/b16-rounded.gif'/></author><thr:total>0</thr:total></entry><entry><id>tag:blogger.com,1999:blog-3886129644493468120.post-1416709236212743317</id><published>2011-02-09T19:06:00.000+05:30</published><updated>2011-02-09T19:06:23.445+05:30</updated><category scheme="http://www.blogger.com/atom/ns#" term="classpath issues"/><category scheme="http://www.blogger.com/atom/ns#" term="JSF2.0"/><category scheme="http://www.blogger.com/atom/ns#" term="Weblogic Server"/><title type='text'>JSF2.0: Unable to load JSF2.0/Primefaces jars on Weblogic Server 10.3.2 start up</title><content type='html'>&lt;div dir=&quot;ltr&quot; style=&quot;text-align: left;&quot; trbidi=&quot;on&quot;&gt;I think except for the option to upgrade to a new version or applying a  patchset there is a workaround that i tried and it worked for me.&lt;br /&gt;
&lt;br /&gt;
&lt;u&gt;&lt;b&gt;Problem&lt;/b&gt;&lt;/u&gt;&lt;br /&gt;
It occurs because weblogic 10 is shipped with Mojarra JSF 1.2 and the version that we want to make it work is Mojarra JSF 2.0.&lt;br /&gt;
&lt;br /&gt;
&lt;u&gt;&lt;b&gt;Solution&lt;/b&gt;&lt;/u&gt;&lt;br /&gt;
It&#39;s a simple fix. In weblogic there is a file called commEnv.bat/sh. If  you are running windows edit the bat file, else if you are running  Linux/Mac edit the sh file.&lt;br /&gt;
&lt;br /&gt;
Search for PRE_CLASSPATH or WEBLOGIC_CLASSPATH  and add a complete path  to the jsf-api.jar, jsf-impl.jar before weblogic.jar and if you are  using Primefaces, just append it afterwords. Restart the server, deploy  your application make sure that jsf-api.jar and jsf-impl.jar are there  in the lib folder, but you are now free to remove the primefaces jar as  it is already loaded by weblogic at server start-up otherwise you will  see the same error still your application won&#39;t break.&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;b&gt;&lt;u&gt;Topic Discussed&lt;/u&gt;&lt;/b&gt;&lt;br /&gt;
http://forums.oracle.com/forums/thread.jspa?threadID=1043858&amp;amp;start=30&amp;amp;tstart=0 &lt;br /&gt;
http://www.coderanch.com/t/486434/JSF/java/Unable-load-primefaces-jar-Weblogic&lt;br /&gt;
&lt;br /&gt;
&lt;b&gt;Hope this Helps! Please write your comments it will help me improve.&lt;/b&gt;&lt;/div&gt;&lt;div class=&quot;blogger-post-footer&quot;&gt;PythonicWay&lt;/div&gt;</content><link rel='replies' type='application/atom+xml' href='http://pythonicway.blogspot.com/feeds/1416709236212743317/comments/default' title='Post Comments'/><link rel='replies' type='text/html' href='http://pythonicway.blogspot.com/2011/02/jsf20-unable-to-load-jsf20primefaces.html#comment-form' title='0 Comments'/><link rel='edit' type='application/atom+xml' href='http://www.blogger.com/feeds/3886129644493468120/posts/default/1416709236212743317'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/3886129644493468120/posts/default/1416709236212743317'/><link rel='alternate' type='text/html' href='http://pythonicway.blogspot.com/2011/02/jsf20-unable-to-load-jsf20primefaces.html' title='JSF2.0: Unable to load JSF2.0/Primefaces jars on Weblogic Server 10.3.2 start up'/><author><name>Unknown</name><email>noreply@blogger.com</email><gd:image rel='http://schemas.google.com/g/2005#thumbnail' width='16' height='16' src='https://img1.blogblog.com/img/b16-rounded.gif'/></author><thr:total>0</thr:total></entry><entry><id>tag:blogger.com,1999:blog-3886129644493468120.post-3182585641785706607</id><published>2011-02-08T19:33:00.002+05:30</published><updated>2012-01-04T08:58:25.489+05:30</updated><category scheme="http://www.blogger.com/atom/ns#" term="application"/><category scheme="http://www.blogger.com/atom/ns#" term="Basics"/><category scheme="http://www.blogger.com/atom/ns#" term="Hello Python"/><category scheme="http://www.blogger.com/atom/ns#" term="Python IDE"/><title type='text'>Python Basics: Built-in function Print usage</title><content type='html'>&lt;div dir=&quot;ltr&quot; style=&quot;text-align: left;&quot; trbidi=&quot;on&quot;&gt;
&lt;div dir=&quot;ltr&quot; style=&quot;text-align: left;&quot; trbidi=&quot;on&quot;&gt;
Before embarking on a journey to learn any programming language most people create a sample Hello World application to see how the language works. Today we are going to learn this only with a variation of how you use it&#39;s in-built print function.&lt;br /&gt;
&lt;br /&gt;
So, Let&#39;s get started.&lt;br /&gt;
&lt;blockquote&gt;
I&#39;ll be using vim to write programs and python 3.2 to run it. If you are using windows prefer python IDLE which comes bundled with python.&lt;/blockquote&gt;
&lt;br /&gt;
&lt;u&gt;&lt;b&gt;1. Source Code: Vim&amp;nbsp;&lt;/b&gt;&lt;/u&gt;&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;&lt;/div&gt;
&lt;div dir=&quot;ltr&quot; style=&quot;text-align: left;&quot; trbidi=&quot;on&quot;&gt;
&lt;div class=&quot;separator&quot; style=&quot;clear: both; text-align: center;&quot;&gt;
&lt;a href=&quot;https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEjl_xD0oDaG5vrz92AgJvaBTQbmLAMW5waJ6YzgA-dJhP0gnzvRao7R4wAOKmm4hvMAYkKjJG0X3G5MKQ5wDPyDTwOVZwF_b7u7I45dkqKuR7YiYFLYmdtURTsWdrjXZSWcGs-PMKypJuSP/s1600/source_edited.JPG&quot; imageanchor=&quot;1&quot; style=&quot;clear: left; float: left; margin-bottom: 1em; margin-right: 1em;&quot;&gt;&lt;img border=&quot;0&quot; height=&quot;106&quot; src=&quot;https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEjl_xD0oDaG5vrz92AgJvaBTQbmLAMW5waJ6YzgA-dJhP0gnzvRao7R4wAOKmm4hvMAYkKjJG0X3G5MKQ5wDPyDTwOVZwF_b7u7I45dkqKuR7YiYFLYmdtURTsWdrjXZSWcGs-PMKypJuSP/s320/source_edited.JPG&quot; width=&quot;320&quot; /&gt;&lt;/a&gt;&lt;/div&gt;
&lt;div style=&quot;text-align: left;&quot;&gt;
&lt;br /&gt;&lt;/div&gt;
&lt;div style=&quot;text-align: left;&quot;&gt;
&lt;br /&gt;&lt;/div&gt;
&lt;div style=&quot;text-align: left;&quot;&gt;
&lt;br /&gt;&lt;/div&gt;
&lt;div style=&quot;text-align: left;&quot;&gt;
&lt;br /&gt;&lt;/div&gt;
&lt;div style=&quot;text-align: left;&quot;&gt;
&lt;br /&gt;&lt;/div&gt;
&lt;div style=&quot;text-align: left;&quot;&gt;
&lt;br /&gt;&lt;/div&gt;
&lt;div style=&quot;text-align: left;&quot;&gt;
&lt;/div&gt;
&lt;div style=&quot;text-align: left;&quot;&gt;
&lt;/div&gt;
&lt;div style=&quot;text-align: left;&quot;&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;u&gt;&lt;b&gt;Explanation:&lt;/b&gt;&lt;/u&gt;&lt;/div&gt;
&lt;div style=&quot;text-align: left;&quot;&gt;
&lt;/div&gt;
&lt;div style=&quot;text-align: left;&quot;&gt;
1. The first line of the code is called the shebang line&lt;/div&gt;
&lt;div style=&quot;text-align: left;&quot;&gt;
2. Line 2 is a comment.&lt;/div&gt;
&lt;div style=&quot;text-align: left;&quot;&gt;
3. Line 4 uses the built-in print function to print the string on the standard output on screen.&lt;/div&gt;
&lt;div style=&quot;text-align: left;&quot;&gt;
4. Line 5 uses a variation of the function.&lt;/div&gt;
&lt;div style=&quot;text-align: left;&quot;&gt;
5. Line 7 is a comment&lt;/div&gt;
&lt;div style=&quot;text-align: left;&quot;&gt;
6. Line 9 has nothing special &lt;/div&gt;
&lt;div style=&quot;text-align: left;&quot;&gt;
7. from Line 10 onwards it shows you the variation of how to use the print function.&lt;/div&gt;
&lt;div style=&quot;text-align: left;&quot;&gt;
&lt;/div&gt;
&lt;div style=&quot;text-align: left;&quot;&gt;
Before i explain you line no 10, 11 and 12 i want you to look at the definition of the function itself.&lt;/div&gt;
&lt;blockquote&gt;
&lt;div style=&quot;text-align: left;&quot;&gt;
print([object...][, sep=&#39; &#39;][, end=&#39;\n&#39;][, file=sys.stdout])&lt;/div&gt;
&lt;/blockquote&gt;
&lt;div style=&quot;text-align: left;&quot;&gt;
sep and end keyword arguments take a string and if nothing is given the defaults are taken and for last file keyword takes a file object and how it works is explained in Line 12. You might have noticed the output. It doesn&#39;t print out line 12 on the screen instead it writes that line to a file specified pybuf.txt. Here, open function returns you a file object and it is defined as follows.&lt;/div&gt;
&lt;div style=&quot;text-align: left;&quot;&gt;
&lt;/div&gt;
&lt;blockquote&gt;
&lt;div style=&quot;text-align: left;&quot;&gt;
open(filename, mode)&lt;/div&gt;
&lt;/blockquote&gt;
&lt;div style=&quot;text-align: left;&quot;&gt;
Both of them are strings. I&#39;ll explain open function later in detail except the filename is name of the file to be created if not existed and mode is set to &#39;a&#39; which means append text to the end of a file.&lt;/div&gt;
&lt;div style=&quot;text-align: left;&quot;&gt;
&lt;br /&gt;&lt;/div&gt;
&lt;div style=&quot;text-align: left;&quot;&gt;
&lt;u&gt;&lt;b&gt;2. Output: Python 3.2&lt;/b&gt;&lt;/u&gt;&lt;/div&gt;
&lt;div style=&quot;text-align: left;&quot;&gt;
&lt;u&gt;&lt;b&gt;&lt;br /&gt;
&lt;/b&gt;&lt;/u&gt;&lt;/div&gt;
&lt;div class=&quot;separator&quot; style=&quot;clear: both; text-align: center;&quot;&gt;
&lt;a href=&quot;https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEgXNFz1PBMKOUVqq0xJeiAPF5fBTr-OUHvaKgb27i40M1hY9RxhiY4v-uGW-nwKYyMRtNb0ycvJsuIA-DJmRMVxuwGG49L4TN2nSrc3UF9DgBB9TULONYnFMEaVvd2sVKrnbNHuwo8AhNQm/s1600/output_edited.JPG&quot; imageanchor=&quot;1&quot; style=&quot;clear: left; float: left; margin-bottom: 1em; margin-right: 1em;&quot;&gt;&lt;img border=&quot;0&quot; src=&quot;https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEgXNFz1PBMKOUVqq0xJeiAPF5fBTr-OUHvaKgb27i40M1hY9RxhiY4v-uGW-nwKYyMRtNb0ycvJsuIA-DJmRMVxuwGG49L4TN2nSrc3UF9DgBB9TULONYnFMEaVvd2sVKrnbNHuwo8AhNQm/s1600/output_edited.JPG&quot; /&gt;&lt;/a&gt;&lt;/div&gt;
&lt;div style=&quot;text-align: left;&quot;&gt;
&lt;u&gt;&lt;b&gt;&lt;br /&gt;
&lt;/b&gt;&lt;/u&gt;&lt;/div&gt;
&lt;div style=&quot;text-align: left;&quot;&gt;
&lt;u&gt;&lt;b&gt;&lt;br /&gt;
&lt;/b&gt;&lt;/u&gt;&lt;/div&gt;
&lt;div style=&quot;text-align: left;&quot;&gt;
&lt;br /&gt;&lt;/div&gt;
&lt;div style=&quot;text-align: left;&quot;&gt;
&lt;br /&gt;&lt;/div&gt;
&lt;div style=&quot;text-align: left;&quot;&gt;
&lt;br /&gt;&lt;/div&gt;
&lt;div style=&quot;text-align: left;&quot;&gt;
&lt;br /&gt;
&lt;br /&gt;&lt;/div&gt;
&lt;div style=&quot;text-align: left;&quot;&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;u&gt;&lt;b&gt;3. pybuf.txt file&lt;/b&gt;&lt;/u&gt;&lt;br /&gt;
&lt;br /&gt;&lt;/div&gt;
&lt;div class=&quot;separator&quot; style=&quot;clear: both; text-align: center;&quot;&gt;
&lt;a href=&quot;https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEjFMcSCu0fPNCEZAy7nqjNL30ii88zuTVzpTAagoZQwjpVYA5Sc_pYLgYWAFt4ROyOUuF7yGAuosipQP6eUjZqpmeH-mlpmkkleOU1andWdFxU1JOXn1wTn0s9LdrbIggg6n9ClDtGPxVaz/s1600/extfile_edited.JPG&quot; imageanchor=&quot;1&quot; style=&quot;clear: left; float: left; margin-bottom: 1em; margin-right: 1em;&quot;&gt;&lt;img border=&quot;0&quot; height=&quot;62&quot; src=&quot;https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEjFMcSCu0fPNCEZAy7nqjNL30ii88zuTVzpTAagoZQwjpVYA5Sc_pYLgYWAFt4ROyOUuF7yGAuosipQP6eUjZqpmeH-mlpmkkleOU1andWdFxU1JOXn1wTn0s9LdrbIggg6n9ClDtGPxVaz/s320/extfile_edited.JPG&quot; width=&quot;320&quot; /&gt;&lt;/a&gt;&lt;/div&gt;
&lt;div style=&quot;text-align: left;&quot;&gt;
&lt;br /&gt;&lt;/div&gt;
&lt;div style=&quot;text-align: left;&quot;&gt;
&lt;br /&gt;&lt;/div&gt;
&lt;div style=&quot;text-align: left;&quot;&gt;
&lt;br /&gt;&lt;/div&gt;
&lt;b&gt;&lt;/b&gt;&lt;br /&gt;
&lt;table cellpadding=&quot;0&quot; cellspacing=&quot;0&quot; class=&quot;tr-caption-container&quot; style=&quot;float: left; margin-right: 1em; text-align: left;&quot;&gt;&lt;tbody&gt; &lt;/tbody&gt;&lt;/table&gt;
&lt;table cellpadding=&quot;0&quot; cellspacing=&quot;0&quot; class=&quot;tr-caption-container&quot; style=&quot;float: left; margin-right: 1em; text-align: left;&quot;&gt;&lt;tbody&gt; &lt;/tbody&gt;&lt;/table&gt;
&lt;table cellpadding=&quot;0&quot; cellspacing=&quot;0&quot; class=&quot;tr-caption-container&quot; style=&quot;float: left; margin-right: 1em; text-align: left;&quot;&gt;&lt;tbody&gt; &lt;/tbody&gt;&lt;/table&gt;
&lt;table cellpadding=&quot;0&quot; cellspacing=&quot;0&quot; class=&quot;tr-caption-container&quot; style=&quot;float: left; margin-right: 1em; text-align: left;&quot;&gt;&lt;tbody&gt; &lt;/tbody&gt;&lt;/table&gt;
&lt;table cellpadding=&quot;0&quot; cellspacing=&quot;0&quot; class=&quot;tr-caption-container&quot; style=&quot;float: left; margin-right: 1em; text-align: left;&quot;&gt;&lt;tbody&gt; &lt;/tbody&gt;&lt;/table&gt;
&lt;table cellpadding=&quot;0&quot; cellspacing=&quot;0&quot; class=&quot;tr-caption-container&quot; style=&quot;float: left; margin-right: 1em; text-align: left;&quot;&gt;&lt;tbody&gt; &lt;/tbody&gt;&lt;/table&gt;
&lt;table cellpadding=&quot;0&quot; cellspacing=&quot;0&quot; class=&quot;tr-caption-container&quot; style=&quot;float: left; margin-right: 1em; text-align: left;&quot;&gt;&lt;tbody&gt; &lt;/tbody&gt;&lt;/table&gt;
&lt;table cellpadding=&quot;0&quot; cellspacing=&quot;0&quot; class=&quot;tr-caption-container&quot; style=&quot;float: left; margin-right: 1em; text-align: left;&quot;&gt;&lt;tbody&gt; &lt;/tbody&gt;&lt;/table&gt;
&lt;table cellpadding=&quot;0&quot; cellspacing=&quot;0&quot; class=&quot;tr-caption-container&quot; style=&quot;float: left; margin-right: 1em; text-align: left;&quot;&gt;&lt;tbody&gt; &lt;/tbody&gt;&lt;/table&gt;
&lt;table cellpadding=&quot;0&quot; cellspacing=&quot;0&quot; class=&quot;tr-caption-container&quot; style=&quot;float: left; margin-right: 1em; text-align: left;&quot;&gt;&lt;tbody&gt; &lt;/tbody&gt;&lt;/table&gt;
&lt;table cellpadding=&quot;0&quot; cellspacing=&quot;0&quot; class=&quot;tr-caption-container&quot; style=&quot;float: left; margin-right: 1em; text-align: left;&quot;&gt;&lt;tbody&gt; &lt;/tbody&gt;&lt;/table&gt;
&lt;table cellpadding=&quot;0&quot; cellspacing=&quot;0&quot; class=&quot;tr-caption-container&quot; style=&quot;float: left; margin-right: 1em; text-align: left;&quot;&gt;&lt;tbody&gt; &lt;/tbody&gt;&lt;/table&gt;
&lt;table cellpadding=&quot;0&quot; cellspacing=&quot;0&quot; class=&quot;tr-caption-container&quot; style=&quot;float: left; margin-right: 1em; text-align: left;&quot;&gt;&lt;tbody&gt; &lt;/tbody&gt;&lt;/table&gt;
&lt;table cellpadding=&quot;0&quot; cellspacing=&quot;0&quot; class=&quot;tr-caption-container&quot; style=&quot;float: left; margin-right: 1em; text-align: left;&quot;&gt;&lt;tbody&gt; &lt;/tbody&gt;&lt;/table&gt;
&lt;table cellpadding=&quot;0&quot; cellspacing=&quot;0&quot; class=&quot;tr-caption-container&quot; style=&quot;float: left; margin-right: 1em; text-align: left;&quot;&gt;&lt;tbody&gt; &lt;/tbody&gt;&lt;/table&gt;
&lt;table cellpadding=&quot;0&quot; cellspacing=&quot;0&quot; class=&quot;tr-caption-container&quot; style=&quot;float: left; margin-right: 1em; text-align: left;&quot;&gt;&lt;tbody&gt; &lt;/tbody&gt;&lt;/table&gt;
&lt;table cellpadding=&quot;0&quot; cellspacing=&quot;0&quot; class=&quot;tr-caption-container&quot; style=&quot;float: left; margin-right: 1em; text-align: left;&quot;&gt;&lt;tbody&gt; &lt;/tbody&gt;&lt;/table&gt;
&lt;table cellpadding=&quot;0&quot; cellspacing=&quot;0&quot; class=&quot;tr-caption-container&quot; style=&quot;float: left; margin-right: 1em; text-align: left;&quot;&gt;&lt;tbody&gt; &lt;/tbody&gt;&lt;/table&gt;
&lt;table cellpadding=&quot;0&quot; cellspacing=&quot;0&quot; class=&quot;tr-caption-container&quot; style=&quot;float: left; margin-right: 1em; text-align: left;&quot;&gt;&lt;tbody&gt; &lt;/tbody&gt;&lt;/table&gt;
&lt;table cellpadding=&quot;0&quot; cellspacing=&quot;0&quot; class=&quot;tr-caption-container&quot; style=&quot;float: left; margin-right: 1em; text-align: left;&quot;&gt;&lt;tbody&gt; &lt;/tbody&gt;&lt;/table&gt;
&lt;table cellpadding=&quot;0&quot; cellspacing=&quot;0&quot; class=&quot;tr-caption-container&quot; style=&quot;float: left; margin-right: 1em; text-align: left;&quot;&gt;&lt;tbody&gt; &lt;/tbody&gt;&lt;/table&gt;
&lt;table cellpadding=&quot;0&quot; cellspacing=&quot;0&quot; class=&quot;tr-caption-container&quot; style=&quot;float: left; margin-right: 1em; text-align: left;&quot;&gt;&lt;tbody&gt; &lt;/tbody&gt;&lt;/table&gt;
&lt;table cellpadding=&quot;0&quot; cellspacing=&quot;0&quot; class=&quot;tr-caption-container&quot; style=&quot;float: left; margin-right: 1em; text-align: left;&quot;&gt;&lt;tbody&gt; &lt;/tbody&gt;&lt;/table&gt;
&lt;table cellpadding=&quot;0&quot; cellspacing=&quot;0&quot; class=&quot;tr-caption-container&quot; style=&quot;float: left; margin-right: 1em; text-align: left;&quot;&gt;&lt;tbody&gt; &lt;/tbody&gt;&lt;/table&gt;
&lt;table cellpadding=&quot;0&quot; cellspacing=&quot;0&quot; class=&quot;tr-caption-container&quot; style=&quot;float: left; margin-right: 1em; text-align: left;&quot;&gt;&lt;tbody&gt; &lt;/tbody&gt;&lt;/table&gt;
&lt;table cellpadding=&quot;0&quot; cellspacing=&quot;0&quot; class=&quot;tr-caption-container&quot; style=&quot;float: left; margin-right: 1em; text-align: left;&quot;&gt;&lt;tbody&gt; &lt;/tbody&gt;&lt;/table&gt;
&lt;table cellpadding=&quot;0&quot; cellspacing=&quot;0&quot; class=&quot;tr-caption-container&quot; style=&quot;float: left; margin-right: 1em; text-align: left;&quot;&gt;&lt;tbody&gt; &lt;/tbody&gt;&lt;/table&gt;
&lt;table cellpadding=&quot;0&quot; cellspacing=&quot;0&quot; class=&quot;tr-caption-container&quot; style=&quot;float: left; margin-right: 1em; text-align: left;&quot;&gt;&lt;tbody&gt; &lt;/tbody&gt;&lt;/table&gt;
&lt;table cellpadding=&quot;0&quot; cellspacing=&quot;0&quot; class=&quot;tr-caption-container&quot; style=&quot;float: left; margin-right: 1em; text-align: left;&quot;&gt;&lt;tbody&gt; &lt;/tbody&gt;&lt;/table&gt;
&lt;table cellpadding=&quot;0&quot; cellspacing=&quot;0&quot; class=&quot;tr-caption-container&quot; style=&quot;float: left; margin-right: 1em; text-align: left;&quot;&gt;&lt;tbody&gt; &lt;/tbody&gt;&lt;/table&gt;
&lt;table cellpadding=&quot;0&quot; cellspacing=&quot;0&quot; class=&quot;tr-caption-container&quot; style=&quot;float: left; margin-right: 1em; text-align: left;&quot;&gt;&lt;tbody&gt; &lt;/tbody&gt;&lt;/table&gt;
&lt;table cellpadding=&quot;0&quot; cellspacing=&quot;0&quot; class=&quot;tr-caption-container&quot; style=&quot;float: left; margin-right: 1em; text-align: left;&quot;&gt;&lt;tbody&gt; &lt;/tbody&gt;&lt;/table&gt;
&lt;table cellpadding=&quot;0&quot; cellspacing=&quot;0&quot; class=&quot;tr-caption-container&quot; style=&quot;float: left; margin-right: 1em; text-align: left;&quot;&gt;&lt;tbody&gt; &lt;/tbody&gt;&lt;/table&gt;
&lt;table cellpadding=&quot;0&quot; cellspacing=&quot;0&quot; class=&quot;tr-caption-container&quot; style=&quot;float: left; margin-right: 1em; text-align: left;&quot;&gt;&lt;tbody&gt; &lt;/tbody&gt;&lt;/table&gt;
&lt;table cellpadding=&quot;0&quot; cellspacing=&quot;0&quot; class=&quot;tr-caption-container&quot; style=&quot;float: left; margin-right: 1em; text-align: left;&quot;&gt;&lt;tbody&gt; &lt;/tbody&gt;&lt;/table&gt;
&lt;table cellpadding=&quot;0&quot; cellspacing=&quot;0&quot; class=&quot;tr-caption-container&quot; style=&quot;float: left; margin-right: 1em; text-align: left;&quot;&gt;&lt;tbody&gt; &lt;/tbody&gt;&lt;/table&gt;
&lt;table cellpadding=&quot;0&quot; cellspacing=&quot;0&quot; class=&quot;tr-caption-container&quot; style=&quot;float: left; margin-right: 1em; text-align: left;&quot;&gt;&lt;tbody&gt; &lt;/tbody&gt;&lt;/table&gt;
&lt;table cellpadding=&quot;0&quot; cellspacing=&quot;0&quot; class=&quot;tr-caption-container&quot; style=&quot;float: left; margin-right: 1em; text-align: left;&quot;&gt;&lt;tbody&gt; &lt;/tbody&gt;&lt;/table&gt;
&lt;table cellpadding=&quot;0&quot; cellspacing=&quot;0&quot; class=&quot;tr-caption-container&quot; style=&quot;float: left; margin-right: 1em; text-align: left;&quot;&gt;&lt;tbody&gt; &lt;/tbody&gt;&lt;/table&gt;
&lt;table cellpadding=&quot;0&quot; cellspacing=&quot;0&quot; class=&quot;tr-caption-container&quot; style=&quot;float: left; margin-right: 1em; text-align: left;&quot;&gt;&lt;tbody&gt; &lt;/tbody&gt;&lt;/table&gt;
&lt;table cellpadding=&quot;0&quot; cellspacing=&quot;0&quot; class=&quot;tr-caption-container&quot; style=&quot;float: left; margin-right: 1em; text-align: left;&quot;&gt;&lt;tbody&gt; &lt;/tbody&gt;&lt;/table&gt;
&lt;/div&gt;
&lt;/div&gt;&lt;div class=&quot;blogger-post-footer&quot;&gt;PythonicWay&lt;/div&gt;</content><link rel='replies' type='application/atom+xml' href='http://pythonicway.blogspot.com/feeds/3182585641785706607/comments/default' title='Post Comments'/><link rel='replies' type='text/html' href='http://pythonicway.blogspot.com/2011/02/python-basics-built-in-function-print.html#comment-form' title='0 Comments'/><link rel='edit' type='application/atom+xml' href='http://www.blogger.com/feeds/3886129644493468120/posts/default/3182585641785706607'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/3886129644493468120/posts/default/3182585641785706607'/><link rel='alternate' type='text/html' href='http://pythonicway.blogspot.com/2011/02/python-basics-built-in-function-print.html' title='Python Basics: Built-in function Print usage'/><author><name>Unknown</name><email>noreply@blogger.com</email><gd:image rel='http://schemas.google.com/g/2005#thumbnail' width='16' height='16' src='https://img1.blogblog.com/img/b16-rounded.gif'/></author><media:thumbnail xmlns:media="http://search.yahoo.com/mrss/" url="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEjl_xD0oDaG5vrz92AgJvaBTQbmLAMW5waJ6YzgA-dJhP0gnzvRao7R4wAOKmm4hvMAYkKjJG0X3G5MKQ5wDPyDTwOVZwF_b7u7I45dkqKuR7YiYFLYmdtURTsWdrjXZSWcGs-PMKypJuSP/s72-c/source_edited.JPG" height="72" width="72"/><thr:total>0</thr:total></entry><entry><id>tag:blogger.com,1999:blog-3886129644493468120.post-4495806259203890645</id><published>2011-02-07T13:45:00.008+05:30</published><updated>2011-06-16T11:58:12.974+05:30</updated><category scheme="http://www.blogger.com/atom/ns#" term="Basics"/><category scheme="http://www.blogger.com/atom/ns#" term="Installation"/><category scheme="http://www.blogger.com/atom/ns#" term="Linux"/><category scheme="http://www.blogger.com/atom/ns#" term="Python"/><category scheme="http://www.blogger.com/atom/ns#" term="Python3.2"/><category scheme="http://www.blogger.com/atom/ns#" term="Ubuntu"/><title type='text'>Install Python 3.2 on Linux [Ubuntu]</title><content type='html'>&lt;div dir=&quot;ltr&quot; style=&quot;text-align: left;&quot; trbidi=&quot;on&quot;&gt;First of all, I don&#39;t see a point to show you how to install Python on Windows. It&#39;s dead easy download the installer from &lt;a href=&quot;http://python.org/&quot;&gt;python.org&lt;/a&gt; and in few clicks you will have python up and running. Installing Python on Linux is bit different and requires some pre-work to be done.&lt;br /&gt;
&lt;br /&gt;
So Let&#39;s get started.&lt;br /&gt;
&lt;blockquote&gt;&lt;b&gt;&lt;span style=&quot;color: red;&quot;&gt;Note:&lt;/span&gt;&lt;/b&gt; Every Modern Linux had a python Installed. You can verify this by opening your Terminal and typing python. It will open the python shell for you. &lt;b&gt;Do not remove the installed version. &lt;/b&gt;&lt;/blockquote&gt;&lt;b&gt;&lt;u&gt;Step 1: Pre-requisites for Ubuntu&lt;/u&gt;&lt;/b&gt;&lt;br /&gt;
&lt;br /&gt;
To be able to compile Python Source, you will need few packages. Fire up the terminal and execute this command&lt;br /&gt;
&lt;blockquote&gt;&lt;b&gt;sudo apt-get install build-essential libncursesw5-dev libreadline5-dev libssl-dev libgdbm-dev libc6-dev libsqlite3-dev tk-dev&lt;/b&gt;&lt;/blockquote&gt;It will take some time to finish depending upon your bandwidth. :)&lt;br /&gt;
&lt;br /&gt;
&lt;u&gt;&lt;b&gt;Step 2: Downloading Python Sources and extracting them on your disk&lt;/b&gt;&lt;/u&gt;&lt;br /&gt;
&lt;br /&gt;
Download a tarball from the python site here is a &lt;a href=&quot;http://www.python.org/ftp/python/3.2/Python-3.2.tgz&quot;&gt;direct link&lt;/a&gt;. Once, the download is completed you can extract the files by  doing a right-click on the file and then clicking the extract option &lt;br /&gt;
&lt;div style=&quot;text-align: center;&quot;&gt;&lt;b&gt;OR&lt;/b&gt;&lt;/div&gt;Fire up the terminal and execute this command which will download the file first and extract it on the disk.&lt;br /&gt;
&lt;blockquote&gt;&lt;b&gt;wget http://www.python.org/ftp/python/3.2/Python-3.2rc2.tgz &amp;amp;&amp;amp; tar -xvf Python-3.2rc2.tgz&lt;/b&gt;&lt;/blockquote&gt;&lt;u&gt;&lt;b&gt;Step 3: Installing Python 3.2&lt;/b&gt;&lt;/u&gt;&lt;br /&gt;
&lt;u&gt;&lt;br /&gt;
&lt;/u&gt;&lt;b&gt;Fire up a new Terminal and execute the following commands &lt;/b&gt;&lt;span id=&quot;topstuff&quot; style=&quot;visibility: visible;&quot;&gt;&lt;b&gt;individually&lt;/b&gt;&lt;/span&gt;&lt;b&gt;.&lt;/b&gt;&lt;br /&gt;
&lt;br /&gt;
&lt;b&gt;1.&amp;nbsp;&amp;nbsp; ./configure&lt;/b&gt;&lt;br /&gt;
&lt;b&gt;2.&amp;nbsp;&amp;nbsp; make&lt;/b&gt;&lt;br /&gt;
&lt;b&gt;3.&amp;nbsp; sudo make altinstall&lt;/b&gt;&lt;br /&gt;
&lt;br /&gt;
&lt;b&gt;Hope this Helps! Please write your comments it will help me improve.&lt;/b&gt;&lt;/div&gt;&lt;div class=&quot;blogger-post-footer&quot;&gt;PythonicWay&lt;/div&gt;</content><link rel='replies' type='application/atom+xml' href='http://pythonicway.blogspot.com/feeds/4495806259203890645/comments/default' title='Post Comments'/><link rel='replies' type='text/html' href='http://pythonicway.blogspot.com/2011/02/install-python-32-on-linux-ubuntu.html#comment-form' title='60 Comments'/><link rel='edit' type='application/atom+xml' href='http://www.blogger.com/feeds/3886129644493468120/posts/default/4495806259203890645'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/3886129644493468120/posts/default/4495806259203890645'/><link rel='alternate' type='text/html' href='http://pythonicway.blogspot.com/2011/02/install-python-32-on-linux-ubuntu.html' title='Install Python 3.2 on Linux [Ubuntu]'/><author><name>Unknown</name><email>noreply@blogger.com</email><gd:image rel='http://schemas.google.com/g/2005#thumbnail' width='16' height='16' src='https://img1.blogblog.com/img/b16-rounded.gif'/></author><thr:total>60</thr:total></entry></feed>