Wednesday 7 December 2011

CSS Only for Webkit

What? Why would you do that? Well, sometimes cross-browser issues can be a pain, and fixing an issue in one browser could mean causing issues in other browsers. This is the time when you should consider creating CSS only for a certain browser, in my case Chrome and Safari.

Here's what I've done (thanks to this blog):
@media screen and (-webkit-min-device-pixel-ratio:0) {
    #my_id .my_form_row.my_embed_label input[type=password] {
        float: left;
    }
}

It is basically a media query supported by CSS3, which says that for "screen" media type that supports webkit, use the CSS code within the bracket. I would only use this technique if you run out of options, since this is kind of a hack for webkit browsers only.

Thursday 10 November 2011

Set Default Parameters in JavaScript using jQuery

When you create a JavaScript function with multiple parameters, it can get a little bit messy.

Consider this JavaScript function:
init_spinning : function(lines, length, width, radius, colour, speed, trail, shadow) {
  var opts = {
    lines: lines,
    length: length,
    width: width==null? 5,
    radius: radius==null? 8
    etc..
  }
}

Usage example:
init_spinning(8, 4, null, null, '#20CNSE', 1.6, 30, false);

Yuck! Not only do you have to remember which ones are mandatory, but also this is error prone.

Using jQuery's $.extend() function, we could use:
init_spinning : function(options) {
  var opts = $.extend({
    lines: 8,
    length: 5,
    width: 7,
    radius: 7,
    color: '#26BCED',
    speed: 1.3,
    trail: 44,
    shadow: false
  }, options||{});
  etc..
}

Usage example:
init_spinning({
  length: 3,
  width: 3,
  radius: 3
});

Much better! In the above example, the function has default values for all the parameters, and you just assign the ones that you need!

Monday 3 October 2011

Hash Table

Here is a good lecture on Hash Table

Tuesday 20 September 2011

Web Services Questions

Here we go:

  • Explain web services architecture (publish-find-bind).
  • What are the types of web services?
  • What is SOAP? Name two types of SOAP web services used.
  • What are the two approaches to create SOAP web services?
  • What is WSDL? Why would you need it?
  • What is the difference between DOM and SAX in JAXP?
  • Would you say JAXB is the best for performance? If not what is?
  • What is contract first? Where do you start?
  • What options do you have for security in Web Services?
  • In RESTful Web Services, what is the difference between POST and PUT?
  • Can you use GET instead of PUT to perform an update?
  • Name different output format that REST supports.
  • How do you handle errors in RESTful web services? Describe the options, the advantages and disadvantages.

Sunday 18 September 2011

Hibernate Questions

Here we go:

  • What is ORM?
  • What are the main advantages of using Hibernate?
  • How do you configure Hibernate?
  • What causes LazyInitializationException? What steps do you need to prevent this from happening?
  • What is OpenSessionInView pattern in Hibernate and when would you want to use it?
  • What is SessionFactory? Is it thread safe?
  • What is a Session? Can you share session object between threads?
  • What is HQL?
  • Name 3 inheritance mapping strategy and describe the limitations of each.
  • What do you think of using hibernate's own connection pooling algorithm?
  • Name the core interfaces of Hibernate framework.
  • What is the difference between session.load() and session.get()
  • What is the difference between session.saveOrUpdate() and session.merge()
  • What is a detached object? What other instance states does Hibernate have?
  • When would you use inverse in Hibernate?
  • What is the difference between join and select fetch strategy?
  • What are the advantages of using Hibernate vs JDBC?
  • What are the main differences between Hibernate and EJB?

Core Spring Questions

Spring questions:

  • Describe the life cycle of a bean in Spring.
  • What is the difference between singleton and prototype bean? Give an example when you would want to use one or the other.
  • What are the advantages of using Spring?
  • What are the main features of Spring?
  • What is Dependency Injection/IOC?
  • What are the three types of dependency injection? Which ones do Spring support?
  • Name all the 7 modules of Spring and describe what they are.
  • What's Bean Factory? What's Application Context? Describe the differences and when would you want to use one or the other?
  • What is auto wiring? Name all five modes.
  • Name two ways of accessing Hibernate using Spring.
  • What is AOP?
  • What is Aspect?
  • What is JointPoint?
  • What is Advice? Name 5 type of Advice.
  • Why use declarative over programmatic transaction management?
  • What are the main differences between EJB CMT and Spring's declarative transaction management?
  • Does Spring's transaction management support transaction context over remote calls?
  • Describe the main differences between EJB and Spring.

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
Share |