/kb

personal knowledgebase

Archive for June, 2008

Repairing corrupted FAT32 drive

without comments

By using fsck as described below I managed to restore one of my hard drives.

$ fsck.msdos -r -v -V /dev/hda2

According to the man file, the options have the following effects:

-r Interactively repair the file system. The user is asked for advice whenever there is more than one approach to fix an inconsistency.
-v Verbose mode. Generates slightly more output.
-V Perform a verification pass. The file system check is repeated after the first run. The second pass should never report any fixable errors. It may take considerably longer than the first pass, because the first pass may have generated long list of modifications that have to be scanned for each disk read.

Reference: Fedora Mailing List.

Written by hgrimelid

June 28th, 2008 at 1:30 pm

Posted in General

Tagged with , ,

Strings and equality in Java

without comments

In order to compare objects in Java we are taught to use the equals()-method, except when the goal is to check for object reference, explicitly, then the == operator must be used. However, String objects does not behave entirely as expected, as seen from the following example.

  String s1 = "Fish";
  String s2 = "Fish";
 
  String s3 = new String("Fish");
  String s4 = new String("Fish");
 
  System.out.println(s1 == s2);       // true
  System.out.println(s1.equals(s2));  // true
 
  System.out.println(s3 == s4);       // false
  System.out.println(s3.equals(s4));  // true

The reason for this behaviour is that strings s3 and s4 are created outside of the string pool. In the string pool, String objects with the same value are set to the same object internally in order to save space.

Written by hgrimelid

June 4th, 2008 at 1:32 pm

Posted in Programming

Tagged with ,