Wednesday, February 28, 2007

Little Java program

My first little java program... after a few tries with the Hello World and reading a book I did my beeting game. It is not a great thing but I need to get used to break problems in parts - the example below doesn't do 100% that.

I need to be able to break each action as much as possible, at the begining I thought it was going to be easy but for this simple example I kept falling into creating one big procedural class. I should be able to break it even more and caught more exception (like entering chars/strings instead of numbers) and will do it after I finish the second book of begining java.

import java.text.NumberFormat;

public class Account {

static int balance;

public Account (int amount) {
balance = amount;

public Account () {
balance = 0;

public void credit (int betamount){
balance = balance + (2 * betamount);

public vo
id debit (int betamount){
balance = balance - betamount;

public boolean checkBet (int betamount){
if (betamount > balance) {
return false;
} else {
return true;

public void showbalance (){
NumberFormat nf = NumberFormat.getCurrencyInstance();
System.out.println("Available balance is : " + nf.format(balance));

Main class

import java.util.Random;
import java.util.Scanner;

public class BettingGame {

static Random myRandom = new Random();
static Scanner myScanner = new Scanner(;

c static void main(String[] args) {

Account myAccount = new Account(1000);
int available;
boolean keepgoiang = true;

do {

System.out.println ("How much will you bet? ");
if (!myScanner.hasNextInt()){;
int bet = myScanner.nextInt();
if (bet == 0) {

do {
System.out.println ("Which number do you chose");
if (myScanner.hasNextInt()){
}while (!myScanner.hasNextInt());
int number = myScanner.nextInt();
int ra
nnum = RandomGenerator(0,10);
System.out.println("Lucky number is: " + rannum);
if (number == rannum){
System.out.print("You win. ");;
} else {
System.out.print("Better Luck next time. ");

} else {
System.out.println ("Not enough founds for that bet");
if (Account.balance == 0) {
keepgoing = false;

}while (keepgoing);

if (myAccount.balance > 0 ) {
System.out.println("Great you quit with money on your pocket");
} else {
System.out.println("You are fucked!");


public static int RandomGenerator (int min, int max){
int RamNumber = myRandom.nextInt(10) + 1;
return RamNumber;


An image of the output on the console:

Monday, February 12, 2007

Fedora Eclipse 3.2.0 and jdk-1_5_0

I am leraning Java (trying to at least) and during the installation I was very pleased to see the Eclipse package under the options but the version installed uses jre-1.4.2-gcj. That is the java runtime engine from the gnu project. It is a great effort but to someone who is reading books about java and the Sun version you get to cases where particular clases/packages (I still don't get hold of the names) are not available. Therefore I installed the Sun JDK.

As always after googling a little I found a great how-to and here are my notes. The link to the original post is at the botton of this post.

First download a jdk/jre from Sun. At the moment of writing this version 6 was available. At work I using a tool to create vxml code with eclipse that recommends 1.4.2 so I choose 1.5 (just in the middle).

I downloaded jdk-1_5_0_11-linux-i586.bin. There is a rpm but every site I checked recommends not getting closed to the sun rpm and all prefers to just run the binary.

Once downloaed copy it to /opt directory and give it rights to be executed. The easiest way is chmod +x filename.

Next cd to /opt and just run the binnary.


This will install everything under the current directory. In my case I ended with /opt/jdk1.5.0_11

Note that the JDK installed Sun JRE so you might want to use this jre instead that the gnu one when browsing the web. So to do this you just create a link on the mozilla

ln -s /opt/jdk1.5.0_11/jre/plugin/i386/ns7/ /usr/lib/mozilla/plugins/

If you use firefox don't worry as firefox checks the mozilla plugins.

Now we start with the tricky part. You need to create a file to include the new paths, in my case I created the following:

[ricardo@mybox]$ more /etc/profile.d/
export J2RE_HOME=/opt/jdk1.5.0_11/jre
export PATH=$J2RE_HOME/bin:$PATH

Once you have this file execute it by typing:

source /etc/profile.d/

This wll set your new java paths. To check it run the command below:

[ricardo@mybox]$ which java

Next step is to run the following command to be able to later change the from gnu java to sun java.

/usr/sbin/alternatives --install /usr/bin/java java /opt/jdk1.5.0_11/jre/bin/java 2

Then type

/usr/sbin/alternatives --config java

This will show you something like this:

[ricardo@mybox]$ /usr/sbin/alternatives --config java

There are 2 programs which provide 'java'.

Selection Command
* 1 /usr/lib/jvm/jre-1.4.2-gcj/bin/java
+ 2 /opt/jdk1.5.0_11/jre/bin/java

Enter to keep the current selection[+], or type selection number:

In the case above the + sign was on option 1. I selected 2 so it changed to the new version I installed.

Final step is to run the command below and get a similar entry as mine.

[ricardo@mybox]$ /usr/sbin/alternatives --display java
java - status is manual.
link currently points to /opt/jdk1.5.0_11/jre/bin/java
/usr/lib/jvm/jre-1.4.2-gcj/bin/java - priority 1420
slave keytool: /usr/lib/jvm/jre-1.4.2-gcj/bin/keytool
slave rmiregistry: /usr/lib/jvm/jre-1.4.2-gcj/bin/rmiregistry
slave jre_exports: /usr/lib/jvm-exports/jre-1.4.2-gcj
slave jre: /usr/lib/jvm/jre-1.4.2-gcj
/opt/jdk1.5.0_11/jre/bin/java - priority 2
slave keytool: (null)
slave rmiregistry: (null)
slave jre_exports: (null)
slave jre: (null)
Current `best' version is /usr/lib/jvm/jre-1.4.2-gcj/bin/java.

Now Eclipse. Eclipse keep using the old runtime everytime you create a new project.

To solve this when you create a project go to the JRE section and click on "Configure JREs" as shown on the image below.

Then on the following screen you click on add and complete the form with the details shown below (note that the libraries section will be auto completed once you selcted the home directory).

The final step is to check the new JRE and every new project will be using the Sun engine.

That is all, Good luck!

Much more information on the link below:

Sunday, February 11, 2007

Install Fedora Core 6 on a Dell Latitude D620

I got a new laptop at work (the hp nx6125 decided to give up on me) and as every time I have a new pc/laptop I will try to run linux on it until -as always- remember that I am a windows sofa lazy user and go back to it. Therefore until my concious realizes that I am trying to learn something here are the notes on what I did. (note if you want notes on how to install windows just click next during installation until death knocks on your door).

I use two flavours of Linux.. Fedora for personal use and Debian for Servers.. Why? No idea.

Note that his are my notes.. the urls where I got all this from are below. This notes are for me to avoid googling again for this in the future.

Downloaded the hp dvd image and booted from the DVD and just hit enter. I found later notes of people recommending the following boot options:

linux i686
--- Check Seems that some early versions installed the wrong architecture kernel version (in the document i586 instead of i686).

linux resolution=1440×900
--- For some reason some use this kind of resolution. I haven't tried it yet but not sure if this is for the nvidia or intel board.

The installation is straight forward and I surf around the packages and selected the ones I wanted. Note that after the installation Fedora will try to update all your applications, if you select Extras as package sources this update process will take a bit longer so have a good book or movie ready while your system goes to the net and updates everything (including kernel).

The hardware on my pc is:

[root@box loginname]$ /sbin/lspci
00:00.0 Host bridge: Intel Corporation Mobile 945GM/PM/GMS/940GML and 945GT Express Memory Controller Hub (rev 03)
00:02.0 VGA compatible controller: Intel Corporation Mobile 945GM/GMS/940GML Express Integrated Graphics Controller (rev 03)
00:02.1 Display controller: Intel Corporation Mobile 945GM/GMS/940GML Express Integrated Graphics Controller (rev 03)
00:1b.0 Audio device: Intel Corporation 82801G (ICH7 Family) High Definition Audio Controller (rev 01)
00:1c.0 PCI bridge: Intel Corporation 82801G (ICH7 Family) PCI Express Port 1 (rev 01)
00:1c.1 PCI bridge: Intel Corporation 82801G (ICH7 Family) PCI Express Port 2 (rev 01)
00:1c.2 PCI bridge: Intel Corporation 82801G (ICH7 Family) PCI Express Port 3 (rev 01)
00:1d.0 USB Controller: Intel Corporation 82801G (ICH7 Family) USB UHCI #1 (rev 01)
00:1d.1 USB Controller: Intel Corporation 82801G (ICH7 Family) USB UHCI #2 (rev 01)
00:1d.2 USB Controller: Intel Corporation 82801G (ICH7 Family) USB UHCI #3 (rev 01)
00:1d.3 USB Controller: Intel Corporation 82801G (ICH7 Family) USB UHCI #4 (rev 01)
00:1d.7 USB Controller: Intel Corporation 82801G (ICH7 Family) USB2 EHCI Controller (rev 01)
00:1e.0 PCI bridge: Intel Corporation 82801 Mobile PCI Bridge (rev e1)
00:1f.0 ISA bridge: Intel Corporation 82801GBM (ICH7-M) LPC Interface Bridge (rev 01)
00:1f.2 IDE interface: Intel Corporation 82801GBM/GHM (ICH7 Family) Serial ATA Storage Controller IDE (rev 01)
00:1f.3 SMBus: Intel Corporation 82801G (ICH7 Family) SMBus Controller (rev 01)
03:01.0 CardBus bridge: O2 Micro, Inc. OZ601/6912/711E0 CardBus/SmartCardBus Controller (rev 40)
09:00.0 Ethernet controller: Broadcom Corporation NetXtreme BCM5752 Gigabit Ethernet PCI Express (rev 02)
0c:00.0 Network controller: Intel Corporation PRO/Wireless 3945ABG Network Connection (rev 02)

From here the only things that I had to work around were:
00:02.1 Display controller: Intel Corporation Mobile 945GM/GMS/940GML Express Integrated Graphics Controller (rev 03)
0c:00.0 Network controller: Intel Corporation PRO/Wireless 3945ABG Network Connection (rev 02)

I will add the details for this below on the document.


Sudo helps normal accounts to run application as root without being root. To add the normal user account as root run the command visudo and enter the following line.

loginname ALL=(ALL) ALL

The sudo configuration is pretty easy and straight forward. You can also create different groups to give access to diferent things like files or applications. In the above case would have access to everything and it will need to type it's own password everytime that sudos a command.


Yum is the apt-get of Fedora and the life saver of the novice that would take care of dependencies and file location when isntalling/updating/removing new software. I remember on '96 or '97 playing with Slackware (influenced by Antonio Ex@@@) and FreeBSD (influenced by Juan Carlos Ne@@@@@) and untaring files and running the make, make config, make install to find out that a file somewhere was not present or your gcc was not the correct one, etc. And yes if you do the manth that was more than 10 years ago and still don't know shit. One day If I get rich and don't need to work anymore I will spend time to learn Slackware (imho the best way to learn what happens under the hood).

I added freshrpm to the repository

[root@box loginname]cd /etc/yum.repos.d/
[root@box loginname]# more freshrpms.repo
name=FreshRPMs for Fedora Core $releasever - $basearch

*****Fedora Kernel Headers

We will need the kernel headers at some point (wireless) and always a pain in the ass but I follow this steps found on the web and it worked.

Note this is a 99% copy of a page I found with my notes around. The original link is below (sorry for this guys!).

First move to:
cd /usr/src/redhat/

We need to download the kernel SRPM package, whose version and release match our currently running kernel. This version is shown by the following command:

# uname -r

I use the following link wget

Next thing is to install the SRPM package. This just extracts the included files in the proper directories under /usr/src/redhat/ or to the directory tree you use for building. It does not actually install any kernels. As a user, run:.
# rpm -ivh kernel-$(uname -r).src.rpm

This extracts the kernel source packages and the various patches in the SOURCES directory and the spec file in the SPECS directory. The SRC RPM file is not needed any more.

Next, we execute the %prep stage of the spec file, by issuing the following command:

# rpmbuild -bp --target $(arch) --rmsource --rmspec SPECS/kernel-2.6.spec

This extracts the kernel source code package and applies all the Red Hat patches. All the files are placed in the BUILD directory. Here follows an explanation of the options:
-bp : Execute only the %prep stage
–target : Specify the architecture. You can explicitly put your architecture, instead of the $(arch) in this option. This is the same thing.
–rmsource : This removes all the kernel SRC RPM related files under the SOURCES directory, so no unneeded files are left to the system.
–rmspec : This also removes the spec file from the SPECS directory.

Now, we move to the directory containing the fedora kernel sources:

# cd /usr/src/redhat/BUILD/kernel-2.6.19/linux-2.6.19.i686

Copy the proper kernel configuration file, that matches your architecture, from the configs directory and place it in our current working directory, naming it as .config and replacing the already existent .config file. For example, I used the kernel-2.6.14-i686.config file :

# cp configs/kernel-2.6.19-i586.config .config

These files most probably contain the same configuration options, but we do this for completeness.

Next thing is to add the proper kernel release number to the Makefile (in directory: BUILD/kernel-2.6.19/linux-2.6.19.i686/). As it is stated in the Fedora release notes, in order to "protect the innocent" the value of the EXTRAVERSION field is -prep. Open this Makefile in a text editor and replace the -prep with the release number of your currently running kernel. For example, my running kernel at the time of writing is 2.6.14-1.1637_FC4. I replace the:


with :
EXTRAVERSION = -1.2895.fc6

# vi /usr/src/redhat/BUILD/kernel-2.6.19/linux-2.6.19.i686/Makefile
EXTRAVERSION = -1.2895.fc6
NAME=Avast! A bilge rat!

The last action of the basic configuration is to run the following command:

# make oldconfig

This command sets the default answers to all kernel configuration questions according to the settings of our .config file. This command is more relevant to kernel re-building, but won’t hurt issuing it.

At this point, if you try to compile any third party kernel modules using this directory as the kernel source directory, you will most probably encounter errors. This is because some more preparation should be done to the kernel sources (this mainly involves the include directory).

A full compilation of the kernel would set all these things straight, but one of the goals is to avoid the compilation of the kernel to save some time. We have not modified any of the kernel configuration options or applied any extra patches, so this would be pointless anyway.

I remind that our current directory is:

A file, named Module.symvers, which contains information about the native kernel modules, needs to be present inside our current directory. This file is normally created after the native kernel modules are compiled. Since we are not building the kernel or any modules and since we have not modified the default kernel configuration, we can use the Module.symvers file, which is included in the official fedora kernel-devel RPM.

The presense of this file is important when we compile any third party modules using these kernel headers. If it’s not there, then our modules will not contain any dependency information, regarding the native kernel modules. This way, if the third party module depends on some native kernel modules, then you will have to load the latter manually.

So, copy the Module.symvers file from the directory, where the official fedora kernel-devel package is installed, into our current directory:

# cp /usr/src/kernels/$(uname -r)-$(arch)/Module.symvers .

Finally, we issue the following command:

# make prepare scripts

This creates:

  1. The include/linux/version.h file, which contains kernel versioning information.
  2. The proper asm symlink for your platform and the asm-offsets.h file inside your platform’s specific asm directory.
  3. The scripts that come with the kernel sources. These are needed when we compile third party modules using these headers.

This is the proper and most complete way of preparing our headers, instead of compiling each of the files mentioned above individually.

That should be the end of all the needed actions in order to accomplish our goal. Final Words: At this point, we have a custom directory that contains:
  • The fedora kernel sources. The kernel has not been compiled.
  • The kernel headers that match those of the kernel-devel RPM package with the difference that they are complete. No files are missing.
The directory /usr/src/redhat/BUILD/kernel-2.6.19/linux-2.6.19.i686 can be moved to any place you like. Give it a proper name that includes your currently running kernel version and release. The kernel headers, contained in this directory, can be used in order to compile any third party kernel modules. The rest of the contents of the /usr/src/redhat/BUILD/ directory, can be deleted, unless you need it.

*****Wireless Intel Corporation PRO/Wireless 3945ABG
My wireless is a Intel. I don't recall exactly what I did as I surf a lot but here is what I remember:

0c:00.0 Network controller: Intel Corporation PRO/Wireless 3945ABG Network Connection (rev 02)

a) Install dkms-ipw3945, ipw3945d and ipw3945-firmware from freshrpms, install the kernel-devel package for your kernel (already done) and reboot.

yum install ipw3945 (not sure)
yum install dkms-ipw3945-1.2.0-1.noarch.rpm
yum install ipw3945-firmware-1.13-1.noarch.rpm
yum install ipw3945d-1.7.22-4.i386.rpm

b) Add the NetworkManager to Gnome so I can geet a fancy icon to log into networks.
  1. Install the software: su -c 'yum install NetworkManager NetworkManager-glib NetworkManager-gnome'
  2. Set the main service to start on boot: su -c '/sbin/chkconfig --level 345 NetworkManager on'
  3. Set the dispatcher service to start on boot: su -c '/sbin/chkconfig --level 345 NetworkManagerDispatcher on'
  4. Start the services: su -c '/sbin/service NetworkManager start ; /sbin/service NetworkManagerDispatcher start'
  5. Now enter this command to load the tray icon: NetworkManagerInfo & (or just Reboot as I did).
This was really easy. Install PPTP and the pptpconfig GUI using the following commands:

# rpm -Uvh
# yum --enablerepo=pptp-stable install pptpconfig

Then open ppptconfig application from the Applications/Internet menu and complete the configuration. On my case I had to disable (or enable?) one of the Encryption options to be able to connect to my work. Also on the Routing tab you can either select to route all traffic through the tunnel or set up rules so your internet traffic goes through your home broadband and your corporate applications go through the tunnel (don't know if this is a good idea on a security point of view).

Mounting NTFS partition on FC6

My laptop has 2 windows partions, one for the windows applications/windows installation and a second one to keep files, documents, etc. This is to avoid any problem in case I need to reinstall windows and to use as sandbox with the Fedora partition.

My steps were:

a) As root (or sudo)
yum install fuse fuse-libs ntfs-3g ntfsprogs ntfsprogs-gnomevfs

b) Check disk configuration to see where the partition is:
[root@box loginname]# /sbin/fdisk -l
Disk /dev/sda: 60.0 GB, 60011642880 bytes
255 heads, 63 sectors/track, 7296 cylinders
Units = cylinders of 16065 * 512 = 8225280 bytes

Device Boot Start End Blocks Id System
/dev/sda1 * 1 1958 15727603+ 7 HPFS/NTFS
/dev/sda2 1959 5222 26218080 7 HPFS/NTFS
/dev/sda3 5223 5235 104422+ 83 Linux
/dev/sda4 5236 7296 16554982+ 5 Extended
/dev/sda5 5236 7296 16554951 8e Linux LVM

The partition I want to mount is /dev/sda2, so I change the /etc/fstab and add the last line on the example below:

[root@box loginname]$ more /etc/fstab
/dev/VolGroup00/LogVol00 / ext3 defaults 1 1
LABEL=/boot /boot ext3 defaults 1 2
devpts /dev/pts devpts gid=5,mode=620 0 0
tmpfs /dev/shm tmpfs defaults 0 0
proc /proc proc defaults 0 0
sysfs /sys sysfs defaults 0 0
/dev/VolGroup00/LogVol01 swap swap defaults 0 0
/dev/sda2 /mnt/drive_e ntfs-3g rw,defaults,umask=0000 0 0

Where /mnt/drive_e is a directory I created to "label" the mounting point.
Then ntfs-3g is the file system and note that rw will make the partition read/write. You can also set it up as ro (read only). Check the man mount for the meaning of umask as it gives several options.

*****Screen Resolution Intel 945 Dell 620

Surfing around I found that many of this dells come with a nvidia driver and I guess my company is a cheaper one and went for the Intel 945 option.

The lspci shows the version of the Display controller
00:02.1 Display controller: Intel Corporation Mobile 945GM/GMS/940GML Express Integrated Graphics Controller (rev 03)

Installation went well but the system keeps booting on 1024x768. I read along and I can see that I can at least run this laptip at 1200x800 and in some cases at 1440x900. Haven't been able to run at 1440x900 but here is what I did for 1280x800.

a) yum install 915resolution
It looks that you need this utility to run customs resolution on the 945. Also this utility needs to be run everytime that you boot your pc.

A few tips, after installing run "locate 915resolution" if nothing is found then run an updatedb.

After install run a 915resolution -l and you will get a list of all options. Probably 1280x800 is not there so run the following options to create the 1280x800

/usr/sbin/915resolution 49 1280 800
/usr/sbin/915resolution 38 1280 800
/usr/sbin/915resolution 58 1280 800

As you have to run this everytime the box boots you can add them on the /etc/rc.local.

I also added the file /etc/default/915resolution so that it has XRESO=1280 YRESO=800.

Finally I changed the /etc/X11/xorg.conf as follows (note that everytime I change the display configuration using the gnome utility this file looses this changes - I was trying to have 2 montiros running) but along the above steps are done it doesn't seem to affect it. Just in case below are the details I originally used on xorg.conf.

Section "Monitor"
Identifier "Monitor1"
VendorName "Monitor Vendor"
ModelName "Monitor 1024x768"
HorizSync 24.0 - 64.0
VertRefresh 43.0 - 60.0
Option "dpms"

Section "Device"
Identifier "Videocard0"
Driver "i810"
BusID "PCI:0:2:0"

Section "Screen"
Identifier "Screen0"
Device "Videocard0"
DefaultDepth 24
SubSection "Display"
Viewport 0 0
Depth 24
Modes "1440x900" "1280x800" "1024x768" "800x600" "640x480"

(again copied from another site)
For some of us, DMA isn't enabled by default for our wonderful FC5 powered computers (like some Dells and Thinkpads). I've been spending a month or two (off and on) trying to find out how to work arround this problem. The long answer, from what I understand, for why this happens has to do with an IDE and a SATA/PATA drivers that are conflicting with one another and trying to control the drive (you might notice that the drive is labled /dev/hdc) and the DMA doesn't work well... or at all. According to the bug-report that I read, this is not a bug but an expected side effect of some DVD drive setups. With recently released kernels it is not required to make a custom-build, so this is done based off of a yum-installed kernel.

Signs of this problem include choppy DVD playback or slow image reading and when running "hdparm -d1 /dev/hdc" to turn DMA on it will respond with "Operation not permitted". If you see this and, like me, have been trying to find a way to enable DMA on your drive this should help you and I'm writing this so that people with this (apperently common) problem can referance one place to solve it.

Ok, now to get to the part where I tell you how to...

In the terminal:

$su -
#gedit /etc/modprobe.conf

add the following line to the end of the file (leaving an extra empty line behind it):

options libata atapi_enabled=1

save, close and continue in the terminal:

#gedit /boot/grub/menu.lst

add the following to the boot parameter:


save, close and reboot.

Now your DVD drive should be called "/dev/scd0", DMA will not be needed and Xine should be able to play it without the choppyness. Further effects of a working DVD drive (from what I hear, tell myself to make me feel better and dream) include faster CD ripping speeds and general read speeds, improved oooo-aaahhhh factor of showing off Linux, improved firtility and a marginal decrease in Windows dependancy...

*****Other installations
yum install flash-plugin
yum install wifi-radar
yum install wlassistant
yum install gnome-commander

*****Usefull URLs
Below are the URLs I used to get the information. Read them as the people who wrote them knew what they were doing that is not my case most of the time.