Saturday, 17 September 2011

J2EE Questions

Continuing from last post with basic questions, it's time for J2EE questions:
  • What is J2EE?
  • What are the 4 J2EE components?
  • What is multi tiered architecture?
  • What is the difference between a 3 tiered architecture and 3 layered architecture?
  • What is a J2EE container? What 7 services does it provide?
  • Describe JAR, WAR and EAR files.
  • What is EJB and what is its role?
  • What are the main differences between EJB 2.1 and EJB 3.0+?
  • What's the difference between Session Bean, Entity Bean, and Message Driven Bean and give an example where each should be used.
  • When would you want to use Stateful Session Bean?
  • What is the difference between Bean Managed Persistence (BMP) and Container Managed Persistence (CMP)?
  • What is deployment descriptor?
  • What is the role of JNDI?
  • What problems can you see using Java enum persisted in a database?

Friday, 16 September 2011

Core Java Questions

After nearly a decade in Java world, it is time to think about the basics (most people say Core Java). Anyone that has been in the Java industry for a long time should know the answer to all of the following questions, and if not, it is time to refresh your memory and maybe get excited again on what made you like Java in the first place. I'm not going to provide the answers since they are just a Google away, so here we go:
  • What is the difference between ArrayList and Vector?
  • What are the differences between Comparable and Comparator?
  • Name design patterns that you use in Java. Give some examples.
  • Implement a Singleton design pattern in Java. Why Singleton? Is the Singleton class that you created thread safe? What about the clone() method?
  • What are the differences between Heap, Perm and Stack space?
  • Explain how HashMap works in Java. Which method/s are used when put() or get() is called? What is the benefit of having immutable keys in HashMap?
  • Explain how Java Garbage Collection works. Explain in terms of young generation, survivor 1 and 2, tenured generation and permanent generation. Can you force garbage collection?
  • What JVM memory tuning options can you use to improve performance?
  • Explain how Serialization works in Java. Include methods that are involved during the serialization/deserialization. What is serialVersionUID? What could happen when serialVersionUID is missing?
  • What's so special about declaring a variable in a Java interface?
  • What is the difference between executing run() and start() in Java thread?
  • Explain why String is immutable? If it weren't, what would be the implications?
  • Can you write an immutable object?
  • What is the difference between creating String using new() and literal?
  • What is the difference between Enumeration and Iterator?
  • Explain deadlock. What would you check in the code that might cause deadlocks?
  • Explain Checked and Unchecked Exception.
  • When is finalize() method called?
  • Explain transient modifier.
  • Explain volatile modifer.
  • What is the difference between public, private and default?
  • What is operator precedence in Java?
  • What is the difference between abstract class and interface?
  • What is the difference between method override and method overload?
  • Explain polymorphism, inheritance, and encapsulation.
  • What is a wrapper class?
  • Explain autoboxing
  • Why would you use synchronized block instead of synchronized method?
  • What is the difference between method wait() and sleep()?
  • What is the difference between & and && operator?
  • What is the difference between >> and >>> operator?
  • In JDBC, which one is faster, Statement or PreparedStatement? Why?
I will be adding more questions later. Stay tuned!

Tuesday, 14 June 2011

Email from a Friend Needing Help

I've got an email that seemed genuine at first glance from my acquaintance.

It almost made me want to reply to the email asking him if he and his family are OK, but at the same time, it looked suspicious. I clicked on "show details" and had a look at the reply-to field and it confirmed my suspicion. The field is pointing to a different email address (in this case yahoo mail), which means that the email was most likely hacked, and the hacker would want me to reply to the message to confirm that my email address exists, and therefore would ask me to send some money to some overseas account.

I ignored the email and a few days later I got an email from him that his email account was hacked. It is another reminder for me that I need to be more careful before responding to any email messages.


Sunday, 24 April 2011

Cloud Outage

