Читать книгу OCP Oracle Certified Professional Java SE 17 Developer Study Guide - Jeanne Boyarsky - Страница 80
Compiling with Wildcards
ОглавлениеYou can use an asterisk to specify that you'd like to include all Java files in a directory. This is convenient when you have a lot of files in a package. We can rewrite the previous javac
command like this:
javac packagea/*.java packageb/*.java
However, you cannot use a wildcard to include subdirectories. If you were to write javac *.java
, the code in the packages would not be picked up.
Now that your code has compiled, you can run it by typing the following command:
java packageb.ClassB
If it works, you'll see Got it
printed. You might have noticed that we typed ClassB
rather than ClassB.class
. As discussed earlier, you don't pass the extension when running a program.
Figure 1.1 shows where the .class
files were created in the directory structure.
FIGURE 1.1 Compiling with packages