Decreasing PDF filesize in Debian

October 10th, 2012 — 9:18am

My colleague attempted to send an e-mail with a 9.1MB PDF file as an attachment, but the receiving mail server didn’t fancy this all too much. So, I want on a quick quest to make the PDF file smaller, to shrink it, as it were. After some Googling around, I found a thread which said it would be possible with gs. It was. The filesize went from 9.1MB (otherwise known as humongous) to 2.1MB (otherwise known as acceptable). For future reference: here’s the command:

gs -sDEVICE=pdfwrite -dCompatibilityLevel=1.4 -dPDFSETTINGS=/screen -dNOPAUSE -dQUIET -dBATCH -sOutputFile=output.pdf input.pdf

Comment » | Uncategorized

Can’t create table ‘a.#sql-688_c3′ (errno: 150)

February 15th, 2012 — 9:56am

TL;DR Check the engine of both involved tables, check the character set of both involved tables, check the data type of both columns, check that the referenced column is indexed.

Yesterday I was in a fight with MySQL. I eventually think that I won by executing “sudo killall mysqld“, after which my immediate issue was fixed, but other issues emerged :) . I had been confronted with the infamous error “ERROR 1005 (HY000): Can’t create table ‘database.#sql-688_c3′ (errno: 150)”, which makes no sense and doesn’t tell me anything I actually want to know.

Of course, everyone who has run into this problem knows that you can issue the query “show innodb status\G” to see the actual issue. Now, I’ve encountered two problems with this approach, the first being that I actively have to search for an error message. The second issue though was the one that really drove me crazy; “show innodb status\G” was lying to me. Here’s what it told me:

120214 15:50:57 Error in foreign key constraint of table database/#sql-688_c3:

FOREIGN KEY ( thecode )
REFERENCES mycodes ( thecode ):
Cannot find an index in the referenced table where the
referenced columns appear as the first columns, or column types
in the table and the referenced table do not match for constraint.
Note that the internal storage type of ENUM and SET changed in
tables created with >= InnoDB-4.1.12, and such columns in old tables
cannot be referenced by such columns in new tables.
See http://dev.mysql.com/doc/refman/5.1/en/innodb-foreign-key-constraints.html
for correct foreign key definition.

Now, the first thing I checked was that the datatype of the column and referenced column actually matched. They did. Maybe the referenced column didn’t have an index? It did. No issues there, so I’ve asked my colleague to come over and look for any issues. He didn’t find any. If I was going crazy, so was he.

What I’ve found, is that when MySQL says ERROR 1005 (HY000): Can’t create table ‘database.#sql-688_c3′ (errno: 150)”, it actually means that one of the following things is happening:

  • The engines of the tables don’t match up (e.g. one is InnoDB, the other MyISAM). Admittedly, “show innodb status\G” will present you with another message than the one above, namely “Cannot resolve table name close to”. Don’t worry, the table does exist and you’re not going crazy, it’s just that you accidently didn’t match up the table engines.
  • The second possible reason was the one I encountered; the character sets of the tables didn’t match. The first was “Latin1″, the other was “utf8″. Yes, MySQL will tell you there’s something wrong with the data type, and you don’t see the character set when you DESCRIBE the tables. Extremely annoying.
  • MySQL might be right too. The datatype might not match, or the referenced column is not indexed. That rarely happens though, I guess.

Anyway, I hope you find this post before you start pulling out your hair.

Comment » | Uncategorized

debian: error: Cannot find php_pdo_driver.h

February 9th, 2012 — 12:50pm

I recently got so fed up with Unity, I decided it was time for me to find something new. In the process, I’ve also decided it might be best to reinstall my machine with Debian instead of Ubuntu. I’ve decided a lot, lately. Since I use PDO with PostgreSQL, I tried to install the pdo_pgsql PECL package, but it failed with the message “Configure: Error: Cannot find php_pdo_driver.h“. Now, I was pretty sure that I had that file on my box, it was located in /usr/include/php5/ext/pdo/. Nevertheless, configure couldn’t find it. Turns out it was looking in a different directory; /usr/include/php/ext/pdo.

The simplest solution I could think of:

 ln -s /usr/include/php5 /usr/include/php

It worked like a charm :)  Of course, it’d be even better to compile PHP myself, but that’s for a different day.

7 comments » | Uncategorized

Getters and setters: evil or necessary evil?

