Skip to content


Great Firefox Extension: Read It Later

Sometimes, I cannot find time to read my daily selected articles. I bookmark them, later I forget to read. E-mailing those articles can be a solution, however it is not effective and takes time to manage.

“Read It Later” is a Firefox extension that creates a manageable list of links to be read later. New features of it for Firefox 3 users are:

  • One click saving, sorting, tagging
  • Sync your list with any number of computers
  • Offline reading
  • Access anywhere
  • RSS feeds
  • Click to save mode
  • Save all tabs for later

Let’s see it in action:

  1. You like a page and want to save it for later reading. Just click the little “tick” at the end of the address bar. It is added your list and the little “tick” turns red. You can add links to your list by right clicking on the link and selecting “Read This Link Later”.

  2. You want to read them now. Click the little “book” icon in the navigation toolbar and select the desired link from the list.

  3. You are complete with the link and want to delete it from the list. Just click the “tick” icon in the address bar one more time, select the “Just Mark As Read” button to delete it. You can add your link to losts of social sites here before deletion if you want.

Tip: You can add links to your list quickly with the “Click to Save Mode” option. You click the links and they are added to your list automatically rather than followed through. It is activated by pressing “Alt + m” or clicking the little red “tick” icon in the bottom right corner. Try it.

Detailed explaination about “Read It Later” is here.
Firefox add-on page for “Read It Later” is here.

I think, it is great. Happy reading. :D

Posted in Firefox.

Tagged with , , , , .


My Top 10 Source Code Search Engines

Here is my top source code seach engines and I wanna share them with you.

  1. Google Code Search

  2. Krugle
  3. Byte My Code
  4. Dzone Snippets
  5. Code Fetch
  6. Codase
  7. Snipplr
  8. O’reilly Code Search
  9. JSourcery
  10. Merobase

Please share yours with us.
Happy coding. :D

Posted in Online Tools, Programming.

Tagged with , , , .


Say “Hello World!” Without Main Method in Java

Can you print out “Hello World!” without writing a main method in Java? Think for a while. Yes, you’re right. It can be possible using “static initialization blocks”. Let’s see the source code first:

package net.cavdar.staticinitializer;

/**
* Says “Hello World!” without main method. A simple use of
* static initialisation.
*
* @author accavdar
*/
public class HelloWorldWithoutMain {
static {
System.out.println(“Hello World!”);
System.exit(0); // prevents “main method not found” error
}
}

So, what is “static initializer block”?

  • A static initializer block is defined using the keyword static.
  • The code in a static initializer block is executed once by the virtual machine when the class is loaded.
  • A static initializer block cannot contain a return statement. Therefore, no need to specify a return type.
  • A static initializer block doesn’t have an argument list.
  • It can initialize only static data members of the class.

Because the static initializer block is executed when the class is first loaded, we can print out “Hello World” without writing a main method. The execution is stopped using “System.exit()” command. So, we prevent “main method not found” error. It is tricky. Isn’t it?

Happy coding. :D

Note: Write fully qualified class name (for our example “net.cavdar.staticinitializer.HelloWorldWithoutMain”) for configuring run options for main class, if you need.

Posted in Java, Tips & Tricks.

Tagged with , , , .


JUnit 4 in 60 Seconds

