Java Interview Question
Agenda:
- Basic Java Questions
- OOPS Questionds
- Servlet
- JDBC
- Spring
- Hibernate
-----------------------------------------------------------------------------------------------------------------------------
Que:What is difference between JDK,JRE,JVM?
Ans: JVM(java Virtual Machine) is an abstract machine. It is a specification that provided runtime environment in which java bytecode can be executed.
JRE(java runtime environment) is a runtime environment which implements JVM and provides all class libraries and other files that files JVM uses at runtime.
JDK(java Development Kit)is the tool necessary to compile document and package java program. The JDK completely includes JRE.
Que: what is synchronization ?
Ans: Synchronization is a process which keeps all concurrent threads in execution to be in sync.
Synchronization avoid memory consistency error caused due to inconsistent view of shared memory.
Que What is difference between process and threads ?
Ans:
Que: How to customized the serialized to recover the loss of Information which happe dua to transient keyword.
We can implements customized serialization by using the following two methods.
1) private void writeObject(OutputStream os) throws Exception.
• This method will be executed automatically by jvm at the time of serialization.
• It is a callback method. Hence at the time of serialization if we want to perform any extra work
we have to define that in this method only.
2) private void readObject(InputStream is)throws Exception.
• This method will be executed automatically by JVM at the time of Deserialization. Hence at the
time of Deserialization if we want to perform any extra activity we have to define that in this
method only.
import java.io.*;
class Account implements Serializable {
String name = "Vikash" ;
transient String pass = "prachi";
private void writeObject(ObjectOutputStream os )throws Exception{
os.defaultWriteObject();
String epswd = "123"+pass;
os.writeObject(epswd);
}
private void readObject(ObjectInputStream is)throws Exception{
is.defaultReadObject();
String epwd = (String)is.readObject();
pass = epwd.substring(3);
}
}
class SerializableDemo {
public static void main(String[] args) throws Exception{
Account ac = new Account();
System.out.println(ac.name+"---------"+ac.pass);
//Serialization proccess
FileOutputStream fout = new FileOutputStream("abc.ser");
ObjectOutputStream oout = new ObjectOutputStream(fout);
oout.writeObject(ac);
//deSerialization proccess
FileInputStream in = new FileInputStream("abc.ser");
ObjectInputStream oin = new ObjectInputStream(in);
Account d1 = (Account)oin.readObject();
System.out.println(d1.name+"---------"+d1.pass);
}
}
Now reading another blog click here


Comments
Post a Comment