February 13th, 2011 — 5:16pm

I’ve been reading a lot about getters and setters over the last few years, including Alan Holub’s infamous article “Getters and setters are evil“, and Martin Fowler’s article “GetterEradicator.” Although I do still feel like getters and setters are to be avoided most of the time, it’s hard to tell where to use them and where you shouldn’t.

I’ve been working on the website of PFZ.nl, the largest PHP community in the Netherlands, together with about eight other programmers I can’t help but respect. While writing the code for this website, I started to notice that each and every class in the system had accessors for most, if not all, protected fields. I’ve started a discussion with my fellow developers, and this is what I’ve argued.

First, I wrote an article on it, which was rather ill-received by some. This is understandable, as the presence of accessors is deeply rooted in OO PHP code, although this isn’t limited to one specific language. Besides, my point of view sounded rather puristic in my first article. Before I want to discuss why accessors should be handled with care, I’d like to go back half a century, to the introduction of OO.

Back in the day, some great minds thought up the concept of OO to make sure software would be easier to change, which means it’s easier to maintain. To accomplish that, they thought up the concept of an Object: a small, focused unit of code that is only ever responsible of one thing. One of the key concepts of OO was that objects should hide their implementation, to let their collaborators send them messages that they could handle for themselves. This concept became known under the term “Encapsulation”, a reinforcement of the guideline “Tell, don’t ask.”

Wikipedia states that the term encapsulation is used to refer to one of two notions: either to restrict access to an objects’ internals, or a language construct that facilitates the bundling of data, and methods operating on said data (which I like to call behaviour). Since the arrival of (decent) OO functionality in PHP, I have seen a lot of accessors which don’t adhere to the above concept: they actually willingly expose implementation, instead of hiding it.

This is not necessarily a bad thing, and sometimes, this even makes sense. The problem doesn’t actually lie with exposing the implementation and the data, but with the collaborator that *directly* uses that data. The number one example of misusing exposed data would be a bank account object: you can either opt for having setBalance( $balance ) and getBalance( ) methods, but common sense would dictate different methods: withdraw, deposit, and transfer. The number one reason for these methods is that the collaborator knows *nothing* about what a balance is, nor should it have to.

Translating this example to (PHP) code, the first option with accessors would probably result into the following class and collaborator.

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
<?php
class BankAccount {
	protected $balance;
	public function setBalance( $balance ) {
		$this->balance = $balance;
		return $this;
	}
 
	public function getBalance( ) {
		return $this->balance;
	}
}
 
class Transaction {
	public function transfer( $amount, BankAccount $from, BackAccount $to ) {
		if( ( $from->getBalance( ) - $amount ) < 0 ) {
			throw new InsuffientFunds( );
		}
		$to->setBalance( $to->getBalance( ) + $amount );
		$from->setBalance( $from->getBalance( ) - $amount );
		return true;
	}
}

Now, although this code is easy to write, there might just as well not be a BankAccount object, as it actually doesn’t *do* anything. It’s devoid of behaviour. This means that it’s a useless object which might just as well be nuked. Refactoring to the second option (withdraw, transfer, deposit), the resulting code might be something like this:

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
<?php
class BankAccount {
	protected $balance;
	public function tranfer( $amount, BankAccount $to ) {
		$this->withdraw( $amount );
		$to->deposit( $amount );
	}
 
	public function withdraw( $amount ) {
		if( ( $this->balance - $amount ) < 0 ) {
			throw new InsufficientFunds( );
		}
		$this->balance -= $amount;
		return;
	}
 
	public function deposit( $amount ) {
		$this->balance += $amount;
		return;
	}
}
 
class Transaction {
	public function transfer( $amount, BankAccount $to, BankAccount $from ) {
		return $from->transfer( $amount, $to );
	}
}

Now, this code (in my opinion) is just as easy to read and write, but there’s a very large benefits using the second approach: the ability to change. Imagine, for example, that there’s a “premium” bank account that allows to go in debt to, say, a thousand euros. You’ll have to change both examples in this case, but you’ll see that the second will accommodate this change much easier. Let’s refactor both examples, starting with the one that uses accessors:

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
<?php
class BankAccount {
    protected $balance;
    protected $overdraw = 0;
 
    public function __construct( $balance, $overdraw = 0 ) {
        $this->balance = $balance;
        $this->overdraw = $overdraw;
    }
 
