It has been two years since I wrote about programming Hadoop in Netbeans using Karmasphere Studio. Meanwhile, apparently Netbeans is no longer supported by them, and they focused on the other IDE, Eclipse. I have relatively no problem in using Eclipse, thanks to some Android projects that I’m working on right now. In this post, I’ll show you another example of programming Hadoop in Eclipse by implementing distributed inverted index in MapReduce. So, let’s get started, shall we? Continue reading
In software development, version control system (VCS) hold an important role. Especially when the project is collaborated by many programmers. Besides to keep tracks of changes, version control could helps handle task distribution and later project integration from the programmers. Basically, there are two flavors of version control system: centralized and distributed. There are many comparison between these two flavors on the net, one of them explained it well with some illustrations. The key point between these two systems is there are local working copies of the project in distributed VCS, while in centralized VCS, every changes must be updated to the central repository. Continue reading
Not so long ago, I created a GUI for data storage using Java and of course JDBC. I followed a tutorial about how to insert database records to the database table. The tutorial said that before we’re inserting new record to the database, we should generate unique key as record identity. The generation process handled by Java code. The tutorial use
System.currentTimeMilis() function to create the key. So, the code will be look like this:
//set new id Number time = System.currentTimeMillis(); Integer id = (time.intValue()/10000);
The generated key then being inserted to the database.
As you may realized, database systems usually have their own key generation technique. For example
AUTO_INCREMENT attribute in MySQL. I followed the tutorial and sure it works. But, I tried database-generation key, and it works too. So, why we should bother generate our own keys?
The O’Reilly Java Author gave an explanation about that. They said:
However, using the supported key generation tools of your database of choice presents several problems:
- Every database engine handles key generation differently. Thus, it is difficult to build a truly portable JDBC application that uses proprietary key generation schemes.
- Until JDBC 3.0, a Java application had no clear way of finding out which keys were generated on an insert.
- Automated key generation wreaks havoc with EJBs.
I got the point that the application should be portable. Who knows that someday we’ll migrating from one database systems to another? So the database generation key will be hard to control.
Another detailed answer came from Scott Selikoff. He wrote a complete article about database key generation and gave an example:
Now, let’s say a user is in the process of creating a new record in your system. For each user record, you also have a set of postal addresses. For example, Bob may be purchasing items on NewEgg and have a home address and a work address. Furthermore, Bob enters his two addresses at the time he creates his account, so the application server receives the information to create all 3 records at once. In such a situation, you would normally have 3 records: 1 user record for Bob and 2 address records. You could add the address info in the user table, although then you have to restrict the number of addresses Bob can have and/or have a user table with a lot of extra columns.
Inserting Bob into the user table is straight forward enough, but there is a problem when you go to insert users into the address table, namely that you need Bob’s newly generated User Id in order to insert any records into the address table. After all, you can’t insert addresses without being connected to a specific user, lest chaos ensue in your data management system.
The problems will arise in complex database relationship. As we don’t know the generated key, we couldn’t set the foreign key of corresponding tables. I didn’t realize this because the GUI I made was using a simple database design. Maybe with no table relation at all.
So, I got my question answered. Do you have another answer for my question? Feel free to share.
Long time ago, I got some challenge to create some MDI (Multiple Document Interface) application. Why I called it challenge? Because I must create it with Java and I didn’t have experience on using Swing. But thanks to Netbeans, it makes Swing gui development far easier.
Netbeans provided some tools for gui building. You just need to drag-and-drop, edit some properties, and adding some event-handling. Voila, your desktop application will be up and running. But there is a but. In MDI application, we’ll need a scrollable desktop pane. For your information, desktop pane is a home for all of child windows. If I dragged the child window outside the desktop pane, the desktop pane should automatically give scroll to facilitate it. Java have library to implement dekstop pane. It’s called
JDesktopPane. But the usual
JDesktopPane didn’t have support for auto-scrolling.
Gerald Nunn in Java World site write a way to conquer this deficiencies. He create some libraries that we can use to enhance the usual
JDesktopPane. He called the object
MDIDesktopPane. All we have to do are just download it, link it to our codes, and use it.
In Netbeans, these were I did:
- I extracted the sample code (library) into the same package with my gui package.
- Using gui builder tools provided by Netbeans, I created
JFrameand inside it, I added
- Using gui builder, Netbeans will generate function called
initComponents. This function lists all of the variable declarations and gui setups for components added before.
- In the
initComponentsfunction will be called. In this area, we will added the
- Before that, I created
MDIDesktopPanedeclaration. It will not far from this:
private MDIDesktopPane desktop = new MDIDesktopPane(); private JScrollPane scrollPane = new JScrollPane();
JScrollPanebecause it will support the scrolling functions.
- Then, after the
initComponentsfunction, I added the
JScrollPaneto the frame.
jMenuBar1.add(new WindowMenu(desktop)); scrollPane.getViewport().add(desktop); getContentPane().setLayout(new BorderLayout()); getContentPane().add(scrollPane,BorderLayout.CENTER);
jMenuBar1was the variable name of my
JMenuBar. It means I added
MDIDesktopto the menu bar.
WindowMenuwas a class to control the display of all of the child menu like cascaded or tiled windows.
- It’s done. It’s simple, right.
WindowMenu class, I finally conquer the scrollable desktop pane. Thanks to Gerald Nunn for his great class.
Did you know the opposite of lightweight? Maybe almost 99% of you said that the opposite was heavyweight. It’s easy. Just take the adjective phrase, which is light, and change it to its opposite, which is heavy. It applied on language. But, did it apply to all language?
Maybe now, 50% of you said that it applied to all language. How about I said that if a thing wasn’t lightweight, so it must be a heavyweight? If you said that I was correct, maybe you forgot about one thing. In mathematics, there was a subject called mathematical logic.
Rings a bell? Remember about the if-then theorem? If “ you do it” then “something happens”. It means that “you do it” was just one of the causes to make “something happens”. But, if something happens, it doesn’t mean that always “you do it”. If you want a clause that said that “something happens” just because “you do it”, use if-and-only-if instead.
Well, why I bother telling a story about if-then and if-only-if? Yeah, I want to tell you about my experience when I was coding Java. Some of you maybe know about swing components in Java. They are divided into two categories, the heavyweight and the lightweight components. I was playing with JInternalFrame instance back then. I wanted to make a popup window when I clicked a button in this JInternalFrame instance. But I also wanted that if the window popped, the JInternalFrame was not enabled, means user couldn’t do anything in JInternalFrame.
Before we continued, I wanted to share that according to JDK API docs:
Disabling a lightweight component does not prevent it from receiving MouseEvents.
So then I checked if the JInternalFrame was a lightweight or not. To do this, I used a method called isLightweight. It returned false. So I think that it was a heavyweight component. Then I disabled this internal frame when the window popped up. But you know what, it didn’t work. The internal frame still could receive MouseEvents. When I checked again in JDK API docs about JInternalFrame, it said that it was a lightweight component. So what happened here?
Well, actually it’s totally my fault. I used isLightweight method when the internal frame still not visible. When I checked about this method, the JDK said:
This method will always return
falseif this component is not displayable because it is impossible to determine the weight of an undisplayable component.
So, the method returned false because the component wasn’t visible and not because it was a heavyweight component. Here, I got the if-then message. It reminded me about an advertisement in television not so long ago. It said: “smart people drink this tonic“*. I guess you could use if-then to conclude its meaning. Well, have a nice day..
* I censored the trademark. I guess you already know about the advertisement already.