How can I boot my Fedora 8 because I reinstalled my Windows XP?

I have my dual-boot on my laptop and it is installed with Windows XP as my primary operating system with a Fedora 8 over it.

I use GRUB for my boot loader and it is written on my Windows’ MBR. I have only one HDD, a SATA one, with three partitions. One for my Windows XP, my files and for my Linux box.

I reinstalled my Windows XP and my grub was fully erased in my Windows’ MBR. I could not boot my Fedora 8 anymore. I spent a day looking for a solution. I almost tried everything I see from the internet but unfortunately they do not work. But I found a working one. Meaning to say, don’t stop looking for it until you find it. This could be of big help to you. Just follow the simple instructions below.

  1. Insert your Fedora 8 installer (CD1) and set your boot sequence to your CD.
  2. When the CD is loaded, choose “Rescue installed system” from the menu.
  3. Wait for it to be loaded and follow the wizard.
  4. In the command, check first the name of your partitions,
    fdisk -l
    It says something like sda, sda1, sda2/hda, hda1, …
  5. In my system, my Windows is installed on my first partition which is the sda.
  6. Change the current directory to /mnt/systimage with a root privilege.
    chroot /mnt/sysimage
  7. Install grub to your MBR’s location device, which is the Windows partition
    /sbin/grub-install /dev/sda
  8. Perfect! Restart your system and set the boot to your hard drive. It will show you the menu listed your Windows and your Linux.
  9. If these steps will not work, repeat again because this really works.

Currently I have my Fedora 8 and Windows XP installed on my laptop. I am enjoying using them for different purpose.

Welcome to dual-booting!

What do you mean by static in Java?

When I was learning Java, I always get confused what static variables and static methods mean. I read a lot of books explaining static and still it’s not clear to me. Let’s consider the “Hello World” class and program in Java.

// HelloWorld.java
public class HelloWorld {
	public static void main (String args[]) {
		System.out.println ("Hello World!");
	}
}

and consider the following class,

// HelloWorld.java
public class HelloWorld {
	public void main (String args[]) {
		System.out.println ("Hello World!");
	}
}

Are these two classes the same?  Of course, they are not the same. The first class has a static keyword in its main method and the other one is simply a method without this keyword static.As always Java follows this signature in the first class. And we consider this as a complete and a running program in Java. The static main method means that all objects created out from this class has only one method main. And you can call main method without instantiating the class and directly invoke this method with the name of the class (HelloWorld.main()).All instance variables and methods of the class that are declared as static are global variables or global methods. And we can call them directly without creating an object from a class by putting it’s class name in front of a variable and a method name in between the dot operator.Let’s consider a class counter example. We define a class, Song, and define the global variable count that increments every time we create an instance of the class, Song.

// Song.java
public class Song {
	private String title;
	// global variable
	public static int count;

	public Song (String title) {
		this.title = title;
		// Increment class variable count every time song is created.
		Song.count++;
	}

	public String toString () {
		return title;
	}
}

// SongDriver.java
public class SongDriver {
	public static void main (String args[]) {
		Song hello = new Song ("Hello");
		System.out.print ("Song " + Song.count + ": ");
		System.out.println (hello);
		Song elMundo = new Song ("El Mundo");
		System.out.print ("Song " + Song.count + ": ");
		System.out.println (elMundo);
	}
}

The program simply increments count when the hello object is created. And it increments again when elMundo is created. And we display the value of count by invoking count with it’s class name, Song.count.Therefore, when we say static, it is global and we can also call them class variable or class methods.

How to write a simple internet/web robot in Java?

When we say robot, yes, it is some kind of a difficult thing to do. But before we say it, let’s try writing them first.

I started writing simple internet/web robot application in Java. A robot that will scrape data from the web. A robot that will add entry to your web. And of course, you can write any kind of robots you like.

There are lot of web tools you can freely use and download from the internet. Since I use Java for my robot, I use HtmlUnit, and Selenium RC (Remote Control). These are only web tools I tested and tried so far. They have their own specific usage and purpose.

In my own experience, I use HtmlUnit for gathering and processing data from the website; and I use Selenium Remote Control for automating my own website to login and process data. These are very interesting thing I’ve learn so far.

