Subscribe

RSS Feed (xml)

Powered By

Skin Design:
Free Blogger Skins

Powered by Blogger

Search Your Question

Friday, May 30, 2008

Turtle 1.0 Interview question

Turtle Turtle is a file fixer software that provides several functions like replacing plain text/pattern from one or multiple files, removing invalid characters from file names and stripping comments from source files etc.
[Note: This Software is available for free]









DOWNLOAD

DotNet Framework & IIS installation order Interview question

If you ever install the dot net framework before the IIS, then your aspx pages would not work. The solution to this problem is that:

open the command prompt [For windows Xp and greater]
>>cd C:\WINDOWS\Microsoft.NET\Framework\v1.1.4322
>>aspnet_regiis.exe -i

In case you are using any other windows then search the aspnet_regiis.exe file and run this file from the command prompt with -i argument.

Note: Today one of my friend asked me about this problem and he told me that he is unable to find any solution of this problem on the net, so i though of publishing it on my blog. Hope it will help many.

Camps & Medicines are needed more than anything else, Pakistan Intl. Airlines will carry donations for free. Interview quations

As you may already know, the disaster that struck Pakistan's Kashmir and NWFP areas has left at least 40,000 dead and 2.5 million homeless (full stats are not in yet, many areas are not accessible at all because of damaged roads due to landslides), there is dire need of clothes, food items, medicines and camping equipment for the survivors.

http://news.google.com.pk/news?hl=en&ned=us&ie=UTF-8&q=earthquake+toll+40%2C000&btnG=Search+News


The winter has arrived and rain and hailstorms have severely hurt the rescue efforts. Please ask your local volunteers to collect as many donations as possible.

Lot of people in Pakistan are collecting donations and lots of cargo trucks, airplanes and helicopters have been dispatched to the affected areas, but the most important items that are short in supply are camps. No more camps are available in and around Lahore, and manufacturers have order for thousands of camps, but they won't be ready for many days.

2.5 million (possibly many more) people are left with no shelter, which means at least half a million camps are required.

The best thing would be to purchase camping equipment and medicines and send them to Pakistan, preferably Islamabad (because Islamabad is the closest big city, 95 km from Muzaffarabad, the epicenter) or Lahore (another 300km from Islamabad) because even with all the monetary aid, camps are not available here at all.

