Feb 24 2008

Introduction to Classes and Objects

I often get asked to explain the difference between a Java class and an object. A common way to describe a Java class is to think of it as a blueprint, cookie cutter, or factory used to create objects with. A class defines the implementation details, the fields and methods to store the state and execute the behavior of objects. In contrast, an object is an instance of a class. There can be one or many object instances for a given class but there is only one class for a given type. A common example of object state is that when you have an ArrayList, the list has a size. The ArrayList also has a certain behavior, to increase by one element and update the list size, when you invoke the add method. The size and contents are the state of an ArrayList, and adding and removing elements is its behavior.

In addition to declaring and implementing the fields and methods, state and behavior, for a object, a class can also define methods that don’t logically belong to a single object instance but that belong to the class type itself. Methods that belong to the class are marked as static. A common example of static methods are those in the Math class. You can’t create a object instance of the Math class, the default constructor is private. Since you can’t instantiate an object, all the methods it declares are invoked at the class level. To invoke the absolute static method made available in the Math class you do so by the following example.

[source:java]
int abs = Math.abs(-10);
[/source]

Here is how you would access the static PI field in the Math class.

[source:java]
System.out.println(“PI: “+Math.PI);
[/source]

Technorati Tags: , , , , , ,


Feb 24 2008

Class Loading Error

The Java language specification dictates that static fields and blocks are initialized the first time a class is loaded, from top to bottom. So my coworker was utterly dismayed when a static hash map in a certain class was getting a new object instance each time he requested an instance of said class. At first I was taken back by the problem as he described it, I thought maybe the object was serialized or marshaled, maybe it was programmer’s error and he had set a new map to the static field in some other setter method, then I remembered that this piece of code uses a new URLClassLoader instance each time it tries to load this particular class. This new class loader was used because we load this class dynamically at runtime as a external plugin. To fix this bug we just keep and used the same class loader instance each time we loaded this plugin class.

Class loaders are fun but this is one example of how if used incorrectly can lead to interesting behavior. These are the type of bugs that reminds me of those Java Puzzlers.

Technorati Tags: , , , , , ,


Feb 24 2008

Software Piracy

On a recent Java Posse episode, while talking about a price increase for IntelleJ IDEA, Joe Nuxoll of the Java Posse went on a bit of a rant about software piracy. Joe said, “Being a software engineer that has made my living selling software I don’t steal it, don’t copy it, I don’t even do that for music or movies or anything. I totally pay for everything, happily.” On the Posse forums, a fellow programmer said that for programmers to steal software is essentially like stealing from themselves.

Even though we could all agree with the sentiment, the absolutism and preachy righteousness tone of Joe’s comments made me think about his premise, that as software developers, we should never download software we are not ‘entitled’ too.

Let me first be clear, I don’t pirate. I pay for software but not because I write code. I pay for the convenience, quality, and utility that the software provides me, but perhaps most importantly because I can afford it and use it professionally. I don’t pay because I feel forced to pay because I also write software applications. I don’t feel that if my software is pirated I won’t get paid. As a developer, it is not like we get royalties on our work, so what do I care that 5% of my software is pirated, those that do pay for it make up the perceived loss.

Like all of you, I know a lot of fellow programmers that do torrent software, but the funny thing is that they really don’t use the software professional. In a way, the programmers that I know to be torrent, download, and crack software do so to try it out for longer than the trail versions allow. These software pirates fall into one of the following categories, they are just software pack rats that download and install every new shiny piece of software and use only once in a blue moon, or they are students of sorts and are trying to learn or experiment with new technology.

To good thing is that for whatever software you are interested their is a free open source equivalent. The open source part of the equation usually doesn’t much matter for end users, but the free part does. Software companies are beginning to understand that this perceived loss in revenue to piracy is negligible, that is why you are seeing a lot of free ‘express’ versions of software packages like Visual Studio, Oracle. Software companies, instead of taking RIAA-like stance of suing college students and the occasional user, are providing the people a legit option to using a free, express, limited version of the same software package and offer professional editions for those that need and use it on a daily basis. Companies like Oracle know that the greatest loss does not come from pirated versions of their software but from the loss market share to Open Source solutions.

Software companies should listen to their customers, even those that use their software a few times, instead of their lawyers, that most likely never have used their software.

Technorati Tags: , , , , ,


Feb 20 2008

andLinux For Windows

