Sunday, October 20, 2013

OCAJP7(1Z0-803) and OCPJP7(1Z0-804) Preparation

OCAJP7(1Z0-803) & OCPJP7(1Z0-804)

It was a looooong journey. I took OCAJP7 at the end of May and OCPJP at the middle of October. I was very suffering when I prepare for the exams, but everything is worth, it is guaranteed that the exams keep me growing. Now I can understand Java SE better and it get my Java skills increment.

Taking a glance of the exams, and experience the real exam level:
(1)
public static void main(String[]args){....}
public static void Main(String[]args){...}
public static void main(){...}

(2)
 try{
     throw new IOException();
}catch(Exception e){
     throw new FileNotFoundException();
}
which Exception will be thrown?
(3)
Files.copy(sourcePath, destinationPath);
Question: if the source file under sourcePath is hidden, what if we copy it to the destination path, is it Hidden?

What resources are required?
(1) The Java Tutorial
Programmer Level 1
Programmer Level 2
Those two links covers the topics of OCAJP7 and OCPJP7 respectively. Those links can only help you understand well which topics you should prepare, but if you only read those materials, it is far from passing the exams.

(2) SCJP6. This book is highly recommended. This books covers all the details of the topics it provided. Because of this book is for SCJP6 exam, some topics of OCAJP7/OCPJP7 are not covered by this book, for example: try-with-resource, string processing, File IO(NIO2), even though, it is still a good book for preparation.

(3)Oracle Certified Professional Java SE7. Java SE7 covers all the topics for OCPJP7, and it is as board/deep as the real exam. The topics not covered in SCJP6, they are involved by Java SE7. It has two mock tests, each has 90 questions, they can help you to estimate your level(The average score of those two mocks is very close to my OCPJP7 score :) ). Here's their official link: http://ocpjp7.blogspot.ca/, a tons of useful information are posted here.

My impression of the exams
1. Topics are not even distributed. Before I took the OCPJP7, I thought it would have a lot of questions are related to Generics and Threads, but when I sit in front of the real exam, I found only about 10 questions about Generics and Threads, and more than 15 questions are about File IO(NIO2) and String processing, and only 1 or 2 questions covered JDBC. Therefore, be careful when you prepare for your exams, you should understand all topics well.

2. Too many details
replaceAll(String regex, String replacement)
replace(char oldChar, char newChar)
Such kind of methods will be involved in your multiple choices questions, and you should know which is the best. For example, replace and replaceAll, they have the same functionality. The old characters will be replaced with the new one, replacing all the occurrence of old characters. When those two methods appear in the same question, you may think replace only replace the first occurrence of the oldChar, right?

Suggestions
1. Be patient when you prepare your exams. Provide enough time for your preparation. Don't register the exam first, you can prepare for it and when you feel you are ready, then go register.

2. Coding. Dont just read the books, it is not enough, you must practice each topic by yourself. If you do your practice, the compile time error and runtime error will be a piece of cake for you! You can use IDE or not, it is your choice, the thing is understanding why the codes is working or why it is not working.

3. The most important part is the topics are not even distributed. I thought the topics about Generics and Threads will have a lot of questions, but I was wrong, it had a lot of File IO questions and made me suffering.I believe when you read the third question about the Files.copy at the beginning of this post, you experienced it already

4. Don't buy any mock exams, it is not necessary. All the resources I suggested is enough for you get a good score. If you can understand them well, the exams are not  too challenging.

I hope this post helps. Best wishes for your exam:)

Friday, October 11, 2013

Java Generated Code - Protocol Buffers



1) Download protobuf from protobuf website.

2) Install gcc and gcc-c++
 > sudo yum install gcc gcc-c++

3) Install Protocol Buffer Compiler using C++ compiler.(You can read the README file of protobuf)
./configure
make 
make check
make install

4) Generate Java file
A. now we have test.proto file, it is:

message ProgrammerInfo
{
    required string name = 1;
    required bool likeCoding = 2;

    enum CodingLanguage{
        JAVA = 0;
        PERL = 1;
        JAVASCRIPT = 2;
    }

    required CodingLanguage programLang = 3 [default = JAVA];
}

B. command to generate java file:
protoc -I=/home/haifzhan/sourceFolder --java_out=/home/haifzhan/outputFolder /home/haifzhan/sourceFolder/test.proto

Now the file called Test.java is generated.

How to use it?

ProgrammerInfo info = ProgrammerInfo.newBuilder().setName("haifzhan")
                            .setLikeCoding(true)
                            .setProgramLang(ProgrammerInfo.CodingLanguage.JAVA)
                            .build();


Wednesday, October 9, 2013

Guake dual monitor setup


Guake dual monitor setup

Guake is a drop-down terminal, I replace default terminal with guake. It worked properly when I only have one monitor, but it has a bug when use dual monitors. It always pops out on my laptop monitor which is not what I want.

Here I will (1) show you how to install Guake on Fedora/CentOs, (2) How to make Guake display on your external monitor.

(1) How to install Guake?
> sudo yum install guake.

(2) How to make guake available for your external monitor?(Guake version 0.4.4-9.fc18)
> sudo vim /usr/bin/guake

If you are using vim viewing your /usr/bin/guake file, you can search the keyword get_final_window_rect(self): using "/get_final_window_rect(self)and replace the existed method with  the following method:

 def get_final_window_rect(self):
        """Gets the final size of the main window of guake. The height
        is the window_height property, width is window_width and the
        horizontal alignment is given by window_alignment.
        """
        screen = self.window.get_screen()
        height = self.client.get_int(KEY('/general/window_height'))
        width = 80
        halignment = self.client.get_int(KEY('/general/window_halignment'))

        # future we might create a field to select which monitor you
        # wanna use
        #monitor = 0 # use the left most monitor
        monitor = screen.get_n_monitors() - 1 # use the right most monitor

        monitor_rect = screen.get_monitor_geometry(monitor)
        window_rect = monitor_rect.copy()
        window_rect.height = window_rect.height * height / 100
        window_rect.width = window_rect.width * width / 100

        if width < monitor_rect.width:
            if halignment == ALIGN_CENTER:
                window_rect.x = monitor_rect.x + (monitor_rect.width - window_rect.width) / 2
            elif halignment == ALIGN_LEFT:
                window_rect.x = monitor_rect.x
            elif halignment == ALIGN_RIGHT:
                window_rect.x = monitor_rect.x + monitor_rect.width - window_rect.width

        window_rect.y = monitor_rect.y
        return window_rect



Now restart your Guake, It should work!