{"id":441,"date":"2014-03-17T10:13:53","date_gmt":"2014-03-17T10:13:53","guid":{"rendered":"http:\/\/codethataint.com\/blog\/?p=441"},"modified":"2014-03-26T06:33:11","modified_gmt":"2014-03-26T06:33:11","slug":"jython-basics","status":"publish","type":"post","link":"https:\/\/codethataint.com\/blog\/jython-basics\/","title":{"rendered":"Jython Basics"},"content":{"rendered":"<p>Below are the code sample which shows how to carry out basic tasks in Jython.The Files should be shared as .py extension if your are using eclipse.To know abount configuring jython in eclipse follow the<br \/>\n<a href=\"http:\/\/www.youtube.com\/watch?v=eSkNj2ACTRQ\" title=\"Configuring Jython eclipse\">Link<\/a><\/p>\n<p><em>Printing a Message in Console<\/em><\/p>\n<pre class=\"brush: java; title: ; notranslate\" title=\"\">\r\n  print 1 + 1\r\n  print &quot;Hello&quot; + &quot; World &quot;\r\n  print &quot;Hello Jython &quot;\r\n  print &quot;Jython &quot;, &quot;Scripting&quot;\r\n<\/pre>\n<p><em>Simple Jython Function that Takes Argument and Print Values<\/em><\/p>\n<pre class=\"brush: java; title: ; notranslate\" title=\"\">\r\ndef displayName(x):\r\n print x \r\n \r\ndisplayName(&quot;Mugil&quot;)\r\n<\/pre>\n<p><em>Jython Function which Calculates the Factorial of a  Number<\/em><\/p>\n<pre class=\"brush: java; title: ; notranslate\" title=\"\">\r\ndef factorial(x):\r\n if x&lt;=1 : \r\n  return 1    \r\n return x * factorial(x-1)\r\n \r\nprint factorial(3)\r\n<\/pre>\n<p><em>Function which compares Two Strings in If Condition<\/em><\/p>\n<pre class=\"brush: java; title: ; notranslate\" title=\"\">\r\ndef compareName(FirstName, LastName):\r\n if FirstName == LastName:\r\n  print &quot;They are Equal&quot;\r\n else:\r\n  print &quot;They are Not Equal&quot;  \r\n   \r\n   \r\ncompareName(&quot;Jython&quot;, &quot;Jython&quot;)\r\n<\/pre>\n<p><strong>Conditional Operators<\/strong><br \/>\n<em>Function which Perform AND, OR and Not Ops<\/em><\/p>\n<pre class=\"brush: java; title: ; notranslate\" title=\"\">\r\ndef BoolOps(pOne, pTwo): \r\n if pOne and pTwo:\r\n  print &quot;They are Equal&quot;\r\n else:\r\n  print &quot;They are Not Equal&quot; \r\n  \r\nBoolOps(1,0)\r\n<\/pre>\n<p><img loading=\"lazy\" decoding=\"async\" src=\"http:\/\/codethataint.com\/blog\/wp-content\/uploads\/2014\/03\/JythonOps-580x477.png\" alt=\"Jython Conditional Operators\" height=\"580\" width=\"477\"\/><\/p>\n<p>Jython Supports Three Numeric Values as Below<\/p>\n<ul>\n<li>Integers<\/li>\n<li>Long<\/li>\n<li>Floating Point<\/li>\n<\/ul>\n<p><img loading=\"lazy\" decoding=\"async\" src=\"http:\/\/codethataint.com\/blog\/wp-content\/uploads\/2014\/03\/MathOps-580x502.png\" alt=\"\" height=\"502\" width=\"580\"\/><\/p>\n<p><em>Array from Delimited String and Looping through It<\/em><\/p>\n<pre class=\"brush: java; title: ; notranslate\" title=\"\">\r\nNames = &quot;A, B, C, D, E&quot;\r\n\r\narrNames = Names.split(&quot;,&quot;)\r\n\r\nfor x in range(len(arrNames)):\r\n print arrNames&#x5B;x]\r\n<\/pre>\n<p><em>Array Function<\/em><\/p>\n<pre class=\"brush: java; title: ; notranslate\" title=\"\">\r\nNames = &quot;A,B,C,D,E,F,G,H,I,J,K,L,M&quot;\r\n\r\narrNames = Names.split(&quot;,&quot;)\r\n\r\n#B\r\nprint arrNames&#x5B;1]\r\n\r\n#&#x5B;'B']\r\nprint arrNames&#x5B;1:2]\r\n\r\n#&#x5B;'B', 'C', 'D', 'E', 'F', 'G', 'H', 'I', 'J', 'K', 'L', 'M']\r\nprint arrNames&#x5B;1:]\r\n\r\n#&#x5B;'A', 'B', 'C', 'D', 'E', 'F']\r\nprint arrNames&#x5B;:6]\r\n\r\n#&#x5B;'B', 'C', 'D', 'E']\r\nprint arrNames&#x5B;1:5]\r\n\r\n#&#x5B;'H', 'I', 'J']\r\nprint arrNames&#x5B;-6:-3]\r\n\r\n#&#x5B;'A', 'B', 'C', 'D', 'E', 'F', 'G', 'H', 'I', 'J', 'K', 'L', 'M']\r\nprint arrNames&#x5B;:]\r\n\r\n#&#x5B;'A', 'C', 'E', 'G', 'I', 'K', 'M']\r\nprint arrNames&#x5B;::2]\r\n<\/pre>\n<p><em>Concatenating Two Arrays together<\/em><\/p>\n<pre class=\"brush: java; title: ; notranslate\" title=\"\">\r\nNames1 = &quot;A,B,C&quot;\r\nNames2 = &quot;D, E, F&quot;\r\n\r\narrNames1 = Names1.split(&quot;,&quot;)\r\narrNames2 = Names2.split(&quot;,&quot;)\r\n\r\narrNames = arrNames1 + arrNames2\r\n\r\nfor i in range(len(arrNames)):\r\n print arrNames&#x5B;i]\r\n<\/pre>\n<p><img loading=\"lazy\" decoding=\"async\" src=\"http:\/\/codethataint.com\/blog\/wp-content\/uploads\/2014\/03\/MathOps1.png\" alt=\"\" height=\"241\" width=\"668\"\/><\/p>\n","protected":false},"excerpt":{"rendered":"<p>Below are the code sample which shows how to carry out basic tasks in Jython.The Files should be shared as .py extension if your are using eclipse.To know abount configuring jython in eclipse follow the Link Printing a Message in Console print 1 + 1 print &quot;Hello&quot; + &quot; World &quot; print &quot;Hello Jython &quot;&hellip; <a href=\"https:\/\/codethataint.com\/blog\/jython-basics\/\">Continue reading <span class=\"meta-nav\">&rarr;<\/span><\/a><\/p>\n","protected":false},"author":1,"featured_media":0,"comment_status":"closed","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[68],"tags":[],"class_list":["post-441","post","type-post","status-publish","format-standard","hentry","category-jython"],"_links":{"self":[{"href":"https:\/\/codethataint.com\/blog\/wp-json\/wp\/v2\/posts\/441","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/codethataint.com\/blog\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/codethataint.com\/blog\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/codethataint.com\/blog\/wp-json\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/codethataint.com\/blog\/wp-json\/wp\/v2\/comments?post=441"}],"version-history":[{"count":18,"href":"https:\/\/codethataint.com\/blog\/wp-json\/wp\/v2\/posts\/441\/revisions"}],"predecessor-version":[{"id":471,"href":"https:\/\/codethataint.com\/blog\/wp-json\/wp\/v2\/posts\/441\/revisions\/471"}],"wp:attachment":[{"href":"https:\/\/codethataint.com\/blog\/wp-json\/wp\/v2\/media?parent=441"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/codethataint.com\/blog\/wp-json\/wp\/v2\/categories?post=441"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/codethataint.com\/blog\/wp-json\/wp\/v2\/tags?post=441"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}