Before virtualization, if you wanted to to simulate a Linux environment on a Windows desktop you would use Cygwin or MKS. I’ve been using Cygwin for a long time now but recently I been tinkering with different Linux images (OpenSUSE, Ubuntu) with VMWare. Now there is a third option, in addition to emulation and virtualization you can run Linux natively in Windows with andLinux.

andLinux is a Ubuntu distribution running as a native Windows application. andLinux uses coLinux which is a port of the Linux kernel to Windows. Basically they cross-platformed Linux. andLinux is still in the beta and the installation feels a bit rough around the edges. But once installed you can run KDE applications such as Konsole, KWord, KPresenter, and Konqueror amongst others.

andLinux

Even though andLinux is in beta and I have not figured out completely how to access Windows’ disk drive and other resources, it is download worthy.

It used to be that to cross platform a software application you spend time porting it, then with virtual machines you write once and run anywhere the VM is running, but now with andLinux the whole Linux Operating System was crossed platformed to Windows.

A similar movement is also happening where Windows application such as Photoshop or Office are made to run as native applications in Linux. The Wine project allows you to run Word, Photoshop and other of your favorite Windows application in Linux. Wine is an implementation of the Windows API on top of X, OpenGL, and Unix.

Technorati Tags: , , , , ,


Feb 15 2008

Eclipse Plugin for Perforce

At work, we use Perforce for our version control system and Eclipse as our default IDE. If you search around you will find two Eclipse plugins for Perforce, P4clipse and P4WSAD. The development of P4clipse seems to have ceased at version 0.6.2 and I have not be able to get that version to work with Eclipse 3.3.1 or later.

P4WSAD works with current version of Eclipse but it is currently in beta. You can easily follow along the instructions to install P4WSAD, basically just add a new report site under the software updates. What wasn’t clear was how to configure the Perforce plugin.

After you install P4WSAD click Window | Open Perspective | Other from the main menu. Select the Perforce perspective and click ok. Write click on the P4 Depots view to create a New Server. In the server configuration you will need to enter the Port, meaning the URL with port number, for the Perfoce server. It is a bit confusing but the port field means the URL, inclucing the port number. You will also need to enter your Perforce username and click spec for your workspace/machine.

Once you configure you depot, you will need to drill down to where you code is stored under the depot, select the source folder, right click, and select Import as Project.

Technorati Tags: , , , , ,


Feb 13 2008

JavaOne 2008 Sessions

I was reading over the descriptions for the currently scheduled sessions for JavaOne 2008. Here is a short list of the sessions that seem interesting to me in no particular order.

  • BOF-5110: Extending Groovys Swing User Interface in Builder to Build Richer Applications
  • BOF-5998: Meet the Java Posse
  • BOF-6229: Cutting-Edge Productivity with RIFE and Web Continuations
  • PAN-5435: The Script Bowl: A Rapid-Fire Comparison of Scripting Languages
  • TS-4806: JRuby on Rails: Web Development Evolved
  • TS-4868: From Java Technology to Ruby…and Back
  • TS-4895: The NetBeans IDE Compared to the Eclipse Rich Client Platform
  • TS-4982: Extending Swing: Creating Your Own Components
  • TS-4986: JavaScript Programming Language: The Language Everybody Loves to Hate
  • TS-5152: Overview of the JavaFX Script Programming Language
  • TS-5165: Programming with Functional Objects in Scala
  • TS-5416: JRuby: Why, What, How…Do it Now
  • TS-5572: Groovy, the Red Pill: Metaprogramming-How to Blow the Mind of Developers on the Java Platform
  • TS-5579: Closures Cookbook
  • TS-5764: Grails in Depth
  • TS-5793: Groovy and Grails: Changing the Landscape of Java Platform, Enterprise Edition (Java EE Platform) Patterns
  • TS-6096: Nimbus: The New Face of Swing
  • TS-6169: Spring Framework 2.5: New and Notable
  • TS-6457: Choosing Your Java Technology-Based Web Framework: A Comparison
  • TS-6490: JRuby on Rails Deployment: What They Didn’t Tell You
  • TS-6609: The JavaFX Script Programming Language for Swing Developers
  • TS-6611: Filthy-Rich Clients: Filthier, Richer, Clientier
  • TS-6656: Extreme Graphical User Interface Makeover: Rock Stars
  • TS-6929: Creating a Compelling User Experience

I have gone to JavaOne four out of the last five years and have compiled pretty complete conference notes for JavaOne 2007 and JavaOne 2006.

Technorati Tags: , , , , , , , , , , ,