NetBeans Refactoring – Part 1

This week I decided to give you, my dear readers, a little rest from my blabbering and go technical a bit. I am going to talk about a very powerful and a personal favorite NetBeans feature: Refactoring.

If you do not know NetBeans, it is a free, cross-platform, open-source Integrated Development Environment (IDE) for software developers and a product of Sun Microsystems. An IDE is a software application that provides extensive facilities to programmers for software development, such as a source code editor, a compiler, an interpreter, build automation tools, and a debugger. For more information about NetBeans’ features, visit the official website.

Refactoring is about changing your source code easily. Imagine moving a class between packages and having to edit the package statements manually at the top of each file, or wanting delete a variable in the code and not knowing if it is referenced somewhere else in your application. Performing these types of operations manually can be time consuming and prone to error. However, with the advanced refactoring capability available in NetBeans, you can do such changes very easily. NetBeans provides many refactoring options on its Refactor menu. I am going illustrate half of them today and the other half in a following post.

EDIT: Part 2 is now available. Click here to read it.

For this post I have created two classes, ImportingClass and MoveClass. View them here and here.

There are some images that are not very clear because of page size limitations. You can click on any image to see it in full size.


Rename refactoring allows you to change not only the name of the class but also any constructors, internal usages, and references to the renamed class by other classes. You can also rename the package, which will automatically rename all instances of the package name in your code, including comments. Here, I am going to change the name of the variable value to AddedValue in class ImportingClass:

Automatically, the variable name is also changed in class MoveClass:


Moving a class from one package to another may seem like an easy task; you just have to copy and paste the contents of the source file into the new directory and then edit the package statement at the top of the file then you are good to go. However, if other classes import or reference that class, then the developer must also search through and modify those files. Here is how you can move MoveClass from the refactoringpackage2 package to refactoringpackage1:


Copy refactoring allows you to copy the contents of a class to another package, automatically changing the package statement at the top of the source file.

Safe Delete:

Sometimes when you are reviewing a previously written code, you decide to remove a class member variable that you think is not used, only to find out that it does indeed appear in your code, and then your class does not compile. With Safe Delete refactoring, you can identify each usage of a class, method, or field in code before deleting it. I am going to illustrate it by trying to delete the AddedValue variable from class ImportingClass:

However, the variable was referenced in class MoveClass, so deleting it would cause an error. T=NetBeans alerts you to that, and can even show you where the member you want to delete is referenced if you clicked the “Show Usages…” button:

Change Method Parameters:

Change Method Parameters allows you to safely change everything in a method header- access modifier and arguments- and notifies you if this change is going to affect your source file. Here, I am going to try to delete the parameter x of the display method of class ImportingClass:

Parameter x is used within the method body, and so a warning is displayed:

For the following examples, I created a class called Truck, which inherits fr0m a class called Vehicle. View here.

Pull Up:

When working with classes and superclasses, Pull Up refactoring is very useful. It allows you to move class members and methods from a subclass up into the superclass.

Push Down:

Push Down is the opposite of Pull Up refactoring. It pushes a superclass member down into a subclass.

And that’s it for this time, note that those are only half of the capabilities of NetBeans refactoring. I am going to go through the other half in a following post soon. If you have any question or comment, do not hesitate to contact me.

EDIT: Part 2 is now available. Click here to read it.



Changing Track. The Correct Decision? Or…

Allow me to be honest; I have always wanted one path for my life to take. That is “The High Life”, with all that comes along with it; first class air tickets, 5 star hotel suites in every city I visit, a luxury car, and so forth. But let’s be realistic, how can someone like me, a struggling computer science student at a regional Egyptian university- not just any regional, the most infamous of them all- whose family is NOT into major drug trafficking- or let’s just say rich, so that I don’t offend the big companies chairpersons who might be reading this to get a background check on me- achieve the so called “high life” without going into the illegal business myself?

The main reason why I decided to take computer science 4 years ago was my firm belief that working in the information technology industry would be the quickest way to get rich. Everyone back then was saying that computers are the future. Everyone was talking about the smart government, the smart village, and everything that can possibly have the word smart attached to it. Everyone who remotely knew me congratulated me on my wise decision to join the all mighty Faculty of Computers and Information.

