Starting from:
$30

$24

Practice 3 Solution

In this practice, we'll be using Java's I/O utilities to explore the source code and byte code of Java core APIs.

Java Source Code

The src.zip in your $JAVA_HOME ( $JAVA_HOME refers to JDK installation directory) contains the Java programming language source files for all classes that make up the Java Core API (that is, sources files for the java.* , javax.* and some org.* packages, ). This source code is provided for informational purposes only, to help developers learn and use the Java programming language.

We provided the src.zip in JDK 1.8.0. Please write a program to:

Read the src.zip file.


Count and print all the .java source files in the java.io and java.nio directories.

Sample output:





















Java Byte Code

The rt.jar file in your $JAVA_HOME/jre/lib contains all of the compiled class files for Java Core API. JRE provides rt.jar as bootstrap classes to be loaded when JVM starts, so that you could use core APIs such as java.lang.String , java.util.ArrayList and java.io.InputStream . A .jar file is essentially a zip file for .class files and you could use zip tools such as WinRAR to explore its content.

We provided the corresponding rt.jar in JDK 1.8.0. Please write a program to:

Read the rt.jar file.

Count and print all the .class bytecode files in the java.io and java.nio packages.


Sample output:

















Think

The src.zip and rt.jar we provided are from the same JDK installation. Does the count of .java source files in java.io and java.nio packages the same as the .class files in these two packages? If not, why? (We'll explore this question in the next lab practice.)

More products