What is the basic difference between Java and .Net ?
Java is platform independent but it uses an respective jvms for each platform
.Net is also platform independent ie., it works on more than one os but the thing is that those platforms alll belong to windows.If you want to run .NET on unix use MONO Java is two things: the Java platform (runtime and APIs) and the Java language. The purpose of the Java platform is to support applications written in the Java language and compiled to Java bytecode. .NET also is two things: the .NET Framework (runtime and APIs) and the plethora of supported programming languages. The purpose of the NET Framework is to support applications written in any language and compiled to MSIL
Another difference is that in .NET you can edit the compiled MSIL or the microsoft intermediate language the compiled source code by using the MSIL debugger provided in .NET framework..Java Does not provide a tool to edit bytecode or to generate a new bytecode. It is possible in .NET.
.Net works for IIS/MTS server only but Java is supported by 45+ servers.
Migration is easy for a project on .Net while it is difficult in case of JAVA
projects...
The thing that microsoft havent created tools that support actual platform support is nothing but if it does so it has a problem of loosing those revenues that can be obtained thorough .Net and windows XP business.
What is the difference between an object and an instance? And give me a real time example to differentiate these two?
Object : Memory allocated by the JVM in Heap is nothing but an object.
Instance: If that memory is assigned to a class definition then it is called an Instance.
An object is part of a process/thread which demands processor time through the JVM.
The act of creating the object from a class is called instantiation.
In literary sense an instance is existance/occurrence of an object.
In this case a duplicate copy(instance) of an object is still the same .
How hashtable is synchronized?why hashmap is not synchronized?Can we make hashmap synchronized?
Hashtable and HashMap both are Key Value pairs and they function both the same way except in synchronization and HashMap accepts one null Key and many null values. hashtable is a legacy class.every legacy class provides synchroniztion.We can make hashmap synchronized but it call extra method. Hashmap is not synchronized but it part of collections and it enter null values.
Will there be a performance penalty if you make a method synchronized? If so, can you make any design changes to improve the performance ?
yes, the performance will be down if we use synchronization.
one can minimise the penalty by including garbage collection algorithm which reduces the cost of collecting large numbers of short- lived objects. and also by using Improved thread synchronization for invoking the synchronized methods.the invoking will be faster.
How would you implement a thread pool ?
public class ThreadPool extends java.lang.Object implements ThreadPoolInt
This class is an generic implementation of a thread pool which takes the following input
a) Size of the pool to be constructed
b) Name of the class which implements Runnable (which has a visible default constructor)
and constructs a thread pool with active threads that are waiting for activation. once the threads have finished processing they come back and wait once again in the pool.
This thread pool engine can be locked i.e. if some internal operation is performed on the pool then it is preferable that the thread engine be locked. Locking ensures that no new threads are issued by the engine. However the currently executing threads are allowed to continue till they come back to the passivePool
How does serialization work ?
Serialization is technique that writes the state of objects in to persistance stroage areas....
The Main use of this is nothing but transfering objects from one plce to another place (or) Globalize the object .....Means
If we want to transfer some data from one place to another place in the objects form ,this tecnique is used. Exactly we are not transfering the objects ,we just store the data of an object to persistance area.that Area will accessed by another objects which are using or need our object Data...for Example in Ejb technolgy (Distributed Technology) objects refferences are passed to clients using Serialization technique only.Serialization works by converting the object to be saved into a stream of bytes and writing it to a disk or a fille.
ObjectOutputStream makes an object so that it can be converted as bytes and then it coonects to another stream FileOutputStream which makes bytes toi be wriiten to file.
Serialization works by implementing java.io.serializable interface.Here the object form information is converted into stream form.It is mandatory to implement this interface while storing the data(information) into any persistance storage medium.
lets write one as follows.
class a{
String s;
a(){
s hi ;
}
}
now
create objectoutputstream object and give it to fileoutputstream with file name say a.ser (use writeObject() method)
if u check the object state is written in this file.
now create object Inputstream object and give it to fileinputstream with file same name a.ser (use readObject() method)
same object will be sent from device to console.
Java is platform independent but it uses an respective jvms for each platform
.Net is also platform independent ie., it works on more than one os but the thing is that those platforms alll belong to windows.If you want to run .NET on unix use MONO Java is two things: the Java platform (runtime and APIs) and the Java language. The purpose of the Java platform is to support applications written in the Java language and compiled to Java bytecode. .NET also is two things: the .NET Framework (runtime and APIs) and the plethora of supported programming languages. The purpose of the NET Framework is to support applications written in any language and compiled to MSIL
Another difference is that in .NET you can edit the compiled MSIL or the microsoft intermediate language the compiled source code by using the MSIL debugger provided in .NET framework..Java Does not provide a tool to edit bytecode or to generate a new bytecode. It is possible in .NET.
.Net works for IIS/MTS server only but Java is supported by 45+ servers.
Migration is easy for a project on .Net while it is difficult in case of JAVA
projects...
The thing that microsoft havent created tools that support actual platform support is nothing but if it does so it has a problem of loosing those revenues that can be obtained thorough .Net and windows XP business.
What is the difference between an object and an instance? And give me a real time example to differentiate these two?
Object : Memory allocated by the JVM in Heap is nothing but an object.
Instance: If that memory is assigned to a class definition then it is called an Instance.
An object is part of a process/thread which demands processor time through the JVM.
The act of creating the object from a class is called instantiation.
In literary sense an instance is existance/occurrence of an object.
In this case a duplicate copy(instance) of an object is still the same .
How hashtable is synchronized?why hashmap is not synchronized?Can we make hashmap synchronized?
Hashtable and HashMap both are Key Value pairs and they function both the same way except in synchronization and HashMap accepts one null Key and many null values. hashtable is a legacy class.every legacy class provides synchroniztion.We can make hashmap synchronized but it call extra method. Hashmap is not synchronized but it part of collections and it enter null values.
Will there be a performance penalty if you make a method synchronized? If so, can you make any design changes to improve the performance ?
yes, the performance will be down if we use synchronization.
one can minimise the penalty by including garbage collection algorithm which reduces the cost of collecting large numbers of short- lived objects. and also by using Improved thread synchronization for invoking the synchronized methods.the invoking will be faster.
How would you implement a thread pool ?
public class ThreadPool extends java.lang.Object implements ThreadPoolInt
This class is an generic implementation of a thread pool which takes the following input
a) Size of the pool to be constructed
b) Name of the class which implements Runnable (which has a visible default constructor)
and constructs a thread pool with active threads that are waiting for activation. once the threads have finished processing they come back and wait once again in the pool.
This thread pool engine can be locked i.e. if some internal operation is performed on the pool then it is preferable that the thread engine be locked. Locking ensures that no new threads are issued by the engine. However the currently executing threads are allowed to continue till they come back to the passivePool
How does serialization work ?
Serialization is technique that writes the state of objects in to persistance stroage areas....
The Main use of this is nothing but transfering objects from one plce to another place (or) Globalize the object .....Means
If we want to transfer some data from one place to another place in the objects form ,this tecnique is used. Exactly we are not transfering the objects ,we just store the data of an object to persistance area.that Area will accessed by another objects which are using or need our object Data...for Example in Ejb technolgy (Distributed Technology) objects refferences are passed to clients using Serialization technique only.Serialization works by converting the object to be saved into a stream of bytes and writing it to a disk or a fille.
ObjectOutputStream makes an object so that it can be converted as bytes and then it coonects to another stream FileOutputStream which makes bytes toi be wriiten to file.
Serialization works by implementing java.io.serializable interface.Here the object form information is converted into stream form.It is mandatory to implement this interface while storing the data(information) into any persistance storage medium.
lets write one as follows.
class a{
String s;
a(){
s hi ;
}
}
now
create objectoutputstream object and give it to fileoutputstream with file name say a.ser (use writeObject() method)
if u check the object state is written in this file.
now create object Inputstream object and give it to fileinputstream with file same name a.ser (use readObject() method)
same object will be sent from device to console.
Post a Comment