The Java Tutorials have been written for 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.
SeeDev.java for updated tutorials taking advantage of the latest releases.
SeeJava Language Changes for a summary of updated language features in Java SE 9 and subsequent releases.
SeeJDK Release Notes for information about new features, enhancements, and removed or deprecated options for all JDK releases.
The programProblem.java
doesn't compile. What do you need to do to make it compile? Why?
Use the Java API documentation for theBox
class (in thejavax.swing
package) to help you answer the following questions.
What static nested class doesBox
define?
What inner class doesBox
define?
What is the superclass ofBox
's inner class?
Which ofBox
's nested classes can you use from any class?
How do you create an instance ofBox
'sFiller
class?
Get the fileClass1.java
. Compile and runClass1
. What is the output?
The following exercises involve modifying the classDataStructure.java
, which the sectionInner Class Example discusses.
Define a method namedprint(DataStructureIterator iterator)
. Invoke this method with an instance of the classEvenIterator
so that it performs the same function as the methodprintEven
.
Invoke the methodprint(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 interfaceDataStructureIterator
.
Define a method namedprint(java.util.function.Function<Integer, Boolean> iterator)
that performs the same function asprint(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);
About Oracle |Contact Us |Legal Notices |Terms of Use |Your Privacy Rights
Copyright © 1995, 2024 Oracle and/or its affiliates. All rights reserved.