I do not know when exactly, but at some point in my academic years, I made this… roadmap for my life. It begins right after my graduation with me enrolling at one of the major private sector software corporations in Egypt and then climbing up the career ladder until I retire while I am on top of the world, yet young and healthy enough to enjoy my hard earned money. After all, computers are the future, right? But perhaps I was overly ambitious.

A few weeks ago I was talking about this to a friend of mine who is NOT a computer science major, but rather a business major. This helps sometimes, we geeks tend to isolate ourselves in this crazy, unrealistic world of hopes and expectations, so getting a wake up call every once in a while is healthy. Unsurprisingly, he disagreed with me, strongly. He believed that this “roadmap” of mine will get me nowhere and the only solution to be on top of the world while you still have a breath left inside you is entrepreneurship. Of course, trying to be an entrepreneur nowadays in the IT industry prior to having years of experience in some big company is nothing but a complete waste of time. It is not the year 1999 anymore. Thus, the solution would be to just, put everything you spent years in learning aside and start some IT-unrelated enterprise, take a risk, be unique, and work hard enough and you will get what you want in a few years time. Coming to think about it, he has a point.

I bet you are thinking that I am crazy at the moment, but bear with me for a minute here. I am not going to talk about the economic stature in Egypt, but my friends, look around you, the most successful and influential- not to mention the richest- people we hear about in the news everyday are entrepreneurs, and I doubt that any of them is doing business in a field related to what they studied at university, that is if they had been into university at all.

So we are set, want to become one of the movers and shakers? Get through your college years quickly, ditch everything you learned there, look for a unique business idea, and you are good to go. But wait a second; everyone knows that new enterprises take four or five years to pay off, assume that you decided to take the risk and start an IT-unrelated business, and after some years you find that you are not doing as good as you expected or even on the verge of bankruptcy and there is no choice other than calling it quits. It happens more often than you think, according to the American Chronicle, 80% of new businesses fail, and that is in America! Eventually, you will be left with no job, no money, and an experience that is better left to be forgotten. What is even worse is that it will be extremely difficult, if not impossible, to find a job in a respectable software company. Which company do you think will prefer to hire you- an old person with nothing but failure- in an entry-level position over a fresh graduate with a fresh mind and new ideas? I say none.

Sorry for the long post, but this is something that I really wanted to share with you. Also, I would really appreciate it if you give me your opinions on this subject. Your comments are always welcomed.

Disclaimer: I do not by any means suggest that the rich people in Egypt are only so for working in illegal businesses. This is just my way of being sarcastic after the crazy rumors we hear everyday in the news about the Egyptian tycoons.

I Am Not Unintelligent Sir, I Just Have A Life

After a long summer, we finally returned to school last Saturday. I was confident that it will be a great source of inspiration for my humble blog, and I wasn’t wrong. On my very second class, “Knowledge-Based Systems”, I was faced with something that I knew I should address here- despite having previously prepared a post for this week, which is now put on the shelf for some other time.

While explaining some principles of Artificial Intelligence, our professor wandered a little off topic- which happens often- to talk about human intelligence, more specifically our intelligence as Computer Science students. He wondered why some of us achieve below average grades while clearly we cannot be unintelligent, as we got high grades at high school to get into this faculty. He concluded that those- the ones with low grades- either do not work hard enough, which makes them unintelligent for neglecting their study, or are indeed, unintelligent (not smart enough)- I believe the word he used was “stupid”.

Now, with all due respect to my dear professor, I have to say that I completely disagree with his point of view. First off, and everyone knows that, in Egypt, achieving a high grade at high school does not have any significance on whether or not you are intelligent or smart. I will not go through the reasons for that as I would really rather not get into a debate about the status of the educational system in Egypt. Just thought I should give a quick reminder.

Second, let’s take a look at ourselves for a moment; we start going to university at the age of 18 or 19. I am going to go out on a limb here and say, after 18 or 19 years of submissions to the wills of our schools’ teachers, parents, and societies’ customs and traditions that are most of the times meaningless and absurd, we take off to a brand new world where all the previous restrictions seem to dissolve by the power of the word “university”; your professors and instructors do not care whether you listen to them or not, your parents suddenly decide that you are old enough to handle yourself, and the society… well, the society remains the same, except the rules are more lenient this time and can be easily bent, if not broken, with little or no punishment. In other words, when you are in Egypt, university years are the best years of your life.

