-
Notifications
You must be signed in to change notification settings - Fork 13
Expand file tree
/
Copy pathjava-compiler-javac.html
More file actions
114 lines (96 loc) · 45.1 KB
/
java-compiler-javac.html
File metadata and controls
114 lines (96 loc) · 45.1 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
<!DOCTYPE html>
<html lang="en-US">
<head>
<meta charset="utf-8">
<meta name="viewport" content="width=device-width,initial-scale=1">
<title>Java - Java Compiler - 'javac'</title>
<meta name="generator" content="VuePress 1.8.2">
<link rel="icon" type="image/png" sizes="32x32" href="/favicon-32x32.png">
<link rel="icon" type="image/png" sizes="16x16" href="/favicon-16x16.png">
<link rel="manifest" href="/site.webmanifest">
<link rel="apple-touch-icon" sizes="180x180" href="/apple-touch-icon.png">
<link rel="mask-icon" href="/safari-pinned-tab.svg" color="#5bbad5">
<meta name="description" content="The 'javac' command - getting started, Compiling for a different version of Java">
<meta property="og:site_name" content="DevTut">
<meta property="og:title" content="Java - Java Compiler - 'javac'">
<meta property="og:description" content="The 'javac' command - getting started, Compiling for a different version of Java">
<meta property="og:type" content="article">
<meta property="og:url" content="/java/java-compiler-javac.html">
<meta property="og:image" content="/logo.png">
<meta name="twitter:title" content="Java - Java Compiler - 'javac'">
<meta name="twitter:description" content="The 'javac' command - getting started, Compiling for a different version of Java">
<meta name="twitter:url" content="/java/java-compiler-javac.html">
<meta name="twitter:card" content="summary_large_image">
<meta name="twitter:image" content="/logo.png">
<meta name="theme-color" content="#ffffff">
<meta name="apple-mobile-web-app-capable" content="yes">
<meta name="apple-mobile-web-app-status-bar-style" content="black">
<meta name="msapplication-TileImage" content="/mstile-150x150.png">
<meta name="msapplication-TileColor" content="#da532c">
<meta name="google-site-verification" content="76_rKXgwMVIjd-axJC_1zPV9OS4mEjvtgjYOWVkAdnQ">
<link rel="preload" href="/assets/css/0.styles.60619e34.css" as="style"><link rel="preload" href="/assets/js/app.1779e102.js" as="script"><link rel="preload" href="/assets/js/3.2cfa8016.js" as="script"><link rel="preload" href="/assets/js/1587.c197fff7.js" as="script">
<link rel="stylesheet" href="/assets/css/0.styles.60619e34.css">
</head>
<body>
<div id="app" data-server-rendered="true"><div class="theme-container"><header class="navbar"><div class="sidebar-button"><svg xmlns="http://www.w3.org/2000/svg" aria-hidden="true" role="img" viewBox="0 0 448 512" class="icon"><path fill="currentColor" d="M436 124H12c-6.627 0-12-5.373-12-12V80c0-6.627 5.373-12 12-12h424c6.627 0 12 5.373 12 12v32c0 6.627-5.373 12-12 12zm0 160H12c-6.627 0-12-5.373-12-12v-32c0-6.627 5.373-12 12-12h424c6.627 0 12 5.373 12 12v32c0 6.627-5.373 12-12 12zm0 160H12c-6.627 0-12-5.373-12-12v-32c0-6.627 5.373-12 12-12h424c6.627 0 12 5.373 12 12v32c0 6.627-5.373 12-12 12z"></path></svg></div> <a href="/" class="home-link router-link-active"><!----> <span class="site-name">DevTut</span></a> <div class="links"><form id="search-form" role="search" class="algolia-search-wrapper search-box"><input id="algolia-search-input" class="search-query"></form> <nav class="nav-links can-hide"> <a href="https://github.com/devtut/generate" target="_blank" rel="noopener noreferrer" class="repo-link">
GitHub
<span><svg xmlns="http://www.w3.org/2000/svg" aria-hidden="true" focusable="false" x="0px" y="0px" viewBox="0 0 100 100" width="15" height="15" class="icon outbound"><path fill="currentColor" d="M18.8,85.1h56l0,0c2.2,0,4-1.8,4-4v-32h-8v28h-48v-48h28v-8h-32l0,0c-2.2,0-4,1.8-4,4v56C14.8,83.3,16.6,85.1,18.8,85.1z"></path> <polygon fill="currentColor" points="45.7,48.7 51.3,54.3 77.2,28.5 77.2,37.2 85.2,37.2 85.2,14.9 62.8,14.9 62.8,22.9 71.5,22.9"></polygon></svg> <span class="sr-only">(opens new window)</span></span></a></nav></div></header> <div class="sidebar-mask"></div> <aside class="sidebar"><nav class="nav-links"> <a href="https://github.com/devtut/generate" target="_blank" rel="noopener noreferrer" class="repo-link">
GitHub
<span><svg xmlns="http://www.w3.org/2000/svg" aria-hidden="true" focusable="false" x="0px" y="0px" viewBox="0 0 100 100" width="15" height="15" class="icon outbound"><path fill="currentColor" d="M18.8,85.1h56l0,0c2.2,0,4-1.8,4-4v-32h-8v28h-48v-48h28v-8h-32l0,0c-2.2,0-4,1.8-4,4v56C14.8,83.3,16.6,85.1,18.8,85.1z"></path> <polygon fill="currentColor" points="45.7,48.7 51.3,54.3 77.2,28.5 77.2,37.2 85.2,37.2 85.2,14.9 62.8,14.9 62.8,22.9 71.5,22.9"></polygon></svg> <span class="sr-only">(opens new window)</span></span></a></nav> <ul class="sidebar-links"><li><section class="sidebar-group depth-0"><p class="sidebar-heading open"><span>Java</span> <!----></p> <ul class="sidebar-links sidebar-group-items"><li><a href="/java/" aria-current="page" class="sidebar-link">Disclaimer</a></li><li><a href="/java/java-editions-versions-releases-and-distributions.html" class="sidebar-link">Java Editions, Versions, Releases and Distributions</a></li><li><a href="/java/installing-java-standard-edition.html" class="sidebar-link">Installing Java (Standard Edition)</a></li><li><a href="/java/getting-started-with-java-language.html" class="sidebar-link">Getting started with Java Language</a></li><li><a href="/java/type-conversion.html" class="sidebar-link">Type Conversion</a></li><li><a href="/java/getters-and-setters.html" class="sidebar-link">Getters and Setters</a></li><li><a href="/java/reference-data-types.html" class="sidebar-link">Reference Data Types</a></li><li><a href="/java/java-compiler-javac.html" aria-current="page" class="active sidebar-link">Java Compiler - 'javac'</a><ul class="sidebar-sub-headers"><li class="sidebar-sub-header"><a href="/java/java-compiler-javac.html#the-javac-command-getting-started" class="sidebar-link">The 'javac' command - getting started</a></li><li class="sidebar-sub-header"><a href="/java/java-compiler-javac.html#compiling-for-a-different-version-of-java" class="sidebar-link">Compiling for a different version of Java</a></li></ul></li><li><a href="/java/documenting-java-code.html" class="sidebar-link">Documenting Java Code</a></li><li><a href="/java/command-line-argument-processing.html" class="sidebar-link">Command line Argument Processing</a></li><li><a href="/java/the-java-command-java-and-javaw.html" class="sidebar-link">The Java Command - 'java' and 'javaw'</a></li><li><a href="/java/literals.html" class="sidebar-link">Literals</a></li><li><a href="/java/primitive-data-types.html" class="sidebar-link">Primitive Data Types</a></li><li><a href="/java/strings.html" class="sidebar-link">Strings</a></li><li><a href="/java/stringbuffer.html" class="sidebar-link">StringBuffer</a></li><li><a href="/java/stringbuilder.html" class="sidebar-link">StringBuilder</a></li><li><a href="/java/string-tokenizer.html" class="sidebar-link">String Tokenizer</a></li><li><a href="/java/splitting-a-string-into-fixed-length-parts.html" class="sidebar-link">Splitting a string into fixed length parts</a></li><li><a href="/java/date-class.html" class="sidebar-link">Date Class</a></li><li><a href="/java/dates-and-time-java-time.html" class="sidebar-link">Dates and Time (java.time.*)</a></li><li><a href="/java/localtime.html" class="sidebar-link">LocalTime</a></li><li><a href="/java/bigdecimal.html" class="sidebar-link">BigDecimal</a></li><li><a href="/java/biginteger.html" class="sidebar-link">BigInteger</a></li><li><a href="/java/numberformat.html" class="sidebar-link">NumberFormat</a></li><li><a href="/java/bit-manipulation.html" class="sidebar-link">Bit Manipulation</a></li><li><a href="/java/arrays.html" class="sidebar-link">Arrays</a></li><li><a href="/java/collections.html" class="sidebar-link">Collections</a></li><li><a href="/java/lists.html" class="sidebar-link">Lists</a></li><li><a href="/java/sets.html" class="sidebar-link">Sets</a></li><li><a href="/java/list-vs-set.html" class="sidebar-link">List vs SET</a></li><li><a href="/java/maps.html" class="sidebar-link">Maps</a></li><li><a href="/java/linkedhashmap.html" class="sidebar-link">LinkedHashMap</a></li><li><a href="/java/weakhashmap.html" class="sidebar-link">WeakHashMap</a></li><li><a href="/java/sortedmap.html" class="sidebar-link">SortedMap</a></li><li><a href="/java/treemap-and-treeset.html" class="sidebar-link">TreeMap and TreeSet</a></li><li><a href="/java/queues-and-deques.html" class="sidebar-link">Queues and Deques</a></li><li><a href="/java/dequeue-interface.html" class="sidebar-link">Dequeue Interface</a></li><li><a href="/java/enums.html" class="sidebar-link">Enums</a></li><li><a href="/java/enum-map.html" class="sidebar-link">Enum Map</a></li><li><a href="/java/enumset-class.html" class="sidebar-link">EnumSet class</a></li><li><a href="/java/enum-starting-with-number.html" class="sidebar-link">Enum starting with number</a></li><li><a href="/java/hashtable.html" class="sidebar-link">Hashtable</a></li><li><a href="/java/operators.html" class="sidebar-link">Operators</a></li><li><a href="/java/constructors.html" class="sidebar-link">Constructors</a></li><li><a href="/java/object-class-methods-and-constructor.html" class="sidebar-link">Object Class Methods and Constructor</a></li><li><a href="/java/annotations.html" class="sidebar-link">Annotations</a></li><li><a href="/java/immutable-class.html" class="sidebar-link">Immutable Class</a></li><li><a href="/java/immutable-objects.html" class="sidebar-link">Immutable Objects</a></li><li><a href="/java/visibility-controlling-access-to-members-of-a-class.html" class="sidebar-link">Visibility (controlling access to members of a class)</a></li><li><a href="/java/generics.html" class="sidebar-link">Generics</a></li><li><a href="/java/classes-and-objects.html" class="sidebar-link">Classes and Objects</a></li><li><a href="/java/local-inner-class.html" class="sidebar-link">Local Inner Class</a></li><li><a href="/java/nested-and-inner-classes.html" class="sidebar-link">Nested and Inner Classes</a></li><li><a href="/java/the-java-util-objects-class.html" class="sidebar-link">The java.util.Objects Class</a></li><li><a href="/java/default-methods.html" class="sidebar-link">Default Methods</a></li><li><a href="/java/packages.html" class="sidebar-link">Packages</a></li><li><a href="/java/inheritance.html" class="sidebar-link">Inheritance</a></li><li><a href="/java/reference-types.html" class="sidebar-link">Reference Types</a></li><li><a href="/java/console-i-o.html" class="sidebar-link">Console I/O</a></li><li><a href="/java/streams.html" class="sidebar-link">Streams</a></li><li><a href="/java/inputstreams-and-outputstreams.html" class="sidebar-link">InputStreams and OutputStreams</a></li><li><a href="/java/readers-and-writers.html" class="sidebar-link">Readers and Writers</a></li><li><a href="/java/preferences.html" class="sidebar-link">Preferences</a></li><li><a href="/java/collection-factory-methods.html" class="sidebar-link">Collection Factory Methods</a></li><li><a href="/java/alternative-collections.html" class="sidebar-link">Alternative Collections</a></li><li><a href="/java/concurrent-collections.html" class="sidebar-link">Concurrent Collections</a></li><li><a href="/java/choosing-collections.html" class="sidebar-link">Choosing Collections</a></li><li><a href="/java/super-keyword.html" class="sidebar-link">super keyword</a></li><li><a href="/java/serialization.html" class="sidebar-link">Serialization</a></li><li><a href="/java/optional.html" class="sidebar-link">Optional</a></li><li><a href="/java/object-references.html" class="sidebar-link">Object References</a></li><li><a href="/java/exceptions-and-exception-handling.html" class="sidebar-link">Exceptions and exception handling</a></li><li><a href="/java/calendar-and-its-subclasses.html" class="sidebar-link">Calendar and its Subclasses</a></li><li><a href="/java/using-the-static-keyword.html" class="sidebar-link">Using the static keyword</a></li><li><a href="/java/properties-class.html" class="sidebar-link">Properties Class</a></li><li><a href="/java/lambda-expressions.html" class="sidebar-link">Lambda Expressions</a></li><li><a href="/java/basic-control-structures.html" class="sidebar-link">Basic Control Structures</a></li><li><a href="/java/bufferedwriter.html" class="sidebar-link">BufferedWriter</a></li><li><a href="/java/new-file-i-o.html" class="sidebar-link">New File I/O</a></li><li><a href="/java/file-i-o.html" class="sidebar-link">File I/O</a></li><li><a href="/java/scanner.html" class="sidebar-link">Scanner</a></li><li><a href="/java/interfaces.html" class="sidebar-link">Interfaces</a></li><li><a href="/java/regular-expressions.html" class="sidebar-link">Regular Expressions</a></li><li><a href="/java/comparable-and-comparator.html" class="sidebar-link">Comparable and Comparator</a></li><li><a href="/java/java-floating-point-operations.html" class="sidebar-link">Java Floating Point Operations</a></li><li><a href="/java/currency-and-money.html" class="sidebar-link">Currency and Money</a></li><li><a href="/java/object-cloning.html" class="sidebar-link">Object Cloning</a></li><li><a href="/java/recursion.html" class="sidebar-link">Recursion</a></li><li><a href="/java/converting-to-and-from-strings.html" class="sidebar-link">Converting to and from Strings</a></li><li><a href="/java/random-number-generation.html" class="sidebar-link">Random Number Generation</a></li><li><a href="/java/singletons.html" class="sidebar-link">Singletons</a></li><li><a href="/java/autoboxing.html" class="sidebar-link">Autoboxing</a></li><li><a href="/java/2d-graphics-in-java.html" class="sidebar-link">2D Graphics in Java</a></li><li><a href="/java/jaxb.html" class="sidebar-link">JAXB</a></li><li><a href="/java/class-java-reflection.html" class="sidebar-link">Class - Java Reflection</a></li><li><a href="/java/networking.html" class="sidebar-link">Networking</a></li><li><a href="/java/nio-networking.html" class="sidebar-link">NIO - Networking</a></li><li><a href="/java/httpurlconnection.html" class="sidebar-link">HttpURLConnection</a></li><li><a href="/java/jax-ws.html" class="sidebar-link">JAX-WS</a></li><li><a href="/java/nashorn-javascript-engine.html" class="sidebar-link">Nashorn JavaScript engine</a></li><li><a href="/java/java-native-interface.html" class="sidebar-link">Java Native Interface</a></li><li><a href="/java/functional-interfaces.html" class="sidebar-link">Functional Interfaces</a></li><li><a href="/java/fluent-interface.html" class="sidebar-link">Fluent Interface</a></li><li><a href="/java/remote-method-invocation-rmi.html" class="sidebar-link">Remote Method Invocation (RMI)</a></li><li><a href="/java/iterator-and-iterable.html" class="sidebar-link">Iterator and Iterable</a></li><li><a href="/java/reflection-api.html" class="sidebar-link">Reflection API</a></li><li><a href="/java/bytebuffer.html" class="sidebar-link">ByteBuffer</a></li><li><a href="/java/applets.html" class="sidebar-link">Applets</a></li><li><a href="/java/expressions.html" class="sidebar-link">Expressions</a></li><li><a href="/java/json-in-java.html" class="sidebar-link">JSON in Java</a></li><li><a href="/java/xml-parsing-using-the-jaxp-apis.html" class="sidebar-link">XML Parsing using the JAXP APIs</a></li><li><a href="/java/xml-xpath-evaluation.html" class="sidebar-link">XML XPath Evaluation</a></li><li><a href="/java/xom-xml-object-model.html" class="sidebar-link">XOM - XML Object Model</a></li><li><a href="/java/polymorphism.html" class="sidebar-link">Polymorphism</a></li><li><a href="/java/encapsulation.html" class="sidebar-link">Encapsulation</a></li><li><a href="/java/java-agents.html" class="sidebar-link">Java Agents</a></li><li><a href="/java/varargs-variable-argument.html" class="sidebar-link">Varargs (Variable Argument)</a></li><li><a href="/java/logging-java-util-logging.html" class="sidebar-link">Logging (java.util.logging)</a></li><li><a href="/java/log4j-log4j2.html" class="sidebar-link">log4j / log4j2</a></li><li><a href="/java/oracle-official-code-standard.html" class="sidebar-link">Oracle Official Code Standard</a></li><li><a href="/java/character-encoding.html" class="sidebar-link">Character encoding</a></li><li><a href="/java/apache-commons-lang.html" class="sidebar-link">Apache Commons Lang</a></li><li><a href="/java/localization-and-internationalization.html" class="sidebar-link">Localization and Internationalization</a></li><li><a href="/java/parallel-programming-with-fork-join-framework.html" class="sidebar-link">Parallel programming with Fork/Join framework</a></li><li><a href="/java/non-access-modifiers.html" class="sidebar-link">Non-Access Modifiers</a></li><li><a href="/java/process.html" class="sidebar-link">Process</a></li><li><a href="/java/java-native-access.html" class="sidebar-link">Java Native Access</a></li><li><a href="/java/modules.html" class="sidebar-link">Modules</a></li><li><a href="/java/concurrent-programming-threads.html" class="sidebar-link">Concurrent Programming (Threads)</a></li><li><a href="/java/executor-executorservice-and-thread-pools.html" class="sidebar-link">Executor, ExecutorService and Thread pools</a></li><li><a href="/java/threadlocal.html" class="sidebar-link">ThreadLocal</a></li><li><a href="/java/using-threadpoolexecutor-in-multithreaded-applications.html" class="sidebar-link">Using ThreadPoolExecutor in MultiThreaded applications.</a></li><li><a href="/java/common-java-pitfalls.html" class="sidebar-link">Common Java Pitfalls</a></li><li><a href="/java/java-pitfalls-exception-usage.html" class="sidebar-link">Java Pitfalls - Exception usage</a></li><li><a href="/java/java-pitfalls-language-syntax.html" class="sidebar-link">Java Pitfalls - Language syntax</a></li><li><a href="/java/java-pitfalls-threads-and-concurrency.html" class="sidebar-link">Java Pitfalls - Threads and Concurrency</a></li><li><a href="/java/java-pitfalls-nulls-and-nullpointerexception.html" class="sidebar-link">Java Pitfalls - Nulls and NullPointerException</a></li><li><a href="/java/java-pitfalls-performance-issues.html" class="sidebar-link">Java Pitfalls - Performance Issues</a></li><li><a href="/java/serviceloader.html" class="sidebar-link">ServiceLoader</a></li><li><a href="/java/classloaders.html" class="sidebar-link">Classloaders</a></li><li><a href="/java/creating-images-programmatically.html" class="sidebar-link">Creating Images Programmatically</a></li><li><a href="/java/atomic-types.html" class="sidebar-link">Atomic Types</a></li><li><a href="/java/rsa-encryption.html" class="sidebar-link">RSA Encryption</a></li><li><a href="/java/secure-objects.html" class="sidebar-link">Secure objects</a></li><li><a href="/java/security-cryptography.html" class="sidebar-link">Security & Cryptography</a></li><li><a href="/java/securitymanager.html" class="sidebar-link">SecurityManager</a></li><li><a href="/java/jndi.html" class="sidebar-link">JNDI</a></li><li><a href="/java/sun-misc-unsafe.html" class="sidebar-link">sun.misc.Unsafe</a></li><li><a href="/java/java-memory-model.html" class="sidebar-link">Java Memory Model</a></li><li><a href="/java/java-deployment.html" class="sidebar-link">Java deployment</a></li><li><a href="/java/java-plugin-system-implementations.html" class="sidebar-link">Java plugin system implementations</a></li><li><a href="/java/javabean.html" class="sidebar-link">JavaBean</a></li><li><a href="/java/java-se-7-features.html" class="sidebar-link">Java SE 7 Features</a></li><li><a href="/java/java-se-8-features.html" class="sidebar-link">Java SE 8 Features</a></li><li><a href="/java/dynamic-method-dispatch.html" class="sidebar-link">Dynamic Method Dispatch</a></li><li><a href="/java/generating-java-code.html" class="sidebar-link">Generating Java Code</a></li><li><a href="/java/jshell.html" class="sidebar-link">JShell</a></li><li><a href="/java/stack-walking-api.html" class="sidebar-link">Stack-Walking API</a></li><li><a href="/java/sockets.html" class="sidebar-link">Sockets</a></li><li><a href="/java/java-sockets.html" class="sidebar-link">Java Sockets</a></li><li><a href="/java/ftp-file-transfer-protocol.html" class="sidebar-link">FTP (File Transfer Protocol)</a></li><li><a href="/java/using-other-scripting-languages-in-java.html" class="sidebar-link">Using Other Scripting Languages in Java</a></li><li><a href="/java/c-comparison.html" class="sidebar-link">C++ Comparison</a></li><li><a href="/java/audio.html" class="sidebar-link">Audio</a></li><li><a href="/java/java-print-service.html" class="sidebar-link">Java Print Service</a></li><li><a href="/java/completablefuture.html" class="sidebar-link">CompletableFuture</a></li><li><a href="/java/runtime-commands.html" class="sidebar-link">Runtime Commands</a></li><li><a href="/java/unit-testing.html" class="sidebar-link">Unit Testing</a></li><li><a href="/java/asserting.html" class="sidebar-link">Asserting</a></li><li><a href="/java/multi-release-jar-files.html" class="sidebar-link">Multi-Release JAR Files</a></li><li><a href="/java/just-in-time-jit-compiler.html" class="sidebar-link">Just in Time (JIT) compiler</a></li><li><a href="/java/bytecode-modification.html" class="sidebar-link">Bytecode Modification</a></li><li><a href="/java/disassembling-and-decompiling.html" class="sidebar-link">Disassembling and Decompiling</a></li><li><a href="/java/jmx.html" class="sidebar-link">JMX</a></li><li><a href="/java/java-virtual-machine-jvm.html" class="sidebar-link">Java Virtual Machine (JVM)</a></li><li><a href="/java/xjc.html" class="sidebar-link">XJC</a></li><li><a href="/java/jvm-flags.html" class="sidebar-link">JVM Flags</a></li><li><a href="/java/jvm-tool-interface.html" class="sidebar-link">JVM Tool Interface</a></li><li><a href="/java/java-memory-management.html" class="sidebar-link">Java Memory Management</a></li><li><a href="/java/java-performance-tuning.html" class="sidebar-link">Java Performance Tuning</a></li><li><a href="/java/benchmarks.html" class="sidebar-link">Benchmarks</a></li><li><a href="/java/fileupload-to-aws.html" class="sidebar-link">FileUpload to AWS</a></li><li><a href="/java/appdynamics-and-tibco-businessworks-instrumentation-for-easy-integration.html" class="sidebar-link">AppDynamics and TIBCO BusinessWorks Instrumentation for Easy Integration</a></li><li><a href="/java/the-classpath.html" class="sidebar-link">The Classpath</a></li><li><a href="/java/resources-on-classpath.html" class="sidebar-link">Resources (on classpath)</a></li><li><a href="/java/contributors.html" class="sidebar-link">The Contributors</a></li></ul></section></li></ul> </aside> <main class="page"> <div class="theme-default-content content__default"><h1 id="java-compiler-javac"><a href="#java-compiler-javac" class="header-anchor">#</a> Java Compiler - 'javac'</h1> <h2 id="the-javac-command-getting-started"><a href="#the-javac-command-getting-started" class="header-anchor">#</a> The 'javac' command - getting started</h2> <h3 id="simple-example"><a href="#simple-example" class="header-anchor">#</a> Simple example</h3> <p>Assuming that the "HelloWorld.java" contains the following Java source:</p> <div class="language-java extra-class"><pre class="language-java"><code><span class="token keyword">public</span> <span class="token keyword">class</span> <span class="token class-name">HelloWorld</span> <span class="token punctuation">{</span>
<span class="token keyword">public</span> <span class="token keyword">static</span> <span class="token keyword">void</span> <span class="token function">main</span><span class="token punctuation">(</span><span class="token class-name">String</span><span class="token punctuation">[</span><span class="token punctuation">]</span> args<span class="token punctuation">)</span> <span class="token punctuation">{</span>
<span class="token class-name">System</span><span class="token punctuation">.</span>out<span class="token punctuation">.</span><span class="token function">println</span><span class="token punctuation">(</span><span class="token string">"Hello world!"</span><span class="token punctuation">)</span><span class="token punctuation">;</span>
<span class="token punctuation">}</span>
<span class="token punctuation">}</span>
</code></pre></div><p>(For an explanation of the above code, please refer to <a href="http://stackoverflow.com/documentation/java/84/compile-and-run-your-first-java-program#t=201608210035544002048" target="_blank" rel="noopener noreferrer">Getting started with Java Language<span><svg xmlns="http://www.w3.org/2000/svg" aria-hidden="true" focusable="false" x="0px" y="0px" viewBox="0 0 100 100" width="15" height="15" class="icon outbound"><path fill="currentColor" d="M18.8,85.1h56l0,0c2.2,0,4-1.8,4-4v-32h-8v28h-48v-48h28v-8h-32l0,0c-2.2,0-4,1.8-4,4v56C14.8,83.3,16.6,85.1,18.8,85.1z"></path> <polygon fill="currentColor" points="45.7,48.7 51.3,54.3 77.2,28.5 77.2,37.2 85.2,37.2 85.2,14.9 62.8,14.9 62.8,22.9 71.5,22.9"></polygon></svg> <span class="sr-only">(opens new window)</span></span></a> .)</p> <p>We can compile the above file using this command:</p> <div class="language-java extra-class"><pre class="language-java"><code>$ javac <span class="token class-name">HelloWorld</span><span class="token punctuation">.</span>java
</code></pre></div><p>This produces a file called "HelloWorld.class", which we can then run as follows:</p> <div class="language-java extra-class"><pre class="language-java"><code>$ java <span class="token class-name">HelloWorld</span>
<span class="token class-name">Hello</span> world<span class="token operator">!</span>
</code></pre></div><p>The key points to note from this example are:</p> <ol><li>The source filename "HelloWorld.java" must match the class name in the source file ... which is <code>HelloWorld</code>. If they don't match, you will get a compilation error.</li> <li>The bytecode filename "HelloWorld.class" corresponds to the classname. If you were to rename the "HelloWorld.class", you would get an error when your tried to run it.</li> <li>When running a Java application using <code>java</code>, you supply the classname NOT the bytecode filename.</li></ol> <h3 id="example-with-packages"><a href="#example-with-packages" class="header-anchor">#</a> Example with packages</h3> <p>Most practical Java code uses packages to organize the namespace for classes and reduce the risk of accidental class name collision.</p> <p>If we wanted to declare the <code>HelloWorld</code> class in a package call <code>com.example</code>, the "HelloWorld.java" would contain the following Java source:</p> <div class="language-java extra-class"><pre class="language-java"><code><span class="token keyword">package</span> <span class="token namespace">com<span class="token punctuation">.</span>example</span><span class="token punctuation">;</span>
<span class="token keyword">public</span> <span class="token keyword">class</span> <span class="token class-name">HelloWorld</span> <span class="token punctuation">{</span>
<span class="token keyword">public</span> <span class="token keyword">static</span> <span class="token keyword">void</span> <span class="token function">main</span><span class="token punctuation">(</span><span class="token class-name">String</span><span class="token punctuation">[</span><span class="token punctuation">]</span> args<span class="token punctuation">)</span> <span class="token punctuation">{</span>
<span class="token class-name">System</span><span class="token punctuation">.</span>out<span class="token punctuation">.</span><span class="token function">println</span><span class="token punctuation">(</span><span class="token string">"Hello world!"</span><span class="token punctuation">)</span><span class="token punctuation">;</span>
<span class="token punctuation">}</span>
<span class="token punctuation">}</span>
</code></pre></div><p>This source code file needs to stored in a directory tree whose structure corresponds to the package naming.</p> <div class="language-java extra-class"><pre class="language-java"><code><span class="token punctuation">.</span> # the current directory <span class="token punctuation">(</span><span class="token keyword">for</span> <span class="token keyword">this</span> example<span class="token punctuation">)</span>
<span class="token operator">|</span>
<span class="token operator">--</span><span class="token operator">--</span>com
<span class="token operator">|</span>
<span class="token operator">--</span><span class="token operator">--</span>example
<span class="token operator">|</span>
<span class="token operator">--</span><span class="token operator">--</span><span class="token class-name">HelloWorld</span><span class="token punctuation">.</span>java
</code></pre></div><p>We can compile the above file using this command:</p> <div class="language-java extra-class"><pre class="language-java"><code>$ javac com<span class="token operator">/</span>example<span class="token operator">/</span><span class="token class-name">HelloWorld</span><span class="token punctuation">.</span>java
</code></pre></div><p>This produces a file called "com/example/HelloWorld.class"; i.e. after compilation, the file structure should look like this:</p> <div class="language-java extra-class"><pre class="language-java"><code><span class="token punctuation">.</span> # the current directory <span class="token punctuation">(</span><span class="token keyword">for</span> <span class="token keyword">this</span> example<span class="token punctuation">)</span>
<span class="token operator">|</span>
<span class="token operator">--</span><span class="token operator">--</span>com
<span class="token operator">|</span>
<span class="token operator">--</span><span class="token operator">--</span>example
<span class="token operator">|</span>
<span class="token operator">--</span><span class="token operator">--</span><span class="token class-name">HelloWorld</span><span class="token punctuation">.</span>java
<span class="token operator">--</span><span class="token operator">--</span><span class="token class-name">HelloWorld</span><span class="token punctuation">.</span><span class="token keyword">class</span>
</code></pre></div><p>We can then run the application as follows:</p> <div class="language-java extra-class"><pre class="language-java"><code>$ java <span class="token class-name"><span class="token namespace">com<span class="token punctuation">.</span>example<span class="token punctuation">.</span></span>HelloWorld</span>
<span class="token class-name">Hello</span> world<span class="token operator">!</span>
</code></pre></div><p>Additional points to note from this example are:</p> <ol><li>The directory structure must match the package name structure.</li> <li>When you run the class, the full class name must be supplied; i.e. "com.example.HelloWorld" not "HelloWorld".</li> <li>You don't have to compile and run Java code out of the current directory. We are just doing it here for illustration.</li></ol> <h3 id="compiling-multiple-files-at-once-with-javac"><a href="#compiling-multiple-files-at-once-with-javac" class="header-anchor">#</a> Compiling multiple files at once with 'javac'.</h3> <p>If your application consists of multiple source code files (and most do!) you can compile them one at a time. Alternatively, you can compile multiple files at the same time by listing the pathnames:</p> <div class="language-java extra-class"><pre class="language-java"><code>$ javac <span class="token class-name">Foo</span><span class="token punctuation">.</span>java <span class="token class-name">Bar</span><span class="token punctuation">.</span>java
</code></pre></div><p>or using your command shell's filename wildcard functionality ....</p> <div class="language-java extra-class"><pre class="language-java"><code>$ javac <span class="token operator">*</span><span class="token punctuation">.</span>java
$ javac com<span class="token operator">/</span>example<span class="token comment">/*.java
$ javac */</span><span class="token operator">*</span><span class="token operator">*</span><span class="token comment">/*.java #Only works on Zsh or with globstar enabled on your shell
</span></code></pre></div><p>This will compile all Java source files in the current directory, in the "com/example" directory, and recursively in child directories respectively. A third alternative is to supply a list of source filenames (and compiler options) as a file. For example:</p> <div class="language-java extra-class"><pre class="language-java"><code>$ javac <span class="token annotation punctuation">@sourcefiles</span>
</code></pre></div><p>where the <code>sourcefiles</code> file contains:</p> <div class="language-java extra-class"><pre class="language-java"><code><span class="token class-name">Foo</span><span class="token punctuation">.</span>java
<span class="token class-name">Bar</span><span class="token punctuation">.</span>java
com<span class="token operator">/</span>example<span class="token operator">/</span><span class="token class-name">HelloWorld</span><span class="token punctuation">.</span>java
</code></pre></div><p>Note: compiling code like this is appropriate for small one-person projects, and for once-off programs. Beyond that, it is advisable to select and use a Java build tool. Alternatively, most programmers use a Java IDE (e.g. <a href="https://netbeans.org/" target="_blank" rel="noopener noreferrer">NetBeans<span><svg xmlns="http://www.w3.org/2000/svg" aria-hidden="true" focusable="false" x="0px" y="0px" viewBox="0 0 100 100" width="15" height="15" class="icon outbound"><path fill="currentColor" d="M18.8,85.1h56l0,0c2.2,0,4-1.8,4-4v-32h-8v28h-48v-48h28v-8h-32l0,0c-2.2,0-4,1.8-4,4v56C14.8,83.3,16.6,85.1,18.8,85.1z"></path> <polygon fill="currentColor" points="45.7,48.7 51.3,54.3 77.2,28.5 77.2,37.2 85.2,37.2 85.2,14.9 62.8,14.9 62.8,22.9 71.5,22.9"></polygon></svg> <span class="sr-only">(opens new window)</span></span></a>, <a href="https://eclipse.org/" target="_blank" rel="noopener noreferrer">eclipse<span><svg xmlns="http://www.w3.org/2000/svg" aria-hidden="true" focusable="false" x="0px" y="0px" viewBox="0 0 100 100" width="15" height="15" class="icon outbound"><path fill="currentColor" d="M18.8,85.1h56l0,0c2.2,0,4-1.8,4-4v-32h-8v28h-48v-48h28v-8h-32l0,0c-2.2,0-4,1.8-4,4v56C14.8,83.3,16.6,85.1,18.8,85.1z"></path> <polygon fill="currentColor" points="45.7,48.7 51.3,54.3 77.2,28.5 77.2,37.2 85.2,37.2 85.2,14.9 62.8,14.9 62.8,22.9 71.5,22.9"></polygon></svg> <span class="sr-only">(opens new window)</span></span></a>, <a href="https://www.jetbrains.com/idea/" target="_blank" rel="noopener noreferrer">IntelliJ IDEA<span><svg xmlns="http://www.w3.org/2000/svg" aria-hidden="true" focusable="false" x="0px" y="0px" viewBox="0 0 100 100" width="15" height="15" class="icon outbound"><path fill="currentColor" d="M18.8,85.1h56l0,0c2.2,0,4-1.8,4-4v-32h-8v28h-48v-48h28v-8h-32l0,0c-2.2,0-4,1.8-4,4v56C14.8,83.3,16.6,85.1,18.8,85.1z"></path> <polygon fill="currentColor" points="45.7,48.7 51.3,54.3 77.2,28.5 77.2,37.2 85.2,37.2 85.2,14.9 62.8,14.9 62.8,22.9 71.5,22.9"></polygon></svg> <span class="sr-only">(opens new window)</span></span></a>) which offers an embedded compiler and incremental building of "projects".</p> <h3 id="commonly-used-javac-options"><a href="#commonly-used-javac-options" class="header-anchor">#</a> Commonly used 'javac' options</h3> <p>Here are a few options for the <code>javac</code> command that are likely to be useful to you</p> <ul><li>The <code>-d</code> option sets a destination directory for writing the ".class" files.</li> <li>The <code>-sourcepath</code> option sets a source code search path.</li> <li>The <code>-cp</code> or <code>-classpath</code> option sets the search path for finding external and previously compiled classes. For more information on the classpath and how to specify it, refer to the <a href="http://stackoverflow.com/documentation/java/3720/classpath" target="_blank" rel="noopener noreferrer">The Classpath<span><svg xmlns="http://www.w3.org/2000/svg" aria-hidden="true" focusable="false" x="0px" y="0px" viewBox="0 0 100 100" width="15" height="15" class="icon outbound"><path fill="currentColor" d="M18.8,85.1h56l0,0c2.2,0,4-1.8,4-4v-32h-8v28h-48v-48h28v-8h-32l0,0c-2.2,0-4,1.8-4,4v56C14.8,83.3,16.6,85.1,18.8,85.1z"></path> <polygon fill="currentColor" points="45.7,48.7 51.3,54.3 77.2,28.5 77.2,37.2 85.2,37.2 85.2,14.9 62.8,14.9 62.8,22.9 71.5,22.9"></polygon></svg> <span class="sr-only">(opens new window)</span></span></a> Topic.</li> <li>The <code>-version</code> option prints the compiler's version information.</li></ul> <p>A more complete list of compiler options will be described in a separate example.</p> <h3 id="references"><a href="#references" class="header-anchor">#</a> References</h3> <p>The definitive reference for the <code>javac</code> command is the <a href="http://docs.oracle.com/javase/8/docs/technotes/tools/windows/javac.html" target="_blank" rel="noopener noreferrer">Oracle manual page for <code>javac</code><span><svg xmlns="http://www.w3.org/2000/svg" aria-hidden="true" focusable="false" x="0px" y="0px" viewBox="0 0 100 100" width="15" height="15" class="icon outbound"><path fill="currentColor" d="M18.8,85.1h56l0,0c2.2,0,4-1.8,4-4v-32h-8v28h-48v-48h28v-8h-32l0,0c-2.2,0-4,1.8-4,4v56C14.8,83.3,16.6,85.1,18.8,85.1z"></path> <polygon fill="currentColor" points="45.7,48.7 51.3,54.3 77.2,28.5 77.2,37.2 85.2,37.2 85.2,14.9 62.8,14.9 62.8,22.9 71.5,22.9"></polygon></svg> <span class="sr-only">(opens new window)</span></span></a>.</p> <h2 id="compiling-for-a-different-version-of-java"><a href="#compiling-for-a-different-version-of-java" class="header-anchor">#</a> Compiling for a different version of Java</h2> <p>The Java programming language (and its runtime) has undergone numerous changes since its release since its initial public release. These changes include:</p> <ul><li>Changes in the Java programming language syntax and semantics</li> <li>Changes in the APIs provided by the Java standard class libraries.</li> <li>Changes in the Java (bytecode) instruction set and classfile format.</li></ul> <p>With very few exceptions (for example the <code>enum</code> keyword, changes to some "internal" classes, etc), these changes are backwards compatible.</p> <ul><li>A Java program that was compiled using an older version of the Java toolchain will run on a newer version Java platform without recompilation.</li> <li>A Java program that was written in an older version of Java will compile successfully with a new Java compiler.</li></ul> <h3 id="compiling-old-java-with-a-newer-compiler"><a href="#compiling-old-java-with-a-newer-compiler" class="header-anchor">#</a> Compiling old Java with a newer compiler</h3> <p>If you need to (re-)compile older Java code on a newer Java platform to run on the newer platform, you generally don't need to give any special compilation flags. In a few cases (e.g. if you had used <code>enum</code> as an identifier) you could use the <code>-source</code> option to disable the new syntax. For example, given the following class:</p> <div class="language-java extra-class"><pre class="language-java"><code><span class="token keyword">public</span> <span class="token keyword">class</span> <span class="token class-name">OldSyntax</span> <span class="token punctuation">{</span>
<span class="token keyword">private</span> <span class="token keyword">static</span> <span class="token keyword">int</span> <span class="token keyword">enum</span><span class="token punctuation">;</span> <span class="token comment">// invalid in Java 5 or later</span>
<span class="token punctuation">}</span>
</code></pre></div><p>the following is required to compile the class using a Java 5 compiler (or later):</p> <div class="language-java extra-class"><pre class="language-java"><code>$ javac <span class="token operator">-</span>source <span class="token number">1.4</span> <span class="token class-name">OldSyntax</span><span class="token punctuation">.</span>java
</code></pre></div><h3 id="compiling-for-an-older-execution-platform"><a href="#compiling-for-an-older-execution-platform" class="header-anchor">#</a> Compiling for an older execution platform</h3> <p>If you need to compile Java to run on an older Java platforms, the simplest approach is to install a JDK for the oldest version you need to support, and use that JDK's compiler in your builds.</p> <p>You can also compile with a newer Java compiler, but there are complicated. First of all, there some important preconditions that must be satisfied:</p> <ul><li>The code you are compiling must not use Java language constructs that were not available in the version of Java that you are targeting.</li> <li>The code must not depend on standard Java classes, fields, methods and so on that were not available in the older platforms.</li> <li>Third party libraries that the code depends must also be built for the older platform and available at compile-time and run-time.</li></ul> <p>Given the preconditions are met, you can recompile code for an older platform using the <code>-target</code> option. For example,</p> <div class="language-java extra-class"><pre class="language-java"><code>$ javac <span class="token operator">-</span>target <span class="token number">1.4</span> <span class="token class-name">SomeClass</span><span class="token punctuation">.</span>java
</code></pre></div><p>will compile the above class to produce bytecodes that are compatible with Java 1.4 or later JVM. (In fact, the <code>-source</code> option implies a compatible <code>-target</code>, so <code>javac -source 1.4 ...</code> would have the same effect. The relationship between <code>-source</code> and <code>-target</code> is described in the Oracle documentation.)</p> <p>Having said that, if you simply use <code>-target</code> or <code>-source</code>, you will still be compiling against the standard class libraries provided by the compiler's JDK. If you are not careful, you can end up with classes with the correct bytecode version, but with dependencies on APIs that are not available. The solution is to use the <code>-bootclasspath</code> option. For example:</p> <div class="language-java extra-class"><pre class="language-java"><code>$ javac <span class="token operator">-</span>target <span class="token number">1.4</span> <span class="token operator">--</span>bootclasspath path<span class="token operator">/</span><span class="token keyword">to</span><span class="token operator">/</span>java1<span class="token punctuation">.</span><span class="token number">4</span><span class="token operator">/</span>rt<span class="token punctuation">.</span>jar <span class="token class-name">SomeClass</span><span class="token punctuation">.</span>java
</code></pre></div><p>will compile against an alternative set of runtime libraries. If the class being compiled has (accidental) dependencies on newer libraries, this will give you compilation errors.</p> <h4 id="remarks"><a href="#remarks" class="header-anchor">#</a> Remarks</h4> <p>The <code>javac</code> command is used for compiling Java source files to bytecode files. Bytecode files are platform independent. This means that you can compile your code on one kind of hardware and operating system, and then run the code on any other platform that supports Java.</p> <p>The <code>javac</code> command is included in the Java Development Kit (JDK) distributions.</p> <p>The Java compiler and the rest of the standard Java toolchain places the following restrictions on the code:</p> <ul><li>Source code is held in files with the suffix ".java"</li> <li>Bytecodes are held in files with the suffix ".class"</li> <li>For source and bytecode files in the file system, the file pathnames must reflect the package and class naming.</li></ul> <p>Note: The <code>javac</code> compiler should not be confused with the <a href="http://stackoverflow.com/documentation/java/5152/just-in-time-jit-compiler" target="_blank" rel="noopener noreferrer">Just in Time (JIT) compiler<span><svg xmlns="http://www.w3.org/2000/svg" aria-hidden="true" focusable="false" x="0px" y="0px" viewBox="0 0 100 100" width="15" height="15" class="icon outbound"><path fill="currentColor" d="M18.8,85.1h56l0,0c2.2,0,4-1.8,4-4v-32h-8v28h-48v-48h28v-8h-32l0,0c-2.2,0-4,1.8-4,4v56C14.8,83.3,16.6,85.1,18.8,85.1z"></path> <polygon fill="currentColor" points="45.7,48.7 51.3,54.3 77.2,28.5 77.2,37.2 85.2,37.2 85.2,14.9 62.8,14.9 62.8,22.9 71.5,22.9"></polygon></svg> <span class="sr-only">(opens new window)</span></span></a> which compiles bytecodes to native code.</p></div> <footer class="page-edit"><div class="edit-link"><a href="https://github.com/devtut/generate/edit/master/docs/java/java-compiler-javac.md" target="_blank" rel="noopener noreferrer">Edit this page on GitHub</a> <span><svg xmlns="http://www.w3.org/2000/svg" aria-hidden="true" focusable="false" x="0px" y="0px" viewBox="0 0 100 100" width="15" height="15" class="icon outbound"><path fill="currentColor" d="M18.8,85.1h56l0,0c2.2,0,4-1.8,4-4v-32h-8v28h-48v-48h28v-8h-32l0,0c-2.2,0-4,1.8-4,4v56C14.8,83.3,16.6,85.1,18.8,85.1z"></path> <polygon fill="currentColor" points="45.7,48.7 51.3,54.3 77.2,28.5 77.2,37.2 85.2,37.2 85.2,14.9 62.8,14.9 62.8,22.9 71.5,22.9"></polygon></svg> <span class="sr-only">(opens new window)</span></span></div> <!----></footer> <div class="page-nav"><p class="inner"><span class="prev">
←
<a href="/java/reference-data-types.html" class="prev">
Reference Data Types
</a></span> <span class="next"><a href="/java/documenting-java-code.html">
Documenting Java Code
</a>
→
</span></p></div> </main></div><div class="global-ui"><!----></div></div>
<script src="/assets/js/app.1779e102.js" defer></script><script src="/assets/js/3.2cfa8016.js" defer></script><script src="/assets/js/1587.c197fff7.js" defer></script>
</body>
</html>