< prev index next >

src/jdk.compiler/share/man/javac.1

Print this page


   1 .\" Copyright (c) 1994, 2019, Oracle and/or its affiliates. All rights reserved.

   2 .\" DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
   3 .\"
   4 .\" This code is free software; you can redistribute it and/or modify it
   5 .\" under the terms of the GNU General Public License version 2 only, as
   6 .\" published by the Free Software Foundation.
   7 .\"
   8 .\" This code is distributed in the hope that it will be useful, but WITHOUT
   9 .\" ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
  10 .\" FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
  11 .\" version 2 for more details (a copy is included in the LICENSE file that
  12 .\" accompanied this code).
  13 .\"
  14 .\" You should have received a copy of the GNU General Public License version
  15 .\" 2 along with this work; if not, write to the Free Software Foundation,
  16 .\" Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
  17 .\"
  18 .\" Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
  19 .\" or visit www.oracle.com if you need additional information or have any
  20 .\" questions.
  21 .\"
  22 .\" Automatically generated by Pandoc 2.3.1




  23 .\"
  24 .TH "JAVAC" "1" "2018" "JDK 13" "JDK Commands"
  25 .hy
  26 .SH NAME
  27 .PP
  28 javac \- read Java class and interface definitions and compile them into
  29 bytecode and class files
  30 .SH SYNOPSIS
  31 .PP
  32 \f[CB]javac\f[R] [\f[I]options\f[R]] [\f[I]sourcefiles\f[R]]
  33 .TP
  34 .B \f[I]options\f[R]
  35 Command\-line options.
  36 See \f[B]Overview of javac Options\f[R].
  37 .RS
  38 .RE
  39 .TP
  40 .B \f[I]sourcefiles\f[R]
  41 One or more source files to be compiled (such as \f[CB]MyClass.java\f[R])
  42 or processed for annotations (such as \f[CB]MyPackage.MyClass\f[R]).
  43 .RS
  44 .RE
  45 .SH DESCRIPTION
  46 .PP
  47 The \f[CB]javac\f[R] command reads class and interface definitions,
  48 written in the Java programming language, and compiles them into
  49 bytecode class files.
  50 The \f[CB]javac\f[R] command can also process annotations in Java source
  51 files and classes.
  52 .PP
  53 A new launcher environment variable, \f[CB]JDK_JAVAC_OPTIONS\f[R], was
  54 introduced in JDK 9 that prepended its content to the command line to
  55 \f[CB]javac\f[R] .
  56 See \f[B]Using JDK_JAVAC_OPTIONS Environment Variable\f[R].
  57 .PP
  58 There are two ways to pass source code file names to \f[CB]javac\f[R].
  59 .IP \[bu] 2
  60 For a small number of source files, you can list the file names on the
  61 command line.
  62 .IP \[bu] 2
  63 For a large number of source files, you can use the
  64 \f[CB]\@\f[R]\f[I]filename\f[R] option on the \f[CB]javac\f[R] command line
  65 to include a file that lists the source file names.
  66 See \f[B]Standard Options\f[R] for a description of the option and
  67 \f[B]javac Command\-Line Argument Files\f[R] for a description of
  68 \f[CB]javac\f[R] argument files.
  69 .PP
  70 Source code file names must have \f[CB]\&.java\f[R] suffixes, class file
  71 names must have \f[CB]\&.class\f[R] suffixes, and both source and class
  72 files must have root names that identify the class.
  73 For example, a class called \f[CB]MyClass\f[R] would be written in a
  74 source file called \f[CB]MyClass.java\f[R] and compiled into a bytecode
  75 class file called \f[CB]MyClass.class\f[R].
  76 .PP
  77 Inner class definitions produce additional class files.
  78 These class files have names that combine the inner and outer class
  79 names, such as \f[CB]MyClass$MyInnerClass.class\f[R].
  80 .PP
  81 You should arrange the source files in a directory tree that reflects
  82 their package tree.
  83 For example:
  84 .IP \[bu] 2
  85 \f[B]Oracle Solaris, Linux, and OS X:\f[R] If all of your source files
  86 are in \f[CB]/workspace\f[R], then put the source code for
  87 \f[CB]com.mysoft.mypack.MyClass\f[R] in
  88 \f[CB]/workspace/com/mysoft/mypack/MyClass.java\f[R].
  89 .IP \[bu] 2
  90 \f[B]Windows:\f[R] If all of your source files are in
  91 \f[CB]\\workspace\f[R], then put the source code for
  92 \f[CB]com.mysoft.mypack.MyClass\f[R] in
  93 \f[CB]\\workspace\\com\\mysoft\\mypack\\MyClass.java\f[R].
  94 .PP
  95 By default, the compiler puts each class file in the same directory as
  96 its source file.
  97 You can specify a separate destination directory with the \f[CB]\-d\f[R]
  98 option described in \f[B]Standard Options\f[R].
  99 .SH PROGRAMMATIC INTERFACE
 100 .PP
 101 The \f[CB]javac\f[R] command supports the new Java Compiler API defined by
 102 the classes and interfaces in the \f[CB]javax.tools\f[R] package.
 103 .SH IMPLICITLY LOADED SOURCE FILES
 104 .PP
 105 To compile a set of source files, the compiler might need to implicitly
 106 load additional source files.
 107 See \f[B]Searching for Types\f[R].
 108 Such files are currently not subject to annotation processing.
 109 By default, the compiler gives a warning when annotation processing
 110 occurs and any implicitly loaded source files are compiled.
 111 The \f[CB]\-implicit\f[R] option provides a way to suppress the warning.
 112 .SH USING JDK_JAVAC_OPTIONS ENVIRONMENT VARIABLE
 113 .PP
 114 The content of the \f[CB]JDK_JAVAC_OPTIONS\f[R] environment variable,
 115 separated by white\-spaces ( ) or white\-space characters (\f[CB]\\n\f[R],
 116 \f[CB]\\t\f[R], \f[CB]\\r\f[R], or \f[CB]\\f\f[R]) is prepended to the command
 117 line arguments passed to \f[CB]javac\f[R] as a list of arguments.
 118 .PP
 119 The encoding requirement for the environment variable is the same as the
 120 \f[CB]javac\f[R] command line on the system.
 121 \f[CB]JDK_JAVAC_OPTIONS\f[R] environment variable content is treated in
 122 the same manner as that specified in the command line.
 123 .PP
 124 Single quotes (\f[CB]\[aq]\f[R]) or double quotes (\f[CB]"\f[R]) can be used
 125 to enclose arguments that\ contain whitespace characters.
 126 All content between the open quote and the first matching close quote
 127 are preserved by simply removing the pair of quotes.
 128 In case a matching quote is not found, the launcher will abort with an
 129 error message.
 130 \f[CB]\@\f[R]\f[I]files\f[R] are supported as they are specified in the
 131 command line.
 132 However, as in \f[CB]\@\f[R]\f[I]files\f[R], use of a wildcard is not
 133 supported.
 134 .PP
 135 \f[B]Examples of quoting arguments containing white spaces:\f[R]
 136 .RS
 137 .PP
 138 \f[CB]export\ JDK_JAVAC_OPTIONS=\[aq]\@"C:\\white\ spaces\\argfile"\[aq]\f[R]
 139 .RE
 140 .RS
 141 .PP
 142 \f[CB]export\ JDK_JAVAC_OPTIONS=\[aq]"\@C:\\white\ spaces\\argfile"\[aq]\f[R]
 143 .RE
 144 .RS
 145 .PP
 146 \f[CB]export\ JDK_JAVAC_OPTIONS=\[aq]\@C:\\"white\ spaces"\\argfile\[aq]\f[R]
 147 .RE
 148 .SH OVERVIEW OF JAVAC OPTIONS
 149 .PP
 150 The compiler has sets of standard options, and cross\-compilation
 151 options that are supported on the current development environment.
 152 The compiler also has a set of nonstandard options that are specific to
 153 the current virtual machine and compiler implementations but are subject
 154 to change in the future.
 155 The nonstandard options begin with \f[CB]\-X\f[R] .
 156 The different sets of \f[CB]javac\f[R] options are described in the
 157 following sections:
 158 .IP \[bu] 2
 159 \f[B]Standard Options\f[R]
 160 .IP \[bu] 2
 161 \f[B]Cross\-Compilation Options for javac\f[R]
 162 .IP \[bu] 2
 163 \f[B]Extra Options\f[R]
 164 .SH STANDARD OPTIONS
 165 .TP
 166 .B \f[CB]\@\f[R]\f[I]filename\f[R]
 167 Reads options and file names from a file.
 168 To shorten or simplify the \f[CB]javac\f[R] command, you can specify one
 169 or more files that contain arguments to the \f[CB]javac\f[R] command
 170 (except \f[CB]\-J\f[R] options).
 171 This lets you to create \f[CB]javac\f[R] commands of any length on any
 172 operating system.
 173 See \f[B]javac Command\-Line Argument Files\f[R].
 174 .RS
 175 .RE
 176 .TP
 177 .B \f[CB]\-A\f[R]\f[I]key\f[R][\f[CB]=\f[R]\f[I]value\f[R]]
 178 Specifies options to pass to annotation processors.
 179 These options aren\[aq]t interpreted by \f[CB]javac\f[R] directly, but are
 180 made available for use by individual processors.
 181 The \f[I]key\f[R] value should be one or more identifiers separated by a
 182 dot (\f[CB]\&.\f[R]).
 183 .RS
 184 .RE
 185 .TP
 186 .B \f[CB]\-\-add\-modules\f[R] \f[I]module\f[R]\f[CB],\f[R]\f[I]module\f[R]
 187 Specifies root modules to resolve in addition to the initial modules, or
 188 all modules on the module path if \f[I]module\f[R] is
 189 \f[CB]ALL\-MODULE\-PATH.\f[R]
 190 .RS
 191 .RE
 192 .TP
 193 .B \f[CB]\-\-boot\-class\-path\f[R] \f[I]path\f[R] or \f[CB]\-bootclasspath\f[R] \f[I]path\f[R]
 194 Overrides the location of the bootstrap class files.
 195 .RS
 196 .PP
 197 \f[B]Note:\f[R]
 198 .PP
 199 This can only be used when compiling for versions prior to JDK 9.
 200 As applicable, see the descriptions in\ \f[CB]\-\-release\f[R],
 201 \f[CB]\-source\f[R], or \f[CB]\-target\f[R]\ for details.
 202 .RE
 203 .TP
 204 .B \f[CB]\-\-class\-path\f[R] \f[I]path\f[R], \f[CB]\-classpath\f[R] \f[I]path\f[R], or \f[CB]\-cp\f[R] \f[I]path\f[R]
 205 Specifies where to find user class files and annotation processors.
 206 This class path overrides the user class path in the \f[CB]CLASSPATH\f[R]
 207 environment variable.
 208 .RS
 209 .IP \[bu] 2
 210 If \f[CB]\-\-class\-path\f[R], \f[CB]\-classpath\f[R], or \f[CB]\-cp\f[R]
 211 aren\[aq]t specified, then the user class path is the current directory.
 212 .IP \[bu] 2
 213 If the \f[CB]\-sourcepath\f[R] option isn\[aq]t specified, then the user
 214 class path is also searched for source files.
 215 .IP \[bu] 2
 216 If the \f[CB]\-processorpath\f[R] option isn\[aq]t specified, then the
 217 class path is also searched for annotation processors.
 218 .RE
 219 .TP
 220 .B \f[CB]\-d\f[R] \f[I]directory\f[R]
 221 Sets the destination directory for class files.
 222 If a class is part of a package, then \f[CB]javac\f[R] puts the class file
 223 in a subdirectory that reflects the package name and creates directories
 224 as needed.
 225 For example:
 226 .RS
 227 .IP \[bu] 2
 228 \f[B]Oracle Solaris, Linux, and OS X:\f[R] If you specify
 229 \f[CB]\-d\ /home/myclasses\f[R] and the class is called
 230 \f[CB]com.mypackage.MyClass\f[R], then the class file is
 231 \f[CB]/home/myclasses/com/mypackage/MyClass.class\f[R].
 232 .IP \[bu] 2
 233 \f[B]Windows:\f[R] If you specify \f[CB]\-d\ C:\\myclasses\f[R] and the
 234 class is called \f[CB]com.mypackage.MyClass\f[R], then the class file is
 235 \f[CB]C:\\myclasses\\com\\mypackage\\MyClass.class\f[R].
 236 .PP
 237 If the \f[CB]\-d\f[R] option isn\[aq]t specified, then \f[CB]javac\f[R] puts
 238 each class file in the same directory as the source file from which it
 239 was generated.
 240 .PP
 241 \f[B]Note:\f[R]
 242 .PP
 243 The directory specified by the \f[CB]\-d\f[R] option isn\[aq]t
 244 automatically added to your user class path.
 245 .RE
 246 .TP
 247 .B \f[CB]\-deprecation\f[R]
 248 Shows a description of each use or override of a deprecated member or
 249 class.
 250 Without the \f[CB]\-deprecation\f[R] option, \f[CB]javac\f[R] shows a
 251 summary of the source files that use or override deprecated members or
 252 classes.
 253 The \f[CB]\-deprecation\f[R] option is shorthand for
 254 \f[CB]\-Xlint:deprecation\f[R].
 255 .RS
 256 .RE
 257 .TP
 258 .B \f[CB]\-\-enable\-preview\f[R]
 259 Enables preview language features.
 260 Used in conjunction with either \f[CB]\-source\f[R] or
 261 \f[CB]\-\-release\f[R].
 262 .RS
 263 .RE
 264 .TP
 265 .B \f[CB]\-encoding\f[R] \f[I]encoding\f[R]
 266 Specifies character encoding used by source files, such as EUC\-JP and
 267 UTF\-8.
 268 If the \f[CB]\-encoding\f[R] option isn\[aq]t specified, then the platform
 269 default converter is used.
 270 .RS
 271 .RE
 272 .TP
 273 .B \f[CB]\-endorseddirs\f[R] \f[I]directories\f[R]
 274 Overrides the location of the endorsed standards path.
 275 .RS
 276 .PP
 277 \f[B]Note:\f[R]
 278 .PP
 279 This can only be used when compiling for versions prior to JDK 9.
 280 As applicable, see the descriptions in\ \f[CB]\-\-release\f[R],
 281 \f[CB]\-source\f[R], or \f[CB]\-target\f[R]\ for details.
 282 .RE
 283 .TP
 284 .B \f[CB]\-extdirs\f[R] \f[I]directories\f[R]
 285 Overrides the location of the installed extensions.
 286 The \f[CB]directories\f[R] variable is a colon\-separated list of
 287 directories.
 288 Each JAR file in the specified directories is searched for class files.
 289 All JAR files found become part of the class path.
 290 .RS
 291 .PP
 292 If you are cross\-compiling, then this option specifies the directories
 293 that contain the extension classes.
 294 See \f[B]Cross\-Compilation Options for javac\f[R].
 295 .PP
 296 \f[B]Note:\f[R]
 297 .PP
 298 This can only be used when compiling for versions prior to JDK 9.
 299 As applicable, see the descriptions in\ \f[CB]\-\-release\f[R],
 300 \f[CB]\-source\f[R], or \f[CB]\-target\f[R]\ for details.
 301 .RE
 302 .TP
 303 .B \f[CB]\-g\f[R]
 304 Generates all debugging information, including local variables.
 305 By default, only line number and source file information is generated.
 306 .RS
 307 .RE
 308 .TP
 309 .B \f[CB]\-g:\f[R][\f[CB]lines\f[R], \f[CB]vars\f[R], \f[CB]source\f[R]]
 310 Generates only the kinds of debugging information specified by the
 311 comma\-separated list of keywords.
 312 Valid keywords are:
 313 .RS
 314 .TP
 315 .B \f[CB]lines\f[R]
 316 Line number debugging information.
 317 .RS
 318 .RE
 319 .TP
 320 .B \f[CB]vars\f[R]
 321 Local variable debugging information.
 322 .RS
 323 .RE
 324 .TP
 325 .B \f[CB]source\f[R]
 326 Source file debugging information.
 327 .RS
 328 .RE
 329 .RE
 330 .TP
 331 .B \f[CB]\-g:none\f[R]
 332 Doesn\[aq]t generate debugging information.
 333 .RS
 334 .RE
 335 .TP
 336 .B \f[CB]\-h\f[R] \f[I]directory\f[R]
 337 Specfies where to place generated native header files.
 338 .RS
 339 .PP
 340 When you specify this option, a native header file is generated for each
 341 class that contains native methods or that has one or more constants
 342 annotated with the \f[B]\f[BC]java.lang.annotation.Native\f[B]\f[R]
 343 [https://docs.oracle.com/javase/10/docs/api/java/lang/annotation/Native.html]
 344 annotation.
 345 If the class is part of a package, then the compiler puts the native
 346 header file in a subdirectory that reflects the package name and creates
 347 directories as needed.
 348 .RE
 349 .TP
 350 .B \f[CB]\-\-help\f[R], \f[CB]\-help\f[R] or \f[CB]\-?\f[R]
 351 Prints a synopsis of the standard options.
 352 .RS
 353 .RE
 354 .TP
 355 .B \f[CB]\-\-help\-extra\f[R] or \f[CB]\-X\f[R]
 356 Prints the help for extra options.
 357 .RS
 358 .RE
 359 .TP
 360 .B \f[CB]\-implicit:\f[R][\f[CB]none\f[R], \f[CB]class\f[R]]
 361 Specifies whether or not to generate class files for implicitly
 362 referenced files:
 363 .RS
 364 .IP \[bu] 2
 365 \f[CB]\-implicit:class\f[R] \-\-\- Automatically generates class files.
 366 .IP \[bu] 2
 367 \f[CB]\-implicit:none\f[R] \-\-\- Suppresses class file generation.
 368 .PP
 369 If this option isn\[aq]t specified, then the default automatically
 370 generates class files.
 371 In this case, the compiler issues a warning if any class files are
 372 generated when also doing annotation processing.
 373 The warning isn\[aq]t issued when the \f[CB]\-implicit\f[R] option is
 374 explicitly set.
 375 See \f[B]Searching for Types\f[R].
 376 .RE
 377 .TP
 378 .B \f[CB]\-J\f[R]\f[I]option\f[R]
 379 Passes \f[I]option\f[R] to the runtime system, where \f[I]option\f[R] is
 380 one of the Java options described on \f[B]java\f[R] command.
 381 For example, \f[CB]\-J\-Xms48m\f[R] sets the startup memory to 48 MB.
 382 .RS
 383 .PP
 384 \f[B]Note:\f[R]
 385 .PP
 386 The \f[CB]CLASSPATH\f[R] environment variable, \f[CB]\-classpath\f[R]
 387 option, \f[CB]\-bootclasspath\f[R] option, and \f[CB]\-extdirs\f[R] option
 388 don\[aq]t specify the classes used to run \f[CB]javac\f[R].
 389 Trying to customize the compiler implementation with these options and
 390 variables is risky and often doesn\[aq]t accomplish what you want.
 391 If you must customize the complier implementation, then use the
 392 \f[CB]\-J\f[R] option to pass options through to the underlying Java
 393 launcher.
 394 .RE
 395 .TP
 396 .B \f[CB]\-\-limit\-modules\f[R] \f[I]module\f[R]\f[CB],\f[R]\f[I]module\f[R]*
 397 Limits the universe of observable modules.
 398 .RS
 399 .RE
 400 .TP
 401 .B \f[CB]\-\-module\f[R] \f[I]module\-name\f[R] or \f[CB]\-m\f[R] \f[I]module\-name\f[R]
 402 Compiles only the specified module and checks time stamps.
 403 .RS
 404 .RE
 405 .TP
 406 .B \f[CB]\-\-module\-path\f[R] \f[I]path\f[R] or \f[CB]\-p\f[R] \f[I]path\f[R]
 407 Specifies where to find application modules.
 408 .RS
 409 .RE
 410 .TP
 411 .B \f[CB]\-\-module\-source\-path\f[R] \f[I]module\-source\-path\f[R]
 412 Specifies where to find input source files for multiple modules.
 413 .RS
 414 .RE
 415 .TP
 416 .B \f[CB]\-\-module\-version\f[R] \f[I]version\f[R]
 417 Specifies the version of modules that are being compiled.
 418 .RS
 419 .RE
 420 .TP
 421 .B \f[CB]\-nowarn\f[R]
 422 Disables warning messages.
 423 This option operates the same as the \f[CB]\-Xlint:none\f[R] option.
 424 .RS
 425 .RE
 426 .TP
 427 .B \f[CB]\-parameters\f[R]
 428 Generates metadata for reflection on method parameters.
 429 Stores formal parameter names of constructors and methods in the
 430 generated class file so that the method
 431 \f[CB]java.lang.reflect.Executable.getParameters\f[R] from the Reflection
 432 API can retrieve them.
 433 .RS
 434 .RE
 435 .TP
 436 .B \f[CB]\-proc:\f[R][\f[CB]none\f[R], \f[CB]only\f[R]]
 437 Controls whether annotation processing and compilation are done.
 438 \f[CB]\-proc:none\f[R] means that compilation takes place without
 439 annotation processing.
 440 \f[CB]\-proc:only\f[R] means that only annotation processing is done,
 441 without any subsequent compilation.
 442 .RS
 443 .RE
 444 .TP
 445 .B \f[CB]\-processor\f[R] \f[I]class1\f[R][\f[CB],\f[R]\f[I]class2\f[R]\f[CB],\f[R]\f[I]class3\f[R]...]
 446 Names of the annotation processors to run.
 447 This bypasses the default discovery process.
 448 .RS
 449 .RE
 450 .TP
 451 .B \f[CB]\-\-processor\-module\-path\f[R] \f[I]path\f[R]
 452 Specifies the module path used for finding annotation processors.
 453 .RS
 454 .RE
 455 .TP
 456 .B \f[CB]\-\-processor\-path\f[R] \f[I]path\f[R] or \f[CB]\-processorpath\f[R] \f[I]path\f[R]
 457 Specifies where to find annotation processors.
 458 If this option isn\[aq]t used, then the class path is searched for
 459 processors.
 460 .RS
 461 .RE
 462 .TP
 463 .B \f[CB]\-profile\f[R] \f[I]profile\f[R]
 464 Checks that the API used is available in the specified profile.
 465 .RS
 466 .PP
 467 \f[B]Note:\f[R]
 468 .PP
 469 This can only be used when compiling for versions prior to JDK 9.
 470 As applicable, see the descriptions in\ \f[CB]\-\-release\f[R],
 471 \f[CB]\-source\f[R], or \f[CB]\-target\f[R]\ for details.
 472 .RE
 473 .TP
 474 .B \f[CB]\-\-release\f[R] \f[I]release\f[R]
 475 Compiles source code according to the rules of the Java programming
 476 language for the specified Java SE release, generating class files
 477 suitable for that release.
 478 Additionally, compiles source code against the API of the specified Java
 479 SE release and the API supported by the corresponding JDK release.
 480 The supported values of \f[I]release\f[R] are the current Java SE release
 481 and a limited number of previous releases.
 482 The exact set of supported values is given in the command\-line help.
 483 .RS
 484 .PP
 485 The API of a Java SE release consists of the \f[CB]java.*\f[R],
 486 \f[CB]javax.*\f[R], and \f[CB]org.*\f[R] packages that are exported by Java
 487 SE modules in the release.
 488 .PP
 489 The API supported by a JDK release consists of the \f[CB]com.*\f[R] and
 490 \f[CB]jdk.*\f[R] packages that are exported by JDK modules in the release,
 491 plus the \f[CB]javax.*\f[R] packages that are exported by standard, but
 492 non\-Java SE, modules in the release.
 493 .PP
 494 \f[B]Note:\f[R]
 495 .PP
 496 The \f[CB]\-\-add\-exports\f[R] option cannot be used to enlarge the set
 497 of packages exported by the Java SE and JDK API.
 498 .RE
 499 .TP
 500 .B \f[CB]\-s\f[R] \f[I]directory\f[R]
 501 Specifies the directory used to place the generated source files.
 502 If a class is part of a package, then the compiler puts the source file
 503 in a subdirectory that reflects the package name and creates directories
 504 as needed.
 505 For example:
 506 .RS
 507 .IP \[bu] 2
 508 \f[B]Oracle Solaris, Linux, and OS X:\f[R] If you specify
 509 \f[CB]\-s\ /home/mysrc\f[R] and the class is called
 510 \f[CB]com.mypackage.MyClass\f[R], then the source file is put in
 511 \f[CB]/home/mysrc/com/mypackage/MyClass.java\f[R].
 512 .IP \[bu] 2
 513 \f[B]Windows:\f[R] If you specify \f[CB]\-s\ C:\\mysrc\f[R] and the class
 514 is called \f[CB]com.mypackage.MyClass\f[R], then the source file is put in
 515 \f[CB]C:\\mysrc\\com\\mypackage\\MyClass.java\f[R].
 516 .RE
 517 .TP
 518 .B \f[CB]\-\-source\f[R] \f[I]release\f[R] or \f[CB]\-source\f[R] \f[I]release\f[R]
 519 Compiles source code according to the rules of the Java programming
 520 language for the specified Java SE release.
 521 The supported values of \f[I]release\f[R] are the current Java SE release
 522 and a limited number of previous releases.
 523 The exact set of supported values is given in the command\-line help.
 524 .RS
 525 .PP
 526 If the option is not specified, the default is to compile source code
 527 according to the rules of the Java programming language for the current
 528 Java SE release.
 529 .RE
 530 .TP
 531 .B \f[CB]\-\-source\-path\f[R] \f[I]path\f[R] or \f[CB]\-sourcepath\f[R] \f[I]path\f[R]
 532 Specifies where to find input source files.
 533 This is the source code path used to search for class or interface
 534 definitions.
 535 As with the user class path, source path entries are separated by colons
 536 (\f[CB]:\f[R]) on Oracle Solaris and semicolons (\f[CB];\f[R]) on Windows.
 537 They can be directories, JAR archives, or ZIP archives.
 538 If packages are used, then the local path name within the directory or
 539 archive must reflect the package name.
 540 .RS
 541 .PP
 542 \f[B]Note:\f[R]
 543 .PP
 544 Classes found through the class path might be recompiled when their
 545 source files are also found.
 546 See \f[B]Searching for Types\f[R].
 547 .RE
 548 .TP
 549 .B \f[CB]\-\-system\f[R] \f[I]jdk\f[R] | \f[CB]none\f[R]
 550 Overrides the location of system modules.
 551 .RS
 552 .RE
 553 .TP
 554 .B \f[CB]\-\-target\f[R] \f[I]release\f[R] or \f[CB]\-target\f[R] \f[I]release\f[R]
 555 Generates \f[CB]class\f[R] files suitable for the specified Java SE
 556 release.
 557 The supported values of \f[I]release\f[R] are the current Java SE release
 558 and a limited number of previous releases.
 559 The exact set of supported values is given in the command\-line help.
 560 .RS
 561 .PP
 562 \f[B]Note:\f[R]
 563 .PP
 564 It is an error to specify a value for \f[I]release\f[R] that is lower
 565 than the the release for which the source code is being compiled.
 566 (See \f[CB]\-\-source\f[R]).
 567 .RE
 568 .TP
 569 .B \f[CB]\-\-upgrade\-module\-path\f[R] \f[I]path\f[R]
 570 Overrides the location of upgradeable modules.
 571 .RS
 572 .RE
 573 .TP
 574 .B \f[CB]\-verbose\f[R]
 575 Outputs messages about what the compiler is doing.
 576 Messages include information about each class loaded and each source
 577 file compiled.
 578 .RS
 579 .RE
 580 .TP
 581 .B \f[CB]\-\-version\f[R] or \f[CB]\-version\f[R]
 582 Prints version information.
 583 .RS
 584 .RE
 585 .TP
 586 .B \f[CB]\-Werror\f[R]
 587 Terminates compilation when warnings occur.
 588 .RS
 589 .RE
 590 .SH CROSS\-COMPILATION OPTIONS FOR JAVAC
 591 .PP
 592 By default, for releases prior to JDK 9, classes were compiled against
 593 the bootstrap classes of the platform that shipped with
 594 the\f[CB]javac\f[R] command.
 595 But \f[CB]javac\f[R] also supports cross\-compiling, in which classes are
 596 compiled against bootstrap classes of a different Java platform
 597 implementation.
 598 It\[aq]s important to use the \f[CB]\-bootclasspath\f[R] and
 599 \f[CB]\-extdirs\f[R] options when cross\-compiling.
 600 .PP
 601 \f[B]Note:\f[R]
 602 .PP
 603 This can only be used when compiling for versions prior to JDK 9.
 604 As applicable, see the descriptions in\ \f[CB]\-\-release\f[R],
 605 \f[CB]\-source\f[R], or \f[CB]\-target\f[R]\ for details.
 606 .SH EXTRA OPTIONS
 607 .TP
 608 .B \f[CB]\-\-add\-exports\f[R] \f[I]module\f[R]\f[CB]/\f[R]\f[I]package\f[R]\f[CB]=\f[R]\f[I]other\-module\f[R](\f[CB],\f[R]\f[I]other\-module\f[R])*
 609 Specifies a package to be considered as exported from its defining
 610 module to additional modules or to all unnamed modules when the value of
 611 \f[I]other\-module\f[R] is \f[CB]ALL\-UNNAMED\f[R].
 612 .RS
 613 .RE
 614 .TP
 615 .B \f[CB]\-\-add\-reads\f[R] \f[I]module\f[R]\f[CB]=\f[R]\f[I]other\-module\f[R](\f[CB],\f[R]\f[I]other\-module\f[R])*
 616 Specifies additional modules to be considered as required by a given
 617 module.
 618 .RS
 619 .RE
 620 .TP
 621 .B \f[CB]\-\-default\-module\-for\-created\-files\f[R] \f[I]module\-name\f[R]
 622 Specifies the fallback target module for files created by annotation
 623 processors, if none is specified or inferred.
 624 .RS
 625 .RE
 626 .TP
 627 .B \f[CB]\-Djava.endorsed.dirs=\f[R]\f[I]dirs\f[R]
 628 Overrides the location of the endorsed standards path.
 629 .RS
 630 .PP
 631 \f[B]Note:\f[R]
 632 .PP
 633 This can only be used when compiling for versions prior to JDK 9.
 634 As applicable, see the descriptions in\ \f[CB]\-\-release\f[R],
 635 \f[CB]\-source\f[R], or \f[CB]\-target\f[R]\ for details.
 636 .RE
 637 .TP
 638 .B \f[CB]\-Djava.ext.dirs=\f[R]\f[I]dirs\f[R]
 639 Overrides the location of installed extensions.
 640 .RS
 641 .PP
 642 \f[B]Note:\f[R]
 643 .PP
 644 This can only be used when compiling for versions prior to JDK 9.
 645 As applicable, see the descriptions in\ \f[CB]\-\-release\f[R],
 646 \f[CB]\-source\f[R], or \f[CB]\-target\f[R]\ for details.
 647 .RE
 648 .TP
 649 .B \f[CB]\-\-doclint\-format\f[R] [\f[CB]html4\f[R]|\f[CB]html5\f[R]]
 650 Specifies the format for documentation comments.
 651 .RS
 652 .RE
 653 .TP
 654 .B \f[CB]\-\-patch\-module\f[R] \f[I]module\f[R]\f[CB]=\f[R]\f[I]file\f[R](\f[CB]:\f[R]\f[I]file\f[R])*
 655 Overrides or augments a module with classes and resources in JAR files
 656 or directories.
 657 .RS
 658 .RE
 659 .TP
 660 .B \f[CB]\-Xbootclasspath:\f[R]\f[I]path\f[R]
 661 Overrides the location of the bootstrap class files.
 662 .RS
 663 .PP
 664 \f[B]Note:\f[R]
 665 .PP
 666 This can only be used when compiling for versions prior to JDK 9.
 667 As applicable, see the descriptions in\ \f[CB]\-\-release\f[R],
 668 \f[CB]\-source\f[R], or \f[CB]\-target\f[R]\ for details.
 669 .RE
 670 .TP
 671 .B \f[CB]\-Xbootclasspath/a:\f[R]\f[I]path\f[R]
 672 Adds a suffix to the bootstrap class path.
 673 .RS
 674 .PP
 675 \f[B]Note:\f[R]
 676 .PP
 677 This can only be used when compiling for versions prior to JDK 9.
 678 As applicable, see the descriptions in\ \f[CB]\-\-release\f[R],
 679 \f[CB]\-source\f[R], or \f[CB]\-target\f[R]\ for details.
 680 .RE
 681 .TP
 682 .B \f[CB]\-Xbootclasspath/p:\f[R]\f[I]path\f[R]
 683 Adds a prefix to the bootstrap class path.
 684 .RS
 685 .PP
 686 \f[B]Note:\f[R]
 687 .PP
 688 This can only be used when compiling for versions prior to JDK 9.
 689 As applicable, see the descriptions in\ \f[CB]\-\-release\f[R],
 690 \f[CB]\-source\f[R], or \f[CB]\-target\f[R]\ for details.
 691 .RE
 692 .TP
 693 .B \f[CB]\-Xdiags:\f[R][\f[CB]compact\f[R], \f[CB]verbose\f[R]]
 694 Selects a diagnostic mode.
 695 .RS
 696 .RE
 697 .TP
 698 .B \f[CB]\-Xdoclint\f[R]
 699 Enables recommended checks for problems in \f[CB]javadoc\f[R] comments
 700 .RS
 701 .RE
 702 .TP
 703 .B \f[CB]\-Xdoclint:\f[R](\f[CB]all\f[R]|\f[CB]none\f[R]|[\f[CB]\-\f[R]]\f[I]group\f[R])[\f[CB]/\f[R]\f[I]access\f[R]]
 704 Enables or disables specific groups of checks,
 705 .RS
 706 .PP
 707 \f[I]group\f[R] can have one of the following values:
 708 .IP \[bu] 2
 709 \f[CB]accessibility\f[R]
 710 .IP \[bu] 2
 711 \f[CB]html\f[R]
 712 .IP \[bu] 2
 713 \f[CB]missing\f[R]
 714 .IP \[bu] 2
 715 \f[CB]reference\f[R]
 716 .IP \[bu] 2
 717 \f[CB]syntax\f[R]
 718 .PP
 719 The variable \f[I]access\f[R] specifies the minimum visibility level of
 720 classes and members that the \f[CB]\-Xdoclint\f[R] option checks.
 721 It can have one of the following values (in order of most to least
 722 visible):
 723 .IP \[bu] 2
 724 \f[CB]public\f[R]
 725 .IP \[bu] 2
 726 \f[CB]protected\f[R]
 727 .IP \[bu] 2
 728 \f[CB]package\f[R]
 729 .IP \[bu] 2
 730 \f[CB]private\f[R]
 731 .PP
 732 The default \f[I]access\f[R] level is \f[CB]private\f[R].
 733 .PP
 734 For more information about these groups of checks, see the
 735 \f[CB]\-Xdoclint\f[R] option of the \f[CB]javadoc\f[R] command.
 736 The \f[CB]\-Xdoclint\f[R] option is disabled by default in the
 737 \f[CB]javac\f[R] command.
 738 .PP
 739 For example, the following option checks classes and members (with all
 740 groups of checks) that have the access level of protected and higher
 741 (which includes protected and public):
 742 .RS
 743 .PP
 744 \f[CB]\-Xdoclint:all/protected\f[R]
 745 .RE
 746 .PP
 747 The following option enables all groups of checks for all access levels,
 748 except it won\[aq]t check for HTML errors for classes and members that
 749 have the access level of package and higher (which includes package,
 750 protected and public):
 751 .RS
 752 .PP
 753 \f[CB]\-Xdoclint:all,\-html/package\f[R]
 754 .RE
 755 .RE
 756 .TP
 757 .B \f[CB]\-Xdoclint/package:\f[R][\f[CB]\-\f[R]]\f[I]packages\f[R](\f[CB],\f[R][\f[CB]\-\f[R]]\f[I]package\f[R])*
 758 Enables or disables checks in specific packages.
 759 Each \f[I]package\f[R] is either the qualified name of a package or a
 760 package name prefix followed by \f[CB]\&.*\f[R], which expands to all
 761 sub\-packages of the given package.
 762 Each \f[I]package\f[R] can be prefixed with a hyphen (\f[CB]\-\f[R]) to
 763 disable checks for a specified package or packages.
 764 .RS
 765 .RE
 766 .TP
 767 .B \f[CB]\-Xlint\f[R]
 768 Enables all recommended warnings.
 769 In this release, enabling all available warnings is recommended.
 770 .RS
 771 .RE
 772 .TP
 773 .B \f[CB]\-Xlint:\f[R][\f[CB]\-\f[R]]\f[I]key\f[R](\f[CB],\f[R][\f[CB]\-\f[R]]\f[I]key\f[R])*
 774 Supplies warnings to enable or disable, separated by comma.
 775 Precede a key by a hyphen (\f[CB]\-\f[R]) to disable the specified
 776 warning.
 777 .RS
 778 .PP
 779 Supported values for \f[I]key\f[R] are:
 780 .IP \[bu] 2
 781 \f[CB]all\f[R]: Enables all warnings.
 782 .IP \[bu] 2
 783 \f[CB]auxiliaryclass\f[R]: Warns about an auxiliary class that\[aq]s
 784 hidden in a source file, and is used from other files.
 785 .IP \[bu] 2
 786 \f[CB]cast\f[R]: Warns about the use of unnecessary casts.
 787 .IP \[bu] 2
 788 \f[CB]classfile\f[R]: Warns about the issues related to classfile
 789 contents.
 790 .IP \[bu] 2
 791 \f[CB]deprecation\f[R]: Warns about the use of deprecated items.
 792 .IP \[bu] 2
 793 \f[CB]dep\-ann\f[R]: Warns about the items marked as deprecated in
 794 \f[CB]javadoc\f[R] but without the \f[CB]\@Deprecated\f[R] annotation.
 795 .IP \[bu] 2
 796 \f[CB]divzero\f[R]: Warns about the division by the constant integer 0.
 797 .IP \[bu] 2
 798 \f[CB]empty\f[R]: Warns about an empty statement after \f[CB]if\f[R].
 799 .IP \[bu] 2
 800 \f[CB]exports\f[R]: Warns about the issues regarding module exports.
 801 .IP \[bu] 2
 802 \f[CB]fallthrough\f[R]: Warns about the falling through from one case of a
 803 switch statement to the next.
 804 .IP \[bu] 2
 805 \f[CB]finally\f[R]: Warns about \f[CB]finally\f[R] clauses that don\[aq]t
 806 terminate normally.
 807 .IP \[bu] 2
 808 \f[CB]module\f[R]: Warns about the module system\-related issues.
 809 .IP \[bu] 2
 810 \f[CB]opens\f[R]: Warns about the issues related to module opens.
 811 .IP \[bu] 2
 812 \f[CB]options\f[R]: Warns about the issues relating to use of command line
 813 options.
 814 .IP \[bu] 2
 815 \f[CB]overloads\f[R]: Warns about the issues related to method overloads.
 816 .IP \[bu] 2
 817 \f[CB]overrides\f[R]: Warns about the issues related to method overrides.
 818 .IP \[bu] 2
 819 \f[CB]path\f[R]: Warns about the invalid path elements on the command l
 820 ine.
 821 .IP \[bu] 2
 822 \f[CB]processing\f[R]: Warns about the issues related to annotation
 823 processing.
 824 .IP \[bu] 2
 825 \f[CB]rawtypes\f[R]: Warns about the use of raw types.
 826 .IP \[bu] 2
 827 \f[CB]removal\f[R]: Warns about the use of an API that has been marked for
 828 removal.
 829 .IP \[bu] 2
 830 \f[CB]requires\-automatic\f[R]: Warns developers about the use of
 831 automatic modules in requires clauses.
 832 .IP \[bu] 2
 833 \f[CB]requires\-transitive\-automatic\f[R]: Warns about automatic modules
 834 in requires transitive.
 835 .IP \[bu] 2
 836 \f[CB]serial\f[R]: Warns about the serializable classes that don\[aq]t
 837 provide a serial version ID.
 838 Also warns about access to non\-public members from a serializable
 839 element.
 840 .IP \[bu] 2
 841 \f[CB]static\f[R]: Warns about the accessing a static member using an
 842 instance.
 843 .IP \[bu] 2
 844 \f[CB]try\f[R]: Warns about the issues relating to the use of try blocks (
 845 that is, try\-with\-resources).
 846 .IP \[bu] 2
 847 \f[CB]unchecked\f[R]: Warns about the unchecked operations.
 848 .IP \[bu] 2
 849 \f[CB]varargs\f[R]: Warns about the potentially unsafe \f[CB]vararg\f[R]
 850 methods.
 851 .IP \[bu] 2
 852 \f[CB]none\f[R]: Disables all warnings.
 853 .PP
 854 See \f[B]Examples of Using \-Xlint keys\f[R].
 855 .RE
 856 .TP
 857 .B \f[CB]\-Xmaxerrs\f[R] \f[I]number\f[R]
 858 Sets the maximum number of errors to print.
 859 .RS
 860 .RE
 861 .TP
 862 .B \f[CB]\-Xmaxwarns\f[R] \f[I]number\f[R]
 863 Sets the maximum number of warnings to print.
 864 .RS
 865 .RE
 866 .TP
 867 .B \f[CB]\-Xpkginfo:\f[R][\f[CB]always\f[R], \f[CB]legacy\f[R], \f[CB]nonempty\f[R]]
 868 Specifies when and how the \f[CB]javac\f[R] command generates
 869 \f[CB]package\-info.class\f[R] files from \f[CB]package\-info.java\f[R]
 870 files using one of the following options:
 871 .RS
 872 .TP
 873 .B \f[CB]always\f[R]
 874 Generates a \f[CB]package\-info.class\f[R] file for every
 875 \f[CB]package\-info.java\f[R] file.
 876 This option may be useful if you use a build system such as Ant, which
 877 checks that each \f[CB]\&.java\f[R] file has a corresponding
 878 \f[CB]\&.class\f[R] file.
 879 .RS
 880 .RE



 881 .TP
 882 .B \f[CB]legacy\f[R]
 883 Generates a \f[CB]package\-info.class\f[R] file only if
 884 \f[CB]package\-info.java\f[R] contains annotations.
 885 This option doesn\[aq]t generate a \f[CB]package\-info.class\f[R] file if
 886 \f[CB]package\-info.java\f[R] contains only comments.
 887 .RS
 888 .PP
 889 \f[B]Note:\f[R]
 890 .PP
 891 A \f[CB]package\-info.class\f[R] file might be generated but be empty if
 892 all the annotations in the \f[CB]package\-info.java\f[R] file have
 893 \f[CB]RetentionPolicy.SOURCE\f[R].
 894 .RE




 895 .TP
 896 .B \f[CB]nonempty\f[R]
 897 Generates a \f[CB]package\-info.class\f[R] file only if
 898 \f[CB]package\-info.java\f[R] contains annotations with
 899 \f[CB]RetentionPolicy.CLASS\f[R] or \f[CB]RetentionPolicy.RUNTIME\f[R].
 900 .RS
 901 .RE
 902 .RE
















 903 .TP
 904 .B \f[CB]\-Xplugin:\f[R]\f[I]name\f[R] \f[I]args\f[R]
 905 Specifies the name and optional arguments for a plug\-in to be run.
 906 .RS
 907 .RE









 908 .TP
 909 .B \f[CB]\-Xprefer:\f[R][\f[CB]source\f[R], \f[CB]newer\f[R]]
 910 Specifies which file to read when both a source file and class file are
 911 found for an implicitly compiled class using one of the following
 912 options.
 913 See \f[B]Searching for Types\f[R].
 914 .RS
 915 .IP \[bu] 2
 916 \f[CB]\-Xprefer:newer\f[R]: Reads the newer of the source or class files
 917 for a type (default).
 918 .IP \[bu] 2
 919 \f[CB]\-Xprefer:source\f[R] : Reads the source file.
 920 Use \f[CB]\-Xprefer:source\f[R] when you want to be sure that any
 921 annotation processors can access annotations declared with a retention
 922 policy of \f[CB]SOURCE\f[R].
 923 .RE










 924 .TP
 925 .B \f[CB]\-Xprint\f[R]
 926 Prints a textual representation of specified types for debugging
 927 purposes.
 928 This doesn\[aq]t perform annotation processing or compilation.
 929 The format of the output could change.
 930 .RS
 931 .RE





























 932 .TP
 933 .B \f[CB]\-XprintProcessorInfo\f[R]
 934 Prints information about which annotations a processor is asked to
 935 process.
 936 .RS
 937 .RE
 938 .TP
 939 .B \f[CB]\-XprintRounds\f[R]
 940 Prints information about initial and subsequent annotation processing
 941 rounds.
 942 .RS
 943 .RE










































 944 .TP
 945 .B \f[CB]\-Xstdout\f[R] \f[I]filename\f[R]
 946 Sends compiler messages to the named file.
 947 By default, compiler messages go to \f[CB]System.err\f[R].
 948 .RS
 949 .RE
 950 .SH JAVAC COMMAND\-LINE ARGUMENT FILES
 951 .PP
 952 An argument file can include \f[CB]javac\f[R] options and source file
 953 names in any combination.
 954 The arguments within a file can be separated by spaces or new line
 955 characters.
 956 If a file name contains embedded spaces, then put the whole file name in
 957 double quotation marks.
 958 .PP
 959 File names within an argument file are relative to the current
 960 directory, not to the location of the argument file.
 961 Wildcards (*) aren\[aq]t allowed in these lists (such as for specifying
 962 \f[CB]*.java\f[R]).
 963 Use of the at sign (\f[CB]\@\f[R]) to recursively interpret files
 964 isn\[aq]t supported.
 965 The \f[CB]\-J\f[R] options aren\[aq]t supported because they\[aq]re passed
 966 to the launcher, which doesn\[aq]t support argument files.
 967 .PP
 968 When executing the \f[CB]javac\f[R] command, pass in the path and name of
 969 each argument file with the at sign (\f[CB]\@\f[R]) leading character.
 970 When the \f[CB]javac\f[R] command encounters an argument beginning with
 971 the at sign (\f[CB]\@\f[R]), it expands the contents of that file into the
 972 argument list.
 973 .SH EXAMPLES OF USING JAVAC \@FILENAME
 974 .TP
 975 .B Single Argument File
 976 You could use a single argument file named \f[CB]argfile\f[R] to hold all
 977 \f[CB]javac\f[R] arguments:
 978 .RS
 979 .RS
 980 .PP
 981 \f[CB]javac\ \@argfile\f[R]
 982 .RE
 983 .PP
 984 This argument file could contain the contents of both files shown in the
 985 following \f[B]Two Argument Files\f[R] example.
 986 .RE



 987 .TP
 988 .B Two Argument Files
 989 You can create two argument files: one for the \f[CB]javac\f[R] options
 990 and the other for the source file names.
 991 Note that the following lists have no line\-continuation characters.
 992 .RS
 993 .PP
 994 Create a file named \f[CB]options\f[R] that contains the following:
 995 .PP
 996 \f[B]Oracle Solaris, Linux, and OS X:\f[R]
 997 .IP
 998 .nf
 999 \f[CB]
1000 \-d\ classes
1001 \-g
1002 \-sourcepath\ /java/pubs/ws/1.3/src/share/classes
1003 \f[R]
1004 .fi
1005 .PP
1006 \f[B]Windows:\f[R]
1007 .IP
1008 .nf
1009 \f[CB]
1010 \-d\ classes
1011 \-g
1012 \-sourcepath\ C:\\java\\pubs\\ws\\1.3\\src\\share\\classes
1013 \f[R]
1014 .fi
1015 .PP
1016 Create a file named \f[CB]classes\f[R] that contains the following:
1017 .IP
1018 .nf
1019 \f[CB]
1020 MyClass1.java
1021 MyClass2.java
1022 MyClass3.java
1023 \f[R]
1024 .fi
1025 .PP
1026 Then, run the \f[CB]javac\f[R] command as follows:
1027 .RS
1028 .PP
1029 \f[CB]javac\ \@options\ \@classes\f[R]
1030 .RE
1031 .RE
1032 .TP
1033 .B Argument Files with Paths
1034 The argument files can have paths, but any file names inside the files
1035 are relative to the current working directory (not \f[CB]path1\f[R] or
1036 \f[CB]path2\f[R]):
1037 .RS
1038 .RS
1039 .PP
1040 \f[CB]javac\ \@path1/options\ \@path2/classes\f[R]
1041 .RE
1042 .RE
1043 .SH EXAMPLES OF USING \-XLINT KEYS


















































1044 .TP
1045 .B \f[CB]cast\f[R]














1046 Warns about unnecessary and redundant casts, for example:
1047 .RS
1048 .RS
1049 .PP
1050 \f[CB]String\ s\ =\ (String)\ "Hello!"\f[R]
1051 .RE
1052 .RE
1053 .TP
1054 .B \f[CB]classfile\f[R]
1055 Warns about issues related to class file contents.
1056 .RS
1057 .RE
1058 .TP
1059 .B \f[CB]deprecation\f[R]
1060 Warns about the use of deprecated items.
1061 For example:
1062 .RS
1063 .IP
1064 .nf
1065 \f[CB]
1066 java.util.Date\ myDate\ =\ new\ java.util.Date();
1067 int\ currentDay\ =\ myDate.getDay();
1068 \f[R]
1069 .fi
1070 .PP
1071 The method \f[CB]java.util.Date.getDay\f[R] has been deprecated since JDK
1072 1.1.
1073 .RE
1074 .TP
1075 .B \f[CB]dep\-ann\f[R]
1076 Warns about items that are documented with the \f[CB]\@deprecated\f[R]
1077 Javadoc comment, but don\[aq]t have the \f[CB]\@Deprecated\f[R]
1078 annotation, for example:
1079 .RS
1080 .IP
1081 .nf
1082 \f[CB]
1083 /**
1084 \ \ *\ \@deprecated\ As\ of\ Java\ SE\ 7,\ replaced\ by\ {\@link\ #newMethod()}
1085 \ \ */
1086 public\ static\ void\ deprecatedMethod()\ {\ }
1087 public\ static\ void\ newMethod()\ {\ }
1088 \f[R]
1089 .fi
1090 .RE
1091 .TP
1092 .B \f[CB]divzero\f[R]









1093 Warns about division by the constant integer 0, for example:
1094 .RS
1095 .RS
1096 .PP
1097 \f[CB]int\ divideByZero\ =\ 42\ /\ 0;\f[R]
1098 .RE
1099 .RE
1100 .TP
1101 .B \f[CB]empty\f[R]
1102 Warns about empty statements after \f[CB]if\f[R]statements, for example:
1103 .RS
1104 .IP
1105 .nf
1106 \f[CB]
1107 class\ E\ {
1108 \ \ \ \ void\ m()\ {
1109 \ \ \ \ \ \ \ \ \ if\ (true)\ ;
1110 \ \ \ \ }
1111 }
1112 \f[R]
1113 .fi
1114 .RE
1115 .TP
1116 .B \f[CB]fallthrough\f[R]
1117 Checks the switch blocks for fall\-through cases and provides a warning
1118 message for any that are found.
1119 Fall\-through cases are cases in a switch block, other than the last
1120 case in the block, whose code doesn\[aq]t include a break statement,
1121 allowing code execution to fall through from that case to the next case.
1122 For example, the code following the case 1 label in this switch block
1123 doesn\[aq]t end with a break statement:
1124 .RS
1125 .IP
1126 .nf
1127 \f[CB]
1128 switch\ (x)\ {
1129 case\ 1:
1130 \ \ System.out.println("1");
1131 \ \ //\ No\ break\ statement\ here.
1132 case\ 2:
1133 \ \ System.out.println("2");
1134 }
1135 \f[R]
1136 .fi
1137 .PP
1138 If the \f[CB]\-Xlint:fallthrough\f[R] option was used when compiling this
1139 code, then the compiler emits a warning about possible fall\-through
1140 into case, with the line number of the case in question.
1141 .RE
1142 .TP
1143 .B \f[CB]finally\f[R]
1144 Warns about \f[CB]finally\f[R] clauses that can\[aq]t be completed
1145 normally, for example:
1146 .RS
1147 .IP
1148 .nf
1149 \f[CB]
1150 public\ static\ int\ m()\ {
1151 \ \ try\ {
1152 \ \ \ \ \ throw\ new\ NullPointerException();
1153 \ \ }\ \ catch\ (NullPointerException();\ {
1154 \ \ \ \ \ System.err.println("Caught\ NullPointerException.");
1155 \ \ \ \ \ return\ 1;
1156 \ \ \ }\ finally\ {
1157 \ \ \ \ \ return\ 0;
1158 \ \ \ }
1159 \ \ }
1160 \f[R]
1161 .fi
1162 .PP
1163 The compiler generates a warning for the \f[CB]finally\f[R] block in this
1164 example.
1165 When the \f[CB]int\f[R] method is called, it returns a value of 0.
1166 A \f[CB]finally\f[R] block executes when the \f[CB]try\f[R] block exits.
1167 In this example, when control is transferred to the \f[CB]catch\f[R]
1168 block, the \f[CB]int\f[R] method exits.
1169 However, the \f[CB]finally\f[R] block must execute, so it\[aq]s executed,
1170 even though control was transferred outside the method.
1171 .RE
1172 .TP
1173 .B \f[CB]options\f[R]
1174 Warns about issues that related to the use of command\-line options.
1175 See \f[B]Cross\-Compilation Options for javac\f[R].
1176 .RS
1177 .RE
1178 .TP
1179 .B \f[CB]overrides\f[R]
1180 Warns about issues related to method overrides.
1181 For example, consider the following two classes:
1182 .RS
1183 .IP
1184 .nf
1185 \f[CB]
1186 public\ class\ ClassWithVarargsMethod\ {
1187 \ \ void\ varargsMethod(String...\ s)\ {\ }
1188 }
1189 
1190 public\ class\ ClassWithOverridingMethod\ extends\ ClassWithVarargsMethod\ {
1191 \ \ \ \@Override
1192 \ \ \ void\ varargsMethod(String[]\ s)\ {\ }
1193 }
1194 \f[R]
1195 .fi
1196 .PP
1197 The compiler generates a warning similar to the following:.
1198 .IP
1199 .nf
1200 \f[CB]
1201 warning:\ [override]\ varargsMethod(String[])\ in\ ClassWithOverridingMethod
1202 overrides\ varargsMethod(String...)\ in\ ClassWithVarargsMethod;\ overriding
1203 method\ is\ missing\ \[aq]...\[aq]
1204 \f[R]
1205 .fi
1206 .PP
1207 When the compiler encounters a \f[CB]varargs\f[R] method, it translates
1208 the \f[CB]varargs\f[R] formal parameter into an array.
1209 In the method \f[CB]ClassWithVarargsMethod.varargsMethod\f[R], the
1210 compiler translates the \f[CB]varargs\f[R] formal parameter
1211 \f[CB]String...\ s\f[R] to the formal parameter \f[CB]String[]\ s\f[R], an
1212 array that matches the formal parameter of the method
1213 \f[CB]ClassWithOverridingMethod.varargsMethod\f[R].
1214 Consequently, this example compiles.
1215 .RE
1216 .TP
1217 .B \f[CB]path\f[R]
1218 Warns about invalid path elements and nonexistent path directories on
1219 the command line (with regard to the class path, the source path, and
1220 other paths).
1221 Such warnings can\[aq]t be suppressed with the
1222 \f[CB]\@SuppressWarnings\f[R] annotation.
1223 For example:
1224 .RS
1225 .IP \[bu] 2
1226 \f[B]Oracle Solaris, Linux, and OS X:\f[R]
1227 \f[CB]javac\ \-Xlint:path\ \-classpath\ /nonexistentpath\ Example.java\f[R]
1228 .IP \[bu] 2
1229 \f[B]Windows:\f[R]
1230 \f[CB]javac\ \-Xlint:path\ \-classpath\ C:\\nonexistentpath\ Example.java\f[R]
1231 .RE
1232 .TP
1233 .B \f[CB]processing\f[R]
1234 Warns about issues related to annotation processing.
1235 The compiler generates this warning when you have a class that has an
1236 annotation, and you use an annotation processor that can\[aq]t handle
1237 that type of exception.
1238 For example, the following is a simple annotation processor:
1239 .RS
1240 .PP
1241 \f[B]Source file AnnocProc.java\f[R]:
1242 .IP
1243 .nf
1244 \f[CB]
1245 import\ java.util.*;
1246 import\ javax.annotation.processing.*;
1247 import\ javax.lang.model.*;
1248 import\ javaz.lang.model.element.*;
1249 
1250 \@SupportedAnnotationTypes("NotAnno")
1251 public\ class\ AnnoProc\ extends\ AbstractProcessor\ {
1252 \ \ public\ boolean\ process(Set<?\ extends\ TypeElement>\ elems,\ RoundEnvironment\ renv){
1253 \ \ \ \ \ return\ true;
1254 \ \ }
1255 
1256 \ \ public\ SourceVersion\ getSupportedSourceVersion()\ {
1257 \ \ \ \ \ return\ SourceVersion.latest();
1258 \ \ \ }
1259 }
1260 \f[R]
1261 .fi
1262 .PP
1263 \f[B]Source file AnnosWithoutProcessors.java\f[R]:
1264 .IP
1265 .nf
1266 \f[CB]
1267 \@interface\ Anno\ {\ }
1268 
1269 \@Anno
1270 class\ AnnosWithoutProcessors\ {\ }
1271 \f[R]
1272 .fi
1273 .PP
1274 The following commands compile the annotation processor
1275 \f[CB]AnnoProc\f[R], then run this annotation processor against the source
1276 file \f[CB]AnnosWithoutProcessors.java\f[R]:
1277 .IP
1278 .nf
1279 \f[CB]
1280 javac\ AnnoProc.java
1281 javac\ \-cp\ .\ \-Xlint:processing\ \-processor\ AnnoProc\ \-proc:only\ AnnosWithoutProcessors.java
1282 \f[R]
1283 .fi
1284 .PP
1285 When the compiler runs the annotation processor against the source file
1286 \f[CB]AnnosWithoutProcessors.java\f[R], it generates the following
1287 warning:
1288 .IP
1289 .nf
1290 \f[CB]
1291 warning:\ [processing]\ No\ processor\ claimed\ any\ of\ these\ annotations:\ Anno
1292 \f[R]
1293 .fi
1294 .PP
1295 To resolve this issue, you can rename the annotation defined and used in
1296 the class \f[CB]AnnosWithoutProcessors\f[R] from \f[CB]Anno\f[R] to
1297 \f[CB]NotAnno\f[R].
1298 .RE
1299 .TP
1300 .B \f[CB]rawtypes\f[R]
1301 Warns about unchecked operations on raw types.
1302 The following statement generates a \f[CB]rawtypes\f[R] warning:
1303 .RS
1304 .RS
1305 .PP
1306 \f[CB]void\ countElements(List\ l)\ {\ ...\ }\f[R]
1307 .RE
1308 .PP
1309 The following example doesn\[aq]t generate a \f[CB]rawtypes\f[R] warning:
1310 .RS
1311 .PP
1312 \f[CB]void\ countElements(List<?>\ l)\ {\ ...\ }\f[R]
1313 .RE
1314 .PP
1315 \f[CB]List\f[R] is a raw type.
1316 However, \f[CB]List<?>\f[R] is an unbounded wildcard parameterized type.
1317 Because \f[CB]List\f[R] is a parameterized interface, always specify its
1318 type argument.
1319 In this example, the \f[CB]List\f[R] formal argument is specified with an
1320 unbounded wildcard (\f[CB]?\f[R]) as its formal type parameter, which
1321 means that the \f[CB]countElements\f[R] method can accept any
1322 instantiation of the \f[CB]List\f[R] interface.
1323 .RE
1324 .TP
1325 .B \f[CB]serial\f[R]
1326 Warns about missing \f[CB]serialVersionUID\f[R] definitions on
1327 serializable classes.
1328 For example:
1329 .RS
1330 .IP
1331 .nf
1332 \f[CB]
1333 public\ class\ PersistentTime\ implements\ Serializable
1334 {
1335 \ \ private\ Date\ time;
1336 
1337 \ \ \ public\ PersistentTime()\ {
1338 \ \ \ \ \ time\ =\ Calendar.getInstance().getTime();
1339 \ \ \ }
1340 
1341 \ \ \ public\ Date\ getTime()\ {
1342 \ \ \ \ \ return\ time;
1343 \ \ \ }
1344 }
1345 \f[R]
1346 .fi
1347 .PP





























































































1348 The compiler generates the following warning:
1349 .IP
1350 .nf
1351 \f[CB]
1352 warning:\ [serial]\ serializable\ class\ PersistentTime\ has\ no\ definition\ of
1353 serialVersionUID
1354 \f[R]
1355 .fi
1356 .PP
1357 If a serializable class doesn\[aq]t explicitly declare a field named
1358 \f[CB]serialVersionUID\f[R], then the serialization runtime environment
1359 calculates a default \f[CB]serialVersionUID\f[R] value for that class
1360 based on various aspects of the class, as described in the Java Object
1361 Serialization Specification.
1362 However, it\[aq]s strongly recommended that all serializable classes
1363 explicitly declare \f[CB]serialVersionUID\f[R] values because the default
1364 process of computing \f[CB]serialVersionUID\f[R] values is highly
1365 sensitive to class details that can vary depending on compiler
1366 implementations.
1367 As a result, this might cause an unexpected
1368 \f[CB]InvalidClassExceptions\f[R] during deserialization.
1369 To guarantee a consistent \f[CB]serialVersionUID\f[R] value across
1370 different Java compiler implementations, a serializable class must
1371 declare an explicit \f[CB]serialVersionUID\f[R] value.
1372 .RE
1373 .TP
1374 .B \f[CB]static\f[R]
1375 Warns about issues relating to the use of statics variables, for
1376 example:
1377 .RS
1378 .IP
1379 .nf
1380 \f[CB]
1381 class\ XLintStatic\ {
1382 \ \ \ \ static\ void\ m1()\ {\ }
1383 \ \ \ \ void\ m2()\ {\ this.m1();\ }
1384 }
1385 \f[R]
1386 .fi
1387 .PP
1388 The compiler generates the following warning:
1389 .IP
1390 .nf
1391 \f[CB]
1392 warning:\ [static]\ static\ method\ should\ be\ qualified\ by\ type\ name,
1393 XLintStatic,\ instead\ of\ by\ an\ expression
1394 \f[R]
1395 .fi
1396 .PP
1397 To resolve this issue, you can call the \f[CB]static\f[R] method
1398 \f[CB]m1\f[R] as follows:
1399 .RS
1400 .PP
1401 \f[CB]XLintStatic.m1();\f[R]
1402 .RE
1403 .PP
1404 Alternately, you can remove the \f[CB]static\f[R] keyword from the
1405 declaration of the method \f[CB]m1\f[R].
1406 .RE
1407 .TP
1408 .B \f[CB]try\f[R]
1409 Warns about issues relating to the use of \f[CB]try\f[R] blocks, including
1410 try\-with\-resources statements.
1411 For example, a warning is generated for the following statement because
1412 the resource \f[CB]ac\f[R] declared in the \f[CB]try\f[R] block isn\[aq]t
1413 used:
1414 .RS
1415 .IP
1416 .nf
1417 \f[CB]
1418 try\ (\ AutoCloseable\ ac\ =\ getResource()\ )\ {\ \ \ \ //\ do\ nothing}
1419 \f[R]
1420 .fi
1421 .RE
1422 .TP
1423 .B \f[CB]unchecked\f[R]
1424 Gives more detail for unchecked conversion warnings that are mandated by
1425 the Java Language Specification, for example:
1426 .RS
1427 .IP
1428 .nf
1429 \f[CB]
1430 List\ l\ =\ new\ ArrayList<Number>();
1431 List<String>\ ls\ =\ l;\ \ \ \ \ \ \ //\ unchecked\ warning
1432 \f[R]
1433 .fi
1434 .PP
1435 During type erasure, the types \f[CB]ArrayList<Number>\f[R] and
1436 \f[CB]List<String>\f[R] become \f[CB]ArrayList\f[R] and \f[CB]List\f[R],
1437 respectively.
1438 .PP
1439 The \f[CB]ls\f[R] command has the parameterized type
1440 \f[CB]List<String>\f[R].
1441 When the \f[CB]List\f[R] referenced by \f[CB]l\f[R] is assigned to
1442 \f[CB]ls\f[R], the compiler generates an unchecked warning.
1443 At compile time, the compiler and JVM can\[aq]t determine whether
1444 \f[CB]l\f[R] refers to a \f[CB]List<String>\f[R] type.
1445 In this case, \f[CB]l\f[R] doesn\[aq]t refer to a \f[CB]List<String>\f[R]
1446 type.
1447 As a result, heap pollution occurs.
1448 .PP
1449 A heap pollution situation occurs when the \f[CB]List\f[R] object
1450 \f[CB]l\f[R], whose static type is \f[CB]List<Number>\f[R], is assigned to
1451 another \f[CB]List\f[R] object, \f[CB]ls\f[R], that has a different static
1452 type, \f[CB]List<String>\f[R].
1453 However, the compiler still allows this assignment.
1454 It must allow this assignment to preserve backward compatibility with
1455 releases of Java SE that don\[aq]t support generics.
1456 Because of type erasure, \f[CB]List<Number>\f[R] and \f[CB]List<String>\f[R]
1457 both become \f[CB]List\f[R].
1458 Consequently, the compiler allows the assignment of the object
1459 \f[CB]l\f[R], which has a raw type of \f[CB]List\f[R], to the object
1460 \f[CB]ls\f[R].
1461 .RE
1462 .TP
1463 .B \f[CB]varargs\f[R]
1464 Warns about unsafe use of variable arguments (\f[CB]varargs\f[R]) methods,
1465 in particular, those that contain non\-reifiable arguments, for example:
1466 .RS
1467 .IP
1468 .nf
1469 \f[CB]
1470 public\ class\ ArrayBuilder\ {
1471 \ \ public\ static\ <T>\ void\ addToList\ (List<T>\ listArg,\ T...\ elements)\ {
1472 \ \ \ \ for\ (T\ x\ :\ elements)\ {
1473 \ \ \ \ \ \ listArg.add(x);
1474 \ \ \ \ }
1475 \ \ }
1476 }
1477 \f[R]
1478 .fi
1479 .PP
1480 A non\-reifiable type is a type whose type information isn\[aq]t fully
1481 available at runtime.
1482 .PP
1483 The compiler generates the following warning for the definition of the
1484 method \f[CB]ArrayBuilder.addToList\f[R]:
1485 .IP
1486 .nf
1487 \f[CB]
1488 warning:\ [varargs]\ Possible\ heap\ pollution\ from\ parameterized\ vararg\ type\ T
1489 \f[R]
1490 .fi
1491 .PP
1492 When the compiler encounters a varargs method, it translates the
1493 \f[CB]varargs\f[R] formal parameter into an array.
1494 However, the Java programming language doesn\[aq]t permit the creation
1495 of arrays of parameterized types.
1496 In the method \f[CB]ArrayBuilder.addToList\f[R], the compiler translates
1497 the \f[CB]varargs\f[R] formal parameter \f[CB]T...\f[R] elements to the
1498 formal parameter \f[CB]T[]\f[R] elements, an array.
1499 However, because of type erasure, the compiler converts the
1500 \f[CB]varargs\f[R] formal parameter to \f[CB]Object[]\f[R] elements.
1501 Consequently, there\[aq]s a possibility of heap pollution.
1502 .RE
1503 .SH EXAMPLE OF COMPILING BY PROVIDING COMMAND\-LINE ARGUMENTS
1504 .PP
1505 To compile as though providing command\-line arguments, use the
1506 following syntax:
1507 .RS
1508 .PP
1509 \f[CB]JavaCompiler\ javac\ =\ ToolProvider.getSystemJavaCompiler();\f[R]
1510 .RE
1511 .PP
1512 The example writes diagnostics to the standard output stream and returns
1513 the exit code that \f[CB]javac\f[R] command would give when called from
1514 the command line.
1515 .PP
1516 You can use other methods in the \f[CB]javax.tools.JavaCompiler\f[R]
1517 interface to handle diagnostics, control where files are read from and
1518 written to, and more.
1519 .SH OLD INTERFACE
1520 .PP
1521 \f[B]Note:\f[R]
1522 .PP
1523 This API is retained for backward compatibility only.
1524 All new code should use the Java Compiler API.
1525 .PP
1526 The \f[CB]com.sun.tools.javac.Main\f[R] class provides two static methods
1527 to call the compiler from a program:
1528 .IP
1529 .nf
1530 \f[CB]
1531 public\ static\ int\ compile(String[]\ args);
1532 public\ static\ int\ compile(String[]\ args,\ PrintWriter\ out);
1533 \f[R]
1534 .fi
1535 .PP
1536 The \f[CB]args\f[R] parameter represents any of the command\-line
1537 arguments that would typically be passed to the compiler.
1538 .PP
1539 The \f[CB]out\f[R] parameter indicates where the compiler diagnostic
1540 output is directed.
1541 .PP
1542 The \f[CB]return\f[R] value is equivalent to the \f[CB]exit\f[R] value from
1543 \f[CB]javac\f[R].
1544 .PP
1545 \f[B]Note:\f[R]
1546 .PP
1547 All other classes and methods found in a package with names that start
1548 with \f[CB]com.sun.tools.javac\f[R] (subpackages of
1549 \f[CB]com.sun.tools.javac\f[R]) are strictly internal and subject to
1550 change at any time.
1551 .SH EXAMPLE OF COMPILING MULTIPLE SOURCE FILES
1552 .PP
1553 This example compiles the \f[CB]Aloha.java\f[R], \f[CB]GutenTag.java\f[R],
1554 \f[CB]Hello.java\f[R], and \f[CB]Hi.java\f[R] source files in the
1555 \f[CB]greetings\f[R] package.
1556 .PP
1557 \f[B]Oracle Solaris, Linux, and OS X:\f[R]
1558 .IP
1559 .nf
1560 \f[CB]
1561 %\ javac\ greetings/*.java
1562 %\ ls\ greetings
1563 Aloha.class\ \ \ \ \ \ \ \ \ GutenTag.class\ \ \ \ \ \ Hello.class\ \ \ \ \ \ \ \ \ Hi.class
1564 Aloha.java\ \ \ \ \ \ \ \ \ \ GutenTag.java\ \ \ \ \ \ \ Hello.java\ \ \ \ \ \ \ \ \ \ Hi.java
1565 \f[R]
1566 .fi
1567 .PP
1568 \f[B]Windows:\f[R]
1569 .IP
1570 .nf
1571 \f[CB]
1572 C:\\>javac\ greetings\\*.java
1573 C:\\>dir\ greetings
1574 Aloha.class\ \ \ \ \ \ \ \ \ GutenTag.class\ \ \ \ \ \ Hello.class\ \ \ \ \ \ \ \ \ Hi.class
1575 Aloha.java\ \ \ \ \ \ \ \ \ \ GutenTag.java\ \ \ \ \ \ \ Hello.java\ \ \ \ \ \ \ \ \ \ Hi.java
1576 \f[R]
1577 .fi
1578 .SH EXAMPLE OF SPECIFYING A USER CLASS PATH
1579 .PP
1580 After changing one of the source files in the previous example,
1581 recompile it:
1582 .PP
1583 \f[B]Oracle Solaris, Linux, and OS X:\f[R]
1584 .IP
1585 .nf
1586 \f[CB]
1587 pwd
1588 /examples
1589 javac\ greetings/Hi.java
1590 \f[R]
1591 .fi
1592 .PP
1593 \f[B]Windows:\f[R]
1594 .IP
1595 .nf
1596 \f[CB]
1597 C:\\>cd
1598 \\examples
1599 C:\\>javac\ greetings\\Hi.java
1600 \f[R]
1601 .fi
1602 .PP
1603 Because \f[CB]greetings.Hi\f[R] refers to other classes in the
1604 \f[CB]greetings\f[R] package, the compiler needs to find these other
1605 classes.
1606 The previous example works because the default user class path is the
1607 directory that contains the package directory.
1608 If you want to recompile this file without concern for which directory
1609 you are in, then add the examples directory to the user class path by
1610 setting \f[CB]CLASSPATH\f[R].
1611 This example uses the \f[CB]\-classpath\f[R] option.
1612 .PP
1613 \f[B]Oracle Solaris, Linux, and OS X:\f[R]
1614 .RS
1615 .PP
1616 \f[CB]javac\ \-classpath\ /examples\ /examples/greetings/Hi.java\f[R]
1617 .RE
1618 .PP
1619 \f[B]Windows:\f[R]
1620 .RS
1621 .PP
1622 \f[CB]C:\\>javac\ \-classpath\ \\examples\ \\examples\\greetings\\Hi.java\f[R]
1623 .RE
1624 .PP
1625 If you change \f[CB]greetings.Hi\f[R] to use a banner utility, then that
1626 utility also needs to be accessible through the user class path.
1627 .PP
1628 \f[B]Oracle Solaris, Linux, and OS X:\f[R]
1629 .IP
1630 .nf
1631 \f[CB]
1632 javac\ \-classpath\ /examples:/lib/Banners.jar\ \\
1633 \ \ \ \ \ \ \ \ \ \ \ \ /examples/greetings/Hi.java
1634 \f[R]
1635 .fi
1636 .PP
1637 \f[B]Windows:\f[R]
1638 .IP
1639 .nf
1640 \f[CB]
1641 C:\\>javac\ \-classpath\ \\examples;\\lib\\Banners.jar\ ^
1642 \ \ \ \ \ \ \ \ \ \ \ \ \\examples\\greetings\\Hi.java
1643 \f[R]
1644 .fi
1645 .PP
1646 To execute a class in the \f[CB]greetings\f[R] package, the program needs
1647 access to the \f[CB]greetings\f[R] package, and to the classes that the
1648 \f[CB]greetings\f[R] classes use.
1649 .PP
1650 \f[B]Oracle Solaris, Linux, and OS X:\f[R]
1651 .RS
1652 .PP
1653 \f[CB]java\ \-classpath\ /examples:/lib/Banners.jar\ greetings.Hi\f[R]
1654 .RE
1655 .PP
1656 \f[B]Windows:\f[R]
1657 .RS
1658 .PP
1659 \f[CB]C:\\>java\ \-classpath\ \\examples;\\lib\\Banners.jar\ greetings.Hi\f[R]
1660 .RE
1661 .PP
1662 The \f[CB]\-source\ 1.7\f[R] option specifies that release 1.7 (or 7) of
1663 the Java programming language must be used to compile OldCode.java.
1664 The \f[CB]\-target\ 1.7\f[R] option ensures that the generated class files
1665 are compatible with JVM 1.7.
1666 .SH ANNOTATION PROCESSING
1667 .PP
1668 The \f[CB]javac\f[R] command provides direct support for annotation
1669 processing, superseding the need for the separate annotation processing
1670 command, \f[CB]apt\f[R].
1671 .PP
1672 The API for annotation processors is defined in the
1673 \f[CB]javax.annotation.processing\f[R] and \f[CB]javax.lang.model\f[R]
1674 packages and subpackages.
1675 .SS How Annotation Processing Works
1676 .PP
1677 Unless annotation processing is disabled with the \f[CB]\-proc:none\f[R]
1678 option, the compiler searches for any annotation processors that are
1679 available.
1680 The search path can be specified with the \f[CB]\-processorpath\f[R]
1681 option.
1682 If no path is specified, then the user class path is used.
1683 Processors are located by means of service provider\-configuration files
1684 named \f[CB]META\-INF/services/javax.annotation.processing\f[R].
1685 Processor on the search path.
1686 Such files should contain the names of any annotation processors to be
1687 used, listed one per line.
1688 Alternatively, processors can be specified explicitly, using the
1689 \f[CB]\-processor\f[R] option.
1690 .PP
1691 After scanning the source files and classes on the command line to
1692 determine what annotations are present, the compiler queries the
1693 processors to determine what annotations they process.
1694 When a match is found, the processor is called.
1695 A processor can claim the annotations it processes, in which case no
1696 further attempt is made to find any processors for those annotations.
1697 After all of the annotations are claimed, the compiler does not search
1698 for additional processors.
1699 .PP
1700 If any processors generate new source files, then another round of
1701 annotation processing occurs: Any newly generated source files are
1702 scanned, and the annotations processed as before.
1703 Any processors called on previous rounds are also called on all
1704 subsequent rounds.
1705 This continues until no new source files are generated.
1706 .PP
1707 After a round occurs where no new source files are generated, the
1708 annotation processors are called one last time, to give them a chance to
1709 complete any remaining work.
1710 Finally, unless the \f[CB]\-proc:only\f[R] option is used, the compiler
1711 compiles the original and all generated source files.
1712 .SH SEARCHING FOR TYPES
1713 .PP
1714 To compile a source file, the compiler often needs information about a
1715 type, but the type definition is not in the source files specified on
1716 the command line.
1717 .PP
1718 The compiler needs type information for every class or interface used,
1719 extended, or implemented in the source file.
1720 This includes classes and interfaces not explicitly mentioned in the
1721 source file, but that provide information through inheritance.
1722 .PP
1723 For example, when you create a subclass of \f[CB]java.awt.Window\f[R], you
1724 are also using the ancestor classes of \f[CB]Window\f[R]:
1725 \f[CB]java.awt.Container\f[R], \f[CB]java.awt.Component\f[R], and
1726 \f[CB]java.lang.Object\f[R].
1727 .PP
1728 When the compiler needs type information, it searches for a source file
1729 or class file that defines the type.
1730 The compiler searches for class files first in the bootstrap and
1731 extension classes, then in the user class path (which by default is the
1732 current directory).
1733 The user class path is defined by setting the \f[CB]CLASSPATH\f[R]
1734 environment variable or by using the \f[CB]\-classpath\f[R] option.
1735 .PP
1736 If you set the \f[CB]\-sourcepath\f[R] option, then the compiler searches
1737 the indicated path for source files.
1738 Otherwise, the compiler searches the user class path for both class
1739 files and source files.
1740 .PP
1741 You can specify different bootstrap or extension classes with the
1742 \f[CB]\-bootclasspath\f[R] and the \f[CB]\-extdirs\f[R] options.
1743 See \f[B]Cross\-Compilation Options for javac\f[R].
1744 .PP
1745 A successful type search may produce a class file, a source file, or
1746 both.
1747 If both are found, then you can use the \f[CB]\-Xprefer\f[R] option to
1748 instruct the compiler which to use.
1749 If \f[CB]newer\f[R] is specified, then the compiler uses the newer of the
1750 two files.
1751 If \f[CB]source\f[R] is specified, the compiler uses the source file.
1752 The default is \f[CB]newer\f[R].
1753 .PP
1754 If a type search finds a source file for a required type, either by
1755 itself, or as a result of the setting for the \f[CB]\-Xprefer\f[R] option,
1756 then the compiler reads the source file to get the information it needs.
1757 By default the compiler also compiles the source file.
1758 You can use the \f[CB]\-implicit\f[R] option to specify the behavior.
1759 If \f[CB]none\f[R] is specified, then no class files are generated for the
1760 source file.
1761 If \f[CB]class\f[R] is specified, then class files are generated for the
1762 source file.
1763 .PP
1764 The compiler might not discover the need for some type information until
1765 after annotation processing completes.
1766 When the type information is found in a source file and no
1767 \f[CB]\-implicit\f[R] option is specified, the compiler gives a warning
1768 that the file is being compiled without being subject to annotation
1769 processing.
1770 To disable the warning, either specify the file on the command line (so
1771 that it will be subject to annotation processing) or use the
1772 \f[CB]\-implicit\f[R] option to specify whether or not class files should
1773 be generated for such source files.











































































   1 '\" t
   2 .\" Copyright (c) 1994, 2015, Oracle and/or its affiliates. All rights reserved.
   3 .\" DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
   4 .\"
   5 .\" This code is free software; you can redistribute it and/or modify it
   6 .\" under the terms of the GNU General Public License version 2 only, as
   7 .\" published by the Free Software Foundation.
   8 .\"
   9 .\" This code is distributed in the hope that it will be useful, but WITHOUT
  10 .\" ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
  11 .\" FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
  12 .\" version 2 for more details (a copy is included in the LICENSE file that
  13 .\" accompanied this code).
  14 .\"
  15 .\" You should have received a copy of the GNU General Public License version
  16 .\" 2 along with this work; if not, write to the Free Software Foundation,
  17 .\" Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
  18 .\"
  19 .\" Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
  20 .\" or visit www.oracle.com if you need additional information or have any
  21 .\" questions.
  22 .\"
  23 .\"     Arch: generic
  24 .\"     Software: JDK 8
  25 .\"     Date: 03 March 2015
  26 .\"     SectDesc: Basic Tools
  27 .\"     Title: javac.1
  28 .\"
  29 .if n .pl 99999
  30 .TH javac 1 "03 March 2015" "JDK 8" "Basic Tools"
  31 .\" -----------------------------------------------------------------
  32 .\" * Define some portability stuff
  33 .\" -----------------------------------------------------------------
  34 .\" ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
  35 .\" http://bugs.debian.org/507673
  36 .\" http://lists.gnu.org/archive/html/groff/2009-02/msg00013.html
  37 .\" ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
  38 .ie \n(.g .ds Aq \(aq
  39 .el       .ds Aq '
  40 .\" -----------------------------------------------------------------
  41 .\" * set default formatting
  42 .\" -----------------------------------------------------------------
  43 .\" disable hyphenation
  44 .nh
  45 .\" disable justification (adjust text to left margin only)
  46 .ad l
  47 .\" -----------------------------------------------------------------
  48 .\" * MAIN CONTENT STARTS HERE *
  49 .\" -----------------------------------------------------------------
  50 
  51 .SH NAME    
  52 javac \- Reads Java class and interface definitions and compiles them into bytecode and class files\&.
  53 .SH SYNOPSIS    
  54 .sp     
  55 .nf     
  56 
  57 \fBjavac\fR [ \fIoptions\fR ] [ \fIsourcefiles\fR ] [ \fIclasses\fR] [ \fI@argfiles\fR ]
  58 .fi     
  59 .sp     
  60 Arguments can be in any order:
  61 .TP     
  62 \fIoptions\fR
  63 Command-line options\&. See Options\&.
  64 .TP     
  65 \fIsourcefiles\fR
  66 One or more source files to be compiled (such as \f3MyClass\&.java\fR)\&.
  67 .TP     
  68 \fIclasses\fR
  69 One or more classes to be processed for annotations (such as \f3MyPackage\&.MyClass\fR)\&.
  70 .TP     
  71 \fI@argfiles\fR
  72 One or more files that list options and source files\&. The \f3-J\fR options are not allowed in these files\&. See Command-Line Argument Files\&.
  73 .SH DESCRIPTION    
  74 The \f3javac\fR command reads class and interface definitions, written in the Java programming language, and compiles them into bytecode class files\&. The \f3javac\fR command can also process annotations in Java source files and classes\&.
  75 .PP
  76 There are two ways to pass source code file names to \f3javac\fR\&.
  77 .TP 0.2i    
  78 \(bu
  79 For a small number of source files, list the file names on the command line\&.
  80 .TP 0.2i    
  81 \(bu
  82 For a large number of source files, list the file names in a file that is separated by blanks or line breaks\&. Use the list file name preceded by an at sign (@) with the \f3javac\fR command\&.
  83 .PP
  84 Source code file names must have \&.java suffixes, class file names must have \&.class suffixes, and both source and class files must have root names that identify the class\&. For example, a class called \f3MyClass\fR would be written in a source file called \f3MyClass\&.java\fR and compiled into a bytecode class file called \f3MyClass\&.class\fR\&.
  85 .PP
  86 Inner class definitions produce additional class files\&. These class files have names that combine the inner and outer class names, such as \f3MyClass$MyInnerClass\&.class\fR\&.
  87 .PP
  88 Arrange source files in a directory tree that reflects their package tree\&. For example, if all of your source files are in \f3/workspace\fR, then put the source code for \f3com\&.mysoft\&.mypack\&.MyClass\fR in \f3/workspace/com/mysoft/mypack/MyClass\&.java\fR\&.
  89 .PP
  90 By default, the compiler puts each class file in the same directory as its source file\&. You can specify a separate destination directory with the \f3-d\fR option\&.
  91 .SH OPTIONS    
  92 The compiler has a set of standard options that are supported on the current development environment\&. An additional set of nonstandard options are specific to the current virtual machine and compiler implementations and are subject to change in the future\&. Nonstandard options begin with the \f3-X\fR option\&.
  93 .TP 0.2i    
  94 \(bu
  95 See also Cross-Compilation Options
  96 .TP 0.2i    
  97 \(bu
  98 See also Nonstandard Options
  99 .SS STANDARD\ OPTIONS    
 100 .TP
 101 -A\fIkey\fR[\fI=value\fR]
 102 .br
 103 Specifies options to pass to annotation processors\&. These options are not interpreted by \f3javac\fR directly, but are made available for use by individual processors\&. The \f3key\fR value should be one or more identifiers separated by a dot (\&.)\&.
 104 .TP
 105 -cp \fIpath\fR or -classpath \fIpath\fR
 106 .br
 107 Specifies where to find user class files, and (optionally) annotation processors and source files\&. This class path overrides the user class path in the \f3CLASSPATH\fR environment variable\&. If neither \f3CLASSPATH\fR, \f3-cp\fR nor \f3-classpath\fR is specified, then the user \fIclass path\fR is the current directory\&. See Setting the Class Path\&.
 108 
 109 If the \f3-sourcepath\fR option is not specified, then the user class path is also searched for source files\&.
 110 
 111 If the \f3-processorpath\fR option is not specified, then the class path is also searched for annotation processors\&.























































































































































































































































































































































































































































































































































































































































































































































































 112 .TP
 113 -Djava\&.ext\&.dirs=\fIdirectories\fR
 114 .br
 115 Overrides the location of installed extensions\&.
 116 .TP
 117 -Djava\&.endorsed\&.dirs=\fIdirectories\fR
 118 .br
 119 Overrides the location of the endorsed standards path\&.
 120 .TP
 121 -d \fIdirectory\fR
 122 .br
 123 Sets the destination directory for class files\&. The directory must already exist because \f3javac\fR does not create it\&. If a class is part of a package, then \f3javac\fR puts the class file in a subdirectory that reflects the package name and creates directories as needed\&.
 124 
 125 If you specify \f3-d\fR\f3/home/myclasses\fR and the class is called \f3com\&.mypackage\&.MyClass\fR, then the class file is \f3/home/myclasses/com/mypackage/MyClass\&.class\fR\&.
 126 
 127 If the \fI-d\fR option is not specified, then \f3javac\fR puts each class file in the same directory as the source file from which it was generated\&.
 128 
 129 \fINote:\fR The directory specified by the \fI-d\fR option is not automatically added to your user class path\&.
 130 .TP
 131 -deprecation
 132 .br
 133 Shows a description of each use or override of a deprecated member or class\&. Without the \f3-deprecation\fR option, \f3javac\fR shows a summary of the source files that use or override deprecated members or classes\&. The \f3-deprecation\fR option is shorthand for \f3-Xlint:deprecation\fR\&.
 134 .TP
 135 -encoding \fIencoding\fR
 136 .br
 137 Sets the source file encoding name, such as EUC-JP and UTF-8\&. If the \f3-encoding\fR option is not specified, then the platform default converter is used\&.
 138 .TP
 139 -endorseddirs \fIdirectories\fR
 140 .br
 141 Overrides the location of the endorsed standards path\&.
 142 .TP
 143 -extdirs \fIdirectories\fR
 144 .br
 145 Overrides the location of the \f3ext\fR directory\&. The directories variable is a colon-separated list of directories\&. Each JAR file in the specified directories is searched for class files\&. All JAR files found become part of the class path\&.
 146 
 147 If you are cross-compiling (compiling classes against bootstrap and extension classes of a different Java platform implementation), then this option specifies the directories that contain the extension classes\&. See Cross-Compilation Options for more information\&.
 148 .TP
 149 -g
 150 .br
 151 Generates all debugging information, including local variables\&. By default, only line number and source file information is generated\&.
 152 .TP
 153 -g:none
 154 .br
 155 Does not generate any debugging information\&.
 156 .TP
 157 -g:[\fIkeyword list\fR]
 158 .br
 159 Generates only some kinds of debugging information, specified by a comma separated list of keywords\&. Valid keywords are:
 160 .RS     
 161 .TP     
 162 source
 163 Source file debugging information\&.
 164 .TP     
 165 lines
 166 Line number debugging information\&.
 167 .TP     
 168 vars
 169 Local variable debugging information\&.
 170 .RE     
 171 
 172 .TP
 173 -help
 174 .br
 175 Prints a synopsis of standard options\&.
 176 .TP
 177 -implicit:[\fIclass, none\fR]
 178 .br
 179 Controls the generation of class files for implicitly loaded source files\&. To automatically generate class files, use \f3-implicit:class\fR\&. To suppress class file generation, use \f3-implicit:none\fR\&. If this option is not specified, then the default is to automatically generate class files\&. In this case, the compiler issues a warning if any such class files are generated when also doing annotation processing\&. The warning is not issued when the \f3-implicit\fR option is set explicitly\&. See Searching for Types\&.
 180 .TP
 181 -J\fIoption\fR
 182 .br
 183 Passes \f3option\fR to the Java Virtual Machine (JVM), where option is one of the options described on the reference page for the Java launcher\&. For example, \f3-J-Xms48m\fR sets the startup memory to 48 MB\&. See java(1)\&.
 184 
 185 \fINote:\fR The \fICLASSPATH\fR, \f3-classpath\fR, \f3-bootclasspath\fR, and \f3-extdirs\fR options do not specify the classes used to run \f3javac\fR\&. Trying to customize the compiler implementation with these options and variables is risky and often does not accomplish what you want\&. If you must customize the complier implementation, then use the \f3-J\fR option to pass options through to the underlying \f3\fRJava launcher\&.
 186 .TP
 187 -nowarn
 188 .br
 189 Disables warning messages\&. This option operates the same as the \f3-Xlint:none\fR option\&.
 190 .TP
 191 -parameters
 192 .br
 193 Stores formal parameter names of constructors and methods in the generated class file so that the method \f3java\&.lang\&.reflect\&.Executable\&.getParameters\fR from the Reflection API can retrieve them\&.
 194 .TP
 195 -proc: [\fInone\fR, \fIonly\fR]
 196 .br
 197 Controls whether annotation processing and compilation are done\&. \f3-proc:none\fR means that compilation takes place without annotation processing\&. \f3-proc:only\fR means that only annotation processing is done, without any subsequent compilation\&.
 198 .TP
 199 -processor \fIclass1\fR [,\fIclass2\fR,\fIclass3\fR\&.\&.\&.]
 200 .br
 201 Names of the annotation processors to run\&. This bypasses the default discovery process\&.
 202 .TP
 203 -processorpath \fIpath\fR
 204 .br
 205 Specifies where to find annotation processors\&. If this option is not used, then the class path is searched for processors\&.
 206 .TP
 207 -s \fIdir\fR
 208 .br
 209 Specifies the directory where to place the generated source files\&. The directory must already exist because \f3javac\fR does not create it\&. If a class is part of a package, then the compiler puts the source file in a subdirectory that reflects the package name and creates directories as needed\&.
 210 
 211 If you specify \f3-s /home/mysrc\fR and the class is called \f3com\&.mypackage\&.MyClass\fR, then the source file is put in \f3/home/mysrc/com/mypackage/MyClass\&.java\fR\&.
 212 .TP
 213 -source \fIrelease\fR
 214 .br
 215 Specifies the version of source code accepted\&. The following values for \f3release\fR are allowed:
 216 .RS     
 217 .TP     
 218 1\&.3
 219 The compiler does not support assertions, generics, or other language features introduced after Java SE 1\&.3\&.
 220 .TP     
 221 1\&.4
 222 The compiler accepts code containing assertions, which were introduced in Java SE 1\&.4\&.
 223 .TP     
 224 1\&.5
 225 The compiler accepts code containing generics and other language features introduced in Java SE 5\&.
 226 .TP     
 227 5
 228 Synonym for 1\&.5\&.
 229 .TP     
 230 1\&.6
 231 No language changes were introduced in Java SE 6\&. However, encoding errors in source files are now reported as errors instead of warnings as in earlier releases of Java Platform, Standard Edition\&.
 232 .TP     
 233 6
 234 Synonym for 1\&.6\&.
 235 .TP     
 236 1\&.7
 237 The compiler accepts code with features introduced in Java SE 7\&.
 238 .TP     
 239 7
 240 Synonym for 1\&.7\&.
 241 .TP     
 242 1\&.8
 243 This is the default value\&. The compiler accepts code with features introduced in Java SE 8\&.
 244 .TP     
 245 8
 246 Synonym for 1\&.8\&.
 247 .RE     
 248 
 249 .TP
 250 -sourcepath \fIsourcepath\fR
 251 .br
 252 Specifies the source code path to search for class or interface definitions\&. As with the user class path, source path entries are separated by colons (:) on Oracle Solaris and semicolons on Windows and can be directories, JAR archives, or ZIP archives\&. If packages are used, then the local path name within the directory or archive must reflect the package name\&.
 253 
 254 \fINote:\fR Classes found through the class path might be recompiled when their source files are also found\&. See Searching for Types\&.
 255 .TP
 256 -verbose
 257 .br
 258 Uses verbose output, which includes information about each class loaded and each source file compiled\&.
 259 .TP
 260 -version
 261 .br
 262 Prints release information\&.
 263 .TP
 264 -werror
 265 .br
 266 Terminates compilation when warnings occur\&.
 267 .TP
 268 -X
 269 .br
 270 Displays information about nonstandard options and exits\&.
 271 .SS CROSS-COMPILATION\ OPTIONS    
 272 By default, classes are compiled against the bootstrap and extension classes of the platform that \f3javac\fR shipped with\&. But \f3javac\fR also supports cross-compiling, where classes are compiled against a bootstrap and extension classes of a different Java platform implementation\&. It is important to use the \f3-bootclasspath\fR and \f3-extdirs\fR options when cross-compiling\&.
 273 .TP
 274 -target \fIversion\fR
 275 .br
 276 Generates class files that target a specified release of the virtual machine\&. Class files will run on the specified target and on later releases, but not on earlier releases of the JVM\&. Valid targets are 1\&.1, 1\&.2, 1\&.3, 1\&.4, 1\&.5 (also 5), 1\&.6 (also 6), 1\&.7 (also 7), and 1\&.8 (also 8)\&.
 277 
 278 The default for the \f3-target\fR option depends on the value of the \f3-source\fR option:
 279 .RS     
 280 .TP 0.2i    
 281 \(bu
 282 If the \f3-source\fR option is not specified, then the value of the \f3-target\fR option is 1\&.8
 283 .TP 0.2i    
 284 \(bu
 285 If the \f3-source\fR option is 1\&.2, then the value of the \f3-target\fR option is 1\&.4
 286 .TP 0.2i    
 287 \(bu
 288 If the \f3-source\fR option is 1\&.3, then the value of the \f3-target\fR option is 1\&.4
 289 .TP 0.2i    
 290 \(bu
 291 If the \f3-source\fR option is 1\&.5, then the value of the \f3-target\fR option is 1\&.8
 292 .TP 0.2i    
 293 \(bu
 294 If the \f3-source\fR option is 1\&.6, then the value of the \f3-target\fR is option 1\&.8
 295 .TP 0.2i    
 296 \(bu
 297 If the \f3-source\fR option is 1\&.7, then the value of the \f3-target\fR is option 1\&.8
 298 .TP 0.2i    
 299 \(bu
 300 For all other values of the \f3-source\fR option, the value of the \f3-target\fR option is the value of the \f3-source\fR option\&.
 301 .RE     
 302 
 303 .TP
 304 -bootclasspath \fIbootclasspath\fR
 305 .br
 306 Cross-compiles against the specified set of boot classes\&. As with the user class path, boot class path entries are separated by colons (:) and can be directories, JAR archives, or ZIP archives\&.
 307 .SS COMPACT\ PROFILE\ OPTION    
 308 Beginning with JDK 8, the \f3javac\fR compiler supports compact profiles\&. With compact profiles, applications that do not require the entire Java platform can be deployed and run with a smaller footprint\&. The compact profiles feature could be used to shorten the download time for applications from app stores\&. This feature makes for more compact deployment of Java applications that bundle the JRE\&. This feature is also useful in small devices\&.
 309 .PP
 310 The supported profile values are \f3compact1\fR, \f3compact2\fR, and \f3compact3\fR\&. These are additive layers\&. Each higher-numbered compact profile contains all of the APIs in profiles with smaller number names\&.
 311 .TP
 312 -profile
 313 .br
 314 When using compact profiles, this option specifies the profile name when compiling\&. For example:
 315 .sp     
 316 .nf     
 317 \f3javac \-profile compact1 Hello\&.java\fP
 318 .fi     
 319 .nf     
 320 \f3\fP
 321 .fi     
 322 .sp     
 323 
 324 
 325 javac does not compile source code that uses any Java SE APIs that is not in the specified profile\&. Here is an example of the error message that results from attempting to compile such source code:
 326 .sp     
 327 .nf     
 328 \f3cd jdk1\&.8\&.0/bin\fP
 329 .fi     
 330 .nf     
 331 \f3\&./javac \-profile compact1 Paint\&.java\fP
 332 .fi     
 333 .nf     
 334 \f3Paint\&.java:5: error: Applet is not available in profile \&'compact1\&'\fP
 335 .fi     
 336 .nf     
 337 \f3import java\&.applet\&.Applet;\fP
 338 .fi     
 339 .nf     
 340 \f3\fP
 341 .fi     
 342 .sp     
 343 
 344 
 345 In this example, you can correct the error by modifying the source to not use the \f3Applet\fR class\&. You could also correct the error by compiling without the -profile option\&. Then the compilation would be run against the full set of Java SE APIs\&. (None of the compact profiles include the \f3Applet\fR class\&.)
 346 
 347 An alternative way to compile with compact profiles is to use the \f3-bootclasspath\fR option to specify a path to an \f3rt\&.jar\fR file that specifies a profile\&'s image\&. Using the \f3-profile\fR option instead does not require a profile image to be present on the system at compile time\&. This is useful when cross-compiling\&.
 348 .SS NONSTANDARD\ OPTIONS    
 349 .TP
 350 -Xbootclasspath/p:\fIpath\fR
 351 .br
 352 Adds a suffix to the bootstrap class path\&.
 353 .TP
 354 -Xbootclasspath/a:\fIpath\fR
 355 .br
 356 Adds a prefix to the bootstrap class path\&.
 357 .TP
 358 -Xbootclasspath/:\fIpath\fR
 359 .br
 360 Overrides the location of the bootstrap class files\&.
 361 .TP
 362 -Xdoclint:[-]\fIgroup\fR [\fI/access\fR]
 363 .br
 364 Enables or disables specific groups of checks, where \fIgroup\fR is one of the following values: \f3accessibility\fR, \f3syntax\fR, \f3reference\fR, \f3html\fR or \f3missing\fR\&. For more information about these groups of checks see the \f3-Xdoclint\fR option of the \f3javadoc\fR command\&. The \f3-Xdoclint\fR option is disabled by default in the \f3javac\fR command\&.
 365 
 366 The variable \fIaccess\fR specifies the minimum visibility level of classes and members that the \f3-Xdoclint\fR option checks\&. It can have one of the following values (in order of most to least visible) : \f3public\fR, \f3protected\fR, \f3package\fR and \f3private\fR\&. For example, the following option checks classes and members (with all groups of checks) that have the access level protected and higher (which includes protected, package and public):
 367 .sp     
 368 .nf     
 369 \f3\-Xdoclint:all/protected\fP
 370 .fi     
 371 .nf     
 372 \f3\fP
 373 .fi     
 374 .sp     
 375 
 376 
 377 The following option enables all groups of checks for all access levels, except it will not check for HTML errors for classes and members that have access level package and higher (which includes package and public):
 378 .sp     
 379 .nf     
 380 \f3\-Xdoclint:all,\-html/package\fP
 381 .fi     
 382 .nf     
 383 \f3\fP
 384 .fi     
 385 .sp     
 386 







 387 .TP
 388 -Xdoclint:none
 389 .br
 390 Disables all groups of checks\&.
 391 .TP
 392 -Xdoclint:all[\fI/access\fR]
 393 .br
 394 Enables all groups of checks\&.
 395 .TP
 396 -Xlint
 397 .br
 398 \fI\fREnables all recommended warnings\&. In this release, enabling all available warnings is recommended\&.
 399 .TP
 400 -Xlint:all
 401 .br
 402 \fI\fREnables all recommended warnings\&. In this release, enabling all available warnings is recommended\&.
 403 .TP
 404 -Xlint:none
 405 .br
 406 Disables all warnings\&.
 407 .TP
 408 -Xlint:\fIname\fR
 409 .br
 410 Disables warning name\&. See Enable or Disable Warnings with the -Xlint Option for a list of warnings you can disable with this option\&.
 411 .TP
 412 -Xlint:\fI-name\fR
 413 .br
 414 Disables warning name\&. See Enable or Disable Warnings with the -Xlint Option with the \f3-Xlint\fR option to get a list of warnings that you can disable with this option\&.
 415 .TP
 416 -Xmaxerrs \fInumber\fR
 417 .br
 418 Sets the maximum number of errors to print\&.
 419 .TP
 420 -Xmaxwarns \fInumber\fR
 421 .br
 422 Sets the maximum number of warnings to print\&.
 423 .TP
 424 -Xstdout \fIfilename\fR
 425 .br
 426 Sends compiler messages to the named file\&. By default, compiler messages go to \f3System\&.err\fR\&.
 427 .TP
 428 -Xprefer:[\fInewer,source\fR]
 429 .br
 430 Specifies which file to read when both a source file and class file are found for a type\&. (See Searching for Types)\&. If the \f3-Xprefer:newer\fR option is used, then it reads the newer of the source or class file for a type (default)\&. If the \f3-Xprefer:source\fR option is used, then it reads the source file\&. Use -\f3Xprefer:source\fR when you want to be sure that any annotation processors can access annotations declared with a retention policy of \f3SOURCE\fR\&.
 431 .TP
 432 -Xpkginfo:[\fIalways\fR,\fIlegacy\fR,\fInonempty\fR]
 433 .br
 434 Control whether javac generates \f3package-info\&.class\fR files from package-info\&.java files\&. Possible mode arguments for this option include the following\&.
 435 .RS     
 436 .TP     
 437 always
 438 Always generate a \f3package-info\&.class\fR file for every \f3package-info\&.java\fR file\&. This option may be useful if you use a build system such as Ant, which checks that each \f3\&.java\fR file has a corresponding \f3\&.class\fR file\&.
 439 .TP     
 440 legacy
 441 Generate a \f3package-info\&.class\fR file only if package-info\&.java contains annotations\&. Don\&'t generate a \f3package-info\&.class\fR file if package-info\&.java only contains comments\&.
 442 
 443 \fINote:\fR A \f3package-info\&.class\fR file might be generated but be empty if all the annotations in the package-info\&.java file have \f3RetentionPolicy\&.SOURCE\fR\&.
 444 .TP     
 445 nonempty
 446 Generate a \f3package-info\&.class\fR file only if package-info\&.java contains annotations with \f3RetentionPolicy\&.CLASS\fR or \f3RetentionPolicy\&.RUNTIME\fR\&.
 447 .RE     
 448 
 449 .TP
 450 -Xprint
 451 .br
 452 Prints a textual representation of specified types for debugging purposes\&. Perform neither annotation processing nor compilation\&. The format of the output could change\&.
 453 .TP
 454 -XprintProcessorInfo
 455 .br
 456 Prints information about which annotations a processor is asked to process\&.
 457 .TP
 458 -XprintRounds
 459 .br
 460 Prints information about initial and subsequent annotation processing rounds\&.
 461 .SH ENABLE\ OR\ DISABLE\ WARNINGS\ WITH\ THE\ -XLINT\ OPTION    
 462 Enable warning \fIname\fR with the \f3-Xlint:name\fR option, where \f3name\fR is one of the following warning names\&. Note that you can disable a warning with the \f3-Xlint:-name:\fR option\&.
 463 .TP     
 464 cast
 465 Warns about unnecessary and redundant casts, for example:
 466 .sp     
 467 .nf     
 468 \f3String s = (String) "Hello!"\fP
 469 .fi     
 470 .nf     
 471 \f3\fP
 472 .fi     
 473 .sp     
 474 
 475 .TP     
 476 classfile
 477 Warns about issues related to class file contents\&.
 478 .TP     
 479 deprecation
 480 Warns about the use of deprecated items, for example:
 481 .sp     
 482 .nf     
 483 \f3java\&.util\&.Date myDate = new java\&.util\&.Date();\fP
 484 .fi     
 485 .nf     
 486 \f3int currentDay = myDate\&.getDay();\fP
 487 .fi     
 488 .nf     
 489 \f3\fP
 490 .fi     
 491 .sp     
 492 
 493 
 494 The method \f3java\&.util\&.Date\&.getDay\fR has been deprecated since JDK 1\&.1
 495 .TP     
 496 dep-ann
 497 Warns about items that are documented with an \f3@deprecated\fR Javadoc comment, but do not have a \f3@Deprecated\fR annotation, for example:
 498 .sp     
 499 .nf     
 500 \f3/**\fP
 501 .fi     
 502 .nf     
 503 \f3  * @deprecated As of Java SE 7, replaced by {@link #newMethod()}\fP
 504 .fi     
 505 .nf     
 506 \f3  */\fP
 507 .fi     
 508 .nf     
 509 \f3public static void deprecatedMethood() { }\fP
 510 .fi     
 511 .nf     
 512 \f3public static void newMethod() { }\fP
 513 .fi     
 514 .nf     
 515 \f3\fP
 516 .fi     
 517 .sp     
 518 
 519 .TP     
 520 divzero
 521 Warns about division by the constant integer 0, for example:
 522 .sp     
 523 .nf     
 524 \f3int divideByZero = 42 / 0;\fP
 525 .fi     
 526 .nf     
 527 \f3\fP
 528 .fi     
 529 .sp     
 530 
 531 .TP     
 532 empty
 533 Warns about empty statements after \f3if\fRstatements, for example:
 534 .sp     
 535 .nf     
 536 \f3class E {\fP
 537 .fi     
 538 .nf     
 539 \f3    void m() {\fP
 540 .fi     
 541 .nf     
 542 \f3         if (true) ;\fP
 543 .fi     
 544 .nf     
 545 \f3    }\fP
 546 .fi     
 547 .nf     
 548 \f3}\fP
 549 .fi     
 550 .nf     
 551 \f3\fP
 552 .fi     
 553 .sp     
 554 
 555 .TP     
 556 fallthrough
 557 Checks the switch blocks for fall-through cases and provides a warning message for any that are found\&. Fall-through cases are cases in a switch block, other than the last case in the block, whose code does not include a break statement, allowing code execution to fall through from that case to the next case\&. For example, the code following the case 1 label in this switch block does not end with a break statement:
 558 .sp     
 559 .nf     
 560 \f3switch (x) {\fP
 561 .fi     
 562 .nf     
 563 \f3case 1:\fP
 564 .fi     
 565 .nf     
 566 \f3  System\&.out\&.println("1");\fP
 567 .fi     
 568 .nf     
 569 \f3  // No break statement here\&.\fP
 570 .fi     
 571 .nf     
 572 \f3case 2:\fP
 573 .fi     
 574 .nf     
 575 \f3  System\&.out\&.println("2");\fP
 576 .fi     
 577 .nf     
 578 \f3}\fP
 579 .fi     
 580 .nf     
 581 \f3\fP
 582 .fi     
 583 .sp     
 584 
 585 
 586 If the \f3-Xlint:fallthrough\fR option was used when compiling this code, then the compiler emits a warning about possible fall-through into case, with the line number of the case in question\&.
 587 .TP     
 588 finally
 589 Warns about \f3finally\fR clauses that cannot complete normally, for example:
 590 .sp     
 591 .nf     
 592 \f3public static int m() {\fP
 593 .fi     
 594 .nf     
 595 \f3  try {\fP
 596 .fi     
 597 .nf     
 598 \f3     throw new NullPointerException();\fP
 599 .fi     
 600 .nf     
 601 \f3  }  catch (NullPointerException(); {\fP
 602 .fi     
 603 .nf     
 604 \f3     System\&.err\&.println("Caught NullPointerException\&.");\fP
 605 .fi     
 606 .nf     
 607 \f3     return 1;\fP
 608 .fi     
 609 .nf     
 610 \f3   } finally {\fP
 611 .fi     
 612 .nf     
 613 \f3     return 0;\fP
 614 .fi     
 615 .nf     
 616 \f3   }\fP
 617 .fi     
 618 .nf     
 619 \f3  }\fP
 620 .fi     
 621 .nf     
 622 \f3\fP
 623 .fi     
 624 .sp     
 625 
 626 
 627 The compiler generates a warning for the \f3finally\fR block in this example\&. When the \f3int\fR method is called, it returns a value of 0\&. A \f3finally\fR block executes when the \f3try\fR block exits\&. In this example, when control is transferred to the \f3catch\fR block, the \f3int\fR method exits\&. However, the \f3finally\fR block must execute, so it is executed, even though control was transferred outside the method\&.
 628 .TP     
 629 options
 630 Warns about issues that related to the use of command-line options\&. See Cross-Compilation Options\&.
 631 .TP     
 632 overrides
 633 Warns about issues regarding method overrides\&. For example, consider the following two classes:
 634 .sp     
 635 .nf     
 636 \f3public class ClassWithVarargsMethod {\fP
 637 .fi     
 638 .nf     
 639 \f3  void varargsMethod(String\&.\&.\&. s) { }\fP
 640 .fi     
 641 .nf     
 642 \f3}\fP
 643 .fi     
 644 .nf     
 645 \f3\fP
 646 .fi     
 647 .nf     
 648 \f3public class ClassWithOverridingMethod extends ClassWithVarargsMethod {\fP
 649 .fi     
 650 .nf     
 651 \f3   @Override\fP
 652 .fi     
 653 .nf     
 654 \f3   void varargsMethod(String[] s) { }\fP
 655 .fi     
 656 .nf     
 657 \f3}\fP
 658 .fi     
 659 .nf     
 660 \f3\fP
 661 .fi     
 662 .sp     
 663 
 664 
 665 The compiler generates a warning similar to the following:\&.
 666 .sp     
 667 .nf     
 668 \f3warning: [override] varargsMethod(String[]) in ClassWithOverridingMethod \fP
 669 .fi     
 670 .nf     
 671 \f3overrides varargsMethod(String\&.\&.\&.) in ClassWithVarargsMethod; overriding\fP
 672 .fi     
 673 .nf     
 674 \f3method is missing \&'\&.\&.\&.\&'\fP
 675 .fi     
 676 .nf     
 677 \f3\fP
 678 .fi     
 679 .sp     
 680 
 681 
 682 When the compiler encounters a \f3varargs\fR method, it translates the \f3varargs\fR formal parameter into an array\&. In the method \f3ClassWithVarargsMethod\&.varargsMethod\fR, the compiler translates the \f3varargs\fR formal parameter \f3String\&.\&.\&. s\fR to the formal parameter \f3String[] s\fR, an array, which matches the formal parameter of the method \f3ClassWithOverridingMethod\&.varargsMethod\fR\&. Consequently, this example compiles\&.
 683 .TP     
 684 path
 685 Warns about invalid path elements and nonexistent path directories on the command line (with regard to the class path, the source path, and other paths)\&. Such warnings cannot be suppressed with the \f3@SuppressWarnings\fR annotation, for example:
 686 .sp     
 687 .nf     
 688 \f3javac \-Xlint:path \-classpath /nonexistentpath Example\&.java\fP
 689 .fi     
 690 .nf     
 691 \f3\fP
 692 .fi     
 693 .sp     
 694 
 695 .TP     
 696 processing
 697 Warn about issues regarding annotation processing\&. The compiler generates this warning when you have a class that has an annotation, and you use an annotation processor that cannot handle that type of exception\&. For example, the following is a simple annotation processor:
 698 
 699 \fISource file AnnocProc\&.java\fR:
 700 .sp     
 701 .nf     
 702 \f3import java\&.util\&.*;\fP
 703 .fi     
 704 .nf     
 705 \f3import javax\&.annotation\&.processing\&.*;\fP
 706 .fi     
 707 .nf     
 708 \f3import javax\&.lang\&.model\&.*;\fP
 709 .fi     
 710 .nf     
 711 \f3import\&.javaz\&.lang\&.model\&.element\&.*;\fP
 712 .fi     
 713 .nf     
 714 \f3\fP
 715 .fi     
 716 .nf     
 717 \f3@SupportedAnnotationTypes("NotAnno")\fP
 718 .fi     
 719 .nf     
 720 \f3public class AnnoProc extends AbstractProcessor {\fP
 721 .fi     
 722 .nf     
 723 \f3  public boolean process(Set<? extends TypeElement> elems, RoundEnvironment renv){\fP
 724 .fi     
 725 .nf     
 726 \f3     return true;\fP
 727 .fi     
 728 .nf     
 729 \f3  }\fP
 730 .fi     
 731 .nf     
 732 \f3\fP
 733 .fi     
 734 .nf     
 735 \f3  public SourceVersion getSupportedSourceVersion() {\fP
 736 .fi     
 737 .nf     
 738 \f3     return SourceVersion\&.latest();\fP
 739 .fi     
 740 .nf     
 741 \f3   }\fP
 742 .fi     
 743 .nf     
 744 \f3}\fP
 745 .fi     
 746 .nf     
 747 \f3\fP
 748 .fi     
 749 .sp     
 750 
 751 
 752 \fISource file AnnosWithoutProcessors\&.java\fR:
 753 .sp     
 754 .nf     
 755 \f3@interface Anno { }\fP
 756 .fi     
 757 .nf     
 758 \f3\fP
 759 .fi     
 760 .nf     
 761 \f3@Anno\fP
 762 .fi     
 763 .nf     
 764 \f3class AnnosWithoutProcessors { }\fP
 765 .fi     
 766 .nf     
 767 \f3\fP
 768 .fi     
 769 .sp     
 770 
 771 
 772 The following commands compile the annotation processor \f3AnnoProc\fR, then run this annotation processor against the source file \f3AnnosWithoutProcessors\&.java\fR:
 773 .sp     
 774 .nf     
 775 \f3javac AnnoProc\&.java\fP
 776 .fi     
 777 .nf     
 778 \f3javac \-cp \&. \-Xlint:processing \-processor AnnoProc \-proc:only AnnosWithoutProcessors\&.java\fP
 779 .fi     
 780 .nf     
 781 \f3\fP
 782 .fi     
 783 .sp     
 784 
 785 
 786 When the compiler runs the annotation processor against the source file \f3AnnosWithoutProcessors\&.java\fR, it generates the following warning:
 787 .sp     
 788 .nf     
 789 \f3warning: [processing] No processor claimed any of these annotations: Anno\fP
 790 .fi     
 791 .nf     
 792 \f3\fP
 793 .fi     
 794 .sp     
 795 
 796 
 797 To resolve this issue, you can rename the annotation defined and used in the class \f3AnnosWithoutProcessors\fR from \f3Anno\fR to \f3NotAnno\fR\&.
 798 .TP     
 799 rawtypes
 800 Warns about unchecked operations on raw types\&. The following statement generates a \f3rawtypes\fR warning:
 801 .sp     
 802 .nf     
 803 \f3void countElements(List l) { \&.\&.\&. }\fP
 804 .fi     
 805 .nf     
 806 \f3\fP
 807 .fi     
 808 .sp     
 809 
 810 
 811 The following example does not generate a \f3rawtypes\fR warning
 812 .sp     
 813 .nf     
 814 \f3void countElements(List<?> l) { \&.\&.\&. }\fP
 815 .fi     
 816 .nf     
 817 \f3\fP
 818 .fi     
 819 .sp     
 820 
 821 
 822 \f3List\fR is a raw type\&. However, \f3List<?>\fR is an unbounded wildcard parameterized type\&. Because \f3List\fR is a parameterized interface, always specify its type argument\&. In this example, the \f3List\fR formal argument is specified with an unbounded wildcard (\f3?\fR) as its formal type parameter, which means that the \f3countElements\fR method can accept any instantiation of the \f3List\fR interface\&.
 823 .TP     
 824 Serial
 825 Warns about missing \f3serialVersionUID\fR definitions on serializable classes, for example:
 826 .sp     
 827 .nf     
 828 \f3public class PersistentTime implements Serializable\fP
 829 .fi     
 830 .nf     
 831 \f3{\fP
 832 .fi     
 833 .nf     
 834 \f3  private Date time;\fP
 835 .fi     
 836 .nf     
 837 \f3\fP
 838 .fi     
 839 .nf     
 840 \f3   public PersistentTime() {\fP
 841 .fi     
 842 .nf     
 843 \f3     time = Calendar\&.getInstance()\&.getTime();\fP
 844 .fi     
 845 .nf     
 846 \f3   }\fP
 847 .fi     
 848 .nf     
 849 \f3\fP
 850 .fi     
 851 .nf     
 852 \f3   public Date getTime() {\fP
 853 .fi     
 854 .nf     
 855 \f3     return time;\fP
 856 .fi     
 857 .nf     
 858 \f3   }\fP
 859 .fi     
 860 .nf     
 861 \f3}\fP
 862 .fi     
 863 .nf     
 864 \f3\fP
 865 .fi     
 866 .sp     
 867 
 868 
 869 The compiler generates the following warning:
 870 .sp     
 871 .nf     
 872 \f3warning: [serial] serializable class PersistentTime has no definition of\fP
 873 .fi     
 874 .nf     
 875 \f3serialVersionUID\fP
 876 .fi     
 877 .nf     
 878 \f3\fP
 879 .fi     
 880 .sp     
 881 
 882 
 883 If a serializable class does not explicitly declare a field named \f3serialVersionUID\fR, then the serialization runtime environment calculates a default \f3serialVersionUID\fR value for that class based on various aspects of the class, as described in the Java Object Serialization Specification\&. However, it is strongly recommended that all serializable classes explicitly declare \f3serialVersionUID\fR values because the default process of computing \f3serialVersionUID\fR vales is highly sensitive to class details that can vary depending on compiler implementations, and as a result, might cause an unexpected \f3InvalidClassExceptions\fR during deserialization\&. To guarantee a consistent \f3serialVersionUID\fR value across different Java compiler implementations, a serializable class must declare an explicit \f3serialVersionUID\fR value\&.
 884 .TP     
 885 static
 886 Warns about issues relating to the use of statics, for example:
 887 .sp     
 888 .nf     
 889 \f3class XLintStatic {\fP
 890 .fi     
 891 .nf     
 892 \f3    static void m1() { }\fP
 893 .fi     
 894 .nf     
 895 \f3    void m2() { this\&.m1(); }\fP
 896 .fi     
 897 .nf     
 898 \f3}\fP
 899 .fi     
 900 .nf     
 901 \f3\fP
 902 .fi     
 903 .sp     
 904 
 905 



 906 The compiler generates the following warning:
 907 .sp     
 908 .nf     
 909 \f3warning: [static] static method should be qualified by type name, \fP
 910 .fi     
 911 .nf     
 912 \f3XLintStatic, instead of by an expression\fP
 913 .fi     
 914 .nf     
 915 \f3\fP
 916 .fi     
 917 .sp     
 918 
 919 
 920 To resolve this issue, you can call the \f3static\fR method \f3m1\fR as follows:
 921 .sp     
 922 .nf     
 923 \f3XLintStatic\&.m1();\fP
 924 .fi     
 925 .nf     
 926 \f3\fP
 927 .fi     
 928 .sp     
 929 
 930 
 931 Alternately, you can remove the \f3static\fR keyword from the declaration of the method \f3m1\fR\&.
 932 .TP     
 933 try
 934 Warns about issues relating to use of \f3try\fR blocks, including try-with-resources statements\&. For example, a warning is generated for the following statement because the resource \f3ac\fR declared in the \f3try\fR block is not used:
 935 .sp     
 936 .nf     
 937 \f3try ( AutoCloseable ac = getResource() ) {    // do nothing}\fP
 938 .fi     
 939 .nf     
 940 \f3\fP
 941 .fi     
 942 .sp     
 943 
 944 .TP     
 945 unchecked
 946 Gives more detail for unchecked conversion warnings that are mandated by the Java Language Specification, for example:
 947 .sp     
 948 .nf     
 949 \f3List l = new ArrayList<Number>();\fP
 950 .fi     
 951 .nf     
 952 \f3List<String> ls = l;       // unchecked warning\fP
 953 .fi     
 954 .nf     
 955 \f3\fP
 956 .fi     
 957 .sp     
 958 
 959 
 960 During type erasure, the types \f3ArrayList<Number>\fR and \f3List<String>\fR become \f3ArrayList\fR and \f3List\fR, respectively\&.
 961 
 962 The \f3ls\fR command has the parameterized type \f3List<String>\fR\&. When the \f3List\fR referenced by \f3l\fR is assigned to \f3ls\fR, the compiler generates an unchecked warning\&. At compile time, the compiler and JVM cannot determine whether \f3l\fR refers to a \f3List<String>\fR type\&. In this case, \f3l\fR does not refer to a \f3List<String>\fR type\&. As a result, heap pollution occurs\&.
 963 
 964 A heap pollution situation occurs when the \f3List\fR object \f3l\fR, whose static type is \f3List<Number>\fR, is assigned to another \f3List\fR object, \f3ls\fR, that has a different static type, \f3List<String>\fR\&. However, the compiler still allows this assignment\&. It must allow this assignment to preserve backward compatibility with releases of Java SE that do not support generics\&. Because of type erasure, \f3List<Number>\fR and \f3List<String>\fR both become \f3List\fR\&. Consequently, the compiler allows the assignment of the object \f3l\fR\f3,\fR which has a raw type of \f3List\fR, to the object \f3ls\fR\&.
 965 .TP     
 966 varargs
 967 Warns about unsafe usages of variable arguments (\f3varargs\fR) methods, in particular, those that contain non-reifiable arguments, for example:
 968 .sp     
 969 .nf     
 970 \f3public class ArrayBuilder {\fP
 971 .fi     
 972 .nf     
 973 \f3  public static <T> void addToList (List<T> listArg, T\&.\&.\&. elements) {\fP
 974 .fi     
 975 .nf     
 976 \f3    for (T x : elements) {\fP
 977 .fi     
 978 .nf     
 979 \f3      listArg\&.add(x);\fP
 980 .fi     
 981 .nf     
 982 \f3    }\fP
 983 .fi     
 984 .nf     
 985 \f3  }\fP
 986 .fi     
 987 .nf     
 988 \f3}\fP
 989 .fi     
 990 .nf     
 991 \f3\fP
 992 .fi     
 993 .sp     
 994 
 995 
 996 \fINote:\fR A non-reifiable type is a type whose type information is not fully available at runtime\&.
 997 
 998 The compiler generates the following warning for the definition of the method \f3ArrayBuilder\&.addToList\fR
 999 .sp     
1000 .nf     
1001 \f3warning: [varargs] Possible heap pollution from parameterized vararg type T\fP
1002 .fi     
1003 .nf     
1004 \f3\fP
1005 .fi     
1006 .sp     
1007 
1008 
1009 When the compiler encounters a varargs method, it translates the \f3varargs\fR formal parameter into an array\&. However, the Java programming language does not permit the creation of arrays of parameterized types\&. In the method \f3ArrayBuilder\&.addToList\fR, the compiler translates the \f3varargs\fR formal parameter \f3T\&.\&.\&.\fR elements to the formal parameter \f3T[]\fR elements, an array\&. However, because of type erasure, the compiler converts the \f3varargs\fR formal parameter to \f3Object[]\fR elements\&. Consequently, there is a possibility of heap pollution\&.
1010 .SH COMMAND-LINE\ ARGUMENT\ FILES    
1011 To shorten or simplify the \f3javac\fR command, you can specify one or more files that contain arguments to the \f3javac\fR command (except \f3-J\fR options)\&. This enables you to create \f3javac\fR commands of any length on any operating system\&.
1012 .PP
1013 An argument file can include \f3javac\fR options and source file names in any combination\&. The arguments within a file can be separated by spaces or new line characters\&. If a file name contains embedded spaces, then put the whole file name in double quotation marks\&.
1014 .PP
1015 File Names within an argument file are relative to the current directory, not the location of the argument file\&. Wild cards (*) are not allowed in these lists (such as for specifying \f3*\&.java\fR)\&. Use of the at sign (@) to recursively interpret files is not supported\&. The \f3-J\fR options are not supported because they are passed to the launcher, which does not support argument files\&.
1016 .PP
1017 When executing the \f3javac\fR command, pass in the path and name of each argument file with the at sign (@) leading character\&. When the \f3javac\fR command encounters an argument beginning with the at sign (@), it expands the contents of that file into the argument list\&.
1018 .PP
1019 \f3Example 1 Single Argument File\fR
1020 .PP
1021 You could use a single argument file named \f3argfile\fR to hold all \f3javac\fR arguments:
1022 .sp     
1023 .nf     
1024 \f3javac @argfile\fP
1025 .fi     
1026 .nf     
1027 \f3\fP
1028 .fi     
1029 .sp     
1030 This argument file could contain the contents of both files shown in Example 2
1031 .PP
1032 \f3Example 2 Two Argument Files\fR
1033 .PP
1034 You can create two argument files: one for the \f3javac\fR options and the other for the source file names\&. Note that the following lists have no line-continuation characters\&.
1035 .PP
1036 Create a file named options that contains the following:
1037 .sp     
1038 .nf     
1039 \f3\-d classes\fP
1040 .fi     
1041 .nf     
1042 \f3\-g\fP
1043 .fi     
1044 .nf     
1045 \f3\-sourcepath /java/pubs/ws/1\&.3/src/share/classes\fP
1046 .fi     
1047 .nf     
1048 \f3\fP
1049 .fi     
1050 .sp     
1051 Create a file named classes that contains the following:
1052 .sp     
1053 .nf     
1054 \f3MyClass1\&.java\fP
1055 .fi     
1056 .nf     
1057 \f3MyClass2\&.java\fP
1058 .fi     
1059 .nf     
1060 \f3MyClass3\&.java\fP
1061 .fi     
1062 .nf     
1063 \f3\fP
1064 .fi     
1065 .sp     
1066 Then, run the \f3javac\fR command as follows:
1067 .sp     
1068 .nf     
1069 \f3javac @options @classes\fP
1070 .fi     
1071 .nf     
1072 \f3\fP
1073 .fi     
1074 .sp     
1075 \f3Example 3 Argument Files with Paths\fR
1076 .PP
1077 The argument files can have paths, but any file names inside the files are relative to the current working directory (not \f3path1\fR or \f3path2\fR):
1078 .sp     
1079 .nf     
1080 \f3javac @path1/options @path2/classes\fP
1081 .fi     
1082 .nf     
1083 \f3\fP
1084 .fi     
1085 .sp     
1086 .SH ANNOTATION\ PROCESSING    
1087 The \f3javac\fR command provides direct support for annotation processing, superseding the need for the separate annotation processing command, \f3apt\fR\&.
1088 .PP
1089 The API for annotation processors is defined in the \f3javax\&.annotation\&.processing\fR and j\f3avax\&.lang\&.model\fR packages and subpackages\&.
1090 .SS HOW\ ANNOTATION\ PROCESSING\ WORKS    
1091 Unless annotation processing is disabled with the \f3-proc:none\fR option, the compiler searches for any annotation processors that are available\&. The search path can be specified with the \f3-processorpath\fR option\&. If no path is specified, then the user class path is used\&. Processors are located by means of service provider-configuration files named \f3META-INF/services/javax\&.annotation\&.processing\fR\&.Processor on the search path\&. Such files should contain the names of any annotation processors to be used, listed one per line\&. Alternatively, processors can be specified explicitly, using the \f3-processor\fR option\&.
1092 .PP
1093 After scanning the source files and classes on the command line to determine what annotations are present, the compiler queries the processors to determine what annotations they process\&. When a match is found, the processor is called\&. A processor can claim the annotations it processes, in which case no further attempt is made to find any processors for those annotations\&. After all of the annotations are claimed, the compiler does not search for additional processors\&.
1094 .PP
1095 If any processors generate new source files, then another round of annotation processing occurs: Any newly generated source files are scanned, and the annotations processed as before\&. Any processors called on previous rounds are also called on all subsequent rounds\&. This continues until no new source files are generated\&.
1096 .PP
1097 After a round occurs where no new source files are generated, the annotation processors are called one last time, to give them a chance to complete any remaining work\&. Finally, unless the \f3-proc:only\fR option is used, the compiler compiles the original and all generated source files\&.
1098 .SS IMPLICITLY\ LOADED\ SOURCE\ FILES    
1099 To compile a set of source files, the compiler might need to implicitly load additional source files\&. See Searching for Types\&. Such files are currently not subject to annotation processing\&. By default, the compiler gives a warning when annotation processing occurred and any implicitly loaded source files are compiled\&. The \f3-implicit\fR option provides a way to suppress the warning\&.
1100 .SH SEARCHING\ FOR\ TYPES    
1101 To compile a source file, the compiler often needs information about a type, but the type definition is not in the source files specified on the command line\&. The compiler needs type information for every class or interface used, extended, or implemented in the source file\&. This includes classes and interfaces not explicitly mentioned in the source file, but that provide information through inheritance\&.
1102 .PP
1103 For example, when you create a subclass \f3java\&.applet\&.Applet\fR, you are also using the ancestor classes of \f3Applet\fR: \f3java\&.awt\&.Panel\fR, \f3java\&.awt\&.Container\fR, \f3java\&.awt\&.Component\fR, and \f3java\&.lang\&.Object\fR\&.
1104 .PP
1105 When the compiler needs type information, it searches for a source file or class file that defines the type\&. The compiler searches for class files first in the bootstrap and extension classes, then in the user class path (which by default is the current directory)\&. The user class path is defined by setting the \f3CLASSPATH\fR environment variable or by using the \f3-classpath\fR option\&.
1106 .PP
1107 If you set the \f3-sourcepath\fR option, then the compiler searches the indicated path for source files\&. Otherwise, the compiler searches the user class path for both class files and source files\&.
1108 .PP
1109 You can specify different bootstrap or extension classes with the \f3-bootclasspath\fR and the \f3-extdirs\fR options\&. See Cross-Compilation Options\&.
1110 .PP
1111 A successful type search may produce a class file, a source file, or both\&. If both are found, then you can use the \f3-Xprefer\fR option to instruct the compiler which to use\&. If \f3newer\fR is specified, then the compiler uses the newer of the two files\&. If \f3source\fR is specified, the compiler uses the source file\&. The default is \f3newer\fR\&.
1112 .PP
1113 If a type search finds a source file for a required type, either by itself, or as a result of the setting for the \f3-Xprefer\fR option, then the compiler reads the source file to get the information it needs\&. By default the compiler also compiles the source file\&. You can use the \f3-implicit\fR option to specify the behavior\&. If \f3none\fR is specified, then no class files are generated for the source file\&. If \f3class\fR is specified, then class files are generated for the source file\&.
1114 .PP
1115 The compiler might not discover the need for some type information until after annotation processing completes\&. When the type information is found in a source file and no \f3-implicit\fR option is specified, the compiler gives a warning that the file is being compiled without being subject to annotation processing\&. To disable the warning, either specify the file on the command line (so that it will be subject to annotation processing) or use the \f3-implicit\fR option to specify whether or not class files should be generated for such source files\&.
1116 .SH PROGRAMMATIC\ INTERFACE    
1117 The \f3javac\fR command supports the new Java Compiler API defined by the classes and interfaces in the \f3javax\&.tools\fR package\&.
1118 .SS EXAMPLE    
1119 To compile as though providing command-line arguments, use the following syntax:
1120 .sp     
1121 .nf     
1122 \f3JavaCompiler javac = ToolProvider\&.getSystemJavaCompiler();\fP
1123 .fi     
1124 .nf     
1125 \f3\fP
1126 .fi     
1127 .sp     
1128 The example writes diagnostics to the standard output stream and returns the exit code that \f3javac\fR would give when called from the command line\&.
1129 .PP
1130 You can use other methods in the \f3javax\&.tools\&.JavaCompiler\fR interface to handle diagnostics, control where files are read from and written to, and more\&.
1131 .SS OLD\ INTERFACE    
1132 \fINote:\fR This API is retained for backward compatibility only\&. All new code should use the newer Java Compiler API\&.
1133 .PP
1134 The \f3com\&.sun\&.tools\&.javac\&.Main\fR class provides two static methods to call the compiler from a program:
1135 .sp     
1136 .nf     
1137 \f3public static int compile(String[] args);\fP
1138 .fi     
1139 .nf     
1140 \f3public static int compile(String[] args, PrintWriter out);\fP
1141 .fi     
1142 .nf     
1143 \f3\fP
1144 .fi     
1145 .sp     
1146 The \f3args\fR parameter represents any of the command-line arguments that would typically be passed to the compiler\&.
1147 .PP
1148 The \f3out\fR parameter indicates where the compiler diagnostic output is directed\&.
1149 .PP
1150 The \f3return\fR value is equivalent to the \f3exit\fR value from \f3javac\fR\&.
1151 .PP
1152 \fINote:\fR All other classes and methods found in a package with names that start with \f3com\&.sun\&.tools\&.javac\fR (subpackages of \f3com\&.sun\&.tools\&.javac\fR) are strictly internal and subject to change at any time\&.
1153 .SH EXAMPLES    
1154 \f3Example 1 Compile a Simple Program\fR
1155 .PP
1156 This example shows how to compile the \f3Hello\&.java\fR source file in the greetings directory\&. The class defined in \f3Hello\&.java\fR is called \f3greetings\&.Hello\fR\&. The greetings directory is the package directory both for the source file and the class file and is underneath the current directory\&. This makes it possible to use the default user class path\&. It also makes it unnecessary to specify a separate destination directory with the \f3-d\fR option\&.
1157 .PP
1158 The source code in \f3Hello\&.java\fR:
1159 .sp     
1160 .nf     
1161 \f3package greetings;\fP
1162 .fi     
1163 .nf     
1164 \f3\fP
1165 .fi     
1166 .nf     
1167 \f3public class Hello {\fP
1168 .fi     
1169 .nf     
1170 \f3    public static void main(String[] args) {\fP
1171 .fi     
1172 .nf     
1173 \f3        for (int i=0; i < args\&.length; i++) {\fP
1174 .fi     
1175 .nf     
1176 \f3            System\&.out\&.println("Hello " + args[i]);\fP
1177 .fi     
1178 .nf     
1179 \f3        }\fP
1180 .fi     
1181 .nf     
1182 \f3    }\fP
1183 .fi     
1184 .nf     
1185 \f3}\fP
1186 .fi     
1187 .nf     
1188 \f3\fP
1189 .fi     
1190 .sp     
1191 Compile greetings\&.Hello:
1192 .sp     
1193 .nf     
1194 \f3javac greetings/Hello\&.java\fP
1195 .fi     
1196 .nf     
1197 \f3\fP
1198 .fi     
1199 .sp     
1200 Run \f3greetings\&.Hello\fR:
1201 .sp     
1202 .nf     
1203 \f3java greetings\&.Hello World Universe Everyone\fP
1204 .fi     
1205 .nf     
1206 \f3Hello World\fP
1207 .fi     
1208 .nf     
1209 \f3Hello Universe\fP
1210 .fi     
1211 .nf     
1212 \f3Hello Everyone\fP
1213 .fi     
1214 .nf     
1215 \f3\fP
1216 .fi     
1217 .sp     
1218 \f3Example 2 Compile Multiple Source Files\fR
1219 .PP
1220 This example compiles the \f3Aloha\&.java\fR, \f3GutenTag\&.java\fR, \f3Hello\&.java\fR, and \f3Hi\&.java\fR source files in the \f3greetings\fR package\&.
1221 .sp     
1222 .nf     
1223 \f3% javac greetings/*\&.java\fP
1224 .fi     
1225 .nf     
1226 \f3% ls greetings\fP
1227 .fi     
1228 .nf     
1229 \f3Aloha\&.class         GutenTag\&.class      Hello\&.class         Hi\&.class\fP
1230 .fi     
1231 .nf     
1232 \f3Aloha\&.java          GutenTag\&.java       Hello\&.java          Hi\&.java\fP
1233 .fi     
1234 .nf     
1235 \f3\fP
1236 .fi     
1237 .sp     
1238 \f3Example 3 Specify a User Class Path\fR
1239 .PP
1240 After changing one of the source files in the previous example, recompile it:
1241 .sp     
1242 .nf     
1243 \f3pwd\fP
1244 .fi     
1245 .nf     
1246 \f3/examples\fP
1247 .fi     
1248 .nf     
1249 \f3javac greetings/Hi\&.java\fP
1250 .fi     
1251 .nf     
1252 \f3\fP
1253 .fi     
1254 .sp     
1255 Because \f3greetings\&.Hi\fR refers to other classes in the \f3greetings\fR package, the compiler needs to find these other classes\&. The previous example works because the default user class path is the directory that contains the package directory\&. If you want to recompile this file without concern for which directory you are in, then add the examples directory to the user class path by setting \f3CLASSPATH\fR\&. This example uses the \f3-classpath\fR option\&.
1256 .sp     
1257 .nf     
1258 \f3javac \-classpath /examples /examples/greetings/Hi\&.java\fP
1259 .fi     
1260 .nf     
1261 \f3\fP
1262 .fi     
1263 .sp     
1264 If you change \f3greetings\&.Hi\fR to use a banner utility, then that utility also needs to be accessible through the user class path\&.
1265 .sp     
1266 .nf     
1267 \f3javac \-classpath /examples:/lib/Banners\&.jar \e\fP
1268 .fi     
1269 .nf     
1270 \f3            /examples/greetings/Hi\&.java\fP
1271 .fi     
1272 .nf     
1273 \f3\fP
1274 .fi     
1275 .sp     
1276 To execute a class in the \f3greetings\fR package, the program needs access to the \f3greetings\fR package, and to the classes that the \f3greetings\fR classes use\&.
1277 .sp     
1278 .nf     
1279 \f3java \-classpath /examples:/lib/Banners\&.jar greetings\&.Hi\fP
1280 .fi     
1281 .nf     
1282 \f3\fP
1283 .fi     
1284 .sp     
1285 \f3Example 4 Separate Source Files and Class Files\fR
1286 .PP
1287 The following example uses \f3javac\fR to compile code that runs on JVM 1\&.7\&.
1288 .sp     
1289 .nf     
1290 \f3javac \-source 1\&.7 \-target 1\&.7 \-bootclasspath jdk1\&.7\&.0/lib/rt\&.jar \e \fP
1291 .fi     
1292 .nf     
1293 \f3\-extdirs "" OldCode\&.java\fP
1294 .fi     
1295 .nf     
1296 \f3\fP
1297 .fi     
1298 .sp     
1299 The \f3-source 1\&.7\fR option specifies that release 1\&.7 (or 7) of the Java programming language be used to compile \f3OldCode\&.java\fR\&. The option \f3-target 1\&.7\fR option ensures that the generated class files are compatible with JVM 1\&.7\&. Note that in most cases, the value of the \f3-target\fR option is the value of the \f3-source\fR option; in this example, you can omit the \f3-target\fR option\&.
1300 .PP
1301 You must specify the \f3-bootclasspath\fR option to specify the correct version of the bootstrap classes (the \f3rt\&.jar\fR library)\&. If not, then the compiler generates a warning:
1302 .sp     
1303 .nf     
1304 \f3javac \-source 1\&.7 OldCode\&.java\fP
1305 .fi     
1306 .nf     
1307 \f3warning: [options] bootstrap class path not set in conjunction with \fP
1308 .fi     
1309 .nf     
1310 \f3\-source 1\&.7\fP
1311 .fi     
1312 .nf     
1313 \f3\fP
1314 .fi     
1315 .sp     
1316 If you do not specify the correct version of bootstrap classes, then the compiler uses the old language rules (in this example, it uses version 1\&.7 of the Java programming language) combined with the new bootstrap classes, which can result in class files that do not work on the older platform (in this case, Java SE 7) because reference to nonexistent methods can get included\&.
1317 .PP
1318 \f3Example 5 Cross Compile\fR
1319 .PP
1320 This example uses \f3javac\fR to compile code that runs on JVM 1\&.7\&.
1321 .sp     
1322 .nf     
1323 \f3javac \-source 1\&.7 \-target 1\&.7 \-bootclasspath jdk1\&.7\&.0/lib/rt\&.jar \e\fP
1324 .fi     
1325 .nf     
1326 \f3            \-extdirs "" OldCode\&.java\fP
1327 .fi     
1328 .nf     
1329 \f3\fP
1330 .fi     
1331 .sp     
1332 The\f3-source 1\&.7\fR option specifies that release 1\&.7 (or 7) of the Java programming language to be used to compile OldCode\&.java\&. The \f3-target 1\&.7\fR option ensures that the generated class files are compatible with JVM 1\&.7\&.
1333 .PP
1334 You must specify the \f3-bootclasspath\fR option to specify the correct version of the bootstrap classes (the \f3rt\&.jar\fR library)\&. If not, then the compiler generates a warning:
1335 .sp     
1336 .nf     
1337 \f3javac \-source 1\&.7 OldCode\&.java\fP
1338 .fi     
1339 .nf     
1340 \f3warning: [options] bootstrap class path not set in conjunction with \-source 1\&.7\fP
1341 .fi     
1342 .nf     
1343 \f3\fP
1344 .fi     
1345 .sp     
1346 If you do not specify the correct version of bootstrap classes, then the compiler uses the old language rules combined with the new bootstrap classes\&. This combination can result in class files that do not work on the older platform (in this case, Java SE 7) because reference to nonexistent methods can get included\&. In this example, the compiler uses release 1\&.7 of the Java programming language\&.
1347 .SH SEE\ ALSO    
1348 .TP 0.2i    
1349 \(bu
1350 java(1)
1351 .TP 0.2i    
1352 \(bu
1353 jdb(1)
1354 .TP 0.2i    
1355 \(bu
1356 javadoc(1)
1357 .TP 0.2i    
1358 \(bu
1359 jar(1)
1360 .TP 0.2i    
1361 \(bu
1362 jdb(1)
1363 .RE
1364 .br
1365 'pl 8.5i
1366 'bp
< prev index next >