tag:blogger.com,1999:blog-65658929454743937762024-02-19T17:57:12.288+05:30Passing the SCJP!My journey of facing the SCJP (Sun Certified Java Programmer) Exam.Saurabh Patilhttp://www.blogger.com/profile/02194232716333965729noreply@blogger.comBlogger21125tag:blogger.com,1999:blog-6565892945474393776.post-52887166463299549582016-11-28T04:17:00.003+05:302016-11-28T04:22:48.836+05:30HashMap - how does choosing the load factor affects the time complexity (Big Oh)? <div dir="ltr" style="text-align: left;" trbidi="on">
<span style="font-family: "verdana" , sans-serif;">This post is more about data structure called HashMap rather than Java.</span><br />
<span style="font-family: "verdana" , sans-serif;"><br /></span>
<span style="font-family: "verdana" , sans-serif;"><b>What is a HashMap? </b></span><br />
<span style="font-family: "verdana" , sans-serif;">HashMap is a data structure that is used to store values by first calculating a key for each value by the hashing function and then storing it. This enables to quickly find the element/value later by calculating the hash key again, usually in O(1) time. </span><br />
<span style="font-family: "verdana" , sans-serif;"><br /></span>
<span style="font-family: "verdana" , sans-serif;"><b>What is the load factor? </b></span><br />
<span style="font-family: "verdana" , sans-serif;">HashMap stores elements in buckets. If 2 or more elements hash to the same hash key then they are stored in the same bucket - this situation is called 'collision'. These 2 elements are stored as a linked list. We should avoid collisions because when collision happens the search for that elements takes longer than O(1) time. This is okay when it happens for some elements that we're trying to store but not good if it happens for many elements. When will it happen for many elements? --> when we will have far lesser buckets than the number of elements that we need to store. We need to decide how full our HashMap should be before we enlarge it.. that fullness factor is called load factor and is given by formula n/N where n is the number of elements stored in the hashmap already and N is the number of buckets. You can consider N also to be the initial capacity of the hashmap because the whole point of this data structure is to make the search operation of O(1) and hence it's important to try our best to design it in a way that there are zero collisions. The default load factor for Java's HashMap is 0.75 with initial capacity=16. That means it will increase the size of the hashmap (and hence rehash) when 12th element is inserted. </span><br />
<span style="font-family: "verdana" , sans-serif;"><br /></span>
<span style="font-family: "verdana" , sans-serif;"><b><span style="font-family: "verdana" , sans-serif;">How does choosing the loa</span><span style="font-family: "verdana" , sans-serif;">d factor affects the performance? </span></b></span><br />
<span style="font-family: "verdana" , sans-serif;">You have probably figured out this by now. </span><br />
<br />
<ul style="text-align: left;">
<li><span style="font-family: "verdana" , sans-serif;">More the load factor, late would be the enlarging of the hashmap buckets, so more would be the chances of collisions, so more elements would have search time greater than O(1).</span></li>
<li><span style="font-family: "verdana" , sans-serif;">Less the load factor (say 0.6 instead of 0.75), then we would be enlarging our hashmap capacity earlier - pre</span><span style="font-family: "verdana" , sans-serif;">cisely when almost approximately 40% of buckets are still empty, this means there would be lesser collision scenarios at this stage and even lesser in the new hashmap that would be created with increased size (and hence increased buckets). </span></li>
</ul>
<span style="font-family: "verdana" , sans-serif;">Shoot for any questions if you have in the comments section. :)</span><br />
</div>
Saurabh Patilhttp://www.blogger.com/profile/02194232716333965729noreply@blogger.com0tag:blogger.com,1999:blog-6565892945474393776.post-1320473015876897062015-08-09T10:37:00.002+05:302015-08-09T10:48:49.892+05:30Mastering the Java CLASSPATH<div dir="ltr" style="text-align: left;" trbidi="on">
<div style="text-align: left;">
<br></br>
<span style="font-family: Verdana, sans-serif;">It's important to understand how the java compiler figures out or searches for all the dependent classes it needs to compile a java file it needs to. I won't waste time in writing something that has already been explained beautifully in this article. So go ahead and read this article till you understand it. </span></div>
<div style="text-align: left;">
<span style="font-family: Verdana, sans-serif;"><br /></span></div>
<div style="text-align: left;">
<span style="font-family: Verdana, sans-serif;"><a href="http://kevinboone.net/classpath.html">http://kevinboone.net/classpath.html</a></span></div>
<div style="text-align: left;">
<span style="font-family: Verdana, sans-serif;"><br /></span></div>
<div style="text-align: left;">
<span style="font-family: Verdana, sans-serif;"><b>Some important take-aways: </b></span></div>
<div style="text-align: left;">
</div>
<br />
<ul style="text-align: left;">
<li><span style="font-family: Verdana, sans-serif;">Java compiler and JVM both use the same technique to figure out the dependent classes they need, the only difference is javac compiler can compile the dependent java file too into a class (to use it) if it has not already done. </span></li>
<li><span style="font-family: Verdana, sans-serif;">javac -classpath "" CPTest2.java : This will wipe out the system classpath that you have set on your computer and as we've given an empty string that means the compiler has no way to reference any other class to help build CPTest2.java. </span></li>
<li><span style="font-family: Verdana, sans-serif;">The java compiler and run-time can search for classes not only in separate files, but also in `JAR' archives. But you've to give the complete path to the .jar file and not only upto the directory in which that .jar file is stored. </span></li>
<li><span style="font-family: Verdana, sans-serif;">Usage of system CLASSPATH variable and how to add it to the javac command in case you wanna add something more to what the system CLASSPATH variable has. </span></li>
</ul>
<span style="font-family: Verdana, sans-serif;"><br /></span><span style="font-family: Verdana, sans-serif;">Understanding of how javac and JVM try to figure out the dependent classes is an important understanding to resolve the famous ClassNotFound exceptions. </span><br />
<br />
<br /></div>Saurabh Patilhttp://www.blogger.com/profile/02194232716333965729noreply@blogger.com0tag:blogger.com,1999:blog-6565892945474393776.post-21503436774818863112013-02-25T20:24:00.002+05:302013-02-25T20:26:37.153+05:30If an object becomes eligible for Garbage Collection and its finalize() method has been called and inside this method the object becomes accessible by a live thread of execution and is not garbage collected. Later at some point the same object becomes eligible for Garbage collection, will the finalize() method be called again?<div dir="ltr" style="text-align: left;" trbidi="on">
<br />
Nice question. Isn't it? :)<br />
<br />
I urge you to think about this for a moment before hurrying to the answer.<br />
<br />
.<br />
.<br />
.<br />
finalize() will run only once. Repeat with me, finalize() will run only once! So, the answer to above question is No.<br />
<br />
<br /></div>
Saurabh Patilhttp://www.blogger.com/profile/02194232716333965729noreply@blogger.com0tag:blogger.com,1999:blog-6565892945474393776.post-6683671467942725652013-02-20T11:39:00.000+05:302013-02-25T20:27:17.425+05:30Understanding SQL joins once and for all <div dir="ltr" style="text-align: left;" trbidi="on">
<span style="font-family: Verdana, sans-serif;"><br /></span>
<span style="font-family: Verdana, sans-serif;">Understanding SQL joins is fundamental to any java programmer who needs to fetch data from database. SQL joins can be very confusing. Here is a very simple Venn diagram that help you understand all the important SQL joins pretty quickly.. </span><br />
<br />
<span style="font-family: Verdana, sans-serif;"><br /></span>
<br />
<table align="center" cellpadding="0" cellspacing="0" class="tr-caption-container" style="float: left; margin-right: 1em; text-align: left;"><tbody>
<tr><td style="text-align: center;"><a href="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEhM2Z5-ZzPuthoPBm16_W5ypFeC94cdgZQfqhsOZd0JRUtvS56QOE1DM51ZJKXfTbpu79VHqOxJ7siKjTdgwN2OK7fWIrHN6WRCBiKdZQ55xSXkJo4SEjyg4vpPbLvMjdOaK-KNTlC4Veyh/s1600/sql+joins.jpg" imageanchor="1" style="margin-left: auto; margin-right: auto;"><span style="font-family: Verdana, sans-serif;"><img border="0" height="235" src="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEhM2Z5-ZzPuthoPBm16_W5ypFeC94cdgZQfqhsOZd0JRUtvS56QOE1DM51ZJKXfTbpu79VHqOxJ7siKjTdgwN2OK7fWIrHN6WRCBiKdZQ55xSXkJo4SEjyg4vpPbLvMjdOaK-KNTlC4Veyh/s400/sql+joins.jpg" width="400" /></span></a></td></tr>
<tr><td class="tr-caption" style="text-align: center;"><span style="font-family: Verdana, sans-serif; font-size: small;">SQL Joins Venn Diagram</span></td></tr>
</tbody></table>
<br />
<br />
<div class="MsoNormal" style="margin: 0in 0in 0.0001pt;">
<span style="font-family: Verdana, sans-serif;"><br /></span></div>
<div class="MsoNormal" style="margin: 0in 0in 0.0001pt;">
<span style="font-family: Verdana, sans-serif;"><br /></span>
<span style="font-family: Verdana, sans-serif;"><br /></span>
<span style="font-family: Verdana, sans-serif;"><br /></span>
<span style="font-family: Verdana, sans-serif;"><br /></span>
<span style="font-family: Verdana, sans-serif;"><br /></span>
<span style="font-family: Verdana, sans-serif;"><br /></span>
<span style="font-family: Verdana, sans-serif;"><br /></span>
<span style="font-family: Verdana, sans-serif;"><br /></span>
<span style="font-family: Verdana, sans-serif;"><br /></span>
<span style="font-family: Verdana, sans-serif;"><br /></span>
<span style="font-family: Verdana, sans-serif;"><br /></span>
<span style="font-family: Verdana, sans-serif;"><br /></span><span style="font-family: Verdana, sans-serif;"><br /></span>
<span style="font-family: Verdana, sans-serif;">INNER JOIN: </span></div>
<div class="MsoNormal" style="margin: 0in 0in 0.0001pt;">
<span style="font-family: Verdana, sans-serif;">Select only those rows that have values in common in the columns specified in the ON clause. Records available in both the tables. <o:p></o:p></span></div>
<div class="MsoNormal" style="margin: 0in 0in 0.0001pt;">
<br /></div>
<div class="MsoNormal" style="margin: 0in 0in 0.0001pt;">
<span style="font-family: Verdana, sans-serif;">LEFT, RIGHT, or FULL OUTER JOIN: </span></div>
<div class="MsoNormal" style="margin: 0in 0in 0.0001pt;">
<span style="font-family: Verdana, sans-serif;">Select all rows from the table on the left (or right, or both) regardless of whether the other table has values in common and (usually) enter NULL where data is missing. (Note: FULL OUTER JOIN not implemented in Access.)</span></div>
<div class="MsoNormal" style="margin: 0in 0in 0.0001pt;">
<br /></div>
<div class="MsoNormal" style="margin: 0in 0in 0.0001pt;">
<span style="font-family: Verdana, sans-serif;">CROSS JOIN:</span></div>
<div class="MsoNormal" style="margin: 0in 0in 0.0001pt;">
<span style="font-family: Verdana, sans-serif;">Select all possible combinations <span class="GramE">of rows</span> and columns from both tables (Cartesian product). If tableA has n records and tableB has m records then a cross join will produce n x m results.. joining every records from tableA with every single record from tableB. So if tableA has 30 records and tableB has 35 records the cross join will produce 30x35 = 1050 records in the result set. (This is Not A Good join - the query may run for a very long time and produce a huge, not very useful result set.) <o:p></o:p></span></div>
<div class="MsoNormal" style="margin: 0in 0in 0.0001pt;">
<span style="font-family: Verdana, sans-serif;"> </span></div>
<div class="MsoNormal" style="margin: 0in 0in 0.0001pt;">
<span style="font-family: Verdana, sans-serif;">MINUS:</span></div>
<div class="MsoNormal" style="margin: 0in 0in 0.0001pt;">
<span style="font-family: Verdana, sans-serif;">You get this by specifying a where clause saying not to include records having a match in tableB. </span></div>
<div class="MsoNormal" style="margin: 0in 0in 0.0001pt;">
<span style="font-family: Verdana, sans-serif;"><br /></span></div>
<div class="MsoNormal" style="margin: 0in 0in 0.0001pt;">
<span style="font-family: Verdana, sans-serif;">Note:</span></div>
<div class="MsoNormal" style="margin: 0in 0in 0.0001pt;">
<span style="font-family: Verdana, sans-serif;">There is nothing like left inner join or right inner join. They both mean inner join, they all are one and the same. </span></div>
<div class="MsoNormal" style="margin: 0in 0in 0.0001pt;">
<span style="font-size: 11pt;"><span style="font-family: Verdana, sans-serif;"><br /></span></span></div>
</div>
Saurabh Patilhttp://www.blogger.com/profile/02194232716333965729noreply@blogger.com0tag:blogger.com,1999:blog-6565892945474393776.post-12590375208863180542013-02-11T09:02:00.002+05:302013-02-11T09:02:39.130+05:30Can we override the main method() ?<div dir="ltr" style="text-align: left;" trbidi="on">
<div class="tr_bq">
<br /></div>
<div class="tr_bq">
Technically the answer is NO. </div>
<br />
> Main method is a static method.<br />
> Static methods belong to the class and not to the objects.<br />
> If you extend a Parent class having main method the child class doesn't have the parent class's main method so there is no question about overriding it.<br />
> You can write your own main method in the child class but that would be again a static method of the child class and would have nothing to do with the main method of the parent class.<br />
<br />
Following code will compile and will execute fine...<br />
<i><br /></i>
<blockquote>
<i>public class Parent{<br /> public static void main(String args[]){<br /> System.out.println("In Parents main method..");<br />}<br />class child extends Parent{<br /> public static void main(String args[]){<br /> System.out.println("In childs main method..");<br />}</i></blockquote>
You can even call the main method of other class from one class directly as its a static method!!<br />
<br />
Any questions??</div>
Saurabh Patilhttp://www.blogger.com/profile/02194232716333965729noreply@blogger.com0tag:blogger.com,1999:blog-6565892945474393776.post-89002800317657408372010-04-19T12:06:00.000+05:302010-04-19T12:06:39.543+05:30Getting current date and time in java<span style="font-family: Verdana, sans-serif;">When you are programming something you may need the current date and current time, say like while naming the reports you want to include the date and time at which the report was generated, so in this case you want to write code that will generate the current date and time. This is a very basic thing and every java programmer should know this.</span><br />
<span style="font-family: Verdana, sans-serif;"><br />
</span><br />
<span style="font-family: Verdana, sans-serif;">We will be using two important classes for this...</span><br />
<span style="font-family: Verdana, sans-serif;">1. java.util.Calendar</span><br />
<span style="font-family: Verdana, sans-serif;">2. java.text.SimpleDateFormat</span><br />
<span style="font-family: Verdana, sans-serif;"><br />
</span><br />
<span style="font-family: Verdana, sans-serif;">And here goes the simple code...</span><br />
<br />
<span style="font-family: "Courier New", Courier, monospace;">Calendar cal = Calendar.getInstance();</span><br />
<span style="font-family: "Courier New", Courier, monospace;">SimpleDateFormat sdf = new SimpleDateFormat("dd:MM:yyyy - HH:mm:ss");</span><br />
<span style="font-family: "Courier New", Courier, monospace;">System.out.println(sdf.format(cal.getTime()));</span><br />
<span style="font-family: Verdana, sans-serif;"></span> <br />
<span style="font-family: Verdana, sans-serif;">Instead of " : " you can have " _ " or any other such differentiator it doesn''t matter. But you need to take care of the Caps of "MM" and "HH". Also note that "YYYY" will not work. Try yourself for everything else.. </span><br />
<span style="font-family: Verdana, sans-serif;"></span> <br />
<span style="font-family: Verdana, sans-serif;">Most importantly note that we are passing the current time as a parameter to the format function of SimpleDateFormat.</span> <br />
<span style="font-family: Verdana, sans-serif;"></span> <br />
<span style="font-family: Verdana, sans-serif;"></span> <br />
<span style="font-family: Verdana, sans-serif;"></span> Saurabh Patilhttp://www.blogger.com/profile/02194232716333965729noreply@blogger.com0tag:blogger.com,1999:blog-6565892945474393776.post-53260652582567464022010-04-13T19:14:00.002+05:302010-04-13T19:19:54.046+05:30When should a class be Static? - A realistic scenario.<div style="text-align: justify;"></div><div style="text-align: justify;"><span style="font-family: Verdana, sans-serif; font-size: x-small;"></span></div><div style="text-align: justify;"><span style="font-family: Verdana, sans-serif;">After learning how the word Static plays its magic, it's important to know when can that be used in a realistic scenario. I will share an experience where I learnt a classic example of when a class should be static.</span></div><div style="text-align: justify;"><br />
</div><div style="text-align: justify;"><span style="font-family: Verdana, sans-serif;">I was developing a class which was going to provide some helper methods for a functionality, say like it was a class which used to do all the data gathering part. So the methods in it were connecting with the database, constructing the query on basis of the input, getting the data, filling it into a collection (e.g: Map or TreeMap) and returning it to the calling function. The functions of this class were to be called by many other classes which were not static (or non-static..it doesn't really matter.) Let's call this class as Helper class. And other calling classes as A, B and C classes.</span></div><div style="text-align: justify;"><br />
</div><div style="text-align: justify;"><span style="font-family: Verdana, sans-serif;">I first made the Helper class non-static. I always questioned myself why it should be static...there is no need! And that was correct! This class could have been non-static! When it is not static, the calling class A needs to create an instance and then call the methods of the Helper class. Like this...</span></div><div style="text-align: justify;"><br />
</div><div style="text-align: justify;"><span style="font-family: "Courier New", Courier, monospace;">Helper help = new Helper();</span></div><div style="text-align: justify;"><span style="font-family: "Courier New", Courier, monospace;">help.getCutomerData(param1,param2,param3) ;</span></div><div style="text-align: justify;"><br />
</div><div style="text-align: justify;"><span style="font-family: Verdana, sans-serif;">There was nothing technically wrong with it... but.. as we say..this was a realistic scenario.</span></div><div style="text-align: justify;"><br />
</div><div style="text-align: justify;"><span style="font-family: Verdana, sans-serif;">I began to think on these lines - does the Helper class has any instance variables? does it have any state? Or is it just a class with methods which help the calling classes? Are the methods using any instance variable? Is any output of the methods stored in the instance variables?? Answer to all these questions was No. I do not need to maintain the state of that class, it was okay if I make it static and the calling function calls directly the methods of the static Helper class. Thus this class has to be made static. </span></div><div style="text-align: justify;"><br />
</div><div style="text-align: justify;"><span style="font-family: Verdana, sans-serif;">The calling class can call the non-static methods of this static Helper class by this way...</span></div><div style="text-align: justify;"><br />
</div><div style="text-align: justify;"><span style="font-family: "Courier New", Courier, monospace;">Helper.getCustomerData(param1,param2,param3);</span></div><div style="text-align: justify;"><br />
</div><div style="text-align: justify;"><span style="font-family: Verdana, sans-serif;">Simple! Crisp! Logical!</span></div>Saurabh Patilhttp://www.blogger.com/profile/02194232716333965729noreply@blogger.com1tag:blogger.com,1999:blog-6565892945474393776.post-28552256801073027132008-09-27T16:43:00.005+05:302008-09-27T16:58:40.932+05:30Not to depend on the Dumps or Question Banks!!<div style="text-align: justify; font-family: verdana;">Hello friends,<br /><br />First my apologies for not being regular in posting exciting articles as before. I will be regular now onwards.<br /><br />I am back with a piece of advice for you all. Please do not depend on the dumps/question bank or any other source which anyone provides you saying,"hey, just read these 200 questions and you will get most of the question from this only!" That sentence is partially true! But partially! You will never score high if you depend only on these question banks. Yes they claim that these are real questions from exams remembered from the people who have v the exams, and many other ways - I don't know. But it's the truth that these will only degrade you. Studying java passionately and then going and giving the exam needs guts, practice and will power to do it - lets what ever the result may be. <span style="font-style: italic;">And if you really study hard SCJP is really not that difficult! Keep this in mind!!</span><br /><br />The number of questions repeated are very very low as compared to what the people selling these question sets say. And anyways knowledge lives forever, what if in the future you cleared SCJP with 90% and were not able to make a proper synchronized method, or unable to solve a simple NullPointerException! That will be so insulting for you! Clear the SCJP with knowledge and hard work, and it will definately pay you back!<br /></div>Saurabh Patilhttp://www.blogger.com/profile/02194232716333965729noreply@blogger.com5tag:blogger.com,1999:blog-6565892945474393776.post-21283451027520910932008-09-11T22:37:00.005+05:302008-09-11T23:02:05.802+05:30What are inner classes?<div style="text-align: justify;"><span style="font-family: verdana;"><br />This topic is not for beginners or those at intermediate level. Not very difficult but may result in headache sometimes. So lets understand what are inner classes or nested classes - as some call them.</span><br /><br /><span style="font-weight: bold; font-family: verdana;">Inner class</span><span style="font-family: verdana;"> - as the name says are inside a class. Normal classes which we see are called outer classes because they are directly inside a file and not inside another class. Hey, if you are wondering whether a class can be inside a class?? Yes, it can be. But there are various complications in its use, and I suggest in real life not to use it unless they are unavoidable. But SCJP exam contains questions about such complex things..so its a very important concept. And hey its not boring, its very interesting topic... I will try to make it more interesting!</span><br /><br /><span style="font-family: verdana;">OK, let's see how a inner class looks like...</span><br /><br /><span style="font-family: verdana;">class A{</span><br /><span style="font-family: verdana;">int a;</span><br /><br /><span style="font-family: verdana;">class B{</span><br /><span style="font-family: verdana;">int b;</span><br /><br /><span style="font-family: verdana;">}//class B ends</span><br /><br /><span style="font-family: verdana;">}// class A ends</span><br /><br /><span style="font-family: verdana;">You can clearly see that B is </span><span style="font-style: italic; font-family: verdana;">inside</span><span style="font-family: verdana;"> A. When we create object of class A it doesn't mean we create object of inner class B also. We have to explicitly create object of inner class B. The inner classes can also be static! Yes, they can be. Also there can be more than one inner classes inside a class. You can create objects of them independently. Inner classes can have variables and methods as other classes... the members can be static, final etc.. The concept of Inner classes is not that simple, I thought to keep the first post easy, I will come with the difficult scenarios related to inner classes soon...</span><br /><br /><span style="font-family: verdana;">If you have any basic questions about inner classes, they do fire them in the comments section.. also try to code yourself, that is first thing to do when you don't understand anything.</span></div>Saurabh Patilhttp://www.blogger.com/profile/02194232716333965729noreply@blogger.com0tag:blogger.com,1999:blog-6565892945474393776.post-58076111461829929332008-08-31T08:06:00.003+05:302008-08-31T08:16:12.588+05:30Enum - tricky ones...<div align="justify"><span style="font-family:verdana;"></span> </div><div align="justify"><span style="font-family:verdana;">I was reading something regarding enums yesterday and found two interesting things which I feel I should share with my readers. These are very simple things for those who already know it but may be surprising for those who don't...<br /><br /><strong>- Enums are not expandable at runtime.</strong><br />So, suppose you have somethings like<br />enum Car { HONDA, MERC };<br />then you cannot add another car say FORD as 3rd constant in the list at runtime. You can have as many references you can to point to the enum constants.<br /><br /><strong>- ; is unnecessary at the end of enum definition!</strong> :)<br />Yeh, this is quite funny and surprising, don't know why java developers didn't do it mandatory. Exam may have questions with multiple code sentences in single line, so look out properly where ; is necessary and where it isn't. And now u know that there is no need of ; after } when the enum definition completes.<br /><br />Thanks!</span></div>Saurabh Patilhttp://www.blogger.com/profile/02194232716333965729noreply@blogger.com0tag:blogger.com,1999:blog-6565892945474393776.post-27125550958293295332008-08-24T12:39:00.005+05:302008-08-24T19:11:46.366+05:30Types of Variables...<div align="justify"><span style="font-family:verdana;">Well it is important to know what are the types of variables because there behaviour and their life and death is directly related to their type! There are 6 types of variables and I classify them on basis of 2 things to make you understand better.<br /><br />- Depending upon what a variable holds they are classified as<br />1. Primitive Variable<br />2. Reference Variable<br /><br />- Depending upon where they are created they are classified as<br />1. Class variable ( also called static variables)<br />2. Instance variable<br />3. Method Parameter<br />4. Local Variable.<br /><br />Let's go one by one to understand them. A <strong>primitive variable</strong> is one which holds the primitive e.g: an int, a char etc. A <strong>reference variable</strong> is one which holds an object of any class, it can be java API class like String or your wn created class. A <strong>class variable</strong> is one which is a static variable and inside the class definition. This variable is created when the class loads in the memory and stays there till the class is in the memory. A class variable is not attached to any instance of that class. A <strong>instance variable </strong>is a non-static member of which is attached to the specific instance of the class. It is reated when a class instance is created and stays in memory untill that instance is in the memory. A <strong>method parameter</strong> is one which we write in method definition to accept the method arguments the method call is passing to it. This thing will be clear after you see the following example. And lastly a <strong>local variable</strong> is the one which is declared inside a method body, it is also sometimes called method variable.<br /><br />Lets take an example to show each type of variable and identify there types..<br /></div></span><div align="justify"><span style="font-family:verdana;">class City</span></div><div align="justify"><span style="font-family:verdana;">{</span></div><div align="justify"><span style="font-family:verdana;"> static int name;</span></div><div align="justify"><span style="font-family:verdana;"> Lake l; </span></div><div align="justify"><span style="font-family:verdana;"> int road;</span></div><div align="justify"><span style="font-family:verdana;"> void getDistance(City c )</span></div><div align="justify"><span style="font-family:verdana;"> {</span></div><div align="justify"><span style="font-family:verdana;"> int distance;</span></div><div align="justify"><span style="font-family:verdana;"> }</span></div><div align="justify"><span style="font-family:verdana;">}</span></div><div align="justify"><span style="font-family:verdana;"></span> </div><div align="justify"><span style="font-family:verdana;">Here,</span></div><div align="justify"><span style="font-family:verdana;"><em>distance</em> is method variable,</span></div><div align="justify"><span style="font-family:verdana;"><em>c</em> is method parameter,</span></div><div align="justify"><span style="font-family:verdana;"><em>road </em>is instance variable,</span></div><div align="justify"><span style="font-family:verdana;"><em>l</em> is reference variable,</span></div><div align="justify"><span style="font-family:verdana;"><em>name </em>is class variable</span></div><div align="justify"><span style="font-family:verdana;"></span> </div><div align="justify"><span style="font-family:verdana;">I hope you got it now.. if not fire the doubts in comments! :)</span></div>Saurabh Patilhttp://www.blogger.com/profile/02194232716333965729noreply@blogger.com1tag:blogger.com,1999:blog-6565892945474393776.post-74878274184602478182008-08-09T10:13:00.007+05:302008-08-09T11:03:06.145+05:30Some strange facts about Constructors...<div align="justify"><span style="font-family:verdana;"></span></div><div align="justify"><span style="font-family:verdana;"><br>Although you would have written many constructors before, I am sure you will find some suprises in following facts about constructors. To start with a constructor is nothing but a piece of code of class with same name as that of class which is called whenever an object is created of that class. Now understand following things one by one...</span></div><div align="justify"><span style="font-family:verdana;"></span></div><div align="justify"><span style="font-family:verdana;"></span></div><div align="justify"><span style="font-family:verdana;"><br>1.If you don't write a constructor for yourself the compiler will insert one - this is call a default constructor. Constructors can have arguments and there can be a no-argument constructor. Compiler inserted constructor will always be a no-arg constructor.</span></div><div align="justify"><span style="font-family:verdana;"></span></div><div align="justify"><span style="font-family:verdana;"></span></div><div align="justify"><span style="font-family:verdana;"><br>2. Constructors can take any number of arguments, even var-args i.e.: variable arguments. (More on this in a few days.) </span></div><div align="justify"><span style="font-family:verdana;"></span></div><div align="justify"><span style="font-family:verdana;"></span></div><div align="justify"><span style="font-family:verdana;"><br>3. Constructors <strong>cannot</strong> <strong>be</strong> marked <strong>final or static or abstract</strong>. Because final, static and abstract keywords are for methods, variables and classes. You can consider that constructors implicitly have final kind of behaviour because they are never inherited! They are not methods beware!</span></div><div align="justify"><span style="font-family:verdana;"></span></div><div align="justify"><span style="font-family:verdana;"></span></div><div align="justify"><span style="font-family:verdana;"><br>4. Constructors <strong>cannot have a return type</strong>! This is a very important and perhaps the only criteria to recognise quickly whether the given entity is a method or constructor. A method should have return type but a constructor should never have a return type. A method can have same name as that of the class - its perfectly legal! :)</span></div><div align="justify"><span style="font-family:verdana;"></span></div><div align="justify"><span style="font-family:verdana;"></span></div><div align="justify"><span style="font-family:verdana;"><br>5. Constructors are <strong>never inherited</strong>! Again...they aren't methods!! You can remember like this - "Constructors are not passed to the younger generation."</span></div><div align="justify"><span style="font-family:Verdana;"></span></div><div align="justify"><span style="font-family:verdana;"></span></div><div align="justify"><span style="font-family:verdana;"><br>6. Whenever a object has to be created then the constructor of that class has to get called and also the constructors of all its super classes should get called. For example if A is parent of B and B is parent of C then to create an object of C we will call C's constructor which in turn will automatically call the constructors of class B and which inturn will call A's constructor and which inturn will call Object's constructor - as by default class A is child of class Object! Remember that the automatically inserted super class constructor call will be always to the no-arg constructor. If you find it a bit difficult then fire your questions in comments.</span></div><div align="justify"><span style="font-family:Verdana;"></span></div><div align="justify"><span style="font-family:verdana;"></span></div><div align="justify"><span style="font-family:verdana;"><br>7. Constructors can use <strong>any access modifier</strong>. They can use private, protected and public access modifiers. And if nothing is written they have the default one- package level access. Start thinking why anyone would want to make a private constructor! :)</span></div><div align="justify"><span style="font-family:verdana;"></span></div><div align="justify"><span style="font-family:verdana;"></span></div><div align="justify"><span style="font-family:verdana;"><br>8. Constructors can be over loaded and hence there can be more than one constructors for a single class. A constructor can call other constructor by the keyword <strong><em>this.</em></strong> A call to another constructor with single argument looks like <strong><em>this(i);</em></strong> .A constructor can even explicitly call its super class constructor by keyword <strong><em>super</em></strong>. A call to parent's constructor with no argument looks like <strong><em>super();</em></strong> . The first statement of every constructor should be a call to <strong><em>this </em></strong>or<strong><em> super.</em></strong></span></div><div align="justify"><span style="font-family:verdana;"></span></div><div align="justify"><span style="font-family:verdana;"></span></div><div align="justify"><span style="font-family:verdana;"><br>9. And here's the most stuning one - <strong>Abstract classes have constructors</strong>! They are called whenever any object of its subclass is created. So the bottom line is every class has a constructor.</span></div><div align="justify"><span style="font-family:verdana;"></span></div><div align="justify"><span style="font-family:verdana;"></span></div><div align="justify"><span style="font-family:verdana;"><br>10. Interfaces do not have a constructor. An interface is just a contract, a contract to fulfill the implementation of some methods, remember that.</span></div><div align="justify"><span style="font-family:Verdana;"></span></div><div align="justify"><span style="font-family:verdana;"></span></div><div align="justify"><span style="font-family:verdana;"><br>11. You can have call to both <strong><em>this( )</em></strong> and<strong><em> super( )</em></strong> in the same constructor. You can have them one inside other, but not both in any single constructor.</span></div><div align="justify"><span style="font-family:verdana;"></span></div><div align="justify"><span style="font-family:verdana;"></span></div><div align="justify"><span style="font-family:verdana;"><br>Hoossh.. that's all what I can remember right now.. curse my neurotic RAM! If I find anything else I will update the list. If you have any question, then do comment..as you have seen I reply to every question asked. </span></div><div align="justify"><span style="font-family:Verdana;">C ya,</span></div>Saurabh Patilhttp://www.blogger.com/profile/02194232716333965729noreply@blogger.com5tag:blogger.com,1999:blog-6565892945474393776.post-10047981081865079002008-07-19T14:42:00.012+05:302008-07-19T15:21:02.989+05:30Can a local variable be static..? uhh..why not?<div align="justify"><span style="font-family:verdana;"><strong>No!</strong> - that's a very straight forward answer to that question and most simple one. In java the local variables can not be static - burn this in your mind. <strong>But Why??</strong>. The local variables are those which are declared inside a method body, so they have scope only for the method execution period. Any static thing in java belongs to the class and not to the instance. Whenever the method is called the method variables are in the memory area of the thread executing that method, so they are on stack. On the other hand the objects and static members of a class are on heap. Static things are to live throughout the method calls and when they are inside the method body (on stack) they can't live outside the scope of method, hence its ridiculous and illogical to have static variables inside a method body. </span></div><div align="justify"><span style="font-family:verdana;">For the exam, you need not know why, just remember that a local variable can never be static - compiler will complain.</span></div>Saurabh Patilhttp://www.blogger.com/profile/02194232716333965729noreply@blogger.com0tag:blogger.com,1999:blog-6565892945474393776.post-44125616058718652632008-07-08T09:28:00.008+05:302008-07-08T10:11:01.925+05:30File name and class name should be same?<div align="justify"><span style="font-family:verdana;"></span></div><span style="font-family:verdana;"><div align="justify"><br />There is a relation between the name of java source file and the public classes you can declare in that file - only the public classes..okay..not classes with any other access level. Hey by the way do you know which access modifiers can be applied to the outer classes/non-inner classes?...that will be a fantastic post in itself...coming soon.. :) So, coming back to the point, yes there is a constraint on the file name when you want to declare a class in the file as public. <strong>The constraint is that the file name should be same as that of your public class name.</strong></span></div><span style="font-family:verdana;"><div align="justify"><br /></div></span><div align="justify"><span style="font-family:verdana;">But it's not that simple to understand by this single sentence, when I heard first time about this thing I had following <strong>doubts</strong>:</span><span style="font-family:verdana;"><br /></div></span><div align="justify"><span style="font-family:verdana;"></span></div><span style="font-family:verdana;"><div align="justify"><br /></div></span><div align="justify"><span style="font-family:verdana;">1. Can I have more than one public classes in my java file?</span></div><span style="font-family:verdana;"><div align="justify"><br /></div></span><div align="justify"><span style="font-family:verdana;">2. Should the class be public to be called by the JVM ?</span></div><span style="font-family:verdana;"><div align="justify"><br /></div></span><div align="justify"><span style="font-family:verdana;">3.If a class is not public but has a main method can it be called by the JVM? If yes then how the hell is it possible??? And if not ...why?? what's the problem in that??</span><span style="font-family:verdana;"><br /></div></span><div align="justify"><span style="font-family:verdana;"></span></div><span style="font-family:verdana;"><div align="justify"><br /></div></span><div align="justify"><span style="font-family:verdana;">There is no simple solution to these questions than coding for yourself and thats what I did! </span></div><span style="font-family:verdana;"><div align="justify"><br /></div></span><div align="justify"><span style="font-family:verdana;">Take a look at the code carefully, it's in the java source file named as <strong>example6.java</strong></span></div><div align="justify"><strong><span style="font-family:verdana;"></span></strong></div><p align="justify"><span style="font-family:verdana;"><img id="BLOGGER_PHOTO_ID_5220493183744949282" style="DISPLAY: block; MARGIN: 0px auto 10px; CURSOR: hand; TEXT-ALIGN: center" alt="" src="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEiCqTD_jcp-2CoCwx8j1AJysjWShpXf9P8uJGF_dtiPEMeg2CD8BPaWUi3ctybZx0mCGxryRxqCidM0Ml5NHibfwh4aVQTu1DlOsQMppS0H27hDpdV3Bi_92dAKcORlIdX-Eng0TZqklh4a/s400/qqq.JPG" border="0" /></span></p><p align="justify"><span style="font-family:verdana;">Let me tell you some things in this example. The source file name is example6.java and there is no class called as <em>example6</em> in the source file. There are two classes <em>class1</em> and <em>class2</em> which are not public! </span></p><p align="justify"><span style="font-family:verdana;"><strong><u>Doubts Answered:</u></strong></span></p><p align="justify"><span style="font-family:verdana;">1. NO! I tried to give public access to class1 and class2 and compiler scolded me for two things - one he said that <em>class1</em> <strong>if public</strong> should be declared in file named <em>class1.java,</em> other is - there can't be any two public classes in a single java file.</span></p><p align="justify"><span style="font-family:verdana;">2. Not al all! You can see that class1 and class2 are not public, still I am calling both of them!</span></p><p align="justify"><span style="font-family:verdana;">3. Yes it can be called if it has a main method! You can see that class1 is not public but has a main method, so I can call it by giving parameter <em>class1</em> to the java command.</span></p><p align="justify"><span style="font-family:verdana;">I hope you have throughly understood the constraints. Just to revise all, here is the conclusion...</span></p><p align="justify"><span style="font-family:verdana;"><strong><u>Conclusion</u></strong>: The above program proves that...</span></p><p align="justify"><span style="font-family:verdana;">1.There is no need that the classes whose main method you are going to call should be public.</span></p><p align="justify"><span style="font-family:verdana;">2.File name can be anything as long as you dont have any public classes in your file.</span></p><p align="justify"><span style="font-family:verdana;">3.Which main method will execute only depends upon which classname you pass to the JVM that is as argument to java command.</span></p><p align="justify"><span style="font-family:verdana;">4. If you want global access of a class and hence declare that class as public then it should be in the same file as the class name, and as you cant have two different names for a single file you can't have two public classes in a single .java file!</span></p>Saurabh Patilhttp://www.blogger.com/profile/02194232716333965729noreply@blogger.com10tag:blogger.com,1999:blog-6565892945474393776.post-70742709243514305762008-07-06T16:58:00.004+05:302008-07-06T17:21:58.304+05:30Difference: positive zero 0 and negative zero -0 ?<div align="justify"><span style="font-family:verdana;"><br /></div></span><br /><div align="justify"><span style="font-family:verdana;"> Recently I have come across some strange things. I know that java language takes positive and negative zero differently than our logical mathematical brain will take. Well the two are certainly different but how does java identifies them? Or more basic question... does java even differenciate between positive and negative zero? The truth is that <strong>IEEE floating point specification</strong> differentiates between positive and negative zero, but <strong>the java specification says that positive zero is equal to negative zero</strong>. Please go through the following code and see if you can satisfy your questions...</span></div><div align="justify"><span style="font-family:Verdana;"></span> </div><img id="BLOGGER_PHOTO_ID_5219867200179438146" style="DISPLAY: block; MARGIN: 0px auto 10px; CURSOR: hand; TEXT-ALIGN: center" alt="" src="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEjg6ekbz1nQSk-NjM4mUv8x4WswqNUgcYlWP-Ef76Se4VYX0CoqFqBYy2ChyphenhyphenyTVQyLCpujgbd0vdusctemU_Hipa8nGxKwKhz6-gB_sGcs_7NAyEKQYVO5BM1MYW9EM6fsDVQkGsFxTt2b1/s400/example4.JPG" border="0" /> <p align="justify"><span style="font-family:verdana;"> I am still not able to understand why I am not getting -0 at 2nd and 4th place. I have posted this in javaranch forums, lets see if I can get some clarification. If you have the answer please comment.</span></p>Saurabh Patilhttp://www.blogger.com/profile/02194232716333965729noreply@blogger.com1tag:blogger.com,1999:blog-6565892945474393776.post-11874431515094113712008-07-02T09:45:00.008+05:302008-07-02T10:15:49.864+05:30Java is pass by value.....Always! - Part2<div align="justify"><span style="font-family:verdana;">In the last post we saw what exactly pass by value and pass by reference means and strictly speaking its a fact that there is nothing like pass by reference in java. So we can say that java is pass by value...always! This post is a continuation so if you havn't please go through the first part - </span><a href="http://passingscjp.blogspot.com/2008/06/java-is-pass-by-valuealways.html"><span style="font-family:verdana;">Java is pass by Value.....Always! - Part1</span></a><span style="font-family:verdana;"><br /><br />However note that, for the clarity of understanding the pass by value is when we pass a value and pass by reference is when we pass a reference to something.<br />Now lets look at the code which demonstrates pass by value and pass by reference.<br /><br />Suppose there is a class TV, which contains a string which shows its state and its setters and getters.(Note:For the time please forget about the access modifiers..etc because this is just to make you understand one concept..I havnt run this program so it may have some errors/exceptions. But this code is perfect to make you understand what you need to at this point of time.)<br /><br /><br />class TV</span></div><div align="justify"><span style="font-family:verdana;">{<br /> string state; // this stores whether TV is currently ON or OFF<br /><br /> TV(string h)<br />{<br />this.state=h; //constructor assign a state for new TV object<br />}<br /><br />setState(string s)<br />{<br />this.state=s;<br />}<br /><br />string getState()<br />{<br />return(state);<br />}<br />}<br /><br />The following code will demonstrate the pass by value with variable i and pass by reference with references remote1 and remote2.<br /><br />class example1<br />{<br />int i=2;<br />public static void main()<br />{<br />TV remote1= new TV("OFF");<br />func2(i);<br />func3(remote1);<br />}<br /><br />func2(int j)<br />{<br />System.out.println(j); // this will print 2<br />j=3;<br />System.out.println(j); // this will print 3<br />System.out.println(i); // this will print 2<br />}<br /><br /><br />func3(TV remote2)<br />{<br />System.out.println(remote2.getState()); //this will print OFF<br />remote2.setState("ON");<br />System.out.println(remote1.getState()); //this will print ON<br />System.out.println(remote2.getState()); //this will print ON<br />}<br /><br />}<br /><br /><br />Here i and j are variables and they are independant of eachother. remote1 and remote2are references and they point to the same object, so both can turn on and off the same TV!<br /><br />Have some doubts still? Go..on.. post a comment.. I will try my best to answer. </span></div>Saurabh Patilhttp://www.blogger.com/profile/02194232716333965729noreply@blogger.com0tag:blogger.com,1999:blog-6565892945474393776.post-87404397157209367242008-06-29T18:26:00.007+05:302008-06-29T18:47:37.301+05:30Rules for legal identifiers...<div align="justify"><span style="font-family:verdana;"><br /></div></span><div align="justify"><span style="font-family:verdana;">The SCJP exam wants you to know perfectly the rules which define legal and illegal identifiers names. Make sure you know this perfectly as there is no excuse for this. Read the following carefully and you will understand it's not that difficult:</span></div><div align="justify"><span style="font-family:verdana;"></span></div><div align="justify"><br /></div><div align="justify"><span style="font-family:verdana;"><strong>Rules for Legal Identifier Names</strong>:</span></div><div align="justify"><br /></div><div align="justify"><span style="font-family:verdana;">1. Identifiers must start with a letter, a currency character ($), or a connectingcharacter such as the underscore ( _ ). Identifiers cannot start with a number!</span></div><div align="justify"><span style="font-family:Verdana;"></span></div><div align="justify"><span style="font-family:Verdana;"></span></div><div align="justify"><span style="font-family:verdana;"></div></span><div align="justify"><span style="font-family:verdana;"><br>2. After the first character, identifiers can contain any combination of letters, currency characters, connecting characters, or numbers.</span></div><div align="justify"><span style="font-family:Verdana;"></span></div><div align="justify"><span style="font-family:Verdana;"></span></div><div align="justify"><span style="font-family:verdana;"></div></span><div align="justify"><span style="font-family:verdana;"><br>3. In practice, there is no limit to the number of characters an identifier cancontain.</span></div><div align="justify"><span style="font-family:verdana;"></span></div><div align="justify"><br /></div><div align="justify"><span style="font-family:verdana;">4. You can't use a Java keyword as an identifier. Following figure lists all of the Java keywords including one new one for 5.0, enum.</span></div><div align="justify"></div><div align="justify"><span style="font-family:Verdana;"></span></div><div align="justify"><span style="font-family:verdana;"></span></div><div align="justify"><span style="font-family:verdana;"><br>5. Identifiers in Java are case-sensitive; so pen and PEN are two different identifiers.</span></div><div align="justify"><br /></div><div align="justify"><span style="font-family:verdana;"></span></div><div align="justify"><span style="font-family:verdana;">The list of Java 1.5 Keywords follow -</span></div><div align="justify"><span style="font-family:verdana;"><img id="BLOGGER_PHOTO_ID_5217287908013497490" style="DISPLAY: block; MARGIN: 0px auto 10px; CURSOR: hand; TEXT-ALIGN: center" height="204" alt="" src="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEjv00aozp0kzhVzTcayZxPhxcmyl-H9pLjxaMfB1A-OC8OUAZNzD7iF7gfntRM9JKDnAv0Qmnuu2T9hkodH76ZcGU99I42sIHy8uDHVEnZyWX_vVZpAp4ommCzkW20MvO8vFoVBVo7TZv-I/s400/javakeywrds.JPG" width="441" border="0" /></span></div><p align="justify"><u><span style="font-family:verdana;">Some of the legal identifiers are:</span></u></p><p align="justify"><span style="font-family:verdana;">$aturn, _$23, _23, $_aturn, there_is_no_limit_to_the_number_of_characters</span></p><p align="justify"><u><span style="font-family:verdana;">Some illegal identifiers are:</span></u></p><p align="justify"><span style="font-family:verdana;">23$, -saturn, :saturn, saturn#, .saturn</span></p><p align="justify"><span style="font-family:Verdana;">If you have any questions...let them come through the comments, I will gladly answer each one of them.</span></p><p align="justify"><span style="font-family:Verdana;"></span></p>Saurabh Patilhttp://www.blogger.com/profile/02194232716333965729noreply@blogger.com0tag:blogger.com,1999:blog-6565892945474393776.post-28362900504090249282008-06-27T09:32:00.007+05:302008-07-02T09:52:58.992+05:30Java is pass by value.....Always! - Part1<div align="justify"><span style="font-family:verdana;"></span></div><div align="justify"><br /><span style="font-family:verdana;">Surprised? Well, lets look at what is pass by value and pass by reference. Let us understand first what is a value and what is a reference. A <strong>value</strong> of any variable/or java object is the value assigned to it....huh...now what does this means? More technically, a variable is nothing but a name given to a memory location and the value of x is what is stored at the memory location of x. A <strong>reference</strong> is a pointer to an object. Say its like a remote control through which you can handle the target object. Take help of following figures...</span></div><br /><div align="center"><span style="font-family:verdana;"><img id="BLOGGER_PHOTO_ID_5216407407346514898" style="DISPLAY: block; MARGIN: 0px auto 10px; CURSOR: hand; TEXT-ALIGN: center" alt="" src="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEim0M6ZgRE3BkWTNXZ1hIK_NFXBATfFcY3-LCOUzsl4cvWpNoA9PtlFhwoy1jXz0aDBYT4Nd8zX0Qmmdm-h7I6uq0vsilPoxB0xoS4GQqfzCWyiktZIp6Rbi3hyphenhyphenmt53oaUN2Zv2XDCbl-lN/s400/qww.GIF" border="0" /><strong>Variable X storing value 7</strong></span></div><br /><span style="font-family:verdana;"><img id="BLOGGER_PHOTO_ID_5216407412968519218" style="DISPLAY: block; MARGIN: 0px auto 10px; WIDTH: 376px; CURSOR: hand; HEIGHT: 204px; TEXT-ALIGN: center" height="150" alt="" src="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEhtEDHLV3mwaAADPcJvJx1kzdkRTfu9I6aMLGR_jxLlMJkNLjokDJvYb_98cAf0dR0_0H9T9qKjhyAsfTroE_3eTk9_FpE986-GuSXC81sw82UfSPXH9e3EgaimSHHt_ZLL7F5cCjG_Th3B/s400/ddd.JPG" width="291" border="0" /> </span><p align="center"><span style="font-family:verdana;"><strong>Reference X storing a remote control</strong><br /><br /></span></p><div align="justify"><span style="font-family:verdana;">Clearly understand the difference between a value and reference and then you can understand what is pass by value and pass by reference. Well basically as far as java is concerned there is no difference!!Thats why I said java is pass by value always. Let's see why there is no difference. In a <strong>pass by value</strong> you always pass the underlying value of that variable...that means what ever is stored at the memory place. So if X is a variable and it has value 7 then the memory location contains the number 7. And when you pass by value you actually pass what is stored in the memory..and so 7 is passed! When X is a reference then also same thing happens...whatever is stored at the memory location is passed. But hey wait..in earlier case memory contained 7, but what is here? Here X is a reference, hence it contains a remote control to someone whom it is pointing to..so the memory contains the remote control! So here the remote control is passed! In both cases the value is passed, in first case the value is the actual value and in next case the value is actually the remote control. When you pass the remote control the entity (to which you are passing the remote control) can manipulate the object. In the next post I will demonstrate code for both the cases and then you will be able to point out the exact difference between pass by value and pass by reference. Hey, by pass by reference we mean passing the value..which is infact the remote control(the reference!) :) </span></div>Saurabh Patilhttp://www.blogger.com/profile/02194232716333965729noreply@blogger.com1tag:blogger.com,1999:blog-6565892945474393776.post-85756878476018243732008-06-21T11:56:00.009+05:302008-06-21T12:45:17.890+05:30Other than SCJP...what lies ahead?<div align="justify"><span style="font-family:verdana;"><br /></span></div><div align="justify"><span style="font-family:verdana;">This post will tell you about other Sun Java Certifications. Although many know only <strong>SCJP</strong> there are other plethora of Sun Java Certifications. Lets look at them, hey this knowledge isn't necessary for an SCJP taker to know but we should know where we are heading, right?</span></div><div align="justify"><span style="font-family:verdana;"><br /></span></div><div align="justify"><span style="font-family:verdana;"></span></div><div align="justify"><span style="font-family:verdana;">Sun Java Certification is itself a ladder and as you climb up the technology becomes more advanced and powerful. Many consider that SCJP is the 1st and most basic exam in the ladder but there is one more, its called <strong>SCJA</strong> - <strong><em>Sun Certified Java Associate</em></strong> Exam. These two are entry level exams in the ladder and you need to pass SCJP before you can give any of further examinations. There are core differences between the syllabus of <strong>SCJA</strong> and <strong>SCJP</strong>, like the "<strong>swing</strong>" is not included in SCJP but it is in SCJA. There is a difference between a java programmer and a java developer. You can call yourself a java developer after you give the special java developer exam called <strong>SCJD</strong> - the<strong><em> Sun Certified Java Developer </em></strong>exam. You are supposed to have the basic knowledge of java as a language after you complete SCJP and SCJD but you still dont know how to use the java language to the fullest i.e: developing web/standalone commercial products/applications from it - thats the path ahead. There are 4 certifications up the ladder each gives you a special knowledge about the corresponding technology.<br />They are...</span></div><div align="justify"><span style="font-family:verdana;">1. <strong>SCWCD</strong> - the <strong><em>Sun Certified Web Component Developer</em></strong> exam.</span></div><div align="justify"><span style="font-family:verdana;">2. <strong>SCBCD </strong>- the<strong> <em>Sun Certified Business Component Developer</em> </strong>exam<strong>.</strong></span></div><div align="justify"><span style="font-family:verdana;">3. <strong>SCDJWS</strong> - the<strong><em> Sun Certified Developer for Java Web Services</em></strong> exam. </span></div><div align="justify"><span style="font-family:verdana;">4. <strong>SCMAD</strong> - the <strong><em>Sun Certified Mobile Application Developer</em></strong> exam.</span></div><div align="justify"><span style="font-family:verdana;"></span></div><div align="justify"><br /><span style="font-family:verdana;">The <strong>SCWCD</strong> portion is about the web components you need to build a web application. You should know how to develope a web application from scratch, before giving SCWCD. The <strong>SCBCD</strong> concentrates upon the business components required in an application, it includes in-depth study of the <strong>EJB</strong> (<em>Enterprise Java Beans</em>) technology. I donn't know about the <strong>SCDJWS</strong>. The next one <strong>SCMAD</strong> is concerned about knowledge about developing the java mobile applications. Hey the mobile in your pocket if it's java enabled (if it's cost is above 8k, mostly it is.) can run java applications developed by you! You may be thinking these certifications aren't that famous (so may be unimportant) but let me tell you that in the software industry, these special level certifications are valued the most. As SCJP is a pre-requisite for all these you need to pass SCJP before giving any of these. The ladder doesn't end here, there is one more certification at the top, and this is the highest one, it called <strong>SCEA</strong> - the <strong><em>Sun Certified Enterprise Architect</em></strong> exam. I really don't know what the portion is at this level and what knowledge we need to have... :)</span></div><div align="justify"><span style="font-family:verdana;"></span></div><div align="justify"><br /><br /><span style="font-family:verdana;">I hope this post has helped you to know where we are and how far the journey is!<br /></span></div>Saurabh Patilhttp://www.blogger.com/profile/02194232716333965729noreply@blogger.com5tag:blogger.com,1999:blog-6565892945474393776.post-3951925339564057922008-06-14T21:26:00.008+05:302008-06-21T10:32:34.583+05:30My level of java knowledge right now...i.e.: before starting preparation...<div style="text-align: justify;"><span style="font-family:verdana;">Now after knowing Java from past 3 years my teachers will be ashamed if I say "I am pretty new to java." So I am not new to java, I know java from past 3 years and yes have done pretty good amount of coding in it. But knowing java and passing the Sun certification examinations are two different things. You don't need to have working knowledge of java to do programs and even projects in it, but the Sun certification examinations demand that you should not only know good ways of programming in java but also know bad ways of programming in java. A normal java programmer will write a code which runs fine, but a SCJP programmer is supposed to write the most efficient code - and that's where you should know the intracacies and details of the programming language. So, here I am, I am able to write java programs..sometimes very long ones, but nah nah.. I don't even know were they efficient or not.</span><br /><br /><span style="font-family:verdana;">Talking to the point, I have gone through most basic Java programming books like the Complete Reference by Herbert Schildt, some chapters of Core Java and even some chapters of SCJP preparation books by Kathy Seirra & Bert Bates. I havn't given even a single Mock Exam and havn't started preparation for the examinations as such. So, this is where I am beginning. Let's start now.... join me.</span></div>Saurabh Patilhttp://www.blogger.com/profile/02194232716333965729noreply@blogger.com1tag:blogger.com,1999:blog-6565892945474393776.post-69882635464454724232008-06-14T20:32:00.004+05:302008-06-21T10:33:38.015+05:30What this blog is about?<div style="text-align: justify;"><span style="font-family:verdana;">Hello friends,</span><br /><br /><span style="font-family:verdana;">Today I have decided to give the SCJP exam. You will find anything and everything related to SCJP over here. You will find the SCJP information, posts stating my journey of study..yeh you got it right...technical posts (and no philosophy..eek..!:) ) and in the process indirectly I will be sharing the knowledge with you all. This is a perfect place for people who are planning to give SCJP in near future or are preparing for it. The most interesting thing about this blog is that it will contain "<strong><em><span style="color: rgb(204, 0, 0);">my journey of facing SCJP</span></em></strong>" and that means I havn't yet given the exam and I will start preparing for SCJP. It's named "facing SCJP" because who knows I will pass or fail! :)</span><br /><br /><span style="font-family:verdana;">Warm Regards,</span><br /><span style="font-family:verdana;">Saurabh</span><br /><br /><br /><br /></div>Saurabh Patilhttp://www.blogger.com/profile/02194232716333965729noreply@blogger.com4