John Mercier

java programming and scjp

  • Blog
  • Projects

Favorite Posts for the Week #3

Posted on May 17, 2010 by John J Mercier

Filed under General | 0 Comments

Well, I haven't been reading my google reader as much as I should so I only have a few links to share.

MDA posted a fitness challenge.

Modern Paleo posted a recipe for greek chicken and another for pork in yellow curry.

NoodleFood made a good comment on the genocidal muslim student.

Sorry, for the short list and lack of comments. The next one should be better.

Share |

SCJP Master Exam Notes

Posted on May 16, 2010 by John J Mercier

Filed under Programming | 0 Comments

I recently took a Master Exam from the Sierra and Bates SCJP book and got a 53%. While I was answering questions I noted any problem I had with a question. Today, I'm going through these notes and the exam report to see what needs work. Also, why not make a blog entry out of it? The following list are things I need to remember for the next exam.

HashMap.size() returns the number of key-value mappings in this map.

The rules for overriding equals() and hashCode()

must consistently return the same integer, provided no information used in equals() is modified

if two objects are equal using equals() then they must return the same hashCode()

if two objects are not equal using equals() then they can have the same hashCode(), or a different hashCode()

calling method((short)7) with method(short x) and method(short... x) in the class will always use method(short x) instead of method(short... x).

Is-A relationships always rely on polymorphism!

Comparator

an interface

override compare(T o1, T o2);

returns 0 if o1.equals(o2)

returns negative if o1 is less than o2

returns positive if o1 is greater than o2

Static variables are not serialized (not sure if I need to know this on the new version of SCJP)

Interfaces cannot have static methods. Interface methods cannot have a body so a static method doesn't make sense. Interface methods are alway public abstract. Interface variables are always public static and final.

What is the difference between high cohesion and loose coupling?

High cohesion is how strong a class's responsibilities are related and focused. For SCJP questions member variables and methods should be related. If a method doesn't interact with a member variable then it is probable not a cohesive method.

Loose coupling is how much information one class needs from another to perform methods. Loose coupling in SCJP would be one class using accessors rather than public member variables.

Encapsulation encourages loose coupling by not sharing member variables directly to other classes or subclasses. Instead public setters and getters are used.

Learn the different variations in generics. <T> input<T>(), <? extends T> <? super T>. All of that.

Can abstract come after a class name? No. I thought this was false but decided I should look it up.

Is TreeSet sorted? Yes according to my Java pocket guide, it is. I believe this means it must implement the comparable interface, or be constructed with a comparator.

Can an Integer constructor take "17" as a param? Yes. Darn, I think I got this one wrong on the exam.

What is the regex "." metacharacter? It matches with any single character. I'm guessing this means in the alphabet.

What does subMap() do? The subMap() method returns a NavigableMap that is linked to the original map. There are some catches.

  • Any new entries can be added to the original Map. new entries added to the submap must be within the range used to create the submap.
  • New entries added to the original map within the range of the submap are also added to the submap.
  • New entries added to the original map outside the range of the submap are not added to the submap.
  • New entries added to the submap are also added to the original map.
  • Using pollFirstXxx() on the original map will only remove from the submap if the entry polled is in the range of the submap.
  • Using pollFirstXxx() on the submap will remove the entry from the original map.
  • One other thing to remember is that the boolean values of headMap, tailMap, and subMap will include the arguments in the submaps.
  • Also, all of these ideas are the same for the Set collections.

Can TreeSet.ceiling() return the argument? Yes. from the javadoc "Returns the least element in this set greater than or equal to the given element, or null if there is no such element." So, if the argument is equal to an entry that entry will be returned.

How to get DateFormat with Locales? Use DateFormat.getDateInstance(DateFormat.LONG, Locale.FRANCE);

  • Also Only one DateFormat is needed to format many Date objects.

What are FileReader and BufferedReader classes? How are they different classes?

