tag:blogger.com,1999:blog-49629624208642131062024-03-13T12:49:32.424-07:00RHANDOM DEVELOPERAnonymoushttp://www.blogger.com/profile/14243367759009338642noreply@blogger.comBlogger3125tag:blogger.com,1999:blog-4962962420864213106.post-39591520466597176112014-01-17T04:12:00.001-08:002014-01-17T04:14:44.049-08:00Collections: When to use them (brief summary)<span class="docEmphStrong"><span style="color: blue;"><b>Collection</b></span></span> is a data structure actually, an
object that can hold references to other objects.<br />
<br />
Collection Framework interfaces:<br />
<br />
1. Lists -<u> Lists</u> of things (ex. Lists of students).<br />
2. Sets - Set is a collection where all the values are <u>unique</u>.<br />
3. Maps - Map is a collection that holds <u>key/value pairs</u>. A unique key is mapped to a specific value, where both the ‘key’ and ‘value’ in are objects.<br />
<br />
Terminologies:<br />
1. Ordered - You can iterate through the collection in a specific order.<br />
2. Sorted - Collection is sorted in the natural order (alphabetical for Strings).<br />
<br />
<u><b>LISTS</b></u><br />
<u><br /></u>
<b>Arraylist</b> - uses arrays internally for data management.<br />
<br />
to be used when:<br />
<br />
<ul>
<li>you need a resizable-array implementation of List interface</li>
<li>you need an ordered collection</li>
<li><span style="color: red;">should be considered when there is more data retrieval that adding or deleting of elements.</span></li>
</ul>
<div>
<b>Vector</b> - also implemented on similar lines of ArrayList, but some of the methods in Vector are synchronized and Vector has more methods when compared to ArrayList.</div>
<br />
<br />
<div>
<br /></div>
<div>
to be used when:</div>
<div>
<ul>
<li>you need an ordered collection</li>
<li><span style="color: red;">should be considered when thread safety is a concern.</span></li>
</ul>
<div>
<b>LinkedList</b> - it is a LinkedList implementation. The LinkedList class uses an inner class called Entry. </div>
</div>
<div>
<br /></div>
<div>
to be used when:</div>
<div>
<ul>
<li>you need an ordered collection</li>
<li><span style="color: red;">faster insertion/deletion and slower retrieval when compared to ArrayList.</span></li>
</ul>
<div>
<u><b>MAPS</b></u></div>
</div>
<div>
<u><br /></u></div>
<div>
<b>HashMap</b> - stores elements in an array of type Entry.</div>
<div>
<u><br /></u></div>
<div>
to be used when:</div>
<div>
<ul>
<li>you need an unsorted and unordered Map</li>
<li><span style="color: red;">you need a map that allows <i>null</i> key and <i>null</i> values</span></li>
<li><span style="color: red;">methods are not synchronized. thread safety is not a concern</span></li>
</ul>
<div>
<b>Hashtable</b> - is implemented in the same fashion as HashMap. </div>
</div>
<div>
<br /></div>
<br />
<div>
to be used when:</div>
<div>
<ul>
<li>you need an unsorted and unordered Map</li>
<li><span style="color: red;">should be considered when security is important</span></li>
<li><span style="color: red;">you need a map that allows <i>null</i> key and <i>null</i> values</span></li>
<li><span style="color: red;">methods are synchronized. thread safety is a concern</span></li>
<li>has more utility methods than HashMap</li>
</ul>
<div>
<b>TreeMap </b></div>
</div>
<div>
<br /></div>
<div>
<div>
The elements in a TreeMap are sorted by the keys. </div>
<div>
As with every Map, only objects can be stored as keys and values in a TreeMap.</div>
<div>
A TreeMap allows null values.</div>
<div>
All keys that go into the TreeMap should implement the Comparable interface.</div>
</div>
<div>
<br /></div>
<div>
<u><b>SETS</b></u></div>
<div>
<u><br /></u></div>
<div>
All Set implementations use Map internally. It has the same usage with Map though take note that objects in Sets should be <u>unique</u>.</div>
<div>
<br /></div>
<div>
<div>
HashSet - uses HashMap internally.</div>
<div>
LinkedhashSet - uses LinkedHashMap</div>
<div>
TreeSet - uses TreeMap </div>
</div>
<div>
<u><br /></u>
<span style="font-size: x-small;">reference: COLLECTIONS – WHAT HAPPENS WITHIN -Compiled by Sharad Ballepu</span></div>
Anonymoushttp://www.blogger.com/profile/14243367759009338642noreply@blogger.com0tag:blogger.com,1999:blog-4962962420864213106.post-11686881385065876272013-11-21T08:45:00.001-08:002013-11-21T08:48:32.068-08:00Setting up your Linux Environment (Ubuntu) for JAVA Development<div>
<br /></div>
This tutorial is for starters. although this may also help professionals. I am using Ubuntu 12.04 LTS and I thought of creating a tutorial on how to setup your Linux environment for java development.<br />
<br />
<h3>
</h3>
<h3>
Installing JDK 6</h3>
<br />
<ul>
<li>download jdk from <a href="http://www.oracle.com/technetwork/java/javase/downloads/jdk6u38-downloads-1877406.html">here</a></li>
<li>create folder jvm in /usr/local</li>
<li>move the downloaded jdk to /usr/local/jvm</li>
<li>change the permission of jdk -> sudo chmod 700 jdk-6u38-linux-i586-rpm.bin</li>
<li>extract jdk using command -> ./jdk-6u38-linux-i586-rpm.bin</li>
<li>create a link for the jdk -> ln -s jdk-6u38 java</li>
<li>add the jdk in your enviromnent PATH. I usually add it in .bashrc</li>
</ul>
<div>
you can add the following in your .bashrc:</div>
<div>
<br /></div>
<div>
export JAVA_HOME=/usr/local/jvm/java</div>
<div>
export JDK_HOME=$JAVA_HOME</div>
<div>
export PATH=$PATH:$JAVA_HOME/bin<br />
<br /></div>
<h3>
</h3>
<h3>
Installing JDK 7</h3>
<div>
Just execute the following commands to install jdk7</div>
<div>
<pre style="background-color: #eeeeee; border: 0px; color: #333333; font-family: 'Ubuntu Mono', 'Ubuntu Beta Mono A', Consolas, 'Bitstream Vera Sans Mono', 'Courier New', Courier, monospace; font-size: 14px; line-height: 18px; margin-bottom: 10px; max-height: 600px; overflow: auto; padding: 5px; vertical-align: baseline; width: auto; word-wrap: normal;"><code style="border: 0px; color: #222222; font-family: 'Ubuntu Mono', 'Ubuntu Beta Mono A', Consolas, 'Bitstream Vera Sans Mono', 'Courier New', Courier, monospace; margin: 0px; padding: 0px; vertical-align: baseline;">sudo add-apt-repository ppa:webupd8team/java
sudo apt-get update
sudo apt-get install oracle-java7-installer</code></pre>
</div>
<div>
<h3>
Installing Subversion</h3>
</div>
<div>
<pre style="background-color: #eeeeee; border: 0px; color: #333333; font-family: 'Ubuntu Mono', 'Ubuntu Beta Mono A', Consolas, 'Bitstream Vera Sans Mono', 'Courier New', Courier, monospace; font-size: 14px; line-height: 18px; margin-bottom: 10px; max-height: 600px; overflow: auto; padding: 5px; vertical-align: baseline; width: auto; word-wrap: normal;"><code style="border: 0px; color: #222222; font-family: 'Ubuntu Mono', 'Ubuntu Beta Mono A', Consolas, 'Bitstream Vera Sans Mono', 'Courier New', Courier, monospace; margin: 0px; padding: 0px; vertical-align: baseline;">sudo apt-get install subversion</code></pre>
</div>
<h3>
Installing Git</h3>
<div>
<pre style="background-color: #eeeeee; border: 0px; color: #333333; font-family: 'Ubuntu Mono', 'Ubuntu Beta Mono A', Consolas, 'Bitstream Vera Sans Mono', 'Courier New', Courier, monospace; font-size: 14px; line-height: 18px; margin-bottom: 10px; max-height: 600px; overflow: auto; padding: 5px; vertical-align: baseline; width: auto; word-wrap: normal;"><code style="border: 0px; color: #222222; font-family: 'Ubuntu Mono', 'Ubuntu Beta Mono A', Consolas, 'Bitstream Vera Sans Mono', 'Courier New', Courier, monospace; margin: 0px; padding: 0px; vertical-align: baseline;">sudo apt-get install git-core</code></pre>
</div>
<h3>
Installing Maven</h3>
<div>
<ul>
<li>Go to Apache Maven website and follow the instructions</li>
<li>place maven in /usr/local/apache-maven</li>
<li>if you have your own settings.xml, create .m2 folder in your home directory and place your settings.xml</li>
<li>add maven in your environment path</li>
</ul>
</div>
<div>
</div>
Anonymoushttp://www.blogger.com/profile/14243367759009338642noreply@blogger.com2tag:blogger.com,1999:blog-4962962420864213106.post-62699914885236975932012-10-02T03:34:00.001-07:002012-10-02T05:09:27.255-07:00Programmer Tip: #1 Constants First<p>Based on my experience, programmers always commit this mistake in using constants in the code. I always see this problem even in large projects made by experienced programmers. So I decided to choose this topic for my first blog. Check this code.</p>
<pre>
public static final String CONSTANT_VALUE = "Value";
public static boolean functn(String compare) {
if(compare.equals(CONSTANT_VALUE)) {
return true;
}
return false;
}
</pre>
<p>
Did you notice something wrong with this code? Well, Yes you're right. What if a null value is passed to the functn method? This code will produce a NullPointerException. So to avoid getting a NullPointerException some programmers will check if the passed value is null or add some try-catch to handle the exception like this
</p>
<pre>
public static final String CONSTANT_VALUE = "Value";
public static boolean functn(String compare) {
if(compare != null
&& compare.equals(CONSTANT_VALUE)) {
return true;
}
return false;
}
public static boolean functnWithTryCatch(String compare) {
try {
if(compare.equals(CONSTANT_VALUE)) {
return true;
}
return false;
} catch (NullPointerException e) {
return false;
}
}
</pre>
<p style="color:red">
Note: declare your constant variables as "static"
</p>
<p>
The right way of doing it is just to put the constant variable first and make the "compare" the parameter in your operation. This is because the constant variable always has a value and will never turn to null. Even if the passed parameter is null, this will not produce any NullPointerException and behave properly. See example below
</p>
<pre>
public static final String CONSTANT_VALUE = "Value";
public static boolean functn(String compare) {
if(CONSTANT_VALUE.equals(compare)) {
return true;
}
return false;
}
</pre>
<p style="color:red">
Notice that the code is now: if(CONSTANT_VALUE.equals(compare))
</p>
<p>Hope you learned something. Sorry if the design and the words used is not that good. Busy eh :p I'll improve this page pag di na ako busy. Thanks ;)</p>Anonymoushttp://www.blogger.com/profile/14243367759009338642noreply@blogger.com0