2013年3月30日土曜日

Exactly two months with Java

So, it has been exactly two months since I became a professional Java developer. (I have about 10 years experience in .NET and C#)

Actually, my work involves dealing with some .NET applications so I am not 100% pure Java developer, but still the team I am part of is nearly 100% Java developers.

I like to share my experiences so far.

Java language
Of course, two months is not long enough for me to see all of the major aspects of any language, but being similar to C# in terms of syntax as well as how it runs in a managed memory environment (virtual machine), my knowledge in areas such as .NET Reflection, IDisposable, generational garbage collector, design patterns, exception handling, all help.

Java syntax
I won't cover the syntax war such as where to put the curly braces. I just follow team's convention so it doesn't bother me, but it does take some getting used to.

Exceptions
This is annoying. Java is more strict about exception potentials. If a method has a potential to throw an exception, you either have to handle it or declare it as part of the method signature. I prefer C# on this where it does't require you to declare it in the signature. Seems this is too much work.

Extends and Implements
In Java, if you implements an interface, you have to say implement and if you extend a class, you have to say extends. Makes sense. However, I liked C#'s simple syntax of ':', but this is something you can get used to quickly.

LINQ
I miss it! Java has nothing like that.

Iterators
In Java, you use "for" with a special syntax that involves a semi-colon. In C#, you use "foreach". I like kind of like Java syntax too.

Events
I miss it in C#. There are no intrinsic notion called Event in Java that supports publisher-subscriber design pattern. As you know, in C# you can declare an event with EventHandler and have clients do += to subscribe to it. Very simple and neat. Java doesn't have that, and you pretty much have to pass a callback interface and have the event source object to "call" the handler. (I don't know if Java has delegate/functor.. does it? If so, you could pass delegate - still new on this)

Eclipse
OK, where do I start with Eclipse... I have so many things to say about this IDE.

Visual Studio vs Eclipse?
I would have to say that Visual Studio is better in the following aspects:

  • Visual Studio is so much faster to load. Period. Even Eclipse-classic, which is the bare-minimum feature set to do vanilla Java development can sometimes spend minutes to load.
  • Visual Studio provides nice feature packaging. In this regard, Visual Studio is like Apple product. You pick an edition from a few choice, and you live with what it comes with (well, there are extensions these days so not true but for most part you are all set once you install a Visual Studio). With Eclipse, you have to either work with EE package which is bloated with lots of feature that you might never use and deal with slowness during both start up time and during use. Trust me. EE was so horribly slow that I set up ProcessMon to see what it's doing, and it was reading ton of files for plugin stuff, taking like 10 minutes in response to a menu item. Its horrible.
  • Visual Studio is much more stable. Back in .NET days, I might have had three instances of Visual Studio running for several months. With Eclipse, I probably forcibly killed Eclipse process (which also creates java.exe and javaw.exe processes on top of eclipse.exe process) maybe like 50 times. It happens less after I built a lean-and-mean Eclipse created from bare-minimum Eclipse classic. Maybe Eclipse appeared hung when it was just working on something. But I couldn't tell and I lost many hours just waiting for it to complete its jobs. Its horrible.

Now, there are nice things about Eclipse too. I haven't come to appreciate it much but I see some potential, and its extensibility.  Feature set is not dictated by a single company. Its built by a community. Writing your own plugin (extension module) is easy - it even came with a tutorial right within Eclipse.

So, Eclipse is much more flexible, but that flexibility also implies complexity and lack of uniform testing of the products. You have to tame it.

Some surprises for Visual Studio users
You have .sln for Visual Studio. Eclipse doesn't have one. Instead, it uses a "folder" which is designated as "workspace". Its very file system oriented.

Namespace hierarchy and file system hierarchy must match. This is Java characteristics. I am so used to be able to put my .cs files at any folder organization, when you see com\company\product\foo\bat\hello.java (and usually deeper than this), you are like "oh crap, do I have to dig deep into this folder structure everytime I wanna open a .java file? (By the way, you don't. If you use Eclipse's Package Explorer, you can get to each .java class directly)

In Visual Studio, .csproj keeps track of the membership of source files. If you have a junk .cs file in your project but if its not part of .csproj then it doesn't matter. Its not part of the project. In Eclipse, it is part of your project. Its file based. If a file is in the folder that contains source, then it is subject to build.

Maven
Maven was very confusing to me at first, but after going through some tutorials it makes sense and it is a nice build system. I don't have much experience with Ant (but have done Nant and MSBuild) but many Java programmers seem to appreciate Mavan in terms of ease of use compared to Ant.

Its concept of repository is very powerful. Its very open-source oriented in the sense that you have a gigantic repository of stuff people build and you build your project by using those in the repository. Your project itself can be part of the repository. Its a wonderful open-source reuse mechanism.

Also dependency management becomes easier as you don't have to be aware of the hierarchical dependency tree. Maven will take care of downloading all needed for you.

I like it. I am not aware of .NET counterpart for this.

I tried to use Maven's POM file (its Maven't project file, if you will) with Eclipse using a special plugin just for that. It didn't work for me (but its due to the projects' complexity and my lack of understanding on my part). But once I gain experience with Maven Eclipse plugin, I would probably prefer to use Maven POM over Eclipse's native .project and .classpath file. (These are kind of similar to Visual Studio's .csproj but not quite


JBoss
This is just one of the web server. Its quite different from IIS. Like many open-source applications, you don't have a Setup.exe for this. You just un-zip a bunch of files to a location you like, and done.

It comes with script (both .sh and .bat for Linux and Windows). I use Cygwin and .sh files but you can easily use CMD to use .bat and do the same thing. To run a server (like IIS's "start"), you open up a console and run an appropriate batch file to start it.

Once you start it, then you would use brower to interact with an administrative page. This is very different from IIS where there is a Windows interface to work with various IIS configurations. You can use JBoss web admin interface to add "application" by pointing to a .WAR file (a zipped up web application content). You could also use file system based deployment of your web application by placing a set of web application files under a special folder called "deployments" and then place a so-called marker file in there. JBoss has a built-in scanner that watches this folder and takes a presence of a marker file as a command. Kinda weird and feels like 80ish way, but it works.

PostgreSQL
Our team happens to use this. I just thought this is nice database. I have been using Microsoft SQL Server but I can see myself using this instead of SQL server. It provides a nice UI to manage database. I haven't had chance to work with this extensively yet but so far it seems a very nice easy-to-use database.

Hibernate
This is a counter-part of .NET ADO.NET Entity Framework. I don't have extensive experience with this either but it seems to have nice infrastructure to define mappings between your class and database schema. I love Entity Framework, but it has some learning curve. I like to see how easy Hibernate is as I think there is a .NET package of hibernate.

OK, maybe that's it.

So far, I am enjoying working with Java and open-source server applications.

0 件のコメント:

コメントを投稿