『Java』面试题TOP10_(java interview questions)

Update: 2007.6.26 By: Border

Java面试题TOP10:
JAVA, JSP, SERVLETS, EJB, STRUTS, XML, ANT, LOG4J, WEBLOGIC ... 都有

可以在Goolge.com中搜 java interview questions java 面试题
如果英语好的还是建议看看英文的,中问的搜来搜去还都是那些东西。

例如:
1. Why do we need public static void main(String args[]) method in Java
We need
public: The method can be accessed outside the class package
static: You need not have an instance of the class to access the method
void: Your application need not return a value, as the JVM launcher would return the value when it exits
main(): This is the entry point for the application

If the main() was not static, you would require an instance of the class in order to execute the method.
If this is the case, what would create the instance of the class? What if your class did not have a public constructor?

2. Explain serialization
Serialization means storing a state of a java object by coverting it to byte stream

3. What are the rules of serialization
Rules:
1. Static fileds are not serialized because they are not part of any one particular object
2. Fileds from the base class are handled only if hose are serializable
3. Transient fileds are not serialized

4. Is Empty .java file a valid source file?
Yes, an empty .java file is a perfectly valid source file.
[Received from Sandesh Sadhale]
5. Is main a keyword in Java?
No, main is not a keyword in Java.

6.What happens if you dont initialize an instance variable of
any of the primitive types in Java?

Java by default initializes it to the default value for that primitive type.
Thus an int will be initialized to 0, a boolean will be initialized to false.

7. How many objects are created in the following piece of code?
MyClass c1, c2, c3; c1 = new MyClass (); c3 = new MyClass ();
  Only 2 objects are created, c1 and c3. The reference c2 is only declared and
not initialized.


8. What will be the default values of all the elements of an array defined as
an instance variable?
If the array is an array of primitive types, then all the elements of the array
will be initialized to the default value corresponding to that primitive type. e.g.
All the elements of an array of int will be initialized to 0, while that of boolean
type will be initialized to false. Whereas if the array is an array of references
(of any type), all the elements will be initialized to null.

9. difference between java.sql.Date and java.util.Date
1)
java.util.Date is the superclass for java.sql.Date i.e public class Date extends
java.util.Date { }
2) java.sql.Date is used for databases where we just need to store date and not
time but java.util.date returns Date as well as time

3) java.util.Date has constructor with 0 parameters but java.sql.Date does not
has the one, so we canot use new Date() here, time in milliseconds needs to be passed

10. 用UML画出你所熟悉的设计模式?

11. 什么是序列化?
序列化可以将对象写入字节流,他也可以从字节流中读取对象。将对象状态转换成字节流之后,
可以用java.io包中各种字节流类将其保存到文件中,管道到另一线程中或通过网络连接将对象数据发送到另一主机。
对象序列化功能非常简单、强大,在RMI、Socket、JMS、EJB都有应用。java核心类的许多类都实现了
java.io.Serializable接口而且,java的序列化比较简单,通常不需要编写保存和恢复对象状态的定制代码。
实现java.io.Serializable接口的类对象可以转换成字节流或从字节流恢复,不需要在类中增加任何代码。


--
Blog: www.borderj.cn
MSN: [email protected]

Border

你可能感兴趣的:(java,sql,weblogic,面试,ejb)