John Mercier

java programming and scjp

  • Blog
  • Projects

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

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 |

Album Creator 1.0.a

Posted on February 23, 2009 by John J Mercier

Filed under Album Creator 1.0a | 0 Comments

I just finished making a web page for a program I made. Check it out.

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 |

StringReaderInputStream

Posted on January 27, 2009 by John J Mercier

Filed under Programming | 0 Comments

Have you every made your own InputStream such as a text formatter or a url extractor. In my case, I made an InputStream that can extract urls from any other InputStream and send those urls to an interface called LinkEater. What I want to talk about in this post is how I tested my LinkParserInputStream.

Everyone that claims to know java should know how InputStreams are designed. They use composition to modify the behavior or other InputStreams. InputStreams are a classic example of the Decorator pattern. I took advantage of this pattern when I made my LinkParserInputStream. It obviously HAS-A InputStream and when it is read from it looks for urls in its composit partner. Just what kind of InputStream can it contain? Well any, but what if you want to test it.

To test my LinkParserInputStream I made a class that can read from a string and return characters like an InputStream. By combining a StringReader with the InputStream interface I was able to do this very simply. I believe this pattern is called the Adapter pattern. Here is how the class turned out...[Read More]

Share |

Notes on spellcheck

Posted on January 17, 2009 by John J Mercier

Filed under Programming | 0 Comments

This is a program that will basically spellcheck a single webpage. This is a research project that will help me learn the Java Application Framework, HTTPClient, downloading, parsing, and spellchecking. The things that I learn here will help me in another project I am working on.[Read More]

Share |

moaxcp

Posted on December 18, 2008 by John J Mercier

Filed under Projects | 1 Comments

moaxcp is an old web site I created at johnmercier.net. I started working on this project in 2003 while I attending PTI. The web site is actually built on top of another project I made for blogging called blogson. Blogson has many blogging features but is not very good for everything a website might need. moaxcp was a presentation of every project I had made at that time.

Technology used: jsp, jdbc
Design Pattern: Model 1

The view is not seperated from the model or control at all. In fact, all three of them are combined. Each module of the program is in its own jsp file so the index.jsp only has to include the header, footer, left, center, and right jsp files. The index.jsp file also includes a connection.jsp file which connects to the database and creates a Statement object for all the modules to use. Each jsp file can include other jsp pages. This allows for a seperation of code but does not seperate the scope used for each jsp. This is slightly different from the traditional Model 1 approach but once the jsp is precompiled it all gets turned into one jsp page for the program.
Interesting featers:
  • The ant build script creates a build.properties file containing an auto-incrementing build number and date. This file is read by the jsp page to display the information.
  • The ant build script actually deployed the entire site, through ftp, to the host server.
  • The ant build script zipped all projects into a zip file for the Download section of the site.
  • The ant build script created md5 checksums for each download in the Download section.
Again this project was only meant to combine all of my projects in a webpage.

Share |

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 (28)
  • www.semrush.com/info (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.