h1

30 simple Java questions

February 23, 2007

30 simple Java questions

  1. What’s the difference between an interface and an abstract class?

    An abstract class may contain code in method bodies, which is not allowed in an interface. With abstract classes, you have to inherit your class from it and Java does not allow multiple inheritance. On the other hand, you can implement multiple interfaces in your class.

  2. Why would you use a synchronized block vs. synchronized method?

    Synchronized blocks place locks for shorter periods than synchronized methods.

  3. Explain the usage of the keyword transient?

    This keyword indicates that the value of this member variable does not have to be serialized with the object. When the class will be de-serialized, this variable will be initialized with a default value of its data type (i.e. zero for integers).

  4. How can you force garbage collection?

    You can’t force GC, but could request it by calling System.gc(). JVM does not guarantee that GC will be started immediately.

For More…

Advertisement

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Connecting to %s

Follow

Get every new post delivered to your Inbox.