FileReader is an InputStreamReader which is a subclass of Reader. BufferedReader is a subclass of Reader as well. They both read characters from a source into a character array or CharBuffer. The major differences are FileReader reads only files, InputStreamReader can read any InputStream (ie file or network stream), and BufferedReader can Buffer any Reader using the Is-A and Has-A relationships similar to the InputStream and BufferedInputStream. I believe this is called the Decorator design pattern.

Share |

javaranch scjp roundup

Posted on May 11, 2010 by John J Mercier

Filed under Programming | 0 Comments

This post is a roundup of all the interesting posts I have found on javaranch along with my comments. Expect to see more of these as I continue to study for SCJP.

Magic! Magic! The way this works should be obvious. When you start your program with * as a command line argument it will get a list of filenames.

Master exam question. A good question about binarySearch in the Arrays class. You have to understand how an insertion point is returned if the Object is not in the array. Insertion point (-(insertion point) - 1) "The insertion point is defined as the point at which the key would be inserted into the array: the index of the first element greater than the key, or a.length if all elements in the array are less than the specified key. Note that this guarantees that the return value will be >= 0 if and only if the key is found."

serialization. Well it's not the serialization part that is important. The second question in the post talks about the JavaBeans naming convention. For SCJP getVariable, setVariable, addListener, removeListener, and isTrue are valid names.

Method Local Inner classes. It is true that method variables need to be marked final when they are used in method local classes.

http://www.coderanch.com/t/493547/java-programmer-SCJP/certification/Local-variables-type-mismatch-int

The problem here is compile-time constants. When an int is less than or equal to 127 and declared as such, final int i = 127, it is a compile-time constant. It is also able to be assigned to a byte without a cast because the compiler knows it is small enough. This also works with short.

pattern matching. In regex there is a key difference between the patterns "a*" and "aa*" The first looks for zero or more "a" at each index, and the second looks for an "a" followed by zero or more "a".

Share |

Favorite Posts for the Week #2

Posted on May 11, 2010 by John J Mercier

Filed under General | 0 Comments

Sorry this is late but nobody is really reading it anyway.

Health