Pakistan International Airlines (PIA) will carry all relief goods for free from all of its stations in its global network ( http://www.piac.com.pk/press_release/pr293.asp)

Here are the url's of PIA's booking offices around the world alphabetized by cities:

http://www.piac.com.pk/b_offices/A.asp

(New York, Chicago, Houston in USA, Toronto in Canada)

List of PIA's worldwide Stations by Countries:

http://en.wikipedia.org/wiki/Pakistan_International_Airlines#Services

Links for online Donations: http://forums.anandtech.com/messageview.aspx?catid=38&threadid=1708958&enterthread=y

Please take action as quickly as possible, because the winter is here and the survivors are looking forward to our help. Feel free to contact me for any more information you need.

Thank you.

Executable Jar File in JAVA. Interview quations

Creating an executable jar file is not that tough if it does not involve any external jars. Create a manifest file and mention the main class path in the manifest file. Place all the class files in a folder along with the manifest file and run the following command:

jar -cfm [name of the jar file] [name of the manifest] *

Flags Description:
c: Create new archive
f: Specify the archive name
m: include manifest

* means include all the files in the current folder and all the sub folders.

The manifest file look something like this:

Main-Class: [name of the main class along with the package details]



Example
If your project has two files a.class and main.class. which are placed in a package(abc.def). Then the manifest would look like this(mainClass.mf):

___________________
Main-Class: abc.def.main
___________________

and the command to create an executable jar will be

jar -cfm test.jar mainClass.mf *

Everything works ok if you are not using any external jars but the problem arises when you have externals jar like you have used the logging component log4j. The manifest attribute Class-Path attribute in which you can mention the paths of the external jars, but i tried it for log4j but it didn't work it gives me error 'Logger Class Def Not Found'. I had created the following manifest for that (Keeping the above exapmle in mind)

__________________
Main-Class: abc.def.main
Class-Path: lib\log4j.jar
__________________

but this didn't worked.

Then i came across a work around for this, which is you create a jar file of your project class files without adding the extenal libaries ie. using the following same manifest:

___________________
Main-Class: abc.def.main
___________________

Place the created jar files along with the external jar files in another folder and then use the following manifest to create the final jar file.

____________________
Main-Class: abc.def.main
Class-Path: main\test.jar lib\log4j.jar
____________________

Notice that test.jar is the jar file of your actual project. the final jar created using the above manifest will work for you.

AJAX : Todays Buzz Interview question

AJAX: Today becoming very common, and you will see lot of people talking about it. Microsoft has also launched an ATLAS Framework which is the implementation of AJAX.

What AJAX is all about??

Want to get the bigger picture, I hope these slide will help you a lot, If not then do write to me for any assistence.

http://www.geocities.com/basit_tanveer/Data/AJAX.ppt

Thursday, May 29, 2008

Executable Jar File in JAVA. Interview question

Creating an executable jar file is not that tough if it does not involve any external jars. Create a manifest file and mention the main class path in the manifest file. Place all the class files in a folder along with the manifest file and run the following command:

jar -cfm [name of the jar file] [name of the manifest] *

Flags Description:
c: Create new archive
f: Specify the archive name
m: include manifest

* means include all the files in the current folder and all the sub folders.

The manifest file look something like this:

Main-Class: [name of the main class along with the package details]

Example
If your project has two files a.class and main.class. which are placed in a package(abc.def). Then the manifest would look like this(mainClass.mf):

___________________
Main-Class: abc.def.main
___________________

and the command to create an executable jar will be

jar -cfm test.jar mainClass.mf *

Everything works ok if you are not using any external jars but the problem arises when you have externals jar like you have used the logging component log4j. The manifest attribute Class-Path attribute in which you can mention the paths of the external jars, but i tried it for log4j but it didn't work it gives me error 'Logger Class Def Not Found'. I had created the following manifest for that (Keeping the above exapmle in mind)

__________________
Main-Class: abc.def.main
Class-Path: lib\log4j.jar
__________________

but this didn't worked.

Then i came across a work around for this, which is you create a jar file of your project class files without adding the extenal libaries ie. using the following same manifest:

___________________
Main-Class: abc.def.main
___________________

Place the created jar files along with the external jar files in another folder and then use the following manifest to create the final jar file.

____________________
Main-Class: abc.def.main
Class-Path: main\test.jar lib\log4j.jar
____________________

Notice that test.jar is the jar file of your actual project. the final jar created using the above manifest will work for you.

AJAX : Todays Buzzword Interview question

AJAX: Today becoming very common, and you will see lot of people talking about it. Microsoft has also launched an ATLAS Framework which is the implementation of AJAX.

What AJAX is all about??

Want to get the bigger picture, I hope these slide will help you a lot, If not then do write to me for any assistence.

http://www.geocities.com/basit_tanveer/Data/AJAX.ppt

AJAX : Todays Buzzword Interview question

AJAX: Today becoming very common, and you will see lot of people talking about it. Microsoft has also launched an ATLAS Framework which is the implementation of AJAX.

What AJAX is all about??

Want to get the bigger picture, I hope these slide will help you a lot, If not then do write to me for any assistence.

http://www.geocities.com/basit_tanveer/Data/AJAX.ppt

AJAX : Todays Buzzword Interview question

AJAX: Today becoming very common, and you will see lot of people talking about it. Microsoft has also launched an ATLAS Framework which is the implementation of AJAX.

What AJAX is all about??

Want to get the bigger picture, I hope these slide will help you a lot, If not then do write to me for any assistence.

http://www.geocities.com/basit_tanveer/Data/AJAX.ppt

AJAX : Todays Buzzword Interview question

AJAX : Todays Buzzword

AJAX: Today becoming very common, and you will see lot of people talking about it. Microsoft has also launched an ATLAS Framework which is the implementation of AJAX.

What AJAX is all about??

Want to get the bigger picture, I hope these slide will help you a lot, If not then do write to me for any assistence.

What is .Resx file in Dot Net? Interview question

What is .Resx file in Dot Net??

It is an XML based file, with key value pair.

Reading from .Resx File:

You can access the .Resx file using this code:

ResXResourceReader reader = new ResXResourceReader(Server.MapPath("test.resx"));
IDictionaryEnumerator rsxr = reader.GetEnumerator();
foreach (DictionaryEntry d in reader)
{
Console.WriteLine(d.Key.ToString() + ":\t" + d.Value.ToString());
}
//Close the reader.
reader.Close();

Writing to .Resx File:

We can write the binary data of an image to the .Resx file using the following code

Image img = Image.FromFile("urdu.jpg");
ResXResourceWriter rsxw = new ResXResourceWriter("urdu.resx");
rsxw.AddResource("urdu.jpg",img);
rsxw.Close();

Use of .Resx File:

It is very useful while working on Localized project [Multiple Languages], You can make different resource files for different languages and depending upon the user choice you can change the Language of the application.

How to use Microsoft Indexing Service? Interview question

Using Microsoft Indexing Service:

Want to add document search in your application, you can use microsoft indexing service to do that. You can create a Catlog in the Microsoft indexing service on the folder whose document you want to search from your application. I will guide you on how to use microsoft indexing service from your ASP.NET page.

Go to Computer Management->Services and Application->Indexing Service and make sure that it is running.



You can create a new Catalg by Right Clicking the 'Indexing Service'. You can give a name to the catalog and browse to the folder which you want to be indexed by this catalog.



MS Indexing Service + ASP.NET
Creating an ASP.NET page that can query from the MS Indexing service, I will use the 'Web' catalog that is created by deafult by the indesing service on the 'c:\inetpub\wwwroot\' folder.

We can connect to the MS Indexing service through the following Connection String {"Provider=\"MSIDXS.1\";Data Source=;Integrated Security .="}

You can select the Name of the File, the path where it is located and some of the text from the file. {Select FileName,Path,Characterization from Scope()}

Code:
protected System.Data.OleDb.OleDbConnection oleDbConnection1;

this.oleDbConnection1.ConnectionString = "Provider=\"MSIDXS.1\";Data Source=Web;Integrated Security .=";

{You can change the 'Data Source' to the name of the catalog in which you want to search}


protected System.Data.OleDb.OleDbCommand oleDbSelectCommand3;
protected System.Data.OleDb.OleDbDataAdapter oleDbDataAdapter2;


this.oleDbSelectCommand3 = new System.Data.OleDb.OleDbCommand();
this.oleDbDataAdapter2 = new System.Data.OleDb.OleDbDataAdapter();

Posting data to another ASPX Page Interview question




One of the common problems faced by the JSP and ASP developers while developing application in ASP.NET is posting data to another ASPX page. By Default if you have a server side form tag in an aspx page then it will post the data to the same page.

I Came across a very easy to understand article for doing this, hope it will also help you in understanding the concept.

Virtual Karma: Complete List of Web 2.0 Applications | Rian's blog Interview question

Virtual Karma: Complete List of Web 2.0 Applications | Rian's blog

Some Useful Web Links Interview question

Hi,

One of my colleague accumulated a list of useful links on the web , i have uploaded that document on the Writely . It you want to collaborate on this document to add more useful links, please send me your email address so that i can add you in the collaborator list.

Its URL is:

http://www.writely.com/Doc.aspx?id=bcsw8fz74pf

Hope it will be useful for you you guys.

Acknowledgments:

Adeel Anwar

Home automation in the Netherlands Interview question

This guy is monitoring everything he can: phone, energy, water, gas usage... This is crazy.... check it out!

read more | digg story

Speed Up your web sites with HTTP Compression Interview question

1. Increase the speed of web page retrieval (effectively the speed of your web site).
2. Reduce the bandwidth utilization.

How to achieve all these??

You can achieve the above goal by decreasing the size of your HTML pages, JS, CSS which can be done be a technique known as HTTP Compression.

Idea behind HTTP Compression:

The idea is to compress data being sent out from your Web server, and have the browser decompress this data on the fly, thus reducing the amount of data sent and increasing the page display speed. There are two ways to compress data coming from a Web server, dynamically, and pre-compressed. Dynamic Content Acceleration compresses the data transmission data on the fly (useful for e-commerce apps, database-driven sites, etc.). Pre-compressed text based data is generated beforehand and stored on the server (.html.gz Files etc). [source:]

The compression techniques (algorithm) used can be
1. GZIP
2. Deflate Compression

I found a very useful link with details of the software used for HTTP compression

ASP.NET 2.0 Magic: Asynchronous Web Pages Interview question

The classic and inherently synchronous processing model of ASP.NET pages is simply unfit. Asynchronous HTTP handlers have existed since ASP.NET 1.0, but the ASP.NET 2.0 provides an easy to use API for managing Asynchronous Web Pages. If we have an I/O incentive operation then the ASP.NET synchronous page is blocked waiting for the I/O to complete, which leaves the end user waiting. In case of asynchronous access the execution of page is divided in to two segment, one when the execution starts and the other when the task is done, these two task works in separate threads.

We can set an asp.net page to execute asynchronously by setting up the Async tag in the Page declaration of the ASP.NET Page.

<%@ Page Async="true" ... %>

This reference on the MSDN will be helpful in understanding it in details.

RSS Puller in ASP Interview question

I have created a sample asp page that pulls the data from RSS and displays it on the page, using an XSL fro formatting the output. You just need to change the URL of RSS in:

<%= getXML(" RSS_URL ") %>

Where:

RSS_URL: URL of the RSS whose contents we want to see.

You can change the output of the RSS by updating the XSL file.

ASP.NET: Interview Questions

Hi, These are the typical questions that i usually asks while taking an ASP.NET specific interview. Hope these might help someone :)

