- 浏览: 611027 次
- 性别:
- 来自: 上海
文章分类
最新评论
-
月光杯:
问题解决了吗?
Exceptions in HDFS -
iostreamin:
神,好厉害,这是我找到的唯一可以ac的Java代码,厉害。
[leetcode] word ladder II -
standalone:
One answer I agree with:引用Whene ...
How many string objects are created? -
DiaoCow:
不错!,一开始对这些确实容易犯迷糊
erlang中的冒号 分号 和 句号 -
standalone:
Exception in thread "main& ...
one java interview question
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.
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.
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
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."
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."
发表评论
-
ssl 与 java 实例
2014-01-27 10:10 844http://www.iteye.com/topic/1125 ... -
Java NIO
2014-01-10 21:28 744看了这个java nio的教程,明白了什么是Selector. ... -
再谈Java的wait(), sleep(), notify()和notifyAll()
2013-07-25 10:59 1943一段时间不用java,这些概念就全混淆了,有必要彻底澄清一下, ... -
Why singleton is anti-pattern?
2013-07-03 10:12 912OO Test Other reasons? -
How to generate the serialVersionUID when you implement Serializable interface,j
2013-07-01 10:52 987http://docs.oracle.com/javase/6 ... -
Java Override的两个问题
2013-06-01 11:40 9851: 如果子类中的方法的参数是父类的方法的子类型,那么算不算o ... -
Java常用类API统计
2013-06-01 11:35 0String charAt(int) compareTo( ... -
How many string objects are created?
2013-06-01 10:18 1356This is a very common java inte ... -
使用Java的DelayQueue容易碰到的一个坑
2013-05-27 17:32 6784今天不忙,学习一下java.util.concurrent.D ... -
[leetcode] Balanced Binary Tree
2013-04-28 14:08 1615Check if a binary tree is balan ... -
[leetcode] find median of two sorted arrays
2013-04-26 10:55 1501http://leetcode.com/onlinejudge ... -
[leetcode] word ladder
2013-04-25 15:05 2307Q: Given two words (start and ... -
[leetcode] word ladder II
2013-04-15 07:35 12088http://leetcode.com/onlinejudge ... -
[leetcode] Count and Say
2013-04-12 14:05 2279http://leetcode.com/onlinejudge ... -
Date/Time处理函数总结 [To Do]
2013-04-12 10:46 706几种我所用到的用来处理日期,时间的函数总结。 Perl 1 ... -
[leetcode] Palindrome Partition
2013-04-12 10:25 1344http://leetcode.com/onlinejudge ... -
[leetcode] Palindrome Partitioning II
2013-04-11 16:45 1549http://leetcode.com/onlinejudge ... -
Profiling your Java code using Spring
2013-03-05 15:02 729Quite good article!!! http://w ... -
Java的Generics的几点限制
2012-12-28 15:00 4796参见 http://docs.oracle.com/ ... -
Overriding Method Using Parameter That is a Subclass?
2012-12-27 22:14 929参见 http://www.coderanch.com/t/3 ...
相关推荐
【标题】"Neusoft Java Question"涉及到的是东软公司在面试过程中经常出现的Java相关问题。这表明面试者需要对Java编程语言有深入的理解和熟练的掌握,以便在面试中表现出色,成功获得心仪的工作岗位。 【描述】...
从给定的文件标题“面试中曾被问到的Java Question.pdf”以及描述“中软 JAVA 培训 资料 pdf 华为 面试题”,我们可以推断出这份文档是关于Java编程语言面试问题的集合,特别强调了在华为等知名IT企业面试中的常见...
QuestionOne.java
### Java高效性原因 Java语言之所以被认为是高效的编程语言,原因之一是它在设计时充分考虑了跨平台兼容性,它通过Java虚拟机(JVM)实现了一次编写,到处运行的特性。当Java程序编译成字节码(.class文件)后,便...
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面试题集.pdf"和"面试中曾被问到的Java Question.pdf"很可能是整理了实际面试中常出现的问题,旨在帮助求职者或开发者更好地准备Java面试。以下是基于这些标签和文件名可能涉及的一些关键...
通过阅读“java华为面试题.pdf”、“大公司的Java面试题集.pdf”、“中软公司--JAVA培训资料.pdf”以及“面试中曾被问到的Java Question.pdf”,你可以系统地复习和巩固这些知识点,从而为面试做好充分准备。...
JavaQuestion.rar 文件是一个压缩包,包含了与2019年NIIT(National Institute of Information Technology)JAVA考试相关的复习材料。NIIT是知名的IT培训机构,其考试通常涵盖广泛的Java编程概念和技术,旨在测试...
Java练习题Question10.txtJava练习题Question10.txtJava练习题Question10.txtJava练习题Question10.txtJava练习题Question10.txtJava练习题Question10.txtJava练习题Question10.txtJava练习题Question10.txtJava练习...
Java练习题Question2.txtJava练习题Question2.txtJava练习题Question2.txtJava练习题Question2.txtJava练习题Question2.txtJava练习题Question2.txtJava练习题Question2.txtJava练习题Question2.txtJava练习题...
Java练习题Question3.txtJava练习题Question3.txtJava练习题Question3.txtJava练习题Question3.txtJava练习题Question3.txtJava练习题Question3.txtJava练习题Question3.txtJava练习题Question3.txtJava练习题...
Java练习题Question8.txtJava练习题Question8.txtJava练习题Question8.txtJava练习题Question8.txtJava练习题Question8.txtJava练习题Question8.txtJava练习题Question8.txtJava练习题Question8.txtJava练习题...
Java练习题Question7.txtJava练习题Question7.txtJava练习题Question7.txtJava练习题Question7.txtJava练习题Question7.txtJava练习题Question7.txtJava练习题Question7.txtJava练习题Question7.txtJava练习题...
Java练习题Question6.txtJava练习题Question6.txtJava练习题Question6.txtJava练习题Question6.txtJava练习题Question6.txtJava练习题Question6.txtJava练习题Question6.txtJava练习题Question6.txtJava练习题...
Java练习题Question5.txtJava练习题Question5.txtJava练习题Question5.txtJava练习题Question5.txtJava练习题Question5.txtJava练习题Question5.txtJava练习题Question5.txtJava练习题Question5.txtJava练习题...
Java练习题Question4.txtJava练习题Question4.txtJava练习题Question4.txtJava练习题Question4.txtJava练习题Question4.txtJava练习题Question4.txtJava练习题Question4.txtJava练习题Question4.txtJava练习题...
Java练习题Question9.txtJava练习题Question9.txtJava练习题Question9.txtJava练习题Question9.txtJava练习题Question9.txtJava练习题Question9.txtJava练习题Question9.txtJava练习题Question9.txtJava练习题...
Java练习题Question1.txtJava练习题Question1.txtJava练习题Question1.txtJava练习题Question1.txtJava练习题Question1.txtJava练习题Question1.txtJava练习题Question1.txtJava练习题Question1.txtJava练习题...
(Java Interview Question 100 IT Enterprise Java Compulsory Interview Question) 【java面试题】100IT名企java面试必考面试题 (Java Interview Question 100 IT Enterprise Java Compulsory Interview Question)
Java QA 快速指南 Java是一种广泛使用的面向对象的编程语言,以其跨平台、高性能、稳定性和丰富的类库而闻名...这份"Java Question and answers (quick version)"PDF文档将帮助你迅速定位和解答Java开发中遇到的问题。