Comments in Java

One of the questions I ran into when preparing for the Java Certification exam dealt with how Java handles nested comments. Since this isn’t something I usually do in my code I wasn’t sure how it worked. It turns out the results were different than I expected.

First lets look at the double slash comments. Since they mark everything to the end of a line as a comment there isn’t really any way to nest them. You can do something like this:

System.out.println("hi"); // Comments // More comments

But the “More comments” is never evaluated because the compiler simply skips the rest of the line. However with /* */ comments can be nested. First lets look at what happens when you nest // comments inside /* */ comments.

1 /* //important comment */
2 class Comment {
3   public static void main(String args[]){
4     System.out.println("test");
5   }
6 }

So what happens in this code? If the compiler sees the // and skips the rest of the line then the rest of the code will be marked as a comment because the closing */ will be skipped. This will produce a compile time error. So lets try compiling the code and see what happens.
Continue reading “Comments in Java”

Passing the Java Programmer Certification Exam

After using Java for about four years, I started wondering how well I really understood the language, so I started looking into Sun’s certification. Sun offers the following certifications:

  • Sun Certified Programmer
  • Sun Certified Developer
  • Sun Certified Web Component Developer
  • Sun Certified Business Component Developer
  • Sun Certified Developer for Java Web Services
  • Sun Certified Enterprise Architech
  • Sun Certified Mobile Application Developer

The Programmer certification is the pre-requisite for all of the other certifications. It consists of a 61 question, two hour test taken at a Prometric testing center. You need at least a 52% to pass. At first I was surprised at such a low passing score, however it makes more sense given the complexity of the questions.

The Developer certification involves writing an actual application based on specifications from Sun. After completing the program, you take a test over your design choices. It seems the test is to make sure that you actually wrote the code yourself.

Sun Certified Programmer & Developer for Java 2 Study Guide (Exam 310-035 & 310-027)Since the Programmer certification was the only one I was eligible for, I started looking for a good study guide. Several years ago I worked through a book by McGraw-Hill when preparing for a CCNA exam. I liked the format so I was pleased when I found for the Java exam. I ordered it used from Amazon. After it arrived I noticed it was jointly written by Kathy Sierra. Kathy specialty is cognition and learning. She worked for Sun and helped develop the Java exams. She is also the creator of the Head First series of books published by O’Reilly and Java Ranch (a website dedicated to Java certification topics).
Continue reading “Passing the Java Programmer Certification Exam”