*What is View State?
*Can you read the View State?
*What is the difference between encoding and encryption? Which is easy to break?
*Can we disable the view state application wide?
*can we disable it on page wide?
*can we disable it for a control?
*What is provider Model?
*Any idea of Data Access Component provided by Microsoft?
*Any idea of Enterprise library?
*What is web service?
*What is WSDL?
*Can a web service be only developed in asp.ent?
*can we use multiple web services from a single application?
*can we call a web service asynchronously?
*Can a web service be used from a windows application?
*What do we need to deploy a web service?
*What is the significance of web.config?
*Can we have multiple web.config files in a sigle web project?
*Can we have more then one configuration file?
*Type of Authentications?
*Can we have multiple assemblies in a single web project?
*What is GAC?
*What is machine.config?
*What different types of session state Management we have in asp.net?
*What are cookies?
*What is Cache?
*What is AJAX?
*Is AJAX a language?
*What is the difference between syncronus and asyncronus?
*What is an Assembly?
*Can an assembly contains more then one classes?
*What is strong name?
*What is the difference b/w client and server side?
*What we need for the deployment of a asp.net we application?
*what is the purpose of IIS?
*Difference between http and https?
*what is purpose of aspnet_wp.exe ?
*what is an ISAPI filter?
*what do you mean by HTTP Handler?
*What is the purpose of Global.asax?
*What is the significance of Application_Start/Session_Start/Application_Error?
*What is the difference between the inline and code behind?
*what is side by side execution?
*can we have two different versions of dot net frameworks running on the same machine?
*What is CLR? Difference b/w CLR and JVM?
*What is CLI?
*What is CTS?
*What is .resx file meant for?
*Any idea of aspnet_regiis?
*Any idea of ASP NET State Service?
*Crystal report is only used for read only data and reporting purposes?
*We can add a crystal report in aspx page using two techniques, what are these?
*What is the difference between stroed procedure and stored function in SQL?
*Can we have an updateable view in SQL?
*What is connection pooling? how can we acheive that in asp.net?
*What is DataSet?
*What is the difference between typed and untyped dataset?
*What is the difference bewteen accessing the data throgh the dataset and datareader?