    public function setBalance( $balance ) {
        $this->balance = $balance;
        return $this;
    }
 
    public function getBalance( ) {
        return $this->balance;
    }
 
    public function getOverdraw( ) {
        return $this->overdraw;
    }
}
 
class Transaction {
    public function transfer( $amount, BankAccount $from, BackAccount $to ) {
        if( ( $from->getBalance( ) + $from->getOverdraw( ) - $amount ) < 0 ) {
            throw new InsuffientFunds( );
        }
        $to->setBalance( $to->getBalance( ) + $amount );
        $from->setBalance( $from->getBalance( ) - $amount );
        return true;
    }
}

Although this works, it’s far from elegant. If you have more than one collaborator for the bank account object, and you usually do, you’ll have to duplicate that logic to all other collaborators. If requirements change, you’ll have to change the logic on each place you’re calculating the balance. There are more issues with the code, but I’ll get to that later. Now, to refactor the well encapsulated version of the code.

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
<?php
class BankAccount {
    protected $balance;
    protected $overdraw = 0;
 
    public function tranfer( $amount, BankAccount $to ) {
        $this->withdraw( $amount );
        $to->deposit( $amount );
    }
 
    public function withdraw( $amount ) {
        if( ( $this->balance + $this->overdraw - $amount ) < 0 ) {
            throw new InsufficientFunds( );
        }
        $this->balance -= $amount;
        return;
    }
 
    public function deposit( $amount ) {
        $this->balance += $amount;
        return;
    }
}
 
class PremiumBankAccount extends BankAccount {
    protected $overdraw = 1000;
}
 
class Transaction {
    public function transfer( $amount, BankAccount $to, BankAccount $from ) {
        return $from->transfer( $amount, $to );
    }
}

Alright, the introduction of the new class PremiumBankAccount could have been done with the setters and getters too, but still, the change had just one line. Better yet: the change only affected the BankAccount class itself, and the rest of the application is still blissfully unaware of any change, although the functionality has been radically changed. The collaborator doesn’t know the bank account even can overdraw, nor should it have to.

If you’re still not convinced the second example is better, I’ll play devils advocate and I’ll ask you to refactor both examples to incorporate functionality so that a bank account can have a currency, say EUR and USD, and you should be able to transfer an arbitrary amount of dollars to a bank account based on EUR. You’ll see how much your Transfer class will have to do, when you’re using only accessors.

Alright, I think I’ve made my point by now: the second example is much better, and indeed, it’s OO like OO was meant to be. Now, obviously, you wouldn’t do it like I did it in the first example, right? You’d *maybe* write the accessors, but you’d put the transfer logic into the bank account itself, right? Good for you, but most classes I see out there today actually lean toward the first example, and this yields my curiosity in finding out: why?

Just open an OO library written in PHP, and grep for “function set”, and you’ll be shocked. Again, the problem doesn’t lie with the accessor per se, but you should check the collaborators, and I can guarantee you that the collaborators are doing calculations and making decisions which should belong in the object itself. By exposing the data, you’re making this possible.

If you work with others you can simply expect people to change your objects’ behaviour instead of using the accessors you wrote, or you can provide well named methods that encapsulate the data, so your coworkers know how to use your class.

So, why do we use so much setters and getters if there is seemingly no need to do so? Well, first of all, I’d like to go back a decade, when I was still in school and getting lessons on programming in Java. Indeed, my books were full of getters and setters, so I just assumed this was the way things work. How could I have known better? The people that wrote the books are notably smarter than I am, so they must be right. Right? Well, not so much.

People starting to learn OO are reading books, tutorials and example code which are littered with accessors. It just makes good sense to copy that pattern onto your own code. If, like me, you were used to writing procedural code, you’ll even feel right at home. You still manipulate the variables, only now they’re in some sort of namespaced array called an object. Awesome. I hereby bid people that write introductory tutorials to stop using accessors “because they can”, and instead only write them “because they have to”.

So, “learning it the wrong way” is a big reason, but there’s another one, and that is layering. Layering your application is supposed to make your code more maintainable, more extendable, more reusable, and more of that. In PHP, there is not a single framework that doesn’t claim to “be MVC”, and that is another reason for the presence of accessors everywhere.

