`
standalone
  • 浏览: 611122 次
  • 性别: Icon_minigender_1
  • 来自: 上海
社区版块
存档分类
最新评论

java question

    博客分类:
  • java
阅读更多

1. what is error? what is exception?

2. String vs. StringBuffer vs. StringBuilder

3. final vs. finally vs. finalize

4. synchronized(a){

       synchronized(b){

}

    }

    any problems?

5. way to avoid GC

6. way to avoid dead lock

7. Collection<?> vs. Collection<Object>

8. Design pattern in java library? pattern in java IO ?

 

分享到:
评论
4 楼 standalone 2010-11-18  
Design patterns are used and supported extensively throughout the Java APIs. Here are some examples:
The Model-View-Controller design pattern is used extensively throughout the Swing API.
The getInstance() method in java.util.Calendar is an example of a simple form of the Factory Method design pattern.
The classes java.lang.System and java.sql.DriverManager are examples of the Singleton pattern, although they are not implemented using the approach recommended in the GoF book but with static methods.
The Prototype pattern is supported in Java through the clone() method defined in class Object and the use of java.lang.Cloneable interface to grant permission for cloning.
The Java Swing classes support the Command pattern by providing an Action interface and an AbstractAction class.
The Java 1.1 event model is based on the observer pattern. In addition, the interface java.util.Observable and the class java.util.Observer provide support for this pattern.
The Adapter pattern is used extensively by the adapter classes in java.awt.event.
The Proxy pattern is used extensively in the implementation of Java's Remote Method Invocation (RMI) and Interface Definition Language (IDL) features.
The structure of Component and Container classes in java.awt provide a good example of the Composite pattern.
The Bridge pattern can be found in the separation of the components in java.awt (e.g., Button and List), and their counterparts in java.awt.peer.
Additional examples and details on the use of design patterns in the Java APIs can be found in the following references:
[Felleisen 1998] Matthias Felleisen and Daniel P. Friedman, A Little Java, a Few Patterns, MIT Press, 1998.
[Grand 1998] Mark Grand, Patterns in Java, Volume 1, John Wiley & Sons, 1998.
[Grand 1999] Mark Grand, Patterns in Java, Volume 2, John Wiley & Sons, 1999.
[Cooper 2000] James W. Cooper, Java Design Patterns: A Tutorial, Addison-Wesley, 2000.
3 楼 standalone 2010-11-16  
Consider the problem of writing a routine that prints out all the elements in a collection.
Here’s how you might write it in an older version of the language:
void printCollection(Collection c) {
Iterator i = c.iterator();
for (k = 0; k < c.size(); k++) {
System.out.println(i.next());
}}
And here is a naive attempt at writing it using generics (and the new for loop syntax):
void printCollection(Collection<Object> c) {
for (Object e : c) {
System.out.println(e);
}}
The problem is that this new version is much less useful than the old one. Whereas
the old code could be called with any kind of collection as a parameter, the new code
only takes Collection<Object>, which, as we’ve just demonstrated, is not a supertype
of all kinds of collections!
So what is the supertype of all kinds of collections? It’s written Collection<?>
(pronounced “collection of unknown”) , that is, a collection whose element type matches
anything. It’s called a wildcard type for obvious reasons. We can write:
void printCollection(Collection<?> c) {
for (Object e : c) {
System.out.println(e);
}}
and now, we can call it with any type of collection. Notice that inside printCollection(),
we can still read elements from c and give them type Object. This is always
safe, since whatever the actual type of the collection, it does contain objects. It isn’t
safe to add arbitrary objects to it however:
Collection<?> c = new ArrayList<String>();
c.add(new Object()); // compile time error
Since we don’t know what the element type of c stands for, we cannot add objects
to it. The add() method takes arguments of type E, the element type of the collection.
When the actual type parameter is ?, it stands for some unknown type. Any parameter
we pass to add would have to be a subtype of this unknown type. Since we don’t know
what type that is, we cannot pass anything in. The sole exception is null, which is a
member of every type.
On the other hand, given a List<?>, we can call get() and make use of the result.
The result type is an unknown type, but we always know that it is an object. It is
5
therefore safe to assign the result of get() to a variable of type Object or pass it as a
parameter where the type Object is expected.
2 楼 standalone 2010-11-16  
explanation to java StringBuilder

Java中的StringBuilder类功能详解
http://developer.51cto.com/art/200906/132698.htm
1 楼 standalone 2010-11-16  
Error: Any departure from the expected behavior of the system or program which stops the working of the system is an error. In general error is which nobody can control or guess when it occurs.

Exception: Any error or problem which one can handle and continue to work normally. Exception can be guessed and can be handled.

In Java Exception and Error are sub class of Throwable. It is differentiated based on the program control. Error such as OutOfMemoryError which no programmer can guess and can handle it. It depends on dynamically based on architectire OS and server configuration. Where as Exception programmer can handle it and can avoid application's misbehavior. For example if your code is looking for a file which is not available then IOException is thrown.Such instances programmer can guess and can handle it.

Note that in Java a compile time error is normally called an "error " while a runtime error is called an "exception."

相关推荐

    neusoft-java-question.rar_Neusoft_java question_东软_面试

    【标题】"Neusoft Java Question"涉及到的是东软公司在面试过程中经常出现的Java相关问题。这表明面试者需要对Java编程语言有深入的理解和熟练的掌握,以便在面试中表现出色,成功获得心仪的工作岗位。 【描述】...

    面试中曾被问到的Java Question.pdf

    从给定的文件标题“面试中曾被问到的Java Question.pdf”以及描述“中软 JAVA 培训 资料 pdf 华为 面试题”,我们可以推断出这份文档是关于Java编程语言面试问题的集合,特别强调了在华为等知名IT企业面试中的常见...

    QuestionOne.java

    QuestionOne.java

    java interview question

    ### Java高效性原因 Java语言之所以被认为是高效的编程语言,原因之一是它在设计时充分考虑了跨平台兼容性,它通过Java虚拟机(JVM)实现了一次编写,到处运行的特性。当Java程序编译成字节码(.class文件)后,便...

    Thinking+In+Java.chm

    it's also the first book I turn to whenever I have a Java question." -Jim Pleger, Loudoun County (Virginia) Government"Much better than any other Java book I've seen. Make that 'by an order of ...

    Java面试考试题打包

    这两个文件"大公司的Java面试题集.pdf"和"面试中曾被问到的Java Question.pdf"很可能是整理了实际面试中常出现的问题,旨在帮助求职者或开发者更好地准备Java面试。以下是基于这些标签和文件名可能涉及的一些关键...

    大公司java面试资料

    通过阅读“java华为面试题.pdf”、“大公司的Java面试题集.pdf”、“中软公司--JAVA培训资料.pdf”以及“面试中曾被问到的Java Question.pdf”,你可以系统地复习和巩固这些知识点,从而为面试做好充分准备。...

    JavaQuestion.rar

    JavaQuestion.rar 文件是一个压缩包,包含了与2019年NIIT(National Institute of Information Technology)JAVA考试相关的复习材料。NIIT是知名的IT培训机构,其考试通常涵盖广泛的Java编程概念和技术,旨在测试...

    Java练习题Question10.txt

    Java练习题Question10.txtJava练习题Question10.txtJava练习题Question10.txtJava练习题Question10.txtJava练习题Question10.txtJava练习题Question10.txtJava练习题Question10.txtJava练习题Question10.txtJava练习...

    Java练习题Question2.txt

    Java练习题Question2.txtJava练习题Question2.txtJava练习题Question2.txtJava练习题Question2.txtJava练习题Question2.txtJava练习题Question2.txtJava练习题Question2.txtJava练习题Question2.txtJava练习题...

    Java练习题Question3.txt

    Java练习题Question3.txtJava练习题Question3.txtJava练习题Question3.txtJava练习题Question3.txtJava练习题Question3.txtJava练习题Question3.txtJava练习题Question3.txtJava练习题Question3.txtJava练习题...

    Java练习题Question8.txt

    Java练习题Question8.txtJava练习题Question8.txtJava练习题Question8.txtJava练习题Question8.txtJava练习题Question8.txtJava练习题Question8.txtJava练习题Question8.txtJava练习题Question8.txtJava练习题...

    Java练习题Question7.txt

    Java练习题Question7.txtJava练习题Question7.txtJava练习题Question7.txtJava练习题Question7.txtJava练习题Question7.txtJava练习题Question7.txtJava练习题Question7.txtJava练习题Question7.txtJava练习题...

    Java练习题Question6.txt

    Java练习题Question6.txtJava练习题Question6.txtJava练习题Question6.txtJava练习题Question6.txtJava练习题Question6.txtJava练习题Question6.txtJava练习题Question6.txtJava练习题Question6.txtJava练习题...

    Java练习题Question5.txt

    Java练习题Question5.txtJava练习题Question5.txtJava练习题Question5.txtJava练习题Question5.txtJava练习题Question5.txtJava练习题Question5.txtJava练习题Question5.txtJava练习题Question5.txtJava练习题...

    Java练习题Question4.txt

    Java练习题Question4.txtJava练习题Question4.txtJava练习题Question4.txtJava练习题Question4.txtJava练习题Question4.txtJava练习题Question4.txtJava练习题Question4.txtJava练习题Question4.txtJava练习题...

    Java练习题Question9.txt

    Java练习题Question9.txtJava练习题Question9.txtJava练习题Question9.txtJava练习题Question9.txtJava练习题Question9.txtJava练习题Question9.txtJava练习题Question9.txtJava练习题Question9.txtJava练习题...

    Java练习题Question1.txt

    Java练习题Question1.txtJava练习题Question1.txtJava练习题Question1.txtJava练习题Question1.txtJava练习题Question1.txtJava练习题Question1.txtJava练习题Question1.txtJava练习题Question1.txtJava练习题...

    【java面试题】100IT名企java面试必考面试题 Java Interview Question

    (Java Interview Question 100 IT Enterprise Java Compulsory Interview Question) 【java面试题】100IT名企java面试必考面试题 (Java Interview Question 100 IT Enterprise Java Compulsory Interview Question)

    5-java-QA.rar_Quick

    Java QA 快速指南 Java是一种广泛使用的面向对象的编程语言,以其跨平台、高性能、稳定性和丰富的类库而闻名...这份"Java Question and answers (quick version)"PDF文档将帮助你迅速定位和解答Java开发中遇到的问题。

Global site tag (gtag.js) - Google Analytics