Thanks,
Happy Interviewing.

Java Interview Questions

Q:

What is the difference between an Interface and an Abstract class?

A:

An abstract class can have instance methods that implement a default behavior. An Interface can only declare constants and instance methods, but cannot implement default behavior and all methods are implicitly abstract. An interface has all public members and no implementation. An abstract class is a class which may have the usual flavors of class members (private, protected, etc.), but has some abstract methods.

Q:

What is the purpose of garbage collection in Java, and when is it used?

A:

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.

Q:

Describe synchronization in respect to multithreading.

A:

With respect to multithreading, synchronization is the capability to control the access of multiple threads to shared resources. Without synchonization, it is possible for one thread to modify a shared variable while another thread is in the process of using or updating same shared variable. This usually leads to significant errors.


Q:

Explain different way of using thread?

A:

The thread could be implemented by using runnable interface or by inheriting from the Thread class. The former is more advantageous, 'cause when you are going for multiple inheritance..the only interface can help.


Q:

What are pass by reference and passby value?

A:

Pass By Reference means the passing the address itself rather than passing the value. Passby Value means passing a copy of the value to be passed.

Q:

What is HashMap and Map?

A:

Map is Interface and Hashmap is class that implements that.

Q:

Difference between HashMap and HashTable?

A:

The HashMap class is roughly equivalent to Hashtable, except that it is unsynchronized and permits nulls. (HashMap allows null values as key and value whereas Hashtable doesnt allow). HashMap does not guarantee that the order of the map will remain constant over time. HashMap is unsynchronized and Hashtable is synchronized.

