<?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: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-27252087</id><updated>2011-07-08T09:30:32.068+05:30</updated><category term='Command'/><category term='C++'/><category term='DML'/><category term='Database'/><category term='Linux'/><category term='C'/><category term='Command Prompt'/><category term='Pass-by-value'/><category term='Files'/><category term='Runtime'/><category term='Tips'/><category term='Efficiency'/><category term='Windows'/><category term='pass-by-reference'/><category term='Exceptions'/><category term='Java'/><category term='Services'/><category term='ShellScript'/><category term='OS'/><title type='text'>teknicallyspeaking</title><subtitle type='html'>discussing some technical aspects covering tools, frameworks, technologies etc (the areas where i m involved and getting experienced) - feel free to discuss!</subtitle><link rel='http://schemas.google.com/g/2005#feed' type='application/atom+xml' href='http://teknicallyspeaking.blogspot.com/feeds/posts/default'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/27252087/posts/default?max-results=100'/><link rel='alternate' type='text/html' href='http://teknicallyspeaking.blogspot.com/'/><link rel='hub' href='http://pubsubhubbub.appspot.com/'/><author><name>Raghavan alias Saravanan M</name><uri>http://www.blogger.com/profile/17770791475348776850</uri><email>noreply@blogger.com</email><gd:image rel='http://schemas.google.com/g/2005#thumbnail' width='16' height='16' src='http://img2.blogblog.com/img/b16-rounded.gif'/></author><generator version='7.00' uri='http://www.blogger.com'>Blogger</generator><openSearch:totalResults>14</openSearch:totalResults><openSearch:startIndex>1</openSearch:startIndex><openSearch:itemsPerPage>100</openSearch:itemsPerPage><entry><id>tag:blogger.com,1999:blog-27252087.post-8844120496807361333</id><published>2009-09-18T20:56:00.004+05:30</published><updated>2009-09-18T21:09:28.460+05:30</updated><category scheme='http://www.blogger.com/atom/ns#' term='Java'/><category scheme='http://www.blogger.com/atom/ns#' term='Command'/><category scheme='http://www.blogger.com/atom/ns#' term='Runtime'/><title type='text'>Multiple commands execution via runtime.exec() in Java</title><content type='html'>&lt;span style="font-family:trebuchet ms;"&gt;  The situation insists you to issue more than one command (native or external) through Java Runtime Environment via (&lt;span style="color: rgb(0, 102, 0);font-family:courier new;" &gt;Runtime.getRuntime().exec("Cmd")&lt;/span&gt;).&lt;/span&gt;&lt;br /&gt;&lt;br /&gt;&lt;span style="font-family:trebuchet ms;"&gt; Ideally speaking, there has to be a way to separate/distinguish the commands from one another.&lt;/span&gt;&lt;br /&gt;&lt;br /&gt;&lt;span style="font-family:trebuchet ms;"&gt;  Few search results in Google suggested to use a &lt;span style="font-style: italic;"&gt;semicolon &lt;/span&gt;in between the commands as 'cmd1;cmd2' in exec() method. &lt;/span&gt;&lt;br /&gt;&lt;br /&gt;&lt;span style="font-family:trebuchet ms;"&gt;   I tried the same way but it did NOT work out. During my trial-and-effort, the &lt;span style="font-weight: bold;"&gt;white space character did the trick :)&lt;/span&gt;&lt;/span&gt;&lt;br /&gt;&lt;br /&gt;&lt;span style="color: rgb(0, 102, 0);font-family:courier new;" &gt;Runtime.getRuntime.exec("pwd date");&lt;/span&gt;&lt;br /&gt;&lt;br /&gt;&lt;span style="font-family:trebuchet ms;"&gt;    But it did work in Unix flavours but &lt;span style="font-weight: bold; color: rgb(153, 0, 0);"&gt;NOT in windows&lt;/span&gt; :( and i am still &lt;/span&gt;&lt;span style="font-family:trebuchet ms;"&gt;finding out a way to resolve.&lt;br /&gt;&lt;br /&gt;&lt;/span&gt;&lt;span style="font-family:trebuchet ms;"&gt;Hope to get it resolved soon.. &lt;/span&gt;&lt;br /&gt;&lt;br /&gt;&lt;span style="font-family:trebuchet ms;"&gt;Cheers...&lt;br /&gt;&lt;br /&gt;&lt;/span&gt;&lt;div class="blogger-post-footer"&gt;&lt;img width='1' height='1' src='https://blogger.googleusercontent.com/tracker/27252087-8844120496807361333?l=teknicallyspeaking.blogspot.com' alt='' /&gt;&lt;/div&gt;</content><link rel='replies' type='application/atom+xml' href='http://teknicallyspeaking.blogspot.com/feeds/8844120496807361333/comments/default' title='Post Comments'/><link rel='replies' type='text/html' href='http://www.blogger.com/comment.g?blogID=27252087&amp;postID=8844120496807361333' title='0 Comments'/><link rel='edit' type='application/atom+xml' href='http://www.blogger.com/feeds/27252087/posts/default/8844120496807361333'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/27252087/posts/default/8844120496807361333'/><link rel='alternate' type='text/html' href='http://teknicallyspeaking.blogspot.com/2009/09/multiple-commands-execution-via.html' title='Multiple commands execution via runtime.exec() in Java'/><author><name>Raghavan alias Saravanan M</name><uri>http://www.blogger.com/profile/17770791475348776850</uri><email>noreply@blogger.com</email><gd:image rel='http://schemas.google.com/g/2005#thumbnail' width='16' height='16' src='http://img2.blogblog.com/img/b16-rounded.gif'/></author><thr:total>0</thr:total></entry><entry><id>tag:blogger.com,1999:blog-27252087.post-1160379406791318025</id><published>2008-11-06T16:59:00.003+05:30</published><updated>2008-11-06T17:06:05.658+05:30</updated><category scheme='http://www.blogger.com/atom/ns#' term='Java'/><category scheme='http://www.blogger.com/atom/ns#' term='Tips'/><category scheme='http://www.blogger.com/atom/ns#' term='Exceptions'/><title type='text'>java.io.UnsupportedEncodingException: Cp850</title><content type='html'>&lt;span style="font-family: trebuchet ms;"&gt;Wow.. A nice exception with which I learnt and found a new thing yesterday.&lt;/span&gt;&lt;br /&gt;&lt;br /&gt;&lt;span style="font-family: trebuchet ms;"&gt;As being asked my one of my colleagues as she was facing this error soon after she launched the application in IE (the browser, Internet Explorer). It was a Struts based application and We digged around all the possibilities by looking at the flow to find out where the encoding has been specified. &lt;/span&gt;&lt;br /&gt;&lt;br /&gt;&lt;span style="font-family: trebuchet ms;"&gt;I was sure that it has to deal with the &lt;span style="font-style: italic;"&gt;encoding settings at the client side&lt;/span&gt; (obviously thats what the &lt;/span&gt;&lt;span style="font-style: italic; font-family: trebuchet ms;"&gt;meaningful &lt;/span&gt;&lt;span style="font-family: trebuchet ms;"&gt;Exception says! lol..). The research continued with applicationResources.properties of struts, other application specific properties file, web.xml (to specify the encoding if any) etc., But no luck!!&lt;/span&gt;&lt;br /&gt;&lt;br /&gt;&lt;span style="font-family: trebuchet ms;"&gt;The entire stack trace is below (fyi).&lt;/span&gt;&lt;br /&gt;&lt;br /&gt;&lt;span style="font-family: courier new; color: rgb(0, 102, 0);"&gt;&lt;span style="font-weight: bold;"&gt;java.io.UnsupportedEncodingException:&lt;/span&gt; Cp850&lt;/span&gt;&lt;br /&gt;&lt;span style="font-family: courier new; color: rgb(0, 102, 0);"&gt;    sun.io.Converters.getConverterClass(Unknown Source)&lt;/span&gt;&lt;br /&gt;&lt;span style="font-family: courier new; color: rgb(0, 102, 0);"&gt;    sun.io.Converters.newConverter(Unknown Source)&lt;/span&gt;&lt;br /&gt;&lt;span style="font-family: courier new; color: rgb(0, 102, 0);"&gt;    sun.io.ByteToCharConverter.getConverter(Unknown Source)&lt;/span&gt;&lt;br /&gt;&lt;span style="font-family: courier new; color: rgb(0, 102, 0);"&gt;    java.lang.StringCoding.decode(Unknown Source)&lt;/span&gt;&lt;br /&gt;&lt;span style="font-family: courier new; color: rgb(0, 102, 0);"&gt;    java.lang.String.&lt;init&gt;(Unknown Source)&lt;/span&gt;&lt;br /&gt;&lt;span style="font-family: courier new; color: rgb(0, 102, 0);"&gt;    java.lang.String.&lt;init&gt;(Unknown Source)&lt;/span&gt;&lt;br /&gt;&lt;span style="font-family: courier new;"&gt;...... &lt;span style="color: rgb(153, 0, 0);font-size:85%;" &gt;&lt;span style="font-family: verdana;"&gt;[here the application specific code goes -- PRIVACY and CONFIDENTIALITY :)]&lt;/span&gt;&lt;/span&gt;&lt;/span&gt;&lt;br /&gt;&lt;br /&gt;&lt;span style="font-family: trebuchet ms;"&gt; Well, she found out the solution with the googling that the "&lt;/span&gt;&lt;span style="font-weight: bold; font-family: trebuchet ms;"&gt;Issue was with the browser (IE 7)&lt;/span&gt;&lt;span style="font-family: trebuchet ms;"&gt; " and it was a bug in it. She got the application up and running in IE 6 :) Cool. &lt;/span&gt;&lt;br /&gt;&lt;br /&gt;&lt;span style="font-family: trebuchet ms;"&gt;  Thought of posting it here so that it may be useful for others whoever faces this issue :).&lt;/span&gt;&lt;div class="blogger-post-footer"&gt;&lt;img width='1' height='1' src='https://blogger.googleusercontent.com/tracker/27252087-1160379406791318025?l=teknicallyspeaking.blogspot.com' alt='' /&gt;&lt;/div&gt;</content><link rel='replies' type='application/atom+xml' href='http://teknicallyspeaking.blogspot.com/feeds/1160379406791318025/comments/default' title='Post Comments'/><link rel='replies' type='text/html' href='http://www.blogger.com/comment.g?blogID=27252087&amp;postID=1160379406791318025' title='0 Comments'/><link rel='edit' type='application/atom+xml' href='http://www.blogger.com/feeds/27252087/posts/default/1160379406791318025'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/27252087/posts/default/1160379406791318025'/><link rel='alternate' type='text/html' href='http://teknicallyspeaking.blogspot.com/2008/11/javaiounsupportedencodingexception.html' title='java.io.UnsupportedEncodingException: Cp850'/><author><name>Raghavan alias Saravanan M</name><uri>http://www.blogger.com/profile/17770791475348776850</uri><email>noreply@blogger.com</email><gd:image rel='http://schemas.google.com/g/2005#thumbnail' width='16' height='16' src='http://img2.blogblog.com/img/b16-rounded.gif'/></author><thr:total>0</thr:total></entry><entry><id>tag:blogger.com,1999:blog-27252087.post-1629142226270663590</id><published>2008-09-08T22:04:00.004+05:30</published><updated>2008-09-08T22:24:00.121+05:30</updated><category scheme='http://www.blogger.com/atom/ns#' term='OS'/><category scheme='http://www.blogger.com/atom/ns#' term='Tips'/><category scheme='http://www.blogger.com/atom/ns#' term='Linux'/><category scheme='http://www.blogger.com/atom/ns#' term='ShellScript'/><title type='text'>Editing the shell script in Windows OS</title><content type='html'>&lt;span style="font-family: trebuchet ms;"&gt;Are you one among them who happened to edit the shell script in Windows OS? You may have various reasons to do that. &lt;/span&gt;&lt;br /&gt;&lt;br /&gt;&lt;span style="font-family: trebuchet ms;"&gt;You should have got the script working very well in the appropriate linux (or any other flavour) box. But just before doing the final operation (be it checking it into CVS (version control system) or sending to the client waiting at onsite) you might have thought of giving a final/finishing touch like adding some documentation etc.,&lt;/span&gt;&lt;br /&gt;&lt;br /&gt;&lt;span style="font-family: trebuchet ms;"&gt;Are you asking, "&lt;span style="font-style: italic; color: rgb(0, 153, 0);"&gt;wats up?&lt;/span&gt;" or "&lt;span style="font-style: italic; color: rgb(0, 102, 0);"&gt;what's a big deal.. huh?&lt;/span&gt;". Wait a minute. All is fine until you execute the script back in the linux box again.&lt;br /&gt;&lt;br /&gt;&lt;span style="font-family: trebuchet ms;"&gt;Boooom.. The linux OS spits out an error message saying that "&lt;/span&gt;&lt;span style="font-weight: bold; color: rgb(255, 0, 0); font-family: trebuchet ms;"&gt;/bin/bash^M: bad interpreter: no such file or directory&lt;/span&gt;&lt;span style="font-family: trebuchet ms;"&gt;"&lt;/span&gt;. What had happened? &lt;/span&gt;&lt;span style="font-style: italic; font-family: trebuchet ms;"&gt;Wondering..? Surprised? Shocked rather??&lt;/span&gt;&lt;br /&gt;&lt;br /&gt;&lt;span style="font-family: trebuchet ms;"&gt;Well, here it goes. &lt;span style="font-style: italic;"&gt;The way the Windows OS deals with the file saving option is quite different than that of Linux OS. Once you are done with the so called final/finishing touch and when you save the file, some control characters are getting added to the shellscript (.sh file)&lt;/span&gt;. That's what the culprit is and hence the error when executing it again in linux. The Bash Shell is unable to deal with such special character ('&lt;span style="font-style: italic; font-weight: bold;"&gt;Control M&lt;/span&gt;' -- is referred as "&lt;span style="font-weight: bold;"&gt;^M&lt;/span&gt;"). &lt;/span&gt;&lt;br /&gt;&lt;br /&gt;&lt;span style="font-family: trebuchet ms;"&gt;It is assumed that &lt;span style="font-style: italic;"&gt;Bash &lt;/span&gt;is the default and widely used Shell. &lt;span style="font-style: italic; color: rgb(102, 0, 0);"&gt;The shell being used and the actual error message might vary as per your system's default shell and the way it is customized.&lt;/span&gt;&lt;/span&gt;&lt;br /&gt;&lt;br /&gt;&lt;span style="font-weight: bold; font-family: trebuchet ms;"&gt;What and Where is the rescue?&lt;/span&gt;&lt;br /&gt;&lt;br /&gt;&lt;span style="font-family: trebuchet ms;"&gt;There has to be a way. Isn't it? Yes, of course. There are two options.&lt;br /&gt;&lt;br /&gt;(1) You can open the file in Linux OS (using your favorite editor like &lt;/span&gt;&lt;span style="font-style: italic; font-family: trebuchet ms;"&gt;vi, emacs &lt;/span&gt;&lt;span style="font-family: trebuchet ms;"&gt;etc.,) and can delete such characters what you find at the end. I am not very sure of this as to what extent those characters are explicitly visible to the end user.&lt;/span&gt;&lt;br /&gt;&lt;br /&gt;&lt;span style="font-family: trebuchet ms;"&gt;(2) But the other excellent alternative is to use the '&lt;span style="font-style: italic;"&gt;dos2unix&lt;/span&gt;' command wherein the usage goes as follows.&lt;/span&gt;&lt;br /&gt;&lt;br /&gt;&lt;span style="font-family: trebuchet ms;"&gt;    &lt;span style="font-weight: bold; font-style: italic; color: rgb(0, 0, 153);"&gt;'dos2unix &lt;filename&gt;' &lt;/span&gt;&lt;span style="font-style: italic; color: rgb(0, 0, 153);"&gt;[eg., dos2unix myShellScript.sh]&lt;/span&gt;&lt;/span&gt;&lt;br /&gt;&lt;br /&gt;&lt;span style="font-family: trebuchet ms;"&gt;This &lt;span style="font-style: italic;"&gt;do2unix command converts the file in the DOS (for Microsoft environment) to the Unix properitary format&lt;/span&gt;. While doing so, it removes the special/control characters and it ultimately cleans the file to be used in Linux versions :).&lt;/span&gt;&lt;br /&gt;&lt;br /&gt;&lt;span style="font-size:85%;"&gt;&lt;span style="font-family: verdana;"&gt;&lt;span style="color: rgb(0, 153, 0); font-weight: bold;"&gt;Note/Word of Caution:&lt;/span&gt; &lt;span style="color: rgb(255, 0, 0);"&gt;Never edit the Linux related files in non-linux OS (Windows)! :)&lt;/span&gt;&lt;/span&gt;&lt;/span&gt;&lt;br /&gt;&lt;br /&gt;&lt;span style="font-family: trebuchet ms;"&gt;Hope this helps to solve the tactics and saves you from the critical moment!&lt;/span&gt;&lt;br /&gt;&lt;span style="font-family: trebuchet ms;"&gt;&lt;/span&gt;&lt;div class="blogger-post-footer"&gt;&lt;img width='1' height='1' src='https://blogger.googleusercontent.com/tracker/27252087-1629142226270663590?l=teknicallyspeaking.blogspot.com' alt='' /&gt;&lt;/div&gt;</content><link rel='replies' type='application/atom+xml' href='http://teknicallyspeaking.blogspot.com/feeds/1629142226270663590/comments/default' title='Post Comments'/><link rel='replies' type='text/html' href='http://www.blogger.com/comment.g?blogID=27252087&amp;postID=1629142226270663590' title='0 Comments'/><link rel='edit' type='application/atom+xml' href='http://www.blogger.com/feeds/27252087/posts/default/1629142226270663590'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/27252087/posts/default/1629142226270663590'/><link rel='alternate' type='text/html' href='http://teknicallyspeaking.blogspot.com/2008/09/editing-shell-script-in-windows-os.html' title='Editing the shell script in Windows OS'/><author><name>Raghavan alias Saravanan M</name><uri>http://www.blogger.com/profile/17770791475348776850</uri><email>noreply@blogger.com</email><gd:image rel='http://schemas.google.com/g/2005#thumbnail' width='16' height='16' src='http://img2.blogblog.com/img/b16-rounded.gif'/></author><thr:total>0</thr:total></entry><entry><id>tag:blogger.com,1999:blog-27252087.post-5796691315890013146</id><published>2008-03-09T17:44:00.005+05:30</published><updated>2008-03-09T19:39:24.927+05:30</updated><category scheme='http://www.blogger.com/atom/ns#' term='OS'/><category scheme='http://www.blogger.com/atom/ns#' term='Java'/><category scheme='http://www.blogger.com/atom/ns#' term='Command'/><category scheme='http://www.blogger.com/atom/ns#' term='Windows'/><category scheme='http://www.blogger.com/atom/ns#' term='Services'/><title type='text'>dealing with windows services in java</title><content type='html'>&amp;amp;&amp;amp;tWell, had been thinking to get the control of windows services in a Java application so that programatically I can manage them (start/stop etc).&lt;div&gt;&lt;br /&gt;&lt;/div&gt;&lt;div&gt;My main intention to start off this was basically to check the status of the service whether it is up and running. If not, start it before you accomplish the relevant task. The triggering factor was to check the 'MySQL' service as i sometimes keep certain services as of type 'Manual' instead of 'Automatic' so that these services may not take up considerable amount of time when the Windows OS gets booted up.&lt;/div&gt;&lt;div&gt;&lt;br /&gt;&lt;/div&gt;&lt;div&gt;At times, when running a J2EE web application used to get the SQLException saying that 'could not obtain a connection', used to panic all of a sudden. Then recollecting our duty as having forgotten to start the particular service :)&lt;/div&gt;&lt;div&gt;&lt;br /&gt;&lt;/div&gt;&lt;div;though i="" am="" on="" the="" way="" of="" doing="" thought="" posting="" interim="" steps="" as="" such="" what="" have="" experienced="" till="" div=""&gt;&lt;div&gt;&lt;br /&gt;&lt;/div&gt;&lt;div&gt;As such, i am able to get the service up and bring it down through the application. Yet to get to know the status of a particular service and conditionally run the service :)&lt;/div&gt;&lt;div&gt;&lt;br /&gt;&lt;/div&gt;&lt;div&gt;First, i remember i can get the external process running inside a Java appliation is via Runtime class (java.lang.Runtime) and its 'exec()' method which takes a String argument which says the OS process to run. A couple of years back i have invoked the IE browser via the same and recollected those stuff.&lt;/div&gt;&lt;div&gt;&lt;br /&gt;&lt;/div&gt;&lt;div&gt;I tried executing the same as&lt;/div&gt;&lt;div&gt;&lt;br /&gt;&lt;/div&gt;&lt;div&gt;  &lt;span class="Apple-style-span" style="color: rgb(0, 102, 0);"&gt;Runtime runtime = new Runtime().exec("iexplore.exe www.javaranch.com");&lt;/span&gt;&lt;/div&gt;&lt;div&gt;&lt;br /&gt;&lt;/div&gt;&lt;div&gt;The second argument is the actual argument to the application/process to be executed.&lt;/div&gt;&lt;div&gt;&lt;br /&gt;&lt;/div&gt;&lt;div&gt; It was giving a different error saying that "&lt;span class="Apple-style-span" style="color: rgb(255, 0, 0);"&gt;java.io.IOException: CreateProcess iexplore.exe www.javaranch.com error=&lt;/span&gt;&lt;span class="Apple-style-span" style="color: rgb(255, 0, 0);"&gt;2&lt;/span&gt;". Had searched a bit in JavaDoc of the Java API in Process, Runtime classes, but really could not get anything. &lt;/div&gt;&lt;div&gt;&lt;br /&gt;&lt;/div&gt;&lt;div&gt; Beforehand, i wanted to try with some other executables like Notepad etc., to my surprise it was working fine. for example the below command&lt;/div&gt;&lt;div&gt;&lt;br /&gt;&lt;/div&gt;&lt;div&gt; &lt;span class="Apple-style-span" style="color: rgb(0, 102, 0);"&gt; runtime.exec("Notepad.exe C:\path.txt");&lt;/span&gt;&lt;/div&gt;&lt;div&gt;&lt;br /&gt;&lt;/div&gt;&lt;div&gt;  perfectly works fine and opens the path.txt inside the notepad application.  Have checked the same with "Calc.exe" as well.&lt;/div&gt;&lt;div&gt;&lt;br /&gt;&lt;/div&gt;&lt;div&gt; I have concluded to certain extent that the way we invoke this particular executable is errenous. I have tested the same by invoking the executable in the command prompt. It gave the infamous error&lt;/div&gt;&lt;div&gt;&lt;br /&gt;&lt;/div&gt;&lt;div&gt;&lt;div&gt;&lt;span class="Apple-style-span" style="color: rgb(255, 0, 0);"&gt;'iexplore.exe' is not recognized as an internal or external command,&lt;/span&gt;&lt;/div&gt;&lt;div&gt;&lt;span class="Apple-style-span" style="color: rgb(255, 0, 0);" operable="" program="" or="" batch="" span=""&gt;&lt;/span&gt;&lt;/div&gt;&lt;/div&gt;&lt;div&gt;&lt;br /&gt;&lt;/div&gt;&lt;div&gt;   Found out that the path was missing to this executable. That means, the location to the 'iexplore.exe' was not added into the path.  Though i checked the same by adding the location to IE.exe in PATH and it worked fine, but it won't be appropriate to do so just for this testing purpose. So reverted back and tried executing the following:&lt;/div&gt;&lt;div&gt;&lt;br /&gt;&lt;/div&gt;&lt;div&gt;  &lt;span class="Apple-style-span" style="color: rgb(0, 102, 0);"&gt;runtime.exec("C:\\Program Files\\Internet Explorer\\iexplore.exe www.javaranch.com");&lt;/span&gt;&lt;/div&gt;&lt;div&gt;&lt;br /&gt;&lt;/div&gt;&lt;div&gt;  What a surprise? It worked fine! &lt;/div&gt;&lt;div&gt;&lt;br /&gt;&lt;/div&gt;&lt;div&gt; Then i moved on to my required, 'services.msc' stuff in the same way.  I got the same error but with different error code even when i gave it with full path :(. For the invocation of &lt;/div&gt;&lt;div&gt;&lt;br /&gt;&lt;/div&gt;&lt;div&gt;   &lt;span class="Apple-style-span" style="color: rgb(0, 102, 0);"&gt;runtime.exec("C:\\WINDOWS\\system32\\services.msc");&lt;/span&gt;&lt;br /&gt;&lt;/div&gt;&lt;div&gt;&lt;br /&gt;&lt;/div&gt;&lt;div&gt;  the error what i got was, &lt;span class="Apple-style-span" style="color: rgb(255, 0, 0);"&gt;"java.io.IOException: CreateProcess: C:\WINDOWS\system32\services.msc error=19&lt;/span&gt;&lt;span class="Apple-style-span" style="color: rgb(255, 0, 0);"&gt;3&lt;/span&gt;". I am sure that the path to 'System32' was not mandatory at all. This error made me get into google and some good links helped me out in finding a way of what this error 193 means, '&lt;span class="Apple-style-span" style="font-style: italic;"&gt;this is not a valid Win32 application'&lt;/span&gt;.  Also could get some other invocations and out of which what i tried was successful. It is below.&lt;/div&gt;&lt;div&gt;&lt;br /&gt;&lt;/div&gt;&lt;div&gt;  &lt;span class="Apple-style-span" style="color: rgb(0, 102, 0);"&gt;runtime.exec("cmd.exe /c services.msc");&lt;/span&gt;&lt;/div&gt;&lt;div&gt;&lt;br /&gt;&lt;/div&gt;&lt;div&gt;  Actually, you have to invoke the Command Prompt (cmd.exe) first and then pass the actual service/exectuable to be invoked as an argument to command prompt. The middle argument '&lt;span class="Apple-style-span" style="color: rgb(153, 51, 0);"&gt;/c&lt;/span&gt;' is for 'carrying out the command and terminates". And i thought it would work even if it is not present, but it failed :(. Need a clarification here. :).  But it holds good when you type it in 'Run prompt'.  The other option to verify it is '&lt;span class="Apple-style-span" style="color: rgb(153, 51, 0);"&gt;/K&lt;/span&gt;' which stands for '&lt;span class="Apple-style-span" style="font-style: italic;"&gt;carries out the command specified by the string but remains&lt;/span&gt;'. &lt;/div&gt;&lt;div&gt;&lt;br /&gt;&lt;/div&gt;&lt;div&gt;  The next question was, how to get the particular service up? I tried by passing the name of the service as an argument as follows.&lt;/div&gt;&lt;div&gt;&lt;br /&gt;&lt;/div&gt;&lt;div&gt;  &lt;span class="Apple-style-span" style="color: rgb(0, 102, 0);"&gt;runtime.exec("cmd.exe /c services.msc MySQL");&lt;/span&gt;&lt;/div&gt;&lt;div&gt;&lt;br /&gt;&lt;/div&gt;&lt;div&gt;  but it dint give any fruitful results :(.  After a while, though why don't i directly execute the particular executable which the service is made run. Of course, the services is also a shortcut or link pointing to the executable placed elsewhere. Tried it out. it worked but with two drawbacks..&lt;/div&gt;&lt;div&gt;&lt;br /&gt;&lt;/div&gt;&lt;div&gt;   1. The java executable was getting hung. :(&lt;/div&gt;&lt;div&gt;   2. Was not having a way to stop the executable rather than killing the process!&lt;/div&gt;&lt;div&gt;&lt;br /&gt;&lt;/div&gt;&lt;div&gt;  Finally when continued searching in google, somewhere i read about the way to start a service. That's through 'NET START &lt;servicename&gt;'. Here is the &lt;a  href=http://forum.java.sun.com/thread.jspa?threadID=786125&amp;messageID=4469034&gt;link&lt;/a&gt;. Got succeeded as well :)&lt;/servicename&gt;&lt;/div&gt;&lt;div&gt;   &lt;/div&gt;&lt;div&gt;&lt;span class="Apple-style-span" style="color: rgb(0, 102, 0);"&gt;  runtime.exec("net start MySQL");&lt;/span&gt;&lt;/div&gt;&lt;div&gt;&lt;span class="Apple-style-span" style="color: rgb(0, 102, 0);"&gt;  runtime.exec("net stop MySQL");&lt;/span&gt;&lt;/div&gt;&lt;div&gt; &lt;/div&gt;&lt;div&gt;  Obviously these are invoking the MySQL Service in the services.msc only. As of now i am able enuf to do till this phase. Let me complete the rest and post it here.. &lt;/div&gt;&lt;div&gt;  &lt;/div&gt;&lt;/div;though&gt;&lt;div class="blogger-post-footer"&gt;&lt;img width='1' height='1' src='https://blogger.googleusercontent.com/tracker/27252087-5796691315890013146?l=teknicallyspeaking.blogspot.com' alt='' /&gt;&lt;/div&gt;</content><link rel='replies' type='application/atom+xml' href='http://teknicallyspeaking.blogspot.com/feeds/5796691315890013146/comments/default' title='Post Comments'/><link rel='replies' type='text/html' href='http://www.blogger.com/comment.g?blogID=27252087&amp;postID=5796691315890013146' title='0 Comments'/><link rel='edit' type='application/atom+xml' href='http://www.blogger.com/feeds/27252087/posts/default/5796691315890013146'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/27252087/posts/default/5796691315890013146'/><link rel='alternate' type='text/html' href='http://teknicallyspeaking.blogspot.com/2008/03/dealing-with-windows-services-in-java.html' title='dealing with windows services in java'/><author><name>Raghavan alias Saravanan M</name><uri>http://www.blogger.com/profile/17770791475348776850</uri><email>noreply@blogger.com</email><gd:image rel='http://schemas.google.com/g/2005#thumbnail' width='16' height='16' src='http://img2.blogblog.com/img/b16-rounded.gif'/></author><thr:total>0</thr:total></entry><entry><id>tag:blogger.com,1999:blog-27252087.post-4090373642382995809</id><published>2008-03-09T16:08:00.005+05:30</published><updated>2008-03-09T16:22:22.101+05:30</updated><category scheme='http://www.blogger.com/atom/ns#' term='OS'/><category scheme='http://www.blogger.com/atom/ns#' term='Command'/><category scheme='http://www.blogger.com/atom/ns#' term='Tips'/><category scheme='http://www.blogger.com/atom/ns#' term='Command Prompt'/><title type='text'>to set the color of the windows cmd prompt</title><content type='html'>&lt;div&gt;&lt;br /&gt;&lt;/div&gt;Basically I  too fall in that 'customizing-freak' category to customize certain features of the OS apart from the specific applications we work on.&lt;div&gt;&lt;br /&gt;&lt;/div&gt;&lt;div&gt;One among them is, to have the preferred font, foreground and background colors in the Comman Prompt and with a shortcut to the command prompt on the Quick Launch bar.&lt;/div&gt;&lt;div&gt;&lt;br /&gt;&lt;/div&gt;&lt;div&gt;Just today when i was searching for a help command for another utility (services.msc), got to know about this favorite-and-regular routine of mine. &lt;/div&gt;&lt;div&gt;&lt;br /&gt;&lt;/div&gt;&lt;div&gt;Windows has a command utility named &lt;b&gt;Color&lt;/b&gt; with an argument to set the foreground and background colors for the window being opened.&lt;/div&gt;&lt;div&gt;&lt;br /&gt;&lt;/div&gt;&lt;div&gt;I bet no one can beat the Microsoft's help/documentation. so for  your info, just copy-pasting the information available in the help!&lt;/div&gt;&lt;div&gt;&lt;br /&gt;&lt;/div&gt;&lt;div&gt;&lt;b&gt;Command : &lt;/b&gt;&lt;i&gt;color help&lt;/i&gt;&lt;/div&gt;&lt;div&gt;&lt;br /&gt;&lt;/div&gt;&lt;div&gt;&lt;div&gt;&lt;span class="Apple-style-span" style="color: rgb(102, 102, 102);"&gt;Sets the default console foreground and background colors.&lt;/span&gt;&lt;/div&gt;&lt;div&gt;&lt;span class="Apple-style-span" style="color: rgb(102, 102, 102);"&gt;&lt;br /&gt;&lt;/span&gt;&lt;/div&gt;&lt;div&gt;&lt;span class="Apple-style-span" style="color: rgb(102, 102, 102);"&gt;COLOR [attr]&lt;/span&gt;&lt;/div&gt;&lt;div&gt;&lt;span class="Apple-style-span" style="color: rgb(102, 102, 102);"&gt;&lt;br /&gt;&lt;/span&gt;&lt;/div&gt;&lt;div&gt;&lt;span class="Apple-style-span" style="color: rgb(102, 102, 102);"&gt;  attr        Specifies color attribute of console output&lt;/span&gt;&lt;/div&gt;&lt;div&gt;&lt;span class="Apple-style-span" style="color: rgb(102, 102, 102);"&gt;&lt;br /&gt;&lt;/span&gt;&lt;/div&gt;&lt;div&gt;&lt;span class="Apple-style-span" style="color: rgb(102, 102, 102);"&gt;Color attributes are specified by TWO hex digits -- the first&lt;/span&gt;&lt;/div&gt;&lt;div&gt;&lt;span class="Apple-style-span" style="color: rgb(102, 102, 102);"&gt;corresponds to the background; the second the foreground.  Each digit&lt;/span&gt;&lt;/div&gt;&lt;div&gt;&lt;span class="Apple-style-span" style="color: rgb(102, 102, 102);"&gt;can be any of the following values:&lt;/span&gt;&lt;/div&gt;&lt;div&gt;&lt;span class="Apple-style-span" style="color: rgb(102, 102, 102);"&gt;&lt;br /&gt;&lt;/span&gt;&lt;/div&gt;&lt;div&gt;&lt;span class="Apple-style-span" style="color: rgb(102, 102, 102);"&gt;    0 = Black       8 = Gray&lt;/span&gt;&lt;/div&gt;&lt;div&gt;&lt;span class="Apple-style-span" style="color: rgb(102, 102, 102);"&gt;    1 = Blue        9 = Light Blue&lt;/span&gt;&lt;/div&gt;&lt;div&gt;&lt;span class="Apple-style-span" style="color: rgb(102, 102, 102);"&gt;    2 = Green       A = Light Green&lt;/span&gt;&lt;/div&gt;&lt;div&gt;&lt;span class="Apple-style-span" style="color: rgb(102, 102, 102);"&gt;    3 = Aqua        B = Light Aqua&lt;/span&gt;&lt;/div&gt;&lt;div&gt;&lt;span class="Apple-style-span" style="color: rgb(102, 102, 102);"&gt;    4 = Red         C = Light Red&lt;/span&gt;&lt;/div&gt;&lt;div&gt;&lt;span class="Apple-style-span" style="color: rgb(102, 102, 102);"&gt;    5 = Purple      D = Light Purple&lt;/span&gt;&lt;/div&gt;&lt;div&gt;&lt;span class="Apple-style-span" style="color: rgb(102, 102, 102);"&gt;    6 = Yellow      E = Light Yellow&lt;/span&gt;&lt;/div&gt;&lt;div&gt;&lt;span class="Apple-style-span" style="color: rgb(102, 102, 102);"&gt;    7 = White       F = Bright White&lt;/span&gt;&lt;/div&gt;&lt;div&gt;&lt;span class="Apple-style-span" style="color: rgb(102, 102, 102);"&gt;&lt;br /&gt;&lt;/span&gt;&lt;/div&gt;&lt;div&gt;&lt;span class="Apple-style-span" style="color: rgb(102, 102, 102);"&gt;If no argument is given, this command restores the color to what it was&lt;/span&gt;&lt;/div&gt;&lt;div&gt;&lt;span class="Apple-style-span" style="color: rgb(102, 102, 102);"&gt;when CMD.EXE started.  This value either comes from the current console&lt;/span&gt;&lt;/div&gt;&lt;div&gt;&lt;span class="Apple-style-span" style="color: rgb(102, 102, 102);"&gt;window, the /T command line switch or from the DefaultColor registry&lt;/span&gt;&lt;/div&gt;&lt;div&gt;&lt;span class="Apple-style-span" style="color: rgb(102, 102, 102);"&gt;value.&lt;/span&gt;&lt;/div&gt;&lt;div&gt;&lt;span class="Apple-style-span" style="color: rgb(102, 102, 102);"&gt;&lt;br /&gt;&lt;/span&gt;&lt;/div&gt;&lt;div&gt;&lt;span class="Apple-style-span" style="color: rgb(102, 102, 102);"&gt;The COLOR command sets ERRORLEVEL to 1 if an attempt is made to execute&lt;/span&gt;&lt;/div&gt;&lt;div&gt;&lt;span class="Apple-style-span" style="color: rgb(102, 102, 102);"&gt;the COLOR command with a foreground and background color that are the&lt;/span&gt;&lt;/div&gt;&lt;div&gt;&lt;span class="Apple-style-span" style="color: rgb(102, 102, 102);"&gt;same.&lt;/span&gt;&lt;/div&gt;&lt;div&gt;&lt;span class="Apple-style-span" style="color: rgb(102, 102, 102);"&gt;&lt;br /&gt;&lt;/span&gt;&lt;/div&gt;&lt;div&gt;&lt;span class="Apple-style-span" style="color: rgb(102, 102, 102);"&gt;Example: "COLOR fc" produces light red on bright white.&lt;/span&gt;&lt;/div&gt;&lt;div&gt;&lt;br /&gt;&lt;/div&gt;&lt;div&gt;My preference goes as : "Color 0a" :P&lt;/div&gt;&lt;div&gt;&lt;br /&gt;&lt;/div&gt;&lt;div&gt;&lt;b&gt;Note:&lt;/b&gt; It just sets the colour for the current window being opened! :)&lt;/div&gt;&lt;div&gt;&lt;br /&gt;&lt;/div&gt;&lt;div&gt;Another Info about the 'DefaultColor' registry value: it is present in the &lt;i&gt;HKEY_USERS/.DEFAULT/Software/Microsoft/CommandProcessor&lt;/i&gt; directory in 'regedit' (Registry Editor).&lt;/div&gt;&lt;/div&gt;&lt;div&gt;&lt;br /&gt;&lt;/div&gt;&lt;div class="blogger-post-footer"&gt;&lt;img width='1' height='1' src='https://blogger.googleusercontent.com/tracker/27252087-4090373642382995809?l=teknicallyspeaking.blogspot.com' alt='' /&gt;&lt;/div&gt;</content><link rel='replies' type='application/atom+xml' href='http://teknicallyspeaking.blogspot.com/feeds/4090373642382995809/comments/default' title='Post Comments'/><link rel='replies' type='text/html' href='http://www.blogger.com/comment.g?blogID=27252087&amp;postID=4090373642382995809' title='0 Comments'/><link rel='edit' type='application/atom+xml' href='http://www.blogger.com/feeds/27252087/posts/default/4090373642382995809'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/27252087/posts/default/4090373642382995809'/><link rel='alternate' type='text/html' href='http://teknicallyspeaking.blogspot.com/2008/03/to-set-color-of-windows-cmd-prompt.html' title='to set the color of the windows cmd prompt'/><author><name>Raghavan alias Saravanan M</name><uri>http://www.blogger.com/profile/17770791475348776850</uri><email>noreply@blogger.com</email><gd:image rel='http://schemas.google.com/g/2005#thumbnail' width='16' height='16' src='http://img2.blogblog.com/img/b16-rounded.gif'/></author><thr:total>0</thr:total></entry><entry><id>tag:blogger.com,1999:blog-27252087.post-8316058177944936066</id><published>2008-01-21T14:48:00.000+05:30</published><updated>2008-01-23T14:32:19.437+05:30</updated><category scheme='http://www.blogger.com/atom/ns#' term='Java'/><category scheme='http://www.blogger.com/atom/ns#' term='Tips'/><title type='text'>Getters and Setters for better encapsulation</title><content type='html'>This is an interesting topic in the beginner's level. Well, at the end of this discussion you would have an answer for these questions.&lt;br /&gt;&lt;br /&gt;&lt;ol&gt;&lt;br /&gt;&lt;li&gt;What are Getters and Setters?&lt;/li&gt;&lt;br /&gt;&lt;li&gt;What way they are beneficial?&lt;/li&gt;&lt;br /&gt;&lt;li&gt;Are they the means of achieving Encapsulation?&lt;/li&gt;&lt;br /&gt;&lt;li&gt;Summary of this encapsulation&lt;/li&gt;&lt;br /&gt;&lt;/ol&gt;&lt;br /&gt;&lt;br /&gt;Let's take you have a Person object and whose size object is what you are trying to access or set.&lt;br /&gt;&lt;br /&gt;The plain version of the class would look like as follows:&lt;br /&gt;&lt;br /&gt;&lt;pre&gt;&lt;br /&gt;&lt;font family="Courier New" color="navy"&gt;&lt;br /&gt;class Person&lt;br /&gt;{&lt;br /&gt;   &lt;br&gt;&lt;br&gt;&lt;br /&gt;   public int age;&lt;br /&gt;   public String name;&lt;br /&gt;&lt;br /&gt;   &lt;br&gt;&lt;br&gt;&lt;br /&gt;   public static void main(String[] args)&lt;br /&gt;   {&lt;br /&gt;      Person obj1 = new Person();&lt;br /&gt;      obj1.age = 5;&lt;br /&gt;      obj1.name = "Raghavan";&lt;br /&gt;      System.out.println("obj1.age="+obj1.age);&lt;br /&gt;      System.out.println("obj1.name="+obj1.name);&lt;br /&gt;   }&lt;br /&gt;}&lt;br /&gt;&lt;/font&gt;&lt;br /&gt;&lt;/pre&gt;&lt;br /&gt;&lt;br /&gt;The following program produces the output as:&lt;br /&gt;&lt;br /&gt;&lt;font family="Courier New" color="Navy"&gt;&lt;br /&gt;&lt;pre&gt;&lt;br /&gt;obj1.age=5&lt;br /&gt;obj1.name=Raghavan&lt;br /&gt;&lt;/pre&gt;&lt;br /&gt;&lt;/font&gt;&lt;br /&gt;&lt;br /&gt;By looking at the above code, you don't seem to get anything strange! Yes so do I :).&lt;br /&gt;&lt;br /&gt;Let's have a &lt;font color="red"&gt;different scenario&lt;/font&gt; on the same class. &lt;br /&gt;&lt;br /&gt;&lt;pre&gt;&lt;br /&gt;&lt;font family="Courier New" color="navy"&gt;&lt;br /&gt;class Person&lt;br /&gt;{&lt;br /&gt;   &lt;br&gt;&lt;br&gt;&lt;br /&gt;   public int age;&lt;br /&gt;   public String name;&lt;br /&gt;&lt;br /&gt;   &lt;br&gt;&lt;br&gt;&lt;br /&gt;   public static void main(String[] args)&lt;br /&gt;   {&lt;br /&gt;      Person obj1 = new Person();&lt;br /&gt;      obj1.age = -5;&lt;br /&gt;      obj1.name = "";&lt;br /&gt;      System.out.println("obj1.age="+obj1.age);&lt;br /&gt;      System.out.println("obj1.name="+obj1.name);&lt;br /&gt;   }&lt;br /&gt;}&lt;br /&gt;&lt;/font&gt;&lt;br /&gt;&lt;/pre&gt;&lt;br /&gt;&lt;br /&gt;&lt;b&gt;Now did you see something strange?&lt;/b&gt;&lt;br /&gt;&lt;br /&gt;If not, look at the two lines carefully.&lt;br /&gt;&lt;br /&gt;&lt;font family="Courier New" color="maroon"&gt;&lt;br /&gt;&lt;pre&gt;&lt;br /&gt;      obj1.age = &lt;b&gt;-5&lt;/b&gt;;&lt;br /&gt;      obj1.name = &lt;b&gt;""&lt;/b&gt;;&lt;br /&gt;&lt;/pre&gt;&lt;br /&gt;&lt;/font&gt;&lt;br /&gt;&lt;br /&gt;They are perfectly valid and  legal to the compiler and runtime, they are syntactically correct! But logically? &lt;br /&gt;&lt;br /&gt;&lt;font color="red"&gt;&lt;br /&gt;&lt;ul&gt;&lt;br /&gt;&lt;li&gt;Can any person have a negative age? &lt;/li&gt;&lt;br /&gt;&lt;li&gt;Can a person's name be empty?&lt;/li&gt;&lt;br /&gt;&lt;/ul&gt;&lt;br /&gt;&lt;/font&gt;&lt;br /&gt;&lt;br /&gt;Why these occurred? Because the variables were of &lt;b&gt;public&lt;/b&gt; during declaration.&lt;br /&gt;&lt;br /&gt;That's why they are allowed outside and &lt;i&gt;any&lt;/i&gt; legal value is allowed in the program without any harm.&lt;br /&gt;&lt;br /&gt;&lt;i&gt;How we go ahead in preventing this scenario?&lt;/i&gt;&lt;br /&gt;&lt;br /&gt;Before the setters/getters were in picture or came into existence, the variables were declared public and given outside access without any harms.&lt;br /&gt;&lt;br /&gt;In that case,&lt;br /&gt;&lt;br /&gt;&lt;font family="Courier New" color="navy"&gt;&lt;br /&gt;&lt;pre&gt;&lt;br /&gt;class Person&lt;br /&gt;{&lt;br /&gt;   public int age;&lt;br /&gt;   &lt;br&gt;&lt;br&gt;&lt;br /&gt;&lt;br /&gt;   public static void main(String[] args) &lt;br /&gt;   {&lt;br /&gt;&lt;br /&gt;     Person myObj = new Person();&lt;br /&gt;     myObj.age = 5;&lt;br /&gt;     System.out.println("myObj.age : "+myObj.age);&lt;br /&gt;     &lt;br&gt;&lt;br&gt;&lt;br /&gt;&lt;br /&gt;     Person myObj2 = new Person();&lt;br /&gt;     &lt;font color="green"&gt;&lt;i&gt;/* Check here! */&lt;/i&gt;&lt;/font&gt;&lt;br /&gt;     &lt;b&gt;myObj.age = -2;&lt;/b&gt; &lt;font color="green"&gt;//Ouch! a syntactically correct but logically incorrect value&lt;/font&gt;&lt;br /&gt;     System.out.println("myObj2.age : "+myObj2.age);&lt;br /&gt;   }&lt;br /&gt;}&lt;br /&gt;&lt;/pre&gt;&lt;br /&gt;&lt;/font&gt;&lt;br /&gt;&lt;br /&gt;Just to have a better control on this value being accessed, there came a rescue in the form of &lt;b&gt;Getters and Setters&lt;/b&gt;. As the name indicates, Getter is used to get/obtain a value and Setter is to set a value back. They are also called as &lt;b&gt;Accessor and Mutators.&lt;/b&gt;&lt;br /&gt;&lt;br /&gt;&lt;font color="red"&gt;What if you allowed the access through a method and NOT directly?&lt;/font&gt;&lt;br /&gt;&lt;br /&gt;For which you need to have two things.&lt;br /&gt;&lt;br /&gt;&lt;ul&gt;&lt;br /&gt;&lt;li&gt; First "protect" your variable from outside access. Means, declare them to be of &lt;i&gt;private&lt;/i&gt;. &lt;/li&gt;&lt;br /&gt;&lt;li&gt;Then provide getter and setter for your private variable. As the variable is pricate, &lt;i&gt;the getter and setters should be public&lt;/i&gt;.&lt;/li&gt;&lt;br /&gt;&lt;/ul&gt;&lt;br /&gt;&lt;br /&gt;Following the same, the code will &lt;i&gt;initially&lt;/i&gt; look like&lt;br /&gt;&lt;br /&gt;&lt;font face="Courier New" color="navy"&gt;&lt;br /&gt;&lt;pre&gt;&lt;br /&gt;class Person&lt;br /&gt;{&lt;br /&gt;   private int age; &lt;br /&gt;   &lt;br&gt;&lt;br&gt;&lt;br /&gt;&lt;br /&gt;   &lt;b&gt;/* Getter Method */&lt;/b&gt;&lt;br /&gt;   &lt;br&gt;&lt;br&gt;&lt;br /&gt;&lt;br /&gt;   public int getAge() {&lt;br /&gt;     return this.age;&lt;br /&gt;   }&lt;br /&gt;   &lt;br&gt;&lt;br&gt;&lt;br /&gt;&lt;br /&gt;   &lt;b&gt;/* Setter Method */&lt;/b&gt;&lt;br /&gt;   &lt;br&gt;&lt;br&gt;&lt;br /&gt;&lt;br /&gt;   public void setAge(int newAge) {&lt;br /&gt;     this.age = newAge;&lt;br /&gt;   }&lt;br /&gt;  &lt;br&gt;&lt;br&gt;&lt;br /&gt;   public static void main(String[] args) &lt;br /&gt;   {&lt;br /&gt;      Person myObj = new Person();&lt;br /&gt;      //myObj.age = 5; &lt;font color="green"&gt;// can't access directly!&lt;/font&gt;&lt;br /&gt;      &lt;b&gt;myObj.setAge(5);&lt;/b&gt;&lt;br /&gt;      System.out.println("myObj.age : "+&lt;b&gt;myObj.getAge()&lt;/b&gt;);&lt;br /&gt;      &lt;br&gt;&lt;br&gt;&lt;br /&gt;&lt;br /&gt;      Person myObj2 = new Person();&lt;br /&gt;      &lt;font color="green"&gt;&lt;i&gt;/* Check here! */&lt;/font&gt;&lt;/i&gt;&lt;br /&gt;      &lt;b&gt;myObj.SetAge(-2); &lt;/b&gt;&lt;font color="green"&gt;//Ouch! a syntactically correct but logically incorrect value&lt;/font&gt;&lt;br /&gt;      System.out.println("myObj2.age : "+&lt;b&gt;myObj2.getAge()&lt;/b&gt;);&lt;br /&gt;   }&lt;br /&gt;}&lt;br /&gt;&lt;/pre&gt;&lt;br /&gt;&lt;/font&gt;&lt;br /&gt;&lt;br /&gt;But had you been exposing your code through this way, it would be very easy in a later point when you realize that setting a negative value is a sin! you should NOT allow that, you have an easy way to get rid of it.&lt;br /&gt;&lt;br /&gt;Just modify/update the setter method as below : &lt;br /&gt;&lt;br /&gt;&lt;font face="Courier New" color="navy"&gt;&lt;br /&gt;&lt;pre&gt;&lt;br /&gt;...&lt;br /&gt;public void setAge(int newAge) {&lt;br /&gt;    &lt;br&gt;&lt;br&gt;&lt;br /&gt;   &lt;font color="green"&gt;&lt;i&gt;/* introducing a new check for Age */&lt;/i&gt;&lt;/font&gt;&lt;br /&gt;   &lt;br&gt;&lt;br&gt;&lt;br /&gt;&lt;br /&gt;   &lt;b&gt;if(newAge &lt;=0){ &lt;/b&gt;&lt;font color="green"&gt;/*definitely age should NOT be zero! */&lt;/font&gt;&lt;br /&gt;     &lt;b&gt;System.err.println("Invalid age!");&lt;br /&gt;     return;&lt;br /&gt;   }&lt;/b&gt;&lt;br /&gt;  &lt;br&gt;&lt;br /&gt;&lt;br /&gt;   this.age = newAge;&lt;br /&gt;&lt;br /&gt;}&lt;br /&gt;&lt;/pre&gt;&lt;br /&gt;&lt;/font&gt;&lt;br /&gt;&lt;br /&gt;This way, you really &lt;b&gt;don't break the existing code&lt;/b&gt;. As such the users would still continue using your setAge() method to set an age.&lt;br /&gt;&lt;br /&gt;Here dealing with the invalid values and the condition to confirm the same may definitely based on the user and requirement. You can either set a default value or throw an exception or just let the user know about invalid value and continue the program normally.&lt;br /&gt;&lt;br /&gt;&lt;b&gt;A Quick Summary of encapsulation goes:&lt;/b&gt;&lt;br /&gt;&lt;br /&gt;Encapsulation reduces coupling between classes, allowing it to make changes to classes without having to change its clients (whoever invokes the methods of this class). This makes maintenance and extension of a software system much easier and less costly.&lt;br /&gt;&lt;br /&gt;Remember that for most systems, much more effort is put into maintenance than into initial development, so proper management of code dependencies pays manyfold.&lt;br /&gt;&lt;br /&gt;   &lt;br&gt;&lt;br&gt;&lt;br /&gt;   &lt;font color="green"&gt;/* 2-arg Constructor */&lt;/font&gt;&lt;br /&gt;   public Person(int age,String name)&lt;br /&gt;   {&lt;br /&gt;      this.age = age;&lt;br /&gt;      this.name = name;&lt;br /&gt;   }&lt;br /&gt;   &lt;br&gt;&lt;br&gt;&lt;br /&gt;   &lt;font color="green"&gt;/*Overridden toString() for our Person class*/&lt;/font&gt;&lt;br /&gt;   public String toString()&lt;br /&gt;   {&lt;br /&gt;       return "[Person] : age="+this.age+", name="+this.name;&lt;br /&gt;   }&lt;div class="blogger-post-footer"&gt;&lt;img width='1' height='1' src='https://blogger.googleusercontent.com/tracker/27252087-8316058177944936066?l=teknicallyspeaking.blogspot.com' alt='' /&gt;&lt;/div&gt;</content><link rel='replies' type='application/atom+xml' href='http://teknicallyspeaking.blogspot.com/feeds/8316058177944936066/comments/default' title='Post Comments'/><link rel='replies' type='text/html' href='http://www.blogger.com/comment.g?blogID=27252087&amp;postID=8316058177944936066' title='4 Comments'/><link rel='edit' type='application/atom+xml' href='http://www.blogger.com/feeds/27252087/posts/default/8316058177944936066'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/27252087/posts/default/8316058177944936066'/><link rel='alternate' type='text/html' href='http://teknicallyspeaking.blogspot.com/2008/01/getters-and-setters-for-better.html' title='Getters and Setters for better encapsulation'/><author><name>Raghavan alias Saravanan M</name><uri>http://www.blogger.com/profile/17770791475348776850</uri><email>noreply@blogger.com</email><gd:image rel='http://schemas.google.com/g/2005#thumbnail' width='16' height='16' src='http://img2.blogblog.com/img/b16-rounded.gif'/></author><thr:total>4</thr:total></entry><entry><id>tag:blogger.com,1999:blog-27252087.post-9100622151042258335</id><published>2007-11-19T18:05:00.001+05:30</published><updated>2008-12-10T01:23:46.490+05:30</updated><category scheme='http://www.blogger.com/atom/ns#' term='OS'/><category scheme='http://www.blogger.com/atom/ns#' term='Command'/><category scheme='http://www.blogger.com/atom/ns#' term='Tips'/><category scheme='http://www.blogger.com/atom/ns#' term='Windows'/><category scheme='http://www.blogger.com/atom/ns#' term='Command Prompt'/><title type='text'>tasklist - cmd in windows similar to ps cmd in linux</title><content type='html'>&lt;div&gt;&lt;span style="font-family:trebuchet ms;"&gt;The people who have worked in Unix and its flavours, would have definitely come across a command called '&lt;strong&gt;ps&lt;/strong&gt;' (which stands for &lt;em&gt;'process status'&lt;/em&gt;). As such the 'ps' command gives you the &lt;em&gt;list of processes running&lt;/em&gt; and the &lt;em&gt;pid (process id)&lt;/em&gt; etc.,&lt;/span&gt;&lt;br /&gt;&lt;span style="font-family:trebuchet ms;"&gt;&lt;/span&gt;&lt;br /&gt;&lt;span style="font-family:trebuchet ms;"&gt;There is a command to achieve the same in Windows OS too. That is &lt;strong&gt;'tasklist'&lt;/strong&gt;. Just execute in the command prompt. Here it gives the &lt;em&gt;"Image Name", "PID", "Session name", "Session#", "Mem Usage". &lt;/em&gt;&lt;/span&gt;&lt;br /&gt;&lt;span style="font-family:trebuchet ms;"&gt;&lt;/span&gt;&lt;br /&gt;&lt;span style="font-family:trebuchet ms;"&gt;&lt;em&gt;Image Name&lt;/em&gt; -&gt; the name of the process running&lt;/span&gt;&lt;br /&gt;&lt;span style="font-family:trebuchet ms;"&gt;&lt;em&gt;PID&lt;/em&gt; -&gt; as you know, the process id (unique id which the OS refers to)&lt;/span&gt;&lt;br /&gt;&lt;span style="font-family:trebuchet ms;"&gt;&lt;em&gt;Session name&lt;/em&gt; -&gt; it shows 'Console' but have to check what it really means&lt;/span&gt;&lt;br /&gt;&lt;span style="font-family:trebuchet ms;"&gt;&lt;em&gt;Session #&lt;/em&gt; -&gt; should be a session id and for console it gives '0'.&lt;/span&gt;&lt;br /&gt;&lt;span style="font-family:trebuchet ms;"&gt;&lt;em&gt;Mem usage&lt;/em&gt; -&gt; the amount of memory each task/process occupies.&lt;/span&gt; &lt;/div&gt;&lt;br /&gt;&lt;div&gt;&lt;/div&gt;&lt;br /&gt;&lt;div&gt;Here is the sample screenshot of the same.&lt;/div&gt;&lt;br /&gt;&lt;div&gt;&lt;/div&gt;&lt;img id="BLOGGER_PHOTO_ID_5134531428942092482" style="DISPLAY: block; MARGIN: 0px auto 10px; CURSOR: hand; TEXT-ALIGN: center" alt="" src="http://1.bp.blogspot.com/_TQ8N__pYJs8/R0GFIXYsGMI/AAAAAAAAAFA/CPyzuoUQstc/s400/tasklist+command+screenshot+19nov07+monday+338+pm+ast.JPG" border="0" /&gt;&lt;br /&gt;&lt;div&gt;&lt;span style="font-family:trebuchet ms;"&gt;It looks like the CUI version of the 'task manager' :)&lt;/span&gt;&lt;br /&gt;&lt;span style="font-family:trebuchet ms;"&gt;&lt;/span&gt;&lt;br /&gt;&lt;span style="font-family:trebuchet ms;"&gt;&lt;/span&gt;&lt;span style="font-family:verdana;font-size:85%;"&gt;&lt;strong&gt;&lt;span style="color:#990000;"&gt;NOTE:&lt;/span&gt;&lt;/strong&gt; &lt;span style="color:#333333;"&gt;&lt;em&gt;It may not work in all versions of Windows&lt;/em&gt;. As such i have tested in Windows XP. I believe it must definitely work in 2000 also. Not sure about the previous versions of 98,95 etc., will check and update later.&lt;/span&gt;&lt;/span&gt;&lt;/div&gt;&lt;div class="blogger-post-footer"&gt;&lt;img width='1' height='1' src='https://blogger.googleusercontent.com/tracker/27252087-9100622151042258335?l=teknicallyspeaking.blogspot.com' alt='' /&gt;&lt;/div&gt;</content><link rel='replies' type='application/atom+xml' href='http://teknicallyspeaking.blogspot.com/feeds/9100622151042258335/comments/default' title='Post Comments'/><link rel='replies' type='text/html' href='http://www.blogger.com/comment.g?blogID=27252087&amp;postID=9100622151042258335' title='0 Comments'/><link rel='edit' type='application/atom+xml' href='http://www.blogger.com/feeds/27252087/posts/default/9100622151042258335'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/27252087/posts/default/9100622151042258335'/><link rel='alternate' type='text/html' href='http://teknicallyspeaking.blogspot.com/2007/11/tasklist-command-in-windows.html' title='tasklist - cmd in windows similar to ps cmd in linux'/><author><name>Raghavan alias Saravanan M</name><uri>http://www.blogger.com/profile/17770791475348776850</uri><email>noreply@blogger.com</email><gd:image rel='http://schemas.google.com/g/2005#thumbnail' width='16' height='16' src='http://img2.blogblog.com/img/b16-rounded.gif'/></author><media:thumbnail xmlns:media='http://search.yahoo.com/mrss/' url='http://1.bp.blogspot.com/_TQ8N__pYJs8/R0GFIXYsGMI/AAAAAAAAAFA/CPyzuoUQstc/s72-c/tasklist+command+screenshot+19nov07+monday+338+pm+ast.JPG' height='72' width='72'/><thr:total>0</thr:total></entry><entry><id>tag:blogger.com,1999:blog-27252087.post-8799628619066215562</id><published>2007-09-13T13:42:00.000+05:30</published><updated>2007-09-13T15:04:58.560+05:30</updated><category scheme='http://www.blogger.com/atom/ns#' term='Pass-by-value'/><category scheme='http://www.blogger.com/atom/ns#' term='pass-by-reference'/><category scheme='http://www.blogger.com/atom/ns#' term='Java'/><title type='text'>Pass by Reference for object references holds good really?</title><content type='html'>&lt;span style="font-family:trebuchet ms;"&gt;&lt;strong&gt;&lt;/strong&gt;&lt;/span&gt;&lt;br /&gt;&lt;span style="font-family:trebuchet ms;"&gt;&lt;strong&gt;Pre-requisite:&lt;/strong&gt; Well, If you want to refreshwith the concepts of "&lt;em&gt;Pass-by-value Vs Pass-by-reference&lt;/em&gt;", you may please refer &lt;a href="http://teknicallyspeaking.blogspot.com/2007/09/pass-by-value-vs-pass-by-reference.html"&gt;this previous entry &lt;/a&gt;in this blog.&lt;/span&gt;&lt;br /&gt;&lt;span style="font-family:Trebuchet MS;"&gt;&lt;/span&gt;&lt;br /&gt;&lt;span style="font-family:trebuchet ms;"&gt;With respect to Java, it "&lt;strong&gt;passes everything by value&lt;/strong&gt;". I repeat, "&lt;em&gt;everything&lt;/em&gt;" by value only. &lt;/span&gt;&lt;br /&gt;&lt;span style="font-family:trebuchet ms;"&gt;&lt;/span&gt;&lt;br /&gt;&lt;span style="font-family:trebuchet ms;"&gt;Generally, we may think that passing by values will hold good only for primitive types and values but not for the object references.&lt;/span&gt;&lt;br /&gt;&lt;span style="font-family:trebuchet ms;"&gt;&lt;/span&gt;&lt;br /&gt;&lt;span style="font-family:trebuchet ms;"&gt;This &lt;em&gt;everything&lt;/em&gt; includes even the references to objects.&lt;br /&gt;&lt;br /&gt;Lets say, you have a method which takes an object as a parameter as follows&lt;br /&gt;&lt;br /&gt;&lt;br /&gt;&lt;/span&gt;&lt;span style="font-family:trebuchet ms;"&gt;&lt;span style="color:#3333ff;"&gt;&lt;span style="font-family:courier new;"&gt;public void doChange(MyClass myClassObj)&lt;br /&gt;{&lt;br /&gt;//do something..&lt;br /&gt;}&lt;/span&gt;&lt;br /&gt;&lt;/span&gt;&lt;br /&gt;&lt;br /&gt;And you call that method from some other piece of code as follows&lt;br /&gt;&lt;br /&gt;&lt;/span&gt;&lt;span style="font-family:trebuchet ms;"&gt;&lt;span style="color:#3333ff;"&gt;&lt;span style="font-family:courier new;"&gt;&lt;span style="color:#006600;"&gt;//calling method&lt;/span&gt;&lt;br /&gt;public void method1()&lt;br /&gt;{&lt;br /&gt;MyClass myClassObj = new MyClass();&lt;br /&gt;&lt;strong&gt;doChange&lt;/strong&gt;(myClassObj);&lt;br /&gt;}&lt;/span&gt;&lt;br /&gt;&lt;br /&gt;&lt;/span&gt;The reference variable &lt;em&gt;myClassObj&lt;/em&gt; is being assigned to an object of class MyClass in Heap. Just like primitive variables holding bit patterns to represent a value, reference variables also store the bit patterns to reach an object.&lt;br /&gt;&lt;br /&gt;Once you call the method &lt;em&gt;doChange&lt;/em&gt;() by passing the reference variable "&lt;em&gt;myClassObj&lt;/em&gt;" to it, the value of the bit patterns held by "&lt;em&gt;myClassObj&lt;/em&gt;" is being copied and passed into the called method doChange(). In the called method doChange(), the copied-and-sent bit pattern is received in the same name as that of the original reference variable "myClassObj". But the compiler treats that as a different one just like primitives.&lt;br /&gt;&lt;br /&gt;Lets say the received reference variable as "myClassObjLocal" for easy understanding. In this stage, both the original refernece variable "myClassObj" and the received reference variable inside the doChange() method "myClassObjLocal" (to compiler) point to the same object in Heap.&lt;br /&gt;&lt;br /&gt;Now if you change the state of the object being pointed by, it will reflect to both the reference variables because both of them point to the same object in Heap. Whereas,if you change the received reference variable "myClassObjLocal" to point to a new object (reassign a different object), it does NOT reflect back to the original object because the bit pattern to the "&lt;em&gt;myClassObjLocal&lt;/em&gt;" alone gets changed!&lt;br /&gt;&lt;br /&gt;If you are clear with the above paragraphs, lets go to an example to make it more clear.&lt;br /&gt;&lt;br /&gt;Lets take a small example.&lt;br /&gt;&lt;br /&gt;&lt;span style="font-family:courier new;color:#3333ff;"&gt;class TestObjRef&lt;br /&gt;{&lt;br /&gt;int intValue;&lt;br /&gt;&lt;br /&gt;public TestObjRef()&lt;br /&gt;{&lt;br /&gt;intValue = 1;&lt;br /&gt;}&lt;br /&gt;&lt;br /&gt;public static void changeStateOfObject(TestObjRef obj)&lt;br /&gt;{&lt;br /&gt;obj.intValue = 2;&lt;br /&gt;}&lt;br /&gt;&lt;br /&gt;public static void changeReference(TestObjRef obj)&lt;br /&gt;{&lt;br /&gt;obj = new TestObjRef();&lt;br /&gt;obj.intValue = 9;&lt;br /&gt;}&lt;br /&gt;&lt;br /&gt;public static void main(String[] args)&lt;br /&gt;{&lt;br /&gt;TestObjRef obj1 = new TestObjRef();&lt;br /&gt;System.out.println("obj1.intValue (1) = "+obj1.intValue);&lt;br /&gt;&lt;strong&gt;changeStateOfObject&lt;/strong&gt;(obj1);&lt;br /&gt;System.out.println("obj1.intValue (2) = "+obj1.intValue);&lt;br /&gt;&lt;strong&gt;changeReference&lt;/strong&gt;(obj1);&lt;br /&gt;System.out.println("obj1.intValue (3) = "+obj1.intValue);&lt;br /&gt;}&lt;br /&gt;}&lt;br /&gt;&lt;/span&gt;&lt;br /&gt;&lt;br /&gt;Running the above code produces the following output:&lt;br /&gt;&lt;br /&gt;&lt;strong&gt;Output:&lt;/strong&gt;&lt;br /&gt;&lt;span style="font-family:courier new;color:#993300;"&gt;obj1.intValue (1) = 1&lt;br /&gt;obj1.intValue (2) = 2&lt;br /&gt;obj1.intValue (3) = 2&lt;br /&gt;&lt;/span&gt;&lt;br /&gt;&lt;br /&gt;&lt;strong&gt;changeStateOfObject Method&lt;/strong&gt;&lt;br /&gt;&lt;br /&gt;This is because, changeStateOfObject() method just changes the value of the variable "intValue" which definitely constitutes the state of object. And as such, both the "obj1" in main() method and "obj" in changeStateOfObject() method point to the same object. Means, they both hold the same bit patterns to reach a single object of TestObjRef class in heap.&lt;br /&gt;&lt;br /&gt;That's why the output in the second line shows the changed state of object "2" as the value of "intValue" property.&lt;br /&gt;&lt;br /&gt;&lt;strong&gt;changeReference() Method&lt;/strong&gt;&lt;br /&gt;&lt;br /&gt;If you look at the changeReference() method, by the time of receiving the argument, both the "obj1" reference variable in main() method and received reference variable "obj" in changeReference() method both hold the same bit patterns to reach the same and single TestObjRef class in Heap.&lt;br /&gt;&lt;br /&gt;But inside the method, the received "obj" reference variable is reassigned to a newly created object of TestObjRef class. In this case, only the bit pattern of the "obj" reference variable inside the changeReference() method is changed and the change is NOT reflected back to the originally sent reference variable "obj1".&lt;br /&gt;&lt;br /&gt;That's why the third line in the output still shows the value of "intValue" as "2" since the changed value "9" is only reflected in the received local reference variable "obj" in changeReference() method.&lt;br /&gt;&lt;br /&gt;&lt;br /&gt;&lt;strong&gt;Note :&lt;/strong&gt;&lt;br /&gt;The received argument (object reference variable) is treated local to the method. That means, the scope of the variable is only local to the called method just like primitives and the variable cannot be accessed outside the method.&lt;br /&gt;&lt;br /&gt;&lt;/span&gt;&lt;span style="font-family:trebuchet ms;"&gt;&lt;/span&gt;&lt;div class="blogger-post-footer"&gt;&lt;img width='1' height='1' src='https://blogger.googleusercontent.com/tracker/27252087-8799628619066215562?l=teknicallyspeaking.blogspot.com' alt='' /&gt;&lt;/div&gt;</content><link rel='replies' type='application/atom+xml' href='http://teknicallyspeaking.blogspot.com/feeds/8799628619066215562/comments/default' title='Post Comments'/><link rel='replies' type='text/html' href='http://www.blogger.com/comment.g?blogID=27252087&amp;postID=8799628619066215562' title='4 Comments'/><link rel='edit' type='application/atom+xml' href='http://www.blogger.com/feeds/27252087/posts/default/8799628619066215562'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/27252087/posts/default/8799628619066215562'/><link rel='alternate' type='text/html' href='http://teknicallyspeaking.blogspot.com/2007/09/pass-by-reference-for-object-references.html' title='Pass by Reference for object references holds good really?'/><author><name>Raghavan alias Saravanan M</name><uri>http://www.blogger.com/profile/17770791475348776850</uri><email>noreply@blogger.com</email><gd:image rel='http://schemas.google.com/g/2005#thumbnail' width='16' height='16' src='http://img2.blogblog.com/img/b16-rounded.gif'/></author><thr:total>4</thr:total></entry><entry><id>tag:blogger.com,1999:blog-27252087.post-3141183463834335134</id><published>2007-09-13T11:41:00.000+05:30</published><updated>2007-09-13T13:40:05.447+05:30</updated><category scheme='http://www.blogger.com/atom/ns#' term='Pass-by-value'/><category scheme='http://www.blogger.com/atom/ns#' term='pass-by-reference'/><category scheme='http://www.blogger.com/atom/ns#' term='C'/><category scheme='http://www.blogger.com/atom/ns#' term='Command Prompt'/><category scheme='http://www.blogger.com/atom/ns#' term='C++'/><title type='text'>Pass by value Vs Pass by Reference</title><content type='html'>&lt;span style="font-family:trebuchet ms;"&gt;We all would have read the two terms "&lt;strong&gt;pass-by-value&lt;/strong&gt;" and "&lt;strong&gt;pass-by-reference&lt;/strong&gt;" especially when you deal with methods (which are also called as functions).&lt;/span&gt;&lt;br /&gt;&lt;span style="font-family:trebuchet ms;"&gt;&lt;/span&gt;&lt;br /&gt;&lt;span style="font-family:trebuchet ms;"&gt;Let's just have a quick glance at both the terms with a small example.&lt;/span&gt;&lt;br /&gt;&lt;span style="font-family:trebuchet ms;"&gt;&lt;/span&gt;&lt;br /&gt;&lt;span style="font-family:trebuchet ms;"&gt;The definition of these terms goes as follows.&lt;/span&gt;&lt;br /&gt;&lt;span style="font-family:trebuchet ms;"&gt;&lt;/span&gt;&lt;br /&gt;&lt;span style="font-family:trebuchet ms;"&gt;&lt;strong&gt;Pass-by-value:&lt;/strong&gt; A copy of the value is being passed from the calling method to the called method. &lt;/span&gt;&lt;br /&gt;&lt;span style="font-family:Trebuchet MS;"&gt;&lt;/span&gt;&lt;br /&gt;&lt;span style="font-family:Trebuchet MS;"&gt;&lt;em&gt;What exactly do you mean by copy of the value?&lt;/em&gt; In general, we tend to pass the variable for the value to be passed. In such case, whatever the value the variable holds is being copied and passed across. That means, you are taking a xerox of the o riginal value and pass the xeroxed copy to the called method.&lt;/span&gt;&lt;br /&gt;&lt;span style="font-family:Trebuchet MS;"&gt;&lt;/span&gt;&lt;br /&gt;&lt;span style="font-family:Trebuchet MS;"&gt;&lt;strong&gt;What are the effects?&lt;/strong&gt;&lt;/span&gt;&lt;br /&gt;&lt;span style="font-family:Trebuchet MS;"&gt;Since you have only passed the xeroxed copy and NOT the original value, whatever changes you do in the called method, the change is not reflected back to the original variable. &lt;/span&gt;&lt;br /&gt;&lt;span style="font-family:Trebuchet MS;"&gt;&lt;/span&gt;&lt;br /&gt;&lt;span style="font-family:Trebuchet MS;"&gt;&lt;strong&gt;A Sample program for pass-by-value:&lt;/strong&gt;&lt;/span&gt;&lt;br /&gt;&lt;strong&gt;&lt;span style="font-family:Trebuchet MS;"&gt;&lt;/span&gt;&lt;/strong&gt;&lt;br /&gt;&lt;span style="font-family:courier new;"&gt;&lt;span style="color:#3333ff;"&gt;&lt;span style="font-size:85%;"&gt;void changeValue(int a)&lt;/span&gt;&lt;br /&gt;&lt;span style="font-size:85%;"&gt;{&lt;/span&gt;&lt;br /&gt;&lt;span style="font-size:85%;"&gt;int b = ++a;&lt;/span&gt;&lt;br /&gt;&lt;span style="font-size:85%;"&gt;printf("changeValue -&gt; a, b contain: %d,%d",a,b);&lt;/span&gt;&lt;br /&gt;&lt;span style="font-size:85%;"&gt;}&lt;/span&gt;&lt;br /&gt;&lt;span style="font-size:85%;"&gt;&lt;/span&gt;&lt;br /&gt;&lt;span style="font-size:85%;"&gt;int changeAndReturn(int a)&lt;/span&gt;&lt;br /&gt;&lt;span style="font-size:85%;"&gt;{&lt;/span&gt;&lt;br /&gt;&lt;span style="font-size:85%;"&gt;int b = ++a;&lt;/span&gt;&lt;br /&gt;&lt;span style="font-size:85%;"&gt;printf("changeAndReturn -&gt; a,b contain : %d,%d",a,b); &lt;/span&gt;&lt;br /&gt;&lt;span style="font-size:85%;"&gt;return b;&lt;/span&gt;&lt;br /&gt;&lt;span style="font-size:85%;"&gt;}&lt;/span&gt;&lt;br /&gt;&lt;br /&gt;&lt;span style="font-size:85%;"&gt;int main()&lt;/span&gt;&lt;br /&gt;&lt;span style="font-size:85%;"&gt;{&lt;/span&gt;&lt;br /&gt;&lt;span style="font-size:85%;"&gt;int i = 1;&lt;/span&gt;&lt;br /&gt;&lt;span style="font-size:85%;"&gt;&lt;strong&gt;changeValue(i);&lt;/strong&gt;&lt;/span&gt;&lt;br /&gt;&lt;span style="font-size:85%;"&gt;j = i;&lt;/span&gt;&lt;br /&gt;&lt;span style="font-size:85%;"&gt;printf("\ni and j is : %d,%d\n",i,j); &lt;/span&gt;&lt;br /&gt;&lt;span style="font-size:85%;"&gt;printf("\ncalling changeAndReturn()..");&lt;/span&gt;&lt;br /&gt;&lt;span style="font-size:85%;"&gt;&lt;strong&gt;changeAndReturn(i);&lt;/strong&gt;&lt;/span&gt;&lt;br /&gt;&lt;span style="font-size:85%;"&gt;j = i;&lt;/span&gt;&lt;br /&gt;&lt;span style="font-size:85%;"&gt;printf("\nNow i and j contain: %d,%d",i,j);&lt;/span&gt;&lt;br /&gt;&lt;span style="font-size:85%;"&gt;}&lt;/span&gt;&lt;/span&gt;&lt;/span&gt;&lt;br /&gt;&lt;span style="font-family:verdana;font-size:85%;color:#999999;"&gt;&lt;/span&gt;&lt;br /&gt;&lt;span style="color:#000000;"&gt;&lt;strong&gt;&lt;span style="font-family:trebuchet ms;"&gt;Output:&lt;/span&gt;&lt;/strong&gt;&lt;br /&gt;&lt;/span&gt;&lt;span style="font-family:courier new;"&gt;&lt;span style="color:#993300;"&gt;changeValue-&gt; a, b contain: 2 2&lt;br /&gt;i and j is: &lt;strong&gt;1,1&lt;/strong&gt;&lt;br /&gt;calling changeAndReturn()..&lt;br /&gt;changeAndReturn -&gt; a,b contain: 2 2&lt;br /&gt;Now i and j contain: &lt;strong&gt;1&lt;/strong&gt; &lt;strong&gt;2&lt;/strong&gt;&lt;/span&gt;&lt;/span&gt;&lt;br /&gt;&lt;strong&gt;&lt;span style="font-family:Trebuchet MS;"&gt;&lt;/span&gt;&lt;/strong&gt;&lt;br /&gt;&lt;strong&gt;&lt;span style="font-family:Trebuchet MS;"&gt;Explanation:&lt;/span&gt;&lt;/strong&gt;&lt;br /&gt;&lt;span style="font-family:Trebuchet MS;"&gt;&lt;strong&gt;&lt;/strong&gt;Let's see how exactly the values are dealt. In the main() method, you are calling changeValue() method as&lt;/span&gt;&lt;br /&gt;&lt;span style="font-family:Trebuchet MS;"&gt;&lt;/span&gt;&lt;br /&gt;&lt;span style="font-family:Trebuchet MS;"&gt;&lt;em&gt;changeValue(i);&lt;/em&gt;&lt;/span&gt;&lt;br /&gt;&lt;span style="font-family:Trebuchet MS;"&gt;&lt;/span&gt;&lt;br /&gt;&lt;span style="font-family:Trebuchet MS;"&gt;At this time, the value of i (which is 1) is being copied (Remember! xeroxed) and the xeroxed copy is what getting passed to the changeValue() method. Inside the changeValue() method, you get (receive) the passed value in the variable name "a". &lt;strong&gt;Note:&lt;/strong&gt; Even if you have received the passed argument as the same name "i" in the function, the compiler would treat both of them differently!&lt;/span&gt;&lt;br /&gt;&lt;span style="font-family:Trebuchet MS;"&gt;&lt;/span&gt;&lt;br /&gt;&lt;span style="font-family:Trebuchet MS;"&gt;Soon after you take a xerox copy of the value of the variable and use it for calling functions, the connection between the copied value and the original value is cut. There is no relation between those two values and /or variables.&lt;/span&gt;&lt;br /&gt;&lt;span style="font-family:Trebuchet MS;"&gt;&lt;/span&gt;&lt;br /&gt;&lt;span style="font-family:Trebuchet MS;"&gt;Inside the method changeValue(), we do the following steps:&lt;/span&gt;&lt;br /&gt;&lt;span style="font-family:Trebuchet MS;"&gt;&lt;/span&gt;&lt;br /&gt;&lt;span style="font-family:Trebuchet MS;color:#000000;"&gt;(i) receive the value passed in the variable whose name is 'a' (implicit)&lt;/span&gt;&lt;br /&gt;&lt;span style="font-family:Trebuchet MS;color:#000000;"&gt;(ii) declare an int variable named 'b'&lt;/span&gt;&lt;br /&gt;&lt;span style="font-family:Trebuchet MS;color:#000000;"&gt;(iii) increment the received value in its variable 'a' and assign the incremented value to 'b'&lt;/span&gt;&lt;br /&gt;&lt;span style="font-family:Trebuchet MS;"&gt;&lt;/span&gt;&lt;br /&gt;&lt;span style="font-family:Trebuchet MS;"&gt;Since because the original value ('i' in main) does NOT hold any relationship with its xeroxcopy ('a' here), the changes you do in the called function (incrementing the value in changeValue()) does NOT reflect back.&lt;/span&gt;&lt;br /&gt;&lt;span style="font-family:Trebuchet MS;"&gt;&lt;/span&gt;&lt;br /&gt;&lt;span style="font-family:Trebuchet MS;"&gt;That's why in the main after the function call returned, the printf statement prints the value both i and j contain 0. Once the function call is returned, the present focus is in main() function and now we are assigning the value of 'i' to 'j' which is 0 only. This clearly shows that there is NO effect on the variable 'i' even after calling the function changeValue() which does some change to it actually.&lt;/span&gt;&lt;br /&gt;&lt;br /&gt;&lt;span style="font-family:trebuchet ms;"&gt;Just to have an effect, we have one more method called &lt;em&gt;changeAndReturn()&lt;/em&gt; which changes the value and returns it. In the calling function (main()), we get the returned value and assign it to 'j'. That's why the second set of output shows the incremented value '2' for both 'i' and 'j'.&lt;/span&gt;&lt;br /&gt;&lt;span style="font-family:Trebuchet MS;"&gt;&lt;/span&gt;&lt;br /&gt;&lt;span style="font-family:Trebuchet MS;"&gt;&lt;strong&gt;Pass-by-reference:&lt;/strong&gt; The memory address of the variable is being passed instead of making a copy of the value. This holds good for C, C++ languages (as far as i know as such).&lt;/span&gt;&lt;br /&gt;&lt;span style="font-family:Trebuchet MS;"&gt;&lt;/span&gt;&lt;br /&gt;&lt;span style="font-family:Trebuchet MS;"&gt;&lt;strong&gt;What are the effects?&lt;/strong&gt;&lt;/span&gt;&lt;br /&gt;&lt;span style="font-family:Trebuchet MS;"&gt;&lt;strong&gt;&lt;/strong&gt;Since you pass the memory address itself to the function and you obtain the value from the received memory address inside the called function, you get the full control over the value. That means, whatever change you do, it will be reflecting in the original variable in the calling function eventhough you do NOT return either the memory address or value back.&lt;/span&gt;&lt;br /&gt;&lt;span style="font-family:Trebuchet MS;"&gt;&lt;/span&gt;&lt;br /&gt;&lt;span style="font-family:Trebuchet MS;"&gt;It is because, you have played around with the memory directly instead of values and in both the calling and called functions, the values are obtained and manipulated with respect to memory only. So the change is reflected back.&lt;/span&gt;&lt;br /&gt;&lt;span style="font-family:Trebuchet MS;"&gt;&lt;/span&gt;&lt;br /&gt;&lt;span style="font-family:Trebuchet MS;"&gt;Let's see a sample program for pass-by-reference:&lt;/span&gt;&lt;br /&gt;&lt;span style="font-family:Trebuchet MS;"&gt;&lt;/span&gt;&lt;br /&gt;&lt;span style="font-family:Trebuchet MS;"&gt;&lt;strong&gt;Sample Program for pass-by-reference:&lt;/strong&gt;&lt;/span&gt;&lt;br /&gt;&lt;strong&gt;&lt;span style="font-family:Trebuchet MS;"&gt;&lt;/span&gt;&lt;/strong&gt;&lt;br /&gt;&lt;span style="font-family:courier new;"&gt;&lt;span style="color:#3333ff;"&gt;void changeValue(int *int_ptr)&lt;br /&gt;{&lt;br /&gt;&lt;/span&gt;&lt;/span&gt;&lt;span style="font-family:courier new;"&gt;&lt;span style="color:#3333ff;"&gt;&lt;em&gt;&lt;span style="color:#006600;"&gt;//doing an increment operation on the 'dereferenced' pointer&lt;/span&gt;&lt;/em&gt;&lt;br /&gt;int b = ++(*int_ptr);&lt;br /&gt;printf("changeValue -&gt; a, b contain: %d,%d",a,b);&lt;br /&gt;}&lt;br /&gt;&lt;br /&gt;&lt;/span&gt;&lt;/span&gt;&lt;span style="color:#3333ff;"&gt;&lt;span style="font-family:courier new;"&gt;int main()&lt;br /&gt;{&lt;br /&gt;int i = 1;&lt;br /&gt;int *int_ptr = &amp;i;&lt;br /&gt;printf("\ncalling changeValue().."); &lt;/span&gt;&lt;/span&gt;&lt;br /&gt;&lt;span style="color:#3333ff;"&gt;&lt;span style="font-family:courier new;"&gt;&lt;span style="color:#006600;"&gt;//Note: we are passing the pointer to the function! (the 'address')&lt;/span&gt;&lt;br /&gt;changeValue(int_ptr);&lt;br /&gt;&lt;span style="color:#006600;"&gt;&lt;em&gt;//assigning the value of 'i' to 'j'&lt;/em&gt;&lt;/span&gt;&lt;br /&gt;&lt;/span&gt;&lt;/span&gt;&lt;span style="font-family:courier new;"&gt;&lt;span style="color:#3333ff;"&gt;int j = i;&lt;br /&gt;printf("\ni and j is : %d,%d\n",i,j);&lt;br /&gt;}&lt;/span&gt;&lt;span style="color:#999999;"&gt;&lt;br /&gt;&lt;/span&gt;&lt;/span&gt;&lt;span style="font-family:trebuchet ms;"&gt;&lt;br /&gt;&lt;/span&gt;&lt;span style="font-family:verdana;"&gt;&lt;span style="color:#999999;"&gt;&lt;span style="font-size:85%;"&gt;&lt;strong&gt;&lt;span style="font-family:trebuchet ms;font-size:100%;color:#000000;"&gt;Output:&lt;/span&gt;&lt;/strong&gt;&lt;br /&gt;&lt;/span&gt;&lt;/span&gt;&lt;span style="font-family:courier new;color:#993300;"&gt;changeValue-&gt; a, b contain: 2 2 &lt;/span&gt;&lt;/span&gt;&lt;br /&gt;&lt;span style="font-family:trebuchet ms;"&gt;&lt;span style="font-family:courier new;"&gt;&lt;span style="color:#993300;"&gt;calling changeValue()..&lt;br /&gt;i and j is: &lt;strong&gt;2&lt;/strong&gt;,&lt;strong&gt;2&lt;/strong&gt;&lt;/span&gt;&lt;/span&gt;&lt;br /&gt;&lt;/span&gt;&lt;br /&gt;&lt;span style="font-family:trebuchet ms;"&gt;&lt;strong&gt;Explanation:&lt;br /&gt;&lt;/strong&gt;&lt;/span&gt;&lt;br /&gt;&lt;span style="font-family:trebuchet ms;"&gt;&lt;strong&gt;&lt;/strong&gt;If you carefully look at the implementation and way of calling the function changeValue(), it actually receives a pointer to an integer! that means, we are passing the 'memory address' of an integer variable.&lt;/span&gt;&lt;br /&gt;&lt;span style="font-family:trebuchet ms;"&gt;&lt;/span&gt;&lt;br /&gt;&lt;span style="font-family:trebuchet ms;"&gt;Inside the function, we do the following steps:&lt;/span&gt;&lt;br /&gt;&lt;span style="font-family:trebuchet ms;"&gt;&lt;/span&gt;&lt;br /&gt;&lt;span style="font-family:trebuchet ms;"&gt;(i) receive the address of the integer variable in the name 'int_ptr' (the same name as in the calling function, here main(). But remember! for the compiler, they both are different!)&lt;/span&gt;&lt;br /&gt;&lt;span style="font-family:trebuchet ms;"&gt;(ii) we declare an integer variable 'b' &lt;/span&gt;&lt;br /&gt;&lt;span style="font-family:trebuchet ms;"&gt;(iii) we dereference the pointer variable ('dereferencing' means obtaining the value present in the location where the pointer is pointing to)&lt;/span&gt;&lt;br /&gt;&lt;span style="font-family:trebuchet ms;"&gt;(iv) we increment the value being obtained by the dereferencing operation&lt;/span&gt;&lt;br /&gt;&lt;span style="font-family:Trebuchet MS;"&gt;&lt;strong&gt;Note:&lt;/strong&gt; here the value is incremented directly in the memory location&lt;/span&gt;&lt;br /&gt;&lt;span style="font-family:trebuchet ms;"&gt;(v) and assign the incremented value to the variable 'b'&lt;/span&gt;&lt;br /&gt;&lt;span style="font-family:trebuchet ms;"&gt;&lt;/span&gt;&lt;br /&gt;&lt;span style="font-family:trebuchet ms;"&gt;One important thing is that, we do NOT return any value back to the calling function. But the changes happend in the memory location directly in the called function (changeValue()). Once the control comes back to the calling function (main()), we are still accessing the value in the same memory location through the original variable 'i' and assigning to 'j'.&lt;/span&gt;&lt;br /&gt;&lt;span style="font-family:trebuchet ms;"&gt;&lt;/span&gt;&lt;br /&gt;&lt;span style="font-family:trebuchet ms;"&gt;That's why we see both i and j having the value '2'.&lt;br /&gt;&lt;br /&gt;&lt;br /&gt;&lt;/span&gt;&lt;span style="font-family:trebuchet ms;"&gt;&lt;/span&gt;&lt;span style="font-family:trebuchet ms;"&gt;&lt;/span&gt;&lt;span style="font-family:trebuchet ms;"&gt;&lt;/span&gt;&lt;div class="blogger-post-footer"&gt;&lt;img width='1' height='1' src='https://blogger.googleusercontent.com/tracker/27252087-3141183463834335134?l=teknicallyspeaking.blogspot.com' alt='' /&gt;&lt;/div&gt;</content><link rel='replies' type='application/atom+xml' href='http://teknicallyspeaking.blogspot.com/feeds/3141183463834335134/comments/default' title='Post Comments'/><link rel='replies' type='text/html' href='http://www.blogger.com/comment.g?blogID=27252087&amp;postID=3141183463834335134' title='0 Comments'/><link rel='edit' type='application/atom+xml' href='http://www.blogger.com/feeds/27252087/posts/default/3141183463834335134'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/27252087/posts/default/3141183463834335134'/><link rel='alternate' type='text/html' href='http://teknicallyspeaking.blogspot.com/2007/09/pass-by-value-vs-pass-by-reference.html' title='Pass by value Vs Pass by Reference'/><author><name>Raghavan alias Saravanan M</name><uri>http://www.blogger.com/profile/17770791475348776850</uri><email>noreply@blogger.com</email><gd:image rel='http://schemas.google.com/g/2005#thumbnail' width='16' height='16' src='http://img2.blogblog.com/img/b16-rounded.gif'/></author><thr:total>0</thr:total></entry><entry><id>tag:blogger.com,1999:blog-27252087.post-6124895988355561317</id><published>2007-04-04T12:27:00.000+05:30</published><updated>2007-04-04T12:40:44.726+05:30</updated><category scheme='http://www.blogger.com/atom/ns#' term='Tips'/><category scheme='http://www.blogger.com/atom/ns#' term='Windows'/><category scheme='http://www.blogger.com/atom/ns#' term='Command Prompt'/><category scheme='http://www.blogger.com/atom/ns#' term='Files'/><title type='text'>How to get the list of files in a directory and save it in a file</title><content type='html'>&lt;span style="font-family:trebuchet ms;"&gt;You may need to get the list of files inside a folder with the appropriate structures being maintained. &lt;/span&gt;&lt;br /&gt;&lt;span style="font-family:Trebuchet MS;"&gt;&lt;/span&gt;&lt;br /&gt;&lt;span style="font-family:trebuchet ms;"&gt;This tip will help you to get the complete list of filenames within a directory structure in Windows OS.&lt;br /&gt;&lt;br /&gt;(1) Go to Command Prompt&lt;br /&gt;(2) Navigate to any directory of your interest&lt;br /&gt;(3) Type &lt;span style="color:#990000;"&gt;&lt;strong&gt;dir /b /s "Root-directory" &gt; "filename.extension"&lt;/strong&gt;&lt;br /&gt;&lt;/span&gt;&lt;br /&gt;whereas&lt;br /&gt;&lt;br /&gt;&lt;strong&gt;&lt;span style="color:#990000;"&gt;/b&lt;/span&gt;&lt;/strong&gt; -&gt; use bare format (no heading information or summary)&lt;br /&gt;{summary is the date time info, size , file or directory attribute etc.}&lt;br /&gt;&lt;br /&gt;&lt;strong&gt;&lt;span style="color:#990000;"&gt;/s&lt;/span&gt;&lt;/strong&gt; -&gt; displays file in specified directory and all subdirectories.&lt;br /&gt;&lt;br /&gt;&lt;strong&gt;&lt;span style="color:#990000;"&gt;Root-directory&lt;/span&gt;&lt;/strong&gt; -&gt; is the directory from which you want the file list info&lt;br /&gt;{if Root-directory is omitted it will process from the current directory}&lt;br /&gt;&lt;br /&gt;&lt;strong&gt;&lt;span style="color:#990000;"&gt;&gt;&lt;/span&gt;&lt;/strong&gt; -&gt; Redirection Operator or Symbol.&lt;br /&gt;{the output of the command on its left would be sent to its right}&lt;br /&gt;&lt;br /&gt;&lt;strong&gt;&lt;span style="color:#990000;"&gt;fileName.extension&lt;/span&gt;&lt;/strong&gt; -&gt; any file name with extension you want&lt;br /&gt;{example. directory-structure.txt}&lt;br /&gt;&lt;br /&gt;&lt;/span&gt;&lt;strong&gt;&lt;u&gt;&lt;span style="font-family:verdana;color:#006600;"&gt;Make it Automated in a Batch File&lt;/span&gt;&lt;/u&gt;&lt;/strong&gt;&lt;br /&gt;&lt;br /&gt;&lt;span style="font-family:trebuchet ms;"&gt;You can even write a batch file with another line to open it in the&lt;br /&gt;appropriate application.&lt;br /&gt;&lt;br /&gt;&lt;br /&gt;&lt;/span&gt;&lt;span style="font-family:trebuchet ms;"&gt;&lt;blockquote&gt;&lt;strong&gt;&lt;span style="color:#990000;"&gt;dir /b /s "Root-directory" &gt; "filename.extension"&lt;br /&gt;notepad "filename.extension"&lt;/span&gt;&lt;/strong&gt;&lt;/blockquote&gt;Save these two lines in a batchfile as "&lt;batchfilename&gt;.bat" and run this batch file from command prompt. It would automatically save it in the file and gets opened in Notepad. You could use any other convenient applications to open as you wish.&lt;br /&gt;&lt;br /&gt;Hope you may need not take screenshots for directory structure {if at all you had been doing so} ;-).&lt;/span&gt;&lt;br /&gt;&lt;/span&gt;&lt;div class="blogger-post-footer"&gt;&lt;img width='1' height='1' src='https://blogger.googleusercontent.com/tracker/27252087-6124895988355561317?l=teknicallyspeaking.blogspot.com' alt='' /&gt;&lt;/div&gt;</content><link rel='replies' type='application/atom+xml' href='http://teknicallyspeaking.blogspot.com/feeds/6124895988355561317/comments/default' title='Post Comments'/><link rel='replies' type='text/html' href='http://www.blogger.com/comment.g?blogID=27252087&amp;postID=6124895988355561317' title='2 Comments'/><link rel='edit' type='application/atom+xml' href='http://www.blogger.com/feeds/27252087/posts/default/6124895988355561317'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/27252087/posts/default/6124895988355561317'/><link rel='alternate' type='text/html' href='http://teknicallyspeaking.blogspot.com/2007/04/how-to-get-list-of-files-in-directory.html' title='How to get the list of files in a directory and save it in a file'/><author><name>Raghavan alias Saravanan M</name><uri>http://www.blogger.com/profile/17770791475348776850</uri><email>noreply@blogger.com</email><gd:image rel='http://schemas.google.com/g/2005#thumbnail' width='16' height='16' src='http://img2.blogblog.com/img/b16-rounded.gif'/></author><thr:total>2</thr:total></entry><entry><id>tag:blogger.com,1999:blog-27252087.post-3521251338379935979</id><published>2007-02-23T21:26:00.000+05:30</published><updated>2007-02-23T21:46:33.605+05:30</updated><category scheme='http://www.blogger.com/atom/ns#' term='Tips'/><category scheme='http://www.blogger.com/atom/ns#' term='Database'/><category scheme='http://www.blogger.com/atom/ns#' term='Efficiency'/><category scheme='http://www.blogger.com/atom/ns#' term='DML'/><title type='text'>Tip to increase the efficiency while deleting huge volume of rows</title><content type='html'>&lt;span style="font-family:trebuchet ms;"&gt;This tip would be very much useful when you have enormous rows in a table and you are trying to delete/remove the rows using the usual, "&lt;strong&gt;&lt;span style="color:#000099;"&gt;DELETE FROM &amp;lt;tableName&amp;gt;;"&lt;/span&gt; &lt;/strong&gt;statement.&lt;/span&gt;&lt;br /&gt;&lt;span style="font-family:trebuchet ms;"&gt;&lt;/span&gt;&lt;br /&gt;&lt;span style="font-family:trebuchet ms;"&gt;You may ask whats the consequences of using the DELETE statement and thats what its purpose is. But, not just deletion, for that matter any DML statement will make use of something called &lt;span style="color:#000099;"&gt;TRANSACTION LOG&lt;/span&gt; which is nothing but the buffer/temporary storage where all the data would be kept until there is an explicit &lt;span style="color:#000099;"&gt;COMMIT&lt;/span&gt; or &lt;span style="color:#000099;"&gt;ROLLBACK&lt;/span&gt;. &lt;/span&gt;&lt;br /&gt;&lt;span style="font-family:trebuchet ms;"&gt;&lt;/span&gt;&lt;br /&gt;&lt;span style="font-family:trebuchet ms;"&gt;&lt;em&gt;&lt;strong&gt;Once a Commit is issued&lt;/strong&gt;&lt;/em&gt;, the data kept in the Transaction Log is written into the database files in its own appropriate format (.dat for data files, .inx for index files in IBM DB2 database - which may vary in Oracle, MySQL, SQL Server etc..). &lt;/span&gt;&lt;br /&gt;&lt;span style="font-family:trebuchet ms;"&gt;&lt;/span&gt;&lt;br /&gt;&lt;span style="font-family:trebuchet ms;"&gt;&lt;em&gt;&lt;strong&gt;When a rollback is issued&lt;/strong&gt;&lt;/em&gt;, the data in the temporary Transaction Log is removed and thereby no state change happens to the data files.&lt;/span&gt;&lt;br /&gt;&lt;span style="font-family:trebuchet ms;"&gt;&lt;/span&gt;&lt;br /&gt;&lt;span style="font-family:trebuchet ms;"&gt;Moreover, its gonna be time consuming wherein the time is directly proportional to the dense of data.&lt;/span&gt;&lt;br /&gt;&lt;span style="font-family:trebuchet ms;"&gt;&lt;/span&gt;&lt;br /&gt;&lt;span style="font-family:trebuchet ms;"&gt;When you deal with large number of data to be dealt with, be it inserting, updating or deleting, you might end up in something called, "&lt;span style="color:#ff0000;"&gt;The Transaction Log is FULL&lt;/span&gt;" while doing the operation. Most of us might not have encountered this situtation as we do just deal with 100s or max 1000s of data. People who are dealing with lakhs, millions of rows might have been aware of this. Say, who are in Data Warehousing, Business Objects etc.&lt;/span&gt;&lt;br /&gt;&lt;span style="font-family:trebuchet ms;"&gt;&lt;/span&gt;&lt;br /&gt;&lt;span style="font-family:trebuchet ms;"&gt;When we encountered the situation, one of my teammates in my client place (Yadati Ravishankar) had come up with a query what he found out in googling. This query does the magic by just clearing up the table with very very less time compared to that of plain old DELETE statement.&lt;/span&gt;&lt;br /&gt;&lt;span style="font-family:trebuchet ms;"&gt;&lt;/span&gt;&lt;br /&gt;&lt;span style="font-family:trebuchet ms;"&gt;Here you go...&lt;/span&gt;&lt;br /&gt;&lt;span style="font-family:trebuchet ms;"&gt;&lt;/span&gt;&lt;br /&gt;&lt;span style="font-family:trebuchet ms;color:#660000;"&gt;&lt;strong&gt;"ALTER TABLE [&amp;lt;SchemaName&amp;gt;.]&amp;lt;tablename&amp;gt; ACTIVATE NOT LOGGED INITIALLY WITH EMPTY TABLE;"&lt;/strong&gt;&lt;/span&gt;&lt;br /&gt;&lt;span style="font-family:trebuchet ms;"&gt;&lt;/span&gt;&lt;br /&gt;&lt;span style="font-family:trebuchet ms;"&gt;This query does alter the table with empty rows but while doing the same it requests the db engine not to activate the Logging. Thereby it is able to get the request serviced within seconds!!&lt;/span&gt;&lt;br /&gt;&lt;span style="font-family:trebuchet ms;"&gt;&lt;/span&gt;&lt;br /&gt;&lt;span style="font-family:trebuchet ms;"&gt;&lt;em&gt;Try with huge data buddies..then only you can make out the difference!!&lt;/em&gt;&lt;/span&gt;&lt;br /&gt;&lt;span style="font-family:trebuchet ms;"&gt;&lt;/span&gt;&lt;br /&gt;&lt;span style="font-family:trebuchet ms;"&gt;Good luck!&lt;/span&gt;&lt;div class="blogger-post-footer"&gt;&lt;img width='1' height='1' src='https://blogger.googleusercontent.com/tracker/27252087-3521251338379935979?l=teknicallyspeaking.blogspot.com' alt='' /&gt;&lt;/div&gt;</content><link rel='replies' type='application/atom+xml' href='http://teknicallyspeaking.blogspot.com/feeds/3521251338379935979/comments/default' title='Post Comments'/><link rel='replies' type='text/html' href='http://www.blogger.com/comment.g?blogID=27252087&amp;postID=3521251338379935979' title='0 Comments'/><link rel='edit' type='application/atom+xml' href='http://www.blogger.com/feeds/27252087/posts/default/3521251338379935979'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/27252087/posts/default/3521251338379935979'/><link rel='alternate' type='text/html' href='http://teknicallyspeaking.blogspot.com/2007/02/tip-to-increase-efficiency-while.html' title='Tip to increase the efficiency while deleting huge volume of rows'/><author><name>Raghavan alias Saravanan M</name><uri>http://www.blogger.com/profile/17770791475348776850</uri><email>noreply@blogger.com</email><gd:image rel='http://schemas.google.com/g/2005#thumbnail' width='16' height='16' src='http://img2.blogblog.com/img/b16-rounded.gif'/></author><thr:total>0</thr:total></entry><entry><id>tag:blogger.com,1999:blog-27252087.post-4702751348898548638</id><published>2007-01-16T17:27:00.000+05:30</published><updated>2007-01-16T17:51:44.101+05:30</updated><title type='text'>Java #Q1: What would be the output?</title><content type='html'>&lt;pre&gt;&lt;span style="font-family:trebuchet ms;color:#6600cc;"&gt;public class Test&lt;/span&gt;&lt;br /&gt;&lt;span style="font-family:trebuchet ms;color:#6600cc;"&gt;{&lt;/span&gt;&lt;br /&gt;&lt;span style="font-family:trebuchet ms;color:#6600cc;"&gt;     public void method1(Object o)&lt;/span&gt;&lt;br /&gt;&lt;span style="font-family:trebuchet ms;color:#6600cc;"&gt;     {&lt;/span&gt;&lt;br /&gt;&lt;span style="font-family:trebuchet ms;color:#6600cc;"&gt;          System.out.print("object");&lt;/span&gt;&lt;br /&gt;&lt;span style="font-family:trebuchet ms;color:#6600cc;"&gt;     }&lt;/span&gt;&lt;br /&gt;&lt;span style="font-family:trebuchet ms;color:#6600cc;"&gt;    public void method1(String s)&lt;/span&gt;&lt;br /&gt;&lt;span style="font-family:trebuchet ms;color:#6600cc;"&gt;    {&lt;/span&gt;&lt;br /&gt;&lt;span style="font-family:trebuchet ms;color:#6600cc;"&gt;          System.out.print("string");&lt;/span&gt;&lt;br /&gt;&lt;span style="font-family:trebuchet ms;color:#6600cc;"&gt;    }&lt;/span&gt;&lt;br /&gt;&lt;span style="font-family:trebuchet ms;color:#6600cc;"&gt;    public static void main(String[] args)&lt;/span&gt;&lt;br /&gt;&lt;span style="font-family:trebuchet ms;color:#6600cc;"&gt;    {&lt;/span&gt;&lt;br /&gt;&lt;span style="font-family:trebuchet ms;color:#6600cc;"&gt;           Test t = new Test();&lt;/span&gt;&lt;br /&gt;&lt;span style="font-family:trebuchet ms;color:#6600cc;"&gt;           t.method1(null);&lt;/span&gt;&lt;br /&gt;&lt;span style="font-family:trebuchet ms;color:#6600cc;"&gt;    }&lt;/span&gt;&lt;br /&gt;&lt;span style="font-family:trebuchet ms;color:#6600cc;"&gt;}&lt;/span&gt;&lt;/pre&gt;&lt;pre&gt;&lt;br /&gt;&lt;span style="font-family:trebuchet ms;"&gt;&lt;/span&gt;&lt;/pre&gt;&lt;br /&gt;&lt;span style="font-family:trebuchet ms;color:#000000;"&gt;When running the program, the output would be &lt;/span&gt;&lt;br /&gt;&lt;span style="font-family:trebuchet ms;color:#000000;"&gt;(a) object&lt;/span&gt;&lt;br /&gt;&lt;span style="font-family:trebuchet ms;color:#000000;"&gt;(b) string&lt;/span&gt;&lt;br /&gt;&lt;span style="font-family:trebuchet ms;color:#000000;"&gt;(c) objectstring&lt;/span&gt;&lt;br /&gt;&lt;span style="font-family:trebuchet ms;color:#000000;"&gt;(d) stringobject&lt;/span&gt;&lt;br /&gt;&lt;span style="font-family:trebuchet ms;"&gt;&lt;/span&gt;&lt;br /&gt;&lt;span style="font-family:trebuchet ms;"&gt;&lt;/span&gt;&lt;br /&gt;&lt;strong&gt;&lt;span style="font-family:trebuchet ms;"&gt;Answer:&lt;/span&gt;&lt;/strong&gt;&lt;br /&gt;&lt;span style="font-family:trebuchet ms;color:#990000;"&gt;(b) string&lt;/span&gt;&lt;br /&gt;&lt;span style="font-family:trebuchet ms;"&gt;&lt;/span&gt;&lt;br /&gt;&lt;strong&gt;&lt;span style="font-family:trebuchet ms;"&gt;Explanation:&lt;/span&gt;&lt;/strong&gt;&lt;br /&gt;&lt;span style="font-family:trebuchet ms;"&gt;It is the hierarchy of objects being searched for a match, which is quite similar to the exception objects of catch blocks. The search process is done in the bottom-up manner wherein the object of class of least node is searched first and its continued upwards to the super/parent classes till the end is reached.&lt;/span&gt;&lt;div class="blogger-post-footer"&gt;&lt;img width='1' height='1' src='https://blogger.googleusercontent.com/tracker/27252087-4702751348898548638?l=teknicallyspeaking.blogspot.com' alt='' /&gt;&lt;/div&gt;</content><link rel='replies' type='application/atom+xml' href='http://teknicallyspeaking.blogspot.com/feeds/4702751348898548638/comments/default' title='Post Comments'/><link rel='replies' type='text/html' href='http://www.blogger.com/comment.g?blogID=27252087&amp;postID=4702751348898548638' title='3 Comments'/><link rel='edit' type='application/atom+xml' href='http://www.blogger.com/feeds/27252087/posts/default/4702751348898548638'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/27252087/posts/default/4702751348898548638'/><link rel='alternate' type='text/html' href='http://teknicallyspeaking.blogspot.com/2007/01/java-q1-what-would-be-output.html' title='Java #Q1: What would be the output?'/><author><name>Raghavan alias Saravanan M</name><uri>http://www.blogger.com/profile/17770791475348776850</uri><email>noreply@blogger.com</email><gd:image rel='http://schemas.google.com/g/2005#thumbnail' width='16' height='16' src='http://img2.blogblog.com/img/b16-rounded.gif'/></author><thr:total>3</thr:total></entry><entry><id>tag:blogger.com,1999:blog-27252087.post-114656559447337665</id><published>2006-05-02T15:53:00.000+05:30</published><updated>2006-05-02T15:57:03.100+05:30</updated><title type='text'>jsfffffff</title><content type='html'>Java Server Faces Notes&lt;br /&gt;=====================&lt;br /&gt;  - M Raghavan alias Saravanan, 13Jan2006 Friday 5:25  PM&lt;br /&gt;&lt;br /&gt; --&gt; JSF - is mainly used to develop the custom UI Parts in any application in a neutral manner.&lt;br /&gt;         (*)to create a standard framework for user interface components for web applications&lt;br /&gt;         (*)JSF lets you build web applications that run on a Java server and render the user interface back to the client&lt;br /&gt;        (*)provides web application lifecycle management through a controller servlet, and a rich component model with event handling and component rendering&lt;br /&gt; --&gt; Though it also follows MVC 2 pattern (separation of presentation logic and business logic) its focus is fully into the VIEW tier, where as &lt;br /&gt; --&gt; Struts is concentrating mainly on the Controller tier. But still there are some overlaps are there between these two frameworks.&lt;br /&gt; --&gt; Integration of these two frameworks is in progress. See Apache site for the same.&lt;br /&gt;&lt;br /&gt; MINIMUM REQUIREMENT:&lt;br /&gt; -----------------------------&lt;br /&gt; --&gt; Works with the Servlet 2.3 or more and JSP 1.2 or more&lt;br /&gt; &lt;br /&gt; Two Main Components of JSF:&lt;br /&gt; ~~~~~~~~~~~~~~~~~~~~~~~~~&lt;br /&gt; (1) Java APIs to represent UI Components, manage state, handle events, and validate Input. (Internationalization and accessibilty!)&lt;br /&gt; (2) Two JSP Custom tag libraries for expressing user interfaces (UI) components within a JSP page and for writing components to server-side objects. Page authors can easily add UI components to their                       pages.&lt;br /&gt;&lt;br /&gt;The UI parts are rendered on the Server and then the rendered output (HTML Of course as most of the clients - browsers are relying on HTML as the Least Common Denominator) is sent to the client on the first.&lt;br /&gt;  &lt;br /&gt;    Browser----&gt;(request for a jsp  page for ex) ----&gt; form.jsp ----&gt; UI  ===&gt; Form rendered with the components&lt;br /&gt;            &lt;!-- Client--!&gt;    &lt;!----     Server      --!&gt;&lt;br /&gt;&lt;br /&gt;&lt;br /&gt;Guidelines/Rules to Use&lt;br /&gt;****************************&lt;br /&gt;   --&gt; In order to user JSF tags, you need to include the taglib directives to the "html" and "core" tag libraries that refer to the standard HTML renderkit library and the JSF core tag library, respectively&lt;br /&gt;   --&gt; A page containing JSF tags is represented by a tree of components whose root is the "UIViewRoot", which is represented by the "view" tag. All component tags MUST BE ENCLOSED in the "view" tag.  Other content such as HTML and other JSP pages can be enclosed within that tag.&lt;br /&gt;   --&gt; A typical JSP page includes a form, which is submitted when a button is clicked. The tags representing the form components (such as textfields and buttons) MUST BE NESTED inside the "form" tag.&lt;br /&gt;&lt;br /&gt;&lt;br /&gt;POINTS TO PONDER:&lt;br /&gt;################&lt;br /&gt;   (1) Value-binding expressions (syntax: #{bean-managed-property}, eg: value="#{UserNumberBean.minimum}")&lt;br /&gt;             (*) minimum is the attribute in the bean class UserNumberBean&lt;br /&gt;   Method-binding expressions (syntax: #{method-name-of-the-bean-to-validate}, eg: validator="#{UserNumberBean.validate}")&lt;br /&gt;              (*) validate is the method in the bean class UserNumberBean&lt;br /&gt;&lt;br /&gt;The Model Object &lt;br /&gt;----------------------&lt;br /&gt;    --&gt; A typical JSF application uses a bean with each page in the application. &lt;br /&gt;    --&gt; The bean defines the properties and methods associated with the UI components used on the page. &lt;br /&gt;    --&gt; A bean can also define a set of methods that perform functions, such as validating the component's data, for the component. &lt;br /&gt;    --&gt; The model object bean is like any other JavaBeans component: it has a set of accessor methods. &lt;br /&gt;&lt;br /&gt;Application Configuration Resource File &lt;br /&gt;------------------------------------------------&lt;br /&gt;An application configuration resource file, "faces-config.xml", is used to define your managed beans, validators, converters, and navigation rules&lt;br /&gt;&lt;br /&gt;Faces Servlet&lt;br /&gt;============&lt;br /&gt;  (*) has to be configured in web.xml (similar to ActionServlet in Struts)&lt;br /&gt;&lt;br /&gt;  --&gt; in order to use the JSF framework in your web applications, you need to define the "FaceServlet and its mapping" in your deployment descript file, web.xml. &lt;br /&gt;  --&gt; This servlet "acts as the FRONT CONTROLLER" and handles "all JSF-related requests"&lt;br /&gt;&lt;br /&gt;JSF Components are organized into categories&lt;br /&gt;********************************************************&lt;br /&gt;   --&gt; Added Components: JSF components you have written or acquired elsewhere and imported into the Java Studio Creator development environment &lt;br /&gt;   --&gt; JSF Standard Components: The basic set of components including form fields, hyperlinks, labels and text. The JSF components are organized into logical groups by function. &lt;br /&gt;   --&gt; JSF Validators/Converters: Components that modify or validate data in other components but are not themselves displayed &lt;br /&gt;   --&gt; Advanced: JSP tags for advanced JSF features. These tags generally do not have a visual appearance and are only useful if you are familiar with both the JSP and JSF technologies. &lt;br /&gt;&lt;br /&gt;Conclusion&lt;br /&gt;###########&lt;br /&gt;  (*) JavaServer Faces (JSF) is a user interface framework for building web applications that run on the server side and render the user interface back to the client. &lt;br /&gt;  (*) It lets you develop tools that simplify coding web-based Java applications&lt;br /&gt;&lt;br /&gt;  (*) JSF requires little more effort than an ordinary JSP configuration -- but with many more benefits&lt;div class="blogger-post-footer"&gt;&lt;img width='1' height='1' src='https://blogger.googleusercontent.com/tracker/27252087-114656559447337665?l=teknicallyspeaking.blogspot.com' alt='' /&gt;&lt;/div&gt;</content><link rel='replies' type='application/atom+xml' href='http://teknicallyspeaking.blogspot.com/feeds/114656559447337665/comments/default' title='Post Comments'/><link rel='replies' type='text/html' href='http://www.blogger.com/comment.g?blogID=27252087&amp;postID=114656559447337665' title='0 Comments'/><link rel='edit' type='application/atom+xml' href='http://www.blogger.com/feeds/27252087/posts/default/114656559447337665'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/27252087/posts/default/114656559447337665'/><link rel='alternate' type='text/html' href='http://teknicallyspeaking.blogspot.com/2006/05/jsfffffff.html' title='jsfffffff'/><author><name>Raghavan alias Saravanan M</name><uri>http://www.blogger.com/profile/17770791475348776850</uri><email>noreply@blogger.com</email><gd:image rel='http://schemas.google.com/g/2005#thumbnail' width='16' height='16' src='http://img2.blogblog.com/img/b16-rounded.gif'/></author><thr:total>0</thr:total></entry><entry><id>tag:blogger.com,1999:blog-27252087.post-114629544033202717</id><published>2006-04-29T12:52:00.000+05:30</published><updated>2006-04-30T13:53:16.666+05:30</updated><title type='text'>just test in teknical stuff</title><content type='html'>&lt;span style="font-family:trebuchet ms;"&gt;hi folks,&lt;/span&gt;&lt;br /&gt;&lt;span style="font-family:trebuchet ms;"&gt;    this just a test post in this teknical stuff..&lt;br /&gt;&lt;br /&gt;Free java e-books, visit &lt;a href="http://www.jvsoft.org/index.html"&gt; http://www.jvsoft.org/index.html&lt;/a&gt;&lt;br /&gt;&lt;/span&gt;&lt;br /&gt;&lt;span style="font-family:trebuchet ms;"&gt;Raghs.&lt;/span&gt;&lt;div class="blogger-post-footer"&gt;&lt;img width='1' height='1' src='https://blogger.googleusercontent.com/tracker/27252087-114629544033202717?l=teknicallyspeaking.blogspot.com' alt='' /&gt;&lt;/div&gt;</content><link rel='replies' type='application/atom+xml' href='http://teknicallyspeaking.blogspot.com/feeds/114629544033202717/comments/default' title='Post Comments'/><link rel='replies' type='text/html' href='http://www.blogger.com/comment.g?blogID=27252087&amp;postID=114629544033202717' title='0 Comments'/><link rel='edit' type='application/atom+xml' href='http://www.blogger.com/feeds/27252087/posts/default/114629544033202717'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/27252087/posts/default/114629544033202717'/><link rel='alternate' type='text/html' href='http://teknicallyspeaking.blogspot.com/2006/04/just-test-in-teknical-stuff.html' title='just test in teknical stuff'/><author><name>Raghavan alias Saravanan M</name><uri>http://www.blogger.com/profile/17770791475348776850</uri><email>noreply@blogger.com</email><gd:image rel='http://schemas.google.com/g/2005#thumbnail' width='16' height='16' src='http://img2.blogblog.com/img/b16-rounded.gif'/></author><thr:total>0</thr:total></entry></feed>