Mark's Daily Apple has a good post, The Difinitive Guide to Sugar, that describes in detail the different kinds of sugar and their effects on health. The best part is where he explains why you should avoid sugar.

  • Sugar stimulates a physiological stressor-reaction cascade that provokes adrenaline and cortisol release and thickens the blood.
  • Sugar effectively disables your immune system by impairing white blood cells’ functioning.
  • Sugar decreases your body’s production of leptin, a hormone critical for appetite regulation.
  • Sugar induces significant oxidative stress in the body.
  • Sugar appears to fuel cancer cells. (Check out Free the Animal for much more on the cancer connection.)
  • Sugar promotes fat storage and weight gain.
  • Sugar disrupts the effective transfer of amino acids to muscle tissue.
  • Sugar intake over time spurs insulin resistance, subsequent Type II diabetes and the entire host of related health issues like nerve damage and cardiovascular disease.
  • I also found a post on artificial sweeteners that you may want to look at. Also, isn't lactose a sugar? I would like to see more info on that.

    Meatza is pizza that uses groud beef for the crust.

    On The Paleo Diet there is a Q&A that talks about lectins, saponins, and gliadin. I broke them down in this table.

     Antinutrient  Found In  Why it is not healthy
     lectins cereal grains and legumes  increasing intestinal permeability, resistant to digestive enzymes, deposited in the internal organs
     saponins  legume sprouts  affect the gut barrier and by extension immune system function, may also increase the risk of autoimmune diseases in genetically susceptible individuals
     gliadins  wheat  resistant to digestive enzyme degradation, arrives intact when it comes into contact with intestinal epithelial cells, increases intestinal permeability
     phytate  bran and seeds inhibits the intestinal absorption of iron, magnesium, calcium and zinc

     Diana Hsieh wrote a nice post with links to making paleo friendly foods.

    and here is A Story on Circumcision.

    Philosphy

     Mistaking fact with opinion. I like to read threads like this because they point out something that can really cause problems with reasoning. The idea is that arguing with opinions rather than facts is a huge mistake. In a society it will lead to mass uncertainty.

    Politics

    Arguments for government spending. People take this seriously.

    1) The political push to reduce government deficits is economically misguided, based on an irrational "phobia" of deficits.

    2) If we want economic growth, we need more spending. Only banks and governments can stimulate spending because, "Governments and banks are the two entities with the power to create something from nothing."

    3) Increasing spending by having the government do it is preferable to having the private greedy selfish bankers do it. And the real reason bankers oppose government spending is because it competes with their private lending.

    4) We shouldn't worry about the so-called impending bankruptcy of Social Security or Medicare or of the US government itself. The government is the source of money and therefore can't run out.

    5) Nor is government debt a "burden on future generations", because it never has to be repaid. Each generation can just pass it onto the next generation, so there's no problem.

    A real example of lobbying doing terrible things.

    I do think at a certain point you become a socialist!

    Share |

    Favorite Posts for the Week #1

    Posted on May 01, 2010 by John J Mercier

    Filed under General | 0 Comments

    The goal of these posts are to share my favorite posts for the week. This is the one post a week where I will be off topic from programming and try to share some of my views. After all, this is my blog and I can put what I want on it. I decided to make it only one post a week because I don't want to get off the topic of programming and java. So for now, this will have to work.

    I'm still developing a process for finding decent posts but google reader is the best way to keep track of everything I like so far. The first thing I do is save an entry and edit it throughout the week with links to things I want to share. Almost everything I read is in google reader so all I have to do is star the items I like.

    Health

    In the case against cardio Mark explains why cardio is bad.

    "Well, we know that this current popular high intensity aerobic pursuit is a dead-end. It requires huge amounts carbohydrate (sugar) to sustain, it promotes hyperinsulinemia (overproduction of insulin), increases oxidative damage (the production of free radicals) by a factor of 10 or 20 times normal, and generates high levels of the stress hormone cortisol in many people, leaving them susceptible to infection, injury, loss of bone density and depletion of lean muscle tissue – while encouraging their bodies to deposit fat."

    Shea makes a great case against circumcision.

    "Given these effects (both the certain and the possible), is circumcision for preventative purposes justified? My answer is a resounding NO! All of the diseases which are supposedly more likely for uncircumcised men have either much less drastic prevention methods, much less drastic treatment methods, or both. Worried about UTIs? Rather than slicing off the flesh of your newborn, why not wait and see if UTIs develop (a fairly small risk in any case) and use the normal, non-surgical treatment: antibiotics."

    Government may soon control all water!

    Open Immigration

    "The only approach that respects individual rights is a policy of open immigration (which is not the same as unrestricted immigration) -- and the abolition of the welfare state."

    Java

    SCJP exam notes posted by Nikunj point out some important concepts you need to understand for SCJP.

    Google explains its approach to Flash support in mobile devices.

     

    Share |

    SCJP exam advice

    Posted on April 29, 2010 by John J Mercier

    Filed under Programming | 0 Comments

    Recently, there have been a few good pointers posted at javaranch on what to expect on the exam here and here.

    "Don't expect the exam center to be quiet. (going last on the day might help. I was the first one for the day and lot of people were coming in and going out in the middle of my exam.)"

    I may have to call the exam center and ask about this. If it is busy in the morning it may be a good idea to take it later in the day.

    "I wasn't able to review drag and drop question. The software was giving a warning that if I try to review the question then I'll have to re answer them which was really frustrating."

    This is a huge deal, and I've seen a lot of complants about this on the forum. This should be fixed asap!

    "Inner classes with most weirdest combination appears every where. You need to know the in and out of inner classes."

    This is where I may have trouble... inner classes that extend inner classes anybody?

    "Don't skip the tough questions thinking you can revisit them later because some of the questions appear easy, but it may not be that easy once you start thinking deeply!"

    I think you could probably skip questions, but if you are skipping every other question maybe you should relax and just answer them. You can always mark the questions to look at later but at least put your best guess.

    Share |

    Updates #1

    Posted on April 28, 2010 by John J Mercier

    Filed under johnmercier.com | 0 Comments

    Installed 25 Roller Themes 

    I installed all 25 themes avaliable for roller from http://wiki.java.net/bin/view/Javanet/OptionalThemesForRoller.

    Using Natural Beauty Theme

    With this theme, there are a few problems that I ran into. Comments did not work. To fix this I needed to change

    • #showWeblogEntryComments($entry)
    • #showWeblogEntryCommentForm($entry)
    to
    • #showWeblogEntryComments($model.weblogEntry)
    • #showWeblogEntryCommentForm($model.weblogEntry)

    I then added my friends and links to the sidebar because it only showed bookmarks from the root folder.

    Referers didn't work (and it was spelled wrong). To change this I had to look at code from another theme and add the true in the #showReferrersList($refs 30 20 true) macro.

    On of the biggest challenges was changing the main tabs to only show my blog and then the projects category. I also want to add an About Me tab. To get away from the category tabs while still using one category name, and checking for the active link, I had to do some tricky coding.

    Using Google Reader Shared Items

    Adding items to your blog from google reader is very easy. In google reader you can share any item simply by clicking the share link at the bottom of the post. This will add the post to you shared items page in google reader. You can add a clip of your shared items to any website. To do this click on your shared items, click on sharing settings and go to the bottom of the page. Click add a clip, customize the settings and copy and paste the clip to your webpage. It is very easy.

    Another way to do this that I haven't tried yet is to add my shared items to the roller planet aggregator. From what I understand this will pull from any rss feed and create a meta-blog. The advantage of sharing items this way is the ability to format the html in any way I want.

     

    Share Icons For Posts

    I started by adding individual buttons for google buzz and facebook. Here are the notes on that. 

    • google buzz
      • go to Buzz - stuff to make your button.
      • use $url.entry($entry.anchor) in data-url to add link to post from roller template
    • facebook
      • go to Share Facebook and build code for template.

    And then I found addthis.com, the ultimate site for sharing blog posts. It has buttons for 271 services and is very customizable.

    Some of the other things I need to do are:

    • Try getting a feed by tag.
    • Try making a planet aggregator that will read my google reader shared items instead of using the google reader widget.
    • Try installing the plugins and text editors for roller.
    • Try to either make this theme the way I want it or attempt to make my own theme again.

    Share |

    Helpful Learning Sites

    Posted on April 26, 2010 by John J Mercier

    Filed under Programming | 0 Comments

    Has anybody noticed how many educations sites are out there for java. One site that I have enjoyed using since I started studying for SCJP is javablackbelt.com. The site takes a different approach to online quizzes and has made an entire community that participates in quiz evaluation and creation using two point systems.

    Knowledge points are earn for passing quizzes. Knowledge points are used to determine what belt you have. The belts are white, yellow, orange, green, blue, brown, and black.

    Contribution points are earned by submitting beta questions to a quiz section. Beta questions are voted on by other users. When the question earns enough votes from quiz takers it is released, earning more contribution points for you.

    The belt track are free quizzes that can be taken in order. You must spend more contribution points to take quizzes outside of the belt track. The belt track starts at very basic java language questions and ends in an ultimate test in coding. From my calculations, the belt track can only get up to a blue belt. To earn higher belts you must participate in question contributions so you can take quizzes outside of the belt track. Quizzes outside of the belt track cover many technologies besides java like sql, ant, html, and css.

    Currently, I'm an orange belt! I have only taken quizzes within the belt track but I have 12 contribution points.

    If you are interested in testing your knowledge of java this is a very fun site to use. If you know of any other sites out there like this let me know!

    Share |

    Server1 Setup ubuntu, java, virtualmin

    Posted on April 24, 2010 by John J Mercier

    Filed under Programming | 0 Comments

    A while ago I wrote a document describing how I setup my own server for shared web hosting using virtualmin. This can be helpful if you ever plan on hosting your websites on your own server. It was fun learning about these technologies so I'm willing to share my notes.

    Server1

    This document explains the steps I took to install and configure server1.

    Note: keep in mind that I have a router setup with dchp enabled.



    Also, I have setup dhcp clients to use server1 as the first dns server along with my isp dns. These settings will come up when setting up the FQDN of server1 and when changing the ip address to static.Remember to change the DNS 1 setting to server1's ip address. The only other router setting I can think of is putting the server in the DMZ.


    Installing The Software


    1. Install fresh copy of ubuntu 8.04(LTS) server edition
    • make sure to extend root volume to second harddrive
    • hostname is server1
    • DO NOT install dns, lamp, postgresql, mail because suexec for apache causes errors
      • tomcat is not an option in this version
    • system mail name is johnmercier.selfip.com
    2. install sun-java and use it
    • sudo apt-get install sun-java6-jdk
    • sudo update-java-alternatives -s java-6-sun
    3. update system packages
    • sudo apt-get upgrade
    4. setup static ip and resolv.conf
    • link
    • test with hostname -f and check for hostname in browser
      • server1.johnmercier.selfip.com will not work until dns is setup.
      • johnmercier.selfip.com should work if httpd is running
    • remove dhcp client
    • link
    5. install virtualmin using the install.sh script on their website
    • link

    VIRTUALMIN SETUP

    1. post install script
    • Basically answered yes to everything.
    2. Check config
    • Default IP address is set to 192.168.1.10, but the detected external addresss is actually 24.165.27.83. This is typically the result of being behind a NAT firewall, and should be corrected on the module configuration page.
      • System Settings -> Module Config -> set Default IP address for DNS records = Automatically detect external address.
    3. Default settings

    4. Server Plans

    5. Bandwidth Monitoring

    6. Skeleton Pages




    future steps
    • setup mod_jk
    • make control panel to edit mod_jk, restart tomcat, change jdk, and access virtualmin, usermin, webmin
    • write webapp to show status of all servers on public page



     

    Share |

    SCJP Notecards

    Posted on April 23, 2010 by John J Mercier

    Filed under Programming | 0 Comments

    For a test this big every strategy needs to be looked into. Note cards are a very easy way to separate all the junk in a paragraph from what you really need to know, but they can be very time consuming to make. Luckily the SCJP book I have lists everything you need to know at the end of each chapter. When I made my note cards (almost a year ago) I wrote each bullet on it's own note card and on the other side I put the reference. When I had time, I would go over the note cards for a chapter and pick out the ones that I didn't understand completely. This way I knew what I had to look for in each chapter in order to fully understand it. Making the note cards was a lot of work and I'm not sure that it helped that much. Sure, writing things down helps put it through the brain in a different way but it seems more like a chore than actual learning. This time around I think I may use flash cards.

    Does anyone think that flash cards could work? A flash card has a question on the front and the answer on the back. It's kind of hard to make flash cards for an exam this big so I'm not sure it's worth the effort. A flash card may also be too simple to represent everything that can be put into a question on the exam. Of course, there are concepts that need to be memorized that are not in code like abstraction, polymorphism and inheritance. Flash cards could even be used to memorize keywords. While I'm reading the SCJP book again I will make some flash cards for the first chapter and see if it helps.

    In other news I'm getting rid of my theme. It doesn't work at all in IE and I'm just getting tire of worrying about the layout. I may work on customizing a different theme but for now I'm going with the Basic theme that came with roller.

    Share |

    Main | Next page »

    Search

    Tag Cloud

    activism addthis.com data_structure downloading facebook google google-buzz introduction java javablackbelt jdbc johnmercier.com jsp linux model-1 netbeans nvidia objectivism official-english programming projects pti roller scjp server sql theme uncertainty velocity welfare-state

    Friends

    • Ed
    • Shane

    Links

    • Glazed Lists
    • JGoodies
    • Java Specialists
    • Swing 2.0
    • Swing Generics
    • ideone
    • pircbot

    Feeds

    • All
    • /General
    • /Projects
    • /Programming
    • Comments

    Referrers

    • direct (6)
    • biosespclac.narod.ru (1)

    Navigation

    • John Mercier
    • Weblog
    • Login

    ©2010 John J Mercier.

    Designed by Free CSS Templates. Template by E. Strokin. Powered by Roller Weblogger 4.0.1.