Q:

Difference between Vector and ArrayList?

A:

Vector is synchronized whereas arraylist is not.

Q:

Difference between Swing and Awt?

A:

AWT are heavy-weight componenets. Swings are light-weight components. Hence swing works faster than AWT.

Q:

What is the difference between a constructor and a method?

A:

A constructor is a member function of a class that is used to create objects of that class. It has the same name as the class itself, has no return type, and is invoked using the new operator.
A method is an ordinary member function of a class. It has its own name, a return type (which may be void), and is invoked using the dot operator.

Q:

What is an Iterator?

A:

Some of the collection classes provide traversal of their contents via a java.util.Iterator interface. This interface allows you to walk through a collection of objects, operating on each object in turn. Remember when using Iterators that they contain a snapshot of the collection at the time the Iterator was obtained; generally it is not advisable to modify the collection itself while traversing an Iterator.


Q:

State the significance of public, private, protected, default modifiers both singly and in combination and state the effect of package relationships on declared items qualified by these modifiers.

A:

public : Public class is visible in other packages, field is visible everywhere (class must be public too)
private : Private variables or methods may be used only by an instance of the same class that declares the variable or method, A private feature may only be accessed by the class that owns the feature.
protected : Is available to all classes in the same package and also available to all subclasses of the class that owns the protected feature.This access is provided even to subclasses that reside in a different package from the class that owns the protected feature.
default :What you get by default ie, without any access modifier (ie, public private or protected).It means that it is visible to all within a particular package
.


Q:

What is an abstract class?

A:

Abstract class must be extended/subclassed (to be useful). It serves as a template. A class that is abstract may not be instantiated (ie, you may not call its constructor), abstract class may contain static data. Any class with an abstract method is automatically abstract itself, and must be declared as such.
A class may be declared abstract even if it has no abstract methods. This prevents it from being instantiated.


Q:

What is static in java?

A:

