Posts

Showing posts from 2011

Java Object Serialization Interview Questions

How many methods in the Serializable interface? Which methods of Serializable interface should I implement? There is no method in the Serializable interface. It’s an empty interface which does not contain any methods. The Serializable interface acts as a marker, telling the object serialization tools that the class is serializable. So we do not implement any methods. What is the difference between Serializalble and Externalizable interface? How can you control over the serialization process i.e. how can you customize the seralization process? When you use Serializable interface, your class is serialized automatically by default. But you can override writeObject() and readObject() two methods to control more complex object serailization process. When you use Externalizable interface, you have a complete control over your class’s serialization process. This interface contains two methods namely readExternal and writeExternal. You should implement these methods and write the logi...

Garbage collection interview questions

Explain garbage collection? Or How you can force the garbage collection ? Or What is the purpose of garbage collection in Java, and when is it used? Or What is Garbage Collection and how to call it explicitly? Or Explain Garbage collection mechanism in Java? Garbage collection is one of the most important features of Java. The purpose of garbage collection is to identify and discard objects that are no longer needed by a program so that their resources can be reclaimed and reused. A Java object is subject to garbage collection when it becomes unreachable to the program in which it is used. Garbage collection is also called automatic memory management as JVM automatically removes the unused variables/objects (value is null) from the memory. Every class inherits finalize() method from java.lang.Object, the finalize() method is called by garbage collector when it determines no more references to the object exists. In Java, it is good idea to explicitly assign null into a variable...

Java Interview Questions and answers

What if the main method is declared as private? The program compiles properly but at runtime it will give “Main method not public.” message. What is meant by pass by reference and pass by value in Java? Pass by reference means, passing the address itself rather than passing the value. Pass by value means passing a copy of the value. If you’re overriding the method equals() of an object, which other method you might also consider? hashCode() What is Byte Code? Or What gives java it’s “write once and run anywhere” nature? All Java programs are compiled into class files that contain bytecodes. These byte codes can be run in any platform and hence java is said to be platform independent. Expain the reason for each keyword of public static void main(String args[])? public- main(..) is the first method called by java environment when a program is executed so it has to accessible from java environment. Hence the access specifier has to be public. static: Java environment should be...

Intents and Notifications

Intents   Intents are the messages that are used to activate following application components  Activities  Services  Broadcast Receivers Intent is an object, which has a data structure holding any one of the following data : Abstract description of an operation to be performed  In the case of broadcasts, a description of something that has happened and is being announced. Invoking Components Application components are invoked through intents in the following way :  Activity : Intent object is passed to following functions to invoke the Activity.  Context.startActivity (Intent intent)  Activity.startActivityForResult (Intent intent, int requestCode) Service : Intent object is passed to following functions to invoke the Service. Context.startService (Intent) Context.bindService (Intent) Broadcast Receivers : Intent object is passed to following functions to invoke the Broadcast Receiver. Context.sendBroadcast ( ...

Android: Menus and Dialogs

Image
Table of contents: 1. Menus Options menu Context menu Sub menu Creating different Menus 2. Dialogs  Alert Dialog Progressbar dialog DatePicker dialog TimePicker Dialog Toast Creating different dialogs  Menus Menus provide familiar interfaces to expose application functions without sacrificing screen space.  Android offers an easy programming interface to provide standardized application menus.   Android offers three fundamental types of application menus:  Options Menu   Context Menu   Sub-menu Options Menu: By default, every Activity supports an Options menu of actions or options. It is revealed by pressing the device MENU key. Options Menu has two groups of menu items:   Icon Menu   Collection of maximum of six menu items   Supports Icons and short-cuts   Expanded Menu   Exposed by the 'More' menu item   Displayed when the icon menu becomes over-loaded   Comprised o...

Android User Interface : Life cycles and Layouts

Image
  Activity  Creating Activity Activity Lifecycle Activity Lifetime Starting Activity Process Lifecycle 2. Layouts  Creating Layout Types of layout Layout parameters Activity: An Activity presents a visual user interface for one focused endeavor the user can undertake. Each Activity represents a screen (similar to the concept of a Form in desktop development) that an application can present to its users. Most Activities are designed to occupy the entire display, but you can create Activities that are semi-transparent, floating (Activity working as a dialog). Creating an Activity:  Create a new Activity by extending the Activity class.   Override the onCreate() method to set the view for the activity   Set the user interface to an Activity using the setContentView method in the onCreate method of the Activity.   Use the findViewById(int) method to retrieve the reference of the widgets in UI.   The bas...

Android Development

Image
1. Android Development 1.1. Android Operation System Android is an operating system based on Linux with a Java programming interface. It provides tools, e.g. a compiler, debugger and a device emulator as well as its own Java Virtual machine (Dalvik Virtual Machine - DVM). Android is created by the Open Handset Alliance which is lead by Google. Android uses a special virtual machine, e.g. the Dalvik Virtual Machine. Dalvik uses special bytecode. Therefore you cannot run standard Java bytecode on Android. Android provides a tool "dx" which allows to convert Java Class files into "dex" (Dalvik Executable) files. Android applications are packed into an .apk (Android Package) file by the program "aapt" (Android Asset Packaging Tool) To simplify development Google provides the Android Development Tools (ADT) for Eclipse . The ADT performs automatically the conversion from class to dex files and creates the apk during deployment. Android supports 2-D and 3-D gr...