If you split up responsibilities into “business logic” (such as transferring an amount to another bank account), and the logic for displaying stuff (such as, when the accounts’ balance is negative, display the balance in red), you’re supposed to be able to change one layer without changing the other. Implementing the separation between those responsibilities will make it easier to display one object in multiple ways.

For example, say I want to display the bank accounts in HTML. I’ve got a few options, one of them being rendering the HTML inside the object itself. Once you start down that road though, your BankAccount class will grow to extreme proportions, as you might want to display the information in HTML, XML, JSON, etc., etc.

Another option is to leave the displaying of the bank account to a template. This template will fetch the accounts’ balance and if < 0, display the balance in red for HTML. Indeed, this is the most widely used technique and, in and on itself, not a bad one to start with. It does have a requirement though: each part of data that you want to display will have to be available to the View layer. As PHP doesn’t know “Friend” classes like C++, and there’s no ability to read protected variables from the same “package” like Java, you’ll have to make the access public. This means that you’ll have to write a public getter for each value you want to display!

On the other side of the object, there’s storage. Generally, objects from the model layer will have to be saved somehow, and that yields the exact same issue: how does the object that saves the values (say, a DataMapper) get the values from the target object? In the exact reverse, how does a DataMapper build the object without being able to set values? You could use the constructor for this, but that might mean you get a constructor with 10+ parameters, which is not the most clean solution ever.

All in all, I don’t think accessors are evil per se, but you should only ever use the accessors in cross-layer situations. Don’t use accessors to build functionality, but only because you need the value to display and/or save.

25 comments » | Object Oriented, programming, Theory, Uncategorized

Holiday to Italy 2010

August 18th, 2010 — 1:44pm

I’ve visited Italy, for the second time of my life. The first time I went there was a long, long time ago, so long even that I can’t remember it and my parents had to tell me about it. This time, I had the pleasure of joining my friends: Ramon, Roos, Robert and Nicolien. Our rented house was in Manerba del Garda.

More information (and pictures), will have to come later. I just wanted to test the flickr-gallery plugin I have installed recently, if I have to be honest. :)

Comment » | holiday, Italy 2010

Generate random password PostgreSQL

July 9th, 2010 — 2:41pm

EDIT: it seems I’ve made a mistake in the previous versions of the script. I was multiplying the double precision I got from calling random( ) with the length( ) of the seed, and casting that to an integer. Unfortunately, I’ve found out that random can return a value < 0.1, which means that ( 0.09 * 4 ) = 0, which means that the 0th character was substring( )‘ed and appended. Alas, that doesn’t work. By taking the smallest integer not lower than the value returned by using ceil( ), this problem is fixed.

Also, I’ve managed to make the whole procedure a little quicker by appending the numeric values after instead of in the loop, and that has certainly sped things up.The code has been updated.

While building our latest and greatest application, we needed to generate initial passwords for the users. This is not uncommon, and I’ve been generating passwords for quite some time using a PHP class called RandomString. However, in the last few months, I have been working with PostgreSQL more and more, and I started to write business logic into the database in the form of plpgsql stored procedures, instead of plain old PHP, as it turns out to make the application itself a lot smaller, leaner, cleaner and – most of all – more readable.

Adding a batch of users was easy: the usernames were derived from several other variables, so there was no need for PHP to get involved in creating the users and their passwords. So, I wanted to generate the passwords using a stored procedure and I don’t like doing the work myself, so I started to Google. Unfortunately, I couldn’t find even a snippet of code while searching the internet, and I’m not that well versed in plpgsql yet, so I decided to ask my geek-friends over at PFZ – PHP Community.

Vincent – also known as PgGuru – had a very nice solution which would allow you to create passwords based on a seed  and a length you could pass to the procedure, but I wanted passwords in the format that he suggested earlier: “BABABAB11“. So I started to hack away at his example, and came up with two stored procedures that you can use to generate random, readable passwords straight in the database, no interference of the client required. Without further ado:

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
--
-- Generates a random, human readable password with the format "BABABA00".
-- It will alternate between a consonant or a vowel, and appends two numbers
-- at the end of the password and then return it.
--
CREATE OR REPLACE FUNCTION generatePassword(
  _length INTEGER
) RETURNS VARCHAR AS $$
 
DECLARE
 _counter INTEGER;
 _password VARCHAR := '';
 _vowels VARCHAR := 'aeiou';
 _consonants VARCHAR := 'bcdfghjkmnpqrstvwxyz'; -- left out 'l', because it can appear as "I".
 _numbers VARCHAR := '23456789'; -- Left out 0 and 1 because they can appear as O and I.
 