With that being said, would you rather spend the best years of your life stuck to a desk or staring into a computer monitor the same way you did in the previous 14 or 15 years of your life instead of going out and exploring this new world called university life? Some people make that decision in order to become college professors in the future. I have to admit it, it is not a bad thing at all, being a professor has a certain “prestige” to it, and the pay is not bad either. However, to be a professor, you have to go through years of humiliation by the real professors, who will make your life a living hell until you get that PhD, not to mention that upon graduation, you will have to see your previous colleagues working in the private sector with monthly salaries that exceed what you make a year as a college instructor. I obviously know what I am talking about as my father is a professor and my sister is an assistant professor at the same university I go to. So, after all, is the prospect of being a professor, with all its bitter and sweet, worth wasting the best years of your life? Some would still say yes, I say no.

For three years now, I have been achieving slightly above average grades at school, and it is NOT because I am unintelligent, it is because I purposely do not work hard enough. My parents have always complained that I am “too smart” to get such low grades. Maybe I am, but I am also too smart not to waste the best years of my life and regret it later. I am definitely not trying to encourage you, my fellow students, to simply forget about studies and spend your time wandering about. I am asking you to work hard and play hard. I am asking you to try and find a balance between your work life and your equally important social life. It may seem difficult and sometimes impossible, but you have to try your best, so that you do not wake up someday in the future finding yourself old and unsuccessful, or even worse, unhappy.

Computer Science Is One For The Rich

Surprised, aren’t you? Before I start, I want to make something clear, I am not one of the typical rich; I do not spend my summers in the sun or have a multi-million something of inheritance. I am just one of the “averages”, whatever that is. However, this “revelation”, if I may put it that way, occurred to me a while ago.

Two months ago, I decided to attend the Egyptian Engineering Day (EED), an annual event hosted by IEEE Gold Egypt, an affiliate with the famous IEEE organization. Usually, I never attend any events or conferences held by Egyptian organizations; most of the times sessions are nothing but too much gibberish that ends up with you losing all interest and ultimately fall asleep or sneak out of the hall to get your fourth cup of coffee of the day. This time though, I willingly broke my rule because I learned that besides the typical sessions, EED is an expo for graduation projects related to engineering from all universities across Egypt, including software engineering. Also, about five or six student groups from our faculty were among the participants, so I thought that some support as well as some inspiration would not hurt.

As our faculty is small and does not produce many projects- about 20 a year- I was familiar with the demonstrated projects. After wandering about the projects expo, focusing on software-engineering related projects, I was surprised to see that almost all the projects demonstrated by universities located in Cairo, specially universities such as AUC (American University in Cairo) and GUC (German University in Cairo), massively outclassed our university projects both technically and in size, even their ideas were exceptionally superior. I was confident that this was not because they received better education. The Faculty of Computers and Information at Menoufia University is known to be the best and most difficult computer science educational organization in Egypt, so why our projects did not live up to those of Cairo universities?

The only reason, ladies and gentlemen, is, as always it is with almost everything in our life, money. Before you start objecting, consider these two models; both are computer science seniors, both have basically learned the same things, however, person A is living the life of luxury in the community of the elites in Egypt, with rich parents who make all his/her wishes come true and absolutely nothing to worry about- other than probably worrying that daddy may not approve of renewing the car he bought for him/her last year as it became “old” this year- while person B lives basically in the slums, with his father working more than 12 hours a day so his family can just get by. In those two, who would be able come up with an “exceptionally superior” project idea that raises eyebrows and be able to follow it through? The answer my friends, is person A; the rich, who has all his/her mental capacities focused on one thing and one thing only:  studies, not to mention the ability to become an ingenious, creative producer.  All that because life is so easy that there is simply nothing to worry about.

I am not degrading the poor nor do I have a grudge against the rich, and I am definitely not trying to send a message to my colleagues to boycott EED. I myself would do my best to participate in it next year. I am merely sharing a piece of my mind. I could be wrong, but until someone proves me wrong, I am convinced that, at least in Egypt, our field of computer science has been, and will always be, dominated by the rich.