Static means one per class, not one for each object no matter how many instance of a class might exist. This means that you can use them without creating an instance of a class.Static methods are implicitly final, because overriding is done based on the type of the object, and static methods are attached to a class, not an object. A static method in a superclass can be shadowed by another static method in a subclass, as long as the original method was not declared final. However, you can't override a static method with a nonstatic method. In other words, you can't change a static method into an instance method in a subclass.


Q:

What is final?

A:

A final class can't be extended ie., final class may not be subclassed. A final method can't be overridden when its class is inherited. You can't change value of a final variable (is a constant).




Q:

What if the main method is declared as private?




A:

The program compiles properly but at runtime it will give "Main method not public." message.


Q:

What if the static modifier is removed from the signature of the main method?

A:

Program compiles. But at runtime throws an error "NoSuchMethodError".


Q:

What if I write static public void instead of public static void?

A:

Program compiles and runs properly.




Q:

What if I do not provide the String array as the argument to the method?

A:

Program compiles but throws a runtime error "NoSuchMethodError".


Q:

What is the first argument of the String array in main method?

A:

The String array is empty. It does not have any element. This is unlike C/C++ where the first element by default is the program name.


Q:

If I do not provide any arguments on the command line, then the String array of Main method will be empty or null?

A:

It is empty. But not null.


Q:

How can one prove that the array is not null but empty using one line of code?

A:

Print args.length. It will print 0. That means it is empty. But if it would have been null then it would have thrown a NullPointerException on attempting to print args.length.

Q:

What environment variables do I need to set on my machine in order to be able to run Java programs?

A:

CLASSPATH and PATH are the two variables.

Q:

Can an application have multiple classes having main method?

A:

Yes it is possible. While starting the application we mention the class name to be run. The JVM will look for the Main method only in the class whose name you have mentioned. Hence there is not conflict amongst the multiple classes having main method.

Q:

Can I have multiple main methods in the same class?

A:

No the program fails to compile. The compiler says that the main method is already defined in the class.

Q:

Do I need to import java.lang package any time? Why ?

A:

No. It is by default loaded internally by the JVM.

Q:

Can I import same package/class twice? Will the JVM load the package twice at runtime?

A:

One can import the same package or same class multiple times. Neither compiler nor JVM complains abt it. And the JVM will internally load the class only once no matter how many times you import the same class.

Q:

What are Checked and UnChecked Exception?

A:

A checked exception is some subclass of Exception (or Exception itself), excluding class RuntimeException and its subclasses.
Making an exception checked forces client programmers to deal with the possibility that the exception will be thrown. eg, IOException thrown by java.io.FileInputStream's read() method·
Unchecked exceptions are RuntimeException and any of its subclasses. Class Error and its subclasses also are unchecked. With an unchecked exception, however, the compiler doesn't force client programmers either to catch the
exception or declare it in a throws clause. In fact, client programmers may not even know that the exception could be thrown. eg, StringIndexOutOfBoundsException thrown by String's charAt() method· Checked exceptions must be caught at compile time. Runtime exceptions do not need to be. Errors often cannot be.

Q:

What is Overriding?

A:

When a class defines a method using the same name, return type, and arguments as a method in its superclass, the method in the class overrides the method in the superclass.
When the method is invoked for an object of the class, it is the new definition of the method that is called, and not the method definition from superclass. Methods may be overridden to be more public, not more private.

Q:

What are different types of inner classes?

A:

Nested top-level classes, Member classes, Local classes, Anonymous classes

Nested top-level classes- If you declare a class within a class and specify the static modifier, the compiler treats the class just like any other top-level class.
Any class outside the declaring class accesses the nested class with the declaring class name acting similarly to a package. eg, outer.inner. Top-level inner classes implicitly have access only to static variables.There can also be inner interfaces. All of these are of the nested top-level variety.

Member classes - Member inner classes are just like other member methods and member variables and access to the member class is restricted, just like methods and variables. This means a public member class acts similarly to a nested top-level class. The primary difference between member classes and nested top-level classes is that member classes have access to the specific instance of the enclosing class.