I played with JUnit 4 library this weekend and here is the short introduction to it:

  1. @Test
    Mark your test cases with @Test annotations. You don’t need to prefix your test cases with “test”.  In addition, your class does not need to extend from “TestCase” class.

    @Test
    public void addition() {
    assertEquals(12, simpleMath.add(7, 5));
    }

    @Test
    public void subtraction() {
    assertEquals(9, simpleMath.substract(12, 3));
    }

  2. @Before and @After
    Use @Before and @After annotations for “setup” and “tearDown” methods respectively. They run before and after every test case.

    @Before
    public void runBeforeEveryTest() {
    simpleMath = new SimpleMath();
    }

    @After
    public void runAfterEveryTest() {
    simpleMath = null;
    }

  3. @BeforeClass and @AfterClass
    Use @BeforeClass and @AfterClass annotations for class wide “setup” and “tearDown” respectively. Think them as one time setup and tearDown. They run for one time before and after all test cases.

    @BeforeClass
    public static void runBeforeClass() {
    // run for one time before all test cases
    }

    @AfterClass
    public static void runAfterClass() {
    // run for one time after all test cases
    }

  4. Exception Handling
    Use “expected” paramater with @Test annotation for test cases that expect exception. Write the class name of the exception that will be thrown.

    @Test(expected = ArithmeticException.class)
    public void divisionWithException() {
    // divide by zero
    simpleMath.divide(1, 0);
    }

  5. @Ignore
    Put @Ignore annotation for test cases you want to ignore. You can add a string parameter that defines the reason of ignorance if you want.

    @Ignore(“Not Ready to Run”)
    @Test
    public void multiplication() {
    assertEquals(15, simpleMath.multiply(3, 5));
    }
  6. Timeout
    Define a timeout period in miliseconds with “timeout” parameter. The test fails when the timeout period exceeds.

    @Test(timeout = 1000)
    public void infinity() {
    while (true)
    ;
    }

  7. New Assertions
    Compare arrays with new assertion methods. Two arrays are equal if they have the same length and each element is equal to the corresponding element in the other array; otherwise, they’re not.

    public static void assertEquals(Object[] expected, Object[] actual);
    public static void assertEquals(String message, Object[] expected, Object[] actual);

    @Test
    public void listEquality() {
    List expected = new ArrayList();
    expected.add(5);

    List actual = new ArrayList();
    actual.add(5);

    assertEquals(expected, actual);
    }

  8. JUnit4Adapter
    Run your Junit 4 tests in Junit 3 test runners with Junit4Adapter.

    public static junit.framework.Test suite() {
    return new JUnit4TestAdapter(SimpleMathTest.class);
    }

Happy coding. :D

Posted in TDD.

Tagged with , , .


Born of a Cuddly Penguin: TUX, Linux Mascot

Have you ever wondered how TUX borned? Yes, I have. Yesterday night, I performed a little search on net and here is the result:

Everthing starts with a debate on the linux-kernel mailing list about a suitable logo/mascot for Linux. Many many different ideas including noble beasts such as Sharks or Eagles and inspirations from other operating system logos suggested before Linus Torvalds (the father of Linux) said: “I am rather fond of Penguins”. :D

After several attempts to draw Penguins in various poses, someone suggested a Penguin holding up the world. Here is the part of famous email from Linus as a response:

So when you think “penguin”, you should be imagining a slighly overweight penguin (*), sitting down after having gorged itself, and having just burped. It’s sitting there with a beatific smile – the world is a good place to be when you have just eaten a few gallons of raw fish and you can feel another “burp” coming.

(*) Not FAT, but you should be able to see that it’s sitting down because it’s really too stuffed to stand up. Think “bean bag” here.

Now, if you have problems associating yourself with something that gets off by eating raw fish, think “chocolate” or something, but you get the idea.

Ok, so we should be thinking of a lovable, cuddly, stuffed penguin sitting down after having gorged itself on herring. Still with me?

OK, but why penguins? Linus explains his love of Penguins in another e-mail as follows:

“Linus likes penguins”. That’s it. There was even a headline on it in some Linux Journal some time ago (I was bitten by a Killer Penguin in Australia – I’m not kidding). Penguins are fun.

As to why use a penguin as a logo? No good reason, really. But a logo doesn’t really ave to _mean_ anything – it’s the association that counts. And I can think of many worse things than have linux being associated with penguins.

Having a penguin as a logo also gives more freedom to people wanting to use linux-related material: instead of being firmly fixed with a specific logo (the triangle, or just “Linux 2.0″ or some other abstract thing), using something like a penguin gives people the chance to make modifications that are still recognizable.

So you can have a real live penguin on a CD cover, for example, and people will get the association. Or you can have a penguin that does something specific (a Penguin writing on wordperfect for the WP Linux CD, whatever – you get the idea).

Compare that to a more abstract logo (like the windows logo – it’s not a bad logo in itself). You can’t really do anything with a logo like that. It just “is”.

Tuxs

Where does the name TUX come from? The first person to call the penguin TUX was James Hughes, who said that it stood for Torvalds UniX in a thread called “Let’s name the penguin” and it is accepted. However, many people observe that TUX is also an abbreviation of tuxedo, the outfit which springs to mind when they see a penguin.

And lastly, you can find lots of funny TUX pics from here. Enjoy it…

Posted in Linux.

Tagged with , , , .