I'm a big fan of a cloud-based note-taking application called Springpad to help me remember things, and it's always been an excellent, reliable tool, and I've recommended this app to everyone that I know. Last Thursday before Easter, I was on my way home and had a look at it on my mobile. For some reason it was asking me to logout and re-login since it could not sync to the cloud, so I did what it asked me to do, but alas, it was a big mistake! At that exact moment, Springpad and other cloud-based applications such as Foursquare, Quora, Hootsuite, Shareaholic were down, as you can see from this article. Even Crust Pizza online ordering system was also down (see their twitter status link). I was not able to login, or access my check list, shopping list, car insurance comparison, bookmarks, trip plans, and other useful stuff that I normally use this tool to take a note of for 2 days. Users were angry, as you can see from this link. I seriously considered going back to using Evernote.

All those cloud-based services are using Amazon EC2 (Amazon Elastic Compute Cloud), a cloud service provided by Amazon designed to be flexible in terms of resizing cloud capacity and other technical functionalities, hence making it easier for developers. When this cloud went down, all the services did go down with it since all the data was stored in this Amazon cloud. Some of the services actually moved their hosting elsewhere until the Amazon cloud was back up so that users could still use them.

Imagine that you don't have access to all your important data for 2 days! It may not seem long but nowadays that is a very long time. Here we can see the downside of using cloud based services. You're at the mercy of your provider if the cloud goes down, but in my opinion, people should not be discouraged by this event. Hosting data on your own has its downsides too, and some downtimes are also expected. What I would suggest they do is:

  • Don't put all of your resources in one cloud. Amazon EC2 has various availability zones, so it is wise to spread your resources into different zones, or better still if possible, into different providers
  • Just because you've outsourced your data to the cloud, does not mean that you should not think of a backup plan just in case it goes down
  • Have offline access, where applicable, so if the cloud goes down, the application can display a meaningful message and users would still be able to continue using it

Sunday, 21 March 2010

NetComm Wireless Modem Router

A couple of days ago my F5D7230-4 Belkin wireless router stopped working. I was hoping that it was an adaptor problem, so I went to the electronics shop and tested it with a new adaptor, but unfortunately it still did not work. I've had this router for more than 3 years and I actually like this wireless router as it had been providing me with excellent signal strength.


Now, the way I set up my home networking was by using a modem router given by my ISP, NetComm NB9W. The "W" is supposed to give me wireless support as well but I was not satisfied with the range. It was so hopeless that when I moved to another room, which is not so far away, the signal was extremely weak. That is the reason why I used my Belkin wireless router on top of this modem. I just switched off the modem's wireless option.

I was a man on a mission to get a new wireless N router/modem. I searched online, ebay, and went to a few computer shops. Initially, I was a bit sceptical about "x" in one devices since essentially a wireless router modem is a 3-in-1 device (a modem, a wireless router, and a switch), hence the reason why I used two separate devices. When one goes wrong, I could just replace the faulty one instead of the whole thing. I then went on to see different reviews of different products on the net, including NetGear, NetComm, Linksys, Belkin, and D-Link. I wanted to get another Belkin since it had been proven as a good performer in terms of its wireless signal. I was also told that the NetComm modem that I have is actually one of the lowest ranges, hence the bad quality. In the end, I purchased the new shiny NetComm NB6Plus4Wn, installed it, and surprised on how easy it was to set it up and also it had good signal strength. I have to admit that it is pretty good so far. Here's a picture of my new 11n wireless modem router in action:


Wednesday, 10 March 2010

Maven Plugin Dependency Duplication

Maven is a great build tool, and it has saved me from taking care of all the libraries and dependency hell, but it is not perfect, at least not in the version that I used (2.0.6). I wanted to use a newer version of one of the hibernate libraries, so I specified the new version in my project pom xml. The problem was that in the final war file, I had both the new version and the old version of the library. One of the plugin dependency actually depends on an older hibernate library, hence Maven automatically included both libraries. It is actually a known bug in 2.0.6 (see MNG-2972) and it's fixed in 2.0.9, so upgrading my Maven to 2.0.9 did the trick.

Monday, 8 March 2010

Transaction Pitfalls

Just thought that I need to post this very useful article about common transaction mistakes in Java platform. It's just so easy to assume that transaction works and then in the end (or worse, in production), you find out that it does not work as intended. The classic "Transaction Rollback" mistake is surprisingly common. I've seen this again and again as people assume that this would work automatically.
Share |