BEGIN
    -- Create a loop for the length of the password (-2, as two numbers will be appended).
    FOR _counter IN 1..( _length - 2 ) LOOP
        _password = _password || CASE
           -- Add a vowel to the password for even values of _counter.
           WHEN ( _counter % 2 = 0 ) THEN SUBSTRING( _vowels, CEIL( RANDOM( ) * LENGTH( _vowels ) )::INT, 1 )
 
           -- Add a consonant to the password for odd values of _counter.
           ELSE SUBSTRING( _consonants, CEIL( RANDOM( ) * LENGTH( _consonants ) )::INT, 1 )
        END;
    END LOOP;
 
    -- Append two randomly selected numbers to the password.
    _password = _password || SUBSTRING( _numbers, CEIL( RANDOM( ) * LENGTH( _numbers ) )::INT, 1 );
    _password = _password || SUBSTRING( _numbers, CEIL( RANDOM( ) * LENGTH( _numbers ) )::INT, 1 );
 
    -- Finally, return the created password.
    RETURN _password;
END;
$$ LANGUAGE plpgsql;
 
--
-- Generates a random password out of the seed passed to it.
--
CREATE OR REPLACE FUNCTION generatePassword (
  _length INTEGER,
  _seed VARCHAR
) RETURNS VARCHAR AS $$
 
DECLARE
 _counter INTEGER;
 _password VARCHAR ::= '';
 
BEGIN
 
    FOR _counter IN 1.._length LOOP
       _password = _password || SUBSTRING( _seed, CEIL( RANDOM( ) * LENGTH( _seed ) )::INT, 1 );
    END LOOP;
 
    RETURN _password;
END;
$$ LANGUAGE 'plpgsql';
 
--
-- Example of usage:
--
SELECT generatePassword( 8 );
SELECT generatePassword( 8, 'abc'::text );

So, there you have it. I hope someone else can benefit from these stored procedures, actually finding them instead of void while doing a Google search ;)

Cheers,

Berry.

7 comments » | plpgsql, postgresql, programming, stored procedures

svn ignores svn:ignore?

June 7th, 2010 — 9:54pm

Well, it did. On one of my pet-projects called Sphoof, hosted over at Google Code, I had created directories for API documentation and log-output from the unit-tests, telling me if the unit tests were successful, the percentage of code coverage and violations of our coding standards. That’s great and all, but it doesn’t necessarily need to be in the repository. Nevertheless, I wanted those directories under the project’s main directory, to keep it all in the same place which makes it that much easier to find. Since they kept on popping up in svn stat, I decided to add the directories to the repository in a flash of humongous FAIL.

After committing all of the API docs and logs, which are bigger than the project itself, I figured I accidentally added them, but I actually wanted to ignore them instead. So, I emptied the directories and “svn propedit svn:ignore .” would have to do the trick. I added the directories I didn’t want to see and committed again. I didn’t work. Figuring it must’ve been my error, I tried again. And again. And again. Finally, I asked one of my co-developers to try it for me instead, see if this was actually a problem between my keyboard and chair. He ignored, committed, and found the repository filled with logs and docs. He tried again. And again. And again.

Finally, I figured out the problem: although subversion will happily tell you that the properties for ‘.’ have been changed, it only ignores files and directories that do not exist in the repository at the time you try ignore them. Yes, I did read the otherwise excellent documentation, but it doesn’t tell you that it can’t be done. It took me a few hours to find out. So: if you find subversion does not listen to the svn:ignore property: make sure that the files aren’t in the repository already. If they are, delete them from the repository, commit the change in which they are deleted and set the ignores as usual.

I do hope this might save someone some time.

2 comments » | subversion

Volume control for Ubuntu 10.04

May 7th, 2010 — 12:35pm

I updated to Ubuntu 10.04 this week, and now I’m listening to Nightwish, I suddenly felt the need to get the volume up. My mouse started on it’s way to the place the volume control-applet used to be, but it seemed to have disappeared. Luckily, this problem too is easy to fix: start the program “gnome-volume-control-applet” by pressing alt  + f2. If that works, you might want to go to “System” > “Preferences” > “Startup applications”, and see if volume control is there and checked. If it’s not there, you can add it, and if it’s there and it’s not checked… well, then check it.

