Java 17 Recipes


Download 3.2 Mb.
Pdf ko'rish
bet30/245
Sana02.06.2024
Hajmi3.2 Mb.
#1839910
1   ...   26   27   28   29   30   31   32   33   ...   245
Bog'liq
Java 17 Recipes

 Executing the Tool
The JavaDoc tool can be run against entire packages or sources. Simply pass a package 
name to the JavaDoc tool rather than individual source file names. For instance, if an 
application includes a package named org.luciano.beans, all source files within that 
package can be documented by running the tool, as follows.
javadoc org.luciano.beans
By default, the JavaDoc tool generates HTML and places it into the same package 
as documented code. That result can become a cluttered nightmare if you like to have 
source files separate from the documentation. Instead, you can set up a destination for 
the generated documentation by passing the –d flag to the JavaDoc tool.
ChApteR 1 GettInG StARted wIth JAvA 17


45
1-13. Reading Environment Variables
 Problem
The application you are developing needs to make use of some environment variables. 
You want to read the values that have been set from the operating-system level.
 Solution
Use the Java System class to retrieve any environment variable values. The System 
class has a method called getenv() that accepts a String argument corresponding to 
the name of a system environment variable. The method then returns the value of the 
given variable. If no matching environment variable exists, a NULL value is returned.
Listing 
1-11
is an example. The ReadOneEnvVariable class accepts an environment 
variable name as a parameter and displays the variable’s value that has been set at the 
operating- system level.
Listing 1-11. Reading an Environment Variable’s Value
package org.java17recipes.chapter1.recipe1_13;
public class ReadOneEnvVariable {
public static void main(String[] args) {
if (args.length > 0) {
String value = System.getenv(args[0]);
if (value != null) {
System.out.println(args[0].toUpperCase() + " = " + value);
} else {
System.out.println("No such environment variable exists");
}
} else {
System.out.println("No arguments passed");
}
}
}
ChApteR 1 GettInG StARted wIth JAvA 17


46
If you are interested in retrieving the entire list of environment variables defined 
on a system, do not pass any arguments to the System.getenv() method. You receive 
an object of type Map having all the values. You can iterate through them, as shown in 
Listing 
1-12
.

Download 3.2 Mb.

Do'stlaringiz bilan baham:
1   ...   26   27   28   29   30   31   32   33   ...   245




Ma'lumotlar bazasi mualliflik huquqi bilan himoyalangan ©fayllar.org 2024
ma'muriyatiga murojaat qiling