The Java Tutorials have been written for JDK 8.Java教程是为JDK 8编写的。Examples and practices described in this page don't take advantage of improvements introduced in later releases and might use technology no longer available.本页中描述的示例和实践没有利用后续版本中引入的改进,并且可能使用不再可用的技术。See Java Language Changes for a summary of updated language features in Java SE 9 and subsequent releases.有关Java SE 9及其后续版本中更新的语言特性的摘要,请参阅Java语言更改。
See JDK Release Notes for information about new features, enhancements, and removed or deprecated options for all JDK releases.有关所有JDK版本的新功能、增强功能以及已删除或不推荐的选项的信息,请参阅JDK发行说明。
The program 程序Problem.java
doesn't compile.Problem.java
无法编译。What do you need to do to make it compile? Why?您需要做什么才能使其编译?为什么?
Use the Java API documentation for the Box
class (in the javax.swing
package) to help you answer the following questions.
What static nested class does Box
define?
What inner class does Box
define?
What is the superclass of Box
's inner class?
Which of Box
's nested classes can you use from any class?
How do you create an instance of Box
's Filler
class?
Get the file Class1.java
. Compile and run Class1
. What is the output?
The following exercises involve modifying the class DataStructure.java
, which the section Inner Class Example discusses.
Define a method named print(DataStructureIterator iterator)
. Invoke this method with an instance of the class EvenIterator
so that it performs the same function as the method printEven
.
Invoke the method print(DataStructureIterator iterator)
so that it prints elements that have an odd index value. Use an anonymous class as the method's argument instead of an instance of the interface DataStructureIterator
.
Define a method named print(java.util.function.Function<Integer, Boolean> iterator)
that performs the same function as print(DataStructureIterator iterator)
. Invoke this method with a lambda expression to print elements that have an even index value. Invoke this method again with a lambda expression to print elements that have an odd index value.
Define two methods so that the following two statements print elements that have an even index value and elements that have an odd index value:
DataStructure ds = new DataStructure() // ... ds.print(DataStructure::isEvenIndex); ds.print(DataStructure::isOddIndex);