Problem easily fixed. Nightwish: you just started to sound a lot louder. :)

2 comments » | ubuntu

Netbeans 6.8 didn't survive Ubuntu upgrade

May 4th, 2010 — 12:09pm

Well, actually, Netbeans did, sun-java6-bin didn’t. I could no longer start Netbeans after my upgrade from Ubuntu 9.10 to 10.04, because of the following error message. You can see that by trying to start Netbeans from terminal: Cannot find java. Please use the –jdkhome switch. It turns out that java went missing, must’ve missed it when the upgrade started. I’ve tried simply reinstalling sun-java6-bin, but that didn’t really work either: it appears that no longer exists. After a while, I found out I had to the following:

sudo add-apt-repository “deb http://archive.canonical.com/ lucid partner”
sudo apt-get update
sudo apt-get install sun-java6-jre sun-java6-plugin sun-java6-fonts

After that, Netbeans works like a charm, just like it did under Ubuntu 9.10. Hope this might help anyone.

Comment » | netbeans, ubuntu

Netbeans 6.8 on Ubuntu 9.10

April 7th, 2010 — 8:29pm

I’m a VIM kinda guy. I like love VIM for everything it is. I write e-mails in VIM, I write presentations and blogposts in VIM, I write todo-lists in VIM and I also write my software using VIM. VIM does have downsides in that respect though, and those downsides are well-known. For starters, VIM doesn’t have smart, context-aware auto-completion. I write a heck of a lot of classes and interfaces, and it’s not always easy to keep track of the names of classes and methods. I’ve always lived with that, as VIM has a lot of upsides as well: I can write and manipulate text in VIM faster than most people can manipulate text in any other editor I’ve seen. It’s also highly customizable, so if there’s anything VIM doesn’t do, I make it do that anyway.

Netbeans is a new kid in town of IDE’s suitable for PHP. In the past, I’ve used Eclipse for PHP development, but that always felt slow and too big for writing PHP. I’ve used the first beta of Netbeans for PHP, but that had issues with quotes, linefeeds and other stuff so I ditched it within half an hour. It seems that Netbeans got a lot better since that first beta, so I figured I should give it another try to see if it can fulfill my (absurdly high) demands when it comes to writing code. I had to install it first, obviously.

Installing Netbeans on Ubuntu really is easy enough, if you have an understanding of how Ubuntu works. For the people who don’t, I’ve kept a short log of how I’ve installed it, hopefully someone will benefit from this. There are a few different methods of installing Netbeans in Ubuntu, which all have there up- and downsides. The way of installing I chose has the downside of being slightly more complex, but you get the last version anyway.

The first, and probably easiest way of installing Netbeans on Ubuntu, is to download and install the Java JDK and Netbeans bundle. To be fair, I’ve never tried it and it seems easy enough, but I’m not sure if you’ll always have the latest version of Netbeans in the bundle. At this time, it seems it does indeed include the latest version.

The second easy way to install Netbeans, is using Ubuntu’s software distribution: simply typing “sudo apt-get install netbeans-ide” will install Netbeans, including all of it’s dependencies. Again, there is the downside that you may not have the most current version in the distribution channels.

The third way, slightly more complicated, ensures you have the latest version of Netbeans installed. Open a terminal and type “which java”. If the command returns a response, you have Java, so you can skip the following. If it doesn’t return anything, Java SDK is not installed on your system, so you have to install it. Luckily, that is easy enough: type “sudo apt-get install sun-java6-bin sun-java6-jdk”, and agree to the license. To prepare you: the download is 160Mb, but that shouldn’t be a problem in this day and age.

After installing Java, it’s time to download the Netbeans installer from the Netbeans download page. I write PHP mostly, so the PHP version seems to be the most decent option. Start the download and save it to a location of your choice. If you’re done downloading, go back to the terminal and cd into the directory you’ve just saved the installer to. Execute the following commands, and enjoy while Netbeans presents you with an installation wizard:

chmod +x netbeans* && ./netbeans-*

That’s it, you’re done. Netbeans should now have an icon on your desktop. Start the application, and start writing code. I’ll give Netbeans an honest chance for about a month and will give an update of it later. Obviously, I won’t abandon VIM for anything but writing code.

Comment » | netbeans, ubuntu

Back to top