Java Reference
In-Depth Information
System.out.println("Caution!");
break;
case "green":
System.out.println("Go (placidly among the haste)");
break;
default:
handleError("Invalid input: " + input);
break;
}
Obviously the strings have to be compile-time constants, either string literals or strings
marked final . In fact, in real code, you would probably want to define final String vari-
ables for the cases. This should lead you to wonder why you're not using a Java 5 Enum (see
Java 5 enums ) . The String Switch has a place where long strings are in use, but it needs care
for issues like case sensitivity (convert to lowercase first, see Problem ) .
Java 7 API Changes
Released in July of 2011, Java 7 includes considerable support for concurrency, including the
new fork/join framework (see Optimizing Parallel Processing with Fork/Join ) .
Large parts of the standard API including I/O and JDBC were updated to implement
AutoCloseable for use in try-with-resource. Closeable now extends AutoCloseable :
public
public interface
interface java
java . lang . AutoCloseable {
public
public abstract
abstract void
void close () throws
throws java . lang . Exception ;
}
public
public interface
interface java
java . io . Closeable extends
extends java . lang . AutoCloseable {
public
public abstract
abstract void
void close () throws
throws java . io . IOException ;
}
URLClassLoader implements Closeable , and gains a close() method, which allows for
updating of external JAR files being classloaded (on MS Windows, files can't be overwritten
while open). This is aimed at, and very useful for, development of web apps.
NIO2—new Filesystem API—includes more filesystem support and operators, and a new
java.io.Path class intended to replace most uses of java.io.File (see Using Path instead
of File ) .
Search WWH ::




Custom Search