Local classes - Local classes are like local variables, specific to a block of code. Their visibility is only within the block of their declaration. In order for the class to be useful beyond the declaration block, it would need to implement a
more publicly available interface.Because local classes are not members, the modifiers public, protected, private, and static are not usable.

Anonymous classes - Anonymous inner classes extend local inner classes one level further. As anonymous classes have no name, you cannot provide a constructor.

Q:

Are the imports checked for validity at compile time? e.g. will the code containing an import such as java.lang.ABCD compile?

A:

Yes the imports are checked for the semantic validity at compile time. The code containing above line of import will not compile. It will throw an error saying,can not resolve symbol
symbol : class ABCD
location: package io
import java.io.ABCD;

Q:

Does importing a package imports the subpackages as well? e.g. Does importing com.MyTest.* also import com.MyTest.UnitTests.*?

A:

No you will have to import the subpackages explicitly. Importing com.MyTest.* will import classes in the package MyTest only. It will not import any class in any of it's subpackage.

Q:

What is the difference between declaring a variable and defining a variable?

A:

In declaration we just mention the type of the variable and it's name. We do not initialize it. But defining means declaration + initialization.
e.g String s; is just a declaration while String s = new String ("abcd"); Or String s = "abcd"; are both definitions.

Q:

What is the default value of an object reference declared as an instance variable?

A:

null unless we define it explicitly.




Q:

Can a top level class be private or protected?

A:

No. A top level class can not be private or protected. It can have either "public" or no modifier. If it does not have a modifier it is supposed to have a default access.If a top level class is declared as private the compiler will complain that the "modifier private is not allowed here". This means that a top level class can not be private. Same is the case with protected.

Q:

What type of parameter passing does Java support?

A:

In Java the arguments are always passed by value .

Q:

Primitive data types are passed by reference or pass by value?

A:

Primitive data types are passed by value.

Q:

Objects are passed by value or by reference?

A:

Java only supports pass by value. With objects, the object reference itself is passed by value and so both the original reference and parameter copy both refer to the same object .

Q:

What is serialization?

A:

Serialization is a mechanism by which you can save the state of an object by converting it to a byte stream.

Q:

How do I serialize an object to a file?

A:

The class whose instances are to be serialized should implement an interface Serializable. Then you pass the instance to the ObjectOutputStream which is connected to a fileoutputstream. This will save the object to a file.

Q:

Which methods of Serializable interface should I implement?

A:

The serializable interface is an empty interface, it does not contain any methods. So we do not implement any methods.

Q:

How can I customize the seralization process? i.e. how can one have a control over the serialization process?

A:

Yes it is possible to have control over serialization process. The class should implement Externalizable interface. This interface contains two methods namely readExternal and writeExternal. You should implement these methods and write the logic for customizing the serialization process.

Q:

What is the common usage of serialization?

A:

Whenever an object is to be sent over the network, objects need to be serialized. Moreover if the state of an object is to be saved, objects need to be serilazed.

Q:

What is Externalizable interface?

A:

Externalizable is an interface which contains two methods readExternal and writeExternal. These methods give you a control over the serialization mechanism. Thus if your class implements this interface, you can customize the serialization process by implementing these methods.

Q:

When you serialize an object, what happens to the object references included in the object?

A:

The serialization mechanism generates an object graph for serialization. Thus it determines whether the included object references are serializable or not. This is a recursive process. Thus when an object is serialized, all the included objects are also serialized alongwith the original obect.

Q:

What one should take care of while serializing the object?

A:

One should make sure that all the included objects are also serializable. If any of the objects is not serializable then it throws a NotSerializableException.

Q:

What happens to the static fields of a class during serialization?

A:

There are three exceptions in which serialization doesnot necessarily read and write to the stream. These are
1. Serialization ignores static fields, because they are not part of ay particular state state.
2. Base class fields are only hendled if the base class itself is serializable.
3. Transient fields.

Archives