Here is a Selenium Remote Control Java source code to open a Google site, type “Ziplok Java” in the search box and click search button:

import com.thoughtworks.selenium.*;
import junit.framework.*;

public class GoogleRobotSearch {
 private Selenium sel;

 public GoogleRobotSearch () {
  sel = new DefaultSelenium("localhost", 4444, "*firefox", "http://www.google.com");
  sel.start();
 }

 public void search() {
  sel.open("http://www.google.com/webhp?hl=en");
  sel.type("q", "Ziplok Java");
  sel.click("btnG");
  sel.waitForPageToLoad("5000");
  sel.stop();
 }

 public static void main (String args[]) {
  GoogleRobotSearch xybot = new GoogleRobotSearch ();
  xybot.search();
 }
}

And here is an equivalent Java source code written in Java with HmlUnit:

import com.gargoylesoftware.htmlunit.WebClient;
import com.gargoylesoftware.htmlunit.html.HtmlForm;
import com.gargoylesoftware.htmlunit.html.HtmlPage;
import com.gargoylesoftware.htmlunit.html.HtmlSubmitInput;
import com.gargoylesoftware.htmlunit.html.HtmlTextInput;

public class GoogleRobotSearch {
 private String bUrl;

 public GoogleRobotSearch (String url) throws Exception {
  bUrl = url;
 }

 public void search () throws Exception {
  WebClient wb = new WebClient ();
  HtmlPage p = (HtmlPage) wb.getPage(bUrl);

  HtmlForm f = p.getFormByName("f");
  HtmlTextInput text = (HtmlTextInput) f.getInputByName("q");
  HtmlSubmitInput submit = (HtmlSubmitInput) f.getInputByName("btnG");
  text.setValueAttribute("Ziplok Java");

  HtmlPage resultPage = (HtmlPage) submit.click();
  System.out.println(resultPage.asText());
 }

 public static void main (String args[]) throws Exception {
  GoogleRobotSearch xyro = new GoogleRobotSearch ("http://www.google.com/");
  xyro.search ();
 }
}

That’s it! It is just easy to write an internet/web robot.

How will you type a text into the input file element in Selenium?

The common problem in Selenium is typing a text into the input element (<input type=”file” />). And this is the common problem I read from most of the forums and I also find it difficult to solve.

I am just a newbie in Selenium and I do not know how to handle problems using this web testing tool. I’ve been Googling in a week just to find an answer. I was lucky because I found one and it really works.

Here are the possible solutions to your problem:

  • Use *chrome environment type rather than *firefox or *iexplore.
  • Set your singed.applets.codebase_principal_support to true in your Mozilla configuration.

I’m crossing my finger on that. Try it and tell me if that works in your machine.

How to update a file in Java?

I’ve been reading books in Java just to find a code on how to update a file just to append a text in it. A lot of code fragments on Java File available but it just give you how to write a file alone, and or how to read a file alone. This article will help you to create at the same time append a text to an existing file.

Here’s a sample of simple and short Java code to create (if not created) and append a file if existing.

public void createOrAppendFile (File f, String text) throws IOException {
 BufferedWriter bw = new BufferedWriter (new FileWriter (File, true));
 bw.write (text);
 bw.newLine();
 bw.flush();
 bw.close();
}

How to setup a headless application in Linux?

I am a newbie to Linux environment and do not know every commands available inside the shell.

This entry will explain and demonstrate to all newbies out there and to those who have not know to setup a headless application in Linux and for those who want to setup headless application in Linux.

Install the following in your Linux distro if you have not install them yet.
1. Xvfb
2. startx
3. import from ImageMagick Tools

Let’s try to run Firefox without a visible display.
1. Start Xvfb.
startx -- `which Xvfb` :1 -screen 0 1024x768x24
2. start Xvfb running on :1 with a screen size of 1024×768 and 24bits/pixel color depth.
DISPLAY=:1 firefox
3. Take a screenshot.
DISPLAY=:1 import -window root firefox.png
Thank you to Jordan Sissel for his blog regarding this problem.