John Mercier

java programming and scjp

  • Blog
  • Projects

Testing .equals()

Posted on June 12, 2011 by John J Mercier

Filed under Programming | 0 Comments

I've recently been reading Effective Java, by Joshua Bloch, and the section about the equals() method has sparked my interest. The book explains that there are 5 properties that equals must enforce. equals() must be reflexive, symmetric, transitive, consistent, and non-null. While I was reading I though about how easy it would be to make methods that tests all of these attributes for any object in java. Each property can have its own test, and there can be one method to test all attributes. Before starting this I tried to see what netbeans comes up with for the generated equals test. Unfortunately, it does not test for all these properties. Here is what I came up with.[Read More]

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 |

SCJP exam advice

Posted on April 29, 2010 by John J Mercier

Filed under Programming | 1 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 |

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 | 1 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 |

A Standard Search Pattern for SCJP Questions

Posted on April 22, 2010 by John J Mercier

Filed under Programming | 0 Comments

Noodle Food is a blog that I have been reading on and off for a few years now and recently there has been a post that got me thinking of strategies for dealing with SCJP questions. The post by Paul Hsieh talks about developing a standard "search pattern" for studying x-rays and I think the idea of a standard "search pattern" for java questions should be developed. So I'm going to list some things to look for in SCJP questions. Note: This is for questions that have very general answers (Compiler error, checked exception, runtime exception). Obviously if it's a question that doesn't have these general answers you don't have to worry about it, but, from what I understand, SCJP has these answers on most questions. So, it's important to look for these things in your search pattern.

The Search Pattern

Sometimes you may look at a question and have a gut feeling that something is wrong. When this happens you should immediately look at the provided answers and see if it is in there. If it is make sure that it does not conflict with other answers and use that answer. This guide is not a complete strategy to taking the exam it is only for questions that are too complicated for the answer to just pop out. It is a systematic way of looking for problems in code.

First check the order as if it were in a java source file. First package, second imports, and then classes. Only one class can be public and of course the file must have that classes name. Next, check for correct blocks of code. All code must be in a set of curly brackets with semicolons after each statement.

Next, check for valid identifiers and assignments. Don't for get to check assignments in for loops. If polymorphism is used make sure the assignment is correct. If and assignment is made with a return from a method check the access to that method along with the return type. If the method throws an exception make sure that it is handled during the assignment. You do not have to go through the method line by line at this point.

The next thing to look at are conditional statements. if, for, while, assert all have conditions that may not make sense. Look for assignments (=) instead of equality checks (==). Look for method calls that do not return boolean.

Line by Line Search

The idea of a line by line search is to start from the beginning of a program and figure out exactly what each line does. If the question does not have a main method the question will usually tell you where to start. Once you find an error don't lose your place. It may not be the answer the question is looking for.

Well this is all I'm going to write on this for now. I'm sure as I go through the book I will find things to add.

Share |

SCJP Certification

Posted on April 21, 2010 by John J Mercier

Filed under Programming | 0 Comments

For a few weeks, while I've been finishing my calculus class, I've been looking at my java books wishing I had something to show for all that I have learned. I have 2 reference books, and two of the Head First books. I believe the best way to show knowledge of java is through the Sun Certification programs. I have been thinking about how much I want to get the SCJP Certification. There are two reasons I want to get the cert. First, it will be my only professional certification. Second, if I ever decide to get a different job it will be for programming.

Before I write what I'm doing to prepare for the cert I have to say that I have already studied for the exam less than a year ago and decided not to take it. I bought the study guide by Kathy Sierra and Bert Bates, wrote a ton of note cards, and even got passing scores on some of the practice quizzes. I was well on my way to getting the cert, but my life was getting to stressful and the goal of being certified seemed impossible. There are a few things causing this stress. I was getting out of the Navy and in the process of finding a job, taking two college classes, and worrying constantly about my future (This may have something to do with my recent return from Afghanistan). Now that I have a good job that I like, I feel less stress and I am ready to get the certification.

What am I doing to study? Yesterday I started my studying. I own a Sun Learning CD-ROM with 5 courses covering a lot of the java programming language. There are practice exercises and a lot of information that will help. The Getting Started section is done so far.

I'm also re-reading the SCJP book. I like to read things from start to finish but I've already been through this book a few times. I plan on going through it once, skimming through the sections I know and reading the ones I don't. After that I'm going to take as many practice tests as I can.

The test questions for this certification are complicated. They incorporate many concepts into one question that you almost have to be a human compiler to get them right. In fact a majority of the questions have "Does not compile" or something similar as an answer. It's really important to learn how to read a question (check for compile errors, runtime exceptions) and come up with the right answer. Practice makes perfect! And I know I need to take as many tests as I can.

Share |

Circular String 2

Posted on January 28, 2009 by John J Mercier

Filed under Programming | 0 Comments

Ok everyone, I finished making my CircularString class. For now, it does not use generics because I only need it for integers. That will be changed if I find a need for it. I have also made a CircularStringShift class that, instead of using a fillIndex, shifts the contents of the buffer and adds to the end. I tested both with 100,000,000 characters, and they are about the same speed. Here is the code.[Read More]

Share |

Main | Next page »
  • General (12)
  • Projects (3)
  • Programming (14)

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 (150)
  • baccaratforums.com/g (37)
  • www.playdota.com/for (37)
  • www.mycraft.com/ueba (36)
  • www.cooksillustrated (35)
  • znakomstvaca.info/si (10)
  • znakomonly.info/site (10)
  • znakomstvaca.info/si (5)
  • microscopiclove.info (5)
  • microscopiclove.info (5)
  • microscopiclove.info (5)
  • microscopiclove.info (5)
  • znakomstvaca.info/si (5)
  • microscopiclove.info (5)
  • microscopiclove.info (5)
  • microscopiclove.info (5)
  • microscopiclove.info (5)
  • microscopiclove.info (5)
  • microscopiclove.info (5)
  • znakomstvaca.info/si (5)
  • microscopiclove.info (5)
  • microscopiclove.info (5)
  • microscopiclove.info (5)
  • microscopiclove.info (5)
  • znakomstvaca.info/si (5)
  • microscopiclove.info (5)
  • microscopiclove.info (5)
  • microscopiclove.info (5)
  • znakomstvaca.info/si (5)
  • microscopiclove.info (5)

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.