For each in java

Java has a for loop, but it didn't have a for each functionality. From jdk5.0 onwards they have added for each functionality in Java.

public class Example{
public static void main(String args[]) throws Exception {

int[] values = { 2,4,6,8,10,12,14,16,18,20 };

for( int i : values)
{
System.out.println(i);
}

}
}


Given an array, a loop variable can select each element of the array in each iteration.

In the above example values is an array of integers. i is an iterator(a variable used for traversing through the elements). In the first iteration i will take value 2 , then it next iteration value 4 and so on until the entire array elements are used.

Formatting a disk partition

A partition can be formatted to different file systems. For a pen drive FAT partition is adopted universally. Linux partition is commonly ext3/ext2/ext4/reiserfs.. . Windows usually work with FAT or NTFS partitions.


For formatting a partition as FAT ( as in the case of a pen drive ), give the command
mkfs.vfat /dev/sdb1
where /dev/sdb1 corresponds to the required partition. To get partition number plug in the device, mount it (automatic), get the number from /etc/mtab.
Note: The partition should have unmounted before formatting it.


Similar commands
mkfs.bfs       mkfs.ext2      mkfs.minix     mkfs.reiserfs
mkfs.cramfs mkfs.ext3 mkfs.msdos mkfs.vfat
can be used for formatting as other file systems.

GUI tools for formatting a partition are gparted (for Gnome) and qtparted (for kde).

Partitioning drives

fdisk is used for partitioning disks. It can be used for creating , deleting partitions , change fs type, labelling etc. It can be executed only as a privileged user. Simply type fdisk followed by the device file name as shown

$ fdisk /dev/sda
The number of cylinders for this disk is set to 30394.
There is nothing wrong with that, but this is larger than 1024,
and could in certain setups cause problems with:
1) software that runs at boot time (e.g., old versions of LILO)
2) booting and partitioning software from other OSs
(e.g., DOS FDISK, OS/2 FDISK)

Command (m for help):


Different operations needed can be specified here. To get a list of possible operation press 'm'.


Command action
a toggle a bootable flag
b edit bsd disklabel
c toggle the dos compatibility flag
d delete a partition
l list known partition types
m print this menu
n add a new partition
o create a new empty DOS partition table
p print the partition table
q quit without saving changes
s create a new empty Sun disklabel
t change a partition's system id
u change display/entry units
v verify the partition table
w write table to disk and exit
x extra functionality (experts only)

Command (m for help):



  • To create a new partition

  • The sequence of commands required are given below

    • Type fdisk followed by device file name as shown above.
    • Press 'n' for creating a new partition.
    • It will ask for partition type ( logical / primary )* . Select which ever is needed.
    • Give the partition number
    • Give the first cylinder number . Press Enter for default value.
    • Give the last cylinder or the size required . For eg; +1024M for 1GB. Here also press Enter for default value
    • To change file system type of the partition, press 't'
    • Give the partition number
    • Give hexcode of the required fs type ( press 'L' to get list of all fs types ).
    • Press 'w' for writing the changes to disk. ( To exit without any change to partition table press 'q' ).


  • To delete a partition
    • Type fdisk followed by device name as shown above.
    • Press 'n' for deleting a partition.
    • Give the partition number
    • Press 'w' for writing the changes to disk. ( To exit without any change to partition table press 'q' ).


* Only primary partitions have bootable property (OS can be installed in any partition as long as its boot loader is kept in some bootable location). A hard disk can have a maximum of four primary partition. To create more partition a partition called extended partition is to be created ( this will be counted as one primary partition ). Inside this extended partition many logical partitions can be created.

GUI is available for modifying the partition table. In SUSE they have their own GUI which can be found in Yast control center. In general gparted (Gnome) and qtparted are used as GUIs.

Installing GRUB

GRUB( GRand Unified Boot loader) can be installed in many ways
  • from current linux installation
  • from live cd

  1. Installing GRUB from current linux.
  2. Type the command
    # grub-install /dev/sda
    where sda corresponds to the harddisk where the boot loader is being installed. The boot loader is in a small portion and hence it keeps all other necessary files in another location. By default the boot loader takes the configuration for the grub from /boot/grub/menu.lst


    note: If the command was executed from a live cd then the grub will look for menu.lst in /boot/grub/ which is actually in the 'cd rom'. Therefor simply executing the command from a live cd won't work.

  3. Installing from a rescue cd

  4. Rescue disks gives an option to boot into an already installed OS.(For example Suse gives options to boot into installed SUSE, Fedora gives option for 'chroot'into already existing fedora)
    From there type command
    # grub-install /dev/sda
    It will install grub.

  5. Installing from a live cd

  6. I am considering Ubuntu as an example

    execute the following commands

    #sudo grub
    grub>find /boot/grub/stage1
    grub>root (hd0,0)
    grub>setup (hd0)

    entries for other OS (like windows ) has to be added manually.
  7. Another method to install from a live cd


  8. $ sudo mount /dev/sda1 /media/disk
    $ sudo mount --bind /dev /media/disk/dev
    $ sudo chroot /media/disk
    # grub-install /dev/sda
    # exit


Stardict : Dictionary for linux

Stardict is both an online and offline dictionary for linux ( it is available for windows too).



Some of the features which I liked

  • Different dictionaries like OALD(Oxford Advanced Learners Dictionary), Orient Longman, Meriam Webster , Britannica and a lot more can be added to it. They are freely downloadable from its site.
  • Word can be specified as a regular expression which gives a list of available words matching it.
  • Similar spelled words are also listed
  • Keeping the stardict in system tray, selecting any text in linux it will give a pop up of meaning.

Go to stardict home page for more details