The Power of Eclipse

I am a Vim guy. I use it every day. I spend time learning things I can do with it. I’ve gotten good with it over the years. I’ve read books, I’ve followed blogs and videos, I script it to my liking using VimScript, and I play VimGolf. I mostly use Vim for smaller scripts and quick proof-of-concept programming, love it to bits, and learn new things all the time.

Yet I always believed there’s something definitely good about all these IDEs out there – there have to be tons of language-specific features that probably a text editor cannot cover.

Enter my new job. I am supposed to be using Java quite a bit now, so I decided to read through the Eclipse Pocket Guide, apart from some other books on JUnit and Java (irrelevant to this post).

Eclipse is fun! I’ve already learned about tons of features I didn’t even know existed! Here’s a quick summary of what I especially like:

[1] Your entire codebase is hyperlinked, and if you hover your mouse over your code fragments with the Ctrl or Cmd key pressed , those hyperlinks activate and navigating your codebases (including all libraries) is just one mouse click away

[2] Java scrapbook pages [likely a predecessor to Scala IDE Worksheets] – Open using File -> New -> Other -> Java -> Java Run/Debug -> Scrapbook page, type in an expression, select the text of the expression and hit Cmd+Shift+D or Ctrl+Shift+D, and voila – it is evaluated for you. Not exactly a REPL, but close

[3] Easy JUnit integration

[4] A solid debugger

[5] Several options in terms of perspectives and views. Several views available for different needs. Might even save personalized perspectives for future use

[6] Great refactoring tools

[7] Easy running shortcuts – Cmd+Option+X+J for Java, Cmd+Option+X+T for a JUnit test case, etc

I am sure there’s a lot more stuff – I’m having fun learning all that 🙂

Pass by value or reference in Java

Something to keep in mind for programmers coming from a C/ C++ background who ‘grow up’ reading and learning about pass by value/ pass by reference of variables between functions – what happens in Java is a bit different from either of these paradigms. Consider what happens when the main method is called in the following Java code:

Java pass by value or reference

Java pass by value or reference

Can you guess what the output is?

The output is an array of 1’s, not an array of 0’s or 2’s. If the pass were by reference, then any changes made in the function test would be reflected in the main – meaning an array of 2’s would be printed. But this is not what happens. If the pass were by value, then an array of 0’s would be printed, because no matter what you do in test, the array will have a local value there and would not be reflected in the main, which will in turn retain the value the array was initialized with. So what is going on here? Why do we get an array of 1’s?

In Java, there are a handful of things to keep in mind:

  1. You can only pass by value
  2. Arrays are objects
  3. No objects are ever passed
  4. References to objects are passed by value
  5. References are pointers under the hood – Java does have pointers after all
  6. Objects can only be manipulated by references

Point number 4 is the most important one. The value of the reference to the array is passed to test – which means if you change the value of the array pointed to by the original reference within the called function, the change will reflect in the calling function. But you can’t make the reference point to something else in the called function, because you only have the value of the reference in the called function, not the reference itself.

For primitive types, however, i.e. if we were to talk about an int, for example, the value in the called function will be a copy of the original, and any changes made in the called function to that primitive type value will be local to the called function, and will not be seen in the calling function at all. This is why some people call Java impurely object oriented, because it allows the concept of certain things, i.e. primitive types, which are not objects, as opposed to purely object oriented programming languages like Python and Ruby where everything is an object.


Sudoku solver using recursive backtracking

Inspired by a video lecture from Stanford University about recursive backtracking and how it can be useful, I sat up all night to write my own recursive backtracker to solve Sudoku’s. You can see it here. The video lecture presents a pseudocode in C++, and there is little to no emphasis on the code itself. While writing the code in Java, I ended up having to make a lot of design decisions, and when it eventually ‘clicked’, I had an ‘aha’ moment. So you can try to download the code, follow the instructions, make it solve a Sudoku of any level of difficulty, and try to break it. Just a little caveat – if you give it an evil or diabolical Sudoku, you will have to increase the stack size of your JVM [up to 50m].

Have fun!

Discovery of my life:: Unicode-variable in Java

Hallo an alle,

ich weiß nämlich nicht ob ihr schon eine Ahnung davon habt, aber ich hab ganz zufällig was Atemberaubendes rausgefunden, betreffend Java!

Also, wenn ihr schon davon Bescheid gewusst habt, ist meine Begeisterung wahrscheinlich ein wenig übertrieben.

Aber in Linux darf man also mit der folgenden Kombination Unicode reintippen: Shift + Ctrl (Str) + u + Unicode


Shift + Ctrl + u + 0611b = 
Shift + Ctrl + u + 03b1 =
Shift + Ctrl + u + 03b2 =
Shift + Ctrl + u + 03b3 = γ
Shift + Ctrl + u + 03b4 = δ


Also ich glaub schon, dass ich künftig mehr Java benützen werde, und ich denke so ein Programm wo die Namen so ausschaun wie oben wäre ein echt cooles Programm 😉 Hab auf Komodo Edit und Terminal ausprobiert und es funktionert prima!